@manahippo/aptos-wallet-adapter 1.0.1 → 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 +8 -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/Coin98Wallet.d.ts +61 -0
- package/dist/WalletAdapters/Coin98Wallet.d.ts.map +1 -0
- package/dist/WalletAdapters/Coin98Wallet.js +245 -0
- package/dist/WalletAdapters/Coin98Wallet.js.map +1 -0
- 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/SafePalWallet.d.ts +65 -0
- package/dist/WalletAdapters/SafePalWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/SafePalWallet.js +245 -0
- package/dist/WalletAdapters/SafePalWallet.js.map +1 -0
- 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 +4 -0
- package/dist/WalletAdapters/index.d.ts.map +1 -1
- package/dist/WalletAdapters/index.js +4 -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/Coin98Wallet.ts +310 -0
- 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/SafePalWallet.ts +319 -0
- package/src/WalletAdapters/SpikaWallet.ts +1 -1
- package/src/WalletAdapters/index.ts +4 -0
- package/src/WalletProviders/WalletProvider.tsx +37 -7
- package/src/utilities/util.ts +13 -0
@@ -0,0 +1,319 @@
|
|
1
|
+
import { MaybeHexString, Types } from 'aptos';
|
2
|
+
import {
|
3
|
+
WalletAccountChangeError,
|
4
|
+
WalletDisconnectionError,
|
5
|
+
WalletGetNetworkError,
|
6
|
+
WalletNetworkChangeError,
|
7
|
+
WalletNotConnectedError,
|
8
|
+
WalletNotReadyError,
|
9
|
+
WalletSignAndSubmitMessageError,
|
10
|
+
WalletSignMessageError,
|
11
|
+
WalletSignTransactionError
|
12
|
+
} from '../WalletProviders/errors';
|
13
|
+
import {
|
14
|
+
AccountKeys,
|
15
|
+
BaseWalletAdapter,
|
16
|
+
NetworkInfo,
|
17
|
+
scopePollingDetectionStrategy,
|
18
|
+
SignMessagePayload,
|
19
|
+
SignMessageResponse,
|
20
|
+
WalletAdapterNetwork,
|
21
|
+
WalletName,
|
22
|
+
WalletReadyState
|
23
|
+
} from './BaseAdapter';
|
24
|
+
|
25
|
+
interface ConnectSafePalAccount {
|
26
|
+
address: MaybeHexString;
|
27
|
+
method: string;
|
28
|
+
publicKey: MaybeHexString;
|
29
|
+
status: number;
|
30
|
+
}
|
31
|
+
|
32
|
+
interface SafePalAccount {
|
33
|
+
address: MaybeHexString;
|
34
|
+
publicKey: MaybeHexString;
|
35
|
+
authKey: MaybeHexString;
|
36
|
+
isConnected: boolean;
|
37
|
+
}
|
38
|
+
interface ISafePalWallet {
|
39
|
+
connect: () => Promise<ConnectSafePalAccount>;
|
40
|
+
account(): Promise<SafePalAccount>;
|
41
|
+
isConnected(): Promise<boolean>;
|
42
|
+
generateTransaction(sender: MaybeHexString, payload: any, options?: any): Promise<any>;
|
43
|
+
signAndSubmitTransaction(transaction: Types.TransactionPayload): Promise<Types.HexEncodedBytes>;
|
44
|
+
signTransaction(transaction: Types.TransactionPayload): Promise<Uint8Array>;
|
45
|
+
signMessage(message: SignMessagePayload): Promise<SignMessageResponse>;
|
46
|
+
disconnect(): Promise<void>;
|
47
|
+
getChainId(): Promise<{ chainId: number }>;
|
48
|
+
network(): Promise<WalletAdapterNetwork>;
|
49
|
+
onAccountChange: (listenr: (newAddress: string) => void) => void;
|
50
|
+
onNetworkChange: (listenr: (network: string) => void) => void;
|
51
|
+
}
|
52
|
+
|
53
|
+
interface SafePalWindow extends Window {
|
54
|
+
safePal?: ISafePalWallet;
|
55
|
+
}
|
56
|
+
|
57
|
+
declare const window: SafePalWindow;
|
58
|
+
|
59
|
+
export const SafePalWalletName = 'SafePal' as WalletName<'SafePal'>;
|
60
|
+
|
61
|
+
export interface SafePalWalletAdapterConfig {
|
62
|
+
provider?: ISafePalWallet;
|
63
|
+
// network?: WalletAdapterNetwork;
|
64
|
+
timeout?: number;
|
65
|
+
}
|
66
|
+
|
67
|
+
export class SafePalWalletAdapter extends BaseWalletAdapter {
|
68
|
+
name = SafePalWalletName;
|
69
|
+
|
70
|
+
url = 'https://chrome.google.com/webstore/detail/safepal-extension-wallet/lgmpcpglpngdoalbgeoldeajfclnhafa';
|
71
|
+
|
72
|
+
icon = 'https://raw.githubusercontent.com/hippospace/aptos-wallet-adapter/main/logos/safePal.png';
|
73
|
+
|
74
|
+
protected _provider: ISafePalWallet | undefined;
|
75
|
+
|
76
|
+
protected _network: WalletAdapterNetwork;
|
77
|
+
|
78
|
+
protected _chainId: string;
|
79
|
+
|
80
|
+
protected _api: string;
|
81
|
+
|
82
|
+
protected _timeout: number;
|
83
|
+
|
84
|
+
protected _readyState: WalletReadyState =
|
85
|
+
typeof window === 'undefined' || typeof document === 'undefined'
|
86
|
+
? WalletReadyState.Unsupported
|
87
|
+
: WalletReadyState.NotDetected;
|
88
|
+
|
89
|
+
protected _connecting: boolean;
|
90
|
+
|
91
|
+
protected _wallet: SafePalAccount | null;
|
92
|
+
|
93
|
+
constructor({
|
94
|
+
// provider,
|
95
|
+
// network = WalletAdapterNetwork.Testnet,
|
96
|
+
timeout = 10000
|
97
|
+
}: SafePalWalletAdapterConfig = {}) {
|
98
|
+
super();
|
99
|
+
|
100
|
+
this._provider = typeof window !== 'undefined' ? window.safePal : undefined;
|
101
|
+
this._network = undefined;
|
102
|
+
this._timeout = timeout;
|
103
|
+
this._connecting = false;
|
104
|
+
this._wallet = null;
|
105
|
+
|
106
|
+
if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
|
107
|
+
scopePollingDetectionStrategy(() => {
|
108
|
+
this._provider = typeof window !== 'undefined' ? window.safePal : undefined;
|
109
|
+
if (this._provider) {
|
110
|
+
this._readyState = WalletReadyState.Installed;
|
111
|
+
this.emit('readyStateChange', this._readyState);
|
112
|
+
return true;
|
113
|
+
}
|
114
|
+
return false;
|
115
|
+
});
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
119
|
+
get publicAccount(): AccountKeys {
|
120
|
+
return {
|
121
|
+
publicKey: this._wallet?.publicKey || null,
|
122
|
+
address: this._wallet?.address || null,
|
123
|
+
authKey: this._wallet?.authKey || null
|
124
|
+
};
|
125
|
+
}
|
126
|
+
|
127
|
+
get network(): NetworkInfo {
|
128
|
+
return {
|
129
|
+
name: this._network,
|
130
|
+
api: this._api,
|
131
|
+
chainId: this._chainId
|
132
|
+
};
|
133
|
+
}
|
134
|
+
|
135
|
+
get connecting(): boolean {
|
136
|
+
return this._connecting;
|
137
|
+
}
|
138
|
+
|
139
|
+
get connected(): boolean {
|
140
|
+
return !!this._wallet?.isConnected;
|
141
|
+
}
|
142
|
+
|
143
|
+
get readyState(): WalletReadyState {
|
144
|
+
return this._readyState;
|
145
|
+
}
|
146
|
+
|
147
|
+
async connect(): Promise<void> {
|
148
|
+
try {
|
149
|
+
if (this.connected || this.connecting) return;
|
150
|
+
if (
|
151
|
+
!(
|
152
|
+
this._readyState === WalletReadyState.Loadable ||
|
153
|
+
this._readyState === WalletReadyState.Installed
|
154
|
+
)
|
155
|
+
)
|
156
|
+
throw new WalletNotReadyError();
|
157
|
+
this._connecting = true;
|
158
|
+
|
159
|
+
const provider = this._provider || window.safePal;
|
160
|
+
const isConnected = await provider?.isConnected();
|
161
|
+
if (isConnected) {
|
162
|
+
await provider?.disconnect();
|
163
|
+
}
|
164
|
+
const response = await provider?.connect();
|
165
|
+
|
166
|
+
if (!response) {
|
167
|
+
throw new WalletNotConnectedError('No connect response');
|
168
|
+
}
|
169
|
+
|
170
|
+
const walletAccount = await provider?.account();
|
171
|
+
if (walletAccount) {
|
172
|
+
this._wallet = {
|
173
|
+
...walletAccount,
|
174
|
+
isConnected: true
|
175
|
+
};
|
176
|
+
|
177
|
+
try {
|
178
|
+
const name = await provider?.network();
|
179
|
+
const { chainId } = await provider?.getChainId();
|
180
|
+
const api = null;
|
181
|
+
|
182
|
+
this._network = name;
|
183
|
+
this._chainId = chainId.toString();
|
184
|
+
this._api = api;
|
185
|
+
} catch (error: any) {
|
186
|
+
const errMsg = error.message;
|
187
|
+
this.emit('error', new WalletGetNetworkError(errMsg));
|
188
|
+
throw error;
|
189
|
+
}
|
190
|
+
}
|
191
|
+
this.emit('connect', this._wallet?.address || '');
|
192
|
+
} catch (error: any) {
|
193
|
+
this.emit('error', new Error(error));
|
194
|
+
throw error;
|
195
|
+
} finally {
|
196
|
+
this._connecting = false;
|
197
|
+
}
|
198
|
+
}
|
199
|
+
|
200
|
+
async disconnect(): Promise<void> {
|
201
|
+
const wallet = this._wallet;
|
202
|
+
const provider = this._provider || window.safePal;
|
203
|
+
if (wallet) {
|
204
|
+
this._wallet = null;
|
205
|
+
|
206
|
+
try {
|
207
|
+
await provider?.disconnect();
|
208
|
+
} catch (error: any) {
|
209
|
+
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
210
|
+
}
|
211
|
+
}
|
212
|
+
|
213
|
+
this.emit('disconnect');
|
214
|
+
}
|
215
|
+
|
216
|
+
async signTransaction(
|
217
|
+
transactionPyld: Types.TransactionPayload,
|
218
|
+
options?: any
|
219
|
+
): Promise<Uint8Array> {
|
220
|
+
try {
|
221
|
+
const wallet = this._wallet;
|
222
|
+
const provider = this._provider || window.safePal;
|
223
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
224
|
+
const tx = await provider.generateTransaction(wallet.address || '', transactionPyld, options);
|
225
|
+
if (!tx) throw new Error('Cannot generate transaction');
|
226
|
+
const response = await provider?.signTransaction(tx);
|
227
|
+
|
228
|
+
if (!response) {
|
229
|
+
throw new Error('No response');
|
230
|
+
}
|
231
|
+
return response;
|
232
|
+
} catch (error: any) {
|
233
|
+
this.emit('error', new WalletSignTransactionError(error));
|
234
|
+
throw error;
|
235
|
+
}
|
236
|
+
}
|
237
|
+
|
238
|
+
async signAndSubmitTransaction(
|
239
|
+
transactionPyld: Types.TransactionPayload,
|
240
|
+
options?: any
|
241
|
+
): Promise<{ hash: Types.HexEncodedBytes }> {
|
242
|
+
try {
|
243
|
+
const wallet = this._wallet;
|
244
|
+
const provider = this._provider || window.safePal;
|
245
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
246
|
+
const tx = await provider.generateTransaction(wallet.address || '', transactionPyld, options);
|
247
|
+
if (!tx) throw new Error('Cannot generate transaction');
|
248
|
+
const response = await provider?.signAndSubmitTransaction(tx);
|
249
|
+
|
250
|
+
if (!response) {
|
251
|
+
throw new Error('No response');
|
252
|
+
}
|
253
|
+
return { hash: response };
|
254
|
+
} catch (error: any) {
|
255
|
+
this.emit('error', new WalletSignAndSubmitMessageError(error));
|
256
|
+
throw error;
|
257
|
+
}
|
258
|
+
}
|
259
|
+
|
260
|
+
async signMessage(msgPayload: SignMessagePayload): Promise<SignMessageResponse> {
|
261
|
+
try {
|
262
|
+
const wallet = this._wallet;
|
263
|
+
const provider = this._provider || window.safePal;
|
264
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
265
|
+
if (typeof msgPayload !== 'object' || !msgPayload.nonce) {
|
266
|
+
throw new WalletSignMessageError('Invalid signMessage Payload');
|
267
|
+
}
|
268
|
+
const response = await provider?.signMessage(msgPayload);
|
269
|
+
if (response) {
|
270
|
+
return response;
|
271
|
+
} else {
|
272
|
+
throw new Error('Sign Message failed');
|
273
|
+
}
|
274
|
+
} catch (error: any) {
|
275
|
+
const errMsg = error.message;
|
276
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
277
|
+
throw error;
|
278
|
+
}
|
279
|
+
}
|
280
|
+
|
281
|
+
async onAccountChange(): Promise<void> {
|
282
|
+
try {
|
283
|
+
const wallet = this._wallet;
|
284
|
+
const provider = this._provider || window.safePal;
|
285
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
286
|
+
const handleChangeAccount = async (newAccount: string) => {
|
287
|
+
const { publicKey } = await provider?.account();
|
288
|
+
this._wallet = {
|
289
|
+
...this._wallet,
|
290
|
+
address: newAccount,
|
291
|
+
publicKey
|
292
|
+
};
|
293
|
+
this.emit('accountChange', newAccount);
|
294
|
+
};
|
295
|
+
await provider?.onAccountChange(handleChangeAccount);
|
296
|
+
} catch (error: any) {
|
297
|
+
const errMsg = error.message;
|
298
|
+
this.emit('error', new WalletAccountChangeError(errMsg));
|
299
|
+
throw error;
|
300
|
+
}
|
301
|
+
}
|
302
|
+
|
303
|
+
async onNetworkChange(): Promise<void> {
|
304
|
+
try {
|
305
|
+
const wallet = this._wallet;
|
306
|
+
const provider = this._provider || window.safePal;
|
307
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
308
|
+
const handleNetworkChange = async (newNetwork: WalletAdapterNetwork) => {
|
309
|
+
this._network = newNetwork;
|
310
|
+
this.emit('networkChange', this._network);
|
311
|
+
};
|
312
|
+
await provider?.onNetworkChange(handleNetworkChange);
|
313
|
+
} catch (error: any) {
|
314
|
+
const errMsg = error.message;
|
315
|
+
this.emit('error', new WalletNetworkChangeError(errMsg));
|
316
|
+
throw error;
|
317
|
+
}
|
318
|
+
}
|
319
|
+
}
|
@@ -51,7 +51,7 @@ export class SpikaWalletAdapter extends BaseWalletAdapter {
|
|
51
51
|
|
52
52
|
url = 'https://chrome.google.com/webstore/detail/spika/fadkojdgchhfkdkklllhcphknohbmjmb';
|
53
53
|
|
54
|
-
icon = 'https://
|
54
|
+
icon = 'https://raw.githubusercontent.com/hippospace/aptos-wallet-adapter/main/logos/spika.svg';
|
55
55
|
|
56
56
|
protected _provider: ISpikaWallet | undefined;
|
57
57
|
|
@@ -15,3 +15,7 @@ export * from './BitkeepWallet';
|
|
15
15
|
export * from './TokenPocketWallet';
|
16
16
|
export * from './ONTOWallet';
|
17
17
|
export * from './BloctoWallet';
|
18
|
+
export * from './Coin98Wallet';
|
19
|
+
export * from './SafePalWallet';
|
20
|
+
export * from './FoxWallet';
|
21
|
+
export * from './MsafeWallet';
|
@@ -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
|
+
};
|