@aptos-labs/wallet-adapter-react 1.4.0 → 2.1.0
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 +33 -0
- package/README.md +52 -54
- package/READMEV1.md +267 -0
- package/dist/index.d.ts +5 -7
- package/dist/index.js +17 -46
- package/dist/index.mjs +17 -46
- package/package.json +2 -2
- package/src/WalletProvider.tsx +37 -56
- package/src/index.tsx +1 -1
- package/src/useWallet.tsx +23 -24
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @aptos-labs/wallet-adapter-react
|
|
2
2
|
|
|
3
|
+
## 2.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- aa3d15a: Make sender optional when sign and submit single signer transaction
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [6257015]
|
|
12
|
+
- Updated dependencies [aa3d15a]
|
|
13
|
+
- @aptos-labs/wallet-adapter-core@3.1.0
|
|
14
|
+
|
|
15
|
+
## 2.0.0
|
|
16
|
+
|
|
17
|
+
### Major Changes
|
|
18
|
+
|
|
19
|
+
- 31e0084: Support TypeScript SDK V2. Fully compatible with existing SDK V1 and Wallet Adapter V1
|
|
20
|
+
but with a full SDK V2 support for the dapp.
|
|
21
|
+
|
|
22
|
+
- Add support for SDK V2 input types
|
|
23
|
+
- `signAndSubmitTransaction()` accept only SDK V2 transaction input type
|
|
24
|
+
- Implement a `submitTransaction()` function for multi signers transactions
|
|
25
|
+
- `signTransaction()` to support both SDK V1 and V2 versions
|
|
26
|
+
- Convert wallet `SignedTransaction` response from `signTransaction()` to TS SDK V2 `AccountAuthenticator`
|
|
27
|
+
- Demo app to demonstrate different trnsaction flows - single signer, sponsor and multi agent transactions
|
|
28
|
+
- Reject promise on core and/or provider errors instead of just returning `false`
|
|
29
|
+
- Use `@aptos-labs/ts-sdk@experimental` version `0.0.7`
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- Updated dependencies [31e0084]
|
|
34
|
+
- @aptos-labs/wallet-adapter-core@3.0.0
|
|
35
|
+
|
|
3
36
|
## 1.4.0
|
|
4
37
|
|
|
5
38
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> **_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)
|
|
2
|
+
|
|
1
3
|
# Wallet Adapter React Provider
|
|
2
4
|
|
|
3
5
|
A react provider wrapper for the Aptos Wallet Adapter
|
|
@@ -26,6 +28,7 @@ signMessage
|
|
|
26
28
|
signTransaction
|
|
27
29
|
signMessageAndVerify
|
|
28
30
|
signAndSubmitBCSTransaction
|
|
31
|
+
submitTransaction
|
|
29
32
|
```
|
|
30
33
|
|
|
31
34
|
### Usage
|
|
@@ -113,6 +116,13 @@ You can find it [here](../wallet-adapter-ant-design/) with instructions on how t
|
|
|
113
116
|
|
|
114
117
|
#### Examples
|
|
115
118
|
|
|
119
|
+
##### Initialize Aptos
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
const aptosConfig = new AptosConfig({ network: Network.TESTNET });
|
|
123
|
+
const aptos = new Aptos(aptosConfig);
|
|
124
|
+
```
|
|
125
|
+
|
|
116
126
|
##### connect(walletName)
|
|
117
127
|
|
|
118
128
|
```js
|
|
@@ -132,61 +142,51 @@ const onConnect = async (walletName) => {
|
|
|
132
142
|
##### signAndSubmitTransaction(payload)
|
|
133
143
|
|
|
134
144
|
```js
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
145
|
+
const onSignAndSubmitTransaction = async () => {
|
|
146
|
+
const response = await signAndSubmitTransaction({
|
|
147
|
+
sender: account.address,
|
|
148
|
+
data: {
|
|
138
149
|
function: "0x1::coin::transfer",
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
+
typeArguments: ["0x1::aptos_coin::AptosCoin"],
|
|
151
|
+
functionArguments: [account.address, 1],
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
// if you want to wait for transaction
|
|
155
|
+
try {
|
|
156
|
+
await aptos.waitForTransaction({ transactionHash: response.hash });
|
|
157
|
+
} catch (error) {
|
|
158
|
+
console.error(error);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
150
161
|
|
|
151
162
|
<button onClick={onSignAndSubmitTransaction}>
|
|
152
163
|
Sign and submit transaction
|
|
153
|
-
</button
|
|
164
|
+
</button>;
|
|
154
165
|
```
|
|
155
166
|
|
|
156
167
|
##### signAndSubmitBCSTransaction(payload)
|
|
157
168
|
|
|
158
169
|
```js
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
)
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
const response = await signAndSubmitBCSTransaction(entryFunctionBCSPayload);
|
|
179
|
-
// if you want to wait for transaction
|
|
180
|
-
try {
|
|
181
|
-
await aptosClient.waitForTransaction(response?.hash || "");
|
|
182
|
-
} catch (error) {
|
|
183
|
-
console.error(error);
|
|
184
|
-
}
|
|
185
|
-
};
|
|
170
|
+
const onSignAndSubmitBCSTransaction = async () => {
|
|
171
|
+
const response = await signAndSubmitTransaction({
|
|
172
|
+
sender: account.address,
|
|
173
|
+
data: {
|
|
174
|
+
function: "0x1::coin::transfer",
|
|
175
|
+
typeArguments: [parseTypeTag(APTOS_COIN)],
|
|
176
|
+
functionArguments: [AccountAddress.from(account.address), new U64(1)],
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
// if you want to wait for transaction
|
|
180
|
+
try {
|
|
181
|
+
await aptos.waitForTransaction({ transactionHash: response.hash });
|
|
182
|
+
} catch (error) {
|
|
183
|
+
console.error(error);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
186
|
|
|
187
187
|
<button onClick={onSignAndSubmitTransaction}>
|
|
188
188
|
Sign and submit BCS transaction
|
|
189
|
-
</button
|
|
189
|
+
</button>;
|
|
190
190
|
```
|
|
191
191
|
|
|
192
192
|
##### signMessage(payload)
|
|
@@ -235,19 +235,17 @@ const onSignMessage = async () => {
|
|
|
235
235
|
##### signTransaction(payload)
|
|
236
236
|
|
|
237
237
|
```js
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
};
|
|
245
|
-
const response = await signTransaction(payload);
|
|
238
|
+
const onSignTransaction = async () => {
|
|
239
|
+
const payload = {
|
|
240
|
+
type: "entry_function_payload",
|
|
241
|
+
function: "0x1::coin::transfer",
|
|
242
|
+
type_arguments: ["0x1::aptos_coin::AptosCoin"],
|
|
243
|
+
arguments: [account?.address, 1], // 1 is in Octas
|
|
246
244
|
};
|
|
245
|
+
const response = await signTransaction(payload);
|
|
246
|
+
};
|
|
247
247
|
|
|
248
|
-
<button onClick={onSignTransaction}>
|
|
249
|
-
Sign transaction
|
|
250
|
-
</button>
|
|
248
|
+
<button onClick={onSignTransaction}>Sign transaction</button>;
|
|
251
249
|
```
|
|
252
250
|
|
|
253
251
|
##### signMessageAndVerify(payload)
|
package/READMEV1.md
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
> **_NOTE:_** This documentation is for Wallet Adapter `v^1.*.*`
|
|
2
|
+
|
|
3
|
+
# Wallet Adapter React Provider
|
|
4
|
+
|
|
5
|
+
A react provider wrapper for the Aptos Wallet Adapter
|
|
6
|
+
|
|
7
|
+
Dapps that want to use the adapter should install this package and other supported wallet packages.
|
|
8
|
+
|
|
9
|
+
### Support
|
|
10
|
+
|
|
11
|
+
The react provider supports all [wallet standard](https://aptos.dev/guides/wallet-standard) functions and feature functions
|
|
12
|
+
|
|
13
|
+
##### Standard functions
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
connect
|
|
17
|
+
disconnect
|
|
18
|
+
connected
|
|
19
|
+
account
|
|
20
|
+
network
|
|
21
|
+
signAndSubmitTransaction
|
|
22
|
+
signMessage
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
##### Feature functions - functions that may not be supported by all wallets
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
signTransaction
|
|
29
|
+
signMessageAndVerify
|
|
30
|
+
signAndSubmitBCSTransaction
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Usage
|
|
34
|
+
|
|
35
|
+
#### Install Dependencies
|
|
36
|
+
|
|
37
|
+
Install wallet dependencies you want to include in your app.
|
|
38
|
+
To do that, you can look at our [supported wallets list](https://github.com/aptos-labs/aptos-wallet-adapter#supported-wallet-packages). Each wallet is a link to npm package where you can install it from.
|
|
39
|
+
|
|
40
|
+
Next, install the `@aptos-labs/wallet-adapter-react`
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
pnpm i @aptos-labs/wallet-adapter-react
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
using npm
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
npm i @aptos-labs/wallet-adapter-react
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### Import dependencies
|
|
53
|
+
|
|
54
|
+
On the `App.jsx` file,
|
|
55
|
+
|
|
56
|
+
Import the installed wallets.
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
import { SomeAptosWallet } from "some-aptos-wallet-package";
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Import the `AptosWalletAdapterProvider`.
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
import { AptosWalletAdapterProvider } from "@aptos-labs/wallet-adapter-react";
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Wrap your app with the Provider, pass it the `plugins (wallets)` you want to have on your app as an array and a `autoConnect` option (set to false by default)
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
const wallets = [new AptosWallet()];
|
|
72
|
+
|
|
73
|
+
<AptosWalletAdapterProvider
|
|
74
|
+
plugins={wallets}
|
|
75
|
+
autoConnect={true}
|
|
76
|
+
onError={(error) => {
|
|
77
|
+
console.log("error", error);
|
|
78
|
+
}}
|
|
79
|
+
>
|
|
80
|
+
<App />
|
|
81
|
+
</AptosWalletAdapterProvider>;
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### Use Wallet
|
|
85
|
+
|
|
86
|
+
On any page you want to use the wallet props, import `useWallet` from `@aptos-labs/wallet-adapter-react`
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
import { useWallet } from "@aptos-labs/wallet-adapter-react";
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Then you can use the exported properties
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
const {
|
|
96
|
+
connect,
|
|
97
|
+
account,
|
|
98
|
+
network,
|
|
99
|
+
connected,
|
|
100
|
+
disconnect,
|
|
101
|
+
wallet,
|
|
102
|
+
wallets,
|
|
103
|
+
signAndSubmitTransaction,
|
|
104
|
+
signAndSubmitBCSTransaction,
|
|
105
|
+
signTransaction,
|
|
106
|
+
signMessage,
|
|
107
|
+
signMessageAndVerify,
|
|
108
|
+
} = useWallet();
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Use a UI package (recommended)
|
|
112
|
+
|
|
113
|
+
As part of the wallet adapter repo we provide a wallet connect UI package that provides a wallet connect button and a wallet select modal.
|
|
114
|
+
You can find it [here](../wallet-adapter-ant-design/) with instructions on how to use it.
|
|
115
|
+
|
|
116
|
+
#### Examples
|
|
117
|
+
|
|
118
|
+
##### connect(walletName)
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
const onConnect = async (walletName) => {
|
|
122
|
+
await connect(walletName);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
<button onClick={() => onConnect(wallet.name)}>{wallet.name}</button>;
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
##### disconnect()
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
<button onClick={disconnect}>Disconnect</button>
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
##### signAndSubmitTransaction(payload)
|
|
135
|
+
|
|
136
|
+
```js
|
|
137
|
+
const onSignAndSubmitTransaction = async () => {
|
|
138
|
+
const payload: Types.TransactionPayload = {
|
|
139
|
+
type: "entry_function_payload",
|
|
140
|
+
function: "0x1::coin::transfer",
|
|
141
|
+
type_arguments: ["0x1::aptos_coin::AptosCoin"],
|
|
142
|
+
arguments: [account?.address, 1], // 1 is in Octas
|
|
143
|
+
};
|
|
144
|
+
const response = await signAndSubmitTransaction(payload);
|
|
145
|
+
// if you want to wait for transaction
|
|
146
|
+
try {
|
|
147
|
+
await aptosClient.waitForTransaction(response?.hash || "");
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.error(error);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
<button onClick={onSignAndSubmitTransaction}>
|
|
154
|
+
Sign and submit transaction
|
|
155
|
+
</button>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
##### signAndSubmitBCSTransaction(payload)
|
|
159
|
+
|
|
160
|
+
```js
|
|
161
|
+
const onSignAndSubmitBCSTransaction = async () => {
|
|
162
|
+
const token = new TxnBuilderTypes.TypeTagStruct(
|
|
163
|
+
TxnBuilderTypes.StructTag.fromString("0x1::aptos_coin::AptosCoin")
|
|
164
|
+
);
|
|
165
|
+
const entryFunctionBCSPayload =
|
|
166
|
+
new TxnBuilderTypes.TransactionPayloadEntryFunction(
|
|
167
|
+
TxnBuilderTypes.EntryFunction.natural(
|
|
168
|
+
"0x1::coin",
|
|
169
|
+
"transfer",
|
|
170
|
+
[token],
|
|
171
|
+
[
|
|
172
|
+
BCS.bcsToBytes(
|
|
173
|
+
TxnBuilderTypes.AccountAddress.fromHex(account!.address)
|
|
174
|
+
),
|
|
175
|
+
BCS.bcsSerializeUint64(2),
|
|
176
|
+
]
|
|
177
|
+
)
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const response = await signAndSubmitBCSTransaction(entryFunctionBCSPayload);
|
|
181
|
+
// if you want to wait for transaction
|
|
182
|
+
try {
|
|
183
|
+
await aptosClient.waitForTransaction(response?.hash || "");
|
|
184
|
+
} catch (error) {
|
|
185
|
+
console.error(error);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
<button onClick={onSignAndSubmitTransaction}>
|
|
190
|
+
Sign and submit BCS transaction
|
|
191
|
+
</button>
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
##### signMessage(payload)
|
|
195
|
+
|
|
196
|
+
```js
|
|
197
|
+
const onSignMessage = async () => {
|
|
198
|
+
const payload = {
|
|
199
|
+
message: "Hello from Aptos Wallet Adapter",
|
|
200
|
+
nonce: "random_string",
|
|
201
|
+
};
|
|
202
|
+
const response = await signMessage(payload);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
<button onClick={onSignMessage}>Sign message</button>;
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
##### Account
|
|
209
|
+
|
|
210
|
+
```js
|
|
211
|
+
<div>{account?.address}</div>
|
|
212
|
+
<div>{account?.publicKey}</div>
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
##### Network
|
|
216
|
+
|
|
217
|
+
```js
|
|
218
|
+
<div>{network?.name}</div>
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
##### Wallet
|
|
222
|
+
|
|
223
|
+
```js
|
|
224
|
+
<div>{wallet?.name}</div>
|
|
225
|
+
<div>{wallet?.icon}</div>
|
|
226
|
+
<div>{wallet?.url}</div>
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
##### Wallets
|
|
230
|
+
|
|
231
|
+
```js
|
|
232
|
+
{
|
|
233
|
+
wallets.map((wallet) => <p>{wallet.name}</p>);
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
##### signTransaction(payload)
|
|
238
|
+
|
|
239
|
+
```js
|
|
240
|
+
const onSignTransaction = async () => {
|
|
241
|
+
const payload: Types.TransactionPayload = {
|
|
242
|
+
type: "entry_function_payload",
|
|
243
|
+
function: "0x1::coin::transfer",
|
|
244
|
+
type_arguments: ["0x1::aptos_coin::AptosCoin"],
|
|
245
|
+
arguments: [account?.address, 1], // 1 is in Octas
|
|
246
|
+
};
|
|
247
|
+
const response = await signTransaction(payload);
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
<button onClick={onSignTransaction}>
|
|
251
|
+
Sign transaction
|
|
252
|
+
</button>
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
##### signMessageAndVerify(payload)
|
|
256
|
+
|
|
257
|
+
```js
|
|
258
|
+
const onSignMessageAndVerify = async () => {
|
|
259
|
+
const payload = {
|
|
260
|
+
message: "Hello from Aptos Wallet Adapter",
|
|
261
|
+
nonce: "random_string",
|
|
262
|
+
};
|
|
263
|
+
const response = await signMessageAndVerify(payload);
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
<button onClick={onSignMessageAndVerify}>Sign message and verify</button>;
|
|
267
|
+
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AccountInfo, NetworkInfo, WalletName, WalletInfo, Wallet, Types,
|
|
1
|
+
import { AccountInfo, NetworkInfo, WalletName, WalletInfo, Wallet, InputTransactionData, InputGenerateTransactionOptions, AnyRawTransaction, Types, AccountAuthenticator, InputSubmitTransactionData, PendingTransactionResponse, 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
3
|
import { ReactNode, FC } from 'react';
|
|
4
4
|
|
|
@@ -11,13 +11,11 @@ interface WalletContextState {
|
|
|
11
11
|
disconnect(): void;
|
|
12
12
|
wallet: WalletInfo | null;
|
|
13
13
|
wallets: ReadonlyArray<Wallet>;
|
|
14
|
-
signAndSubmitTransaction
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
signMessage(message: SignMessagePayload): Promise<SignMessageResponse
|
|
14
|
+
signAndSubmitTransaction(transaction: InputTransactionData, options?: InputGenerateTransactionOptions): Promise<any>;
|
|
15
|
+
signTransaction(transactionOrPayload: AnyRawTransaction | Types.TransactionPayload, asFeePayer?: boolean, options?: InputGenerateTransactionOptions): Promise<AccountAuthenticator>;
|
|
16
|
+
submitTransaction(transaction: InputSubmitTransactionData): Promise<PendingTransactionResponse>;
|
|
17
|
+
signMessage(message: SignMessagePayload): Promise<SignMessageResponse>;
|
|
18
18
|
signMessageAndVerify(message: SignMessagePayload): Promise<boolean>;
|
|
19
|
-
submitTransaction(transaction: InputGenerateTransactionData): Promise<any>;
|
|
20
|
-
signMultiAgentTransaction(transaction: TxnBuilderTypes.MultiAgentRawTransaction | TxnBuilderTypes.FeePayerRawTransaction): Promise<any>;
|
|
21
19
|
}
|
|
22
20
|
declare function useWallet(): WalletContextState;
|
|
23
21
|
|
package/dist/index.js
CHANGED
|
@@ -33,11 +33,11 @@ module.exports = __toCommonJS(src_exports);
|
|
|
33
33
|
// src/useWallet.tsx
|
|
34
34
|
var import_wallet_adapter_core = require("@aptos-labs/wallet-adapter-core");
|
|
35
35
|
var import_react = require("react");
|
|
36
|
-
var
|
|
36
|
+
var DEFAULT_CONTEXT = {
|
|
37
37
|
connected: false
|
|
38
38
|
};
|
|
39
39
|
var WalletContext = (0, import_react.createContext)(
|
|
40
|
-
|
|
40
|
+
DEFAULT_CONTEXT
|
|
41
41
|
);
|
|
42
42
|
function useWallet() {
|
|
43
43
|
const context = (0, import_react.useContext)(WalletContext);
|
|
@@ -77,8 +77,7 @@ var AptosWalletAdapterProvider = ({
|
|
|
77
77
|
console.log("connect error", error);
|
|
78
78
|
if (onError)
|
|
79
79
|
onError(error);
|
|
80
|
-
|
|
81
|
-
throw error;
|
|
80
|
+
return Promise.reject(error);
|
|
82
81
|
} finally {
|
|
83
82
|
setIsLoading(false);
|
|
84
83
|
}
|
|
@@ -86,37 +85,19 @@ var AptosWalletAdapterProvider = ({
|
|
|
86
85
|
const disconnect = async () => {
|
|
87
86
|
try {
|
|
88
87
|
await walletCore.disconnect();
|
|
89
|
-
} catch (e) {
|
|
90
|
-
console.log("disconnect error", e);
|
|
91
|
-
if (onError)
|
|
92
|
-
onError(e);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
const signAndSubmitTransaction = async (transaction, options) => {
|
|
96
|
-
try {
|
|
97
|
-
return await walletCore.signAndSubmitTransaction(transaction, options);
|
|
98
88
|
} catch (error) {
|
|
99
89
|
if (onError)
|
|
100
90
|
onError(error);
|
|
101
|
-
|
|
102
|
-
throw error;
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
const signAndSubmitBCSTransaction = async (transaction, options) => {
|
|
106
|
-
try {
|
|
107
|
-
return await walletCore.signAndSubmitBCSTransaction(transaction, options);
|
|
108
|
-
} catch (error) {
|
|
109
|
-
throw error;
|
|
91
|
+
return Promise.reject(error);
|
|
110
92
|
}
|
|
111
93
|
};
|
|
112
|
-
const signTransaction = async (transaction, options) => {
|
|
94
|
+
const signTransaction = async (transaction, asFeePayer, options) => {
|
|
113
95
|
try {
|
|
114
|
-
return await walletCore.signTransaction(transaction, options);
|
|
96
|
+
return await walletCore.signTransaction(transaction, asFeePayer, options);
|
|
115
97
|
} catch (error) {
|
|
116
98
|
if (onError)
|
|
117
99
|
onError(error);
|
|
118
|
-
|
|
119
|
-
throw error;
|
|
100
|
+
return Promise.reject(error);
|
|
120
101
|
}
|
|
121
102
|
};
|
|
122
103
|
const signMessage = async (message) => {
|
|
@@ -125,9 +106,7 @@ var AptosWalletAdapterProvider = ({
|
|
|
125
106
|
} catch (error) {
|
|
126
107
|
if (onError)
|
|
127
108
|
onError(error);
|
|
128
|
-
|
|
129
|
-
throw error;
|
|
130
|
-
return null;
|
|
109
|
+
return Promise.reject(error);
|
|
131
110
|
}
|
|
132
111
|
};
|
|
133
112
|
const signMessageAndVerify = async (message) => {
|
|
@@ -136,31 +115,25 @@ var AptosWalletAdapterProvider = ({
|
|
|
136
115
|
} catch (error) {
|
|
137
116
|
if (onError)
|
|
138
117
|
onError(error);
|
|
139
|
-
|
|
140
|
-
throw error;
|
|
141
|
-
return false;
|
|
118
|
+
return Promise.reject(error);
|
|
142
119
|
}
|
|
143
120
|
};
|
|
144
|
-
const
|
|
121
|
+
const submitTransaction = async (transaction) => {
|
|
145
122
|
try {
|
|
146
|
-
return await walletCore.
|
|
123
|
+
return await walletCore.submitTransaction(transaction);
|
|
147
124
|
} catch (error) {
|
|
148
125
|
if (onError)
|
|
149
126
|
onError(error);
|
|
150
|
-
|
|
151
|
-
throw error;
|
|
152
|
-
return false;
|
|
127
|
+
return Promise.reject(error);
|
|
153
128
|
}
|
|
154
129
|
};
|
|
155
|
-
const
|
|
130
|
+
const signAndSubmitTransaction = async (transaction, options) => {
|
|
156
131
|
try {
|
|
157
|
-
return await walletCore.
|
|
132
|
+
return await walletCore.signAndSubmitTransaction(transaction, options);
|
|
158
133
|
} catch (error) {
|
|
159
134
|
if (onError)
|
|
160
135
|
onError(error);
|
|
161
|
-
|
|
162
|
-
throw error;
|
|
163
|
-
return false;
|
|
136
|
+
return Promise.reject(error);
|
|
164
137
|
}
|
|
165
138
|
};
|
|
166
139
|
(0, import_react2.useEffect)(() => {
|
|
@@ -253,13 +226,11 @@ var AptosWalletAdapterProvider = ({
|
|
|
253
226
|
wallet,
|
|
254
227
|
wallets,
|
|
255
228
|
signAndSubmitTransaction,
|
|
256
|
-
signAndSubmitBCSTransaction,
|
|
257
229
|
signTransaction,
|
|
258
230
|
signMessage,
|
|
259
231
|
signMessageAndVerify,
|
|
260
|
-
|
|
261
|
-
submitTransaction
|
|
262
|
-
isLoading
|
|
232
|
+
isLoading,
|
|
233
|
+
submitTransaction
|
|
263
234
|
},
|
|
264
235
|
children
|
|
265
236
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -7,11 +7,11 @@ import {
|
|
|
7
7
|
isMobile
|
|
8
8
|
} from "@aptos-labs/wallet-adapter-core";
|
|
9
9
|
import { createContext, useContext } from "react";
|
|
10
|
-
var
|
|
10
|
+
var DEFAULT_CONTEXT = {
|
|
11
11
|
connected: false
|
|
12
12
|
};
|
|
13
13
|
var WalletContext = createContext(
|
|
14
|
-
|
|
14
|
+
DEFAULT_CONTEXT
|
|
15
15
|
);
|
|
16
16
|
function useWallet() {
|
|
17
17
|
const context = useContext(WalletContext);
|
|
@@ -56,8 +56,7 @@ var AptosWalletAdapterProvider = ({
|
|
|
56
56
|
console.log("connect error", error);
|
|
57
57
|
if (onError)
|
|
58
58
|
onError(error);
|
|
59
|
-
|
|
60
|
-
throw error;
|
|
59
|
+
return Promise.reject(error);
|
|
61
60
|
} finally {
|
|
62
61
|
setIsLoading(false);
|
|
63
62
|
}
|
|
@@ -65,37 +64,19 @@ var AptosWalletAdapterProvider = ({
|
|
|
65
64
|
const disconnect = async () => {
|
|
66
65
|
try {
|
|
67
66
|
await walletCore.disconnect();
|
|
68
|
-
} catch (e) {
|
|
69
|
-
console.log("disconnect error", e);
|
|
70
|
-
if (onError)
|
|
71
|
-
onError(e);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
const signAndSubmitTransaction = async (transaction, options) => {
|
|
75
|
-
try {
|
|
76
|
-
return await walletCore.signAndSubmitTransaction(transaction, options);
|
|
77
67
|
} catch (error) {
|
|
78
68
|
if (onError)
|
|
79
69
|
onError(error);
|
|
80
|
-
|
|
81
|
-
throw error;
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
const signAndSubmitBCSTransaction = async (transaction, options) => {
|
|
85
|
-
try {
|
|
86
|
-
return await walletCore.signAndSubmitBCSTransaction(transaction, options);
|
|
87
|
-
} catch (error) {
|
|
88
|
-
throw error;
|
|
70
|
+
return Promise.reject(error);
|
|
89
71
|
}
|
|
90
72
|
};
|
|
91
|
-
const signTransaction = async (transaction, options) => {
|
|
73
|
+
const signTransaction = async (transaction, asFeePayer, options) => {
|
|
92
74
|
try {
|
|
93
|
-
return await walletCore.signTransaction(transaction, options);
|
|
75
|
+
return await walletCore.signTransaction(transaction, asFeePayer, options);
|
|
94
76
|
} catch (error) {
|
|
95
77
|
if (onError)
|
|
96
78
|
onError(error);
|
|
97
|
-
|
|
98
|
-
throw error;
|
|
79
|
+
return Promise.reject(error);
|
|
99
80
|
}
|
|
100
81
|
};
|
|
101
82
|
const signMessage = async (message) => {
|
|
@@ -104,9 +85,7 @@ var AptosWalletAdapterProvider = ({
|
|
|
104
85
|
} catch (error) {
|
|
105
86
|
if (onError)
|
|
106
87
|
onError(error);
|
|
107
|
-
|
|
108
|
-
throw error;
|
|
109
|
-
return null;
|
|
88
|
+
return Promise.reject(error);
|
|
110
89
|
}
|
|
111
90
|
};
|
|
112
91
|
const signMessageAndVerify = async (message) => {
|
|
@@ -115,31 +94,25 @@ var AptosWalletAdapterProvider = ({
|
|
|
115
94
|
} catch (error) {
|
|
116
95
|
if (onError)
|
|
117
96
|
onError(error);
|
|
118
|
-
|
|
119
|
-
throw error;
|
|
120
|
-
return false;
|
|
97
|
+
return Promise.reject(error);
|
|
121
98
|
}
|
|
122
99
|
};
|
|
123
|
-
const
|
|
100
|
+
const submitTransaction = async (transaction) => {
|
|
124
101
|
try {
|
|
125
|
-
return await walletCore.
|
|
102
|
+
return await walletCore.submitTransaction(transaction);
|
|
126
103
|
} catch (error) {
|
|
127
104
|
if (onError)
|
|
128
105
|
onError(error);
|
|
129
|
-
|
|
130
|
-
throw error;
|
|
131
|
-
return false;
|
|
106
|
+
return Promise.reject(error);
|
|
132
107
|
}
|
|
133
108
|
};
|
|
134
|
-
const
|
|
109
|
+
const signAndSubmitTransaction = async (transaction, options) => {
|
|
135
110
|
try {
|
|
136
|
-
return await walletCore.
|
|
111
|
+
return await walletCore.signAndSubmitTransaction(transaction, options);
|
|
137
112
|
} catch (error) {
|
|
138
113
|
if (onError)
|
|
139
114
|
onError(error);
|
|
140
|
-
|
|
141
|
-
throw error;
|
|
142
|
-
return false;
|
|
115
|
+
return Promise.reject(error);
|
|
143
116
|
}
|
|
144
117
|
};
|
|
145
118
|
useEffect(() => {
|
|
@@ -232,13 +205,11 @@ var AptosWalletAdapterProvider = ({
|
|
|
232
205
|
wallet,
|
|
233
206
|
wallets,
|
|
234
207
|
signAndSubmitTransaction,
|
|
235
|
-
signAndSubmitBCSTransaction,
|
|
236
208
|
signTransaction,
|
|
237
209
|
signMessage,
|
|
238
210
|
signMessageAndVerify,
|
|
239
|
-
|
|
240
|
-
submitTransaction
|
|
241
|
-
isLoading
|
|
211
|
+
isLoading,
|
|
212
|
+
submitTransaction
|
|
242
213
|
},
|
|
243
214
|
children
|
|
244
215
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aptos-labs/wallet-adapter-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Aptos Wallet Adapter React Provider",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@aptos-labs/wallet-adapter-tsconfig": "0.0.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@aptos-labs/wallet-adapter-core": "
|
|
40
|
+
"@aptos-labs/wallet-adapter-core": "3.1.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"react": "^18"
|
package/src/WalletProvider.tsx
CHANGED
|
@@ -13,11 +13,15 @@ import type {
|
|
|
13
13
|
SignMessagePayload,
|
|
14
14
|
Wallet,
|
|
15
15
|
WalletInfo,
|
|
16
|
+
InputGenerateTransactionOptions,
|
|
17
|
+
AnyRawTransaction,
|
|
18
|
+
InputSubmitTransactionData,
|
|
19
|
+
AccountAuthenticator,
|
|
20
|
+
PendingTransactionResponse,
|
|
21
|
+
SignMessageResponse,
|
|
16
22
|
WalletName,
|
|
17
|
-
TransactionOptions,
|
|
18
|
-
TxnBuilderTypes,
|
|
19
23
|
Types,
|
|
20
|
-
|
|
24
|
+
InputTransactionData,
|
|
21
25
|
} from "@aptos-labs/wallet-adapter-core";
|
|
22
26
|
import { WalletCore } from "@aptos-labs/wallet-adapter-core";
|
|
23
27
|
|
|
@@ -65,7 +69,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
65
69
|
} catch (error: any) {
|
|
66
70
|
console.log("connect error", error);
|
|
67
71
|
if (onError) onError(error);
|
|
68
|
-
|
|
72
|
+
return Promise.reject(error);
|
|
69
73
|
} finally {
|
|
70
74
|
setIsLoading(false);
|
|
71
75
|
}
|
|
@@ -74,90 +78,69 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
74
78
|
const disconnect = async () => {
|
|
75
79
|
try {
|
|
76
80
|
await walletCore.disconnect();
|
|
77
|
-
} catch (
|
|
78
|
-
console.log("disconnect error", e);
|
|
79
|
-
if (onError) onError(e);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const signAndSubmitTransaction = async (
|
|
84
|
-
transaction: Types.TransactionPayload,
|
|
85
|
-
options?: TransactionOptions
|
|
86
|
-
) => {
|
|
87
|
-
try {
|
|
88
|
-
return await walletCore.signAndSubmitTransaction(transaction, options);
|
|
89
|
-
} catch (error: any) {
|
|
81
|
+
} catch (error) {
|
|
90
82
|
if (onError) onError(error);
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const signAndSubmitBCSTransaction = async (
|
|
96
|
-
transaction: TxnBuilderTypes.TransactionPayload,
|
|
97
|
-
options?: TransactionOptions
|
|
98
|
-
) => {
|
|
99
|
-
try {
|
|
100
|
-
return await walletCore.signAndSubmitBCSTransaction(transaction, options);
|
|
101
|
-
} catch (error: any) {
|
|
102
|
-
throw error;
|
|
83
|
+
return Promise.reject(error);
|
|
103
84
|
}
|
|
104
85
|
};
|
|
105
86
|
|
|
106
87
|
const signTransaction = async (
|
|
107
|
-
transaction: Types.TransactionPayload,
|
|
108
|
-
|
|
109
|
-
|
|
88
|
+
transaction: AnyRawTransaction | Types.TransactionPayload,
|
|
89
|
+
asFeePayer?: boolean,
|
|
90
|
+
options?: InputGenerateTransactionOptions
|
|
91
|
+
): Promise<AccountAuthenticator> => {
|
|
110
92
|
try {
|
|
111
|
-
return await walletCore.signTransaction(transaction, options);
|
|
93
|
+
return await walletCore.signTransaction(transaction, asFeePayer, options);
|
|
112
94
|
} catch (error: any) {
|
|
113
95
|
if (onError) onError(error);
|
|
114
|
-
|
|
96
|
+
return Promise.reject(error);
|
|
115
97
|
}
|
|
116
98
|
};
|
|
117
99
|
|
|
118
|
-
const signMessage = async (
|
|
100
|
+
const signMessage = async (
|
|
101
|
+
message: SignMessagePayload
|
|
102
|
+
): Promise<SignMessageResponse> => {
|
|
119
103
|
try {
|
|
120
104
|
return await walletCore.signMessage(message);
|
|
121
105
|
} catch (error: any) {
|
|
122
106
|
if (onError) onError(error);
|
|
123
|
-
|
|
124
|
-
return null;
|
|
107
|
+
return Promise.reject(error);
|
|
125
108
|
}
|
|
126
109
|
};
|
|
127
110
|
|
|
128
|
-
const signMessageAndVerify = async (
|
|
111
|
+
const signMessageAndVerify = async (
|
|
112
|
+
message: SignMessagePayload
|
|
113
|
+
): Promise<boolean> => {
|
|
129
114
|
try {
|
|
130
115
|
return await walletCore.signMessageAndVerify(message);
|
|
131
116
|
} catch (error: any) {
|
|
132
117
|
if (onError) onError(error);
|
|
133
|
-
|
|
134
|
-
return false;
|
|
118
|
+
return Promise.reject(error);
|
|
135
119
|
}
|
|
136
120
|
};
|
|
137
121
|
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
) => {
|
|
122
|
+
const submitTransaction = async (
|
|
123
|
+
transaction: InputSubmitTransactionData
|
|
124
|
+
): Promise<PendingTransactionResponse> => {
|
|
141
125
|
try {
|
|
142
|
-
return await walletCore.
|
|
126
|
+
return await walletCore.submitTransaction(transaction);
|
|
143
127
|
} catch (error: any) {
|
|
144
128
|
if (onError) onError(error);
|
|
145
|
-
|
|
146
|
-
return false;
|
|
129
|
+
return Promise.reject(error);
|
|
147
130
|
}
|
|
148
|
-
}
|
|
131
|
+
};
|
|
149
132
|
|
|
150
|
-
const
|
|
151
|
-
|
|
133
|
+
const signAndSubmitTransaction = async (
|
|
134
|
+
transaction: InputTransactionData,
|
|
135
|
+
options?: InputGenerateTransactionOptions
|
|
152
136
|
) => {
|
|
153
137
|
try {
|
|
154
|
-
return await walletCore.
|
|
138
|
+
return await walletCore.signAndSubmitTransaction(transaction, options);
|
|
155
139
|
} catch (error: any) {
|
|
156
140
|
if (onError) onError(error);
|
|
157
|
-
|
|
158
|
-
return false;
|
|
141
|
+
return Promise.reject(error);
|
|
159
142
|
}
|
|
160
|
-
}
|
|
143
|
+
};
|
|
161
144
|
|
|
162
145
|
useEffect(() => {
|
|
163
146
|
if (autoConnect) {
|
|
@@ -261,13 +244,11 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
261
244
|
wallet,
|
|
262
245
|
wallets,
|
|
263
246
|
signAndSubmitTransaction,
|
|
264
|
-
signAndSubmitBCSTransaction,
|
|
265
247
|
signTransaction,
|
|
266
248
|
signMessage,
|
|
267
249
|
signMessageAndVerify,
|
|
268
|
-
signMultiAgentTransaction,
|
|
269
|
-
submitTransaction,
|
|
270
250
|
isLoading,
|
|
251
|
+
submitTransaction,
|
|
271
252
|
}}
|
|
272
253
|
>
|
|
273
254
|
{children}
|
package/src/index.tsx
CHANGED
package/src/useWallet.tsx
CHANGED
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
AccountInfo,
|
|
3
3
|
NetworkInfo,
|
|
4
4
|
WalletInfo,
|
|
5
|
-
WalletName,
|
|
6
5
|
SignMessagePayload,
|
|
7
6
|
SignMessageResponse,
|
|
8
7
|
Wallet,
|
|
@@ -11,20 +10,24 @@ import {
|
|
|
11
10
|
isInAppBrowser,
|
|
12
11
|
isRedirectable,
|
|
13
12
|
isMobile,
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
InputGenerateTransactionOptions,
|
|
14
|
+
AnyRawTransaction,
|
|
15
|
+
InputTransactionData,
|
|
16
|
+
InputSubmitTransactionData,
|
|
17
|
+
PendingTransactionResponse,
|
|
18
|
+
AccountAuthenticator,
|
|
16
19
|
Types,
|
|
17
|
-
|
|
20
|
+
WalletName,
|
|
18
21
|
} from "@aptos-labs/wallet-adapter-core";
|
|
19
22
|
import { createContext, useContext } from "react";
|
|
20
23
|
|
|
21
|
-
export type {
|
|
24
|
+
export type { Wallet, WalletName };
|
|
22
25
|
export {
|
|
23
26
|
WalletReadyState,
|
|
24
|
-
NetworkName,
|
|
25
27
|
isInAppBrowser,
|
|
26
28
|
isRedirectable,
|
|
27
29
|
isMobile,
|
|
30
|
+
NetworkName,
|
|
28
31
|
};
|
|
29
32
|
|
|
30
33
|
export interface WalletContextState {
|
|
@@ -36,32 +39,28 @@ export interface WalletContextState {
|
|
|
36
39
|
disconnect(): void;
|
|
37
40
|
wallet: WalletInfo | null;
|
|
38
41
|
wallets: ReadonlyArray<Wallet>;
|
|
39
|
-
signAndSubmitTransaction
|
|
40
|
-
transaction:
|
|
41
|
-
options?:
|
|
42
|
+
signAndSubmitTransaction(
|
|
43
|
+
transaction: InputTransactionData,
|
|
44
|
+
options?: InputGenerateTransactionOptions
|
|
42
45
|
): Promise<any>;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
): Promise<
|
|
51
|
-
signMessage(message: SignMessagePayload): Promise<SignMessageResponse
|
|
46
|
+
signTransaction(
|
|
47
|
+
transactionOrPayload: AnyRawTransaction | Types.TransactionPayload,
|
|
48
|
+
asFeePayer?: boolean,
|
|
49
|
+
options?: InputGenerateTransactionOptions
|
|
50
|
+
): Promise<AccountAuthenticator>;
|
|
51
|
+
submitTransaction(
|
|
52
|
+
transaction: InputSubmitTransactionData
|
|
53
|
+
): Promise<PendingTransactionResponse>;
|
|
54
|
+
signMessage(message: SignMessagePayload): Promise<SignMessageResponse>;
|
|
52
55
|
signMessageAndVerify(message: SignMessagePayload): Promise<boolean>;
|
|
53
|
-
submitTransaction(transaction: InputGenerateTransactionData): Promise<any>;
|
|
54
|
-
signMultiAgentTransaction(
|
|
55
|
-
transaction: TxnBuilderTypes.MultiAgentRawTransaction | TxnBuilderTypes.FeePayerRawTransaction,
|
|
56
|
-
): Promise<any>;
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
const
|
|
58
|
+
const DEFAULT_CONTEXT = {
|
|
60
59
|
connected: false,
|
|
61
60
|
};
|
|
62
61
|
|
|
63
62
|
export const WalletContext = createContext<WalletContextState>(
|
|
64
|
-
|
|
63
|
+
DEFAULT_CONTEXT as WalletContextState
|
|
65
64
|
);
|
|
66
65
|
|
|
67
66
|
export function useWallet(): WalletContextState {
|