@manahippo/aptos-wallet-adapter 1.0.2 → 1.0.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/README.md +6 -6
- package/dist/WalletAdapters/BloctoWallet.d.ts +3 -3
- package/dist/WalletAdapters/BloctoWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/BloctoWallet.js +1 -3
- package/dist/WalletAdapters/BloctoWallet.js.map +1 -1
- package/dist/WalletAdapters/FoxWallet.d.ts +64 -0
- package/dist/WalletAdapters/FoxWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/FoxWallet.js +239 -0
- package/dist/WalletAdapters/FoxWallet.js.map +1 -0
- package/dist/WalletAdapters/HyperPayWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/HyperPayWallet.js +2 -2
- package/dist/WalletAdapters/HyperPayWallet.js.map +1 -1
- package/dist/WalletAdapters/MsafeWallet.d.ts +39 -0
- package/dist/WalletAdapters/MsafeWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/MsafeWallet.js +225 -0
- package/dist/WalletAdapters/MsafeWallet.js.map +1 -0
- package/dist/WalletAdapters/NightlyWallet.js +2 -2
- package/dist/WalletAdapters/NightlyWallet.js.map +1 -1
- package/dist/WalletAdapters/SpikaWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/SpikaWallet.js +1 -1
- package/dist/WalletAdapters/SpikaWallet.js.map +1 -1
- package/dist/WalletAdapters/index.d.ts +2 -0
- package/dist/WalletAdapters/index.d.ts.map +1 -1
- package/dist/WalletAdapters/index.js +2 -0
- package/dist/WalletAdapters/index.js.map +1 -1
- package/dist/WalletProviders/WalletProvider.d.ts.map +1 -1
- package/dist/WalletProviders/WalletProvider.js +35 -6
- package/dist/WalletProviders/WalletProvider.js.map +1 -1
- package/dist/utilities/util.d.ts +4 -0
- package/dist/utilities/util.d.ts.map +1 -1
- package/dist/utilities/util.js +23 -1
- package/dist/utilities/util.js.map +1 -1
- package/package.json +4 -3
- package/src/WalletAdapters/BloctoWallet.ts +7 -7
- package/src/WalletAdapters/FoxWallet.ts +312 -0
- package/src/WalletAdapters/HyperPayWallet.ts +2 -2
- package/src/WalletAdapters/MsafeWallet.ts +261 -0
- package/src/WalletAdapters/NightlyWallet.ts +2 -2
- package/src/WalletAdapters/SpikaWallet.ts +1 -1
- package/src/WalletAdapters/index.ts +2 -0
- package/src/WalletProviders/WalletProvider.tsx +37 -7
- package/src/utilities/util.ts +13 -0
@@ -1,10 +1,14 @@
|
|
1
1
|
import { FC, ReactNode, useCallback, useEffect, useRef, useState } from 'react';
|
2
2
|
import { Types } from 'aptos';
|
3
3
|
import {
|
4
|
+
WalletConnectionError,
|
4
5
|
WalletError,
|
5
6
|
WalletNotConnectedError,
|
6
7
|
WalletNotReadyError,
|
7
|
-
WalletNotSelectedError
|
8
|
+
WalletNotSelectedError,
|
9
|
+
WalletSignAndSubmitMessageError,
|
10
|
+
WalletSignMessageError,
|
11
|
+
WalletSignTransactionError
|
8
12
|
} from './errors';
|
9
13
|
import { useLocalStorage } from '../hooks/useLocalStorage';
|
10
14
|
import {
|
@@ -16,6 +20,7 @@ import {
|
|
16
20
|
WalletReadyState
|
17
21
|
} from '../WalletAdapters/BaseAdapter';
|
18
22
|
import { Wallet, WalletContext } from './useWallet';
|
23
|
+
import { timeoutPromise } from '../utilities/util';
|
19
24
|
|
20
25
|
export interface WalletProviderProps {
|
21
26
|
children: ReactNode;
|
@@ -39,6 +44,8 @@ const initialState: {
|
|
39
44
|
network: null
|
40
45
|
};
|
41
46
|
|
47
|
+
const TIMEOUT = 90;
|
48
|
+
|
42
49
|
export const WalletProvider: FC<WalletProviderProps> = ({
|
43
50
|
children,
|
44
51
|
wallets: adapters,
|
@@ -117,6 +124,7 @@ export const WalletProvider: FC<WalletProviderProps> = ({
|
|
117
124
|
|
118
125
|
window.addEventListener('beforeunload', listener);
|
119
126
|
return () => window.removeEventListener('beforeunload', listener);
|
127
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
120
128
|
}, [isUnloading, autoConnect]);
|
121
129
|
|
122
130
|
// Handle the adapter's connect event
|
@@ -261,12 +269,17 @@ export const WalletProvider: FC<WalletProviderProps> = ({
|
|
261
269
|
isConnecting.current = true;
|
262
270
|
setConnecting(true);
|
263
271
|
try {
|
264
|
-
|
272
|
+
const timeout = timeoutPromise(TIMEOUT * 1000);
|
273
|
+
await Promise.race([walletToConnect.adapter.connect(), timeout.promise]);
|
274
|
+
clearTimeout(timeout.timeoutId);
|
265
275
|
} catch (error: any) {
|
266
276
|
// Clear the selected wallet
|
267
277
|
setName(null);
|
268
|
-
|
269
|
-
|
278
|
+
if (error === 'timeout') {
|
279
|
+
throw handleError(new WalletConnectionError(error));
|
280
|
+
} else {
|
281
|
+
throw error;
|
282
|
+
}
|
270
283
|
} finally {
|
271
284
|
setConnecting(false);
|
272
285
|
isConnecting.current = false;
|
@@ -314,7 +327,13 @@ export const WalletProvider: FC<WalletProviderProps> = ({
|
|
314
327
|
async (transaction: Types.TransactionPayload, option?: any) => {
|
315
328
|
if (!adapter) throw handleError(new WalletNotSelectedError());
|
316
329
|
if (!connected) throw handleError(new WalletNotConnectedError());
|
317
|
-
const
|
330
|
+
const timeout = timeoutPromise(TIMEOUT * 1000);
|
331
|
+
const response = await Promise.race([
|
332
|
+
adapter.signAndSubmitTransaction(transaction, option),
|
333
|
+
timeout.promise
|
334
|
+
]);
|
335
|
+
clearTimeout(timeout.timeoutId);
|
336
|
+
if (!response) throw handleError(new WalletSignAndSubmitMessageError('Timeout'));
|
318
337
|
return response;
|
319
338
|
},
|
320
339
|
[adapter, handleError, connected]
|
@@ -324,7 +343,14 @@ export const WalletProvider: FC<WalletProviderProps> = ({
|
|
324
343
|
async (transaction: Types.TransactionPayload, option?: any) => {
|
325
344
|
if (!adapter) throw handleError(new WalletNotSelectedError());
|
326
345
|
if (!connected) throw handleError(new WalletNotConnectedError());
|
327
|
-
|
346
|
+
const timeout = timeoutPromise(TIMEOUT * 1000);
|
347
|
+
const response = await Promise.race([
|
348
|
+
adapter.signTransaction(transaction, option),
|
349
|
+
timeout.promise
|
350
|
+
]);
|
351
|
+
clearTimeout(timeout.timeoutId);
|
352
|
+
if (!response) throw handleError(new WalletSignTransactionError('Timeout'));
|
353
|
+
return response;
|
328
354
|
},
|
329
355
|
[adapter, handleError, connected]
|
330
356
|
);
|
@@ -333,7 +359,11 @@ export const WalletProvider: FC<WalletProviderProps> = ({
|
|
333
359
|
async (msgPayload: string | SignMessagePayload | Uint8Array) => {
|
334
360
|
if (!adapter) throw handleError(new WalletNotSelectedError());
|
335
361
|
if (!connected) throw handleError(new WalletNotConnectedError());
|
336
|
-
|
362
|
+
const timeout = timeoutPromise(TIMEOUT * 1000);
|
363
|
+
const response = await Promise.race([adapter.signMessage(msgPayload), timeout.promise]);
|
364
|
+
clearTimeout(timeout.timeoutId);
|
365
|
+
if (!response) throw handleError(new WalletSignMessageError('Timeout'));
|
366
|
+
return response;
|
337
367
|
},
|
338
368
|
[adapter, handleError, connected]
|
339
369
|
);
|
package/src/utilities/util.ts
CHANGED
@@ -9,3 +9,16 @@ export const payloadV1ToV0 = (payload: Types.TransactionPayload) => {
|
|
9
9
|
arguments: v1.arguments
|
10
10
|
};
|
11
11
|
};
|
12
|
+
|
13
|
+
export const timeoutPromise = (timeout) => {
|
14
|
+
let timeoutId;
|
15
|
+
const promise: Promise<void> = new Promise((resolve, reject) => {
|
16
|
+
timeoutId = setTimeout(async () => {
|
17
|
+
reject('timeout');
|
18
|
+
}, timeout);
|
19
|
+
});
|
20
|
+
return {
|
21
|
+
timeoutId,
|
22
|
+
promise
|
23
|
+
};
|
24
|
+
};
|