@reown/appkit 1.6.0 → 1.6.1-rc.1.0
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/esm/exports/constants.js +1 -1
- package/dist/esm/exports/constants.js.map +1 -1
- package/dist/esm/package.json +5 -5
- package/dist/esm/src/adapters/ChainAdapterBlueprint.js +10 -9
- package/dist/esm/src/adapters/ChainAdapterBlueprint.js.map +1 -1
- package/dist/esm/src/client.js +97 -107
- package/dist/esm/src/client.js.map +1 -1
- package/dist/esm/src/library/react/index.js.map +1 -1
- package/dist/esm/src/universal-adapter/client.js +8 -1
- package/dist/esm/src/universal-adapter/client.js.map +1 -1
- package/dist/esm/src/utils/HelpersUtil.js +13 -0
- package/dist/esm/src/utils/HelpersUtil.js.map +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/exports/constants.d.ts +1 -1
- package/dist/types/src/adapters/ChainAdapterBlueprint.d.ts +4 -9
- package/dist/types/src/adapters/index.d.ts +1 -0
- package/dist/types/src/client.d.ts +8 -2
- package/dist/types/src/library/react/index.d.ts +1 -0
- package/dist/types/src/universal-adapter/client.d.ts +1 -0
- package/dist/types/src/utils/HelpersUtil.d.ts +14 -0
- package/dist/types/src/utils/TypesUtil.d.ts +8 -5
- package/package.json +13 -13
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const PACKAGE_VERSION = '1.6.0';
|
|
1
|
+
export const PACKAGE_VERSION = '1.6.1-rc.1.0';
|
|
2
2
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../exports/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../exports/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,cAAc,CAAA"}
|
package/dist/esm/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reown/appkit",
|
|
3
|
-
"version": "1.6.0",
|
|
3
|
+
"version": "1.6.1-rc.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/esm/exports/index.js",
|
|
6
6
|
"types": "./dist/types/exports/index.d.ts",
|
|
@@ -105,9 +105,9 @@
|
|
|
105
105
|
"@reown/appkit-ui": "workspace:*",
|
|
106
106
|
"@reown/appkit-utils": "workspace:*",
|
|
107
107
|
"@reown/appkit-wallet": "workspace:*",
|
|
108
|
-
"@walletconnect/types": "2.17.
|
|
109
|
-
"@walletconnect/universal-provider": "2.17.
|
|
110
|
-
"@walletconnect/utils": "2.17.
|
|
108
|
+
"@walletconnect/types": "2.17.2",
|
|
109
|
+
"@walletconnect/universal-provider": "2.17.2",
|
|
110
|
+
"@walletconnect/utils": "2.17.2",
|
|
111
111
|
"bs58": "6.0.0",
|
|
112
112
|
"valtio": "1.11.2",
|
|
113
113
|
"viem": "2.x"
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"@vitest/coverage-v8": "2.1.3",
|
|
119
119
|
"@vue/runtime-core": "3.4.3",
|
|
120
120
|
"@walletconnect/types": "2.13.3",
|
|
121
|
-
"@walletconnect/universal-provider": "2.17.
|
|
121
|
+
"@walletconnect/universal-provider": "2.17.2",
|
|
122
122
|
"react": "18.3.1",
|
|
123
123
|
"react-dom": "18.3.1",
|
|
124
124
|
"vitest": "2.1.3",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { getW3mThemeVariables } from '@reown/appkit-common';
|
|
1
|
+
import { getW3mThemeVariables, ConstantsUtil as CommonConstantsUtil } from '@reown/appkit-common';
|
|
2
2
|
import { AccountController, OptionsController, ThemeController } from '@reown/appkit-core';
|
|
3
|
-
import {
|
|
3
|
+
import { PresetsUtil } from '@reown/appkit-utils';
|
|
4
4
|
import { snapshot } from 'valtio/vanilla';
|
|
5
5
|
/**
|
|
6
6
|
* Abstract class representing a chain adapter blueprint.
|
|
@@ -47,11 +47,11 @@ export class AdapterBlueprint {
|
|
|
47
47
|
*/
|
|
48
48
|
setUniversalProvider(universalProvider) {
|
|
49
49
|
this.addConnector({
|
|
50
|
-
id:
|
|
50
|
+
id: CommonConstantsUtil.CONNECTOR_ID.WALLET_CONNECT,
|
|
51
51
|
type: 'WALLET_CONNECT',
|
|
52
|
-
name: PresetsUtil.ConnectorNamesMap[
|
|
52
|
+
name: PresetsUtil.ConnectorNamesMap[CommonConstantsUtil.CONNECTOR_ID.WALLET_CONNECT],
|
|
53
53
|
provider: universalProvider,
|
|
54
|
-
imageId: PresetsUtil.ConnectorImageIds[
|
|
54
|
+
imageId: PresetsUtil.ConnectorImageIds[CommonConstantsUtil.CONNECTOR_ID.WALLET_CONNECT],
|
|
55
55
|
chain: this.namespace,
|
|
56
56
|
chains: []
|
|
57
57
|
});
|
|
@@ -62,11 +62,11 @@ export class AdapterBlueprint {
|
|
|
62
62
|
*/
|
|
63
63
|
setAuthProvider(authProvider) {
|
|
64
64
|
this.addConnector({
|
|
65
|
-
id:
|
|
65
|
+
id: CommonConstantsUtil.CONNECTOR_ID.AUTH,
|
|
66
66
|
type: 'AUTH',
|
|
67
67
|
name: 'Auth',
|
|
68
68
|
provider: authProvider,
|
|
69
|
-
imageId: PresetsUtil.ConnectorImageIds[
|
|
69
|
+
imageId: PresetsUtil.ConnectorImageIds[CommonConstantsUtil.CONNECTOR_ID.AUTH],
|
|
70
70
|
chain: this.namespace,
|
|
71
71
|
chains: []
|
|
72
72
|
});
|
|
@@ -76,8 +76,8 @@ export class AdapterBlueprint {
|
|
|
76
76
|
* @param {...Connector} connectors - The connectors to add
|
|
77
77
|
*/
|
|
78
78
|
addConnector(...connectors) {
|
|
79
|
-
if (connectors.some(connector => connector.id ===
|
|
80
|
-
const authConnector = connectors.find(connector => connector.id ===
|
|
79
|
+
if (connectors.some(connector => connector.id === CommonConstantsUtil.CONNECTOR_ID.AUTH)) {
|
|
80
|
+
const authConnector = connectors.find(connector => connector.id === CommonConstantsUtil.CONNECTOR_ID.AUTH);
|
|
81
81
|
const optionsState = snapshot(OptionsController.state);
|
|
82
82
|
const themeMode = ThemeController.getSnapshot().themeMode;
|
|
83
83
|
const themeVariables = ThemeController.getSnapshot().themeVariables;
|
|
@@ -101,6 +101,7 @@ export class AdapterBlueprint {
|
|
|
101
101
|
connectorsAdded.add(connector.id);
|
|
102
102
|
return true;
|
|
103
103
|
});
|
|
104
|
+
this.emit('connectors', this.availableConnectors);
|
|
104
105
|
}
|
|
105
106
|
setStatus(status, chainNamespace) {
|
|
106
107
|
AccountController.setStatus(status, chainNamespace);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChainAdapterBlueprint.js","sourceRoot":"","sources":["../../../../src/adapters/ChainAdapterBlueprint.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,
|
|
1
|
+
{"version":3,"file":"ChainAdapterBlueprint.js","sourceRoot":"","sources":["../../../../src/adapters/ChainAdapterBlueprint.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,aAAa,IAAI,mBAAmB,EAIrC,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EAQhB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAGjD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAiBzC;;;GAGG;AACH,MAAM,OAAgB,gBAAgB;IAapC;;;OAGG;IACH,YAAY,MAAgC;QAVlC,wBAAmB,GAAgB,EAAE,CAAA;QAIvC,mBAAc,GAAG,IAAI,GAAG,EAA4C,CAAA;QAO1E,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;QACxB,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,SAAS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CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAA;IACnD,CAAC;IAES,SAAS,CAAC,MAAwC,EAAE,cAA+B;QAC3F,iBAAiB,CAAC,SAAS,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IACrD,CAAC;IAED;;;;;OAKG;IACI,EAAE,CAAsB,SAAY,EAAE,QAA0B;QACrE,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YACxC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,GAAG,EAAE,CAAC,CAAA;QAC/C,CAAC;QAED,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,QAAoC,CAAC,CAAA;IAC/E,CAAC;IAED;;;;;OAKG;IACI,GAAG,CAAsB,SAAY,EAAE,QAA0B;QACtE,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;QACpD,IAAI,SAAS,EAAE,CAAC;YACd,SAAS,CAAC,MAAM,CAAC,QAAoC,CAAC,CAAA;QACxD,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACO,IAAI,CAAsB,SAAY,EAAE,IAAmB;QACnE,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;QACpD,IAAI,SAAS,EAAE,CAAC;YACd,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAoB,CAAC,CAAC,CAAA;QAC/D,CAAC;IACH,CAAC;CAkKF"}
|
package/dist/esm/src/client.js
CHANGED
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
import { ConstantsUtil as CoreConstantsUtil, SIWXUtil } from '@reown/appkit-core';
|
|
3
3
|
import { AccountController, BlockchainApiController, ConnectionController, ConnectorController, CoreHelperUtil, EventsController, ModalController, ChainController, PublicStateController, ThemeController, SnackController, RouterController, EnsController, OptionsController, AssetUtil, ApiController, AlertController, StorageUtil } from '@reown/appkit-core';
|
|
4
4
|
import { setColorTheme, setThemeVariables } from '@reown/appkit-ui';
|
|
5
|
-
import { ConstantsUtil,
|
|
5
|
+
import { NetworkUtil, ConstantsUtil, ParseUtil } from '@reown/appkit-common';
|
|
6
6
|
import { UniversalAdapter, UniversalAdapter as UniversalAdapterClient } from './universal-adapter/client.js';
|
|
7
7
|
import { CaipNetworksUtil, ErrorUtil, LoggerUtil, ConstantsUtil as UtilConstantsUtil } from '@reown/appkit-utils';
|
|
8
8
|
import { W3mFrameHelpers, W3mFrameRpcConstants } from '@reown/appkit-wallet';
|
|
9
9
|
import { ProviderUtil } from './store/ProviderUtil.js';
|
|
10
10
|
import UniversalProvider from '@walletconnect/universal-provider';
|
|
11
11
|
import { W3mFrameProviderSingleton } from './auth-provider/W3MFrameProviderSingleton.js';
|
|
12
|
+
import { WcHelpersUtil } from './utils/HelpersUtil.js';
|
|
13
|
+
import { WalletUtil } from '@reown/appkit-scaffold-ui/utils';
|
|
12
14
|
// -- Export Controllers -------------------------------------------------------
|
|
13
15
|
export { AccountController };
|
|
14
16
|
// -- Constants ----------------------------------------- //
|
|
@@ -189,12 +191,10 @@ export class AppKit {
|
|
|
189
191
|
async initialize(options) {
|
|
190
192
|
this.caipNetworks = this.extendCaipNetworks(options);
|
|
191
193
|
this.defaultCaipNetwork = this.extendDefaultCaipNetwork(options);
|
|
192
|
-
|
|
193
|
-
this.createAuthProvider();
|
|
194
|
-
await this.createUniversalProvider();
|
|
194
|
+
this.initControllers(options);
|
|
195
195
|
this.createClients();
|
|
196
196
|
ChainController.initialize(options.adapters ?? [], this.caipNetworks);
|
|
197
|
-
this.chainAdapters =
|
|
197
|
+
this.chainAdapters = this.createAdapters(options.adapters);
|
|
198
198
|
await this.initChainAdapters();
|
|
199
199
|
this.syncRequestedNetworks();
|
|
200
200
|
await this.initOrContinue();
|
|
@@ -213,10 +213,14 @@ export class AppKit {
|
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
});
|
|
216
|
+
PublicStateController.set({ initialized: true });
|
|
216
217
|
}
|
|
217
218
|
// -- Public -------------------------------------------------------------------
|
|
218
219
|
async open(options) {
|
|
219
220
|
await this.initOrContinue();
|
|
221
|
+
if (options?.uri && this.universalAdapter) {
|
|
222
|
+
ConnectionController.setUri(options.uri);
|
|
223
|
+
}
|
|
220
224
|
ModalController.open(options);
|
|
221
225
|
}
|
|
222
226
|
async close() {
|
|
@@ -369,17 +373,22 @@ export class AppKit {
|
|
|
369
373
|
async disconnect() {
|
|
370
374
|
await this.connectionControllerClient?.disconnect();
|
|
371
375
|
}
|
|
376
|
+
getConnectMethodsOrder() {
|
|
377
|
+
return WalletUtil.getConnectOrderMethod(OptionsController.state.features, ConnectorController.getConnectors());
|
|
378
|
+
}
|
|
372
379
|
// -- Private ------------------------------------------------------------------
|
|
373
|
-
|
|
380
|
+
initControllers(options) {
|
|
374
381
|
OptionsController.setDebug(options.debug !== false);
|
|
375
382
|
OptionsController.setProjectId(options.projectId);
|
|
376
383
|
OptionsController.setSdkVersion(options.sdkVersion);
|
|
377
384
|
OptionsController.setEnableEmbedded(options.enableEmbedded);
|
|
385
|
+
if (options.allowUnsupportedChain) {
|
|
386
|
+
OptionsController.setAllowUnsupportedChain(options.allowUnsupportedChain);
|
|
387
|
+
}
|
|
378
388
|
if (!options.projectId) {
|
|
379
389
|
AlertController.open(ErrorUtil.ALERT_ERRORS.PROJECT_ID_NOT_CONFIGURED, 'error');
|
|
380
390
|
return;
|
|
381
391
|
}
|
|
382
|
-
this.adapters = options.adapters;
|
|
383
392
|
const defaultMetaData = this.getDefaultMetaData();
|
|
384
393
|
if (!options.metadata && defaultMetaData) {
|
|
385
394
|
options.metadata = defaultMetaData;
|
|
@@ -423,18 +432,14 @@ export class AppKit {
|
|
|
423
432
|
if (options.siwx) {
|
|
424
433
|
throw new Error('Cannot set both `siweConfig` and `siwx` options');
|
|
425
434
|
}
|
|
426
|
-
|
|
427
|
-
if (typeof siwe.mapToSIWX !== 'function') {
|
|
428
|
-
throw new Error('Please update the `@reown/appkit-siwe` package to the latest version');
|
|
429
|
-
}
|
|
430
|
-
OptionsController.setSIWX(siwe.mapToSIWX(options.siweConfig));
|
|
435
|
+
OptionsController.setSIWX(options.siweConfig.mapToSIWX());
|
|
431
436
|
}
|
|
432
437
|
}
|
|
433
438
|
}
|
|
434
439
|
getDefaultMetaData() {
|
|
435
440
|
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
436
441
|
return {
|
|
437
|
-
name: document.getElementsByTagName('title')[0]?.textContent || '',
|
|
442
|
+
name: document.getElementsByTagName('title')?.[0]?.textContent || '',
|
|
438
443
|
description: document.querySelector('meta[property="og:description"]')?.content || '',
|
|
439
444
|
url: window.location.origin,
|
|
440
445
|
icons: [document.querySelector('link[rel~="icon"]')?.href || '']
|
|
@@ -484,9 +489,7 @@ export class AppKit {
|
|
|
484
489
|
this.connectionControllerClient = {
|
|
485
490
|
connectWalletConnect: async (onUri) => {
|
|
486
491
|
const adapter = this.getAdapter(ChainController.state.activeChain);
|
|
487
|
-
this.universalProvider?.on('display_uri',
|
|
488
|
-
onUri(uri);
|
|
489
|
-
});
|
|
492
|
+
this.universalProvider?.on('display_uri', onUri);
|
|
490
493
|
this.setClientId((await this.universalProvider?.client?.core?.crypto?.getClientId()) || null);
|
|
491
494
|
let isAuthenticated = false;
|
|
492
495
|
if (this.universalProvider) {
|
|
@@ -518,37 +521,15 @@ export class AppKit {
|
|
|
518
521
|
if (!adapter) {
|
|
519
522
|
throw new Error('Adapter not found');
|
|
520
523
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
this.getCaipNetwork()?.rpcUrls?.default?.http?.[0]
|
|
531
|
-
});
|
|
532
|
-
/**
|
|
533
|
-
* In some cases with wagmi connectors, the connector is already connected
|
|
534
|
-
* which throws an `Is already connected`error. In such cases, we need to reconnect
|
|
535
|
-
* to restore the session.
|
|
536
|
-
* We check if the reconnect method exists (which it does for wagmi connectors) and if so
|
|
537
|
-
* we attempt to reconnect and restore the session state.
|
|
538
|
-
*/
|
|
539
|
-
}
|
|
540
|
-
catch (error) {
|
|
541
|
-
if (!adapter?.reconnect) {
|
|
542
|
-
throw new Error('Adapter is not able to connect');
|
|
543
|
-
}
|
|
544
|
-
await adapter.reconnect({
|
|
545
|
-
id,
|
|
546
|
-
info,
|
|
547
|
-
type,
|
|
548
|
-
provider,
|
|
549
|
-
chainId: this.getCaipNetwork()?.id
|
|
550
|
-
});
|
|
551
|
-
}
|
|
524
|
+
const res = await adapter.connect({
|
|
525
|
+
id,
|
|
526
|
+
info,
|
|
527
|
+
type,
|
|
528
|
+
provider,
|
|
529
|
+
chainId: caipNetwork?.id || this.getCaipNetwork()?.id,
|
|
530
|
+
rpcUrl: caipNetwork?.rpcUrls?.default?.http?.[0] ||
|
|
531
|
+
this.getCaipNetwork()?.rpcUrls?.default?.http?.[0]
|
|
532
|
+
});
|
|
552
533
|
if (res) {
|
|
553
534
|
this.syncProvider({
|
|
554
535
|
...res,
|
|
@@ -578,12 +559,8 @@ export class AppKit {
|
|
|
578
559
|
const provider = ProviderUtil.getProvider(ChainController.state.activeChain);
|
|
579
560
|
const providerType = ProviderUtil.state.providerIds[ChainController.state.activeChain];
|
|
580
561
|
await adapter?.disconnect({ provider, providerType });
|
|
562
|
+
ProviderUtil.resetChain(ChainController.state.activeChain);
|
|
581
563
|
this.setStatus('disconnected', ChainController.state.activeChain);
|
|
582
|
-
StorageUtil.deleteConnectedConnector();
|
|
583
|
-
StorageUtil.deleteActiveCaipNetworkId();
|
|
584
|
-
ChainController.state.chains.forEach(chain => {
|
|
585
|
-
this.resetAccount(chain.namespace);
|
|
586
|
-
});
|
|
587
564
|
},
|
|
588
565
|
checkInstalled: (ids) => {
|
|
589
566
|
if (!ids) {
|
|
@@ -603,7 +580,8 @@ export class AppKit {
|
|
|
603
580
|
sendTransaction: async (args) => {
|
|
604
581
|
if (args.chainNamespace === 'eip155') {
|
|
605
582
|
const adapter = this.getAdapter(ChainController.state.activeChain);
|
|
606
|
-
const
|
|
583
|
+
const provider = ProviderUtil.getProvider(ChainController.state.activeChain);
|
|
584
|
+
const result = await adapter?.sendTransaction({ ...args, provider });
|
|
607
585
|
return result?.hash || '';
|
|
608
586
|
}
|
|
609
587
|
return '';
|
|
@@ -704,7 +682,7 @@ export class AppKit {
|
|
|
704
682
|
try {
|
|
705
683
|
ChainController.state.activeChain = caipNetwork.chainNamespace;
|
|
706
684
|
await this.connectionControllerClient?.connectExternal?.({
|
|
707
|
-
id:
|
|
685
|
+
id: ConstantsUtil.CONNECTOR_ID.AUTH,
|
|
708
686
|
provider: this.authProvider,
|
|
709
687
|
chain: caipNetwork.chainNamespace,
|
|
710
688
|
chainId: caipNetwork.id,
|
|
@@ -822,8 +800,8 @@ export class AppKit {
|
|
|
822
800
|
}
|
|
823
801
|
});
|
|
824
802
|
provider.onNotConnected(() => {
|
|
825
|
-
const
|
|
826
|
-
const isConnectedWithAuth =
|
|
803
|
+
const connectorId = StorageUtil.getConnectedConnectorId();
|
|
804
|
+
const isConnectedWithAuth = connectorId === ConstantsUtil.CONNECTOR_ID.AUTH;
|
|
827
805
|
if (!isConnected && isConnectedWithAuth) {
|
|
828
806
|
this.setCaipAddress(undefined, ChainController.state.activeChain);
|
|
829
807
|
this.setLoading(false);
|
|
@@ -837,7 +815,7 @@ export class AppKit {
|
|
|
837
815
|
this.syncProvider({
|
|
838
816
|
type: UtilConstantsUtil.CONNECTOR_TYPE_AUTH,
|
|
839
817
|
provider,
|
|
840
|
-
id:
|
|
818
|
+
id: ConstantsUtil.CONNECTOR_ID.AUTH,
|
|
841
819
|
chainNamespace: namespace
|
|
842
820
|
});
|
|
843
821
|
// To keep backwards compatibility, eip155 chainIds are numbers and not actual caipChainIds
|
|
@@ -866,8 +844,8 @@ export class AppKit {
|
|
|
866
844
|
});
|
|
867
845
|
if (isConnected && this.connectionControllerClient?.connectExternal) {
|
|
868
846
|
await this.connectionControllerClient?.connectExternal({
|
|
869
|
-
id:
|
|
870
|
-
info: { name:
|
|
847
|
+
id: ConstantsUtil.CONNECTOR_ID.AUTH,
|
|
848
|
+
info: { name: ConstantsUtil.CONNECTOR_ID.AUTH },
|
|
871
849
|
type: UtilConstantsUtil.CONNECTOR_TYPE_AUTH,
|
|
872
850
|
provider,
|
|
873
851
|
chainId: ChainController.state.activeCaipNetwork?.id
|
|
@@ -901,6 +879,16 @@ export class AppKit {
|
|
|
901
879
|
this.setCaipNetwork(caipNetwork);
|
|
902
880
|
}
|
|
903
881
|
});
|
|
882
|
+
this.universalProvider.on('session_event', (callbackData) => {
|
|
883
|
+
if (WcHelpersUtil.isSessionEventData(callbackData)) {
|
|
884
|
+
const { name, data } = callbackData.params.event;
|
|
885
|
+
if (name === 'accountsChanged' &&
|
|
886
|
+
Array.isArray(data) &&
|
|
887
|
+
CoreHelperUtil.isCaipAddress(data[0])) {
|
|
888
|
+
this.syncAccount(ParseUtil.parseCaipAddress(data[0]));
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
});
|
|
904
892
|
}
|
|
905
893
|
}
|
|
906
894
|
listenAdapter(chainNamespace) {
|
|
@@ -1005,7 +993,7 @@ export class AppKit {
|
|
|
1005
993
|
else {
|
|
1006
994
|
ProviderUtil.setProvider(chainNamespace, this.universalProvider);
|
|
1007
995
|
}
|
|
1008
|
-
StorageUtil.
|
|
996
|
+
StorageUtil.setConnectedConnectorId(ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT);
|
|
1009
997
|
let address = '';
|
|
1010
998
|
if (caipAddress.split(':').length === 3) {
|
|
1011
999
|
address = caipAddress.split(':')[2];
|
|
@@ -1060,7 +1048,7 @@ export class AppKit {
|
|
|
1060
1048
|
syncProvider({ type, provider, id, chainNamespace }) {
|
|
1061
1049
|
ProviderUtil.setProviderId(chainNamespace, type);
|
|
1062
1050
|
ProviderUtil.setProvider(chainNamespace, provider);
|
|
1063
|
-
StorageUtil.
|
|
1051
|
+
StorageUtil.setConnectedConnectorId(id);
|
|
1064
1052
|
}
|
|
1065
1053
|
async syncAccount({ address, chainId, chainNamespace }) {
|
|
1066
1054
|
const { namespace: activeNamespace, chainId: activeChainId } = StorageUtil.getActiveNetworkProps();
|
|
@@ -1096,12 +1084,12 @@ export class AppKit {
|
|
|
1096
1084
|
}
|
|
1097
1085
|
}
|
|
1098
1086
|
syncConnectedWalletInfo(chainNamespace) {
|
|
1099
|
-
const
|
|
1087
|
+
const connectorId = StorageUtil.getConnectedConnectorId();
|
|
1100
1088
|
const providerType = ProviderUtil.state.providerIds[chainNamespace];
|
|
1101
1089
|
if (providerType === UtilConstantsUtil.CONNECTOR_TYPE_ANNOUNCED ||
|
|
1102
1090
|
providerType === UtilConstantsUtil.CONNECTOR_TYPE_INJECTED) {
|
|
1103
|
-
if (
|
|
1104
|
-
const connector = this.getConnectors().find(c => c.id ===
|
|
1091
|
+
if (connectorId) {
|
|
1092
|
+
const connector = this.getConnectors().find(c => c.id === connectorId);
|
|
1105
1093
|
if (connector?.info) {
|
|
1106
1094
|
this.setConnectedWalletInfo({ ...connector.info }, chainNamespace);
|
|
1107
1095
|
}
|
|
@@ -1117,12 +1105,12 @@ export class AppKit {
|
|
|
1117
1105
|
}, chainNamespace);
|
|
1118
1106
|
}
|
|
1119
1107
|
}
|
|
1120
|
-
else if (
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
this.setConnectedWalletInfo({ name:
|
|
1108
|
+
else if (connectorId) {
|
|
1109
|
+
if (connectorId === ConstantsUtil.CONNECTOR_ID.COINBASE) {
|
|
1110
|
+
const connector = this.getConnectors().find(c => c.id === ConstantsUtil.CONNECTOR_ID.COINBASE);
|
|
1111
|
+
this.setConnectedWalletInfo({ name: 'Coinbase Wallet', icon: this.getConnectorImage(connector) }, chainNamespace);
|
|
1112
|
+
}
|
|
1113
|
+
this.setConnectedWalletInfo({ name: connectorId }, chainNamespace);
|
|
1126
1114
|
}
|
|
1127
1115
|
}
|
|
1128
1116
|
async syncIdentity({ address, chainId, chainNamespace }) {
|
|
@@ -1188,18 +1176,16 @@ export class AppKit {
|
|
|
1188
1176
|
[], chainNamespace));
|
|
1189
1177
|
}
|
|
1190
1178
|
async syncExistingConnection() {
|
|
1191
|
-
const
|
|
1179
|
+
const connectorId = StorageUtil.getConnectedConnectorId();
|
|
1192
1180
|
const activeNamespace = StorageUtil.getActiveNamespace();
|
|
1193
|
-
if (
|
|
1181
|
+
if (connectorId === ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT && activeNamespace) {
|
|
1194
1182
|
this.syncWalletConnectAccount();
|
|
1195
1183
|
}
|
|
1196
|
-
else if (
|
|
1197
|
-
connectedConnector !== UtilConstantsUtil.CONNECTOR_TYPE_W3M_AUTH &&
|
|
1198
|
-
activeNamespace) {
|
|
1184
|
+
else if (connectorId && connectorId !== ConstantsUtil.CONNECTOR_ID.AUTH && activeNamespace) {
|
|
1199
1185
|
this.setStatus('connecting', activeNamespace);
|
|
1200
1186
|
const adapter = this.getAdapter(activeNamespace);
|
|
1201
1187
|
const res = await adapter?.syncConnection({
|
|
1202
|
-
id:
|
|
1188
|
+
id: connectorId,
|
|
1203
1189
|
chainId: this.getCaipNetwork()?.id,
|
|
1204
1190
|
namespace: activeNamespace,
|
|
1205
1191
|
rpcUrl: this.getCaipNetwork()?.rpcUrls?.default?.http?.[0]
|
|
@@ -1207,7 +1193,7 @@ export class AppKit {
|
|
|
1207
1193
|
if (res) {
|
|
1208
1194
|
const accounts = await adapter?.getAccounts({
|
|
1209
1195
|
namespace: activeNamespace,
|
|
1210
|
-
id:
|
|
1196
|
+
id: connectorId
|
|
1211
1197
|
});
|
|
1212
1198
|
this.syncProvider({ ...res, chainNamespace: activeNamespace });
|
|
1213
1199
|
await this.syncAccount({ ...res, chainNamespace: activeNamespace });
|
|
@@ -1223,7 +1209,7 @@ export class AppKit {
|
|
|
1223
1209
|
}
|
|
1224
1210
|
}
|
|
1225
1211
|
}
|
|
1226
|
-
else if (
|
|
1212
|
+
else if (connectorId !== ConstantsUtil.CONNECTOR_ID.AUTH) {
|
|
1227
1213
|
this.setStatus('disconnected', ChainController.state.activeChain);
|
|
1228
1214
|
}
|
|
1229
1215
|
}
|
|
@@ -1232,7 +1218,7 @@ export class AppKit {
|
|
|
1232
1218
|
}
|
|
1233
1219
|
createUniversalProvider() {
|
|
1234
1220
|
if (!this.universalProviderInitPromise &&
|
|
1235
|
-
|
|
1221
|
+
CoreHelperUtil.isClient() &&
|
|
1236
1222
|
this.options?.projectId) {
|
|
1237
1223
|
this.universalProviderInitPromise = this.initializeUniversalAdapter();
|
|
1238
1224
|
}
|
|
@@ -1268,7 +1254,10 @@ export class AppKit {
|
|
|
1268
1254
|
},
|
|
1269
1255
|
logger
|
|
1270
1256
|
};
|
|
1271
|
-
this.universalProvider
|
|
1257
|
+
OptionsController.setUsingInjectedUniversalProvider(Boolean(this.options?.universalProvider));
|
|
1258
|
+
this.universalProvider =
|
|
1259
|
+
this.options.universalProvider ?? (await UniversalProvider.init(universalProviderOptions));
|
|
1260
|
+
this.listenWalletConnect();
|
|
1272
1261
|
}
|
|
1273
1262
|
async getUniversalProvider() {
|
|
1274
1263
|
if (!this.universalProvider) {
|
|
@@ -1282,13 +1271,13 @@ export class AppKit {
|
|
|
1282
1271
|
return this.universalProvider;
|
|
1283
1272
|
}
|
|
1284
1273
|
createAuthProvider() {
|
|
1285
|
-
const
|
|
1274
|
+
const isEmailEnabled = this.options?.features?.email === undefined
|
|
1286
1275
|
? CoreConstantsUtil.DEFAULT_FEATURES.email
|
|
1287
1276
|
: this.options?.features?.email;
|
|
1288
|
-
const
|
|
1277
|
+
const isSocialsEnabled = this.options?.features?.socials
|
|
1289
1278
|
? this.options?.features?.socials?.length > 0
|
|
1290
1279
|
: CoreConstantsUtil.DEFAULT_FEATURES.socials;
|
|
1291
|
-
if (this.options?.projectId && (
|
|
1280
|
+
if (!this.authProvider && this.options?.projectId && (isEmailEnabled || isSocialsEnabled)) {
|
|
1292
1281
|
this.authProvider = W3mFrameProviderSingleton.getInstance({
|
|
1293
1282
|
projectId: this.options.projectId,
|
|
1294
1283
|
onTimeout: () => {
|
|
@@ -1298,10 +1287,19 @@ export class AppKit {
|
|
|
1298
1287
|
this.listenAuthConnector(this.authProvider);
|
|
1299
1288
|
}
|
|
1300
1289
|
}
|
|
1301
|
-
async
|
|
1302
|
-
|
|
1303
|
-
|
|
1290
|
+
async createUniversalProviderForAdapter(chainNamespace) {
|
|
1291
|
+
await this.getUniversalProvider();
|
|
1292
|
+
if (this.universalProvider) {
|
|
1293
|
+
this.chainAdapters?.[chainNamespace]?.setUniversalProvider?.(this.universalProvider);
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
createAuthProviderForAdapter(chainNamespace) {
|
|
1297
|
+
this.createAuthProvider();
|
|
1298
|
+
if (this.authProvider) {
|
|
1299
|
+
this.chainAdapters?.[chainNamespace]?.setAuthProvider?.(this.authProvider);
|
|
1304
1300
|
}
|
|
1301
|
+
}
|
|
1302
|
+
createAdapters(blueprints) {
|
|
1305
1303
|
this.syncRequestedNetworks();
|
|
1306
1304
|
return this.chainNamespaces.reduce((adapters, namespace) => {
|
|
1307
1305
|
const blueprint = blueprints?.find(b => b.namespace === namespace);
|
|
@@ -1313,25 +1311,12 @@ export class AppKit {
|
|
|
1313
1311
|
projectId: this.options?.projectId,
|
|
1314
1312
|
networks: this.caipNetworks
|
|
1315
1313
|
});
|
|
1316
|
-
if (this.universalProvider) {
|
|
1317
|
-
adapters[namespace].setUniversalProvider(this.universalProvider);
|
|
1318
|
-
}
|
|
1319
|
-
if (this.authProvider) {
|
|
1320
|
-
adapters[namespace].setAuthProvider(this.authProvider);
|
|
1321
|
-
}
|
|
1322
|
-
adapters[namespace].syncConnectors(this.options, this);
|
|
1323
1314
|
}
|
|
1324
1315
|
else {
|
|
1325
1316
|
adapters[namespace] = new UniversalAdapter({
|
|
1326
1317
|
namespace,
|
|
1327
1318
|
networks: this.caipNetworks
|
|
1328
1319
|
});
|
|
1329
|
-
if (this.universalProvider) {
|
|
1330
|
-
adapters[namespace].setUniversalProvider(this.universalProvider);
|
|
1331
|
-
}
|
|
1332
|
-
if (this.authProvider) {
|
|
1333
|
-
adapters[namespace].setAuthProvider(this.authProvider);
|
|
1334
|
-
}
|
|
1335
1320
|
}
|
|
1336
1321
|
ChainController.state.chains.set(namespace, {
|
|
1337
1322
|
namespace,
|
|
@@ -1345,16 +1330,21 @@ export class AppKit {
|
|
|
1345
1330
|
// eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter
|
|
1346
1331
|
}, {});
|
|
1347
1332
|
}
|
|
1333
|
+
async createConnectorsForAdapter(namespace) {
|
|
1334
|
+
await this.createUniversalProviderForAdapter(namespace);
|
|
1335
|
+
this.createAuthProviderForAdapter(namespace);
|
|
1336
|
+
}
|
|
1337
|
+
onConnectors(chainNamespace) {
|
|
1338
|
+
const adapter = this.getAdapter(chainNamespace);
|
|
1339
|
+
adapter?.on('connectors', this.setConnectors.bind(this));
|
|
1340
|
+
}
|
|
1348
1341
|
async initChainAdapters() {
|
|
1349
|
-
await Promise.all(
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
this.setConnectors(this.chainAdapters?.[namespace]?.connectors || []);
|
|
1355
|
-
}
|
|
1342
|
+
await Promise.all(this.chainNamespaces.map(async (namespace) => {
|
|
1343
|
+
this.onConnectors(namespace);
|
|
1344
|
+
this.listenAdapter(namespace);
|
|
1345
|
+
this.chainAdapters?.[namespace].syncConnectors(this.options, this);
|
|
1346
|
+
await this.createConnectorsForAdapter(namespace);
|
|
1356
1347
|
}));
|
|
1357
|
-
this.listenWalletConnect();
|
|
1358
1348
|
}
|
|
1359
1349
|
setDefaultNetwork() {
|
|
1360
1350
|
const previousNetwork = StorageUtil.getActiveCaipNetworkId();
|