@reown/appkit 1.6.1-rc.0 → 1.6.1-rc.2.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 +1 -1
- 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 +123 -135
- 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/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/exports/constants.d.ts +1 -1
- package/dist/types/src/adapters/ChainAdapterBlueprint.d.ts +2 -1
- package/dist/types/src/adapters/index.d.ts +1 -0
- package/dist/types/src/client.d.ts +8 -3
- 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/TypesUtil.d.ts +8 -5
- package/package.json +9 -9
- package/dist/esm/src/networks/solana/eclipseDevnet.js +0 -17
- package/dist/esm/src/networks/solana/eclipseDevnet.js.map +0 -1
- package/dist/esm/src/tests/appkit.test.js +0 -714
- package/dist/esm/src/tests/appkit.test.js.map +0 -1
- package/dist/esm/src/tests/mocks/Adapter.js +0 -30
- package/dist/esm/src/tests/mocks/Adapter.js.map +0 -1
- package/dist/esm/src/tests/mocks/AppKit.js +0 -24
- package/dist/esm/src/tests/mocks/AppKit.js.map +0 -1
- package/dist/esm/src/tests/mocks/Options.js +0 -14
- package/dist/esm/src/tests/mocks/Options.js.map +0 -1
- package/dist/esm/src/tests/mocks/UniversalProvider.js +0 -137
- package/dist/esm/src/tests/mocks/UniversalProvider.js.map +0 -1
- package/dist/esm/src/tests/siwe.test.js +0 -205
- package/dist/esm/src/tests/siwe.test.js.map +0 -1
- package/dist/esm/src/tests/universal-adapter.test.js +0 -115
- package/dist/esm/src/tests/universal-adapter.test.js.map +0 -1
- package/dist/esm/src/tests/utils/HelpersUtil.test.js +0 -195
- package/dist/esm/src/tests/utils/HelpersUtil.test.js.map +0 -1
- package/dist/esm/tsconfig.tsbuildinfo +0 -1
- package/dist/types/src/networks/solana/eclipseDevnet.d.ts +0 -42
- package/dist/types/src/tests/appkit.test.d.ts +0 -1
- package/dist/types/src/tests/mocks/Adapter.d.ts +0 -3
- package/dist/types/src/tests/mocks/AppKit.d.ts +0 -3
- package/dist/types/src/tests/mocks/Options.d.ts +0 -18
- package/dist/types/src/tests/mocks/UniversalProvider.d.ts +0 -3
- package/dist/types/src/tests/siwe.test.d.ts +0 -1
- package/dist/types/src/tests/universal-adapter.test.d.ts +0 -1
- package/dist/types/src/tests/utils/HelpersUtil.test.d.ts +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const PACKAGE_VERSION = '1.6.1-rc.0';
|
|
1
|
+
export const PACKAGE_VERSION = '1.6.1-rc.2.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
|
-
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;IAC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,CAAC,CAAC,CAAA;QAEF,IAAI,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,7 +2,7 @@
|
|
|
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 {
|
|
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';
|
|
@@ -10,6 +10,7 @@ import { ProviderUtil } from './store/ProviderUtil.js';
|
|
|
10
10
|
import UniversalProvider from '@walletconnect/universal-provider';
|
|
11
11
|
import { W3mFrameProviderSingleton } from './auth-provider/W3MFrameProviderSingleton.js';
|
|
12
12
|
import { WcHelpersUtil } from './utils/HelpersUtil.js';
|
|
13
|
+
import { WalletUtil } from '@reown/appkit-scaffold-ui/utils';
|
|
13
14
|
// -- Export Controllers -------------------------------------------------------
|
|
14
15
|
export { AccountController };
|
|
15
16
|
// -- Constants ----------------------------------------- //
|
|
@@ -190,12 +191,10 @@ export class AppKit {
|
|
|
190
191
|
async initialize(options) {
|
|
191
192
|
this.caipNetworks = this.extendCaipNetworks(options);
|
|
192
193
|
this.defaultCaipNetwork = this.extendDefaultCaipNetwork(options);
|
|
193
|
-
|
|
194
|
-
this.createAuthProvider();
|
|
195
|
-
await this.createUniversalProvider();
|
|
194
|
+
this.initControllers(options);
|
|
196
195
|
this.createClients();
|
|
197
196
|
ChainController.initialize(options.adapters ?? [], this.caipNetworks);
|
|
198
|
-
this.chainAdapters =
|
|
197
|
+
this.chainAdapters = this.createAdapters(options.adapters);
|
|
199
198
|
await this.initChainAdapters();
|
|
200
199
|
this.syncRequestedNetworks();
|
|
201
200
|
await this.initOrContinue();
|
|
@@ -214,10 +213,14 @@ export class AppKit {
|
|
|
214
213
|
}
|
|
215
214
|
}
|
|
216
215
|
});
|
|
216
|
+
PublicStateController.set({ initialized: true });
|
|
217
217
|
}
|
|
218
218
|
// -- Public -------------------------------------------------------------------
|
|
219
219
|
async open(options) {
|
|
220
220
|
await this.initOrContinue();
|
|
221
|
+
if (options?.uri && this.universalAdapter) {
|
|
222
|
+
ConnectionController.setUri(options.uri);
|
|
223
|
+
}
|
|
221
224
|
ModalController.open(options);
|
|
222
225
|
}
|
|
223
226
|
async close() {
|
|
@@ -368,10 +371,13 @@ export class AppKit {
|
|
|
368
371
|
OptionsController.setSocialsOrder(socialsOrder);
|
|
369
372
|
}
|
|
370
373
|
async disconnect() {
|
|
371
|
-
await
|
|
374
|
+
await ChainController.disconnect();
|
|
375
|
+
}
|
|
376
|
+
getConnectMethodsOrder() {
|
|
377
|
+
return WalletUtil.getConnectOrderMethod(OptionsController.state.features, ConnectorController.getConnectors());
|
|
372
378
|
}
|
|
373
379
|
// -- Private ------------------------------------------------------------------
|
|
374
|
-
|
|
380
|
+
initControllers(options) {
|
|
375
381
|
OptionsController.setDebug(options.debug !== false);
|
|
376
382
|
OptionsController.setProjectId(options.projectId);
|
|
377
383
|
OptionsController.setSdkVersion(options.sdkVersion);
|
|
@@ -383,7 +389,6 @@ export class AppKit {
|
|
|
383
389
|
AlertController.open(ErrorUtil.ALERT_ERRORS.PROJECT_ID_NOT_CONFIGURED, 'error');
|
|
384
390
|
return;
|
|
385
391
|
}
|
|
386
|
-
this.adapters = options.adapters;
|
|
387
392
|
const defaultMetaData = this.getDefaultMetaData();
|
|
388
393
|
if (!options.metadata && defaultMetaData) {
|
|
389
394
|
options.metadata = defaultMetaData;
|
|
@@ -427,18 +432,14 @@ export class AppKit {
|
|
|
427
432
|
if (options.siwx) {
|
|
428
433
|
throw new Error('Cannot set both `siweConfig` and `siwx` options');
|
|
429
434
|
}
|
|
430
|
-
|
|
431
|
-
if (typeof siwe.mapToSIWX !== 'function') {
|
|
432
|
-
throw new Error('Please update the `@reown/appkit-siwe` package to the latest version');
|
|
433
|
-
}
|
|
434
|
-
OptionsController.setSIWX(siwe.mapToSIWX(options.siweConfig));
|
|
435
|
+
OptionsController.setSIWX(options.siweConfig.mapToSIWX());
|
|
435
436
|
}
|
|
436
437
|
}
|
|
437
438
|
}
|
|
438
439
|
getDefaultMetaData() {
|
|
439
440
|
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
440
441
|
return {
|
|
441
|
-
name: document.getElementsByTagName('title')[0]?.textContent || '',
|
|
442
|
+
name: document.getElementsByTagName('title')?.[0]?.textContent || '',
|
|
442
443
|
description: document.querySelector('meta[property="og:description"]')?.content || '',
|
|
443
444
|
url: window.location.origin,
|
|
444
445
|
icons: [document.querySelector('link[rel~="icon"]')?.href || '']
|
|
@@ -488,9 +489,7 @@ export class AppKit {
|
|
|
488
489
|
this.connectionControllerClient = {
|
|
489
490
|
connectWalletConnect: async (onUri) => {
|
|
490
491
|
const adapter = this.getAdapter(ChainController.state.activeChain);
|
|
491
|
-
this.universalProvider?.on('display_uri',
|
|
492
|
-
onUri(uri);
|
|
493
|
-
});
|
|
492
|
+
this.universalProvider?.on('display_uri', onUri);
|
|
494
493
|
this.setClientId((await this.universalProvider?.client?.core?.crypto?.getClientId()) || null);
|
|
495
494
|
let isAuthenticated = false;
|
|
496
495
|
if (this.universalProvider) {
|
|
@@ -522,37 +521,15 @@ export class AppKit {
|
|
|
522
521
|
if (!adapter) {
|
|
523
522
|
throw new Error('Adapter not found');
|
|
524
523
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
this.getCaipNetwork()?.rpcUrls?.default?.http?.[0]
|
|
535
|
-
});
|
|
536
|
-
/**
|
|
537
|
-
* In some cases with wagmi connectors, the connector is already connected
|
|
538
|
-
* which throws an `Is already connected`error. In such cases, we need to reconnect
|
|
539
|
-
* to restore the session.
|
|
540
|
-
* We check if the reconnect method exists (which it does for wagmi connectors) and if so
|
|
541
|
-
* we attempt to reconnect and restore the session state.
|
|
542
|
-
*/
|
|
543
|
-
}
|
|
544
|
-
catch (error) {
|
|
545
|
-
if (!adapter?.reconnect) {
|
|
546
|
-
throw new Error('Adapter is not able to connect');
|
|
547
|
-
}
|
|
548
|
-
await adapter.reconnect({
|
|
549
|
-
id,
|
|
550
|
-
info,
|
|
551
|
-
type,
|
|
552
|
-
provider,
|
|
553
|
-
chainId: this.getCaipNetwork()?.id
|
|
554
|
-
});
|
|
555
|
-
}
|
|
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
|
+
});
|
|
556
533
|
if (res) {
|
|
557
534
|
this.syncProvider({
|
|
558
535
|
...res,
|
|
@@ -582,6 +559,7 @@ export class AppKit {
|
|
|
582
559
|
const provider = ProviderUtil.getProvider(ChainController.state.activeChain);
|
|
583
560
|
const providerType = ProviderUtil.state.providerIds[ChainController.state.activeChain];
|
|
584
561
|
await adapter?.disconnect({ provider, providerType });
|
|
562
|
+
ProviderUtil.resetChain(ChainController.state.activeChain);
|
|
585
563
|
this.setStatus('disconnected', ChainController.state.activeChain);
|
|
586
564
|
},
|
|
587
565
|
checkInstalled: (ids) => {
|
|
@@ -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,
|
|
@@ -763,9 +741,6 @@ export class AppKit {
|
|
|
763
741
|
ConnectionController.setClient(this.connectionControllerClient);
|
|
764
742
|
}
|
|
765
743
|
}
|
|
766
|
-
async handleDisconnect() {
|
|
767
|
-
await this.connectionControllerClient?.disconnect();
|
|
768
|
-
}
|
|
769
744
|
async listenAuthConnector(provider) {
|
|
770
745
|
this.setLoading(true);
|
|
771
746
|
const isLoginEmailUsed = provider.getLoginEmailUsed();
|
|
@@ -822,8 +797,8 @@ export class AppKit {
|
|
|
822
797
|
}
|
|
823
798
|
});
|
|
824
799
|
provider.onNotConnected(() => {
|
|
825
|
-
const
|
|
826
|
-
const isConnectedWithAuth =
|
|
800
|
+
const connectorId = StorageUtil.getConnectedConnectorId();
|
|
801
|
+
const isConnectedWithAuth = connectorId === ConstantsUtil.CONNECTOR_ID.AUTH;
|
|
827
802
|
if (!isConnected && isConnectedWithAuth) {
|
|
828
803
|
this.setCaipAddress(undefined, ChainController.state.activeChain);
|
|
829
804
|
this.setLoading(false);
|
|
@@ -837,7 +812,7 @@ export class AppKit {
|
|
|
837
812
|
this.syncProvider({
|
|
838
813
|
type: UtilConstantsUtil.CONNECTOR_TYPE_AUTH,
|
|
839
814
|
provider,
|
|
840
|
-
id:
|
|
815
|
+
id: ConstantsUtil.CONNECTOR_ID.AUTH,
|
|
841
816
|
chainNamespace: namespace
|
|
842
817
|
});
|
|
843
818
|
// To keep backwards compatibility, eip155 chainIds are numbers and not actual caipChainIds
|
|
@@ -866,8 +841,8 @@ export class AppKit {
|
|
|
866
841
|
});
|
|
867
842
|
if (isConnected && this.connectionControllerClient?.connectExternal) {
|
|
868
843
|
await this.connectionControllerClient?.connectExternal({
|
|
869
|
-
id:
|
|
870
|
-
info: { name:
|
|
844
|
+
id: ConstantsUtil.CONNECTOR_ID.AUTH,
|
|
845
|
+
info: { name: ConstantsUtil.CONNECTOR_ID.AUTH },
|
|
871
846
|
type: UtilConstantsUtil.CONNECTOR_TYPE_AUTH,
|
|
872
847
|
provider,
|
|
873
848
|
chainId: ChainController.state.activeCaipNetwork?.id
|
|
@@ -943,11 +918,7 @@ export class AppKit {
|
|
|
943
918
|
this.setUnsupportedNetwork(chainId);
|
|
944
919
|
}
|
|
945
920
|
});
|
|
946
|
-
adapter.on('disconnect', ()
|
|
947
|
-
if (ChainController.state.activeChain === chainNamespace) {
|
|
948
|
-
this.handleDisconnect();
|
|
949
|
-
}
|
|
950
|
-
});
|
|
921
|
+
adapter.on('disconnect', this.disconnect.bind(this));
|
|
951
922
|
adapter.on('pendingTransactions', () => {
|
|
952
923
|
const address = AccountController.state.address;
|
|
953
924
|
const activeCaipNetwork = ChainController.state.activeCaipNetwork;
|
|
@@ -1015,7 +986,7 @@ export class AppKit {
|
|
|
1015
986
|
else {
|
|
1016
987
|
ProviderUtil.setProvider(chainNamespace, this.universalProvider);
|
|
1017
988
|
}
|
|
1018
|
-
StorageUtil.
|
|
989
|
+
StorageUtil.setConnectedConnectorId(ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT);
|
|
1019
990
|
let address = '';
|
|
1020
991
|
if (caipAddress.split(':').length === 3) {
|
|
1021
992
|
address = caipAddress.split(':')[2];
|
|
@@ -1070,13 +1041,13 @@ export class AppKit {
|
|
|
1070
1041
|
syncProvider({ type, provider, id, chainNamespace }) {
|
|
1071
1042
|
ProviderUtil.setProviderId(chainNamespace, type);
|
|
1072
1043
|
ProviderUtil.setProvider(chainNamespace, provider);
|
|
1073
|
-
StorageUtil.
|
|
1044
|
+
StorageUtil.setConnectedConnectorId(id);
|
|
1074
1045
|
}
|
|
1075
1046
|
async syncAccount({ address, chainId, chainNamespace }) {
|
|
1076
1047
|
const { namespace: activeNamespace, chainId: activeChainId } = StorageUtil.getActiveNetworkProps();
|
|
1077
1048
|
const chainIdToUse = chainId || activeChainId;
|
|
1078
1049
|
// Only update state when needed
|
|
1079
|
-
if (address
|
|
1050
|
+
if (address?.toLowerCase() !== AccountController.state.address?.toLowerCase()) {
|
|
1080
1051
|
this.setCaipAddress(`${chainNamespace}:${chainId}:${address}`, chainNamespace);
|
|
1081
1052
|
await this.syncIdentity({ address, chainId, chainNamespace });
|
|
1082
1053
|
}
|
|
@@ -1106,12 +1077,12 @@ export class AppKit {
|
|
|
1106
1077
|
}
|
|
1107
1078
|
}
|
|
1108
1079
|
syncConnectedWalletInfo(chainNamespace) {
|
|
1109
|
-
const
|
|
1080
|
+
const connectorId = StorageUtil.getConnectedConnectorId();
|
|
1110
1081
|
const providerType = ProviderUtil.state.providerIds[chainNamespace];
|
|
1111
1082
|
if (providerType === UtilConstantsUtil.CONNECTOR_TYPE_ANNOUNCED ||
|
|
1112
1083
|
providerType === UtilConstantsUtil.CONNECTOR_TYPE_INJECTED) {
|
|
1113
|
-
if (
|
|
1114
|
-
const connector = this.getConnectors().find(c => c.id ===
|
|
1084
|
+
if (connectorId) {
|
|
1085
|
+
const connector = this.getConnectors().find(c => c.id === connectorId);
|
|
1115
1086
|
if (connector?.info) {
|
|
1116
1087
|
this.setConnectedWalletInfo({ ...connector.info }, chainNamespace);
|
|
1117
1088
|
}
|
|
@@ -1127,12 +1098,12 @@ export class AppKit {
|
|
|
1127
1098
|
}, chainNamespace);
|
|
1128
1099
|
}
|
|
1129
1100
|
}
|
|
1130
|
-
else if (
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
this.setConnectedWalletInfo({ name:
|
|
1101
|
+
else if (connectorId) {
|
|
1102
|
+
if (connectorId === ConstantsUtil.CONNECTOR_ID.COINBASE) {
|
|
1103
|
+
const connector = this.getConnectors().find(c => c.id === ConstantsUtil.CONNECTOR_ID.COINBASE);
|
|
1104
|
+
this.setConnectedWalletInfo({ name: 'Coinbase Wallet', icon: this.getConnectorImage(connector) }, chainNamespace);
|
|
1105
|
+
}
|
|
1106
|
+
this.setConnectedWalletInfo({ name: connectorId }, chainNamespace);
|
|
1136
1107
|
}
|
|
1137
1108
|
}
|
|
1138
1109
|
async syncIdentity({ address, chainId, chainNamespace }) {
|
|
@@ -1198,43 +1169,56 @@ export class AppKit {
|
|
|
1198
1169
|
[], chainNamespace));
|
|
1199
1170
|
}
|
|
1200
1171
|
async syncExistingConnection() {
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
rpcUrl: this.getCaipNetwork()?.rpcUrls?.default?.http?.[0]
|
|
1216
|
-
});
|
|
1217
|
-
if (res) {
|
|
1218
|
-
const accounts = await adapter?.getAccounts({
|
|
1172
|
+
try {
|
|
1173
|
+
const connectorId = StorageUtil.getConnectedConnectorId();
|
|
1174
|
+
const activeNamespace = StorageUtil.getActiveNamespace();
|
|
1175
|
+
if (connectorId === ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT && activeNamespace) {
|
|
1176
|
+
this.syncWalletConnectAccount();
|
|
1177
|
+
}
|
|
1178
|
+
else if (connectorId &&
|
|
1179
|
+
connectorId !== ConstantsUtil.CONNECTOR_ID.AUTH &&
|
|
1180
|
+
activeNamespace) {
|
|
1181
|
+
this.setStatus('connecting', activeNamespace);
|
|
1182
|
+
const adapter = this.getAdapter(activeNamespace);
|
|
1183
|
+
const res = await adapter?.syncConnection({
|
|
1184
|
+
id: connectorId,
|
|
1185
|
+
chainId: this.getCaipNetwork()?.id,
|
|
1219
1186
|
namespace: activeNamespace,
|
|
1220
|
-
|
|
1187
|
+
rpcUrl: this.getCaipNetwork()?.rpcUrls?.default?.http?.[0]
|
|
1221
1188
|
});
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
this.
|
|
1189
|
+
if (res) {
|
|
1190
|
+
const accounts = await adapter?.getAccounts({
|
|
1191
|
+
namespace: activeNamespace,
|
|
1192
|
+
id: connectorId
|
|
1193
|
+
});
|
|
1194
|
+
if (!accounts || accounts.accounts.length === 0) {
|
|
1195
|
+
throw new Error('No accounts found');
|
|
1196
|
+
}
|
|
1197
|
+
this.syncProvider({ ...res, chainNamespace: activeNamespace });
|
|
1198
|
+
await this.syncAccount({ ...res, chainNamespace: activeNamespace });
|
|
1199
|
+
this.setAllAccounts(accounts.accounts, activeNamespace);
|
|
1200
|
+
this.setStatus('connected', activeNamespace);
|
|
1201
|
+
}
|
|
1202
|
+
else {
|
|
1203
|
+
this.setStatus('disconnected', activeNamespace);
|
|
1233
1204
|
}
|
|
1205
|
+
if (!this.caipNetworks?.some(network => network.id === res?.chainId)) {
|
|
1206
|
+
if (res?.chainId) {
|
|
1207
|
+
this.setUnsupportedNetwork(res.chainId);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
else if (connectorId !== ConstantsUtil.CONNECTOR_ID.AUTH) {
|
|
1212
|
+
this.setStatus('disconnected', ChainController.state.activeChain);
|
|
1234
1213
|
}
|
|
1235
1214
|
}
|
|
1236
|
-
|
|
1237
|
-
|
|
1215
|
+
catch (err) {
|
|
1216
|
+
// eslint-disable-next-line no-console
|
|
1217
|
+
console.log("AppKit:syncExistingConnection - couldn't sync existing connection", err);
|
|
1218
|
+
this.disconnect().finally(() => {
|
|
1219
|
+
StorageUtil.deleteConnectedConnectorId();
|
|
1220
|
+
this.setStatus('disconnected', ChainController.state.activeChain);
|
|
1221
|
+
});
|
|
1238
1222
|
}
|
|
1239
1223
|
}
|
|
1240
1224
|
getAdapter(namespace) {
|
|
@@ -1242,7 +1226,7 @@ export class AppKit {
|
|
|
1242
1226
|
}
|
|
1243
1227
|
createUniversalProvider() {
|
|
1244
1228
|
if (!this.universalProviderInitPromise &&
|
|
1245
|
-
|
|
1229
|
+
CoreHelperUtil.isClient() &&
|
|
1246
1230
|
this.options?.projectId) {
|
|
1247
1231
|
this.universalProviderInitPromise = this.initializeUniversalAdapter();
|
|
1248
1232
|
}
|
|
@@ -1278,7 +1262,10 @@ export class AppKit {
|
|
|
1278
1262
|
},
|
|
1279
1263
|
logger
|
|
1280
1264
|
};
|
|
1281
|
-
this.universalProvider
|
|
1265
|
+
OptionsController.setUsingInjectedUniversalProvider(Boolean(this.options?.universalProvider));
|
|
1266
|
+
this.universalProvider =
|
|
1267
|
+
this.options.universalProvider ?? (await UniversalProvider.init(universalProviderOptions));
|
|
1268
|
+
this.listenWalletConnect();
|
|
1282
1269
|
}
|
|
1283
1270
|
async getUniversalProvider() {
|
|
1284
1271
|
if (!this.universalProvider) {
|
|
@@ -1292,13 +1279,13 @@ export class AppKit {
|
|
|
1292
1279
|
return this.universalProvider;
|
|
1293
1280
|
}
|
|
1294
1281
|
createAuthProvider() {
|
|
1295
|
-
const
|
|
1282
|
+
const isEmailEnabled = this.options?.features?.email === undefined
|
|
1296
1283
|
? CoreConstantsUtil.DEFAULT_FEATURES.email
|
|
1297
1284
|
: this.options?.features?.email;
|
|
1298
|
-
const
|
|
1285
|
+
const isSocialsEnabled = this.options?.features?.socials
|
|
1299
1286
|
? this.options?.features?.socials?.length > 0
|
|
1300
1287
|
: CoreConstantsUtil.DEFAULT_FEATURES.socials;
|
|
1301
|
-
if (this.options?.projectId && (
|
|
1288
|
+
if (!this.authProvider && this.options?.projectId && (isEmailEnabled || isSocialsEnabled)) {
|
|
1302
1289
|
this.authProvider = W3mFrameProviderSingleton.getInstance({
|
|
1303
1290
|
projectId: this.options.projectId,
|
|
1304
1291
|
onTimeout: () => {
|
|
@@ -1308,10 +1295,19 @@ export class AppKit {
|
|
|
1308
1295
|
this.listenAuthConnector(this.authProvider);
|
|
1309
1296
|
}
|
|
1310
1297
|
}
|
|
1311
|
-
async
|
|
1312
|
-
|
|
1313
|
-
|
|
1298
|
+
async createUniversalProviderForAdapter(chainNamespace) {
|
|
1299
|
+
await this.getUniversalProvider();
|
|
1300
|
+
if (this.universalProvider) {
|
|
1301
|
+
this.chainAdapters?.[chainNamespace]?.setUniversalProvider?.(this.universalProvider);
|
|
1314
1302
|
}
|
|
1303
|
+
}
|
|
1304
|
+
createAuthProviderForAdapter(chainNamespace) {
|
|
1305
|
+
this.createAuthProvider();
|
|
1306
|
+
if (this.authProvider) {
|
|
1307
|
+
this.chainAdapters?.[chainNamespace]?.setAuthProvider?.(this.authProvider);
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
createAdapters(blueprints) {
|
|
1315
1311
|
this.syncRequestedNetworks();
|
|
1316
1312
|
return this.chainNamespaces.reduce((adapters, namespace) => {
|
|
1317
1313
|
const blueprint = blueprints?.find(b => b.namespace === namespace);
|
|
@@ -1323,25 +1319,12 @@ export class AppKit {
|
|
|
1323
1319
|
projectId: this.options?.projectId,
|
|
1324
1320
|
networks: this.caipNetworks
|
|
1325
1321
|
});
|
|
1326
|
-
if (this.universalProvider) {
|
|
1327
|
-
adapters[namespace].setUniversalProvider(this.universalProvider);
|
|
1328
|
-
}
|
|
1329
|
-
if (this.authProvider) {
|
|
1330
|
-
adapters[namespace].setAuthProvider(this.authProvider);
|
|
1331
|
-
}
|
|
1332
|
-
adapters[namespace].syncConnectors(this.options, this);
|
|
1333
1322
|
}
|
|
1334
1323
|
else {
|
|
1335
1324
|
adapters[namespace] = new UniversalAdapter({
|
|
1336
1325
|
namespace,
|
|
1337
1326
|
networks: this.caipNetworks
|
|
1338
1327
|
});
|
|
1339
|
-
if (this.universalProvider) {
|
|
1340
|
-
adapters[namespace].setUniversalProvider(this.universalProvider);
|
|
1341
|
-
}
|
|
1342
|
-
if (this.authProvider) {
|
|
1343
|
-
adapters[namespace].setAuthProvider(this.authProvider);
|
|
1344
|
-
}
|
|
1345
1328
|
}
|
|
1346
1329
|
ChainController.state.chains.set(namespace, {
|
|
1347
1330
|
namespace,
|
|
@@ -1355,16 +1338,21 @@ export class AppKit {
|
|
|
1355
1338
|
// eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter
|
|
1356
1339
|
}, {});
|
|
1357
1340
|
}
|
|
1341
|
+
async createConnectorsForAdapter(namespace) {
|
|
1342
|
+
await this.createUniversalProviderForAdapter(namespace);
|
|
1343
|
+
this.createAuthProviderForAdapter(namespace);
|
|
1344
|
+
}
|
|
1345
|
+
onConnectors(chainNamespace) {
|
|
1346
|
+
const adapter = this.getAdapter(chainNamespace);
|
|
1347
|
+
adapter?.on('connectors', this.setConnectors.bind(this));
|
|
1348
|
+
}
|
|
1358
1349
|
async initChainAdapters() {
|
|
1359
|
-
await Promise.all(
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
this.setConnectors(this.chainAdapters?.[namespace]?.connectors || []);
|
|
1365
|
-
}
|
|
1350
|
+
await Promise.all(this.chainNamespaces.map(async (namespace) => {
|
|
1351
|
+
this.onConnectors(namespace);
|
|
1352
|
+
this.listenAdapter(namespace);
|
|
1353
|
+
this.chainAdapters?.[namespace].syncConnectors(this.options, this);
|
|
1354
|
+
await this.createConnectorsForAdapter(namespace);
|
|
1366
1355
|
}));
|
|
1367
|
-
this.listenWalletConnect();
|
|
1368
1356
|
}
|
|
1369
1357
|
setDefaultNetwork() {
|
|
1370
1358
|
const previousNetwork = StorageUtil.getActiveCaipNetworkId();
|