@aptos-labs/wallet-adapter-react 1.2.1 → 1.2.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 +9 -0
- package/dist/index.js +12 -7
- package/dist/index.mjs +12 -7
- package/package.json +2 -2
- package/src/WalletProvider.tsx +15 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @aptos-labs/wallet-adapter-react
|
|
2
2
|
|
|
3
|
+
## 1.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 22ecf6a: Throw `wallet already connected` error when trying to connect to an already connected wallet
|
|
8
|
+
- e4b06de: Await for wallet connect request before setting isLoading state
|
|
9
|
+
- Updated dependencies [22ecf6a]
|
|
10
|
+
- @aptos-labs/wallet-adapter-core@2.3.2
|
|
11
|
+
|
|
3
12
|
## 1.2.1
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -65,20 +65,23 @@ var AptosWalletAdapterProvider = ({
|
|
|
65
65
|
const [{ connected, account, network, wallet }, setState] = (0, import_react2.useState)(initialState);
|
|
66
66
|
const [isLoading, setIsLoading] = (0, import_react2.useState)(true);
|
|
67
67
|
const walletCore = (0, import_react2.useMemo)(() => new import_wallet_adapter_core2.WalletCore(plugins), []);
|
|
68
|
-
const [wallets, setWallets] = (0, import_react2.useState)(
|
|
69
|
-
|
|
68
|
+
const [wallets, setWallets] = (0, import_react2.useState)(
|
|
69
|
+
walletCore.wallets
|
|
70
|
+
);
|
|
71
|
+
const connect = async (walletName) => {
|
|
70
72
|
try {
|
|
71
73
|
setIsLoading(true);
|
|
72
|
-
walletCore.connect(walletName);
|
|
73
|
-
} catch (
|
|
74
|
-
console.log("connect error",
|
|
74
|
+
await walletCore.connect(walletName);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.log("connect error", error);
|
|
77
|
+
throw error;
|
|
75
78
|
} finally {
|
|
76
79
|
setIsLoading(false);
|
|
77
80
|
}
|
|
78
81
|
};
|
|
79
|
-
const disconnect = () => {
|
|
82
|
+
const disconnect = async () => {
|
|
80
83
|
try {
|
|
81
|
-
walletCore.disconnect();
|
|
84
|
+
await walletCore.disconnect();
|
|
82
85
|
} catch (e) {
|
|
83
86
|
console.log("disconnect error", e);
|
|
84
87
|
}
|
|
@@ -122,6 +125,8 @@ var AptosWalletAdapterProvider = ({
|
|
|
122
125
|
if (autoConnect) {
|
|
123
126
|
if (localStorage.getItem("AptosWalletName")) {
|
|
124
127
|
connect(localStorage.getItem("AptosWalletName"));
|
|
128
|
+
} else {
|
|
129
|
+
setIsLoading(false);
|
|
125
130
|
}
|
|
126
131
|
}
|
|
127
132
|
}, wallets);
|
package/dist/index.mjs
CHANGED
|
@@ -44,20 +44,23 @@ var AptosWalletAdapterProvider = ({
|
|
|
44
44
|
const [{ connected, account, network, wallet }, setState] = useState(initialState);
|
|
45
45
|
const [isLoading, setIsLoading] = useState(true);
|
|
46
46
|
const walletCore = useMemo(() => new WalletCore(plugins), []);
|
|
47
|
-
const [wallets, setWallets] = useState(
|
|
48
|
-
|
|
47
|
+
const [wallets, setWallets] = useState(
|
|
48
|
+
walletCore.wallets
|
|
49
|
+
);
|
|
50
|
+
const connect = async (walletName) => {
|
|
49
51
|
try {
|
|
50
52
|
setIsLoading(true);
|
|
51
|
-
walletCore.connect(walletName);
|
|
52
|
-
} catch (
|
|
53
|
-
console.log("connect error",
|
|
53
|
+
await walletCore.connect(walletName);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.log("connect error", error);
|
|
56
|
+
throw error;
|
|
54
57
|
} finally {
|
|
55
58
|
setIsLoading(false);
|
|
56
59
|
}
|
|
57
60
|
};
|
|
58
|
-
const disconnect = () => {
|
|
61
|
+
const disconnect = async () => {
|
|
59
62
|
try {
|
|
60
|
-
walletCore.disconnect();
|
|
63
|
+
await walletCore.disconnect();
|
|
61
64
|
} catch (e) {
|
|
62
65
|
console.log("disconnect error", e);
|
|
63
66
|
}
|
|
@@ -101,6 +104,8 @@ var AptosWalletAdapterProvider = ({
|
|
|
101
104
|
if (autoConnect) {
|
|
102
105
|
if (localStorage.getItem("AptosWalletName")) {
|
|
103
106
|
connect(localStorage.getItem("AptosWalletName"));
|
|
107
|
+
} else {
|
|
108
|
+
setIsLoading(false);
|
|
104
109
|
}
|
|
105
110
|
}
|
|
106
111
|
}, wallets);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aptos-labs/wallet-adapter-react",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
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": "2.3.
|
|
40
|
+
"@aptos-labs/wallet-adapter-core": "2.3.2",
|
|
41
41
|
"aptos": "^1.3.17",
|
|
42
42
|
"react": "^18"
|
|
43
43
|
},
|
package/src/WalletProvider.tsx
CHANGED
|
@@ -45,25 +45,30 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
45
45
|
const [{ connected, account, network, wallet }, setState] =
|
|
46
46
|
useState(initialState);
|
|
47
47
|
|
|
48
|
+
// a local state to track whether wallet connect request is loading
|
|
49
|
+
// https://github.com/aptos-labs/aptos-wallet-adapter/issues/94
|
|
48
50
|
const [isLoading, setIsLoading] = useState<boolean>(true);
|
|
49
51
|
|
|
50
52
|
const walletCore = useMemo(() => new WalletCore(plugins), []);
|
|
51
|
-
const [wallets, setWallets] = useState<ReadonlyArray<Wallet>>(
|
|
53
|
+
const [wallets, setWallets] = useState<ReadonlyArray<Wallet>>(
|
|
54
|
+
walletCore.wallets
|
|
55
|
+
);
|
|
52
56
|
|
|
53
|
-
const connect = (walletName: WalletName) => {
|
|
57
|
+
const connect = async (walletName: WalletName) => {
|
|
54
58
|
try {
|
|
55
59
|
setIsLoading(true);
|
|
56
|
-
walletCore.connect(walletName);
|
|
57
|
-
} catch (
|
|
58
|
-
console.log("connect error",
|
|
60
|
+
await walletCore.connect(walletName);
|
|
61
|
+
} catch (error: any) {
|
|
62
|
+
console.log("connect error", error);
|
|
63
|
+
throw error;
|
|
59
64
|
} finally {
|
|
60
65
|
setIsLoading(false);
|
|
61
66
|
}
|
|
62
67
|
};
|
|
63
68
|
|
|
64
|
-
const disconnect = () => {
|
|
69
|
+
const disconnect = async () => {
|
|
65
70
|
try {
|
|
66
|
-
walletCore.disconnect();
|
|
71
|
+
await walletCore.disconnect();
|
|
67
72
|
} catch (e) {
|
|
68
73
|
console.log("disconnect error", e);
|
|
69
74
|
}
|
|
@@ -117,6 +122,9 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
117
122
|
if (autoConnect) {
|
|
118
123
|
if (localStorage.getItem("AptosWalletName")) {
|
|
119
124
|
connect(localStorage.getItem("AptosWalletName") as WalletName);
|
|
125
|
+
} else {
|
|
126
|
+
// if we dont use autoconnect set the connect is loading to false
|
|
127
|
+
setIsLoading(false);
|
|
120
128
|
}
|
|
121
129
|
}
|
|
122
130
|
}, wallets);
|