@reown/appkit 1.6.2 → 1.6.3-rc.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/auth-provider/W3MFrameProviderSingleton.js +7 -2
- package/dist/esm/src/auth-provider/W3MFrameProviderSingleton.js.map +1 -1
- package/dist/esm/src/client.js +117 -66
- package/dist/esm/src/client.js.map +1 -1
- package/dist/esm/src/library/vue/index.js +3 -3
- package/dist/esm/src/library/vue/index.js.map +1 -1
- package/dist/esm/src/networks/bitcoin.js +2 -1
- package/dist/esm/src/networks/bitcoin.js.map +1 -1
- package/dist/esm/src/tests/appkit.test.js +948 -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/Emitter.js +29 -0
- package/dist/esm/src/tests/mocks/Emitter.js.map +1 -0
- package/dist/esm/src/tests/mocks/Options.js +23 -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 +240 -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 +217 -0
- package/dist/esm/src/tests/utils/HelpersUtil.test.js.map +1 -0
- package/dist/esm/tests/appkit.test.js +1084 -0
- package/dist/esm/tests/appkit.test.js.map +1 -0
- package/dist/esm/tests/mocks/Adapter.js +30 -0
- package/dist/esm/tests/mocks/Adapter.js.map +1 -0
- package/dist/esm/tests/mocks/AppKit.js +24 -0
- package/dist/esm/tests/mocks/AppKit.js.map +1 -0
- package/dist/esm/tests/mocks/Options.js +32 -0
- package/dist/esm/tests/mocks/Options.js.map +1 -0
- package/dist/esm/tests/mocks/UniversalProvider.js +137 -0
- package/dist/esm/tests/mocks/UniversalProvider.js.map +1 -0
- package/dist/esm/tests/siwe.test.js +258 -0
- package/dist/esm/tests/siwe.test.js.map +1 -0
- package/dist/esm/tests/universal-adapter.test.js +115 -0
- package/dist/esm/tests/universal-adapter.test.js.map +1 -0
- package/dist/esm/tests/utils/HelpersUtil.test.js +217 -0
- package/dist/esm/tests/utils/HelpersUtil.test.js.map +1 -0
- 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/auth-provider/W3MFrameProviderSingleton.d.ts +2 -1
- package/dist/types/src/client.d.ts +4 -2
- package/dist/types/src/library/react/index.d.ts +1 -1
- package/dist/types/src/library/vue/index.d.ts +6 -6
- package/dist/types/src/networks/bitcoin.d.ts +1 -1
- 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/Emitter.d.ts +12 -0
- package/dist/types/src/tests/mocks/Options.d.ts +19 -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/tests/appkit.test.d.ts +1 -0
- package/dist/types/tests/mocks/Adapter.d.ts +3 -0
- package/dist/types/tests/mocks/AppKit.d.ts +3 -0
- package/dist/types/tests/mocks/Options.d.ts +19 -0
- package/dist/types/tests/mocks/UniversalProvider.d.ts +3 -0
- package/dist/types/tests/siwe.test.d.ts +1 -0
- package/dist/types/tests/universal-adapter.test.d.ts +1 -0
- package/dist/types/tests/utils/HelpersUtil.test.d.ts +1 -0
- package/package.json +9 -9
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const PACKAGE_VERSION = '1.6.
|
|
1
|
+
export const PACKAGE_VERSION = '1.6.3-rc.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,YAAY,CAAA"}
|
package/dist/esm/package.json
CHANGED
|
@@ -2,9 +2,14 @@ import { W3mFrameProvider } from '@reown/appkit-wallet';
|
|
|
2
2
|
export class W3mFrameProviderSingleton {
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/no-empty-function -- This is a singleton
|
|
4
4
|
constructor() { }
|
|
5
|
-
static getInstance({ projectId, chainId, onTimeout }) {
|
|
5
|
+
static getInstance({ projectId, chainId, enableLogger, onTimeout }) {
|
|
6
6
|
if (!W3mFrameProviderSingleton.instance) {
|
|
7
|
-
W3mFrameProviderSingleton.instance = new W3mFrameProvider({
|
|
7
|
+
W3mFrameProviderSingleton.instance = new W3mFrameProvider({
|
|
8
|
+
projectId,
|
|
9
|
+
chainId,
|
|
10
|
+
enableLogger,
|
|
11
|
+
onTimeout
|
|
12
|
+
});
|
|
8
13
|
}
|
|
9
14
|
return W3mFrameProviderSingleton.instance;
|
|
10
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"W3MFrameProviderSingleton.js","sourceRoot":"","sources":["../../../../src/auth-provider/W3MFrameProviderSingleton.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"W3MFrameProviderSingleton.js","sourceRoot":"","sources":["../../../../src/auth-provider/W3MFrameProviderSingleton.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AASvD,MAAM,OAAO,yBAAyB;IAGpC,uFAAuF;IACvF,gBAAuB,CAAC;IAEjB,MAAM,CAAC,WAAW,CAAC,EACxB,SAAS,EACT,OAAO,EACP,YAAY,EACZ,SAAS,EACc;QACvB,IAAI,CAAC,yBAAyB,CAAC,QAAQ,EAAE,CAAC;YACxC,yBAAyB,CAAC,QAAQ,GAAG,IAAI,gBAAgB,CAAC;gBACxD,SAAS;gBACT,OAAO;gBACP,YAAY;gBACZ,SAAS;aACV,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,yBAAyB,CAAC,QAAQ,CAAA;IAC3C,CAAC;CACF"}
|
package/dist/esm/src/client.js
CHANGED
|
@@ -4,7 +4,7 @@ import { AccountController, BlockchainApiController, ConnectionController, Conne
|
|
|
4
4
|
import { setColorTheme, setThemeVariables } from '@reown/appkit-ui';
|
|
5
5
|
import { NetworkUtil, ConstantsUtil, ParseUtil } from '@reown/appkit-common';
|
|
6
6
|
import { UniversalAdapter, UniversalAdapter as UniversalAdapterClient } from './universal-adapter/client.js';
|
|
7
|
-
import { CaipNetworksUtil, ErrorUtil, LoggerUtil, ConstantsUtil as UtilConstantsUtil } from '@reown/appkit-utils';
|
|
7
|
+
import { CaipNetworksUtil, ErrorUtil, HelpersUtil, 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';
|
|
@@ -114,7 +114,7 @@ export class AppKit {
|
|
|
114
114
|
if (chainNamespace) {
|
|
115
115
|
return ChainController.getRequestedCaipNetworks(chainNamespace).filter(c => c.chainNamespace === chainNamespace)?.[0];
|
|
116
116
|
}
|
|
117
|
-
return ChainController.state.activeCaipNetwork;
|
|
117
|
+
return ChainController.state.activeCaipNetwork || this.defaultCaipNetwork;
|
|
118
118
|
};
|
|
119
119
|
this.getCaipNetworkId = () => {
|
|
120
120
|
const network = this.getCaipNetwork();
|
|
@@ -371,7 +371,7 @@ export class AppKit {
|
|
|
371
371
|
OptionsController.setSocialsOrder(socialsOrder);
|
|
372
372
|
}
|
|
373
373
|
async disconnect() {
|
|
374
|
-
await
|
|
374
|
+
await ConnectionController.disconnect();
|
|
375
375
|
}
|
|
376
376
|
getConnectMethodsOrder() {
|
|
377
377
|
return WalletUtil.getConnectOrderMethod(OptionsController.state.features, ConnectorController.getConnectors());
|
|
@@ -410,6 +410,7 @@ export class AppKit {
|
|
|
410
410
|
OptionsController.setEnableWalletGuide(options.enableWalletGuide !== false);
|
|
411
411
|
OptionsController.setEnableWallets(options.enableWallets !== false);
|
|
412
412
|
OptionsController.setEIP6963Enabled(options.enableEIP6963 !== false);
|
|
413
|
+
OptionsController.setEnableAuthLogger(options.enableAuthLogger !== false);
|
|
413
414
|
if (options.metadata) {
|
|
414
415
|
OptionsController.setMetadata(options.metadata);
|
|
415
416
|
}
|
|
@@ -505,6 +506,7 @@ export class AppKit {
|
|
|
505
506
|
}
|
|
506
507
|
else {
|
|
507
508
|
await adapter?.connectWalletConnect(onUri, this.getCaipNetwork()?.id);
|
|
509
|
+
StorageUtil.setConnectedNamespaces([...ChainController.state.chains.keys()]);
|
|
508
510
|
}
|
|
509
511
|
await this.syncWalletConnectAccount();
|
|
510
512
|
},
|
|
@@ -530,6 +532,7 @@ export class AppKit {
|
|
|
530
532
|
rpcUrl: caipNetwork?.rpcUrls?.default?.http?.[0] ||
|
|
531
533
|
this.getCaipNetwork()?.rpcUrls?.default?.http?.[0]
|
|
532
534
|
});
|
|
535
|
+
StorageUtil.addConnectedNamespace(chainToUse);
|
|
533
536
|
if (res) {
|
|
534
537
|
this.syncProvider({
|
|
535
538
|
...res,
|
|
@@ -549,18 +552,22 @@ export class AppKit {
|
|
|
549
552
|
}
|
|
550
553
|
},
|
|
551
554
|
reconnectExternal: async ({ id, info, type, provider }) => {
|
|
552
|
-
const
|
|
555
|
+
const namespace = ChainController.state.activeChain;
|
|
556
|
+
const adapter = this.getAdapter(namespace);
|
|
553
557
|
if (adapter?.reconnect) {
|
|
554
558
|
await adapter?.reconnect({ id, info, type, provider, chainId: this.getCaipNetwork()?.id });
|
|
559
|
+
StorageUtil.addConnectedNamespace(namespace);
|
|
555
560
|
}
|
|
556
561
|
},
|
|
557
562
|
disconnect: async () => {
|
|
558
|
-
const
|
|
559
|
-
const
|
|
560
|
-
const
|
|
563
|
+
const namespace = ChainController.state.activeChain;
|
|
564
|
+
const adapter = this.getAdapter(namespace);
|
|
565
|
+
const provider = ProviderUtil.getProvider(namespace);
|
|
566
|
+
const providerType = ProviderUtil.state.providerIds[namespace];
|
|
561
567
|
await adapter?.disconnect({ provider, providerType });
|
|
562
|
-
|
|
563
|
-
|
|
568
|
+
StorageUtil.removeConnectedNamespace(namespace);
|
|
569
|
+
ProviderUtil.resetChain(namespace);
|
|
570
|
+
this.setStatus('disconnected', namespace);
|
|
564
571
|
},
|
|
565
572
|
checkInstalled: (ids) => {
|
|
566
573
|
if (!ids) {
|
|
@@ -578,7 +585,7 @@ export class AppKit {
|
|
|
578
585
|
return result?.signature || '';
|
|
579
586
|
},
|
|
580
587
|
sendTransaction: async (args) => {
|
|
581
|
-
if (args.chainNamespace ===
|
|
588
|
+
if (args.chainNamespace === ConstantsUtil.CHAIN.EVM) {
|
|
582
589
|
const adapter = this.getAdapter(ChainController.state.activeChain);
|
|
583
590
|
const provider = ProviderUtil.getProvider(ChainController.state.activeChain);
|
|
584
591
|
const result = await adapter?.sendTransaction({ ...args, provider });
|
|
@@ -587,7 +594,7 @@ export class AppKit {
|
|
|
587
594
|
return '';
|
|
588
595
|
},
|
|
589
596
|
estimateGas: async (args) => {
|
|
590
|
-
if (args.chainNamespace ===
|
|
597
|
+
if (args.chainNamespace === ConstantsUtil.CHAIN.EVM) {
|
|
591
598
|
const adapter = this.getAdapter(ChainController.state.activeChain);
|
|
592
599
|
const provider = ProviderUtil.getProvider(ChainController.state.activeChain);
|
|
593
600
|
const caipNetwork = this.getCaipNetwork();
|
|
@@ -797,15 +804,17 @@ export class AppKit {
|
|
|
797
804
|
}
|
|
798
805
|
});
|
|
799
806
|
provider.onNotConnected(() => {
|
|
800
|
-
const
|
|
807
|
+
const namespace = ChainController.state.activeChain;
|
|
808
|
+
const connectorId = StorageUtil.getConnectedConnectorId(namespace);
|
|
801
809
|
const isConnectedWithAuth = connectorId === ConstantsUtil.CONNECTOR_ID.AUTH;
|
|
802
810
|
if (!isConnected && isConnectedWithAuth) {
|
|
803
|
-
this.setCaipAddress(undefined,
|
|
811
|
+
this.setCaipAddress(undefined, namespace);
|
|
804
812
|
this.setLoading(false);
|
|
805
813
|
}
|
|
806
814
|
});
|
|
807
815
|
provider.onIsConnected(() => {
|
|
808
816
|
provider.connect();
|
|
817
|
+
StorageUtil.addConnectedNamespace(ChainController.state.activeChain);
|
|
809
818
|
});
|
|
810
819
|
provider.onConnect(async (user) => {
|
|
811
820
|
const namespace = ChainController.state.activeChain;
|
|
@@ -816,14 +825,21 @@ export class AppKit {
|
|
|
816
825
|
chainNamespace: namespace
|
|
817
826
|
});
|
|
818
827
|
// To keep backwards compatibility, eip155 chainIds are numbers and not actual caipChainIds
|
|
819
|
-
const caipAddress = namespace ===
|
|
828
|
+
const caipAddress = namespace === ConstantsUtil.CHAIN.EVM
|
|
820
829
|
? `eip155:${user.chainId}:${user.address}`
|
|
821
830
|
: `${user.chainId}:${user.address}`;
|
|
822
|
-
this.setCaipAddress(caipAddress, namespace);
|
|
823
831
|
this.setSmartAccountDeployed(Boolean(user.smartAccountDeployed), namespace);
|
|
832
|
+
if (!HelpersUtil.isLowerCaseMatch(user.address, AccountController.state.address)) {
|
|
833
|
+
this.syncIdentity({
|
|
834
|
+
address: user.address,
|
|
835
|
+
chainId: user.chainId,
|
|
836
|
+
chainNamespace: namespace
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
this.setCaipAddress(caipAddress, namespace);
|
|
824
840
|
const preferredAccountType = (user.preferredAccountType || 'eoa');
|
|
825
841
|
this.setPreferredAccountType(preferredAccountType, namespace);
|
|
826
|
-
const userAccounts = user.accounts?.map(account => CoreHelperUtil.createAccount(namespace, account.address, namespace ===
|
|
842
|
+
const userAccounts = user.accounts?.map(account => CoreHelperUtil.createAccount(namespace, account.address, namespace === ConstantsUtil.CHAIN.EVM ? account.type : 'eoa'));
|
|
827
843
|
this.setAllAccounts(userAccounts || [
|
|
828
844
|
CoreHelperUtil.createAccount(namespace, user.address, preferredAccountType)
|
|
829
845
|
], namespace);
|
|
@@ -839,6 +855,7 @@ export class AppKit {
|
|
|
839
855
|
}
|
|
840
856
|
this.setPreferredAccountType(type, ChainController.state.activeChain);
|
|
841
857
|
});
|
|
858
|
+
const namespace = ChainController.state.activeChain;
|
|
842
859
|
if (isConnected && this.connectionControllerClient?.connectExternal) {
|
|
843
860
|
await this.connectionControllerClient?.connectExternal({
|
|
844
861
|
id: ConstantsUtil.CONNECTOR_ID.AUTH,
|
|
@@ -848,11 +865,12 @@ export class AppKit {
|
|
|
848
865
|
chainId: ChainController.state.activeCaipNetwork?.id
|
|
849
866
|
});
|
|
850
867
|
this.setLoading(false);
|
|
851
|
-
this.setStatus('connected',
|
|
868
|
+
this.setStatus('connected', namespace);
|
|
852
869
|
}
|
|
853
870
|
else {
|
|
854
871
|
this.setLoading(false);
|
|
855
|
-
this.setStatus('disconnected',
|
|
872
|
+
this.setStatus('disconnected', namespace);
|
|
873
|
+
StorageUtil.removeConnectedNamespace(namespace);
|
|
856
874
|
}
|
|
857
875
|
}
|
|
858
876
|
listenWalletConnect() {
|
|
@@ -975,7 +993,7 @@ export class AppKit {
|
|
|
975
993
|
ProviderUtil.setProviderId(chainNamespace, UtilConstantsUtil.CONNECTOR_TYPE_WALLET_CONNECT);
|
|
976
994
|
if (this.caipNetworks &&
|
|
977
995
|
ChainController.state.activeCaipNetwork &&
|
|
978
|
-
adapter?.namespace !==
|
|
996
|
+
adapter?.namespace !== ConstantsUtil.CHAIN.EVM) {
|
|
979
997
|
const provider = adapter?.getWalletConnectProvider({
|
|
980
998
|
caipNetworks: this.caipNetworks,
|
|
981
999
|
provider: this.universalProvider,
|
|
@@ -986,7 +1004,8 @@ export class AppKit {
|
|
|
986
1004
|
else {
|
|
987
1005
|
ProviderUtil.setProvider(chainNamespace, this.universalProvider);
|
|
988
1006
|
}
|
|
989
|
-
StorageUtil.setConnectedConnectorId(ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT);
|
|
1007
|
+
StorageUtil.setConnectedConnectorId(chainNamespace, ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT);
|
|
1008
|
+
StorageUtil.addConnectedNamespace(chainNamespace);
|
|
990
1009
|
let address = '';
|
|
991
1010
|
if (caipAddress.split(':').length === 3) {
|
|
992
1011
|
address = caipAddress.split(':')[2];
|
|
@@ -1041,13 +1060,14 @@ export class AppKit {
|
|
|
1041
1060
|
syncProvider({ type, provider, id, chainNamespace }) {
|
|
1042
1061
|
ProviderUtil.setProviderId(chainNamespace, type);
|
|
1043
1062
|
ProviderUtil.setProvider(chainNamespace, provider);
|
|
1044
|
-
StorageUtil.setConnectedConnectorId(id);
|
|
1063
|
+
StorageUtil.setConnectedConnectorId(chainNamespace, id);
|
|
1045
1064
|
}
|
|
1046
|
-
async syncAccount(
|
|
1065
|
+
async syncAccount(params) {
|
|
1066
|
+
const { address, chainId, chainNamespace } = params;
|
|
1047
1067
|
const { namespace: activeNamespace, chainId: activeChainId } = StorageUtil.getActiveNetworkProps();
|
|
1048
1068
|
const chainIdToUse = chainId || activeChainId;
|
|
1049
1069
|
// Only update state when needed
|
|
1050
|
-
if (address
|
|
1070
|
+
if (!HelpersUtil.isLowerCaseMatch(address, AccountController.state.address)) {
|
|
1051
1071
|
this.setCaipAddress(`${chainNamespace}:${chainId}:${address}`, chainNamespace);
|
|
1052
1072
|
await this.syncIdentity({ address, chainId, chainNamespace });
|
|
1053
1073
|
}
|
|
@@ -1066,6 +1086,10 @@ export class AppKit {
|
|
|
1066
1086
|
if (!caipNetwork) {
|
|
1067
1087
|
return;
|
|
1068
1088
|
}
|
|
1089
|
+
if (caipNetwork.testnet) {
|
|
1090
|
+
this.setBalance('0.00', caipNetwork.nativeCurrency.symbol, caipNetwork.chainNamespace);
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1069
1093
|
const balance = await adapter?.getBalance({
|
|
1070
1094
|
address: params.address,
|
|
1071
1095
|
chainId: params.chainId,
|
|
@@ -1077,14 +1101,16 @@ export class AppKit {
|
|
|
1077
1101
|
}
|
|
1078
1102
|
}
|
|
1079
1103
|
syncConnectedWalletInfo(chainNamespace) {
|
|
1080
|
-
const connectorId = StorageUtil.getConnectedConnectorId();
|
|
1104
|
+
const connectorId = StorageUtil.getConnectedConnectorId(chainNamespace);
|
|
1081
1105
|
const providerType = ProviderUtil.state.providerIds[chainNamespace];
|
|
1082
1106
|
if (providerType === UtilConstantsUtil.CONNECTOR_TYPE_ANNOUNCED ||
|
|
1083
1107
|
providerType === UtilConstantsUtil.CONNECTOR_TYPE_INJECTED) {
|
|
1084
1108
|
if (connectorId) {
|
|
1085
1109
|
const connector = this.getConnectors().find(c => c.id === connectorId);
|
|
1086
|
-
if (connector
|
|
1087
|
-
|
|
1110
|
+
if (connector) {
|
|
1111
|
+
const { info, name, imageUrl } = connector;
|
|
1112
|
+
const icon = imageUrl || this.getConnectorImage(connector);
|
|
1113
|
+
this.setConnectedWalletInfo({ name, icon, ...info }, chainNamespace);
|
|
1088
1114
|
}
|
|
1089
1115
|
}
|
|
1090
1116
|
}
|
|
@@ -1107,7 +1133,8 @@ export class AppKit {
|
|
|
1107
1133
|
}
|
|
1108
1134
|
}
|
|
1109
1135
|
async syncIdentity({ address, chainId, chainNamespace }) {
|
|
1110
|
-
|
|
1136
|
+
const activeCaipNetwork = this.caipNetworks?.find(n => n.caipNetworkId === `${chainNamespace}:${chainId}`);
|
|
1137
|
+
if (chainNamespace !== ConstantsUtil.CHAIN.EVM || activeCaipNetwork?.testnet) {
|
|
1111
1138
|
return;
|
|
1112
1139
|
}
|
|
1113
1140
|
try {
|
|
@@ -1168,56 +1195,78 @@ export class AppKit {
|
|
|
1168
1195
|
uniqueChainNamespaces.forEach(chainNamespace => this.setRequestedCaipNetworks(this.caipNetworks?.filter(caipNetwork => caipNetwork.chainNamespace === chainNamespace) ??
|
|
1169
1196
|
[], chainNamespace));
|
|
1170
1197
|
}
|
|
1171
|
-
async
|
|
1198
|
+
async syncAdapterConnection(namespace) {
|
|
1199
|
+
const adapter = this.getAdapter(namespace);
|
|
1200
|
+
const connectorId = StorageUtil.getConnectedConnectorId(namespace);
|
|
1201
|
+
const caipNetwork = this.getCaipNetwork();
|
|
1172
1202
|
try {
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
if (connectorId === ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT && activeNamespace) {
|
|
1176
|
-
this.syncWalletConnectAccount();
|
|
1203
|
+
if (!adapter || !connectorId) {
|
|
1204
|
+
throw new Error(`Adapter or connectorId not found for namespace ${namespace}`);
|
|
1177
1205
|
}
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
namespace
|
|
1187
|
-
|
|
1206
|
+
const connection = await adapter?.syncConnection({
|
|
1207
|
+
namespace,
|
|
1208
|
+
id: connectorId,
|
|
1209
|
+
chainId: caipNetwork?.id,
|
|
1210
|
+
rpcUrl: caipNetwork?.rpcUrls?.default?.http?.[0]
|
|
1211
|
+
});
|
|
1212
|
+
if (connection) {
|
|
1213
|
+
const accounts = await adapter?.getAccounts({
|
|
1214
|
+
namespace,
|
|
1215
|
+
id: connectorId
|
|
1188
1216
|
});
|
|
1189
|
-
if (
|
|
1190
|
-
|
|
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);
|
|
1217
|
+
if (accounts && accounts.accounts.length > 0) {
|
|
1218
|
+
this.setAllAccounts(accounts.accounts, namespace);
|
|
1201
1219
|
}
|
|
1202
1220
|
else {
|
|
1203
|
-
this.
|
|
1204
|
-
}
|
|
1205
|
-
if (!this.caipNetworks?.some(network => network.id === res?.chainId)) {
|
|
1206
|
-
if (res?.chainId) {
|
|
1207
|
-
this.setUnsupportedNetwork(res.chainId);
|
|
1208
|
-
}
|
|
1221
|
+
this.setAllAccounts([CoreHelperUtil.createAccount(namespace, connection.address, 'eoa')], namespace);
|
|
1209
1222
|
}
|
|
1223
|
+
this.syncProvider({ ...connection, chainNamespace: namespace });
|
|
1224
|
+
await this.syncAccount({ ...connection, chainNamespace: namespace });
|
|
1225
|
+
this.setStatus('connected', namespace);
|
|
1210
1226
|
}
|
|
1211
|
-
else
|
|
1212
|
-
this.setStatus('disconnected',
|
|
1227
|
+
else {
|
|
1228
|
+
this.setStatus('disconnected', namespace);
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
catch (e) {
|
|
1232
|
+
console.warn(`Error syncing connection for namespace ${namespace}`, e);
|
|
1233
|
+
StorageUtil.deleteConnectedConnectorId(namespace);
|
|
1234
|
+
this.setStatus('disconnected', namespace);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
async syncNamespaceConnection(namespace) {
|
|
1238
|
+
const connectorId = StorageUtil.getConnectedConnectorId(namespace);
|
|
1239
|
+
const isEmailUsed = this.authProvider?.getLoginEmailUsed();
|
|
1240
|
+
if (isEmailUsed) {
|
|
1241
|
+
return;
|
|
1242
|
+
}
|
|
1243
|
+
this.setStatus('connecting', namespace);
|
|
1244
|
+
switch (connectorId) {
|
|
1245
|
+
case ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT:
|
|
1246
|
+
await this.syncWalletConnectAccount();
|
|
1247
|
+
break;
|
|
1248
|
+
case ConstantsUtil.CONNECTOR_ID.AUTH:
|
|
1249
|
+
// Handled during initialization of adapters' auth provider
|
|
1250
|
+
break;
|
|
1251
|
+
default:
|
|
1252
|
+
await this.syncAdapterConnection(namespace);
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
async syncExistingConnection() {
|
|
1256
|
+
const connectedNamespaces = StorageUtil.getConnectedNamespaces();
|
|
1257
|
+
try {
|
|
1258
|
+
if (connectedNamespaces?.length > 0) {
|
|
1259
|
+
await Promise.all(connectedNamespaces.map(namespace => this.syncNamespaceConnection(namespace)));
|
|
1213
1260
|
}
|
|
1214
1261
|
}
|
|
1215
1262
|
catch (err) {
|
|
1216
1263
|
// eslint-disable-next-line no-console
|
|
1217
|
-
console.
|
|
1264
|
+
console.warn("AppKit couldn't sync existing connection", err);
|
|
1218
1265
|
this.disconnect().finally(() => {
|
|
1219
|
-
|
|
1220
|
-
|
|
1266
|
+
connectedNamespaces.forEach(namespace => {
|
|
1267
|
+
StorageUtil.deleteConnectedConnectorId(namespace);
|
|
1268
|
+
this.setStatus('disconnected', namespace);
|
|
1269
|
+
});
|
|
1221
1270
|
});
|
|
1222
1271
|
}
|
|
1223
1272
|
}
|
|
@@ -1285,9 +1334,11 @@ export class AppKit {
|
|
|
1285
1334
|
const isSocialsEnabled = this.options?.features?.socials
|
|
1286
1335
|
? this.options?.features?.socials?.length > 0
|
|
1287
1336
|
: CoreConstantsUtil.DEFAULT_FEATURES.socials;
|
|
1288
|
-
|
|
1337
|
+
const isAuthEnabled = isEmailEnabled || isSocialsEnabled;
|
|
1338
|
+
if (!this.authProvider && this.options?.projectId && isAuthEnabled) {
|
|
1289
1339
|
this.authProvider = W3mFrameProviderSingleton.getInstance({
|
|
1290
1340
|
projectId: this.options.projectId,
|
|
1341
|
+
enableLogger: this.options.enableAuthLogger,
|
|
1291
1342
|
onTimeout: () => {
|
|
1292
1343
|
AlertController.open(ErrorUtil.ALERT_ERRORS.SOCIALS_TIMEOUT, 'error');
|
|
1293
1344
|
}
|