@reown/appkit 1.5.4-wcm-d-6052bd13d.0 → 1.6.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/exports/index.js +0 -1
- package/dist/esm/exports/index.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 +183 -71
- 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 +1 -5
- 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/exports/index.d.ts +0 -1
- package/dist/types/src/adapters/ChainAdapterBlueprint.d.ts +2 -1
- package/dist/types/src/client.d.ts +17 -6
- package/dist/types/src/library/react/index.d.ts +0 -1
- package/dist/types/src/library/vue/index.d.ts +1 -0
- package/dist/types/src/universal-adapter/client.d.ts +0 -4
- package/dist/types/src/utils/TypesUtil.d.ts +0 -3
- package/package.json +9 -9
- package/dist/esm/src/tests/appkit.test.js +0 -607
- 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/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 -20
- 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.
|
|
1
|
+
export const PACKAGE_VERSION = '1.6.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,OAAO,CAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { CoreHelperUtil } from '@reown/appkit-core';
|
|
2
2
|
import { AppKit } from '../src/client.js';
|
|
3
3
|
import { PACKAGE_VERSION } from './constants.js';
|
|
4
|
-
export * from '../src/universal-adapter/index.js';
|
|
5
4
|
// -- Views ------------------------------------------------------------
|
|
6
5
|
export * from '@reown/appkit-scaffold-ui';
|
|
7
6
|
// -- Utils & Other -----------------------------------------------------
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../exports/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../exports/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEhD,wEAAwE;AACxE,cAAc,2BAA2B,CAAA;AAEzC,yEAAyE;AACzE,cAAc,uBAAuB,CAAA;AAGrC,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAItE,MAAM,UAAU,YAAY,CAAC,OAAqB;IAChD,OAAO,IAAI,MAAM,CAAC;QAChB,GAAG,OAAO;QACV,UAAU,EAAE,cAAc,CAAC,kBAAkB,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,EAAE,MAAM,EAAE,eAAe,CAAC;KAC/F,CAAC,CAAA;AACJ,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,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,EAOhB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAGhE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"ChainAdapterBlueprint.js","source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AAI,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,9 +2,9 @@
|
|
|
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
|
-
import { CaipNetworksUtil, ErrorUtil, ConstantsUtil as UtilConstantsUtil } from '@reown/appkit-utils';
|
|
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';
|
|
@@ -56,6 +56,7 @@ export class AppKit {
|
|
|
56
56
|
constructor(options) {
|
|
57
57
|
this.chainNamespaces = [];
|
|
58
58
|
this.initPromise = undefined;
|
|
59
|
+
this.reportedAlertErrors = {};
|
|
59
60
|
this.setStatus = (status, chain) => {
|
|
60
61
|
StorageUtil.setConnectionStatus(status);
|
|
61
62
|
AccountController.setStatus(status, chain);
|
|
@@ -192,21 +193,30 @@ export class AppKit {
|
|
|
192
193
|
this.createAuthProvider();
|
|
193
194
|
await this.createUniversalProvider();
|
|
194
195
|
this.createClients();
|
|
195
|
-
ChainController.initialize(options.adapters ?? []);
|
|
196
|
+
ChainController.initialize(options.adapters ?? [], this.caipNetworks);
|
|
196
197
|
this.chainAdapters = await this.createAdapters(options.adapters);
|
|
197
198
|
await this.initChainAdapters();
|
|
198
199
|
this.syncRequestedNetworks();
|
|
199
200
|
await this.initOrContinue();
|
|
200
201
|
await this.syncExistingConnection();
|
|
201
202
|
this.version = options.sdkVersion;
|
|
203
|
+
const { ...optionsCopy } = options;
|
|
204
|
+
delete optionsCopy.adapters;
|
|
205
|
+
EventsController.sendEvent({
|
|
206
|
+
type: 'track',
|
|
207
|
+
event: 'INITIALIZE',
|
|
208
|
+
properties: {
|
|
209
|
+
...optionsCopy,
|
|
210
|
+
networks: options.networks.map(n => n.id),
|
|
211
|
+
siweConfig: {
|
|
212
|
+
options: options.siweConfig?.options || {}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
});
|
|
202
216
|
}
|
|
203
217
|
// -- Public -------------------------------------------------------------------
|
|
204
218
|
async open(options) {
|
|
205
219
|
await this.initOrContinue();
|
|
206
|
-
if (options?.uri && this.universalAdapter) {
|
|
207
|
-
console.log('options.uri', options.uri);
|
|
208
|
-
ConnectionController.setUri(options.uri);
|
|
209
|
-
}
|
|
210
220
|
ModalController.open(options);
|
|
211
221
|
}
|
|
212
222
|
async close() {
|
|
@@ -241,8 +251,8 @@ export class AppKit {
|
|
|
241
251
|
? ProviderUtil.state.providerIds[ChainController.state.activeChain]
|
|
242
252
|
: null;
|
|
243
253
|
}
|
|
244
|
-
|
|
245
|
-
return
|
|
254
|
+
subscribeProviders(callback) {
|
|
255
|
+
return ProviderUtil.subscribeProviders(callback);
|
|
246
256
|
}
|
|
247
257
|
getThemeMode() {
|
|
248
258
|
return ThemeController.state.themeMode;
|
|
@@ -254,6 +264,12 @@ export class AppKit {
|
|
|
254
264
|
ThemeController.setThemeMode(themeMode);
|
|
255
265
|
setColorTheme(ThemeController.state.themeMode);
|
|
256
266
|
}
|
|
267
|
+
setTermsConditionsUrl(termsConditionsUrl) {
|
|
268
|
+
OptionsController.setTermsConditionsUrl(termsConditionsUrl);
|
|
269
|
+
}
|
|
270
|
+
setPrivacyPolicyUrl(privacyPolicyUrl) {
|
|
271
|
+
OptionsController.setPrivacyPolicyUrl(privacyPolicyUrl);
|
|
272
|
+
}
|
|
257
273
|
setThemeVariables(themeVariables) {
|
|
258
274
|
ThemeController.setThemeVariables(themeVariables);
|
|
259
275
|
setThemeVariables(ThemeController.state.themeVariables);
|
|
@@ -330,14 +346,35 @@ export class AppKit {
|
|
|
330
346
|
isTransactionShouldReplaceView() {
|
|
331
347
|
return RouterController.state.transactionStack[RouterController.state.transactionStack.length - 1]?.replace;
|
|
332
348
|
}
|
|
349
|
+
updateFeatures(newFeatures) {
|
|
350
|
+
OptionsController.setFeatures(newFeatures);
|
|
351
|
+
}
|
|
352
|
+
updateOptions(newOptions) {
|
|
353
|
+
const currentOptions = OptionsController.state || {};
|
|
354
|
+
const updatedOptions = { ...currentOptions, ...newOptions };
|
|
355
|
+
OptionsController.setOptions(updatedOptions);
|
|
356
|
+
}
|
|
357
|
+
setConnectMethodsOrder(connectMethodsOrder) {
|
|
358
|
+
OptionsController.setConnectMethodsOrder(connectMethodsOrder);
|
|
359
|
+
}
|
|
360
|
+
setWalletFeaturesOrder(walletFeaturesOrder) {
|
|
361
|
+
OptionsController.setWalletFeaturesOrder(walletFeaturesOrder);
|
|
362
|
+
}
|
|
363
|
+
setCollapseWallets(collapseWallets) {
|
|
364
|
+
OptionsController.setCollapseWallets(collapseWallets);
|
|
365
|
+
}
|
|
366
|
+
setSocialsOrder(socialsOrder) {
|
|
367
|
+
OptionsController.setSocialsOrder(socialsOrder);
|
|
368
|
+
}
|
|
333
369
|
async disconnect() {
|
|
334
370
|
await this.connectionControllerClient?.disconnect();
|
|
335
371
|
}
|
|
336
372
|
// -- Private ------------------------------------------------------------------
|
|
337
373
|
async initControllers(options) {
|
|
338
|
-
OptionsController.setDebug(options.debug);
|
|
374
|
+
OptionsController.setDebug(options.debug !== false);
|
|
339
375
|
OptionsController.setProjectId(options.projectId);
|
|
340
376
|
OptionsController.setSdkVersion(options.sdkVersion);
|
|
377
|
+
OptionsController.setEnableEmbedded(options.enableEmbedded);
|
|
341
378
|
if (!options.projectId) {
|
|
342
379
|
AlertController.open(ErrorUtil.ALERT_ERRORS.PROJECT_ID_NOT_CONFIGURED, 'error');
|
|
343
380
|
return;
|
|
@@ -361,7 +398,9 @@ export class AppKit {
|
|
|
361
398
|
OptionsController.setCustomWallets(options.customWallets);
|
|
362
399
|
OptionsController.setFeatures(options.features);
|
|
363
400
|
OptionsController.setEnableWalletConnect(options.enableWalletConnect !== false);
|
|
401
|
+
OptionsController.setEnableWalletGuide(options.enableWalletGuide !== false);
|
|
364
402
|
OptionsController.setEnableWallets(options.enableWallets !== false);
|
|
403
|
+
OptionsController.setEIP6963Enabled(options.enableEIP6963 !== false);
|
|
365
404
|
if (options.metadata) {
|
|
366
405
|
OptionsController.setMetadata(options.metadata);
|
|
367
406
|
}
|
|
@@ -479,15 +518,37 @@ export class AppKit {
|
|
|
479
518
|
if (!adapter) {
|
|
480
519
|
throw new Error('Adapter not found');
|
|
481
520
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
this.getCaipNetwork()?.
|
|
490
|
-
|
|
521
|
+
let res = undefined;
|
|
522
|
+
try {
|
|
523
|
+
res = await adapter.connect({
|
|
524
|
+
id,
|
|
525
|
+
info,
|
|
526
|
+
type,
|
|
527
|
+
provider,
|
|
528
|
+
chainId: caipNetwork?.id || this.getCaipNetwork()?.id,
|
|
529
|
+
rpcUrl: caipNetwork?.rpcUrls?.default?.http?.[0] ||
|
|
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
|
+
}
|
|
491
552
|
if (res) {
|
|
492
553
|
this.syncProvider({
|
|
493
554
|
...res,
|
|
@@ -518,8 +579,8 @@ export class AppKit {
|
|
|
518
579
|
const providerType = ProviderUtil.state.providerIds[ChainController.state.activeChain];
|
|
519
580
|
await adapter?.disconnect({ provider, providerType });
|
|
520
581
|
this.setStatus('disconnected', ChainController.state.activeChain);
|
|
521
|
-
|
|
522
|
-
|
|
582
|
+
StorageUtil.deleteConnectedConnector();
|
|
583
|
+
StorageUtil.deleteActiveCaipNetworkId();
|
|
523
584
|
ChainController.state.chains.forEach(chain => {
|
|
524
585
|
this.resetAccount(chain.namespace);
|
|
525
586
|
});
|
|
@@ -749,13 +810,19 @@ export class AppKit {
|
|
|
749
810
|
}
|
|
750
811
|
if (this.isTransactionStackEmpty()) {
|
|
751
812
|
this.close();
|
|
813
|
+
if (AccountController.state.address && ChainController.state.activeCaipNetwork?.id) {
|
|
814
|
+
this.updateBalance();
|
|
815
|
+
}
|
|
752
816
|
}
|
|
753
817
|
else {
|
|
754
818
|
this.popTransactionStack();
|
|
819
|
+
if (AccountController.state.address && ChainController.state.activeCaipNetwork?.id) {
|
|
820
|
+
this.updateBalance();
|
|
821
|
+
}
|
|
755
822
|
}
|
|
756
823
|
});
|
|
757
824
|
provider.onNotConnected(() => {
|
|
758
|
-
const connectedConnector =
|
|
825
|
+
const connectedConnector = StorageUtil.getConnectedConnector();
|
|
759
826
|
const isConnectedWithAuth = connectedConnector === UtilConstantsUtil.AUTH_CONNECTOR_ID;
|
|
760
827
|
if (!isConnected && isConnectedWithAuth) {
|
|
761
828
|
this.setCaipAddress(undefined, ChainController.state.activeChain);
|
|
@@ -838,6 +905,9 @@ export class AppKit {
|
|
|
838
905
|
}
|
|
839
906
|
listenAdapter(chainNamespace) {
|
|
840
907
|
const adapter = this.getAdapter(chainNamespace);
|
|
908
|
+
if (!adapter) {
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
841
911
|
const connectionStatus = StorageUtil.getConnectionStatus();
|
|
842
912
|
if (connectionStatus === 'connected') {
|
|
843
913
|
this.setStatus('connecting', chainNamespace);
|
|
@@ -845,7 +915,7 @@ export class AppKit {
|
|
|
845
915
|
else {
|
|
846
916
|
this.setStatus(connectionStatus, chainNamespace);
|
|
847
917
|
}
|
|
848
|
-
adapter
|
|
918
|
+
adapter.on('switchNetwork', ({ address, chainId }) => {
|
|
849
919
|
if (chainId && this.caipNetworks?.find(n => n.id === chainId)) {
|
|
850
920
|
if (ChainController.state.activeChain === chainNamespace && address) {
|
|
851
921
|
this.syncAccount({ address, chainId, chainNamespace });
|
|
@@ -863,12 +933,20 @@ export class AppKit {
|
|
|
863
933
|
this.setUnsupportedNetwork(chainId);
|
|
864
934
|
}
|
|
865
935
|
});
|
|
866
|
-
adapter
|
|
936
|
+
adapter.on('disconnect', () => {
|
|
867
937
|
if (ChainController.state.activeChain === chainNamespace) {
|
|
868
938
|
this.handleDisconnect();
|
|
869
939
|
}
|
|
870
940
|
});
|
|
871
|
-
adapter
|
|
941
|
+
adapter.on('pendingTransactions', () => {
|
|
942
|
+
const address = AccountController.state.address;
|
|
943
|
+
const activeCaipNetwork = ChainController.state.activeCaipNetwork;
|
|
944
|
+
if (!address || !activeCaipNetwork?.id) {
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
this.updateBalance();
|
|
948
|
+
});
|
|
949
|
+
adapter.on('accountChanged', ({ address, chainId }) => {
|
|
872
950
|
if (ChainController.state.activeChain === chainNamespace && chainId) {
|
|
873
951
|
this.syncAccount({
|
|
874
952
|
address,
|
|
@@ -886,6 +964,17 @@ export class AppKit {
|
|
|
886
964
|
}
|
|
887
965
|
});
|
|
888
966
|
}
|
|
967
|
+
updateBalance() {
|
|
968
|
+
const adapter = this.getAdapter(ChainController.state.activeChain);
|
|
969
|
+
if (adapter) {
|
|
970
|
+
adapter.getBalance({
|
|
971
|
+
address: AccountController.state.address,
|
|
972
|
+
chainId: ChainController.state.activeCaipNetwork?.id,
|
|
973
|
+
caipNetwork: this.getCaipNetwork(),
|
|
974
|
+
tokens: this.options.tokens
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
}
|
|
889
978
|
getChainsFromNamespaces(namespaces = {}) {
|
|
890
979
|
return Object.values(namespaces).flatMap(namespace => {
|
|
891
980
|
const chains = (namespace.chains || []);
|
|
@@ -898,7 +987,6 @@ export class AppKit {
|
|
|
898
987
|
}
|
|
899
988
|
async syncWalletConnectAccount() {
|
|
900
989
|
const adapter = this.getAdapter(ChainController.state.activeChain);
|
|
901
|
-
StorageUtil.setConnectedNamespace(ChainController.state.activeChain);
|
|
902
990
|
this.chainNamespaces.forEach(async (chainNamespace) => {
|
|
903
991
|
const caipAddress = this.universalProvider?.session?.namespaces?.[chainNamespace]
|
|
904
992
|
?.accounts[0];
|
|
@@ -973,38 +1061,42 @@ export class AppKit {
|
|
|
973
1061
|
ProviderUtil.setProviderId(chainNamespace, type);
|
|
974
1062
|
ProviderUtil.setProvider(chainNamespace, provider);
|
|
975
1063
|
StorageUtil.setConnectedConnector(id);
|
|
976
|
-
StorageUtil.setConnectedNamespace(ChainController.state.activeChain);
|
|
977
1064
|
}
|
|
978
1065
|
async syncAccount({ address, chainId, chainNamespace }) {
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
1066
|
+
const { namespace: activeNamespace, chainId: activeChainId } = StorageUtil.getActiveNetworkProps();
|
|
1067
|
+
const chainIdToUse = chainId || activeChainId;
|
|
1068
|
+
// Only update state when needed
|
|
1069
|
+
if (address.toLowerCase() !== AccountController.state.address?.toLowerCase()) {
|
|
1070
|
+
this.setCaipAddress(`${chainNamespace}:${chainId}:${address}`, chainNamespace);
|
|
1071
|
+
await this.syncIdentity({ address, chainId, chainNamespace });
|
|
1072
|
+
}
|
|
983
1073
|
this.setStatus('connected', chainNamespace);
|
|
984
|
-
if (chainNamespace ===
|
|
985
|
-
const caipNetwork = this.caipNetworks?.find(n => n.id ===
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
}
|
|
989
|
-
else {
|
|
990
|
-
this.setCaipNetwork(this.caipNetworks?.find(n => n.chainNamespace === chainNamespace));
|
|
991
|
-
}
|
|
1074
|
+
if (chainIdToUse && chainNamespace === activeNamespace) {
|
|
1075
|
+
const caipNetwork = this.caipNetworks?.find(n => n.id.toString() === chainIdToUse.toString());
|
|
1076
|
+
const fallBackCaipNetwork = this.caipNetworks?.find(n => n.chainNamespace === chainNamespace);
|
|
1077
|
+
this.setCaipNetwork(caipNetwork || fallBackCaipNetwork);
|
|
992
1078
|
this.syncConnectedWalletInfo(chainNamespace);
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1079
|
+
await this.syncBalance({ address, chainId: chainIdToUse, chainNamespace });
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
async syncBalance(params) {
|
|
1083
|
+
const adapter = this.getAdapter(params.chainNamespace);
|
|
1084
|
+
const caipNetwork = NetworkUtil.getNetworksByNamespace(this.caipNetworks, params.chainNamespace).find(n => n.id.toString() === params.chainId.toString());
|
|
1085
|
+
if (!caipNetwork) {
|
|
1086
|
+
return;
|
|
1087
|
+
}
|
|
1088
|
+
const balance = await adapter?.getBalance({
|
|
1089
|
+
address: params.address,
|
|
1090
|
+
chainId: params.chainId,
|
|
1091
|
+
caipNetwork,
|
|
1092
|
+
tokens: this.options.tokens
|
|
1093
|
+
});
|
|
1094
|
+
if (balance) {
|
|
1095
|
+
this.setBalance(balance.balance, balance.symbol, params.chainNamespace);
|
|
1004
1096
|
}
|
|
1005
1097
|
}
|
|
1006
1098
|
syncConnectedWalletInfo(chainNamespace) {
|
|
1007
|
-
const currentActiveWallet =
|
|
1099
|
+
const currentActiveWallet = StorageUtil.getConnectedConnector();
|
|
1008
1100
|
const providerType = ProviderUtil.state.providerIds[chainNamespace];
|
|
1009
1101
|
if (providerType === UtilConstantsUtil.CONNECTOR_TYPE_ANNOUNCED ||
|
|
1010
1102
|
providerType === UtilConstantsUtil.CONNECTOR_TYPE_INJECTED) {
|
|
@@ -1096,35 +1188,34 @@ export class AppKit {
|
|
|
1096
1188
|
[], chainNamespace));
|
|
1097
1189
|
}
|
|
1098
1190
|
async syncExistingConnection() {
|
|
1099
|
-
const connectedConnector =
|
|
1100
|
-
const
|
|
1101
|
-
if (connectedConnector === UtilConstantsUtil.CONNECTOR_TYPE_WALLET_CONNECT &&
|
|
1102
|
-
connectedNamespace) {
|
|
1191
|
+
const connectedConnector = StorageUtil.getConnectedConnector();
|
|
1192
|
+
const activeNamespace = StorageUtil.getActiveNamespace();
|
|
1193
|
+
if (connectedConnector === UtilConstantsUtil.CONNECTOR_TYPE_WALLET_CONNECT && activeNamespace) {
|
|
1103
1194
|
this.syncWalletConnectAccount();
|
|
1104
1195
|
}
|
|
1105
1196
|
else if (connectedConnector &&
|
|
1106
1197
|
connectedConnector !== UtilConstantsUtil.CONNECTOR_TYPE_W3M_AUTH &&
|
|
1107
|
-
|
|
1108
|
-
this.setStatus('connecting',
|
|
1109
|
-
const adapter = this.getAdapter(
|
|
1198
|
+
activeNamespace) {
|
|
1199
|
+
this.setStatus('connecting', activeNamespace);
|
|
1200
|
+
const adapter = this.getAdapter(activeNamespace);
|
|
1110
1201
|
const res = await adapter?.syncConnection({
|
|
1111
1202
|
id: connectedConnector,
|
|
1112
1203
|
chainId: this.getCaipNetwork()?.id,
|
|
1113
|
-
namespace:
|
|
1204
|
+
namespace: activeNamespace,
|
|
1114
1205
|
rpcUrl: this.getCaipNetwork()?.rpcUrls?.default?.http?.[0]
|
|
1115
1206
|
});
|
|
1116
1207
|
if (res) {
|
|
1117
1208
|
const accounts = await adapter?.getAccounts({
|
|
1118
|
-
namespace:
|
|
1209
|
+
namespace: activeNamespace,
|
|
1119
1210
|
id: connectedConnector
|
|
1120
1211
|
});
|
|
1121
|
-
this.syncProvider({ ...res, chainNamespace:
|
|
1122
|
-
await this.syncAccount({ ...res, chainNamespace:
|
|
1123
|
-
this.setAllAccounts(accounts?.accounts || [],
|
|
1124
|
-
this.setStatus('connected',
|
|
1212
|
+
this.syncProvider({ ...res, chainNamespace: activeNamespace });
|
|
1213
|
+
await this.syncAccount({ ...res, chainNamespace: activeNamespace });
|
|
1214
|
+
this.setAllAccounts(accounts?.accounts || [], activeNamespace);
|
|
1215
|
+
this.setStatus('connected', activeNamespace);
|
|
1125
1216
|
}
|
|
1126
1217
|
else {
|
|
1127
|
-
this.setStatus('disconnected',
|
|
1218
|
+
this.setStatus('disconnected', activeNamespace);
|
|
1128
1219
|
}
|
|
1129
1220
|
if (!this.caipNetworks?.some(network => network.id === res?.chainId)) {
|
|
1130
1221
|
if (res?.chainId) {
|
|
@@ -1147,7 +1238,26 @@ export class AppKit {
|
|
|
1147
1238
|
}
|
|
1148
1239
|
return this.universalProviderInitPromise;
|
|
1149
1240
|
}
|
|
1241
|
+
handleAlertError(error) {
|
|
1242
|
+
const matchedUniversalProviderError = Object.entries(ErrorUtil.UniversalProviderErrors).find(([, { message }]) => error.message.includes(message));
|
|
1243
|
+
const [errorKey, errorValue] = matchedUniversalProviderError ?? [];
|
|
1244
|
+
const { message, alertErrorKey } = errorValue ?? {};
|
|
1245
|
+
if (errorKey && message && !this.reportedAlertErrors[errorKey]) {
|
|
1246
|
+
const alertError = ErrorUtil.ALERT_ERRORS[alertErrorKey];
|
|
1247
|
+
if (alertError) {
|
|
1248
|
+
AlertController.open(alertError, 'error');
|
|
1249
|
+
this.reportedAlertErrors[errorKey] = true;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1150
1253
|
async initializeUniversalAdapter() {
|
|
1254
|
+
const logger = LoggerUtil.createLogger((error, ...args) => {
|
|
1255
|
+
if (error) {
|
|
1256
|
+
this.handleAlertError(error);
|
|
1257
|
+
}
|
|
1258
|
+
// eslint-disable-next-line no-console
|
|
1259
|
+
console.error(...args);
|
|
1260
|
+
});
|
|
1151
1261
|
const universalProviderOptions = {
|
|
1152
1262
|
projectId: this.options?.projectId,
|
|
1153
1263
|
metadata: {
|
|
@@ -1155,11 +1265,10 @@ export class AppKit {
|
|
|
1155
1265
|
description: this.options?.metadata ? this.options?.metadata.description : '',
|
|
1156
1266
|
url: this.options?.metadata ? this.options?.metadata.url : '',
|
|
1157
1267
|
icons: this.options?.metadata ? this.options?.metadata.icons : ['']
|
|
1158
|
-
}
|
|
1268
|
+
},
|
|
1269
|
+
logger
|
|
1159
1270
|
};
|
|
1160
|
-
|
|
1161
|
-
this.universalProvider =
|
|
1162
|
-
this.options.walletConnectProvider ?? (await UniversalProvider.init(universalProviderOptions));
|
|
1271
|
+
this.universalProvider = await UniversalProvider.init(universalProviderOptions);
|
|
1163
1272
|
}
|
|
1164
1273
|
async getUniversalProvider() {
|
|
1165
1274
|
if (!this.universalProvider) {
|
|
@@ -1181,7 +1290,10 @@ export class AppKit {
|
|
|
1181
1290
|
: CoreConstantsUtil.DEFAULT_FEATURES.socials;
|
|
1182
1291
|
if (this.options?.projectId && (emailEnabled || socialsEnabled)) {
|
|
1183
1292
|
this.authProvider = W3mFrameProviderSingleton.getInstance({
|
|
1184
|
-
projectId: this.options.projectId
|
|
1293
|
+
projectId: this.options.projectId,
|
|
1294
|
+
onTimeout: () => {
|
|
1295
|
+
AlertController.open(ErrorUtil.ALERT_ERRORS.SOCIALS_TIMEOUT, 'error');
|
|
1296
|
+
}
|
|
1185
1297
|
});
|
|
1186
1298
|
this.listenAuthConnector(this.authProvider);
|
|
1187
1299
|
}
|
|
@@ -1245,7 +1357,7 @@ export class AppKit {
|
|
|
1245
1357
|
this.listenWalletConnect();
|
|
1246
1358
|
}
|
|
1247
1359
|
setDefaultNetwork() {
|
|
1248
|
-
const previousNetwork =
|
|
1360
|
+
const previousNetwork = StorageUtil.getActiveCaipNetworkId();
|
|
1249
1361
|
const caipNetwork = previousNetwork && this.caipNetworks?.length
|
|
1250
1362
|
? this.caipNetworks.find(n => n.caipNetworkId === previousNetwork)
|
|
1251
1363
|
: undefined;
|