@aptos-labs/wallet-adapter-react 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +63 -35
- package/dist/index.d.ts +1 -2
- package/package.json +2 -3
- package/src/WalletProvider.tsx +2 -2
- package/src/useWallet.tsx +2 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -20,11 +20,12 @@ signAndSubmitTransaction
|
|
|
20
20
|
signMessage
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
##### Feature functions
|
|
23
|
+
##### Feature functions - functions that may not be supported by all wallets
|
|
24
24
|
|
|
25
25
|
```
|
|
26
26
|
signTransaction
|
|
27
27
|
signMessageAndVerify
|
|
28
|
+
signAndSubmitBCSTransaction
|
|
28
29
|
```
|
|
29
30
|
|
|
30
31
|
### Usage
|
|
@@ -67,7 +68,13 @@ Wrap your app with the Provider, pass it the `plugins (wallets)` you want to hav
|
|
|
67
68
|
```js
|
|
68
69
|
const wallets = [new AptosWallet()];
|
|
69
70
|
|
|
70
|
-
<AptosWalletAdapterProvider
|
|
71
|
+
<AptosWalletAdapterProvider
|
|
72
|
+
plugins={wallets}
|
|
73
|
+
autoConnect={true}
|
|
74
|
+
onError={(error) => {
|
|
75
|
+
console.log("error", error);
|
|
76
|
+
}}
|
|
77
|
+
>
|
|
71
78
|
<App />
|
|
72
79
|
</AptosWalletAdapterProvider>;
|
|
73
80
|
```
|
|
@@ -92,6 +99,7 @@ const {
|
|
|
92
99
|
wallet,
|
|
93
100
|
wallets,
|
|
94
101
|
signAndSubmitTransaction,
|
|
102
|
+
signAndSubmitBCSTransaction,
|
|
95
103
|
signTransaction,
|
|
96
104
|
signMessage,
|
|
97
105
|
signMessageAndVerify,
|
|
@@ -108,7 +116,11 @@ You can find it [here](../wallet-adapter-ant-design/) with instructions on how t
|
|
|
108
116
|
##### connect(walletName)
|
|
109
117
|
|
|
110
118
|
```js
|
|
111
|
-
|
|
119
|
+
const onConnect = async (walletName) => {
|
|
120
|
+
await connect(walletName);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
<button onClick={() => onConnect(wallet.name)}>{wallet.name}</button>;
|
|
112
124
|
```
|
|
113
125
|
|
|
114
126
|
##### disconnect()
|
|
@@ -127,13 +139,12 @@ You can find it [here](../wallet-adapter-ant-design/) with instructions on how t
|
|
|
127
139
|
type_arguments: ["0x1::aptos_coin::AptosCoin"],
|
|
128
140
|
arguments: [account?.address, 1], // 1 is in Octas
|
|
129
141
|
};
|
|
142
|
+
const response = await signAndSubmitTransaction(payload);
|
|
143
|
+
// if you want to wait for transaction
|
|
130
144
|
try {
|
|
131
|
-
const response = await signAndSubmitTransaction(payload);
|
|
132
|
-
// if you want to wait for transaction
|
|
133
145
|
await aptosClient.waitForTransaction(response?.hash || "");
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
console.log("error", error);
|
|
146
|
+
} catch (error) {
|
|
147
|
+
console.error(error);
|
|
137
148
|
}
|
|
138
149
|
};
|
|
139
150
|
|
|
@@ -142,27 +153,56 @@ You can find it [here](../wallet-adapter-ant-design/) with instructions on how t
|
|
|
142
153
|
</button>
|
|
143
154
|
```
|
|
144
155
|
|
|
145
|
-
#####
|
|
156
|
+
##### signAndSubmitBCSTransaction(payload)
|
|
146
157
|
|
|
147
158
|
```js
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
159
|
+
const onSignAndSubmitBCSTransaction = async () => {
|
|
160
|
+
const token = new TxnBuilderTypes.TypeTagStruct(
|
|
161
|
+
TxnBuilderTypes.StructTag.fromString("0x1::aptos_coin::AptosCoin")
|
|
162
|
+
);
|
|
163
|
+
const entryFunctionBCSPayload =
|
|
164
|
+
new TxnBuilderTypes.TransactionPayloadEntryFunction(
|
|
165
|
+
TxnBuilderTypes.EntryFunction.natural(
|
|
166
|
+
"0x1::coin",
|
|
167
|
+
"transfer",
|
|
168
|
+
[token],
|
|
169
|
+
[
|
|
170
|
+
BCS.bcsToBytes(
|
|
171
|
+
TxnBuilderTypes.AccountAddress.fromHex(account!.address)
|
|
172
|
+
),
|
|
173
|
+
BCS.bcsSerializeUint64(2),
|
|
174
|
+
]
|
|
175
|
+
)
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
const response = await signAndSubmitBCSTransaction(entryFunctionBCSPayload);
|
|
179
|
+
// if you want to wait for transaction
|
|
153
180
|
try {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
console.log("error", error);
|
|
181
|
+
await aptosClient.waitForTransaction(response?.hash || "");
|
|
182
|
+
} catch (error) {
|
|
183
|
+
console.error(error);
|
|
158
184
|
}
|
|
159
185
|
};
|
|
160
186
|
|
|
161
|
-
<button onClick={
|
|
162
|
-
Sign
|
|
187
|
+
<button onClick={onSignAndSubmitTransaction}>
|
|
188
|
+
Sign and submit BCS transaction
|
|
163
189
|
</button>
|
|
164
190
|
```
|
|
165
191
|
|
|
192
|
+
##### signMessage(payload)
|
|
193
|
+
|
|
194
|
+
```js
|
|
195
|
+
const onSignMessage = async () => {
|
|
196
|
+
const payload = {
|
|
197
|
+
message: "Hello from Aptos Wallet Adapter",
|
|
198
|
+
nonce: "random_string",
|
|
199
|
+
};
|
|
200
|
+
const response = await signMessage(payload);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
<button onClick={onSignMessage}>Sign message</button>;
|
|
204
|
+
```
|
|
205
|
+
|
|
166
206
|
##### Account
|
|
167
207
|
|
|
168
208
|
```js
|
|
@@ -202,12 +242,7 @@ You can find it [here](../wallet-adapter-ant-design/) with instructions on how t
|
|
|
202
242
|
type_arguments: ["0x1::aptos_coin::AptosCoin"],
|
|
203
243
|
arguments: [account?.address, 1], // 1 is in Octas
|
|
204
244
|
};
|
|
205
|
-
|
|
206
|
-
const response = await signTransaction(payload);
|
|
207
|
-
console.log("response", response);
|
|
208
|
-
} catch (error: any) {
|
|
209
|
-
console.log("error", error);
|
|
210
|
-
}
|
|
245
|
+
const response = await signTransaction(payload);
|
|
211
246
|
};
|
|
212
247
|
|
|
213
248
|
<button onClick={onSignTransaction}>
|
|
@@ -223,15 +258,8 @@ const onSignMessageAndVerify = async () => {
|
|
|
223
258
|
message: "Hello from Aptos Wallet Adapter",
|
|
224
259
|
nonce: "random_string",
|
|
225
260
|
};
|
|
226
|
-
|
|
227
|
-
const response = await signMessageAndVerify(payload);
|
|
228
|
-
console.log("response", response);
|
|
229
|
-
} catch (error: any) {
|
|
230
|
-
console.log("error", error);
|
|
231
|
-
}
|
|
261
|
+
const response = await signMessageAndVerify(payload);
|
|
232
262
|
};
|
|
233
263
|
|
|
234
|
-
<button onClick={onSignMessageAndVerify}>
|
|
235
|
-
Sign message and verify
|
|
236
|
-
</button>
|
|
264
|
+
<button onClick={onSignMessageAndVerify}>Sign message and verify</button>;
|
|
237
265
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { AccountInfo, NetworkInfo, WalletName, WalletInfo, Wallet, TransactionOptions, SignMessagePayload, SignMessageResponse } from '@aptos-labs/wallet-adapter-core';
|
|
1
|
+
import { AccountInfo, NetworkInfo, WalletName, WalletInfo, Wallet, Types, TransactionOptions, TxnBuilderTypes, SignMessagePayload, SignMessageResponse } from '@aptos-labs/wallet-adapter-core';
|
|
2
2
|
export { NetworkName, Wallet, WalletName, WalletReadyState, isInAppBrowser, isMobile, isRedirectable } from '@aptos-labs/wallet-adapter-core';
|
|
3
|
-
import { Types, TxnBuilderTypes } from 'aptos';
|
|
4
3
|
import { ReactNode, FC } from 'react';
|
|
5
4
|
|
|
6
5
|
interface WalletContextState {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aptos-labs/wallet-adapter-react",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Aptos Wallet Adapter React Provider",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -37,8 +37,7 @@
|
|
|
37
37
|
"@aptos-labs/wallet-adapter-tsconfig": "0.0.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@aptos-labs/wallet-adapter-core": "2.5.
|
|
41
|
-
"aptos": "^1.3.17",
|
|
40
|
+
"@aptos-labs/wallet-adapter-core": "2.5.1",
|
|
42
41
|
"react": "^18"
|
|
43
42
|
},
|
|
44
43
|
"scripts": {
|
package/src/WalletProvider.tsx
CHANGED
|
@@ -15,11 +15,11 @@ import type {
|
|
|
15
15
|
WalletInfo,
|
|
16
16
|
WalletName,
|
|
17
17
|
TransactionOptions,
|
|
18
|
+
TxnBuilderTypes,
|
|
19
|
+
Types,
|
|
18
20
|
} from "@aptos-labs/wallet-adapter-core";
|
|
19
21
|
import { WalletCore } from "@aptos-labs/wallet-adapter-core";
|
|
20
22
|
|
|
21
|
-
import { TxnBuilderTypes, Types } from "aptos";
|
|
22
|
-
|
|
23
23
|
export interface AptosWalletProviderProps {
|
|
24
24
|
children: ReactNode;
|
|
25
25
|
plugins: ReadonlyArray<Wallet>;
|
package/src/useWallet.tsx
CHANGED
|
@@ -12,9 +12,10 @@ import {
|
|
|
12
12
|
isRedirectable,
|
|
13
13
|
isMobile,
|
|
14
14
|
TransactionOptions,
|
|
15
|
+
TxnBuilderTypes,
|
|
16
|
+
Types,
|
|
15
17
|
} from "@aptos-labs/wallet-adapter-core";
|
|
16
18
|
import { createContext, useContext } from "react";
|
|
17
|
-
import { TxnBuilderTypes, Types } from "aptos";
|
|
18
19
|
|
|
19
20
|
export type { WalletName, Wallet };
|
|
20
21
|
export {
|