@etherplay/connect 0.0.14 → 0.0.16
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/dist/index.d.ts +27 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +155 -89
- package/dist/index.js.map +1 -1
- package/dist/provider.d.ts +1 -0
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +21 -6
- package/dist/provider.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +212 -146
- package/src/provider.ts +29 -13
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,22 @@ export type WalletMechanism<WalletName extends string | undefined, Address exten
|
|
|
20
20
|
});
|
|
21
21
|
export type Mechanism = AlchemyMechanism | WalletMechanism<string | undefined, `0x${string}` | undefined>;
|
|
22
22
|
export type FullfilledMechanism = AlchemyMechanism | WalletMechanism<string, `0x${string}`>;
|
|
23
|
+
export type WalletState = {
|
|
24
|
+
provider: EIP1193WindowWalletProvider;
|
|
25
|
+
accounts: `0x${string}`[];
|
|
26
|
+
accountChanged?: `0x${string}`;
|
|
27
|
+
chainId: string;
|
|
28
|
+
invalidChainId: boolean;
|
|
29
|
+
switchingChain: 'addingChain' | 'switchingChain' | false;
|
|
30
|
+
} & ({
|
|
31
|
+
status: 'connected';
|
|
32
|
+
} | {
|
|
33
|
+
status: 'locked';
|
|
34
|
+
unlocking: boolean;
|
|
35
|
+
} | {
|
|
36
|
+
status: 'disconnected';
|
|
37
|
+
connecting: boolean;
|
|
38
|
+
});
|
|
23
39
|
export type Connection = {
|
|
24
40
|
error?: {
|
|
25
41
|
message: string;
|
|
@@ -46,30 +62,18 @@ export type Connection = {
|
|
|
46
62
|
step: 'WaitingForWalletConnection';
|
|
47
63
|
wallet: undefined;
|
|
48
64
|
mechanism: WalletMechanism<string, undefined>;
|
|
65
|
+
} | {
|
|
66
|
+
step: 'ChooseWalletAccount';
|
|
67
|
+
mechanism: WalletMechanism<string, undefined>;
|
|
68
|
+
wallet: WalletState;
|
|
49
69
|
} | {
|
|
50
70
|
step: 'WalletConnected';
|
|
51
71
|
mechanism: WalletMechanism<string, `0x${string}`>;
|
|
52
|
-
wallet:
|
|
53
|
-
provider: EIP1193WindowWalletProvider;
|
|
54
|
-
locked: boolean;
|
|
55
|
-
disconnected: boolean;
|
|
56
|
-
accountChanged?: `0x${string}`;
|
|
57
|
-
chainId: string;
|
|
58
|
-
invalidChainId: boolean;
|
|
59
|
-
switchingChain: 'addingChain' | 'switchingChain' | false;
|
|
60
|
-
};
|
|
72
|
+
wallet: WalletState;
|
|
61
73
|
} | {
|
|
62
74
|
step: 'WaitingForSignature';
|
|
63
75
|
mechanism: WalletMechanism<string, `0x${string}`>;
|
|
64
|
-
wallet:
|
|
65
|
-
provider: EIP1193WindowWalletProvider;
|
|
66
|
-
locked: boolean;
|
|
67
|
-
disconnected: boolean;
|
|
68
|
-
accountChanged?: `0x${string}`;
|
|
69
|
-
chainId: string;
|
|
70
|
-
invalidChainId: boolean;
|
|
71
|
-
switchingChain: 'addingChain' | 'switchingChain' | false;
|
|
72
|
-
};
|
|
76
|
+
wallet: WalletState;
|
|
73
77
|
} | {
|
|
74
78
|
step: 'SignedIn';
|
|
75
79
|
mechanism: AlchemyMechanism;
|
|
@@ -79,15 +83,7 @@ export type Connection = {
|
|
|
79
83
|
step: 'SignedIn';
|
|
80
84
|
mechanism: WalletMechanism<string, `0x${string}`>;
|
|
81
85
|
account: OriginAccount;
|
|
82
|
-
wallet:
|
|
83
|
-
provider: EIP1193WindowWalletProvider;
|
|
84
|
-
locked: boolean;
|
|
85
|
-
disconnected: boolean;
|
|
86
|
-
accountChanged?: `0x${string}`;
|
|
87
|
-
chainId: string;
|
|
88
|
-
invalidChainId: boolean;
|
|
89
|
-
switchingChain: 'addingChain' | 'switchingChain' | false;
|
|
90
|
-
};
|
|
86
|
+
wallet: WalletState;
|
|
91
87
|
});
|
|
92
88
|
interface EIP6963ProviderInfo {
|
|
93
89
|
uuid: string;
|
|
@@ -124,7 +120,9 @@ export declare function createConnection(settings: {
|
|
|
124
120
|
cancel: () => void;
|
|
125
121
|
back: (step: "MechanismToChoose" | "Idle" | "WalletToChoose") => void;
|
|
126
122
|
requestSignature: () => Promise<void>;
|
|
127
|
-
|
|
123
|
+
connecToAddress: (address: `0x${string}`, options?: {
|
|
124
|
+
requireUserConfirmationBeforeSignatureRequest: boolean;
|
|
125
|
+
}) => void;
|
|
128
126
|
disconnect: () => void;
|
|
129
127
|
getSignatureForPublicKeyPublication: () => Promise<`0x${string}`>;
|
|
130
128
|
switchWalletChain: (chainId: string, config?: {
|
|
@@ -3258,6 +3256,7 @@ export declare function createConnection(settings: {
|
|
|
3258
3256
|
}): Promise<U["result"]>;
|
|
3259
3257
|
} & {
|
|
3260
3258
|
setWalletProvider: (walletProvider: EIP1193WindowWalletProvider | undefined) => void;
|
|
3259
|
+
setWalletStatus: (newStatus: "connected" | "locked" | "disconnected") => void;
|
|
3261
3260
|
} & {
|
|
3262
3261
|
chainId: string;
|
|
3263
3262
|
};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,oBAAoB,CAAC;AAGxE,OAAO,KAAK,EAAC,cAAc,EAAE,2BAA2B,EAAC,MAAM,UAAU,CAAC;AAC1E,OAAO,EACN,wBAAwB,EAGxB,gBAAgB,EAChB,iCAAiC,EACjC,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAC,wBAAwB,EAAE,iCAAiC,EAAE,gBAAgB,EAAC,CAAC;AACvF,YAAY,EAAC,aAAa,EAAC,CAAC;AAE5B,MAAM,MAAM,aAAa,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,gBAAgB,CAAC;CAE5B,CAAC;AAEF,MAAM,MAAM,eAAe,CAAC,UAAU,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nection(settings) {
|
|
|
99
99
|
_wallet = { provider: walletProvider, chainId };
|
|
100
100
|
alwaysOnProvider.setWalletProvider(walletProvider);
|
|
101
101
|
watchForChainIdChange(_wallet.provider);
|
|
102
|
+
let accounts = [];
|
|
103
|
+
// try {
|
|
104
|
+
accounts = await walletProvider.request({ method: 'eth_accounts' });
|
|
105
|
+
accounts = accounts.map((v) => v.toLowerCase());
|
|
106
|
+
// } catch {}
|
|
107
|
+
// // TODO try catch ? and use logic of onAccountChanged
|
|
102
108
|
set({
|
|
103
109
|
step: 'SignedIn',
|
|
104
110
|
account: existingAccount,
|
|
@@ -106,15 +112,17 @@ export function createConnection(settings) {
|
|
|
106
112
|
wallets: $connection.wallets,
|
|
107
113
|
wallet: {
|
|
108
114
|
provider: walletProvider,
|
|
109
|
-
|
|
110
|
-
|
|
115
|
+
accounts,
|
|
116
|
+
status: 'connected',
|
|
111
117
|
accountChanged: undefined,
|
|
112
118
|
chainId,
|
|
113
119
|
invalidChainId: alwaysOnChainId != chainId,
|
|
114
120
|
switchingChain: false,
|
|
115
121
|
},
|
|
116
122
|
});
|
|
117
|
-
|
|
123
|
+
alwaysOnProvider.setWalletStatus('connected');
|
|
124
|
+
// TODO use the same logic before hand
|
|
125
|
+
onAccountChanged(accounts);
|
|
118
126
|
watchForAccountChange(walletProvider);
|
|
119
127
|
})
|
|
120
128
|
.catch((err) => {
|
|
@@ -147,21 +155,29 @@ export function createConnection(settings) {
|
|
|
147
155
|
_wallet = { provider: walletProvider, chainId };
|
|
148
156
|
alwaysOnProvider.setWalletProvider(walletProvider);
|
|
149
157
|
watchForChainIdChange(_wallet.provider);
|
|
158
|
+
let accounts = [];
|
|
159
|
+
// try {
|
|
160
|
+
accounts = await walletProvider.request({ method: 'eth_accounts' });
|
|
161
|
+
accounts = accounts.map((v) => v.toLowerCase());
|
|
162
|
+
// } catch {}
|
|
163
|
+
// // TODO try catch ? and use logic of onAccountChanged
|
|
150
164
|
set({
|
|
151
165
|
step: 'WalletConnected',
|
|
152
166
|
mechanism: lastWallet,
|
|
153
167
|
wallets: $connection.wallets,
|
|
154
168
|
wallet: {
|
|
155
169
|
provider: walletProvider,
|
|
156
|
-
|
|
157
|
-
|
|
170
|
+
accounts,
|
|
171
|
+
status: 'connected',
|
|
158
172
|
accountChanged: undefined,
|
|
159
173
|
chainId,
|
|
160
174
|
invalidChainId: alwaysOnChainId != chainId,
|
|
161
175
|
switchingChain: false,
|
|
162
176
|
},
|
|
163
177
|
});
|
|
164
|
-
|
|
178
|
+
alwaysOnProvider.setWalletStatus('connected');
|
|
179
|
+
// TODO use the same logic before hand
|
|
180
|
+
onAccountChanged(accounts);
|
|
165
181
|
watchForAccountChange(walletProvider);
|
|
166
182
|
})
|
|
167
183
|
.catch((err) => {
|
|
@@ -220,12 +236,7 @@ export function createConnection(settings) {
|
|
|
220
236
|
if ($connection.step !== 'WalletConnected') {
|
|
221
237
|
throw new Error(`invalid step: ${$connection.step}, needs to be WalletConnected`);
|
|
222
238
|
}
|
|
223
|
-
|
|
224
|
-
// TODO error ?
|
|
225
|
-
throw new Error(`no wallet provided initialised`);
|
|
226
|
-
}
|
|
227
|
-
const provider = _wallet.provider;
|
|
228
|
-
const chainId = _wallet.chainId;
|
|
239
|
+
const provider = $connection.wallet.provider;
|
|
229
240
|
const message = originKeyMessage(origin);
|
|
230
241
|
const msg = hashMessage(message);
|
|
231
242
|
set({
|
|
@@ -273,36 +284,25 @@ export function createConnection(settings) {
|
|
|
273
284
|
set({
|
|
274
285
|
...$connection,
|
|
275
286
|
step: 'SignedIn',
|
|
276
|
-
mechanism: {
|
|
277
|
-
type: 'wallet',
|
|
278
|
-
name: $connection.mechanism.name,
|
|
279
|
-
address: $connection.mechanism.address,
|
|
280
|
-
},
|
|
281
287
|
account,
|
|
282
|
-
wallet:
|
|
283
|
-
chainId,
|
|
284
|
-
provider: provider,
|
|
285
|
-
locked: false,
|
|
286
|
-
disconnected: false,
|
|
287
|
-
accountChanged: undefined, // TODO check account list
|
|
288
|
-
invalidChainId: alwaysOnChainId != chainId,
|
|
289
|
-
switchingChain: false,
|
|
290
|
-
},
|
|
288
|
+
wallet: $connection.wallet,
|
|
291
289
|
});
|
|
292
290
|
if (remember) {
|
|
293
291
|
saveOriginAccount(account);
|
|
294
292
|
}
|
|
295
293
|
}
|
|
296
|
-
function
|
|
297
|
-
if ($connection.
|
|
294
|
+
function connecToAddress(address, options) {
|
|
295
|
+
if ($connection.wallet) {
|
|
298
296
|
connect({
|
|
299
297
|
type: 'wallet',
|
|
300
298
|
address,
|
|
301
299
|
name: $connection.mechanism.name,
|
|
300
|
+
}, {
|
|
301
|
+
requireUserConfirmationBeforeSignatureRequest: options?.requireUserConfirmationBeforeSignatureRequest,
|
|
302
302
|
});
|
|
303
303
|
}
|
|
304
304
|
else {
|
|
305
|
-
throw new Error(`need to be using a
|
|
305
|
+
throw new Error(`need to be using a wallet`);
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
308
|
function onChainChanged(chainIdAsHex) {
|
|
@@ -332,23 +332,35 @@ export function createConnection(settings) {
|
|
|
332
332
|
...$connection,
|
|
333
333
|
wallet: {
|
|
334
334
|
...$connection.wallet,
|
|
335
|
-
|
|
335
|
+
status: 'locked',
|
|
336
|
+
unlocking: false,
|
|
336
337
|
},
|
|
337
338
|
});
|
|
339
|
+
alwaysOnProvider.setWalletStatus('locked');
|
|
338
340
|
}
|
|
339
341
|
else {
|
|
340
342
|
const disconnected = accountsFormated.find((v) => v == addressSignedIn) ? false : true;
|
|
341
|
-
if (
|
|
343
|
+
if (disconnected) {
|
|
342
344
|
set({
|
|
343
345
|
...$connection,
|
|
344
346
|
wallet: {
|
|
345
347
|
...$connection.wallet,
|
|
346
|
-
|
|
347
|
-
|
|
348
|
+
status: 'disconnected',
|
|
349
|
+
connecting: false,
|
|
348
350
|
},
|
|
349
351
|
});
|
|
352
|
+
alwaysOnProvider.setWalletStatus('disconnected');
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
set({
|
|
356
|
+
...$connection,
|
|
357
|
+
wallet: {
|
|
358
|
+
...$connection.wallet,
|
|
359
|
+
status: 'connected',
|
|
360
|
+
},
|
|
361
|
+
});
|
|
362
|
+
alwaysOnProvider.setWalletStatus('connected');
|
|
350
363
|
}
|
|
351
|
-
// TODO disconnected ?
|
|
352
364
|
}
|
|
353
365
|
if (accountsFormated.length > 0 && accountsFormated[0] != $connection.mechanism.address) {
|
|
354
366
|
set({
|
|
@@ -387,7 +399,8 @@ export function createConnection(settings) {
|
|
|
387
399
|
remember = !(options?.doNotStoreLocally || false);
|
|
388
400
|
if (mechanism) {
|
|
389
401
|
if (mechanism.type === 'wallet') {
|
|
390
|
-
const
|
|
402
|
+
const specificAddress = mechanism.address;
|
|
403
|
+
const walletName = mechanism.name || ($connection.wallets.length == 1 ? $connection.wallets[0].info.name : undefined);
|
|
391
404
|
if (walletName) {
|
|
392
405
|
const wallet = $connection.wallets.find((v) => v.info.name == walletName || v.info.uuid == walletName);
|
|
393
406
|
if (wallet) {
|
|
@@ -396,13 +409,13 @@ export function createConnection(settings) {
|
|
|
396
409
|
stopatchingForAccountChange(_wallet.provider);
|
|
397
410
|
stopatchingForChainIdChange(_wallet.provider);
|
|
398
411
|
}
|
|
399
|
-
const
|
|
412
|
+
const mechanismToSave = {
|
|
400
413
|
type: 'wallet',
|
|
401
414
|
name: walletName,
|
|
402
415
|
};
|
|
403
416
|
set({
|
|
404
417
|
step: 'WaitingForWalletConnection', // TODO FetchingAccounts
|
|
405
|
-
mechanism,
|
|
418
|
+
mechanism: mechanismToSave,
|
|
406
419
|
wallets: $connection.wallets,
|
|
407
420
|
wallet: undefined,
|
|
408
421
|
});
|
|
@@ -420,52 +433,69 @@ export function createConnection(settings) {
|
|
|
420
433
|
if (accounts.length === 0) {
|
|
421
434
|
set({
|
|
422
435
|
step: 'WaitingForWalletConnection', // TODO add another step to unlock ?
|
|
423
|
-
mechanism,
|
|
436
|
+
mechanism: mechanismToSave,
|
|
424
437
|
wallets: $connection.wallets,
|
|
425
438
|
wallet: undefined,
|
|
426
439
|
});
|
|
427
440
|
accounts = await provider.request({ method: 'eth_requestAccounts' });
|
|
428
441
|
accounts = accounts.map((v) => v.toLowerCase());
|
|
429
442
|
if (accounts.length > 0) {
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
443
|
+
const nextStep = !specificAddress && accounts.length > 1 ? 'ChooseWalletAccount' : 'WalletConnected';
|
|
444
|
+
let account = accounts[0];
|
|
445
|
+
if (specificAddress) {
|
|
446
|
+
if (accounts.find((v) => v === specificAddress)) {
|
|
447
|
+
account = specificAddress;
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
// TODO error
|
|
451
|
+
throw new Error(`could not find address ${specificAddress}`);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
const newState = nextStep === 'ChooseWalletAccount'
|
|
455
|
+
? {
|
|
456
|
+
step: nextStep,
|
|
457
|
+
mechanism: mechanismToSave,
|
|
439
458
|
wallets: $connection.wallets,
|
|
440
459
|
wallet: {
|
|
441
460
|
provider: _wallet.provider,
|
|
442
|
-
|
|
443
|
-
|
|
461
|
+
accounts,
|
|
462
|
+
status: 'connected',
|
|
444
463
|
accountChanged: undefined,
|
|
445
464
|
chainId,
|
|
446
465
|
invalidChainId: alwaysOnChainId != chainId,
|
|
447
466
|
switchingChain: false,
|
|
448
467
|
},
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
mechanism: walletMechanism,
|
|
468
|
+
}
|
|
469
|
+
: {
|
|
470
|
+
step: nextStep,
|
|
471
|
+
mechanism: {
|
|
472
|
+
...mechanismToSave,
|
|
473
|
+
address: account,
|
|
474
|
+
},
|
|
457
475
|
wallets: $connection.wallets,
|
|
458
476
|
wallet: {
|
|
459
477
|
provider: _wallet.provider,
|
|
460
|
-
|
|
461
|
-
|
|
478
|
+
accounts,
|
|
479
|
+
status: 'connected',
|
|
462
480
|
accountChanged: undefined,
|
|
463
481
|
chainId,
|
|
464
482
|
invalidChainId: alwaysOnChainId != chainId,
|
|
465
483
|
switchingChain: false,
|
|
466
484
|
},
|
|
467
|
-
}
|
|
468
|
-
|
|
485
|
+
};
|
|
486
|
+
if (newState.step === 'WalletConnected' && options?.requestSignatureRightAway) {
|
|
487
|
+
watchForAccountChange(_wallet.provider);
|
|
488
|
+
set(newState);
|
|
489
|
+
alwaysOnProvider.setWalletStatus('connected');
|
|
490
|
+
saveLastWallet(newState.mechanism);
|
|
491
|
+
await requestSignature();
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
set(newState);
|
|
495
|
+
alwaysOnProvider.setWalletStatus('connected');
|
|
496
|
+
if (newState.step === 'WalletConnected') {
|
|
497
|
+
saveLastWallet(newState.mechanism);
|
|
498
|
+
}
|
|
469
499
|
watchForAccountChange(_wallet.provider);
|
|
470
500
|
}
|
|
471
501
|
}
|
|
@@ -479,47 +509,66 @@ export function createConnection(settings) {
|
|
|
479
509
|
}
|
|
480
510
|
}
|
|
481
511
|
else {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
512
|
+
let account = accounts[0];
|
|
513
|
+
if (specificAddress) {
|
|
514
|
+
if (accounts.find((v) => v === specificAddress)) {
|
|
515
|
+
account = specificAddress;
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
// TODO error
|
|
519
|
+
throw new Error(`could not find address ${specificAddress}`);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
const nextStep = !specificAddress && accounts.length > 1 ? 'ChooseWalletAccount' : 'WalletConnected';
|
|
523
|
+
const newState = nextStep === 'ChooseWalletAccount'
|
|
524
|
+
? {
|
|
525
|
+
step: nextStep,
|
|
526
|
+
mechanism: mechanismToSave,
|
|
490
527
|
wallets: $connection.wallets,
|
|
491
528
|
wallet: {
|
|
492
529
|
provider: _wallet.provider,
|
|
493
|
-
|
|
494
|
-
|
|
530
|
+
accounts,
|
|
531
|
+
status: 'connected',
|
|
495
532
|
accountChanged: undefined,
|
|
496
533
|
chainId,
|
|
497
534
|
invalidChainId: alwaysOnChainId != chainId,
|
|
498
535
|
switchingChain: false,
|
|
499
536
|
},
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
step: 'WalletConnected',
|
|
508
|
-
mechanism: walletMechanism,
|
|
537
|
+
}
|
|
538
|
+
: {
|
|
539
|
+
step: nextStep,
|
|
540
|
+
mechanism: {
|
|
541
|
+
...mechanismToSave,
|
|
542
|
+
address: account,
|
|
543
|
+
},
|
|
509
544
|
wallets: $connection.wallets,
|
|
510
545
|
wallet: {
|
|
511
546
|
provider: _wallet.provider,
|
|
512
|
-
|
|
513
|
-
|
|
547
|
+
accounts,
|
|
548
|
+
status: 'connected',
|
|
514
549
|
accountChanged: undefined,
|
|
515
550
|
chainId,
|
|
516
551
|
invalidChainId: alwaysOnChainId != chainId,
|
|
517
552
|
switchingChain: false,
|
|
518
553
|
},
|
|
519
|
-
}
|
|
520
|
-
|
|
554
|
+
};
|
|
555
|
+
if (newState.step === 'WalletConnected' &&
|
|
556
|
+
requestSignatureAutomaticallyIfPossible &&
|
|
557
|
+
!options?.requireUserConfirmationBeforeSignatureRequest) {
|
|
558
|
+
set(newState);
|
|
559
|
+
alwaysOnProvider.setWalletStatus('connected');
|
|
560
|
+
saveLastWallet(newState.mechanism);
|
|
561
|
+
watchForAccountChange(_wallet.provider);
|
|
521
562
|
await requestSignature();
|
|
522
563
|
}
|
|
564
|
+
else {
|
|
565
|
+
watchForAccountChange(_wallet.provider);
|
|
566
|
+
set(newState);
|
|
567
|
+
alwaysOnProvider.setWalletStatus('connected');
|
|
568
|
+
if (newState.step === 'WalletConnected') {
|
|
569
|
+
saveLastWallet(newState.mechanism);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
523
572
|
}
|
|
524
573
|
}
|
|
525
574
|
else {
|
|
@@ -710,12 +759,29 @@ export function createConnection(settings) {
|
|
|
710
759
|
throw new Error(`no saved public key publication signature for ${account.address}`);
|
|
711
760
|
}
|
|
712
761
|
async function unlock() {
|
|
713
|
-
|
|
762
|
+
const wallet = $connection.wallet;
|
|
763
|
+
if (!wallet || wallet.status !== 'locked') {
|
|
714
764
|
throw new Error(`invalid state`);
|
|
715
765
|
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
766
|
+
set({
|
|
767
|
+
...$connection,
|
|
768
|
+
wallet: {
|
|
769
|
+
...wallet,
|
|
770
|
+
unlocking: true,
|
|
771
|
+
},
|
|
772
|
+
});
|
|
773
|
+
try {
|
|
774
|
+
await wallet.provider.request({ method: 'eth_requestAccounts' }).then(onAccountChanged);
|
|
775
|
+
}
|
|
776
|
+
catch {
|
|
777
|
+
set({
|
|
778
|
+
...$connection,
|
|
779
|
+
wallet: {
|
|
780
|
+
...wallet,
|
|
781
|
+
unlocking: false,
|
|
782
|
+
},
|
|
783
|
+
});
|
|
784
|
+
}
|
|
719
785
|
}
|
|
720
786
|
async function switchWalletChain(chainId, config) {
|
|
721
787
|
if (!$connection.wallet) {
|
|
@@ -876,7 +942,7 @@ export function createConnection(settings) {
|
|
|
876
942
|
cancel,
|
|
877
943
|
back,
|
|
878
944
|
requestSignature,
|
|
879
|
-
|
|
945
|
+
connecToAddress,
|
|
880
946
|
disconnect,
|
|
881
947
|
getSignatureForPublicKeyPublication,
|
|
882
948
|
switchWalletChain,
|