@reown/appkit 1.5.3 → 1.5.4-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.map +1 -1
- package/dist/esm/src/client.js +154 -68
- package/dist/esm/src/client.js.map +1 -1
- package/dist/esm/src/tests/appkit.test.js +626 -0
- package/dist/esm/src/tests/appkit.test.js.map +1 -0
- package/dist/esm/src/tests/mocks/Adapter.js +30 -0
- package/dist/esm/src/tests/mocks/Adapter.js.map +1 -0
- package/dist/esm/src/tests/mocks/AppKit.js +24 -0
- package/dist/esm/src/tests/mocks/AppKit.js.map +1 -0
- package/dist/esm/src/tests/mocks/Options.js +14 -0
- package/dist/esm/src/tests/mocks/Options.js.map +1 -0
- package/dist/esm/src/tests/mocks/UniversalProvider.js +137 -0
- package/dist/esm/src/tests/mocks/UniversalProvider.js.map +1 -0
- package/dist/esm/src/tests/siwe.test.js +205 -0
- package/dist/esm/src/tests/siwe.test.js.map +1 -0
- package/dist/esm/src/tests/universal-adapter.test.js +115 -0
- package/dist/esm/src/tests/universal-adapter.test.js.map +1 -0
- package/dist/esm/src/tests/utils/HelpersUtil.test.js +195 -0
- package/dist/esm/src/tests/utils/HelpersUtil.test.js.map +1 -0
- package/dist/esm/src/universal-adapter/client.js +13 -1
- package/dist/esm/src/universal-adapter/client.js.map +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -0
- package/dist/types/exports/constants.d.ts +1 -1
- package/dist/types/src/adapters/ChainAdapterBlueprint.d.ts +15 -2
- package/dist/types/src/client.d.ts +13 -3
- package/dist/types/src/library/vue/index.d.ts +1 -0
- package/dist/types/src/tests/appkit.test.d.ts +1 -0
- package/dist/types/src/tests/mocks/Adapter.d.ts +3 -0
- package/dist/types/src/tests/mocks/AppKit.d.ts +3 -0
- package/dist/types/src/tests/mocks/Options.d.ts +18 -0
- package/dist/types/src/tests/mocks/UniversalProvider.d.ts +3 -0
- package/dist/types/src/tests/siwe.test.d.ts +1 -0
- package/dist/types/src/tests/universal-adapter.test.d.ts +1 -0
- package/dist/types/src/tests/utils/HelpersUtil.test.d.ts +1 -0
- package/dist/types/src/universal-adapter/client.d.ts +4 -0
- package/package.json +9 -9
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const PACKAGE_VERSION = '1.5.
|
|
1
|
+
export const PACKAGE_VERSION = '1.5.4-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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChainAdapterBlueprint.js","sourceRoot":"","sources":["../../../../src/adapters/ChainAdapterBlueprint.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EAIrB,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,
|
|
1
|
+
{"version":3,"file":"ChainAdapterBlueprint.js","sourceRoot":"","sources":["../../../../src/adapters/ChainAdapterBlueprint.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EAIrB,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EAOhB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAA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 @@
|
|
|
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 { ConstantsUtil, NetworkUtil } from '@reown/appkit-common';
|
|
6
6
|
import { UniversalAdapter, UniversalAdapter as UniversalAdapterClient } from './universal-adapter/client.js';
|
|
7
7
|
import { CaipNetworksUtil, ErrorUtil, ConstantsUtil as UtilConstantsUtil } from '@reown/appkit-utils';
|
|
8
8
|
import { W3mFrameHelpers, W3mFrameRpcConstants } from '@reown/appkit-wallet';
|
|
@@ -192,13 +192,26 @@ export class AppKit {
|
|
|
192
192
|
this.createAuthProvider();
|
|
193
193
|
await this.createUniversalProvider();
|
|
194
194
|
this.createClients();
|
|
195
|
-
ChainController.initialize(options.adapters ?? []);
|
|
195
|
+
ChainController.initialize(options.adapters ?? [], this.caipNetworks);
|
|
196
196
|
this.chainAdapters = await this.createAdapters(options.adapters);
|
|
197
197
|
await this.initChainAdapters();
|
|
198
198
|
this.syncRequestedNetworks();
|
|
199
199
|
await this.initOrContinue();
|
|
200
200
|
await this.syncExistingConnection();
|
|
201
201
|
this.version = options.sdkVersion;
|
|
202
|
+
const { ...optionsCopy } = options;
|
|
203
|
+
delete optionsCopy.adapters;
|
|
204
|
+
EventsController.sendEvent({
|
|
205
|
+
type: 'track',
|
|
206
|
+
event: 'INITIALIZE',
|
|
207
|
+
properties: {
|
|
208
|
+
...optionsCopy,
|
|
209
|
+
networks: options.networks.map(n => n.id),
|
|
210
|
+
siweConfig: {
|
|
211
|
+
options: options.siweConfig?.options || {}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
});
|
|
202
215
|
}
|
|
203
216
|
// -- Public -------------------------------------------------------------------
|
|
204
217
|
async open(options) {
|
|
@@ -237,8 +250,8 @@ export class AppKit {
|
|
|
237
250
|
? ProviderUtil.state.providerIds[ChainController.state.activeChain]
|
|
238
251
|
: null;
|
|
239
252
|
}
|
|
240
|
-
|
|
241
|
-
return
|
|
253
|
+
subscribeProviders(callback) {
|
|
254
|
+
return ProviderUtil.subscribeProviders(callback);
|
|
242
255
|
}
|
|
243
256
|
getThemeMode() {
|
|
244
257
|
return ThemeController.state.themeMode;
|
|
@@ -250,6 +263,12 @@ export class AppKit {
|
|
|
250
263
|
ThemeController.setThemeMode(themeMode);
|
|
251
264
|
setColorTheme(ThemeController.state.themeMode);
|
|
252
265
|
}
|
|
266
|
+
setTermsConditionsUrl(termsConditionsUrl) {
|
|
267
|
+
OptionsController.setTermsConditionsUrl(termsConditionsUrl);
|
|
268
|
+
}
|
|
269
|
+
setPrivacyPolicyUrl(privacyPolicyUrl) {
|
|
270
|
+
OptionsController.setPrivacyPolicyUrl(privacyPolicyUrl);
|
|
271
|
+
}
|
|
253
272
|
setThemeVariables(themeVariables) {
|
|
254
273
|
ThemeController.setThemeVariables(themeVariables);
|
|
255
274
|
setThemeVariables(ThemeController.state.themeVariables);
|
|
@@ -326,6 +345,26 @@ export class AppKit {
|
|
|
326
345
|
isTransactionShouldReplaceView() {
|
|
327
346
|
return RouterController.state.transactionStack[RouterController.state.transactionStack.length - 1]?.replace;
|
|
328
347
|
}
|
|
348
|
+
updateFeatures(newFeatures) {
|
|
349
|
+
OptionsController.setFeatures(newFeatures);
|
|
350
|
+
}
|
|
351
|
+
updateOptions(newOptions) {
|
|
352
|
+
const currentOptions = OptionsController.state || {};
|
|
353
|
+
const updatedOptions = { ...currentOptions, ...newOptions };
|
|
354
|
+
OptionsController.setOptions(updatedOptions);
|
|
355
|
+
}
|
|
356
|
+
setConnectMethodsOrder(connectMethodsOrder) {
|
|
357
|
+
OptionsController.setConnectMethodsOrder(connectMethodsOrder);
|
|
358
|
+
}
|
|
359
|
+
setWalletFeaturesOrder(walletFeaturesOrder) {
|
|
360
|
+
OptionsController.setWalletFeaturesOrder(walletFeaturesOrder);
|
|
361
|
+
}
|
|
362
|
+
setCollapseWallets(collapseWallets) {
|
|
363
|
+
OptionsController.setCollapseWallets(collapseWallets);
|
|
364
|
+
}
|
|
365
|
+
setSocialsOrder(socialsOrder) {
|
|
366
|
+
OptionsController.setSocialsOrder(socialsOrder);
|
|
367
|
+
}
|
|
329
368
|
async disconnect() {
|
|
330
369
|
await this.connectionControllerClient?.disconnect();
|
|
331
370
|
}
|
|
@@ -334,6 +373,7 @@ export class AppKit {
|
|
|
334
373
|
OptionsController.setDebug(options.debug);
|
|
335
374
|
OptionsController.setProjectId(options.projectId);
|
|
336
375
|
OptionsController.setSdkVersion(options.sdkVersion);
|
|
376
|
+
OptionsController.setEnableEmbedded(options.enableEmbedded);
|
|
337
377
|
if (!options.projectId) {
|
|
338
378
|
AlertController.open(ErrorUtil.ALERT_ERRORS.PROJECT_ID_NOT_CONFIGURED, 'error');
|
|
339
379
|
return;
|
|
@@ -357,7 +397,9 @@ export class AppKit {
|
|
|
357
397
|
OptionsController.setCustomWallets(options.customWallets);
|
|
358
398
|
OptionsController.setFeatures(options.features);
|
|
359
399
|
OptionsController.setEnableWalletConnect(options.enableWalletConnect !== false);
|
|
400
|
+
OptionsController.setEnableWalletGuide(options.enableWalletGuide !== false);
|
|
360
401
|
OptionsController.setEnableWallets(options.enableWallets !== false);
|
|
402
|
+
OptionsController.setEIP6963Enabled(options.enableEIP6963 !== false);
|
|
361
403
|
if (options.metadata) {
|
|
362
404
|
OptionsController.setMetadata(options.metadata);
|
|
363
405
|
}
|
|
@@ -463,16 +505,19 @@ export class AppKit {
|
|
|
463
505
|
await this.syncWalletConnectAccount();
|
|
464
506
|
},
|
|
465
507
|
connectExternal: async ({ id, info, type, provider, chain, caipNetwork }) => {
|
|
466
|
-
|
|
508
|
+
const activeChain = ChainController.state.activeChain;
|
|
509
|
+
if (chain && chain !== activeChain && !caipNetwork) {
|
|
467
510
|
const toConnectNetwork = this.caipNetworks?.find(network => network.chainNamespace === chain);
|
|
468
511
|
if (toConnectNetwork) {
|
|
469
512
|
this.setCaipNetwork(toConnectNetwork);
|
|
470
513
|
}
|
|
471
514
|
}
|
|
472
|
-
const
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
515
|
+
const chainToUse = chain || activeChain;
|
|
516
|
+
const adapter = this.getAdapter(chainToUse);
|
|
517
|
+
if (!adapter) {
|
|
518
|
+
throw new Error('Adapter not found');
|
|
519
|
+
}
|
|
520
|
+
const res = await adapter.connect({
|
|
476
521
|
id,
|
|
477
522
|
info,
|
|
478
523
|
type,
|
|
@@ -484,12 +529,14 @@ export class AppKit {
|
|
|
484
529
|
if (res) {
|
|
485
530
|
this.syncProvider({
|
|
486
531
|
...res,
|
|
487
|
-
chainNamespace:
|
|
532
|
+
chainNamespace: chainToUse
|
|
488
533
|
});
|
|
489
534
|
await this.syncAccount({
|
|
490
535
|
...res,
|
|
491
|
-
chainNamespace:
|
|
536
|
+
chainNamespace: chainToUse
|
|
492
537
|
});
|
|
538
|
+
const { accounts } = await adapter.getAccounts({ namespace: chainToUse, id });
|
|
539
|
+
this.setAllAccounts(accounts, chainToUse);
|
|
493
540
|
}
|
|
494
541
|
if (!this.caipNetworks?.some(network => network.id === res?.chainId)) {
|
|
495
542
|
if (res?.chainId) {
|
|
@@ -509,8 +556,8 @@ export class AppKit {
|
|
|
509
556
|
const providerType = ProviderUtil.state.providerIds[ChainController.state.activeChain];
|
|
510
557
|
await adapter?.disconnect({ provider, providerType });
|
|
511
558
|
this.setStatus('disconnected', ChainController.state.activeChain);
|
|
512
|
-
|
|
513
|
-
|
|
559
|
+
StorageUtil.deleteConnectedConnector();
|
|
560
|
+
StorageUtil.deleteActiveCaipNetworkId();
|
|
514
561
|
ChainController.state.chains.forEach(chain => {
|
|
515
562
|
this.resetAccount(chain.namespace);
|
|
516
563
|
});
|
|
@@ -740,13 +787,19 @@ export class AppKit {
|
|
|
740
787
|
}
|
|
741
788
|
if (this.isTransactionStackEmpty()) {
|
|
742
789
|
this.close();
|
|
790
|
+
if (AccountController.state.address && ChainController.state.activeCaipNetwork?.id) {
|
|
791
|
+
this.updateBalance();
|
|
792
|
+
}
|
|
743
793
|
}
|
|
744
794
|
else {
|
|
745
795
|
this.popTransactionStack();
|
|
796
|
+
if (AccountController.state.address && ChainController.state.activeCaipNetwork?.id) {
|
|
797
|
+
this.updateBalance();
|
|
798
|
+
}
|
|
746
799
|
}
|
|
747
800
|
});
|
|
748
801
|
provider.onNotConnected(() => {
|
|
749
|
-
const connectedConnector =
|
|
802
|
+
const connectedConnector = StorageUtil.getConnectedConnector();
|
|
750
803
|
const isConnectedWithAuth = connectedConnector === UtilConstantsUtil.AUTH_CONNECTOR_ID;
|
|
751
804
|
if (!isConnected && isConnectedWithAuth) {
|
|
752
805
|
this.setCaipAddress(undefined, ChainController.state.activeChain);
|
|
@@ -757,24 +810,25 @@ export class AppKit {
|
|
|
757
810
|
provider.connect();
|
|
758
811
|
});
|
|
759
812
|
provider.onConnect(async (user) => {
|
|
813
|
+
const namespace = ChainController.state.activeChain;
|
|
760
814
|
this.syncProvider({
|
|
761
815
|
type: UtilConstantsUtil.CONNECTOR_TYPE_AUTH,
|
|
762
816
|
provider,
|
|
763
817
|
id: UtilConstantsUtil.AUTH_CONNECTOR_ID,
|
|
764
|
-
chainNamespace:
|
|
818
|
+
chainNamespace: namespace
|
|
765
819
|
});
|
|
766
|
-
|
|
820
|
+
// To keep backwards compatibility, eip155 chainIds are numbers and not actual caipChainIds
|
|
821
|
+
const caipAddress = namespace === 'eip155'
|
|
767
822
|
? `eip155:${user.chainId}:${user.address}`
|
|
768
823
|
: `${user.chainId}:${user.address}`;
|
|
769
|
-
this.setCaipAddress(caipAddress,
|
|
770
|
-
this.setSmartAccountDeployed(Boolean(user.smartAccountDeployed),
|
|
771
|
-
|
|
772
|
-
this.
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
], ChainController.state.activeChain);
|
|
824
|
+
this.setCaipAddress(caipAddress, namespace);
|
|
825
|
+
this.setSmartAccountDeployed(Boolean(user.smartAccountDeployed), namespace);
|
|
826
|
+
const preferredAccountType = (user.preferredAccountType || 'eoa');
|
|
827
|
+
this.setPreferredAccountType(preferredAccountType, namespace);
|
|
828
|
+
const userAccounts = user.accounts?.map(account => CoreHelperUtil.createAccount(namespace, account.address, namespace === 'eip155' ? preferredAccountType : 'eoa'));
|
|
829
|
+
this.setAllAccounts(userAccounts || [
|
|
830
|
+
CoreHelperUtil.createAccount(namespace, user.address, preferredAccountType)
|
|
831
|
+
], namespace);
|
|
778
832
|
await provider.getSmartAccountEnabledNetworks();
|
|
779
833
|
this.setLoading(false);
|
|
780
834
|
});
|
|
@@ -828,6 +882,9 @@ export class AppKit {
|
|
|
828
882
|
}
|
|
829
883
|
listenAdapter(chainNamespace) {
|
|
830
884
|
const adapter = this.getAdapter(chainNamespace);
|
|
885
|
+
if (!adapter) {
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
831
888
|
const connectionStatus = StorageUtil.getConnectionStatus();
|
|
832
889
|
if (connectionStatus === 'connected') {
|
|
833
890
|
this.setStatus('connecting', chainNamespace);
|
|
@@ -835,7 +892,7 @@ export class AppKit {
|
|
|
835
892
|
else {
|
|
836
893
|
this.setStatus(connectionStatus, chainNamespace);
|
|
837
894
|
}
|
|
838
|
-
adapter
|
|
895
|
+
adapter.on('switchNetwork', ({ address, chainId }) => {
|
|
839
896
|
if (chainId && this.caipNetworks?.find(n => n.id === chainId)) {
|
|
840
897
|
if (ChainController.state.activeChain === chainNamespace && address) {
|
|
841
898
|
this.syncAccount({ address, chainId, chainNamespace });
|
|
@@ -853,12 +910,20 @@ export class AppKit {
|
|
|
853
910
|
this.setUnsupportedNetwork(chainId);
|
|
854
911
|
}
|
|
855
912
|
});
|
|
856
|
-
adapter
|
|
913
|
+
adapter.on('disconnect', () => {
|
|
857
914
|
if (ChainController.state.activeChain === chainNamespace) {
|
|
858
915
|
this.handleDisconnect();
|
|
859
916
|
}
|
|
860
917
|
});
|
|
861
|
-
adapter
|
|
918
|
+
adapter.on('pendingTransactions', () => {
|
|
919
|
+
const address = AccountController.state.address;
|
|
920
|
+
const activeCaipNetwork = ChainController.state.activeCaipNetwork;
|
|
921
|
+
if (!address || !activeCaipNetwork?.id) {
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
this.updateBalance();
|
|
925
|
+
});
|
|
926
|
+
adapter.on('accountChanged', ({ address, chainId }) => {
|
|
862
927
|
if (ChainController.state.activeChain === chainNamespace && chainId) {
|
|
863
928
|
this.syncAccount({
|
|
864
929
|
address,
|
|
@@ -876,6 +941,17 @@ export class AppKit {
|
|
|
876
941
|
}
|
|
877
942
|
});
|
|
878
943
|
}
|
|
944
|
+
updateBalance() {
|
|
945
|
+
const adapter = this.getAdapter(ChainController.state.activeChain);
|
|
946
|
+
if (adapter) {
|
|
947
|
+
adapter.getBalance({
|
|
948
|
+
address: AccountController.state.address,
|
|
949
|
+
chainId: ChainController.state.activeCaipNetwork?.id,
|
|
950
|
+
caipNetwork: this.getCaipNetwork(),
|
|
951
|
+
tokens: this.options.tokens
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
}
|
|
879
955
|
getChainsFromNamespaces(namespaces = {}) {
|
|
880
956
|
return Object.values(namespaces).flatMap(namespace => {
|
|
881
957
|
const chains = (namespace.chains || []);
|
|
@@ -888,7 +964,6 @@ export class AppKit {
|
|
|
888
964
|
}
|
|
889
965
|
async syncWalletConnectAccount() {
|
|
890
966
|
const adapter = this.getAdapter(ChainController.state.activeChain);
|
|
891
|
-
StorageUtil.setConnectedNamespace(ChainController.state.activeChain);
|
|
892
967
|
this.chainNamespaces.forEach(async (chainNamespace) => {
|
|
893
968
|
const caipAddress = this.universalProvider?.session?.namespaces?.[chainNamespace]
|
|
894
969
|
?.accounts[0];
|
|
@@ -956,45 +1031,49 @@ export class AppKit {
|
|
|
956
1031
|
})
|
|
957
1032
|
.filter((address, index, self) => self.indexOf(address) === index);
|
|
958
1033
|
if (addresses) {
|
|
959
|
-
this.setAllAccounts(addresses.map(address => (
|
|
1034
|
+
this.setAllAccounts(addresses.map(address => CoreHelperUtil.createAccount(chainNamespace, address, chainNamespace === 'bip122' ? 'payment' : 'eoa')), chainNamespace);
|
|
960
1035
|
}
|
|
961
1036
|
}
|
|
962
1037
|
syncProvider({ type, provider, id, chainNamespace }) {
|
|
963
1038
|
ProviderUtil.setProviderId(chainNamespace, type);
|
|
964
1039
|
ProviderUtil.setProvider(chainNamespace, provider);
|
|
965
1040
|
StorageUtil.setConnectedConnector(id);
|
|
966
|
-
StorageUtil.setConnectedNamespace(ChainController.state.activeChain);
|
|
967
1041
|
}
|
|
968
1042
|
async syncAccount({ address, chainId, chainNamespace }) {
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
1043
|
+
const { namespace: activeNamespace, chainId: activeChainId } = StorageUtil.getActiveNetworkProps();
|
|
1044
|
+
const chainIdToUse = chainId || activeChainId;
|
|
1045
|
+
// Only update state when needed
|
|
1046
|
+
if (address.toLowerCase() !== AccountController.state.address?.toLowerCase()) {
|
|
1047
|
+
this.setCaipAddress(`${chainNamespace}:${chainId}:${address}`, chainNamespace);
|
|
1048
|
+
await this.syncIdentity({ address, chainId, chainNamespace });
|
|
1049
|
+
}
|
|
973
1050
|
this.setStatus('connected', chainNamespace);
|
|
974
|
-
if (chainNamespace ===
|
|
975
|
-
const caipNetwork = this.caipNetworks?.find(n => n.id ===
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
}
|
|
979
|
-
else {
|
|
980
|
-
this.setCaipNetwork(this.caipNetworks?.find(n => n.chainNamespace === chainNamespace));
|
|
981
|
-
}
|
|
1051
|
+
if (chainIdToUse && chainNamespace === activeNamespace) {
|
|
1052
|
+
const caipNetwork = this.caipNetworks?.find(n => n.id.toString() === chainIdToUse.toString());
|
|
1053
|
+
const fallBackCaipNetwork = this.caipNetworks?.find(n => n.chainNamespace === chainNamespace);
|
|
1054
|
+
this.setCaipNetwork(caipNetwork || fallBackCaipNetwork);
|
|
982
1055
|
this.syncConnectedWalletInfo(chainNamespace);
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1056
|
+
await this.syncBalance({ address, chainId: chainIdToUse, chainNamespace });
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
async syncBalance(params) {
|
|
1060
|
+
const adapter = this.getAdapter(params.chainNamespace);
|
|
1061
|
+
const caipNetwork = NetworkUtil.getNetworksByNamespace(this.caipNetworks, params.chainNamespace).find(n => n.id.toString() === params.chainId.toString());
|
|
1062
|
+
if (!caipNetwork) {
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
const balance = await adapter?.getBalance({
|
|
1066
|
+
address: params.address,
|
|
1067
|
+
chainId: params.chainId,
|
|
1068
|
+
caipNetwork,
|
|
1069
|
+
tokens: this.options.tokens
|
|
1070
|
+
});
|
|
1071
|
+
if (balance) {
|
|
1072
|
+
this.setBalance(balance.balance, balance.symbol, params.chainNamespace);
|
|
994
1073
|
}
|
|
995
1074
|
}
|
|
996
1075
|
syncConnectedWalletInfo(chainNamespace) {
|
|
997
|
-
const currentActiveWallet =
|
|
1076
|
+
const currentActiveWallet = StorageUtil.getConnectedConnector();
|
|
998
1077
|
const providerType = ProviderUtil.state.providerIds[chainNamespace];
|
|
999
1078
|
if (providerType === UtilConstantsUtil.CONNECTOR_TYPE_ANNOUNCED ||
|
|
1000
1079
|
providerType === UtilConstantsUtil.CONNECTOR_TYPE_INJECTED) {
|
|
@@ -1024,6 +1103,9 @@ export class AppKit {
|
|
|
1024
1103
|
}
|
|
1025
1104
|
}
|
|
1026
1105
|
async syncIdentity({ address, chainId, chainNamespace }) {
|
|
1106
|
+
if (chainNamespace !== 'eip155') {
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1027
1109
|
try {
|
|
1028
1110
|
const { name, avatar } = await this.fetchIdentity({
|
|
1029
1111
|
address
|
|
@@ -1083,30 +1165,34 @@ export class AppKit {
|
|
|
1083
1165
|
[], chainNamespace));
|
|
1084
1166
|
}
|
|
1085
1167
|
async syncExistingConnection() {
|
|
1086
|
-
const connectedConnector =
|
|
1087
|
-
const
|
|
1088
|
-
if (connectedConnector === UtilConstantsUtil.CONNECTOR_TYPE_WALLET_CONNECT &&
|
|
1089
|
-
connectedNamespace) {
|
|
1168
|
+
const connectedConnector = StorageUtil.getConnectedConnector();
|
|
1169
|
+
const activeNamespace = StorageUtil.getActiveNamespace();
|
|
1170
|
+
if (connectedConnector === UtilConstantsUtil.CONNECTOR_TYPE_WALLET_CONNECT && activeNamespace) {
|
|
1090
1171
|
this.syncWalletConnectAccount();
|
|
1091
1172
|
}
|
|
1092
1173
|
else if (connectedConnector &&
|
|
1093
1174
|
connectedConnector !== UtilConstantsUtil.CONNECTOR_TYPE_W3M_AUTH &&
|
|
1094
|
-
|
|
1095
|
-
this.setStatus('connecting',
|
|
1096
|
-
const adapter = this.getAdapter(
|
|
1175
|
+
activeNamespace) {
|
|
1176
|
+
this.setStatus('connecting', activeNamespace);
|
|
1177
|
+
const adapter = this.getAdapter(activeNamespace);
|
|
1097
1178
|
const res = await adapter?.syncConnection({
|
|
1098
1179
|
id: connectedConnector,
|
|
1099
1180
|
chainId: this.getCaipNetwork()?.id,
|
|
1100
|
-
namespace:
|
|
1181
|
+
namespace: activeNamespace,
|
|
1101
1182
|
rpcUrl: this.getCaipNetwork()?.rpcUrls?.default?.http?.[0]
|
|
1102
1183
|
});
|
|
1103
1184
|
if (res) {
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1185
|
+
const accounts = await adapter?.getAccounts({
|
|
1186
|
+
namespace: activeNamespace,
|
|
1187
|
+
id: connectedConnector
|
|
1188
|
+
});
|
|
1189
|
+
this.syncProvider({ ...res, chainNamespace: activeNamespace });
|
|
1190
|
+
await this.syncAccount({ ...res, chainNamespace: activeNamespace });
|
|
1191
|
+
this.setAllAccounts(accounts?.accounts || [], activeNamespace);
|
|
1192
|
+
this.setStatus('connected', activeNamespace);
|
|
1107
1193
|
}
|
|
1108
1194
|
else {
|
|
1109
|
-
this.setStatus('disconnected',
|
|
1195
|
+
this.setStatus('disconnected', activeNamespace);
|
|
1110
1196
|
}
|
|
1111
1197
|
if (!this.caipNetworks?.some(network => network.id === res?.chainId)) {
|
|
1112
1198
|
if (res?.chainId) {
|
|
@@ -1225,7 +1311,7 @@ export class AppKit {
|
|
|
1225
1311
|
this.listenWalletConnect();
|
|
1226
1312
|
}
|
|
1227
1313
|
setDefaultNetwork() {
|
|
1228
|
-
const previousNetwork =
|
|
1314
|
+
const previousNetwork = StorageUtil.getActiveCaipNetworkId();
|
|
1229
1315
|
const caipNetwork = previousNetwork && this.caipNetworks?.length
|
|
1230
1316
|
? this.caipNetworks.find(n => n.caipNetworkId === previousNetwork)
|
|
1231
1317
|
: undefined;
|