@aptos-labs/wallet-adapter-react 1.3.1 → 1.4.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 +21 -0
- package/README.md +63 -35
- package/dist/index.d.ts +3 -2
- package/dist/index.js +24 -0
- package/dist/index.mjs +24 -0
- package/package.json +4 -3
- package/src/WalletProvider.tsx +29 -2
- package/src/useWallet.tsx +7 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @aptos-labs/wallet-adapter-react
|
|
2
2
|
|
|
3
|
+
## 1.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 7acfa69: Adding support for the new Typescript SDK in the package `@aptos-labs/ts-sdk`. The wallet adapter now supports submitting a basic transaction with the new SDK types.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- dd6e1ed: Moves dependencies to peer dependencies as needed
|
|
12
|
+
- Updated dependencies [7acfa69]
|
|
13
|
+
- Updated dependencies [dd6e1ed]
|
|
14
|
+
- @aptos-labs/wallet-adapter-core@2.6.0
|
|
15
|
+
|
|
16
|
+
## 1.3.2
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 7e314e5: Update aptos dependency
|
|
21
|
+
- Updated dependencies [7e314e5]
|
|
22
|
+
- @aptos-labs/wallet-adapter-core@2.5.1
|
|
23
|
+
|
|
3
24
|
## 1.3.1
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
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, InputGenerateTransactionData } 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 {
|
|
@@ -17,6 +16,8 @@ interface WalletContextState {
|
|
|
17
16
|
signTransaction<T extends Types.TransactionPayload>(transaction: T, options?: TransactionOptions): Promise<any>;
|
|
18
17
|
signMessage(message: SignMessagePayload): Promise<SignMessageResponse | null>;
|
|
19
18
|
signMessageAndVerify(message: SignMessagePayload): Promise<boolean>;
|
|
19
|
+
submitTransaction(transaction: InputGenerateTransactionData): Promise<any>;
|
|
20
|
+
signMultiAgentTransaction(transaction: TxnBuilderTypes.MultiAgentRawTransaction | TxnBuilderTypes.FeePayerRawTransaction): Promise<any>;
|
|
20
21
|
}
|
|
21
22
|
declare function useWallet(): WalletContextState;
|
|
22
23
|
|
package/dist/index.js
CHANGED
|
@@ -141,6 +141,28 @@ var AptosWalletAdapterProvider = ({
|
|
|
141
141
|
return false;
|
|
142
142
|
}
|
|
143
143
|
};
|
|
144
|
+
const signMultiAgentTransaction = async (transaction) => {
|
|
145
|
+
try {
|
|
146
|
+
return await walletCore.signMultiAgentTransaction(transaction);
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (onError)
|
|
149
|
+
onError(error);
|
|
150
|
+
else
|
|
151
|
+
throw error;
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
const submitTransaction = async (transaction) => {
|
|
156
|
+
try {
|
|
157
|
+
return await walletCore.submitTransaction(transaction);
|
|
158
|
+
} catch (error) {
|
|
159
|
+
if (onError)
|
|
160
|
+
onError(error);
|
|
161
|
+
else
|
|
162
|
+
throw error;
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
144
166
|
(0, import_react2.useEffect)(() => {
|
|
145
167
|
if (autoConnect) {
|
|
146
168
|
if (localStorage.getItem("AptosWalletName")) {
|
|
@@ -235,6 +257,8 @@ var AptosWalletAdapterProvider = ({
|
|
|
235
257
|
signTransaction,
|
|
236
258
|
signMessage,
|
|
237
259
|
signMessageAndVerify,
|
|
260
|
+
signMultiAgentTransaction,
|
|
261
|
+
submitTransaction,
|
|
238
262
|
isLoading
|
|
239
263
|
},
|
|
240
264
|
children
|
package/dist/index.mjs
CHANGED
|
@@ -120,6 +120,28 @@ var AptosWalletAdapterProvider = ({
|
|
|
120
120
|
return false;
|
|
121
121
|
}
|
|
122
122
|
};
|
|
123
|
+
const signMultiAgentTransaction = async (transaction) => {
|
|
124
|
+
try {
|
|
125
|
+
return await walletCore.signMultiAgentTransaction(transaction);
|
|
126
|
+
} catch (error) {
|
|
127
|
+
if (onError)
|
|
128
|
+
onError(error);
|
|
129
|
+
else
|
|
130
|
+
throw error;
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
const submitTransaction = async (transaction) => {
|
|
135
|
+
try {
|
|
136
|
+
return await walletCore.submitTransaction(transaction);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
if (onError)
|
|
139
|
+
onError(error);
|
|
140
|
+
else
|
|
141
|
+
throw error;
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
123
145
|
useEffect(() => {
|
|
124
146
|
if (autoConnect) {
|
|
125
147
|
if (localStorage.getItem("AptosWalletName")) {
|
|
@@ -214,6 +236,8 @@ var AptosWalletAdapterProvider = ({
|
|
|
214
236
|
signTransaction,
|
|
215
237
|
signMessage,
|
|
216
238
|
signMessageAndVerify,
|
|
239
|
+
signMultiAgentTransaction,
|
|
240
|
+
submitTransaction,
|
|
217
241
|
isLoading
|
|
218
242
|
},
|
|
219
243
|
children
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aptos-labs/wallet-adapter-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Aptos Wallet Adapter React Provider",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -37,8 +37,9 @@
|
|
|
37
37
|
"@aptos-labs/wallet-adapter-tsconfig": "0.0.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@aptos-labs/wallet-adapter-core": "2.
|
|
41
|
-
|
|
40
|
+
"@aptos-labs/wallet-adapter-core": "2.6.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
42
43
|
"react": "^18"
|
|
43
44
|
},
|
|
44
45
|
"scripts": {
|
package/src/WalletProvider.tsx
CHANGED
|
@@ -15,11 +15,12 @@ import type {
|
|
|
15
15
|
WalletInfo,
|
|
16
16
|
WalletName,
|
|
17
17
|
TransactionOptions,
|
|
18
|
+
TxnBuilderTypes,
|
|
19
|
+
Types,
|
|
20
|
+
InputGenerateTransactionData,
|
|
18
21
|
} from "@aptos-labs/wallet-adapter-core";
|
|
19
22
|
import { WalletCore } from "@aptos-labs/wallet-adapter-core";
|
|
20
23
|
|
|
21
|
-
import { TxnBuilderTypes, Types } from "aptos";
|
|
22
|
-
|
|
23
24
|
export interface AptosWalletProviderProps {
|
|
24
25
|
children: ReactNode;
|
|
25
26
|
plugins: ReadonlyArray<Wallet>;
|
|
@@ -134,6 +135,30 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
134
135
|
}
|
|
135
136
|
};
|
|
136
137
|
|
|
138
|
+
const signMultiAgentTransaction = async (
|
|
139
|
+
transaction: TxnBuilderTypes.MultiAgentRawTransaction | TxnBuilderTypes.FeePayerRawTransaction,
|
|
140
|
+
) => {
|
|
141
|
+
try {
|
|
142
|
+
return await walletCore.signMultiAgentTransaction(transaction);
|
|
143
|
+
} catch (error: any) {
|
|
144
|
+
if (onError) onError(error);
|
|
145
|
+
else throw error;
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const submitTransaction = async (
|
|
151
|
+
transaction: InputGenerateTransactionData,
|
|
152
|
+
) => {
|
|
153
|
+
try {
|
|
154
|
+
return await walletCore.submitTransaction(transaction);
|
|
155
|
+
} catch (error: any) {
|
|
156
|
+
if (onError) onError(error);
|
|
157
|
+
else throw error;
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
137
162
|
useEffect(() => {
|
|
138
163
|
if (autoConnect) {
|
|
139
164
|
if (localStorage.getItem("AptosWalletName")) {
|
|
@@ -240,6 +265,8 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
240
265
|
signTransaction,
|
|
241
266
|
signMessage,
|
|
242
267
|
signMessageAndVerify,
|
|
268
|
+
signMultiAgentTransaction,
|
|
269
|
+
submitTransaction,
|
|
243
270
|
isLoading,
|
|
244
271
|
}}
|
|
245
272
|
>
|
package/src/useWallet.tsx
CHANGED
|
@@ -12,9 +12,11 @@ import {
|
|
|
12
12
|
isRedirectable,
|
|
13
13
|
isMobile,
|
|
14
14
|
TransactionOptions,
|
|
15
|
+
TxnBuilderTypes,
|
|
16
|
+
Types,
|
|
17
|
+
InputGenerateTransactionData,
|
|
15
18
|
} from "@aptos-labs/wallet-adapter-core";
|
|
16
19
|
import { createContext, useContext } from "react";
|
|
17
|
-
import { TxnBuilderTypes, Types } from "aptos";
|
|
18
20
|
|
|
19
21
|
export type { WalletName, Wallet };
|
|
20
22
|
export {
|
|
@@ -48,6 +50,10 @@ export interface WalletContextState {
|
|
|
48
50
|
): Promise<any>;
|
|
49
51
|
signMessage(message: SignMessagePayload): Promise<SignMessageResponse | null>;
|
|
50
52
|
signMessageAndVerify(message: SignMessagePayload): Promise<boolean>;
|
|
53
|
+
submitTransaction(transaction: InputGenerateTransactionData): Promise<any>;
|
|
54
|
+
signMultiAgentTransaction(
|
|
55
|
+
transaction: TxnBuilderTypes.MultiAgentRawTransaction | TxnBuilderTypes.FeePayerRawTransaction,
|
|
56
|
+
): Promise<any>;
|
|
51
57
|
}
|
|
52
58
|
|
|
53
59
|
const DEFAULT_COUNTEXT = {
|