@aptos-labs/wallet-adapter-react 1.0.3 → 1.0.5
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 +15 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +12 -15
- package/dist/index.mjs +12 -15
- package/package.json +11 -11
- package/src/WalletProvider.tsx +19 -17
- package/src/useWallet.tsx +5 -1
- package/dist/index.global.js +0 -160
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @aptos-labs/wallet-adapter-react
|
|
2
2
|
|
|
3
|
+
## 1.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 56a3f9f: BCS transaction support in react provider package
|
|
8
|
+
|
|
9
|
+
## 1.0.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 8dea640: Fix wallet adapter auto reconnect on page refresh
|
|
14
|
+
- Updated dependencies [50968c4]
|
|
15
|
+
- Updated dependencies [8dea640]
|
|
16
|
+
- @aptos-labs/wallet-adapter-core@2.1.0
|
|
17
|
+
|
|
3
18
|
## 1.0.3
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AccountInfo, NetworkInfo, WalletName, WalletInfo, Wallet, SignMessagePayload, SignMessageResponse } from '@aptos-labs/wallet-adapter-core';
|
|
2
2
|
export { NetworkName, WalletName, WalletReadyState } from '@aptos-labs/wallet-adapter-core';
|
|
3
|
-
import { Types } from 'aptos';
|
|
3
|
+
import { Types, TxnBuilderTypes } from 'aptos';
|
|
4
4
|
import { ReactNode, FC } from 'react';
|
|
5
5
|
|
|
6
6
|
interface WalletContextState {
|
|
@@ -13,6 +13,7 @@ interface WalletContextState {
|
|
|
13
13
|
wallet: WalletInfo | null;
|
|
14
14
|
wallets: Wallet[];
|
|
15
15
|
signAndSubmitTransaction<T extends Types.TransactionPayload, V>(transaction: T, options?: V): Promise<any>;
|
|
16
|
+
signAndSubmitBCSTransaction<T extends TxnBuilderTypes.TransactionPayload, V>(transaction: T, options?: V): Promise<any>;
|
|
16
17
|
signTransaction<T extends Types.TransactionPayload, V>(transaction: T, options?: V): Promise<any>;
|
|
17
18
|
signMessage(message: SignMessagePayload): Promise<SignMessageResponse | null>;
|
|
18
19
|
signMessageAndVerify(message: SignMessagePayload): Promise<boolean>;
|
package/dist/index.js
CHANGED
|
@@ -87,6 +87,13 @@ var AptosWalletAdapterProvider = ({
|
|
|
87
87
|
throw error;
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
|
+
const signAndSubmitBCSTransaction = async (transaction) => {
|
|
91
|
+
try {
|
|
92
|
+
return await walletCore.signAndSubmitBCSTransaction(transaction);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
90
97
|
const signTransaction = async (transaction) => {
|
|
91
98
|
try {
|
|
92
99
|
return await walletCore.signTransaction(transaction);
|
|
@@ -114,13 +121,13 @@ var AptosWalletAdapterProvider = ({
|
|
|
114
121
|
connect(localStorage.getItem("AptosWalletName"));
|
|
115
122
|
}
|
|
116
123
|
}
|
|
117
|
-
},
|
|
124
|
+
}, wallets);
|
|
118
125
|
(0, import_react2.useEffect)(() => {
|
|
119
126
|
if (connected) {
|
|
120
127
|
walletCore.onAccountChange();
|
|
121
128
|
walletCore.onNetworkChange();
|
|
122
129
|
}
|
|
123
|
-
}, [wallets, connected]);
|
|
130
|
+
}, [...wallets, connected]);
|
|
124
131
|
const handleConnect = () => {
|
|
125
132
|
setState((state) => {
|
|
126
133
|
return {
|
|
@@ -170,18 +177,7 @@ var AptosWalletAdapterProvider = ({
|
|
|
170
177
|
});
|
|
171
178
|
}, [connected]);
|
|
172
179
|
const handleReadyStateChange = (wallet2) => {
|
|
173
|
-
setWallets((
|
|
174
|
-
const index = prevWallets.findIndex(
|
|
175
|
-
(currWallet) => currWallet === wallet2
|
|
176
|
-
);
|
|
177
|
-
if (index === -1)
|
|
178
|
-
return prevWallets;
|
|
179
|
-
return [
|
|
180
|
-
...prevWallets.slice(0, index),
|
|
181
|
-
wallet2,
|
|
182
|
-
...prevWallets.slice(index + 1)
|
|
183
|
-
];
|
|
184
|
-
});
|
|
180
|
+
setWallets((wallets2) => [...wallets2]);
|
|
185
181
|
};
|
|
186
182
|
(0, import_react2.useEffect)(() => {
|
|
187
183
|
walletCore.on("connect", handleConnect);
|
|
@@ -196,7 +192,7 @@ var AptosWalletAdapterProvider = ({
|
|
|
196
192
|
walletCore.off("networkChange", handleNetworkChange);
|
|
197
193
|
walletCore.off("readyStateChange", handleReadyStateChange);
|
|
198
194
|
};
|
|
199
|
-
}, [wallets, connected]);
|
|
195
|
+
}, [...wallets, connected]);
|
|
200
196
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WalletContext.Provider, {
|
|
201
197
|
value: {
|
|
202
198
|
connect,
|
|
@@ -207,6 +203,7 @@ var AptosWalletAdapterProvider = ({
|
|
|
207
203
|
wallet,
|
|
208
204
|
wallets,
|
|
209
205
|
signAndSubmitTransaction,
|
|
206
|
+
signAndSubmitBCSTransaction,
|
|
210
207
|
signTransaction,
|
|
211
208
|
signMessage,
|
|
212
209
|
signMessageAndVerify,
|
package/dist/index.mjs
CHANGED
|
@@ -66,6 +66,13 @@ var AptosWalletAdapterProvider = ({
|
|
|
66
66
|
throw error;
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
|
+
const signAndSubmitBCSTransaction = async (transaction) => {
|
|
70
|
+
try {
|
|
71
|
+
return await walletCore.signAndSubmitBCSTransaction(transaction);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
69
76
|
const signTransaction = async (transaction) => {
|
|
70
77
|
try {
|
|
71
78
|
return await walletCore.signTransaction(transaction);
|
|
@@ -93,13 +100,13 @@ var AptosWalletAdapterProvider = ({
|
|
|
93
100
|
connect(localStorage.getItem("AptosWalletName"));
|
|
94
101
|
}
|
|
95
102
|
}
|
|
96
|
-
},
|
|
103
|
+
}, wallets);
|
|
97
104
|
useEffect(() => {
|
|
98
105
|
if (connected) {
|
|
99
106
|
walletCore.onAccountChange();
|
|
100
107
|
walletCore.onNetworkChange();
|
|
101
108
|
}
|
|
102
|
-
}, [wallets, connected]);
|
|
109
|
+
}, [...wallets, connected]);
|
|
103
110
|
const handleConnect = () => {
|
|
104
111
|
setState((state) => {
|
|
105
112
|
return {
|
|
@@ -149,18 +156,7 @@ var AptosWalletAdapterProvider = ({
|
|
|
149
156
|
});
|
|
150
157
|
}, [connected]);
|
|
151
158
|
const handleReadyStateChange = (wallet2) => {
|
|
152
|
-
setWallets((
|
|
153
|
-
const index = prevWallets.findIndex(
|
|
154
|
-
(currWallet) => currWallet === wallet2
|
|
155
|
-
);
|
|
156
|
-
if (index === -1)
|
|
157
|
-
return prevWallets;
|
|
158
|
-
return [
|
|
159
|
-
...prevWallets.slice(0, index),
|
|
160
|
-
wallet2,
|
|
161
|
-
...prevWallets.slice(index + 1)
|
|
162
|
-
];
|
|
163
|
-
});
|
|
159
|
+
setWallets((wallets2) => [...wallets2]);
|
|
164
160
|
};
|
|
165
161
|
useEffect(() => {
|
|
166
162
|
walletCore.on("connect", handleConnect);
|
|
@@ -175,7 +171,7 @@ var AptosWalletAdapterProvider = ({
|
|
|
175
171
|
walletCore.off("networkChange", handleNetworkChange);
|
|
176
172
|
walletCore.off("readyStateChange", handleReadyStateChange);
|
|
177
173
|
};
|
|
178
|
-
}, [wallets, connected]);
|
|
174
|
+
}, [...wallets, connected]);
|
|
179
175
|
return /* @__PURE__ */ jsx(WalletContext.Provider, {
|
|
180
176
|
value: {
|
|
181
177
|
connect,
|
|
@@ -186,6 +182,7 @@ var AptosWalletAdapterProvider = ({
|
|
|
186
182
|
wallet,
|
|
187
183
|
wallets,
|
|
188
184
|
signAndSubmitTransaction,
|
|
185
|
+
signAndSubmitBCSTransaction,
|
|
189
186
|
signTransaction,
|
|
190
187
|
signMessage,
|
|
191
188
|
signMessageAndVerify,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aptos-labs/wallet-adapter-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Aptos Wallet Adapter React Provider",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -28,23 +28,23 @@
|
|
|
28
28
|
"Wallet Adapter Provider",
|
|
29
29
|
"React"
|
|
30
30
|
],
|
|
31
|
-
"scripts": {
|
|
32
|
-
"build": "tsup src/index.tsx --format esm,cjs --dts --external react",
|
|
33
|
-
"dev": "tsup src/index.tsx --format esm,cjs --watch --dts --external react",
|
|
34
|
-
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
35
|
-
"lint": "TIMING=1 eslint \"src/**/*.ts*\""
|
|
36
|
-
},
|
|
37
31
|
"devDependencies": {
|
|
38
|
-
"@aptos-labs/wallet-adapter-tsconfig": "workspace:*",
|
|
39
32
|
"@types/react": "^18.0.17",
|
|
40
33
|
"@types/react-dom": "^18.0.6",
|
|
41
34
|
"eslint": "^8.15.0",
|
|
42
35
|
"typescript": "^4.5.3",
|
|
43
|
-
"tsup": "^5.10.1"
|
|
36
|
+
"tsup": "^5.10.1",
|
|
37
|
+
"@aptos-labs/wallet-adapter-tsconfig": "0.0.0"
|
|
44
38
|
},
|
|
45
39
|
"dependencies": {
|
|
46
|
-
"@aptos-labs/wallet-adapter-core": "2.0
|
|
40
|
+
"@aptos-labs/wallet-adapter-core": "2.1.0",
|
|
47
41
|
"aptos": "^1.3.17",
|
|
48
42
|
"react": "^18"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup src/index.tsx --format esm,cjs --dts --external react",
|
|
46
|
+
"dev": "tsup src/index.tsx --format esm,cjs --watch --dts --external react",
|
|
47
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
48
|
+
"lint": "TIMING=1 eslint \"src/**/*.ts*\""
|
|
49
49
|
}
|
|
50
|
-
}
|
|
50
|
+
}
|
package/src/WalletProvider.tsx
CHANGED
|
@@ -17,7 +17,7 @@ import type {
|
|
|
17
17
|
} from "@aptos-labs/wallet-adapter-core";
|
|
18
18
|
import { WalletCore } from "@aptos-labs/wallet-adapter-core";
|
|
19
19
|
|
|
20
|
-
import { Types } from "aptos";
|
|
20
|
+
import { TxnBuilderTypes, Types } from "aptos";
|
|
21
21
|
|
|
22
22
|
export interface AptosWalletProviderProps {
|
|
23
23
|
children: ReactNode;
|
|
@@ -79,6 +79,16 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
+
const signAndSubmitBCSTransaction = async (
|
|
83
|
+
transaction: TxnBuilderTypes.TransactionPayload
|
|
84
|
+
) => {
|
|
85
|
+
try {
|
|
86
|
+
return await walletCore.signAndSubmitBCSTransaction(transaction);
|
|
87
|
+
} catch (error: any) {
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
82
92
|
const signTransaction = async (transaction: Types.TransactionPayload) => {
|
|
83
93
|
try {
|
|
84
94
|
return await walletCore.signTransaction(transaction);
|
|
@@ -109,14 +119,14 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
109
119
|
connect(localStorage.getItem("AptosWalletName") as WalletName);
|
|
110
120
|
}
|
|
111
121
|
}
|
|
112
|
-
},
|
|
122
|
+
}, wallets);
|
|
113
123
|
|
|
114
124
|
useEffect(() => {
|
|
115
125
|
if (connected) {
|
|
116
126
|
walletCore.onAccountChange();
|
|
117
127
|
walletCore.onNetworkChange();
|
|
118
128
|
}
|
|
119
|
-
}, [wallets, connected]);
|
|
129
|
+
}, [...wallets, connected]);
|
|
120
130
|
|
|
121
131
|
// Handle the adapter's connect event
|
|
122
132
|
const handleConnect = () => {
|
|
@@ -169,20 +179,11 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
169
179
|
});
|
|
170
180
|
}, [connected]);
|
|
171
181
|
|
|
172
|
-
//
|
|
182
|
+
// Whenever the readyState of any supported wallet changes we produce a new wallets state array
|
|
183
|
+
// which in turn causes consumers of the `useWallet` hook to re-render.
|
|
184
|
+
// See https://github.com/aptos-labs/aptos-wallet-adapter/pull/129#issuecomment-1519026572 for reasoning.
|
|
173
185
|
const handleReadyStateChange = (wallet: Wallet) => {
|
|
174
|
-
setWallets((
|
|
175
|
-
const index = prevWallets.findIndex(
|
|
176
|
-
(currWallet) => currWallet === wallet
|
|
177
|
-
);
|
|
178
|
-
if (index === -1) return prevWallets;
|
|
179
|
-
|
|
180
|
-
return [
|
|
181
|
-
...prevWallets.slice(0, index),
|
|
182
|
-
wallet,
|
|
183
|
-
...prevWallets.slice(index + 1),
|
|
184
|
-
];
|
|
185
|
-
});
|
|
186
|
+
setWallets((wallets) => [...wallets]);
|
|
186
187
|
};
|
|
187
188
|
|
|
188
189
|
useEffect(() => {
|
|
@@ -198,7 +199,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
198
199
|
walletCore.off("networkChange", handleNetworkChange);
|
|
199
200
|
walletCore.off("readyStateChange", handleReadyStateChange);
|
|
200
201
|
};
|
|
201
|
-
}, [wallets, connected]);
|
|
202
|
+
}, [...wallets, connected]);
|
|
202
203
|
|
|
203
204
|
return (
|
|
204
205
|
<WalletContext.Provider
|
|
@@ -211,6 +212,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
211
212
|
wallet,
|
|
212
213
|
wallets,
|
|
213
214
|
signAndSubmitTransaction,
|
|
215
|
+
signAndSubmitBCSTransaction,
|
|
214
216
|
signTransaction,
|
|
215
217
|
signMessage,
|
|
216
218
|
signMessageAndVerify,
|
package/src/useWallet.tsx
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
NetworkName,
|
|
11
11
|
} from "@aptos-labs/wallet-adapter-core";
|
|
12
12
|
import { createContext, useContext } from "react";
|
|
13
|
-
import { Types } from "aptos";
|
|
13
|
+
import { TxnBuilderTypes, Types } from "aptos";
|
|
14
14
|
|
|
15
15
|
export type { WalletName };
|
|
16
16
|
export { WalletReadyState, NetworkName };
|
|
@@ -28,6 +28,10 @@ export interface WalletContextState {
|
|
|
28
28
|
transaction: T,
|
|
29
29
|
options?: V
|
|
30
30
|
): Promise<any>;
|
|
31
|
+
signAndSubmitBCSTransaction<T extends TxnBuilderTypes.TransactionPayload, V>(
|
|
32
|
+
transaction: T,
|
|
33
|
+
options?: V
|
|
34
|
+
): Promise<any>;
|
|
31
35
|
signTransaction<T extends Types.TransactionPayload, V>(
|
|
32
36
|
transaction: T,
|
|
33
37
|
options?: V
|