@aptos-labs/wallet-adapter-react 1.2.1 → 1.2.3
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 +17 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +18 -13
- package/dist/index.mjs +18 -13
- package/package.json +2 -2
- package/src/WalletProvider.tsx +27 -13
- package/src/useWallet.tsx +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @aptos-labs/wallet-adapter-react
|
|
2
2
|
|
|
3
|
+
## 1.2.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- dc98bf4: fix sendAndSubmitTransaction params
|
|
8
|
+
- Updated dependencies [dc98bf4]
|
|
9
|
+
- @aptos-labs/wallet-adapter-core@2.3.3
|
|
10
|
+
|
|
11
|
+
## 1.2.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 22ecf6a: Throw `wallet already connected` error when trying to connect to an already connected wallet
|
|
16
|
+
- e4b06de: Await for wallet connect request before setting isLoading state
|
|
17
|
+
- Updated dependencies [22ecf6a]
|
|
18
|
+
- @aptos-labs/wallet-adapter-core@2.3.2
|
|
19
|
+
|
|
3
20
|
## 1.2.1
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AccountInfo, NetworkInfo, WalletName, WalletInfo, Wallet, SignMessagePayload, SignMessageResponse } from '@aptos-labs/wallet-adapter-core';
|
|
1
|
+
import { AccountInfo, NetworkInfo, WalletName, WalletInfo, Wallet, TransactionOptions, 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 { Types, TxnBuilderTypes } from 'aptos';
|
|
4
4
|
import { ReactNode, FC } from 'react';
|
|
@@ -12,9 +12,9 @@ interface WalletContextState {
|
|
|
12
12
|
disconnect(): void;
|
|
13
13
|
wallet: WalletInfo | null;
|
|
14
14
|
wallets: ReadonlyArray<Wallet>;
|
|
15
|
-
signAndSubmitTransaction<T extends Types.TransactionPayload
|
|
16
|
-
signAndSubmitBCSTransaction<T extends TxnBuilderTypes.TransactionPayload
|
|
17
|
-
signTransaction<T extends Types.TransactionPayload
|
|
15
|
+
signAndSubmitTransaction<T extends Types.TransactionPayload>(transaction: T, options?: TransactionOptions): Promise<any>;
|
|
16
|
+
signAndSubmitBCSTransaction<T extends TxnBuilderTypes.TransactionPayload>(transaction: T, options?: TransactionOptions): Promise<any>;
|
|
17
|
+
signTransaction<T extends Types.TransactionPayload>(transaction: T, options?: TransactionOptions): Promise<any>;
|
|
18
18
|
signMessage(message: SignMessagePayload): Promise<SignMessageResponse | null>;
|
|
19
19
|
signMessageAndVerify(message: SignMessagePayload): Promise<boolean>;
|
|
20
20
|
}
|
package/dist/index.js
CHANGED
|
@@ -65,41 +65,44 @@ 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
|
}
|
|
85
88
|
};
|
|
86
|
-
const signAndSubmitTransaction = async (transaction) => {
|
|
89
|
+
const signAndSubmitTransaction = async (transaction, options) => {
|
|
87
90
|
try {
|
|
88
|
-
return await walletCore.signAndSubmitTransaction(transaction);
|
|
91
|
+
return await walletCore.signAndSubmitTransaction(transaction, options);
|
|
89
92
|
} catch (error) {
|
|
90
93
|
throw error;
|
|
91
94
|
}
|
|
92
95
|
};
|
|
93
|
-
const signAndSubmitBCSTransaction = async (transaction) => {
|
|
96
|
+
const signAndSubmitBCSTransaction = async (transaction, options) => {
|
|
94
97
|
try {
|
|
95
|
-
return await walletCore.signAndSubmitBCSTransaction(transaction);
|
|
98
|
+
return await walletCore.signAndSubmitBCSTransaction(transaction, options);
|
|
96
99
|
} catch (error) {
|
|
97
100
|
throw error;
|
|
98
101
|
}
|
|
99
102
|
};
|
|
100
|
-
const signTransaction = async (transaction) => {
|
|
103
|
+
const signTransaction = async (transaction, options) => {
|
|
101
104
|
try {
|
|
102
|
-
return await walletCore.signTransaction(transaction);
|
|
105
|
+
return await walletCore.signTransaction(transaction, options);
|
|
103
106
|
} catch (error) {
|
|
104
107
|
throw error;
|
|
105
108
|
}
|
|
@@ -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,41 +44,44 @@ 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
|
}
|
|
64
67
|
};
|
|
65
|
-
const signAndSubmitTransaction = async (transaction) => {
|
|
68
|
+
const signAndSubmitTransaction = async (transaction, options) => {
|
|
66
69
|
try {
|
|
67
|
-
return await walletCore.signAndSubmitTransaction(transaction);
|
|
70
|
+
return await walletCore.signAndSubmitTransaction(transaction, options);
|
|
68
71
|
} catch (error) {
|
|
69
72
|
throw error;
|
|
70
73
|
}
|
|
71
74
|
};
|
|
72
|
-
const signAndSubmitBCSTransaction = async (transaction) => {
|
|
75
|
+
const signAndSubmitBCSTransaction = async (transaction, options) => {
|
|
73
76
|
try {
|
|
74
|
-
return await walletCore.signAndSubmitBCSTransaction(transaction);
|
|
77
|
+
return await walletCore.signAndSubmitBCSTransaction(transaction, options);
|
|
75
78
|
} catch (error) {
|
|
76
79
|
throw error;
|
|
77
80
|
}
|
|
78
81
|
};
|
|
79
|
-
const signTransaction = async (transaction) => {
|
|
82
|
+
const signTransaction = async (transaction, options) => {
|
|
80
83
|
try {
|
|
81
|
-
return await walletCore.signTransaction(transaction);
|
|
84
|
+
return await walletCore.signTransaction(transaction, options);
|
|
82
85
|
} catch (error) {
|
|
83
86
|
throw error;
|
|
84
87
|
}
|
|
@@ -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.3",
|
|
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.3",
|
|
41
41
|
"aptos": "^1.3.17",
|
|
42
42
|
"react": "^18"
|
|
43
43
|
},
|
package/src/WalletProvider.tsx
CHANGED
|
@@ -14,6 +14,7 @@ import type {
|
|
|
14
14
|
Wallet,
|
|
15
15
|
WalletInfo,
|
|
16
16
|
WalletName,
|
|
17
|
+
TransactionOptions,
|
|
17
18
|
} from "@aptos-labs/wallet-adapter-core";
|
|
18
19
|
import { WalletCore } from "@aptos-labs/wallet-adapter-core";
|
|
19
20
|
|
|
@@ -45,53 +46,63 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
45
46
|
const [{ connected, account, network, wallet }, setState] =
|
|
46
47
|
useState(initialState);
|
|
47
48
|
|
|
49
|
+
// a local state to track whether wallet connect request is loading
|
|
50
|
+
// https://github.com/aptos-labs/aptos-wallet-adapter/issues/94
|
|
48
51
|
const [isLoading, setIsLoading] = useState<boolean>(true);
|
|
49
52
|
|
|
50
53
|
const walletCore = useMemo(() => new WalletCore(plugins), []);
|
|
51
|
-
const [wallets, setWallets] = useState<ReadonlyArray<Wallet>>(
|
|
54
|
+
const [wallets, setWallets] = useState<ReadonlyArray<Wallet>>(
|
|
55
|
+
walletCore.wallets
|
|
56
|
+
);
|
|
52
57
|
|
|
53
|
-
const connect = (walletName: WalletName) => {
|
|
58
|
+
const connect = async (walletName: WalletName) => {
|
|
54
59
|
try {
|
|
55
60
|
setIsLoading(true);
|
|
56
|
-
walletCore.connect(walletName);
|
|
57
|
-
} catch (
|
|
58
|
-
console.log("connect error",
|
|
61
|
+
await walletCore.connect(walletName);
|
|
62
|
+
} catch (error: any) {
|
|
63
|
+
console.log("connect error", error);
|
|
64
|
+
throw error;
|
|
59
65
|
} finally {
|
|
60
66
|
setIsLoading(false);
|
|
61
67
|
}
|
|
62
68
|
};
|
|
63
69
|
|
|
64
|
-
const disconnect = () => {
|
|
70
|
+
const disconnect = async () => {
|
|
65
71
|
try {
|
|
66
|
-
walletCore.disconnect();
|
|
72
|
+
await walletCore.disconnect();
|
|
67
73
|
} catch (e) {
|
|
68
74
|
console.log("disconnect error", e);
|
|
69
75
|
}
|
|
70
76
|
};
|
|
71
77
|
|
|
72
78
|
const signAndSubmitTransaction = async (
|
|
73
|
-
transaction: Types.TransactionPayload
|
|
79
|
+
transaction: Types.TransactionPayload,
|
|
80
|
+
options?: TransactionOptions
|
|
74
81
|
) => {
|
|
75
82
|
try {
|
|
76
|
-
return await walletCore.signAndSubmitTransaction(transaction);
|
|
83
|
+
return await walletCore.signAndSubmitTransaction(transaction, options);
|
|
77
84
|
} catch (error: any) {
|
|
78
85
|
throw error;
|
|
79
86
|
}
|
|
80
87
|
};
|
|
81
88
|
|
|
82
89
|
const signAndSubmitBCSTransaction = async (
|
|
83
|
-
transaction: TxnBuilderTypes.TransactionPayload
|
|
90
|
+
transaction: TxnBuilderTypes.TransactionPayload,
|
|
91
|
+
options?: TransactionOptions
|
|
84
92
|
) => {
|
|
85
93
|
try {
|
|
86
|
-
return await walletCore.signAndSubmitBCSTransaction(transaction);
|
|
94
|
+
return await walletCore.signAndSubmitBCSTransaction(transaction, options);
|
|
87
95
|
} catch (error: any) {
|
|
88
96
|
throw error;
|
|
89
97
|
}
|
|
90
98
|
};
|
|
91
99
|
|
|
92
|
-
const signTransaction = async (
|
|
100
|
+
const signTransaction = async (
|
|
101
|
+
transaction: Types.TransactionPayload,
|
|
102
|
+
options?: TransactionOptions
|
|
103
|
+
) => {
|
|
93
104
|
try {
|
|
94
|
-
return await walletCore.signTransaction(transaction);
|
|
105
|
+
return await walletCore.signTransaction(transaction, options);
|
|
95
106
|
} catch (error: any) {
|
|
96
107
|
throw error;
|
|
97
108
|
}
|
|
@@ -117,6 +128,9 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
117
128
|
if (autoConnect) {
|
|
118
129
|
if (localStorage.getItem("AptosWalletName")) {
|
|
119
130
|
connect(localStorage.getItem("AptosWalletName") as WalletName);
|
|
131
|
+
} else {
|
|
132
|
+
// if we dont use autoconnect set the connect is loading to false
|
|
133
|
+
setIsLoading(false);
|
|
120
134
|
}
|
|
121
135
|
}
|
|
122
136
|
}, wallets);
|
package/src/useWallet.tsx
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
isInAppBrowser,
|
|
12
12
|
isRedirectable,
|
|
13
13
|
isMobile,
|
|
14
|
+
TransactionOptions,
|
|
14
15
|
} from "@aptos-labs/wallet-adapter-core";
|
|
15
16
|
import { createContext, useContext } from "react";
|
|
16
17
|
import { TxnBuilderTypes, Types } from "aptos";
|
|
@@ -33,17 +34,17 @@ export interface WalletContextState {
|
|
|
33
34
|
disconnect(): void;
|
|
34
35
|
wallet: WalletInfo | null;
|
|
35
36
|
wallets: ReadonlyArray<Wallet>;
|
|
36
|
-
signAndSubmitTransaction<T extends Types.TransactionPayload
|
|
37
|
+
signAndSubmitTransaction<T extends Types.TransactionPayload>(
|
|
37
38
|
transaction: T,
|
|
38
|
-
options?:
|
|
39
|
+
options?: TransactionOptions
|
|
39
40
|
): Promise<any>;
|
|
40
|
-
signAndSubmitBCSTransaction<T extends TxnBuilderTypes.TransactionPayload
|
|
41
|
+
signAndSubmitBCSTransaction<T extends TxnBuilderTypes.TransactionPayload>(
|
|
41
42
|
transaction: T,
|
|
42
|
-
options?:
|
|
43
|
+
options?: TransactionOptions
|
|
43
44
|
): Promise<any>;
|
|
44
|
-
signTransaction<T extends Types.TransactionPayload
|
|
45
|
+
signTransaction<T extends Types.TransactionPayload>(
|
|
45
46
|
transaction: T,
|
|
46
|
-
options?:
|
|
47
|
+
options?: TransactionOptions
|
|
47
48
|
): Promise<any>;
|
|
48
49
|
signMessage(message: SignMessagePayload): Promise<SignMessageResponse | null>;
|
|
49
50
|
signMessageAndVerify(message: SignMessagePayload): Promise<boolean>;
|