@aptos-labs/wallet-adapter-react 0.2.4 → 1.0.1
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 +11 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.global.js +160 -0
- package/dist/index.js +6 -1
- package/dist/index.mjs +6 -1
- package/package.json +10 -10
- package/src/WalletProvider.tsx +9 -6
- package/src/useWallet.tsx +5 -4
package/dist/index.js
CHANGED
|
@@ -60,13 +60,17 @@ var AptosWalletAdapterProvider = ({
|
|
|
60
60
|
autoConnect = false
|
|
61
61
|
}) => {
|
|
62
62
|
const [{ connected, account, network, wallet }, setState] = (0, import_react2.useState)(initialState);
|
|
63
|
+
const [isLoading, setIsLoading] = (0, import_react2.useState)(true);
|
|
63
64
|
const walletCore = (0, import_react2.useMemo)(() => new import_wallet_adapter_core2.WalletCore(plugins), []);
|
|
64
65
|
const [wallets, setWallets] = (0, import_react2.useState)(walletCore.wallets);
|
|
65
66
|
const connect = (walletName) => {
|
|
66
67
|
try {
|
|
68
|
+
setIsLoading(true);
|
|
67
69
|
walletCore.connect(walletName);
|
|
68
70
|
} catch (e) {
|
|
69
71
|
console.log("connect error", e);
|
|
72
|
+
} finally {
|
|
73
|
+
setIsLoading(false);
|
|
70
74
|
}
|
|
71
75
|
};
|
|
72
76
|
const disconnect = () => {
|
|
@@ -205,7 +209,8 @@ var AptosWalletAdapterProvider = ({
|
|
|
205
209
|
signAndSubmitTransaction,
|
|
206
210
|
signTransaction,
|
|
207
211
|
signMessage,
|
|
208
|
-
signMessageAndVerify
|
|
212
|
+
signMessageAndVerify,
|
|
213
|
+
isLoading
|
|
209
214
|
},
|
|
210
215
|
children
|
|
211
216
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -39,13 +39,17 @@ var AptosWalletAdapterProvider = ({
|
|
|
39
39
|
autoConnect = false
|
|
40
40
|
}) => {
|
|
41
41
|
const [{ connected, account, network, wallet }, setState] = useState(initialState);
|
|
42
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
42
43
|
const walletCore = useMemo(() => new WalletCore(plugins), []);
|
|
43
44
|
const [wallets, setWallets] = useState(walletCore.wallets);
|
|
44
45
|
const connect = (walletName) => {
|
|
45
46
|
try {
|
|
47
|
+
setIsLoading(true);
|
|
46
48
|
walletCore.connect(walletName);
|
|
47
49
|
} catch (e) {
|
|
48
50
|
console.log("connect error", e);
|
|
51
|
+
} finally {
|
|
52
|
+
setIsLoading(false);
|
|
49
53
|
}
|
|
50
54
|
};
|
|
51
55
|
const disconnect = () => {
|
|
@@ -184,7 +188,8 @@ var AptosWalletAdapterProvider = ({
|
|
|
184
188
|
signAndSubmitTransaction,
|
|
185
189
|
signTransaction,
|
|
186
190
|
signMessage,
|
|
187
|
-
signMessageAndVerify
|
|
191
|
+
signMessageAndVerify,
|
|
192
|
+
isLoading
|
|
188
193
|
},
|
|
189
194
|
children
|
|
190
195
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aptos-labs/wallet-adapter-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
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
|
+
},
|
|
31
37
|
"devDependencies": {
|
|
38
|
+
"@aptos-labs/wallet-adapter-tsconfig": "workspace:*",
|
|
32
39
|
"@types/react": "^18.0.17",
|
|
33
40
|
"@types/react-dom": "^18.0.6",
|
|
34
41
|
"eslint": "^8.15.0",
|
|
35
42
|
"typescript": "^4.5.3",
|
|
36
|
-
"tsup": "^5.10.1"
|
|
37
|
-
"@aptos-labs/wallet-adapter-tsconfig": "0.0.0"
|
|
43
|
+
"tsup": "^5.10.1"
|
|
38
44
|
},
|
|
39
45
|
"dependencies": {
|
|
40
46
|
"@aptos-labs/wallet-adapter-core": "*",
|
|
41
47
|
"aptos": "^1.3.17",
|
|
42
48
|
"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
|
@@ -11,14 +11,13 @@ import type {
|
|
|
11
11
|
AccountInfo,
|
|
12
12
|
NetworkInfo,
|
|
13
13
|
SignMessagePayload,
|
|
14
|
+
TransactionPayload,
|
|
14
15
|
Wallet,
|
|
15
16
|
WalletInfo,
|
|
16
17
|
WalletName,
|
|
17
18
|
} from "@aptos-labs/wallet-adapter-core";
|
|
18
19
|
import { WalletCore } from "@aptos-labs/wallet-adapter-core";
|
|
19
20
|
|
|
20
|
-
import { Types } from "aptos";
|
|
21
|
-
|
|
22
21
|
export interface AptosWalletProviderProps {
|
|
23
22
|
children: ReactNode;
|
|
24
23
|
plugins: Wallet[];
|
|
@@ -45,14 +44,19 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
45
44
|
const [{ connected, account, network, wallet }, setState] =
|
|
46
45
|
useState(initialState);
|
|
47
46
|
|
|
47
|
+
const [isLoading, setIsLoading] = useState<boolean>(true);
|
|
48
|
+
|
|
48
49
|
const walletCore = useMemo(() => new WalletCore(plugins), []);
|
|
49
50
|
const [wallets, setWallets] = useState<Wallet[]>(walletCore.wallets);
|
|
50
51
|
|
|
51
52
|
const connect = (walletName: WalletName) => {
|
|
52
53
|
try {
|
|
54
|
+
setIsLoading(true);
|
|
53
55
|
walletCore.connect(walletName);
|
|
54
56
|
} catch (e) {
|
|
55
57
|
console.log("connect error", e);
|
|
58
|
+
} finally {
|
|
59
|
+
setIsLoading(false);
|
|
56
60
|
}
|
|
57
61
|
};
|
|
58
62
|
|
|
@@ -64,9 +68,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
64
68
|
}
|
|
65
69
|
};
|
|
66
70
|
|
|
67
|
-
const signAndSubmitTransaction = async (
|
|
68
|
-
transaction: Types.TransactionPayload
|
|
69
|
-
) => {
|
|
71
|
+
const signAndSubmitTransaction = async (transaction: TransactionPayload) => {
|
|
70
72
|
try {
|
|
71
73
|
return await walletCore.signAndSubmitTransaction(transaction);
|
|
72
74
|
} catch (error: any) {
|
|
@@ -74,7 +76,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
74
76
|
}
|
|
75
77
|
};
|
|
76
78
|
|
|
77
|
-
const signTransaction = async (transaction:
|
|
79
|
+
const signTransaction = async (transaction: TransactionPayload) => {
|
|
78
80
|
try {
|
|
79
81
|
return await walletCore.signTransaction(transaction);
|
|
80
82
|
} catch (error: any) {
|
|
@@ -209,6 +211,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
209
211
|
signTransaction,
|
|
210
212
|
signMessage,
|
|
211
213
|
signMessageAndVerify,
|
|
214
|
+
isLoading,
|
|
212
215
|
}}
|
|
213
216
|
>
|
|
214
217
|
{children}
|
package/src/useWallet.tsx
CHANGED
|
@@ -7,27 +7,28 @@ import {
|
|
|
7
7
|
SignMessageResponse,
|
|
8
8
|
Wallet,
|
|
9
9
|
WalletReadyState,
|
|
10
|
-
NetworkName
|
|
10
|
+
NetworkName,
|
|
11
|
+
TransactionPayload,
|
|
11
12
|
} from "@aptos-labs/wallet-adapter-core";
|
|
12
13
|
import { createContext, useContext } from "react";
|
|
13
|
-
import { Types } from "aptos";
|
|
14
14
|
|
|
15
15
|
export type { WalletName };
|
|
16
16
|
export { WalletReadyState, NetworkName };
|
|
17
17
|
|
|
18
18
|
export interface WalletContextState {
|
|
19
19
|
connected: boolean;
|
|
20
|
+
isLoading: boolean;
|
|
20
21
|
account: AccountInfo | null;
|
|
21
22
|
network: NetworkInfo | null;
|
|
22
23
|
connect(walletName: WalletName): void;
|
|
23
24
|
disconnect(): void;
|
|
24
25
|
wallet: WalletInfo | null;
|
|
25
26
|
wallets: Wallet[];
|
|
26
|
-
signAndSubmitTransaction<T extends
|
|
27
|
+
signAndSubmitTransaction<T extends TransactionPayload, V>(
|
|
27
28
|
transaction: T,
|
|
28
29
|
options?: V
|
|
29
30
|
): Promise<any>;
|
|
30
|
-
signTransaction<T extends
|
|
31
|
+
signTransaction<T extends TransactionPayload, V>(
|
|
31
32
|
transaction: T,
|
|
32
33
|
options?: V
|
|
33
34
|
): Promise<any>;
|