Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content modifications for demo dapp #201

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
> **_NOTE:_** Use the Wallet Adapter v2.0.0 and up with the Aptos TypeScript SDK V2

# Aptos Wallet Adapter

A monorepo modular wallet adapter developed and maintained by Aptos for wallet and dapp builders that includes:
Expand All @@ -19,7 +21,7 @@ Note: These are in alphabetical order, any new wallets must be in alphabetical o
- [Fewcha](https://www.npmjs.com/package/fewcha-plugin-wallet-adapter)
- [Flipper](https://www.npmjs.com/package/@flipperplatform/wallet-adapter-plugin)
- [Martian](https://www.npmjs.com/package/@martianwallet/aptos-wallet-adapter)
- [MSafe](https://www.npmjs.com/package/@msafe/aptos-wallet-adapter)
- [MSafe](https://www.npmjs.com/package/@msafe/aptos-wallet-adapter)
- [Nightly](https://www.npmjs.com/package/@nightlylabs/aptos-wallet-adapter-plugin)
- [OpenBlock](https://www.npmjs.com/package/@openblockhq/aptos-wallet-adapter)
- [Petra](https://www.npmjs.com/package/petra-plugin-wallet-adapter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ export default function SingleSignerTransaction({
nonce: Math.random().toString(16),
};
const response = await signMessage(payload);
setSuccessAlertMessage(
JSON.stringify({ onSignMessageAndVerify: response })
);
setSuccessAlertMessage(JSON.stringify({ onSignMessage: response }));
};

const onSignAndSubmitTransaction = async () => {
Expand Down
10 changes: 10 additions & 0 deletions apps/nextjs-example/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import MultiAgentTransaction from "../components/transactionFlow/MultiAgent";
import Row from "../components/Row";
import Col from "../components/Col";
import { Network } from "@aptos-labs/ts-sdk";
import { Typography } from "antd";

const { Link } = Typography;

const WalletButtons = dynamic(() => import("../components/WalletButtons"), {
suspense: false,
Expand Down Expand Up @@ -44,6 +47,13 @@ export default function App() {
<h1 className="flex justify-center mt-2 mb-4 text-4xl font-extrabold tracking-tight leading-none text-black">
Aptos Wallet Adapter Tester ({network?.name ?? ""})
</h1>
<Link
href="https://github.com/aptos-labs/aptos-wallet-adapter/tree/main/apps/nextjs-example"
target="_blank"
className="flex justify-center tracking-tight leading-none text-black"
>
Demo app source code
</Link>
<table className="table-auto w-full border-separate border-spacing-y-8 shadow-lg bg-white border-separate">
<tbody>
<WalletSelect />
Expand Down
106 changes: 52 additions & 54 deletions packages/wallet-adapter-react/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
> **_NOTE:_** This documentation is for Wallet Adapter `v2.0.0` and up that is fully comatible with the Aptos TypeScript SDK V2. For Wallet Adapter `v^1.*.*` refer to [this guide](./READMEV1.md)

# Wallet Adapter React Provider

A react provider wrapper for the Aptos Wallet Adapter
Expand Down Expand Up @@ -26,6 +28,7 @@ signMessage
signTransaction
signMessageAndVerify
signAndSubmitBCSTransaction
submitTransaction
```

### Usage
Expand Down Expand Up @@ -113,6 +116,13 @@ You can find it [here](../wallet-adapter-ant-design/) with instructions on how t

#### Examples

##### Initialize Aptos

```js
const aptosConfig = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(aptosConfig);
```

##### connect(walletName)

```js
Expand All @@ -132,61 +142,51 @@ const onConnect = async (walletName) => {
##### signAndSubmitTransaction(payload)

```js
const onSignAndSubmitTransaction = async () => {
const payload: Types.TransactionPayload = {
type: "entry_function_payload",
const onSignAndSubmitTransaction = async () => {
const response = await signAndSubmitTransaction({
sender: account.address,
data: {
function: "0x1::coin::transfer",
type_arguments: ["0x1::aptos_coin::AptosCoin"],
arguments: [account?.address, 1], // 1 is in Octas
};
const response = await signAndSubmitTransaction(payload);
// if you want to wait for transaction
try {
await aptosClient.waitForTransaction(response?.hash || "");
} catch (error) {
console.error(error);
}
};
typeArguments: ["0x1::aptos_coin::AptosCoin"],
functionArguments: [account.address, 1],
},
});
// if you want to wait for transaction
try {
await aptos.waitForTransaction({ transactionHash: response.hash });
} catch (error) {
console.error(error);
}
};

<button onClick={onSignAndSubmitTransaction}>
Sign and submit transaction
</button>
</button>;
```

##### signAndSubmitBCSTransaction(payload)

```js
const onSignAndSubmitBCSTransaction = async () => {
const token = new TxnBuilderTypes.TypeTagStruct(
TxnBuilderTypes.StructTag.fromString("0x1::aptos_coin::AptosCoin")
);
const entryFunctionBCSPayload =
new TxnBuilderTypes.TransactionPayloadEntryFunction(
TxnBuilderTypes.EntryFunction.natural(
"0x1::coin",
"transfer",
[token],
[
BCS.bcsToBytes(
TxnBuilderTypes.AccountAddress.fromHex(account!.address)
),
BCS.bcsSerializeUint64(2),
]
)
);

const response = await signAndSubmitBCSTransaction(entryFunctionBCSPayload);
// if you want to wait for transaction
try {
await aptosClient.waitForTransaction(response?.hash || "");
} catch (error) {
console.error(error);
}
};
const onSignAndSubmitBCSTransaction = async () => {
const response = await signAndSubmitTransaction({
sender: account.address,
data: {
function: "0x1::coin::transfer",
typeArguments: [parseTypeTag(APTOS_COIN)],
functionArguments: [AccountAddress.from(account.address), new U64(1)],
},
});
// if you want to wait for transaction
try {
await aptos.waitForTransaction({ transactionHash: response.hash });
} catch (error) {
console.error(error);
}
};

<button onClick={onSignAndSubmitTransaction}>
Sign and submit BCS transaction
</button>
</button>;
```

##### signMessage(payload)
Expand Down Expand Up @@ -235,19 +235,17 @@ const onSignMessage = async () => {
##### signTransaction(payload)

```js
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
};
const response = await signTransaction(payload);
const onSignTransaction = async () => {
const payload = {
type: "entry_function_payload",
function: "0x1::coin::transfer",
type_arguments: ["0x1::aptos_coin::AptosCoin"],
arguments: [account?.address, 1], // 1 is in Octas
};
const response = await signTransaction(payload);
};

<button onClick={onSignTransaction}>
Sign transaction
</button>
<button onClick={onSignTransaction}>Sign transaction</button>;
```

##### signMessageAndVerify(payload)
Expand Down
Loading
Loading