Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmaayan committed Nov 21, 2022
1 parent 08f30ae commit 2f01938
Show file tree
Hide file tree
Showing 49 changed files with 5,038 additions and 215 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
root: true,
// This tells ESLint to load the config from the package `eslint-config-custom`
extends: ["custom"],
extends: ["adapter"],
settings: {
next: {
rootDir: ["apps/*/"],
Expand Down
76 changes: 3 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,3 @@
# Turborepo starter

This is an official pnpm starter turborepo.

## What's inside?

This turborepo uses [pnpm](https://pnpm.io) as a package manager. It includes the following packages/apps:

### Apps and Packages

- `docs`: a [Next.js](https://nextjs.org/) app
- `web`: another [Next.js](https://nextjs.org/) app
- `ui`: a stub React component library shared by both `web` and `docs` applications
- `eslint-config-custom`: `eslint` configurations (includes `eslint-config-next` and `eslint-config-prettier`)
- `tsconfig`: `tsconfig.json`s used throughout the monorepo

Each package/app is 100% [TypeScript](https://www.typescriptlang.org/).

### Utilities

This turborepo has some additional tools already setup for you:

- [TypeScript](https://www.typescriptlang.org/) for static type checking
- [ESLint](https://eslint.org/) for code linting
- [Prettier](https://prettier.io) for code formatting

### Build

To build all apps and packages, run the following command:

```
cd my-turborepo
pnpm run build
```

### Develop

To develop all apps and packages, run the following command:

```
cd my-turborepo
pnpm run dev
```

### Remote Caching

Turborepo can use a technique known as [Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching) to share cache artifacts across machines, enabling you to share build caches with your team and CI/CD pipelines.

By default, Turborepo will cache locally. To enable Remote Caching you will need an account with Vercel. If you don't have an account you can [create one](https://vercel.com/signup), then enter the following commands:

```
cd my-turborepo
pnpm dlx turbo login
```

This will authenticate the Turborepo CLI with your [Vercel account](https://vercel.com/docs/concepts/personal-accounts/overview).

Next, you can link your Turborepo to your Remote Cache by running the following command from the root of your turborepo:

```
pnpm dlx turbo link
```

## Useful Links

Learn more about the power of Turborepo:

- [Pipelines](https://turbo.build/repo/docs/core-concepts/monorepos/running-tasks)
- [Caching](https://turbo.build/repo/docs/core-concepts/caching)
- [Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching)
- [Filtering](https://turbo.build/repo/docs/core-concepts/monorepos/filtering)
- [Configuration Options](https://turbo.build/repo/docs/reference/configuration)
- [CLI Usage](https://turbo.build/repo/docs/reference/command-line-reference)
git clone
pnpm i
pnpm turbo run dev
7 changes: 3 additions & 4 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
"dependencies": {
"next": "13.0.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"ui": "workspace:*"
"react-dom": "18.2.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"eslint-config-custom": "workspace:*",
"eslint-config-adapter": "workspace:*",
"eslint": "7.32.0",
"tsconfig": "workspace:*",
"@aptos/wallet-adapter-tsconfig": "workspace:*",
"@types/node": "^17.0.12",
"@types/react": "^18.0.22",
"@types/react-dom": "^18.0.7",
Expand Down
3 changes: 0 additions & 3 deletions apps/docs/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Button } from "ui";

export default function Docs() {
return (
<div>
<h1>Docs</h1>
<Button />
</div>
);
}
2 changes: 1 addition & 1 deletion apps/docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "tsconfig/nextjs.json",
"extends": "@aptos/wallet-adapter-tsconfig/nextjs.json",
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
12 changes: 7 additions & 5 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@
"lint": "next lint"
},
"dependencies": {
"aptos": "^1.3.17",
"@aptos/wallet-adapter-plugin": "workspace:*",
"@aptos/wallet-adapter-react": "workspace:*",
"next": "13.0.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"ui": "workspace:*"
"react-dom": "18.2.0"
},
"devDependencies": {
"@aptos/wallet-adapter-tsconfig": "workspace:*",
"@babel/core": "^7.0.0",
"eslint-config-custom": "workspace:*",
"eslint": "7.32.0",
"tsconfig": "workspace:*",
"@types/node": "^17.0.12",
"@types/react": "^18.0.22",
"@types/react-dom": "^18.0.7",
"eslint": "7.32.0",
"eslint-config-adapter": "workspace:*",
"typescript": "^4.5.3"
}
}
127 changes: 127 additions & 0 deletions apps/web/pages/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { AptosClient, Types } from "aptos";
import { useWallet, WalletName, Wallet } from "@aptos/wallet-adapter-react/src";
import { useState } from "react";

export const DEVNET_NODE_URL = "https://fullnode.devnet.aptoslabs.com/v1";

const aptosClient = new AptosClient(DEVNET_NODE_URL, {
WITH_CREDENTIALS: false,
});

type Props = {
wallets: Wallet[];
};

export default function App({ wallets }: Props) {
const {
connect,
disconnect,
account,
network,
getWallet,
signAndSubmitTransaction,
signTransaction,
signMessage,
} = useWallet();
const [txsLink, setTxsLink] = useState<string>("");
const [messageResponse, setMessageResponse] = useState();

const onConnectClick = (wallet: WalletName) => {
connect(wallet);
};

const onSignAndSubmitTransaction = async () => {
const payload: Types.TransactionPayload = {
type: "entry_function_payload",
function: "0x1::coin::transfer",
type_arguments: ["0x1::aptos_coin::AptosCoin"],
arguments: [account?.address, 1], // 1 is in Octas
};
try {
const response = await signAndSubmitTransaction(payload);
await aptosClient.waitForTransaction(response?.hash || "");
setTxsLink(`https://explorer.devnet.aptos.dev/txn/${response?.hash}`);
} catch (error: any) {
console.log("error", error);
}
};

const onSignTransaction = async () => {
const payload: Types.TransactionPayload = {
type: "entry_function_payload",
function: "0x1::coin::transfer",
type_arguments: ["0x1::aptos_coin::AptosCoin"],
arguments: [account?.address, 1], // 1 is in Octas
};
try {
const response = await signTransaction(payload);
console.log("response", response);
} catch (error: any) {
console.log("error", error);
}
};

const onSignMessage = async () => {
const payload = {
message: "Hello from Aptos Wallet Adapter",
nonce: "random_string",
};
try {
const response = await signMessage(payload);
setMessageResponse(response as any);
} catch (error: any) {
console.log("error", error);
}
};

return (
<div>
<div>
{wallets.map((wallet) => {
return (
<button
disabled={wallet.readyState !== "Installed"}
key={wallet.name}
onClick={() => onConnectClick(wallet.name)}
>
{wallet.name}
</button>
);
})}
</div>
<div>
<button onClick={disconnect}>Disconnect</button>
</div>
<div>
<button onClick={onSignAndSubmitTransaction}>
Sign and submit transaction
</button>
{txsLink.length > 0 && (
<p>
<a href={txsLink} target="_blank">
{txsLink}
</a>
</p>
)}
</div>
<div>
<button onClick={onSignTransaction}>Sign transaction</button>
</div>

<div>
<button onClick={onSignMessage}>Sign Message</button>
{messageResponse && <p>{JSON.stringify(messageResponse)}</p>}
</div>

<div>
Wallet Name: <div>{JSON.stringify(getWallet()?.name)}</div>
</div>
<div>
Account: <div>{JSON.stringify(account)}</div>
</div>
<div>
Network: <div>{JSON.stringify(network)}</div>
</div>
</div>
);
}
20 changes: 15 additions & 5 deletions apps/web/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { Button } from "ui";
import {
PetraWallet,
MartianWallet,
RiseWallet,
} from "@aptos/wallet-adapter-plugin/src/wallets";
import { AptosWalletAdapterProvider } from "@aptos/wallet-adapter-react/src";
import App from "./App";

export default function Web() {
const wallets = [new PetraWallet(), new MartianWallet(), new RiseWallet()];

return (
<div>
<h1>Web</h1>
<Button />
</div>
<AptosWalletAdapterProvider plugins={wallets} autoConnect={true}>
<div>
<h1>Web</h1>
</div>
<App wallets={wallets} />
</AptosWalletAdapterProvider>
);
}
2 changes: 1 addition & 1 deletion apps/web/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "tsconfig/nextjs.json",
"extends": "@aptos/wallet-adapter-tsconfig/nextjs.json",
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
],
"scripts": {
"build": "turbo run build",
"dev": "turbo run dev --parallel",
"dev": "turbo run dev --no-cache --parallel --continue",
"lint": "turbo run lint",
"format": "prettier --write \"**/*.{ts,tsx,md}\""
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"clean": "turbo run clean && rm -rf node_modules",
"changeset": "changeset",
"version-packages": "changeset version",
"release": "turbo run build --filter=docs^... && changeset publish"
},
"devDependencies": {
"eslint-config-custom": "workspace:*",
"eslint-config-adapter": "workspace:*",
"@changesets/cli": "^2.22.0",
"prettier": "latest",
"turbo": "latest"
},
Expand All @@ -22,4 +27,4 @@
},
"dependencies": {},
"packageManager": "[email protected]"
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "eslint-config-custom",
"name": "eslint-config-adapter",
"version": "0.0.0",
"main": "index.js",
"license": "MIT",
Expand Down
6 changes: 5 additions & 1 deletion packages/tsconfig/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"name": "tsconfig",
"name": "@aptos/wallet-adapter-tsconfig",
"version": "0.0.0",
"private": true,
"license": "MIT",
"publishConfig": {
"access": "public"
},
"files": [
"base.json",
"nextjs.json",
Expand Down
2 changes: 1 addition & 1 deletion packages/tsconfig/react-library.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"extends": "./base.json",
"compilerOptions": {
"jsx": "react-jsx",
"lib": ["ES2015"],
"lib": ["dom", "ES2015"],
"module": "ESNext",
"target": "es6"
}
Expand Down
4 changes: 0 additions & 4 deletions packages/ui/Button.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions packages/ui/index.tsx

This file was deleted.

19 changes: 0 additions & 19 deletions packages/ui/package.json

This file was deleted.

4 changes: 4 additions & 0 deletions packages/wallet-adapter-core/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ["adapter"],
};
Loading

0 comments on commit 2f01938

Please sign in to comment.