@reown/appkit-cdn 1.5.3-d55ad02.0 → 1.5.3

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.
Files changed (32) hide show
  1. package/dist/{appkit-DzvwQvlf.js → appkit-DzmuJOIk.js} +1831 -1740
  2. package/dist/{appkit-DzvwQvlf.js.map → appkit-DzmuJOIk.js.map} +1 -1
  3. package/dist/appkit.js +1 -1
  4. package/dist/{ccip-zsB2BkYF.js → ccip-oJ7D52h2.js} +2 -2
  5. package/dist/{ccip-zsB2BkYF.js.map → ccip-oJ7D52h2.js.map} +1 -1
  6. package/dist/{hooks.module-DNX6U7Ho.js → hooks.module-B2xqDe4d.js} +2 -2
  7. package/dist/{hooks.module-DNX6U7Ho.js.map → hooks.module-B2xqDe4d.js.map} +1 -1
  8. package/dist/{index-BxOGuMA7.js → index-4BL-xvPV.js} +2 -2
  9. package/dist/{index-BxOGuMA7.js.map → index-4BL-xvPV.js.map} +1 -1
  10. package/dist/{index-DAGjeNF9.js → index-BCD-kidI.js} +3 -3
  11. package/dist/{index-DAGjeNF9.js.map → index-BCD-kidI.js.map} +1 -1
  12. package/dist/{index-B0uLXw8m.js → index-BCUshd0_.js} +3 -3
  13. package/dist/{index-B0uLXw8m.js.map → index-BCUshd0_.js.map} +1 -1
  14. package/dist/{index-BEeFNebT.js → index-BtyArmdy.js} +3 -3
  15. package/dist/{index-BEeFNebT.js.map → index-BtyArmdy.js.map} +1 -1
  16. package/dist/{index-CddnljwX.js → index-CRnsv5ja.js} +8 -4
  17. package/dist/{index-CddnljwX.js.map → index-CRnsv5ja.js.map} +1 -1
  18. package/dist/{index-BYpF8N_A.js → index-CjymKZdr.js} +3 -3
  19. package/dist/{index-BYpF8N_A.js.map → index-CjymKZdr.js.map} +1 -1
  20. package/dist/{index-CFRZcZYC.js → index-DWlvgckp.js} +2 -2
  21. package/dist/{index-CFRZcZYC.js.map → index-DWlvgckp.js.map} +1 -1
  22. package/dist/{index-DHyiWE9V.js → index-t1a7ymTD.js} +3 -3
  23. package/dist/{index-DHyiWE9V.js.map → index-t1a7ymTD.js.map} +1 -1
  24. package/dist/{index.es-DWLMeaKr.js → index.es-DznsrD1v.js} +3 -3
  25. package/dist/{index.es-DWLMeaKr.js.map → index.es-DznsrD1v.js.map} +1 -1
  26. package/dist/{metamask-sdk-DKgosmUG.js → metamask-sdk-B6ijR6YT.js} +2 -2
  27. package/dist/{metamask-sdk-DKgosmUG.js.map → metamask-sdk-B6ijR6YT.js.map} +1 -1
  28. package/dist/{native-ClayS85q.js → native-k0b2Co6F.js} +2 -2
  29. package/dist/{native-ClayS85q.js.map → native-k0b2Co6F.js.map} +1 -1
  30. package/dist/{w3m-modal-Cdt8C88F.js → w3m-modal-CoAkKS0G.js} +2 -2
  31. package/dist/{w3m-modal-Cdt8C88F.js.map → w3m-modal-CoAkKS0G.js.map} +1 -1
  32. package/package.json +7 -7
@@ -4392,7 +4392,8 @@ const SafeLocalStorageKeys = {
4392
4392
  CONNECTED_SOCIAL_USERNAME: "@appkit/connected_social_username",
4393
4393
  RECENT_WALLETS: "@appkit/recent_wallets",
4394
4394
  DEEPLINK_CHOICE: "WALLETCONNECT_DEEPLINK_CHOICE",
4395
- CONNECTED_NAMESPACE: "@appkit/connected_namespace"
4395
+ CONNECTED_NAMESPACE: "@appkit/connected_namespace",
4396
+ CONNECTION_STATUS: "@appkit/connection_status"
4396
4397
  };
4397
4398
  const SafeLocalStorage = {
4398
4399
  setItem(key2, value) {
@@ -12724,6 +12725,1347 @@ const PublicStateController = {
12724
12725
  Object.assign(state$c, { ...state$c, ...newState });
12725
12726
  }
12726
12727
  };
12728
+ const accountState$1 = {
12729
+ currentTab: 0,
12730
+ tokenBalance: [],
12731
+ smartAccountDeployed: false,
12732
+ addressLabels: /* @__PURE__ */ new Map(),
12733
+ allAccounts: []
12734
+ };
12735
+ const networkState$1 = {
12736
+ supportsAllNetworks: true,
12737
+ smartAccountEnabledNetworks: []
12738
+ };
12739
+ const state$b = proxy({
12740
+ chains: proxyMap(),
12741
+ activeCaipAddress: void 0,
12742
+ activeChain: void 0,
12743
+ activeCaipNetwork: void 0,
12744
+ noAdapters: false,
12745
+ universalAdapter: {
12746
+ networkControllerClient: void 0,
12747
+ connectionControllerClient: void 0
12748
+ }
12749
+ });
12750
+ const ChainController = {
12751
+ state: state$b,
12752
+ subscribe(callback) {
12753
+ return subscribe(state$b, () => {
12754
+ callback(state$b);
12755
+ });
12756
+ },
12757
+ subscribeKey(key2, callback) {
12758
+ return subscribeKey(state$b, key2, callback);
12759
+ },
12760
+ subscribeChainProp(property, callback, chain) {
12761
+ let prev = void 0;
12762
+ return subscribe(state$b.chains, () => {
12763
+ var _a3;
12764
+ const activeChain = chain || state$b.activeChain;
12765
+ if (activeChain) {
12766
+ const nextValue = (_a3 = state$b.chains.get(activeChain)) == null ? void 0 : _a3[property];
12767
+ if (prev !== nextValue) {
12768
+ prev = nextValue;
12769
+ callback(nextValue);
12770
+ }
12771
+ }
12772
+ });
12773
+ },
12774
+ initialize(adapters) {
12775
+ const adapterToActivate = adapters == null ? void 0 : adapters[0];
12776
+ if ((adapters == null ? void 0 : adapters.length) === 0 || !adapterToActivate) {
12777
+ state$b.noAdapters = true;
12778
+ }
12779
+ if (!state$b.noAdapters) {
12780
+ state$b.activeChain = adapterToActivate == null ? void 0 : adapterToActivate.namespace;
12781
+ PublicStateController.set({ activeChain: adapterToActivate == null ? void 0 : adapterToActivate.namespace });
12782
+ adapters.forEach((adapter) => {
12783
+ state$b.chains.set(adapter.namespace, {
12784
+ namespace: adapter.namespace,
12785
+ connectionControllerClient: adapter.connectionControllerClient,
12786
+ networkControllerClient: adapter.networkControllerClient,
12787
+ adapterType: adapter.adapterType,
12788
+ accountState: accountState$1,
12789
+ networkState: networkState$1,
12790
+ caipNetworks: adapter.caipNetworks
12791
+ });
12792
+ });
12793
+ }
12794
+ },
12795
+ setAdapterNetworkState(chain, props) {
12796
+ const chainAdapter = state$b.chains.get(chain);
12797
+ if (chainAdapter) {
12798
+ chainAdapter.networkState = ref$1({
12799
+ ...chainAdapter.networkState,
12800
+ ...props
12801
+ });
12802
+ state$b.chains.set(chain, ref$1(chainAdapter));
12803
+ }
12804
+ },
12805
+ setChainAccountData(chain, accountProps, _unknown = true) {
12806
+ if (!chain) {
12807
+ throw new Error("Chain is required to update chain account data");
12808
+ }
12809
+ const chainAdapter = state$b.chains.get(chain);
12810
+ if (chainAdapter) {
12811
+ chainAdapter.accountState = ref$1({
12812
+ ...chainAdapter.accountState,
12813
+ ...accountProps
12814
+ });
12815
+ state$b.chains.set(chain, chainAdapter);
12816
+ if (state$b.chains.size === 1 || state$b.activeChain === chain) {
12817
+ if (accountProps.caipAddress) {
12818
+ state$b.activeCaipAddress = accountProps.caipAddress;
12819
+ }
12820
+ AccountController.replaceState(chainAdapter.accountState);
12821
+ }
12822
+ }
12823
+ },
12824
+ // eslint-disable-next-line max-params
12825
+ setAccountProp(prop, value, chain, replaceState = true) {
12826
+ this.setChainAccountData(chain, {
12827
+ [prop]: value
12828
+ }, replaceState);
12829
+ },
12830
+ setActiveNamespace(chain) {
12831
+ var _a3, _b2;
12832
+ state$b.activeChain = chain;
12833
+ const newAdapter = chain ? state$b.chains.get(chain) : void 0;
12834
+ const caipNetwork = (_a3 = newAdapter == null ? void 0 : newAdapter.networkState) == null ? void 0 : _a3.caipNetwork;
12835
+ if (caipNetwork == null ? void 0 : caipNetwork.id) {
12836
+ state$b.activeCaipAddress = (_b2 = newAdapter == null ? void 0 : newAdapter.accountState) == null ? void 0 : _b2.caipAddress;
12837
+ state$b.activeCaipNetwork = caipNetwork;
12838
+ SafeLocalStorage.setItem(SafeLocalStorageKeys.ACTIVE_CAIP_NETWORK_ID, caipNetwork == null ? void 0 : caipNetwork.caipNetworkId);
12839
+ PublicStateController.set({
12840
+ activeChain: chain,
12841
+ selectedNetworkId: caipNetwork == null ? void 0 : caipNetwork.caipNetworkId
12842
+ });
12843
+ }
12844
+ },
12845
+ setActiveCaipNetwork(caipNetwork) {
12846
+ var _a3, _b2, _c;
12847
+ if (!caipNetwork) {
12848
+ return;
12849
+ }
12850
+ const newAdapter = state$b.chains.get(caipNetwork.chainNamespace);
12851
+ state$b.activeChain = caipNetwork.chainNamespace;
12852
+ state$b.activeCaipNetwork = caipNetwork;
12853
+ if ((_a3 = newAdapter == null ? void 0 : newAdapter.accountState) == null ? void 0 : _a3.address) {
12854
+ state$b.activeCaipAddress = `${caipNetwork.chainNamespace}:${caipNetwork.id}:${(_b2 = newAdapter == null ? void 0 : newAdapter.accountState) == null ? void 0 : _b2.address}`;
12855
+ } else {
12856
+ state$b.activeCaipAddress = void 0;
12857
+ }
12858
+ if (newAdapter) {
12859
+ AccountController.replaceState(newAdapter.accountState);
12860
+ }
12861
+ PublicStateController.set({
12862
+ activeChain: state$b.activeChain,
12863
+ selectedNetworkId: (_c = state$b.activeCaipNetwork) == null ? void 0 : _c.caipNetworkId
12864
+ });
12865
+ SafeLocalStorage.setItem(SafeLocalStorageKeys.ACTIVE_CAIP_NETWORK_ID, caipNetwork.caipNetworkId);
12866
+ const isSupported = this.checkIfSupportedNetwork(caipNetwork.chainNamespace);
12867
+ if (!isSupported) {
12868
+ this.showUnsupportedChainUI();
12869
+ }
12870
+ },
12871
+ addCaipNetwork(caipNetwork) {
12872
+ var _a3;
12873
+ if (!caipNetwork) {
12874
+ return;
12875
+ }
12876
+ const chain = state$b.chains.get(caipNetwork.chainNamespace);
12877
+ if (chain) {
12878
+ (_a3 = chain == null ? void 0 : chain.caipNetworks) == null ? void 0 : _a3.push(caipNetwork);
12879
+ }
12880
+ },
12881
+ async switchActiveNetwork(network) {
12882
+ var _a3;
12883
+ const activeAdapter = ChainController.state.chains.get(ChainController.state.activeChain);
12884
+ const unsupportedNetwork = !((_a3 = activeAdapter == null ? void 0 : activeAdapter.caipNetworks) == null ? void 0 : _a3.some((caipNetwork) => {
12885
+ var _a4;
12886
+ return caipNetwork.id === ((_a4 = state$b.activeCaipNetwork) == null ? void 0 : _a4.id);
12887
+ }));
12888
+ const networkControllerClient = this.getNetworkControllerClient(network.chainNamespace);
12889
+ if (networkControllerClient) {
12890
+ await networkControllerClient.switchCaipNetwork(network);
12891
+ }
12892
+ if (unsupportedNetwork) {
12893
+ RouterController.goBack();
12894
+ }
12895
+ this.setActiveCaipNetwork(network);
12896
+ if (network) {
12897
+ EventsController.sendEvent({
12898
+ type: "track",
12899
+ event: "SWITCH_NETWORK",
12900
+ properties: { network: network.caipNetworkId }
12901
+ });
12902
+ }
12903
+ },
12904
+ setActiveConnector(connector) {
12905
+ if (connector) {
12906
+ state$b.activeConnector = ref$1(connector);
12907
+ }
12908
+ },
12909
+ getNetworkControllerClient(chainNamespace) {
12910
+ const chain = chainNamespace || state$b.activeChain;
12911
+ const chainAdapter = state$b.chains.get(chain);
12912
+ if (!chainAdapter) {
12913
+ throw new Error("Chain adapter not found");
12914
+ }
12915
+ if (!chainAdapter.networkControllerClient) {
12916
+ throw new Error("NetworkController client not set");
12917
+ }
12918
+ return chainAdapter.networkControllerClient;
12919
+ },
12920
+ getConnectionControllerClient(_chain) {
12921
+ const chain = _chain || state$b.activeChain;
12922
+ if (!chain) {
12923
+ throw new Error("Chain is required to get connection controller client");
12924
+ }
12925
+ const chainAdapter = state$b.chains.get(chain);
12926
+ if (!(chainAdapter == null ? void 0 : chainAdapter.connectionControllerClient)) {
12927
+ throw new Error("ConnectionController client not set");
12928
+ }
12929
+ return chainAdapter.connectionControllerClient;
12930
+ },
12931
+ getAccountProp(key2, _chain) {
12932
+ var _a3;
12933
+ let chain = state$b.activeChain;
12934
+ if (_chain) {
12935
+ chain = _chain;
12936
+ }
12937
+ if (!chain) {
12938
+ return void 0;
12939
+ }
12940
+ const chainAccountState = (_a3 = state$b.chains.get(chain)) == null ? void 0 : _a3.accountState;
12941
+ if (!chainAccountState) {
12942
+ return void 0;
12943
+ }
12944
+ return chainAccountState[key2];
12945
+ },
12946
+ getNetworkProp(key2, namespace) {
12947
+ var _a3;
12948
+ const chainNetworkState = (_a3 = state$b.chains.get(namespace)) == null ? void 0 : _a3.networkState;
12949
+ if (!chainNetworkState) {
12950
+ return void 0;
12951
+ }
12952
+ return chainNetworkState[key2];
12953
+ },
12954
+ getRequestedCaipNetworks(chainToFilter) {
12955
+ const adapter = state$b.chains.get(chainToFilter);
12956
+ const { approvedCaipNetworkIds = [], requestedCaipNetworks = [] } = (adapter == null ? void 0 : adapter.networkState) || {};
12957
+ const sortedNetworks = CoreHelperUtil.sortRequestedNetworks(approvedCaipNetworkIds, requestedCaipNetworks);
12958
+ return sortedNetworks;
12959
+ },
12960
+ getAllRequestedCaipNetworks() {
12961
+ const requestedCaipNetworks = [];
12962
+ state$b.chains.forEach((chainAdapter) => {
12963
+ const caipNetworks = this.getRequestedCaipNetworks(chainAdapter.namespace);
12964
+ requestedCaipNetworks.push(...caipNetworks);
12965
+ });
12966
+ return requestedCaipNetworks;
12967
+ },
12968
+ setRequestedCaipNetworks(requestedNetworks, chain) {
12969
+ this.setAdapterNetworkState(chain, { requestedCaipNetworks: requestedNetworks });
12970
+ },
12971
+ getAllApprovedCaipNetworkIds() {
12972
+ const approvedCaipNetworkIds = [];
12973
+ state$b.chains.forEach((chainAdapter) => {
12974
+ const approvedIds = this.getApprovedCaipNetworkIds(chainAdapter.namespace);
12975
+ approvedCaipNetworkIds.push(...approvedIds);
12976
+ });
12977
+ return approvedCaipNetworkIds;
12978
+ },
12979
+ getActiveCaipNetwork() {
12980
+ return state$b.activeCaipNetwork;
12981
+ },
12982
+ getActiveCaipAddress() {
12983
+ return state$b.activeCaipAddress;
12984
+ },
12985
+ getApprovedCaipNetworkIds(namespace) {
12986
+ var _a3;
12987
+ const adapter = state$b.chains.get(namespace);
12988
+ const approvedCaipNetworkIds = ((_a3 = adapter == null ? void 0 : adapter.networkState) == null ? void 0 : _a3.approvedCaipNetworkIds) || [];
12989
+ return approvedCaipNetworkIds;
12990
+ },
12991
+ async setApprovedCaipNetworksData(namespace) {
12992
+ const networkControllerClient = this.getNetworkControllerClient();
12993
+ const data2 = await (networkControllerClient == null ? void 0 : networkControllerClient.getApprovedCaipNetworksData());
12994
+ this.setAdapterNetworkState(namespace, {
12995
+ approvedCaipNetworkIds: data2 == null ? void 0 : data2.approvedCaipNetworkIds,
12996
+ supportsAllNetworks: data2 == null ? void 0 : data2.supportsAllNetworks
12997
+ });
12998
+ },
12999
+ checkIfSupportedNetwork(namespace) {
13000
+ const activeCaipNetwork = this.state.activeCaipNetwork;
13001
+ const requestedCaipNetworks = this.getRequestedCaipNetworks(namespace);
13002
+ if (!requestedCaipNetworks.length) {
13003
+ return true;
13004
+ }
13005
+ return requestedCaipNetworks == null ? void 0 : requestedCaipNetworks.some((network) => network.id === (activeCaipNetwork == null ? void 0 : activeCaipNetwork.id));
13006
+ },
13007
+ checkIfSupportedChainId(chainId) {
13008
+ if (!this.state.activeChain) {
13009
+ return true;
13010
+ }
13011
+ const requestedCaipNetworks = this.getRequestedCaipNetworks(this.state.activeChain);
13012
+ return requestedCaipNetworks == null ? void 0 : requestedCaipNetworks.some((network) => network.id === chainId);
13013
+ },
13014
+ // Smart Account Network Handlers
13015
+ setSmartAccountEnabledNetworks(smartAccountEnabledNetworks, chain) {
13016
+ this.setAdapterNetworkState(chain, { smartAccountEnabledNetworks });
13017
+ },
13018
+ checkIfSmartAccountEnabled() {
13019
+ var _a3;
13020
+ const networkId = NetworkUtil.caipNetworkIdToNumber((_a3 = state$b.activeCaipNetwork) == null ? void 0 : _a3.caipNetworkId);
13021
+ const activeChain = this.state.activeChain;
13022
+ if (!activeChain || !networkId) {
13023
+ return false;
13024
+ }
13025
+ const smartAccountEnabledNetworks = this.getNetworkProp("smartAccountEnabledNetworks", activeChain);
13026
+ return Boolean(smartAccountEnabledNetworks == null ? void 0 : smartAccountEnabledNetworks.includes(Number(networkId)));
13027
+ },
13028
+ getActiveNetworkTokenAddress() {
13029
+ var _a3, _b2;
13030
+ const namespace = ((_a3 = this.state.activeCaipNetwork) == null ? void 0 : _a3.chainNamespace) || "eip155";
13031
+ const chainId = ((_b2 = this.state.activeCaipNetwork) == null ? void 0 : _b2.id) || 1;
13032
+ const address = ConstantsUtil$2.NATIVE_TOKEN_ADDRESS[namespace];
13033
+ return `${namespace}:${chainId}:${address}`;
13034
+ },
13035
+ showUnsupportedChainUI() {
13036
+ setTimeout(() => {
13037
+ ModalController.open({ view: "UnsupportedChain" });
13038
+ }, 300);
13039
+ },
13040
+ checkIfNamesSupported() {
13041
+ const activeCaipNetwork = state$b.activeCaipNetwork;
13042
+ return Boolean((activeCaipNetwork == null ? void 0 : activeCaipNetwork.chainNamespace) && ConstantsUtil$2.NAMES_SUPPORTED_CHAIN_NAMESPACES.includes(activeCaipNetwork.chainNamespace));
13043
+ },
13044
+ resetNetwork(namespace) {
13045
+ this.setAdapterNetworkState(namespace, {
13046
+ approvedCaipNetworkIds: void 0,
13047
+ supportsAllNetworks: true,
13048
+ smartAccountEnabledNetworks: []
13049
+ });
13050
+ },
13051
+ resetAccount(chain) {
13052
+ const chainToWrite = chain;
13053
+ if (!chainToWrite) {
13054
+ throw new Error("Chain is required to set account prop");
13055
+ }
13056
+ this.state.activeCaipAddress = void 0;
13057
+ this.setChainAccountData(chainToWrite, ref$1({
13058
+ smartAccountDeployed: false,
13059
+ currentTab: 0,
13060
+ caipAddress: void 0,
13061
+ address: void 0,
13062
+ balance: void 0,
13063
+ balanceSymbol: void 0,
13064
+ profileName: void 0,
13065
+ profileImage: void 0,
13066
+ addressExplorerUrl: void 0,
13067
+ tokenBalance: [],
13068
+ connectedWalletInfo: void 0,
13069
+ preferredAccountType: void 0,
13070
+ socialProvider: void 0,
13071
+ socialWindow: void 0,
13072
+ farcasterUrl: void 0,
13073
+ provider: void 0
13074
+ }));
13075
+ }
13076
+ };
13077
+ const StorageUtil = {
13078
+ setWalletConnectDeepLink({ name: name2, href }) {
13079
+ try {
13080
+ SafeLocalStorage.setItem(SafeLocalStorageKeys.DEEPLINK_CHOICE, JSON.stringify({ href, name: name2 }));
13081
+ } catch {
13082
+ console.info("Unable to set WalletConnect deep link");
13083
+ }
13084
+ },
13085
+ getWalletConnectDeepLink() {
13086
+ try {
13087
+ const deepLink = SafeLocalStorage.getItem(SafeLocalStorageKeys.DEEPLINK_CHOICE);
13088
+ if (deepLink) {
13089
+ return JSON.parse(deepLink);
13090
+ }
13091
+ } catch {
13092
+ console.info("Unable to get WalletConnect deep link");
13093
+ }
13094
+ return void 0;
13095
+ },
13096
+ deleteWalletConnectDeepLink() {
13097
+ try {
13098
+ SafeLocalStorage.removeItem(SafeLocalStorageKeys.DEEPLINK_CHOICE);
13099
+ } catch {
13100
+ console.info("Unable to delete WalletConnect deep link");
13101
+ }
13102
+ },
13103
+ setAppKitRecent(wallet) {
13104
+ try {
13105
+ const recentWallets = StorageUtil.getRecentWallets();
13106
+ const exists2 = recentWallets.find((w2) => w2.id === wallet.id);
13107
+ if (!exists2) {
13108
+ recentWallets.unshift(wallet);
13109
+ if (recentWallets.length > 2) {
13110
+ recentWallets.pop();
13111
+ }
13112
+ SafeLocalStorage.setItem(SafeLocalStorageKeys.RECENT_WALLETS, JSON.stringify(recentWallets));
13113
+ }
13114
+ } catch {
13115
+ console.info("Unable to set AppKit recent");
13116
+ }
13117
+ },
13118
+ getRecentWallets() {
13119
+ try {
13120
+ const recent = SafeLocalStorage.getItem(SafeLocalStorageKeys.RECENT_WALLETS);
13121
+ return recent ? JSON.parse(recent) : [];
13122
+ } catch {
13123
+ console.info("Unable to get AppKit recent");
13124
+ }
13125
+ return [];
13126
+ },
13127
+ setConnectedConnector(connectorType) {
13128
+ try {
13129
+ SafeLocalStorage.setItem(SafeLocalStorageKeys.CONNECTED_CONNECTOR, connectorType);
13130
+ } catch {
13131
+ console.info("Unable to set Connected Connector");
13132
+ }
13133
+ },
13134
+ setConnectedNamespace(namespace) {
13135
+ try {
13136
+ SafeLocalStorage.setItem(SafeLocalStorageKeys.CONNECTED_NAMESPACE, namespace);
13137
+ } catch {
13138
+ console.info("Unable to set Connected Namespace");
13139
+ }
13140
+ },
13141
+ getConnectedConnector() {
13142
+ try {
13143
+ return SafeLocalStorage.getItem(SafeLocalStorageKeys.CONNECTED_CONNECTOR);
13144
+ } catch {
13145
+ console.info("Unable to get Connected Connector");
13146
+ }
13147
+ return void 0;
13148
+ },
13149
+ setConnectedSocialProvider(socialProvider) {
13150
+ try {
13151
+ SafeLocalStorage.setItem(SafeLocalStorageKeys.CONNECTED_SOCIAL, socialProvider);
13152
+ } catch {
13153
+ console.info("Unable to set Connected Social Provider");
13154
+ }
13155
+ },
13156
+ getConnectedSocialProvider() {
13157
+ try {
13158
+ return SafeLocalStorage.getItem(SafeLocalStorageKeys.CONNECTED_SOCIAL);
13159
+ } catch {
13160
+ console.info("Unable to get Connected Social Provider");
13161
+ }
13162
+ return void 0;
13163
+ },
13164
+ getConnectedSocialUsername() {
13165
+ try {
13166
+ return SafeLocalStorage.getItem(SafeLocalStorageKeys.CONNECTED_SOCIAL_USERNAME);
13167
+ } catch {
13168
+ console.info("Unable to get Connected Social Username");
13169
+ }
13170
+ return void 0;
13171
+ },
13172
+ getStoredActiveCaipNetwork() {
13173
+ const storedCaipNetworkId = SafeLocalStorage.getItem(SafeLocalStorageKeys.ACTIVE_CAIP_NETWORK_ID);
13174
+ const allRequestedCaipNetworks = ChainController.getAllRequestedCaipNetworks();
13175
+ const storedCaipNetwork = allRequestedCaipNetworks == null ? void 0 : allRequestedCaipNetworks.find((c2) => c2.caipNetworkId === storedCaipNetworkId);
13176
+ return storedCaipNetwork;
13177
+ },
13178
+ setConnectionStatus(status) {
13179
+ try {
13180
+ SafeLocalStorage.setItem(SafeLocalStorageKeys.CONNECTION_STATUS, status);
13181
+ } catch {
13182
+ console.info("Unable to set Connection Status");
13183
+ }
13184
+ },
13185
+ getConnectionStatus() {
13186
+ try {
13187
+ return SafeLocalStorage.getItem(SafeLocalStorageKeys.CONNECTION_STATUS);
13188
+ } catch {
13189
+ return void 0;
13190
+ }
13191
+ }
13192
+ };
13193
+ const state$a = proxy({
13194
+ walletImages: {},
13195
+ networkImages: {},
13196
+ chainImages: {},
13197
+ connectorImages: {},
13198
+ tokenImages: {},
13199
+ currencyImages: {}
13200
+ });
13201
+ const AssetController = {
13202
+ state: state$a,
13203
+ subscribeNetworkImages(callback) {
13204
+ return subscribe(state$a.networkImages, () => callback(state$a.networkImages));
13205
+ },
13206
+ subscribeKey(key2, callback) {
13207
+ return subscribeKey(state$a, key2, callback);
13208
+ },
13209
+ subscribe(callback) {
13210
+ return subscribe(state$a, () => callback(state$a));
13211
+ },
13212
+ setWalletImage(key2, value) {
13213
+ state$a.walletImages[key2] = value;
13214
+ },
13215
+ setNetworkImage(key2, value) {
13216
+ state$a.networkImages[key2] = value;
13217
+ },
13218
+ setChainImage(key2, value) {
13219
+ state$a.chainImages[key2] = value;
13220
+ },
13221
+ setConnectorImage(key2, value) {
13222
+ state$a.connectorImages[key2] = value;
13223
+ },
13224
+ setTokenImage(key2, value) {
13225
+ state$a.tokenImages[key2] = value;
13226
+ },
13227
+ setCurrencyImage(key2, value) {
13228
+ state$a.currencyImages[key2] = value;
13229
+ }
13230
+ };
13231
+ const baseUrl = CoreHelperUtil.getApiUrl();
13232
+ const api$1 = new FetchUtil({ baseUrl, clientId: null });
13233
+ const entries = "40";
13234
+ const recommendedEntries = "4";
13235
+ const imageCountToFetch = 20;
13236
+ const state$9 = proxy({
13237
+ page: 1,
13238
+ count: 0,
13239
+ featured: [],
13240
+ recommended: [],
13241
+ wallets: [],
13242
+ search: [],
13243
+ isAnalyticsEnabled: false,
13244
+ excludedRDNS: []
13245
+ });
13246
+ const ApiController = {
13247
+ state: state$9,
13248
+ subscribeKey(key2, callback) {
13249
+ return subscribeKey(state$9, key2, callback);
13250
+ },
13251
+ _getSdkProperties() {
13252
+ const { projectId, sdkType, sdkVersion } = OptionsController.state;
13253
+ return {
13254
+ projectId,
13255
+ st: sdkType || "appkit",
13256
+ sv: sdkVersion || "html-wagmi-4.2.2"
13257
+ };
13258
+ },
13259
+ _filterOutExtensions(wallets2) {
13260
+ if (OptionsController.state.isUniversalProvider) {
13261
+ return wallets2.filter((w2) => Boolean(w2.mobile_link || w2.desktop_link || w2.webapp_link));
13262
+ }
13263
+ return wallets2;
13264
+ },
13265
+ async _fetchWalletImage(imageId) {
13266
+ const imageUrl = `${api$1.baseUrl}/getWalletImage/${imageId}`;
13267
+ const blob2 = await api$1.getBlob({ path: imageUrl, params: ApiController._getSdkProperties() });
13268
+ AssetController.setWalletImage(imageId, URL.createObjectURL(blob2));
13269
+ },
13270
+ async _fetchNetworkImage(imageId) {
13271
+ const imageUrl = `${api$1.baseUrl}/public/getAssetImage/${imageId}`;
13272
+ const blob2 = await api$1.getBlob({ path: imageUrl, params: ApiController._getSdkProperties() });
13273
+ AssetController.setNetworkImage(imageId, URL.createObjectURL(blob2));
13274
+ },
13275
+ async _fetchConnectorImage(imageId) {
13276
+ const imageUrl = `${api$1.baseUrl}/public/getAssetImage/${imageId}`;
13277
+ const blob2 = await api$1.getBlob({ path: imageUrl, params: ApiController._getSdkProperties() });
13278
+ AssetController.setConnectorImage(imageId, URL.createObjectURL(blob2));
13279
+ },
13280
+ async _fetchCurrencyImage(countryCode) {
13281
+ const imageUrl = `${api$1.baseUrl}/public/getCurrencyImage/${countryCode}`;
13282
+ const blob2 = await api$1.getBlob({ path: imageUrl, params: ApiController._getSdkProperties() });
13283
+ AssetController.setCurrencyImage(countryCode, URL.createObjectURL(blob2));
13284
+ },
13285
+ async _fetchTokenImage(symbol) {
13286
+ const imageUrl = `${api$1.baseUrl}/public/getTokenImage/${symbol}`;
13287
+ const blob2 = await api$1.getBlob({ path: imageUrl, params: ApiController._getSdkProperties() });
13288
+ AssetController.setTokenImage(symbol, URL.createObjectURL(blob2));
13289
+ },
13290
+ async fetchNetworkImages() {
13291
+ const requestedCaipNetworks = ChainController.getAllRequestedCaipNetworks();
13292
+ const ids = requestedCaipNetworks == null ? void 0 : requestedCaipNetworks.map(({ assets }) => assets == null ? void 0 : assets.imageId).filter(Boolean);
13293
+ if (ids) {
13294
+ await Promise.allSettled(ids.map((id) => ApiController._fetchNetworkImage(id)));
13295
+ }
13296
+ },
13297
+ async fetchConnectorImages() {
13298
+ const { connectors } = ConnectorController.state;
13299
+ const ids = connectors.map(({ imageId }) => imageId).filter(Boolean);
13300
+ await Promise.allSettled(ids.map((id) => ApiController._fetchConnectorImage(id)));
13301
+ },
13302
+ async fetchCurrencyImages(currencies = []) {
13303
+ await Promise.allSettled(currencies.map((currency) => ApiController._fetchCurrencyImage(currency)));
13304
+ },
13305
+ async fetchTokenImages(tokens = []) {
13306
+ await Promise.allSettled(tokens.map((token2) => ApiController._fetchTokenImage(token2)));
13307
+ },
13308
+ async fetchFeaturedWallets() {
13309
+ const { featuredWalletIds } = OptionsController.state;
13310
+ if (featuredWalletIds == null ? void 0 : featuredWalletIds.length) {
13311
+ const { data: data2 } = await api$1.get({
13312
+ path: "/getWallets",
13313
+ params: {
13314
+ ...ApiController._getSdkProperties(),
13315
+ page: "1",
13316
+ entries: (featuredWalletIds == null ? void 0 : featuredWalletIds.length) ? String(featuredWalletIds.length) : recommendedEntries,
13317
+ include: featuredWalletIds == null ? void 0 : featuredWalletIds.join(",")
13318
+ }
13319
+ });
13320
+ data2.sort((a3, b4) => featuredWalletIds.indexOf(a3.id) - featuredWalletIds.indexOf(b4.id));
13321
+ const images = data2.map((d4) => d4.image_id).filter(Boolean);
13322
+ await Promise.allSettled(images.map((id) => ApiController._fetchWalletImage(id)));
13323
+ state$9.featured = data2;
13324
+ }
13325
+ },
13326
+ async fetchRecommendedWallets() {
13327
+ var _a3;
13328
+ try {
13329
+ const { includeWalletIds, excludeWalletIds, featuredWalletIds } = OptionsController.state;
13330
+ const exclude = [...excludeWalletIds ?? [], ...featuredWalletIds ?? []].filter(Boolean);
13331
+ const { data: data2, count } = await api$1.get({
13332
+ path: "/getWallets",
13333
+ params: {
13334
+ ...ApiController._getSdkProperties(),
13335
+ page: "1",
13336
+ chains: (_a3 = ChainController.state.activeCaipNetwork) == null ? void 0 : _a3.caipNetworkId,
13337
+ entries: recommendedEntries,
13338
+ include: includeWalletIds == null ? void 0 : includeWalletIds.join(","),
13339
+ exclude: exclude == null ? void 0 : exclude.join(",")
13340
+ }
13341
+ });
13342
+ const recent = StorageUtil.getRecentWallets();
13343
+ const recommendedImages = data2.map((d4) => d4.image_id).filter(Boolean);
13344
+ const recentImages = recent.map((r4) => r4.image_id).filter(Boolean);
13345
+ await Promise.allSettled([...recommendedImages, ...recentImages].map((id) => ApiController._fetchWalletImage(id)));
13346
+ state$9.recommended = data2;
13347
+ state$9.count = count ?? 0;
13348
+ } catch {
13349
+ }
13350
+ },
13351
+ async fetchWallets({ page }) {
13352
+ var _a3;
13353
+ const { includeWalletIds, excludeWalletIds, featuredWalletIds } = OptionsController.state;
13354
+ const exclude = [
13355
+ ...state$9.recommended.map(({ id }) => id),
13356
+ ...excludeWalletIds ?? [],
13357
+ ...featuredWalletIds ?? []
13358
+ ].filter(Boolean);
13359
+ const { data: data2, count } = await api$1.get({
13360
+ path: "/getWallets",
13361
+ params: {
13362
+ ...ApiController._getSdkProperties(),
13363
+ page: String(page),
13364
+ entries,
13365
+ chains: (_a3 = ChainController.state.activeCaipNetwork) == null ? void 0 : _a3.caipNetworkId,
13366
+ include: includeWalletIds == null ? void 0 : includeWalletIds.join(","),
13367
+ exclude: exclude.join(",")
13368
+ }
13369
+ });
13370
+ const images = data2.slice(0, imageCountToFetch).map((w2) => w2.image_id).filter(Boolean);
13371
+ await Promise.allSettled(images.map((id) => ApiController._fetchWalletImage(id)));
13372
+ state$9.wallets = CoreHelperUtil.uniqueBy([...state$9.wallets, ...ApiController._filterOutExtensions(data2)], "id");
13373
+ state$9.count = count > state$9.count ? count : state$9.count;
13374
+ state$9.page = page;
13375
+ },
13376
+ async searchWalletByIds({ ids }) {
13377
+ var _a3;
13378
+ const { data: data2 } = await api$1.get({
13379
+ path: "/getWallets",
13380
+ params: {
13381
+ ...ApiController._getSdkProperties(),
13382
+ page: "1",
13383
+ entries: String(ids.length),
13384
+ chains: (_a3 = ChainController.state.activeCaipNetwork) == null ? void 0 : _a3.caipNetworkId,
13385
+ include: ids == null ? void 0 : ids.join(",")
13386
+ }
13387
+ });
13388
+ if (data2) {
13389
+ data2.forEach((wallet) => {
13390
+ if (wallet == null ? void 0 : wallet.rdns) {
13391
+ state$9.excludedRDNS.push(wallet.rdns);
13392
+ }
13393
+ });
13394
+ }
13395
+ },
13396
+ async searchWallet({ search, badge }) {
13397
+ var _a3;
13398
+ const { includeWalletIds, excludeWalletIds } = OptionsController.state;
13399
+ state$9.search = [];
13400
+ const { data: data2 } = await api$1.get({
13401
+ path: "/getWallets",
13402
+ params: {
13403
+ ...ApiController._getSdkProperties(),
13404
+ page: "1",
13405
+ entries: "100",
13406
+ search: search == null ? void 0 : search.trim(),
13407
+ badge_type: badge,
13408
+ chains: (_a3 = ChainController.state.activeCaipNetwork) == null ? void 0 : _a3.caipNetworkId,
13409
+ include: includeWalletIds == null ? void 0 : includeWalletIds.join(","),
13410
+ exclude: excludeWalletIds == null ? void 0 : excludeWalletIds.join(",")
13411
+ }
13412
+ });
13413
+ EventsController.sendEvent({
13414
+ type: "track",
13415
+ event: "SEARCH_WALLET",
13416
+ properties: { badge: badge ?? "", search: search ?? "" }
13417
+ });
13418
+ const images = data2.map((w2) => w2.image_id).filter(Boolean);
13419
+ await Promise.allSettled([
13420
+ ...images.map((id) => ApiController._fetchWalletImage(id)),
13421
+ CoreHelperUtil.wait(300)
13422
+ ]);
13423
+ state$9.search = ApiController._filterOutExtensions(data2);
13424
+ },
13425
+ async reFetchWallets() {
13426
+ state$9.page = 1;
13427
+ state$9.wallets = [];
13428
+ await ApiController.fetchFeaturedWallets();
13429
+ await ApiController.fetchRecommendedWallets();
13430
+ },
13431
+ prefetch() {
13432
+ var _a3;
13433
+ const promises = [
13434
+ ApiController.fetchFeaturedWallets(),
13435
+ ApiController.fetchRecommendedWallets(),
13436
+ ApiController.fetchNetworkImages(),
13437
+ ApiController.fetchConnectorImages()
13438
+ ];
13439
+ if ((_a3 = OptionsController.state.features) == null ? void 0 : _a3.analytics) {
13440
+ promises.push(ApiController.fetchAnalyticsConfig());
13441
+ }
13442
+ state$9.prefetchPromise = Promise.race([Promise.allSettled(promises)]);
13443
+ },
13444
+ async fetchAnalyticsConfig() {
13445
+ const { isAnalyticsEnabled } = await api$1.get({
13446
+ path: "/getAnalyticsConfig",
13447
+ params: ApiController._getSdkProperties()
13448
+ });
13449
+ OptionsController.setFeatures({ analytics: isAnalyticsEnabled });
13450
+ }
13451
+ };
13452
+ const state$8 = proxy({
13453
+ loading: false,
13454
+ open: false,
13455
+ shake: false
13456
+ });
13457
+ const ModalController = {
13458
+ state: state$8,
13459
+ subscribe(callback) {
13460
+ return subscribe(state$8, () => callback(state$8));
13461
+ },
13462
+ subscribeKey(key2, callback) {
13463
+ return subscribeKey(state$8, key2, callback);
13464
+ },
13465
+ async open(options) {
13466
+ await ApiController.state.prefetchPromise;
13467
+ const caipAddress = ChainController.state.activeCaipAddress;
13468
+ const noAdapters = ChainController.state.noAdapters;
13469
+ if (options == null ? void 0 : options.view) {
13470
+ RouterController.reset(options.view);
13471
+ } else if (caipAddress) {
13472
+ RouterController.reset("Account");
13473
+ } else if (noAdapters && !CoreHelperUtil.isMobile()) {
13474
+ RouterController.reset("ConnectingWalletConnect");
13475
+ } else {
13476
+ RouterController.reset("Connect");
13477
+ }
13478
+ state$8.open = true;
13479
+ PublicStateController.set({ open: true });
13480
+ EventsController.sendEvent({
13481
+ type: "track",
13482
+ event: "MODAL_OPEN",
13483
+ properties: { connected: Boolean(caipAddress) }
13484
+ });
13485
+ },
13486
+ close() {
13487
+ const connected = Boolean(ChainController.state.activeCaipAddress);
13488
+ state$8.open = false;
13489
+ PublicStateController.set({ open: false });
13490
+ EventsController.sendEvent({
13491
+ type: "track",
13492
+ event: "MODAL_CLOSE",
13493
+ properties: { connected }
13494
+ });
13495
+ },
13496
+ setLoading(loading) {
13497
+ state$8.loading = loading;
13498
+ PublicStateController.set({ loading });
13499
+ },
13500
+ shake() {
13501
+ if (state$8.shake) {
13502
+ return;
13503
+ }
13504
+ state$8.shake = true;
13505
+ setTimeout(() => {
13506
+ state$8.shake = false;
13507
+ }, 500);
13508
+ }
13509
+ };
13510
+ const USDC_CURRENCY_DEFAULT = {
13511
+ id: "2b92315d-eab7-5bef-84fa-089a131333f5",
13512
+ name: "USD Coin",
13513
+ symbol: "USDC",
13514
+ networks: [
13515
+ {
13516
+ name: "ethereum-mainnet",
13517
+ display_name: "Ethereum",
13518
+ chain_id: "1",
13519
+ contract_address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
13520
+ },
13521
+ {
13522
+ name: "polygon-mainnet",
13523
+ display_name: "Polygon",
13524
+ chain_id: "137",
13525
+ contract_address: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"
13526
+ }
13527
+ ]
13528
+ };
13529
+ const USD_CURRENCY_DEFAULT = {
13530
+ id: "USD",
13531
+ payment_method_limits: [
13532
+ {
13533
+ id: "card",
13534
+ min: "10.00",
13535
+ max: "7500.00"
13536
+ },
13537
+ {
13538
+ id: "ach_bank_account",
13539
+ min: "10.00",
13540
+ max: "25000.00"
13541
+ }
13542
+ ]
13543
+ };
13544
+ const defaultState = {
13545
+ providers: ONRAMP_PROVIDERS,
13546
+ selectedProvider: null,
13547
+ error: null,
13548
+ purchaseCurrency: USDC_CURRENCY_DEFAULT,
13549
+ paymentCurrency: USD_CURRENCY_DEFAULT,
13550
+ purchaseCurrencies: [USDC_CURRENCY_DEFAULT],
13551
+ paymentCurrencies: [],
13552
+ quotesLoading: false
13553
+ };
13554
+ const state$7 = proxy(defaultState);
13555
+ const OnRampController = {
13556
+ state: state$7,
13557
+ subscribe(callback) {
13558
+ return subscribe(state$7, () => callback(state$7));
13559
+ },
13560
+ subscribeKey(key2, callback) {
13561
+ return subscribeKey(state$7, key2, callback);
13562
+ },
13563
+ setSelectedProvider(provider) {
13564
+ if (provider && provider.name === "meld") {
13565
+ const pubKey = process$1.env["NODE_ENV"] === "production" ? MELD_PROD_PUBLIC_KEY : MELD_DEV_PUBLIC_KEY;
13566
+ const currency = ChainController.state.activeChain === ConstantsUtil$3.CHAIN.SOLANA ? "SOL" : "USDC";
13567
+ const address = AccountController.state.address ?? "";
13568
+ const url = new URL(provider.url);
13569
+ url.searchParams.append("publicKey", pubKey);
13570
+ url.searchParams.append("destinationCurrencyCode", currency);
13571
+ url.searchParams.append("walletAddress", address);
13572
+ provider.url = url.toString();
13573
+ }
13574
+ state$7.selectedProvider = provider;
13575
+ },
13576
+ setPurchaseCurrency(currency) {
13577
+ state$7.purchaseCurrency = currency;
13578
+ },
13579
+ setPaymentCurrency(currency) {
13580
+ state$7.paymentCurrency = currency;
13581
+ },
13582
+ setPurchaseAmount(amount) {
13583
+ this.state.purchaseAmount = amount;
13584
+ },
13585
+ setPaymentAmount(amount) {
13586
+ this.state.paymentAmount = amount;
13587
+ },
13588
+ async getAvailableCurrencies() {
13589
+ const options = await BlockchainApiController.getOnrampOptions();
13590
+ state$7.purchaseCurrencies = options.purchaseCurrencies;
13591
+ state$7.paymentCurrencies = options.paymentCurrencies;
13592
+ state$7.paymentCurrency = options.paymentCurrencies[0] || USD_CURRENCY_DEFAULT;
13593
+ state$7.purchaseCurrency = options.purchaseCurrencies[0] || USDC_CURRENCY_DEFAULT;
13594
+ await ApiController.fetchCurrencyImages(options.paymentCurrencies.map((currency) => currency.id));
13595
+ await ApiController.fetchTokenImages(options.purchaseCurrencies.map((currency) => currency.symbol));
13596
+ },
13597
+ async getQuote() {
13598
+ var _a3, _b2;
13599
+ state$7.quotesLoading = true;
13600
+ try {
13601
+ const quote = await BlockchainApiController.getOnrampQuote({
13602
+ purchaseCurrency: state$7.purchaseCurrency,
13603
+ paymentCurrency: state$7.paymentCurrency,
13604
+ amount: ((_a3 = state$7.paymentAmount) == null ? void 0 : _a3.toString()) || "0",
13605
+ network: (_b2 = state$7.purchaseCurrency) == null ? void 0 : _b2.symbol
13606
+ });
13607
+ state$7.quotesLoading = false;
13608
+ state$7.purchaseAmount = Number(quote.purchaseAmount.amount);
13609
+ return quote;
13610
+ } catch (error) {
13611
+ state$7.error = error.message;
13612
+ state$7.quotesLoading = false;
13613
+ return null;
13614
+ } finally {
13615
+ state$7.quotesLoading = false;
13616
+ }
13617
+ },
13618
+ resetState() {
13619
+ state$7.providers = ONRAMP_PROVIDERS;
13620
+ state$7.selectedProvider = null;
13621
+ state$7.error = null;
13622
+ state$7.purchaseCurrency = USDC_CURRENCY_DEFAULT;
13623
+ state$7.paymentCurrency = USD_CURRENCY_DEFAULT;
13624
+ state$7.purchaseCurrencies = [USDC_CURRENCY_DEFAULT];
13625
+ state$7.paymentCurrencies = [];
13626
+ state$7.paymentAmount = void 0;
13627
+ state$7.purchaseAmount = void 0;
13628
+ state$7.quotesLoading = false;
13629
+ }
13630
+ };
13631
+ const state$6 = proxy({
13632
+ loading: false
13633
+ });
13634
+ const SendController = {
13635
+ state: state$6,
13636
+ subscribe(callback) {
13637
+ return subscribe(state$6, () => callback(state$6));
13638
+ },
13639
+ subscribeKey(key2, callback) {
13640
+ return subscribeKey(state$6, key2, callback);
13641
+ },
13642
+ setToken(token2) {
13643
+ if (token2) {
13644
+ state$6.token = ref$1(token2);
13645
+ }
13646
+ },
13647
+ setTokenAmount(sendTokenAmount) {
13648
+ state$6.sendTokenAmount = sendTokenAmount;
13649
+ },
13650
+ setReceiverAddress(receiverAddress) {
13651
+ state$6.receiverAddress = receiverAddress;
13652
+ },
13653
+ setReceiverProfileImageUrl(receiverProfileImageUrl) {
13654
+ state$6.receiverProfileImageUrl = receiverProfileImageUrl;
13655
+ },
13656
+ setReceiverProfileName(receiverProfileName) {
13657
+ state$6.receiverProfileName = receiverProfileName;
13658
+ },
13659
+ setGasPrice(gasPrice) {
13660
+ state$6.gasPrice = gasPrice;
13661
+ },
13662
+ setGasPriceInUsd(gasPriceInUSD) {
13663
+ state$6.gasPriceInUSD = gasPriceInUSD;
13664
+ },
13665
+ setLoading(loading) {
13666
+ state$6.loading = loading;
13667
+ },
13668
+ sendToken() {
13669
+ var _a3;
13670
+ switch ((_a3 = ChainController.state.activeCaipNetwork) == null ? void 0 : _a3.chainNamespace) {
13671
+ case "eip155":
13672
+ this.sendEvmToken();
13673
+ return;
13674
+ case "solana":
13675
+ this.sendSolanaToken();
13676
+ return;
13677
+ default:
13678
+ throw new Error("Unsupported chain");
13679
+ }
13680
+ },
13681
+ sendEvmToken() {
13682
+ var _a3, _b2, _c, _d, _e2;
13683
+ if (((_a3 = this.state.token) == null ? void 0 : _a3.address) && this.state.sendTokenAmount && this.state.receiverAddress) {
13684
+ EventsController.sendEvent({
13685
+ type: "track",
13686
+ event: "SEND_INITIATED",
13687
+ properties: {
13688
+ isSmartAccount: AccountController.state.preferredAccountType === W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
13689
+ token: this.state.token.address,
13690
+ amount: this.state.sendTokenAmount,
13691
+ network: ((_b2 = ChainController.state.activeCaipNetwork) == null ? void 0 : _b2.caipNetworkId) || ""
13692
+ }
13693
+ });
13694
+ this.sendERC20Token({
13695
+ receiverAddress: this.state.receiverAddress,
13696
+ tokenAddress: this.state.token.address,
13697
+ sendTokenAmount: this.state.sendTokenAmount,
13698
+ decimals: this.state.token.quantity.decimals
13699
+ });
13700
+ } else if (this.state.receiverAddress && this.state.sendTokenAmount && this.state.gasPrice && ((_c = this.state.token) == null ? void 0 : _c.quantity.decimals)) {
13701
+ EventsController.sendEvent({
13702
+ type: "track",
13703
+ event: "SEND_INITIATED",
13704
+ properties: {
13705
+ isSmartAccount: AccountController.state.preferredAccountType === W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
13706
+ token: (_d = this.state.token) == null ? void 0 : _d.symbol,
13707
+ amount: this.state.sendTokenAmount,
13708
+ network: ((_e2 = ChainController.state.activeCaipNetwork) == null ? void 0 : _e2.caipNetworkId) || ""
13709
+ }
13710
+ });
13711
+ this.sendNativeToken({
13712
+ receiverAddress: this.state.receiverAddress,
13713
+ sendTokenAmount: this.state.sendTokenAmount,
13714
+ gasPrice: this.state.gasPrice,
13715
+ decimals: this.state.token.quantity.decimals
13716
+ });
13717
+ }
13718
+ },
13719
+ async sendNativeToken(params) {
13720
+ var _a3, _b2, _c, _d;
13721
+ RouterController.pushTransactionStack({
13722
+ view: "Account",
13723
+ goBack: false
13724
+ });
13725
+ const to2 = params.receiverAddress;
13726
+ const address = AccountController.state.address;
13727
+ const value = ConnectionController.parseUnits(params.sendTokenAmount.toString(), Number(params.decimals));
13728
+ const data2 = "0x";
13729
+ try {
13730
+ await ConnectionController.sendTransaction({
13731
+ chainNamespace: "eip155",
13732
+ to: to2,
13733
+ address,
13734
+ data: data2,
13735
+ value: value ?? BigInt(0),
13736
+ gasPrice: params.gasPrice
13737
+ });
13738
+ SnackController.showSuccess("Transaction started");
13739
+ EventsController.sendEvent({
13740
+ type: "track",
13741
+ event: "SEND_SUCCESS",
13742
+ properties: {
13743
+ isSmartAccount: AccountController.state.preferredAccountType === W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
13744
+ token: ((_a3 = this.state.token) == null ? void 0 : _a3.symbol) || "",
13745
+ amount: params.sendTokenAmount,
13746
+ network: ((_b2 = ChainController.state.activeCaipNetwork) == null ? void 0 : _b2.caipNetworkId) || ""
13747
+ }
13748
+ });
13749
+ this.resetSend();
13750
+ } catch (error) {
13751
+ EventsController.sendEvent({
13752
+ type: "track",
13753
+ event: "SEND_ERROR",
13754
+ properties: {
13755
+ isSmartAccount: AccountController.state.preferredAccountType === W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
13756
+ token: ((_c = this.state.token) == null ? void 0 : _c.symbol) || "",
13757
+ amount: params.sendTokenAmount,
13758
+ network: ((_d = ChainController.state.activeCaipNetwork) == null ? void 0 : _d.caipNetworkId) || ""
13759
+ }
13760
+ });
13761
+ SnackController.showError("Something went wrong");
13762
+ }
13763
+ },
13764
+ async sendERC20Token(params) {
13765
+ RouterController.pushTransactionStack({
13766
+ view: "Account",
13767
+ goBack: false
13768
+ });
13769
+ const amount = ConnectionController.parseUnits(params.sendTokenAmount.toString(), Number(params.decimals));
13770
+ try {
13771
+ if (AccountController.state.address && params.sendTokenAmount && params.receiverAddress && params.tokenAddress) {
13772
+ const tokenAddress = CoreHelperUtil.getPlainAddress(params.tokenAddress);
13773
+ await ConnectionController.writeContract({
13774
+ fromAddress: AccountController.state.address,
13775
+ tokenAddress,
13776
+ receiverAddress: params.receiverAddress,
13777
+ tokenAmount: amount ?? BigInt(0),
13778
+ method: "transfer",
13779
+ abi: ContractUtil.getERC20Abi(tokenAddress)
13780
+ });
13781
+ SnackController.showSuccess("Transaction started");
13782
+ this.resetSend();
13783
+ }
13784
+ } catch (error) {
13785
+ SnackController.showError("Something went wrong");
13786
+ }
13787
+ },
13788
+ sendSolanaToken() {
13789
+ if (!this.state.sendTokenAmount || !this.state.receiverAddress) {
13790
+ SnackController.showError("Please enter a valid amount and receiver address");
13791
+ return;
13792
+ }
13793
+ RouterController.pushTransactionStack({
13794
+ view: "Account",
13795
+ goBack: false
13796
+ });
13797
+ ConnectionController.sendTransaction({
13798
+ chainNamespace: "solana",
13799
+ to: this.state.receiverAddress,
13800
+ value: this.state.sendTokenAmount
13801
+ }).then(() => {
13802
+ this.resetSend();
13803
+ AccountController.fetchTokenBalance();
13804
+ }).catch((error) => {
13805
+ SnackController.showError("Failed to send transaction. Please try again.");
13806
+ console.error("SendController:sendToken - failed to send solana transaction", error);
13807
+ });
13808
+ },
13809
+ resetSend() {
13810
+ state$6.token = void 0;
13811
+ state$6.sendTokenAmount = void 0;
13812
+ state$6.receiverAddress = void 0;
13813
+ state$6.receiverProfileImageUrl = void 0;
13814
+ state$6.receiverProfileName = void 0;
13815
+ state$6.loading = false;
13816
+ }
13817
+ };
13818
+ const state$5 = proxy({
13819
+ message: "",
13820
+ open: false,
13821
+ triggerRect: {
13822
+ width: 0,
13823
+ height: 0,
13824
+ top: 0,
13825
+ left: 0
13826
+ },
13827
+ variant: "shade"
13828
+ });
13829
+ const TooltipController = {
13830
+ state: state$5,
13831
+ subscribe(callback) {
13832
+ return subscribe(state$5, () => callback(state$5));
13833
+ },
13834
+ subscribeKey(key2, callback) {
13835
+ return subscribeKey(state$5, key2, callback);
13836
+ },
13837
+ showTooltip({ message, triggerRect, variant }) {
13838
+ state$5.open = true;
13839
+ state$5.message = message;
13840
+ state$5.triggerRect = triggerRect;
13841
+ state$5.variant = variant;
13842
+ },
13843
+ hide() {
13844
+ state$5.open = false;
13845
+ state$5.message = "";
13846
+ state$5.triggerRect = {
13847
+ width: 0,
13848
+ height: 0,
13849
+ top: 0,
13850
+ left: 0
13851
+ };
13852
+ }
13853
+ };
13854
+ const SLIP44_MSB = 2147483648;
13855
+ const EnsUtil = {
13856
+ convertEVMChainIdToCoinType(chainId) {
13857
+ if (chainId >= SLIP44_MSB) {
13858
+ throw new Error("Invalid chainId");
13859
+ }
13860
+ return (SLIP44_MSB | chainId) >>> 0;
13861
+ }
13862
+ };
13863
+ const state$4 = proxy({
13864
+ suggestions: [],
13865
+ loading: false
13866
+ });
13867
+ const EnsController = {
13868
+ state: state$4,
13869
+ subscribe(callback) {
13870
+ return subscribe(state$4, () => callback(state$4));
13871
+ },
13872
+ subscribeKey(key2, callback) {
13873
+ return subscribeKey(state$4, key2, callback);
13874
+ },
13875
+ async resolveName(name2) {
13876
+ var _a3, _b2;
13877
+ try {
13878
+ return await BlockchainApiController.lookupEnsName(name2);
13879
+ } catch (e3) {
13880
+ const error = e3;
13881
+ throw new Error(((_b2 = (_a3 = error == null ? void 0 : error.reasons) == null ? void 0 : _a3[0]) == null ? void 0 : _b2.description) || "Error resolving name");
13882
+ }
13883
+ },
13884
+ async isNameRegistered(name2) {
13885
+ try {
13886
+ await BlockchainApiController.lookupEnsName(name2);
13887
+ return true;
13888
+ } catch {
13889
+ return false;
13890
+ }
13891
+ },
13892
+ async getSuggestions(value) {
13893
+ try {
13894
+ state$4.loading = true;
13895
+ state$4.suggestions = [];
13896
+ const response = await BlockchainApiController.getEnsNameSuggestions(value);
13897
+ state$4.suggestions = response.suggestions.map((suggestion) => ({
13898
+ ...suggestion,
13899
+ name: suggestion.name
13900
+ })) || [];
13901
+ return state$4.suggestions;
13902
+ } catch (e3) {
13903
+ const errorMessage = this.parseEnsApiError(e3, "Error fetching name suggestions");
13904
+ throw new Error(errorMessage);
13905
+ } finally {
13906
+ state$4.loading = false;
13907
+ }
13908
+ },
13909
+ async getNamesForAddress(address) {
13910
+ try {
13911
+ const network = ChainController.state.activeCaipNetwork;
13912
+ if (!network) {
13913
+ return [];
13914
+ }
13915
+ const response = await BlockchainApiController.reverseLookupEnsName({ address });
13916
+ return response;
13917
+ } catch (e3) {
13918
+ const errorMessage = this.parseEnsApiError(e3, "Error fetching names for address");
13919
+ throw new Error(errorMessage);
13920
+ }
13921
+ },
13922
+ async registerName(name2) {
13923
+ const network = ChainController.state.activeCaipNetwork;
13924
+ if (!network) {
13925
+ throw new Error("Network not found");
13926
+ }
13927
+ const address = AccountController.state.address;
13928
+ const emailConnector = ConnectorController.getAuthConnector();
13929
+ if (!address || !emailConnector) {
13930
+ throw new Error("Address or auth connector not found");
13931
+ }
13932
+ state$4.loading = true;
13933
+ try {
13934
+ const message = JSON.stringify({
13935
+ name: name2,
13936
+ attributes: {},
13937
+ // Unix timestamp
13938
+ timestamp: Math.floor(Date.now() / 1e3)
13939
+ });
13940
+ RouterController.pushTransactionStack({
13941
+ view: "RegisterAccountNameSuccess",
13942
+ goBack: false,
13943
+ replace: true,
13944
+ onCancel() {
13945
+ state$4.loading = false;
13946
+ }
13947
+ });
13948
+ const signature2 = await ConnectionController.signMessage(message);
13949
+ const networkId = network.id;
13950
+ if (!networkId) {
13951
+ throw new Error("Network not found");
13952
+ }
13953
+ const coinType = EnsUtil.convertEVMChainIdToCoinType(Number(networkId));
13954
+ await BlockchainApiController.registerEnsName({
13955
+ coinType,
13956
+ address,
13957
+ signature: signature2,
13958
+ message
13959
+ });
13960
+ AccountController.setProfileName(name2, network.chainNamespace);
13961
+ RouterController.replace("RegisterAccountNameSuccess");
13962
+ } catch (e3) {
13963
+ const errorMessage = this.parseEnsApiError(e3, `Error registering name ${name2}`);
13964
+ RouterController.replace("RegisterAccountName");
13965
+ throw new Error(errorMessage);
13966
+ } finally {
13967
+ state$4.loading = false;
13968
+ }
13969
+ },
13970
+ validateName(name2) {
13971
+ return /^[a-zA-Z0-9-]{4,}$/u.test(name2);
13972
+ },
13973
+ parseEnsApiError(error, defaultError) {
13974
+ var _a3, _b2;
13975
+ const ensError = error;
13976
+ return ((_b2 = (_a3 = ensError == null ? void 0 : ensError.reasons) == null ? void 0 : _a3[0]) == null ? void 0 : _b2.description) || defaultError;
13977
+ }
13978
+ };
13979
+ const state$3 = proxy({
13980
+ message: "",
13981
+ variant: "info",
13982
+ open: false
13983
+ });
13984
+ const AlertController = {
13985
+ state: state$3,
13986
+ subscribeKey(key2, callback) {
13987
+ return subscribeKey(state$3, key2, callback);
13988
+ },
13989
+ open(message, variant) {
13990
+ const { debug } = OptionsController.state;
13991
+ const { shortMessage, longMessage } = message;
13992
+ if (debug) {
13993
+ state$3.message = shortMessage;
13994
+ state$3.variant = variant;
13995
+ state$3.open = true;
13996
+ }
13997
+ if (longMessage) {
13998
+ console.error(typeof longMessage === "function" ? longMessage() : longMessage);
13999
+ }
14000
+ },
14001
+ close() {
14002
+ state$3.open = false;
14003
+ state$3.message = "";
14004
+ state$3.variant = "info";
14005
+ }
14006
+ };
14007
+ const namespaceImageIds = {
14008
+ // Ethereum
14009
+ eip155: "ba0ba0cd-17c6-4806-ad93-f9d174f17900",
14010
+ // Solana
14011
+ solana: "a1b58899-f671-4276-6a5e-56ca5bd59700",
14012
+ // Polkadot
14013
+ polkadot: "",
14014
+ // Bitcoin
14015
+ bip122: ""
14016
+ };
14017
+ const AssetUtil = {
14018
+ async fetchWalletImage(imageId) {
14019
+ if (!imageId) {
14020
+ return void 0;
14021
+ }
14022
+ await ApiController._fetchWalletImage(imageId);
14023
+ return this.getWalletImageById(imageId);
14024
+ },
14025
+ getWalletImageById(imageId) {
14026
+ if (!imageId) {
14027
+ return void 0;
14028
+ }
14029
+ return AssetController.state.walletImages[imageId];
14030
+ },
14031
+ getWalletImage(wallet) {
14032
+ if (wallet == null ? void 0 : wallet.image_url) {
14033
+ return wallet == null ? void 0 : wallet.image_url;
14034
+ }
14035
+ if (wallet == null ? void 0 : wallet.image_id) {
14036
+ return AssetController.state.walletImages[wallet.image_id];
14037
+ }
14038
+ return void 0;
14039
+ },
14040
+ getNetworkImage(network) {
14041
+ var _a3, _b2, _c;
14042
+ if ((_a3 = network == null ? void 0 : network.assets) == null ? void 0 : _a3.imageUrl) {
14043
+ return (_b2 = network == null ? void 0 : network.assets) == null ? void 0 : _b2.imageUrl;
14044
+ }
14045
+ if ((_c = network == null ? void 0 : network.assets) == null ? void 0 : _c.imageId) {
14046
+ return AssetController.state.networkImages[network.assets.imageId];
14047
+ }
14048
+ return void 0;
14049
+ },
14050
+ getNetworkImageById(imageId) {
14051
+ if (!imageId) {
14052
+ return void 0;
14053
+ }
14054
+ return AssetController.state.networkImages[imageId];
14055
+ },
14056
+ getConnectorImage(connector) {
14057
+ if (connector == null ? void 0 : connector.imageUrl) {
14058
+ return connector.imageUrl;
14059
+ }
14060
+ if (connector == null ? void 0 : connector.imageId) {
14061
+ return AssetController.state.connectorImages[connector.imageId];
14062
+ }
14063
+ return void 0;
14064
+ },
14065
+ getChainImage(chain) {
14066
+ return AssetController.state.networkImages[namespaceImageIds[chain]];
14067
+ }
14068
+ };
12727
14069
  const global$1 = globalThis || void 0 || self;
12728
14070
  var events = { exports: {} };
12729
14071
  var R$2 = typeof Reflect === "object" ? Reflect : null;
@@ -16952,7 +18294,7 @@ function getHighWaterMark(state2, options, duplexKey, isDuplex) {
16952
18294
  }
16953
18295
  return state2.objectMode ? 16 : 16 * 1024;
16954
18296
  }
16955
- var state$b = {
18297
+ var state$2 = {
16956
18298
  getHighWaterMark
16957
18299
  };
16958
18300
  var browser$d = deprecate;
@@ -17019,7 +18361,7 @@ function require_stream_writable$1() {
17019
18361
  return Buffer2.isBuffer(obj) || obj instanceof OurUint8Array;
17020
18362
  }
17021
18363
  var destroyImpl = destroy_1$1;
17022
- var _require = state$b, getHighWaterMark2 = _require.getHighWaterMark;
18364
+ var _require = state$2, getHighWaterMark2 = _require.getHighWaterMark;
17023
18365
  var _require$codes2 = errorsBrowser.codes, ERR_INVALID_ARG_TYPE = _require$codes2.ERR_INVALID_ARG_TYPE, ERR_METHOD_NOT_IMPLEMENTED2 = _require$codes2.ERR_METHOD_NOT_IMPLEMENTED, ERR_MULTIPLE_CALLBACK2 = _require$codes2.ERR_MULTIPLE_CALLBACK, ERR_STREAM_CANNOT_PIPE = _require$codes2.ERR_STREAM_CANNOT_PIPE, ERR_STREAM_DESTROYED2 = _require$codes2.ERR_STREAM_DESTROYED, ERR_STREAM_NULL_VALUES = _require$codes2.ERR_STREAM_NULL_VALUES, ERR_STREAM_WRITE_AFTER_END = _require$codes2.ERR_STREAM_WRITE_AFTER_END, ERR_UNKNOWN_ENCODING = _require$codes2.ERR_UNKNOWN_ENCODING;
17024
18366
  var errorOrDestroy2 = destroyImpl.errorOrDestroy;
17025
18367
  inherits_browserExports(Writable, Stream2);
@@ -18162,7 +19504,7 @@ function require_stream_readable$1() {
18162
19504
  }
18163
19505
  var BufferList2 = requireBuffer_list();
18164
19506
  var destroyImpl = destroy_1$1;
18165
- var _require = state$b, getHighWaterMark2 = _require.getHighWaterMark;
19507
+ var _require = state$2, getHighWaterMark2 = _require.getHighWaterMark;
18166
19508
  var _require$codes2 = errorsBrowser.codes, ERR_INVALID_ARG_TYPE = _require$codes2.ERR_INVALID_ARG_TYPE, ERR_STREAM_PUSH_AFTER_EOF = _require$codes2.ERR_STREAM_PUSH_AFTER_EOF, ERR_METHOD_NOT_IMPLEMENTED2 = _require$codes2.ERR_METHOD_NOT_IMPLEMENTED, ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes2.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;
18167
19509
  var StringDecoder;
18168
19510
  var createReadableStreamAsyncIterator;
@@ -36677,7 +38019,7 @@ function requireElliptic() {
36677
38019
  }
36678
38020
  var asn1$1 = {};
36679
38021
  var asn1 = {};
36680
- var api$1 = {};
38022
+ var api = {};
36681
38023
  var vmBrowserify = {};
36682
38024
  var hasRequiredVmBrowserify;
36683
38025
  function requireVmBrowserify() {
@@ -36849,7 +38191,7 @@ function requireVmBrowserify() {
36849
38191
  var hasRequiredApi;
36850
38192
  function requireApi() {
36851
38193
  if (hasRequiredApi)
36852
- return api$1;
38194
+ return api;
36853
38195
  hasRequiredApi = 1;
36854
38196
  (function(exports2) {
36855
38197
  var asn12 = requireAsn1$1();
@@ -36899,8 +38241,8 @@ function requireApi() {
36899
38241
  Entity.prototype.encode = function encode5(data2, enc, reporter2) {
36900
38242
  return this._getEncoder(enc).encode(data2, reporter2);
36901
38243
  };
36902
- })(api$1);
36903
- return api$1;
38244
+ })(api);
38245
+ return api;
36904
38246
  }
36905
38247
  var base$4 = {};
36906
38248
  var reporter = {};
@@ -57862,1729 +59204,415 @@ class dr {
57862
59204
  }
57863
59205
  async connect(s2) {
57864
59206
  if (!this.client)
57865
- throw new Error("Sign Client not initialized");
57866
- if (this.setNamespaces(s2), await this.cleanupPendingPairings(), !s2.skipPairing)
57867
- return await this.pair(s2.pairingTopic);
57868
- }
57869
- async authenticate(s2, i4) {
57870
- if (!this.client)
57871
- throw new Error("Sign Client not initialized");
57872
- this.setNamespaces(s2), await this.cleanupPendingPairings();
57873
- const { uri: p3, response: w2 } = await this.client.authenticate(s2, i4);
57874
- p3 && (this.uri = p3, this.events.emit("display_uri", p3));
57875
- const I2 = await w2();
57876
- if (this.session = I2.session, this.session) {
57877
- const y3 = Ha(this.session.namespaces);
57878
- this.namespaces = Fi(this.namespaces, y3), this.persist("namespaces", this.namespaces), this.onConnect();
57879
- }
57880
- return I2;
57881
- }
57882
- on(s2, i4) {
57883
- this.events.on(s2, i4);
57884
- }
57885
- once(s2, i4) {
57886
- this.events.once(s2, i4);
57887
- }
57888
- removeListener(s2, i4) {
57889
- this.events.removeListener(s2, i4);
57890
- }
57891
- off(s2, i4) {
57892
- this.events.off(s2, i4);
57893
- }
57894
- get isWalletConnect() {
57895
- return true;
57896
- }
57897
- async pair(s2) {
57898
- this.shouldAbortPairingAttempt = false;
57899
- let i4 = 0;
57900
- do {
57901
- if (this.shouldAbortPairingAttempt)
57902
- throw new Error("Pairing aborted");
57903
- if (i4 >= this.maxPairingAttempts)
57904
- throw new Error("Max auto pairing attempts reached");
57905
- const { uri: p3, approval: w2 } = await this.client.connect({ pairingTopic: s2, requiredNamespaces: this.namespaces, optionalNamespaces: this.optionalNamespaces, sessionProperties: this.sessionProperties });
57906
- p3 && (this.uri = p3, this.events.emit("display_uri", p3)), await w2().then((I2) => {
57907
- this.session = I2;
57908
- const y3 = Ha(I2.namespaces);
57909
- this.namespaces = Fi(this.namespaces, y3), this.persist("namespaces", this.namespaces);
57910
- }).catch((I2) => {
57911
- if (I2.message !== it)
57912
- throw I2;
57913
- i4++;
57914
- });
57915
- } while (!this.session);
57916
- return this.onConnect(), this.session;
57917
- }
57918
- setDefaultChain(s2, i4) {
57919
- try {
57920
- if (!this.session)
57921
- return;
57922
- const [p3, w2] = this.validateChain(s2), I2 = this.getProvider(p3);
57923
- I2.name === ze ? I2.setDefaultChain(`${p3}:${w2}`, i4) : I2.setDefaultChain(w2, i4);
57924
- } catch (p3) {
57925
- if (!/Please call connect/.test(p3.message))
57926
- throw p3;
57927
- }
57928
- }
57929
- async cleanupPendingPairings(s2 = {}) {
57930
- this.logger.info("Cleaning up inactive pairings...");
57931
- const i4 = this.client.pairing.getAll();
57932
- if (Nr$1(i4)) {
57933
- for (const p3 of i4)
57934
- s2.deletePairings ? this.client.core.expirer.set(p3.topic, 0) : await this.client.core.relayer.subscriber.unsubscribe(p3.topic);
57935
- this.logger.info(`Inactive pairings cleared: ${i4.length}`);
57936
- }
57937
- }
57938
- abortPairingAttempt() {
57939
- this.shouldAbortPairingAttempt = true;
57940
- }
57941
- async checkStorage() {
57942
- if (this.namespaces = await this.getFromStore("namespaces"), this.optionalNamespaces = await this.getFromStore("optionalNamespaces") || {}, this.client.session.length) {
57943
- const s2 = this.client.session.keys.length - 1;
57944
- this.session = this.client.session.get(this.client.session.keys[s2]), this.createProviders();
57945
- }
57946
- }
57947
- async initialize() {
57948
- this.logger.trace("Initialized"), await this.createClient(), await this.checkStorage(), this.registerEventListeners();
57949
- }
57950
- async createClient() {
57951
- this.client = this.providerOpts.client || await _e.init({ core: this.providerOpts.core, logger: this.providerOpts.logger || ya, relayUrl: this.providerOpts.relayUrl || Yg, projectId: this.providerOpts.projectId, metadata: this.providerOpts.metadata, storageOptions: this.providerOpts.storageOptions, storage: this.providerOpts.storage, name: this.providerOpts.name, customStoragePrefix: this.providerOpts.customStoragePrefix, telemetryEnabled: this.providerOpts.telemetryEnabled }), this.logger.trace("SignClient Initialized");
57952
- }
57953
- createProviders() {
57954
- if (!this.client)
57955
- throw new Error("Sign Client not initialized");
57956
- if (!this.session)
57957
- throw new Error("Session not initialized. Please call connect() before enable()");
57958
- const s2 = [...new Set(Object.keys(this.session.namespaces).map((i4) => xo(i4)))];
57959
- Mi("client", this.client), Mi("events", this.events), Mi("disableProviderPing", this.disableProviderPing), s2.forEach((i4) => {
57960
- if (!this.session)
57961
- return;
57962
- const p3 = rv(i4, this.session), w2 = Ta(p3), I2 = Fi(this.namespaces, this.optionalNamespaces), y3 = Bi(pr({}, I2[i4]), { accounts: p3, chains: w2 });
57963
- switch (i4) {
57964
- case "eip155":
57965
- this.rpcProviders[i4] = new hv({ namespace: y3 });
57966
- break;
57967
- case "algorand":
57968
- this.rpcProviders[i4] = new dv({ namespace: y3 });
57969
- break;
57970
- case "solana":
57971
- this.rpcProviders[i4] = new lv({ namespace: y3 });
57972
- break;
57973
- case "cosmos":
57974
- this.rpcProviders[i4] = new pv({ namespace: y3 });
57975
- break;
57976
- case "polkadot":
57977
- this.rpcProviders[i4] = new sv({ namespace: y3 });
57978
- break;
57979
- case "cip34":
57980
- this.rpcProviders[i4] = new gv({ namespace: y3 });
57981
- break;
57982
- case "elrond":
57983
- this.rpcProviders[i4] = new vv({ namespace: y3 });
57984
- break;
57985
- case "multiversx":
57986
- this.rpcProviders[i4] = new _v({ namespace: y3 });
57987
- break;
57988
- case "near":
57989
- this.rpcProviders[i4] = new mv({ namespace: y3 });
57990
- break;
57991
- default:
57992
- this.rpcProviders[ze] ? this.rpcProviders[ze].updateNamespace(y3) : this.rpcProviders[ze] = new wv({ namespace: y3 });
57993
- }
57994
- });
57995
- }
57996
- registerEventListeners() {
57997
- if (typeof this.client > "u")
57998
- throw new Error("Sign Client is not initialized");
57999
- this.client.on("session_ping", (s2) => {
58000
- this.events.emit("session_ping", s2);
58001
- }), this.client.on("session_event", (s2) => {
58002
- const { params: i4 } = s2, { event: p3 } = i4;
58003
- if (p3.name === "accountsChanged") {
58004
- const w2 = p3.data;
58005
- w2 && Nr$1(w2) && this.events.emit("accountsChanged", w2.map(iv));
58006
- } else if (p3.name === "chainChanged") {
58007
- const w2 = i4.chainId, I2 = i4.event.data, y3 = xo(w2), J = Wi(w2) !== Wi(I2) ? `${y3}:${Wi(I2)}` : w2;
58008
- this.onChainChanged(J);
58009
- } else
58010
- this.events.emit(p3.name, p3.data);
58011
- this.events.emit("session_event", s2);
58012
- }), this.client.on("session_update", ({ topic: s2, params: i4 }) => {
58013
- var p3;
58014
- const { namespaces: w2 } = i4, I2 = (p3 = this.client) == null ? void 0 : p3.session.get(s2);
58015
- this.session = Bi(pr({}, I2), { namespaces: w2 }), this.onSessionUpdate(), this.events.emit("session_update", { topic: s2, params: i4 });
58016
- }), this.client.on("session_delete", async (s2) => {
58017
- await this.cleanup(), this.events.emit("session_delete", s2), this.events.emit("disconnect", Bi(pr({}, er$1("USER_DISCONNECTED")), { data: s2.topic }));
58018
- }), this.on(Tt.DEFAULT_CHAIN_CHANGED, (s2) => {
58019
- this.onChainChanged(s2, true);
58020
- });
58021
- }
58022
- getProvider(s2) {
58023
- return this.rpcProviders[s2] || this.rpcProviders[ze];
58024
- }
58025
- onSessionUpdate() {
58026
- Object.keys(this.rpcProviders).forEach((s2) => {
58027
- var i4;
58028
- this.getProvider(s2).updateNamespace((i4 = this.session) == null ? void 0 : i4.namespaces[s2]);
58029
- });
58030
- }
58031
- setNamespaces(s2) {
58032
- const { namespaces: i4, optionalNamespaces: p3, sessionProperties: w2 } = s2;
58033
- i4 && Object.keys(i4).length && (this.namespaces = i4), p3 && Object.keys(p3).length && (this.optionalNamespaces = p3), this.sessionProperties = w2, this.persist("namespaces", i4), this.persist("optionalNamespaces", p3);
58034
- }
58035
- validateChain(s2) {
58036
- const [i4, p3] = (s2 == null ? void 0 : s2.split(":")) || ["", ""];
58037
- if (!this.namespaces || !Object.keys(this.namespaces).length)
58038
- return [i4, p3];
58039
- if (i4 && !Object.keys(this.namespaces || {}).map((y3) => xo(y3)).includes(i4))
58040
- throw new Error(`Namespace '${i4}' is not configured. Please call connect() first with namespace config.`);
58041
- if (i4 && p3)
58042
- return [i4, p3];
58043
- const w2 = xo(Object.keys(this.namespaces)[0]), I2 = this.rpcProviders[w2].getDefaultChain();
58044
- return [w2, I2];
58045
- }
58046
- async requestAccounts() {
58047
- const [s2] = this.validateChain();
58048
- return await this.getProvider(s2).requestAccounts();
58049
- }
58050
- onChainChanged(s2, i4 = false) {
58051
- if (!this.namespaces)
58052
- return;
58053
- const [p3, w2] = this.validateChain(s2);
58054
- w2 && (i4 || this.getProvider(p3).setDefaultChain(w2), this.namespaces[p3] ? this.namespaces[p3].defaultChain = w2 : this.namespaces[`${p3}:${w2}`] ? this.namespaces[`${p3}:${w2}`].defaultChain = w2 : this.namespaces[`${p3}:${w2}`] = { defaultChain: w2 }, this.persist("namespaces", this.namespaces), this.events.emit("chainChanged", w2));
58055
- }
58056
- onConnect() {
58057
- this.createProviders(), this.events.emit("connect", { session: this.session });
58058
- }
58059
- async cleanup() {
58060
- this.session = void 0, this.namespaces = void 0, this.optionalNamespaces = void 0, this.sessionProperties = void 0, this.persist("namespaces", void 0), this.persist("optionalNamespaces", void 0), this.persist("sessionProperties", void 0), await this.cleanupPendingPairings({ deletePairings: true });
58061
- }
58062
- persist(s2, i4) {
58063
- this.client.core.storage.setItem(`${Sa}/${s2}`, i4);
58064
- }
58065
- async getFromStore(s2) {
58066
- return await this.client.core.storage.getItem(`${Sa}/${s2}`);
58067
- }
58068
- }
58069
- const Ev = dr;
58070
- const SIWXUtil = {
58071
- getSIWX() {
58072
- return OptionsController.state.siwx;
58073
- },
58074
- async initializeIfEnabled() {
58075
- var _a3;
58076
- const siwx = OptionsController.state.siwx;
58077
- const caipAddress = ChainController.getActiveCaipAddress();
58078
- if (!(siwx && caipAddress)) {
58079
- return;
58080
- }
58081
- const [namespace, chainId, address] = caipAddress.split(":");
58082
- if (!ChainController.checkIfSupportedNetwork(namespace)) {
58083
- return;
58084
- }
58085
- try {
58086
- const sessions = await siwx.getSessions(`${namespace}:${chainId}`, address);
58087
- if (sessions.length) {
58088
- return;
58089
- }
58090
- await ModalController.open({
58091
- view: "SIWXSignMessage"
58092
- });
58093
- } catch (error) {
58094
- console.error("SIWXUtil:initializeIfEnabled", error);
58095
- EventsController.sendEvent({
58096
- type: "track",
58097
- event: "SIWX_AUTH_ERROR",
58098
- properties: this.getSIWXEventProperties()
58099
- });
58100
- await ((_a3 = ConnectionController._getClient()) == null ? void 0 : _a3.disconnect().catch(console.error));
58101
- RouterController.reset("Connect");
58102
- SnackController.showError("A problem occurred while trying initialize authentication");
58103
- }
58104
- },
58105
- async requestSignMessage() {
58106
- const siwx = OptionsController.state.siwx;
58107
- const address = CoreHelperUtil.getPlainAddress(ChainController.getActiveCaipAddress());
58108
- const network = ChainController.getActiveCaipNetwork();
58109
- const client = ConnectionController._getClient();
58110
- if (!siwx) {
58111
- throw new Error("SIWX is not enabled");
58112
- }
58113
- if (!address) {
58114
- throw new Error("No ActiveCaipAddress found");
58115
- }
58116
- if (!network) {
58117
- throw new Error("No ActiveCaipNetwork or client found");
58118
- }
58119
- if (!client) {
58120
- throw new Error("No ConnectionController client found");
58121
- }
58122
- try {
58123
- const siwxMessage = await siwx.createMessage({
58124
- chainId: network.caipNetworkId,
58125
- accountAddress: address
58126
- });
58127
- const message = siwxMessage.toString();
58128
- if (StorageUtil.getConnectedConnector() === "ID_AUTH") {
58129
- RouterController.pushTransactionStack({
58130
- view: null,
58131
- goBack: false,
58132
- replace: true
58133
- });
58134
- }
58135
- const signature2 = await client.signMessage(message);
58136
- await siwx.addSession({
58137
- data: siwxMessage,
58138
- message,
58139
- signature: signature2
58140
- });
58141
- ModalController.close();
58142
- EventsController.sendEvent({
58143
- type: "track",
58144
- event: "SIWX_AUTH_SUCCESS",
58145
- properties: this.getSIWXEventProperties()
58146
- });
58147
- } catch (error) {
58148
- const properties = this.getSIWXEventProperties();
58149
- if (!ModalController.state.open || RouterController.state.view === "ApproveTransaction") {
58150
- await ModalController.open({
58151
- view: "SIWXSignMessage"
58152
- });
58153
- }
58154
- if (properties.isSmartAccount) {
58155
- SnackController.showError("This application might not support Smart Accounts");
58156
- } else {
58157
- SnackController.showError("Signature declined");
58158
- }
58159
- EventsController.sendEvent({
58160
- type: "track",
58161
- event: "SIWX_AUTH_ERROR",
58162
- properties
58163
- });
58164
- console.error("SWIXUtil:requestSignMessage", error);
58165
- }
58166
- },
58167
- async cancelSignMessage() {
58168
- try {
58169
- await ConnectionController.disconnect();
58170
- RouterController.reset("Connect");
58171
- EventsController.sendEvent({
58172
- event: "CLICK_CANCEL_SIWX",
58173
- type: "track",
58174
- properties: this.getSIWXEventProperties()
58175
- });
58176
- } catch (error) {
58177
- console.error("SIWXUtil:cancelSignMessage", error);
58178
- }
58179
- },
58180
- async getSessions() {
58181
- const siwx = OptionsController.state.siwx;
58182
- const address = CoreHelperUtil.getPlainAddress(ChainController.getActiveCaipAddress());
58183
- const network = ChainController.getActiveCaipNetwork();
58184
- if (!(siwx && address && network)) {
58185
- return [];
58186
- }
58187
- return siwx.getSessions(network.caipNetworkId, address);
58188
- },
58189
- async isSIWXCloseDisabled() {
58190
- const siwx = this.getSIWX();
58191
- if (siwx) {
58192
- const isApproveSignScreen = RouterController.state.view === "ApproveTransaction";
58193
- const isSiwxSignMessage = RouterController.state.view === "SIWXSignMessage";
58194
- if (isApproveSignScreen || isSiwxSignMessage) {
58195
- return (await this.getSessions()).length === 0;
58196
- }
58197
- }
58198
- return false;
58199
- },
58200
- async universalProviderAuthenticate({ universalProvider, chains, methods }) {
58201
- var _a3;
58202
- const siwx = SIWXUtil.getSIWX();
58203
- const namespaces = new Set(chains.map((chain) => chain.split(":")[0]));
58204
- if (!siwx || namespaces.size !== 1) {
58205
- return false;
58206
- }
58207
- const siwxMessage = await siwx.createMessage({
58208
- chainId: "",
58209
- accountAddress: ""
58210
- });
58211
- const result = await universalProvider.authenticate({
58212
- nonce: siwxMessage.nonce,
58213
- domain: siwxMessage.domain,
58214
- uri: siwxMessage.uri,
58215
- exp: siwxMessage.expirationTime,
58216
- iat: siwxMessage.issuedAt,
58217
- nbf: siwxMessage.notBefore,
58218
- requestId: siwxMessage.requestId,
58219
- version: siwxMessage.version,
58220
- resources: siwxMessage.resources,
58221
- statement: siwxMessage.statement,
58222
- methods,
58223
- chains
58224
- });
58225
- if ((_a3 = result == null ? void 0 : result.auths) == null ? void 0 : _a3.length) {
58226
- const sessions = result.auths.map((cacao) => {
58227
- const message = universalProvider.client.formatAuthMessage({
58228
- request: cacao.p,
58229
- iss: cacao.p.iss
58230
- });
58231
- return {
58232
- data: {
58233
- ...cacao.p,
58234
- accountAddress: cacao.p.iss.split(":").slice(-1).join(""),
58235
- chainId: cacao.p.iss.split(":").slice(2, 4).join(":"),
58236
- uri: cacao.p.aud,
58237
- version: cacao.p.version || siwxMessage.version,
58238
- expirationTime: cacao.p.exp,
58239
- issuedAt: cacao.p.iat,
58240
- notBefore: cacao.p.nbf
58241
- },
58242
- message,
58243
- signature: cacao.s.s,
58244
- cacao
58245
- };
58246
- });
58247
- try {
58248
- await siwx.setSessions(sessions);
58249
- EventsController.sendEvent({
58250
- type: "track",
58251
- event: "SIWX_AUTH_SUCCESS",
58252
- properties: SIWXUtil.getSIWXEventProperties()
58253
- });
58254
- } catch (error) {
58255
- console.error("SIWX:universalProviderAuth - failed to set sessions", error);
58256
- EventsController.sendEvent({
58257
- type: "track",
58258
- event: "SIWX_AUTH_ERROR",
58259
- properties: SIWXUtil.getSIWXEventProperties()
58260
- });
58261
- await universalProvider.disconnect().catch(console.error);
58262
- throw error;
58263
- }
58264
- }
58265
- return true;
58266
- },
58267
- getSIWXEventProperties() {
58268
- var _a3;
58269
- return {
58270
- network: ((_a3 = ChainController.state.activeCaipNetwork) == null ? void 0 : _a3.caipNetworkId) || "",
58271
- isSmartAccount: AccountController.state.preferredAccountType === W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT
58272
- };
58273
- }
58274
- };
58275
- const accountState$1 = {
58276
- currentTab: 0,
58277
- tokenBalance: [],
58278
- smartAccountDeployed: false,
58279
- addressLabels: /* @__PURE__ */ new Map(),
58280
- allAccounts: []
58281
- };
58282
- const networkState$1 = {
58283
- supportsAllNetworks: true,
58284
- smartAccountEnabledNetworks: []
58285
- };
58286
- const state$a = proxy({
58287
- chains: proxyMap(),
58288
- activeCaipAddress: void 0,
58289
- activeChain: void 0,
58290
- activeCaipNetwork: void 0,
58291
- noAdapters: false,
58292
- universalAdapter: {
58293
- networkControllerClient: void 0,
58294
- connectionControllerClient: void 0
58295
- }
58296
- });
58297
- const ChainController = {
58298
- state: state$a,
58299
- subscribe(callback) {
58300
- return subscribe(state$a, () => {
58301
- callback(state$a);
58302
- });
58303
- },
58304
- subscribeKey(key2, callback) {
58305
- return subscribeKey(state$a, key2, callback);
58306
- },
58307
- subscribeChainProp(property, callback, chain) {
58308
- let prev = void 0;
58309
- return subscribe(state$a.chains, () => {
58310
- var _a3;
58311
- const activeChain = chain || state$a.activeChain;
58312
- if (activeChain) {
58313
- const nextValue = (_a3 = state$a.chains.get(activeChain)) == null ? void 0 : _a3[property];
58314
- if (prev !== nextValue) {
58315
- prev = nextValue;
58316
- callback(nextValue);
58317
- }
58318
- }
58319
- });
58320
- },
58321
- initialize(adapters) {
58322
- const adapterToActivate = adapters == null ? void 0 : adapters[0];
58323
- if ((adapters == null ? void 0 : adapters.length) === 0 || !adapterToActivate) {
58324
- state$a.noAdapters = true;
58325
- }
58326
- if (!state$a.noAdapters) {
58327
- state$a.activeChain = adapterToActivate == null ? void 0 : adapterToActivate.namespace;
58328
- PublicStateController.set({ activeChain: adapterToActivate == null ? void 0 : adapterToActivate.namespace });
58329
- adapters.forEach((adapter) => {
58330
- state$a.chains.set(adapter.namespace, {
58331
- namespace: adapter.namespace,
58332
- connectionControllerClient: adapter.connectionControllerClient,
58333
- networkControllerClient: adapter.networkControllerClient,
58334
- adapterType: adapter.adapterType,
58335
- accountState: accountState$1,
58336
- networkState: networkState$1,
58337
- caipNetworks: adapter.caipNetworks
58338
- });
58339
- });
58340
- }
58341
- },
58342
- setAdapterNetworkState(chain, props) {
58343
- const chainAdapter = state$a.chains.get(chain);
58344
- if (chainAdapter) {
58345
- chainAdapter.networkState = ref$1({
58346
- ...chainAdapter.networkState,
58347
- ...props
58348
- });
58349
- state$a.chains.set(chain, ref$1(chainAdapter));
58350
- }
58351
- },
58352
- setChainAccountData(chain, accountProps, _unknown = true) {
58353
- if (!chain) {
58354
- throw new Error("Chain is required to update chain account data");
58355
- }
58356
- const chainAdapter = state$a.chains.get(chain);
58357
- if (chainAdapter) {
58358
- chainAdapter.accountState = ref$1({
58359
- ...chainAdapter.accountState,
58360
- ...accountProps
58361
- });
58362
- state$a.chains.set(chain, chainAdapter);
58363
- if (state$a.chains.size === 1 || state$a.activeChain === chain) {
58364
- if (accountProps.caipAddress) {
58365
- state$a.activeCaipAddress = accountProps.caipAddress;
58366
- }
58367
- AccountController.replaceState(chainAdapter.accountState);
58368
- }
58369
- }
58370
- },
58371
- // eslint-disable-next-line max-params
58372
- setAccountProp(prop, value, chain, replaceState = true) {
58373
- this.setChainAccountData(chain, {
58374
- [prop]: value
58375
- }, replaceState);
58376
- },
58377
- setActiveNamespace(chain) {
58378
- var _a3, _b2;
58379
- state$a.activeChain = chain;
58380
- const newAdapter = chain ? state$a.chains.get(chain) : void 0;
58381
- const caipNetwork = (_a3 = newAdapter == null ? void 0 : newAdapter.networkState) == null ? void 0 : _a3.caipNetwork;
58382
- if (caipNetwork == null ? void 0 : caipNetwork.id) {
58383
- state$a.activeCaipAddress = (_b2 = newAdapter == null ? void 0 : newAdapter.accountState) == null ? void 0 : _b2.caipAddress;
58384
- state$a.activeCaipNetwork = caipNetwork;
58385
- SafeLocalStorage.setItem(SafeLocalStorageKeys.ACTIVE_CAIP_NETWORK_ID, caipNetwork == null ? void 0 : caipNetwork.caipNetworkId);
58386
- PublicStateController.set({
58387
- activeChain: chain,
58388
- selectedNetworkId: caipNetwork == null ? void 0 : caipNetwork.caipNetworkId
58389
- });
58390
- }
58391
- },
58392
- setActiveCaipNetwork(caipNetwork) {
58393
- var _a3, _b2;
58394
- if (!caipNetwork) {
58395
- return;
58396
- }
58397
- const newAdapter = state$a.chains.get(caipNetwork.chainNamespace);
58398
- state$a.activeChain = caipNetwork.chainNamespace;
58399
- state$a.activeCaipNetwork = caipNetwork;
58400
- state$a.activeCaipAddress = (_a3 = newAdapter == null ? void 0 : newAdapter.accountState) == null ? void 0 : _a3.caipAddress;
58401
- if (newAdapter) {
58402
- AccountController.replaceState(newAdapter.accountState);
58403
- }
58404
- PublicStateController.set({
58405
- activeChain: state$a.activeChain,
58406
- selectedNetworkId: (_b2 = state$a.activeCaipNetwork) == null ? void 0 : _b2.caipNetworkId
58407
- });
58408
- SafeLocalStorage.setItem(SafeLocalStorageKeys.ACTIVE_CAIP_NETWORK_ID, caipNetwork.caipNetworkId);
58409
- const isSupported = this.checkIfSupportedNetwork(caipNetwork.chainNamespace);
58410
- if (!isSupported) {
58411
- this.showUnsupportedChainUI();
58412
- }
58413
- },
58414
- addCaipNetwork(caipNetwork) {
58415
- var _a3;
58416
- if (!caipNetwork) {
58417
- return;
58418
- }
58419
- const chain = state$a.chains.get(caipNetwork.chainNamespace);
58420
- if (chain) {
58421
- (_a3 = chain == null ? void 0 : chain.caipNetworks) == null ? void 0 : _a3.push(caipNetwork);
58422
- }
58423
- },
58424
- async switchActiveNetwork(network) {
58425
- const networkControllerClient = this.getNetworkControllerClient(network.chainNamespace);
58426
- if (networkControllerClient) {
58427
- await networkControllerClient.switchCaipNetwork(network);
58428
- }
58429
- this.setActiveCaipNetwork(network);
58430
- if (network) {
58431
- EventsController.sendEvent({
58432
- type: "track",
58433
- event: "SWITCH_NETWORK",
58434
- properties: { network: network.caipNetworkId }
58435
- });
58436
- await SIWXUtil.initializeIfEnabled();
58437
- }
58438
- },
58439
- setActiveConnector(connector) {
58440
- if (connector) {
58441
- state$a.activeConnector = ref$1(connector);
58442
- }
58443
- },
58444
- getNetworkControllerClient(chainNamespace) {
58445
- const chain = chainNamespace || state$a.activeChain;
58446
- const chainAdapter = state$a.chains.get(chain);
58447
- if (!chainAdapter) {
58448
- throw new Error("Chain adapter not found");
58449
- }
58450
- if (!chainAdapter.networkControllerClient) {
58451
- throw new Error("NetworkController client not set");
58452
- }
58453
- return chainAdapter.networkControllerClient;
58454
- },
58455
- getConnectionControllerClient(_chain) {
58456
- const chain = _chain || state$a.activeChain;
58457
- if (!chain) {
58458
- throw new Error("Chain is required to get connection controller client");
58459
- }
58460
- const chainAdapter = state$a.chains.get(chain);
58461
- if (!(chainAdapter == null ? void 0 : chainAdapter.connectionControllerClient)) {
58462
- throw new Error("ConnectionController client not set");
58463
- }
58464
- return chainAdapter.connectionControllerClient;
58465
- },
58466
- getAccountProp(key2, _chain) {
58467
- var _a3;
58468
- let chain = state$a.activeChain;
58469
- if (_chain) {
58470
- chain = _chain;
58471
- }
58472
- if (!chain) {
58473
- return void 0;
58474
- }
58475
- const chainAccountState = (_a3 = state$a.chains.get(chain)) == null ? void 0 : _a3.accountState;
58476
- if (!chainAccountState) {
58477
- return void 0;
58478
- }
58479
- return chainAccountState[key2];
58480
- },
58481
- getNetworkProp(key2, namespace) {
58482
- var _a3;
58483
- const chainNetworkState = (_a3 = state$a.chains.get(namespace)) == null ? void 0 : _a3.networkState;
58484
- if (!chainNetworkState) {
58485
- return void 0;
58486
- }
58487
- return chainNetworkState[key2];
58488
- },
58489
- getRequestedCaipNetworks(chainToFilter) {
58490
- const adapter = state$a.chains.get(chainToFilter);
58491
- const { approvedCaipNetworkIds = [], requestedCaipNetworks = [] } = (adapter == null ? void 0 : adapter.networkState) || {};
58492
- const sortedNetworks = CoreHelperUtil.sortRequestedNetworks(approvedCaipNetworkIds, requestedCaipNetworks);
58493
- return sortedNetworks;
58494
- },
58495
- getAllRequestedCaipNetworks() {
58496
- const requestedCaipNetworks = [];
58497
- state$a.chains.forEach((chainAdapter) => {
58498
- const caipNetworks = this.getRequestedCaipNetworks(chainAdapter.namespace);
58499
- requestedCaipNetworks.push(...caipNetworks);
58500
- });
58501
- return requestedCaipNetworks;
58502
- },
58503
- setRequestedCaipNetworks(requestedNetworks, chain) {
58504
- this.setAdapterNetworkState(chain, { requestedCaipNetworks: requestedNetworks });
58505
- },
58506
- getAllApprovedCaipNetworkIds() {
58507
- const approvedCaipNetworkIds = [];
58508
- state$a.chains.forEach((chainAdapter) => {
58509
- const approvedIds = this.getApprovedCaipNetworkIds(chainAdapter.namespace);
58510
- approvedCaipNetworkIds.push(...approvedIds);
58511
- });
58512
- return approvedCaipNetworkIds;
58513
- },
58514
- getActiveCaipNetwork() {
58515
- return state$a.activeCaipNetwork;
58516
- },
58517
- getActiveCaipAddress() {
58518
- return state$a.activeCaipAddress;
58519
- },
58520
- getApprovedCaipNetworkIds(namespace) {
58521
- var _a3;
58522
- const adapter = state$a.chains.get(namespace);
58523
- const approvedCaipNetworkIds = ((_a3 = adapter == null ? void 0 : adapter.networkState) == null ? void 0 : _a3.approvedCaipNetworkIds) || [];
58524
- return approvedCaipNetworkIds;
58525
- },
58526
- async setApprovedCaipNetworksData(namespace) {
58527
- const networkControllerClient = this.getNetworkControllerClient();
58528
- const data2 = await (networkControllerClient == null ? void 0 : networkControllerClient.getApprovedCaipNetworksData());
58529
- this.setAdapterNetworkState(namespace, {
58530
- approvedCaipNetworkIds: data2 == null ? void 0 : data2.approvedCaipNetworkIds,
58531
- supportsAllNetworks: data2 == null ? void 0 : data2.supportsAllNetworks
58532
- });
58533
- },
58534
- checkIfSupportedNetwork(namespace) {
58535
- const activeCaipNetwork = this.state.activeCaipNetwork;
58536
- const requestedCaipNetworks = this.getRequestedCaipNetworks(namespace);
58537
- if (!requestedCaipNetworks.length) {
58538
- return true;
58539
- }
58540
- return requestedCaipNetworks == null ? void 0 : requestedCaipNetworks.some((network) => network.id === (activeCaipNetwork == null ? void 0 : activeCaipNetwork.id));
58541
- },
58542
- checkIfSupportedChainId(chainId) {
58543
- if (!this.state.activeChain) {
58544
- return true;
58545
- }
58546
- const requestedCaipNetworks = this.getRequestedCaipNetworks(this.state.activeChain);
58547
- return requestedCaipNetworks == null ? void 0 : requestedCaipNetworks.some((network) => network.id === chainId);
58548
- },
58549
- // Smart Account Network Handlers
58550
- setSmartAccountEnabledNetworks(smartAccountEnabledNetworks, chain) {
58551
- this.setAdapterNetworkState(chain, { smartAccountEnabledNetworks });
58552
- },
58553
- checkIfSmartAccountEnabled() {
58554
- var _a3;
58555
- const networkId = NetworkUtil.caipNetworkIdToNumber((_a3 = state$a.activeCaipNetwork) == null ? void 0 : _a3.caipNetworkId);
58556
- const activeChain = this.state.activeChain;
58557
- if (!activeChain || !networkId) {
58558
- return false;
58559
- }
58560
- const smartAccountEnabledNetworks = this.getNetworkProp("smartAccountEnabledNetworks", activeChain);
58561
- return Boolean(smartAccountEnabledNetworks == null ? void 0 : smartAccountEnabledNetworks.includes(Number(networkId)));
58562
- },
58563
- getActiveNetworkTokenAddress() {
58564
- var _a3, _b2;
58565
- const namespace = ((_a3 = this.state.activeCaipNetwork) == null ? void 0 : _a3.chainNamespace) || "eip155";
58566
- const chainId = ((_b2 = this.state.activeCaipNetwork) == null ? void 0 : _b2.id) || 1;
58567
- const address = ConstantsUtil$2.NATIVE_TOKEN_ADDRESS[namespace];
58568
- return `${namespace}:${chainId}:${address}`;
58569
- },
58570
- showUnsupportedChainUI() {
58571
- setTimeout(() => {
58572
- ModalController.open({ view: "UnsupportedChain" });
58573
- }, 300);
58574
- },
58575
- checkIfNamesSupported() {
58576
- const activeCaipNetwork = state$a.activeCaipNetwork;
58577
- return Boolean((activeCaipNetwork == null ? void 0 : activeCaipNetwork.chainNamespace) && ConstantsUtil$2.NAMES_SUPPORTED_CHAIN_NAMESPACES.includes(activeCaipNetwork.chainNamespace));
58578
- },
58579
- resetNetwork(namespace) {
58580
- this.setAdapterNetworkState(namespace, {
58581
- approvedCaipNetworkIds: void 0,
58582
- supportsAllNetworks: true,
58583
- smartAccountEnabledNetworks: []
58584
- });
58585
- },
58586
- resetAccount(chain) {
58587
- const chainToWrite = chain;
58588
- if (!chainToWrite) {
58589
- throw new Error("Chain is required to set account prop");
58590
- }
58591
- this.state.activeCaipAddress = void 0;
58592
- this.setChainAccountData(chainToWrite, ref$1({
58593
- smartAccountDeployed: false,
58594
- currentTab: 0,
58595
- caipAddress: void 0,
58596
- address: void 0,
58597
- balance: void 0,
58598
- balanceSymbol: void 0,
58599
- profileName: void 0,
58600
- profileImage: void 0,
58601
- addressExplorerUrl: void 0,
58602
- tokenBalance: [],
58603
- connectedWalletInfo: void 0,
58604
- preferredAccountType: void 0,
58605
- socialProvider: void 0,
58606
- socialWindow: void 0,
58607
- farcasterUrl: void 0,
58608
- provider: void 0
58609
- }));
58610
- }
58611
- };
58612
- const StorageUtil = {
58613
- setWalletConnectDeepLink({ name: name2, href }) {
58614
- try {
58615
- SafeLocalStorage.setItem(SafeLocalStorageKeys.DEEPLINK_CHOICE, JSON.stringify({ href, name: name2 }));
58616
- } catch {
58617
- console.info("Unable to set WalletConnect deep link");
58618
- }
58619
- },
58620
- getWalletConnectDeepLink() {
58621
- try {
58622
- const deepLink = SafeLocalStorage.getItem(SafeLocalStorageKeys.DEEPLINK_CHOICE);
58623
- if (deepLink) {
58624
- return JSON.parse(deepLink);
58625
- }
58626
- } catch {
58627
- console.info("Unable to get WalletConnect deep link");
58628
- }
58629
- return void 0;
58630
- },
58631
- deleteWalletConnectDeepLink() {
58632
- try {
58633
- SafeLocalStorage.removeItem(SafeLocalStorageKeys.DEEPLINK_CHOICE);
58634
- } catch {
58635
- console.info("Unable to delete WalletConnect deep link");
58636
- }
58637
- },
58638
- setAppKitRecent(wallet) {
58639
- try {
58640
- const recentWallets = StorageUtil.getRecentWallets();
58641
- const exists2 = recentWallets.find((w2) => w2.id === wallet.id);
58642
- if (!exists2) {
58643
- recentWallets.unshift(wallet);
58644
- if (recentWallets.length > 2) {
58645
- recentWallets.pop();
58646
- }
58647
- SafeLocalStorage.setItem(SafeLocalStorageKeys.RECENT_WALLETS, JSON.stringify(recentWallets));
58648
- }
58649
- } catch {
58650
- console.info("Unable to set AppKit recent");
58651
- }
58652
- },
58653
- getRecentWallets() {
58654
- try {
58655
- const recent = SafeLocalStorage.getItem(SafeLocalStorageKeys.RECENT_WALLETS);
58656
- return recent ? JSON.parse(recent) : [];
58657
- } catch {
58658
- console.info("Unable to get AppKit recent");
58659
- }
58660
- return [];
58661
- },
58662
- setConnectedConnector(connectorType) {
58663
- try {
58664
- SafeLocalStorage.setItem(SafeLocalStorageKeys.CONNECTED_CONNECTOR, connectorType);
58665
- } catch {
58666
- console.info("Unable to set Connected Connector");
58667
- }
58668
- },
58669
- setConnectedNamespace(namespace) {
58670
- try {
58671
- SafeLocalStorage.setItem(SafeLocalStorageKeys.CONNECTED_NAMESPACE, namespace);
58672
- } catch {
58673
- console.info("Unable to set Connected Namespace");
58674
- }
58675
- },
58676
- getConnectedConnector() {
58677
- try {
58678
- return SafeLocalStorage.getItem(SafeLocalStorageKeys.CONNECTED_CONNECTOR);
58679
- } catch {
58680
- console.info("Unable to get Connected Connector");
58681
- }
58682
- return void 0;
58683
- },
58684
- setConnectedSocialProvider(socialProvider) {
58685
- try {
58686
- SafeLocalStorage.setItem(SafeLocalStorageKeys.CONNECTED_SOCIAL, socialProvider);
58687
- } catch {
58688
- console.info("Unable to set Connected Social Provider");
58689
- }
58690
- },
58691
- getConnectedSocialProvider() {
58692
- try {
58693
- return SafeLocalStorage.getItem(SafeLocalStorageKeys.CONNECTED_SOCIAL);
58694
- } catch {
58695
- console.info("Unable to get Connected Social Provider");
58696
- }
58697
- return void 0;
58698
- },
58699
- getConnectedSocialUsername() {
58700
- try {
58701
- return SafeLocalStorage.getItem(SafeLocalStorageKeys.CONNECTED_SOCIAL_USERNAME);
58702
- } catch {
58703
- console.info("Unable to get Connected Social Username");
58704
- }
58705
- return void 0;
58706
- },
58707
- getStoredActiveCaipNetwork() {
58708
- const storedCaipNetworkId = SafeLocalStorage.getItem(SafeLocalStorageKeys.ACTIVE_CAIP_NETWORK_ID);
58709
- const allRequestedCaipNetworks = ChainController.getAllRequestedCaipNetworks();
58710
- const storedCaipNetwork = allRequestedCaipNetworks == null ? void 0 : allRequestedCaipNetworks.find((c2) => c2.caipNetworkId === storedCaipNetworkId);
58711
- return storedCaipNetwork;
58712
- }
58713
- };
58714
- const state$9 = proxy({
58715
- walletImages: {},
58716
- networkImages: {},
58717
- chainImages: {},
58718
- connectorImages: {},
58719
- tokenImages: {},
58720
- currencyImages: {}
58721
- });
58722
- const AssetController = {
58723
- state: state$9,
58724
- subscribeNetworkImages(callback) {
58725
- return subscribe(state$9.networkImages, () => callback(state$9.networkImages));
58726
- },
58727
- subscribeKey(key2, callback) {
58728
- return subscribeKey(state$9, key2, callback);
58729
- },
58730
- subscribe(callback) {
58731
- return subscribe(state$9, () => callback(state$9));
58732
- },
58733
- setWalletImage(key2, value) {
58734
- state$9.walletImages[key2] = value;
58735
- },
58736
- setNetworkImage(key2, value) {
58737
- state$9.networkImages[key2] = value;
58738
- },
58739
- setChainImage(key2, value) {
58740
- state$9.chainImages[key2] = value;
58741
- },
58742
- setConnectorImage(key2, value) {
58743
- state$9.connectorImages[key2] = value;
58744
- },
58745
- setTokenImage(key2, value) {
58746
- state$9.tokenImages[key2] = value;
58747
- },
58748
- setCurrencyImage(key2, value) {
58749
- state$9.currencyImages[key2] = value;
58750
- }
58751
- };
58752
- const baseUrl = CoreHelperUtil.getApiUrl();
58753
- const api = new FetchUtil({ baseUrl, clientId: null });
58754
- const entries = "40";
58755
- const recommendedEntries = "4";
58756
- const imageCountToFetch = 20;
58757
- const state$8 = proxy({
58758
- page: 1,
58759
- count: 0,
58760
- featured: [],
58761
- recommended: [],
58762
- wallets: [],
58763
- search: [],
58764
- isAnalyticsEnabled: false,
58765
- excludedRDNS: []
58766
- });
58767
- const ApiController = {
58768
- state: state$8,
58769
- subscribeKey(key2, callback) {
58770
- return subscribeKey(state$8, key2, callback);
58771
- },
58772
- _getSdkProperties() {
58773
- const { projectId, sdkType, sdkVersion } = OptionsController.state;
58774
- return {
58775
- projectId,
58776
- st: sdkType || "appkit",
58777
- sv: sdkVersion || "html-wagmi-4.2.2"
58778
- };
58779
- },
58780
- _filterOutExtensions(wallets2) {
58781
- if (OptionsController.state.isUniversalProvider) {
58782
- return wallets2.filter((w2) => Boolean(w2.mobile_link || w2.desktop_link || w2.webapp_link));
58783
- }
58784
- return wallets2;
58785
- },
58786
- async _fetchWalletImage(imageId) {
58787
- const imageUrl = `${api.baseUrl}/getWalletImage/${imageId}`;
58788
- const blob2 = await api.getBlob({ path: imageUrl, params: ApiController._getSdkProperties() });
58789
- AssetController.setWalletImage(imageId, URL.createObjectURL(blob2));
58790
- },
58791
- async _fetchNetworkImage(imageId) {
58792
- const imageUrl = `${api.baseUrl}/public/getAssetImage/${imageId}`;
58793
- const blob2 = await api.getBlob({ path: imageUrl, params: ApiController._getSdkProperties() });
58794
- AssetController.setNetworkImage(imageId, URL.createObjectURL(blob2));
58795
- },
58796
- async _fetchConnectorImage(imageId) {
58797
- const imageUrl = `${api.baseUrl}/public/getAssetImage/${imageId}`;
58798
- const blob2 = await api.getBlob({ path: imageUrl, params: ApiController._getSdkProperties() });
58799
- AssetController.setConnectorImage(imageId, URL.createObjectURL(blob2));
58800
- },
58801
- async _fetchCurrencyImage(countryCode) {
58802
- const imageUrl = `${api.baseUrl}/public/getCurrencyImage/${countryCode}`;
58803
- const blob2 = await api.getBlob({ path: imageUrl, params: ApiController._getSdkProperties() });
58804
- AssetController.setCurrencyImage(countryCode, URL.createObjectURL(blob2));
58805
- },
58806
- async _fetchTokenImage(symbol) {
58807
- const imageUrl = `${api.baseUrl}/public/getTokenImage/${symbol}`;
58808
- const blob2 = await api.getBlob({ path: imageUrl, params: ApiController._getSdkProperties() });
58809
- AssetController.setTokenImage(symbol, URL.createObjectURL(blob2));
58810
- },
58811
- async fetchNetworkImages() {
58812
- const requestedCaipNetworks = ChainController.getAllRequestedCaipNetworks();
58813
- const ids = requestedCaipNetworks == null ? void 0 : requestedCaipNetworks.map(({ assets }) => assets == null ? void 0 : assets.imageId).filter(Boolean);
58814
- if (ids) {
58815
- await Promise.allSettled(ids.map((id) => ApiController._fetchNetworkImage(id)));
58816
- }
58817
- },
58818
- async fetchConnectorImages() {
58819
- const { connectors } = ConnectorController.state;
58820
- const ids = connectors.map(({ imageId }) => imageId).filter(Boolean);
58821
- await Promise.allSettled(ids.map((id) => ApiController._fetchConnectorImage(id)));
58822
- },
58823
- async fetchCurrencyImages(currencies = []) {
58824
- await Promise.allSettled(currencies.map((currency) => ApiController._fetchCurrencyImage(currency)));
58825
- },
58826
- async fetchTokenImages(tokens = []) {
58827
- await Promise.allSettled(tokens.map((token2) => ApiController._fetchTokenImage(token2)));
58828
- },
58829
- async fetchFeaturedWallets() {
58830
- const { featuredWalletIds } = OptionsController.state;
58831
- if (featuredWalletIds == null ? void 0 : featuredWalletIds.length) {
58832
- const { data: data2 } = await api.get({
58833
- path: "/getWallets",
58834
- params: {
58835
- ...ApiController._getSdkProperties(),
58836
- page: "1",
58837
- entries: (featuredWalletIds == null ? void 0 : featuredWalletIds.length) ? String(featuredWalletIds.length) : recommendedEntries,
58838
- include: featuredWalletIds == null ? void 0 : featuredWalletIds.join(",")
58839
- }
58840
- });
58841
- data2.sort((a3, b4) => featuredWalletIds.indexOf(a3.id) - featuredWalletIds.indexOf(b4.id));
58842
- const images = data2.map((d4) => d4.image_id).filter(Boolean);
58843
- await Promise.allSettled(images.map((id) => ApiController._fetchWalletImage(id)));
58844
- state$8.featured = data2;
59207
+ throw new Error("Sign Client not initialized");
59208
+ if (this.setNamespaces(s2), await this.cleanupPendingPairings(), !s2.skipPairing)
59209
+ return await this.pair(s2.pairingTopic);
59210
+ }
59211
+ async authenticate(s2, i4) {
59212
+ if (!this.client)
59213
+ throw new Error("Sign Client not initialized");
59214
+ this.setNamespaces(s2), await this.cleanupPendingPairings();
59215
+ const { uri: p3, response: w2 } = await this.client.authenticate(s2, i4);
59216
+ p3 && (this.uri = p3, this.events.emit("display_uri", p3));
59217
+ const I2 = await w2();
59218
+ if (this.session = I2.session, this.session) {
59219
+ const y3 = Ha(this.session.namespaces);
59220
+ this.namespaces = Fi(this.namespaces, y3), this.persist("namespaces", this.namespaces), this.onConnect();
58845
59221
  }
58846
- },
58847
- async fetchRecommendedWallets() {
58848
- var _a3;
58849
- try {
58850
- const { includeWalletIds, excludeWalletIds, featuredWalletIds } = OptionsController.state;
58851
- const exclude = [...excludeWalletIds ?? [], ...featuredWalletIds ?? []].filter(Boolean);
58852
- const { data: data2, count } = await api.get({
58853
- path: "/getWallets",
58854
- params: {
58855
- ...ApiController._getSdkProperties(),
58856
- page: "1",
58857
- chains: (_a3 = ChainController.state.activeCaipNetwork) == null ? void 0 : _a3.caipNetworkId,
58858
- entries: recommendedEntries,
58859
- include: includeWalletIds == null ? void 0 : includeWalletIds.join(","),
58860
- exclude: exclude == null ? void 0 : exclude.join(",")
58861
- }
59222
+ return I2;
59223
+ }
59224
+ on(s2, i4) {
59225
+ this.events.on(s2, i4);
59226
+ }
59227
+ once(s2, i4) {
59228
+ this.events.once(s2, i4);
59229
+ }
59230
+ removeListener(s2, i4) {
59231
+ this.events.removeListener(s2, i4);
59232
+ }
59233
+ off(s2, i4) {
59234
+ this.events.off(s2, i4);
59235
+ }
59236
+ get isWalletConnect() {
59237
+ return true;
59238
+ }
59239
+ async pair(s2) {
59240
+ this.shouldAbortPairingAttempt = false;
59241
+ let i4 = 0;
59242
+ do {
59243
+ if (this.shouldAbortPairingAttempt)
59244
+ throw new Error("Pairing aborted");
59245
+ if (i4 >= this.maxPairingAttempts)
59246
+ throw new Error("Max auto pairing attempts reached");
59247
+ const { uri: p3, approval: w2 } = await this.client.connect({ pairingTopic: s2, requiredNamespaces: this.namespaces, optionalNamespaces: this.optionalNamespaces, sessionProperties: this.sessionProperties });
59248
+ p3 && (this.uri = p3, this.events.emit("display_uri", p3)), await w2().then((I2) => {
59249
+ this.session = I2;
59250
+ const y3 = Ha(I2.namespaces);
59251
+ this.namespaces = Fi(this.namespaces, y3), this.persist("namespaces", this.namespaces);
59252
+ }).catch((I2) => {
59253
+ if (I2.message !== it)
59254
+ throw I2;
59255
+ i4++;
58862
59256
  });
58863
- const recent = StorageUtil.getRecentWallets();
58864
- const recommendedImages = data2.map((d4) => d4.image_id).filter(Boolean);
58865
- const recentImages = recent.map((r4) => r4.image_id).filter(Boolean);
58866
- await Promise.allSettled([...recommendedImages, ...recentImages].map((id) => ApiController._fetchWalletImage(id)));
58867
- state$8.recommended = data2;
58868
- state$8.count = count ?? 0;
58869
- } catch {
59257
+ } while (!this.session);
59258
+ return this.onConnect(), this.session;
59259
+ }
59260
+ setDefaultChain(s2, i4) {
59261
+ try {
59262
+ if (!this.session)
59263
+ return;
59264
+ const [p3, w2] = this.validateChain(s2), I2 = this.getProvider(p3);
59265
+ I2.name === ze ? I2.setDefaultChain(`${p3}:${w2}`, i4) : I2.setDefaultChain(w2, i4);
59266
+ } catch (p3) {
59267
+ if (!/Please call connect/.test(p3.message))
59268
+ throw p3;
58870
59269
  }
58871
- },
58872
- async fetchWallets({ page }) {
58873
- var _a3;
58874
- const { includeWalletIds, excludeWalletIds, featuredWalletIds } = OptionsController.state;
58875
- const exclude = [
58876
- ...state$8.recommended.map(({ id }) => id),
58877
- ...excludeWalletIds ?? [],
58878
- ...featuredWalletIds ?? []
58879
- ].filter(Boolean);
58880
- const { data: data2, count } = await api.get({
58881
- path: "/getWallets",
58882
- params: {
58883
- ...ApiController._getSdkProperties(),
58884
- page: String(page),
58885
- entries,
58886
- chains: (_a3 = ChainController.state.activeCaipNetwork) == null ? void 0 : _a3.caipNetworkId,
58887
- include: includeWalletIds == null ? void 0 : includeWalletIds.join(","),
58888
- exclude: exclude.join(",")
58889
- }
58890
- });
58891
- const images = data2.slice(0, imageCountToFetch).map((w2) => w2.image_id).filter(Boolean);
58892
- await Promise.allSettled(images.map((id) => ApiController._fetchWalletImage(id)));
58893
- state$8.wallets = CoreHelperUtil.uniqueBy([...state$8.wallets, ...ApiController._filterOutExtensions(data2)], "id");
58894
- state$8.count = count > state$8.count ? count : state$8.count;
58895
- state$8.page = page;
58896
- },
58897
- async searchWalletByIds({ ids }) {
58898
- var _a3;
58899
- const { data: data2 } = await api.get({
58900
- path: "/getWallets",
58901
- params: {
58902
- ...ApiController._getSdkProperties(),
58903
- page: "1",
58904
- entries: String(ids.length),
58905
- chains: (_a3 = ChainController.state.activeCaipNetwork) == null ? void 0 : _a3.caipNetworkId,
58906
- include: ids == null ? void 0 : ids.join(",")
58907
- }
58908
- });
58909
- if (data2) {
58910
- data2.forEach((wallet) => {
58911
- if (wallet == null ? void 0 : wallet.rdns) {
58912
- state$8.excludedRDNS.push(wallet.rdns);
58913
- }
58914
- });
59270
+ }
59271
+ async cleanupPendingPairings(s2 = {}) {
59272
+ this.logger.info("Cleaning up inactive pairings...");
59273
+ const i4 = this.client.pairing.getAll();
59274
+ if (Nr$1(i4)) {
59275
+ for (const p3 of i4)
59276
+ s2.deletePairings ? this.client.core.expirer.set(p3.topic, 0) : await this.client.core.relayer.subscriber.unsubscribe(p3.topic);
59277
+ this.logger.info(`Inactive pairings cleared: ${i4.length}`);
58915
59278
  }
58916
- },
58917
- async searchWallet({ search, badge }) {
58918
- var _a3;
58919
- const { includeWalletIds, excludeWalletIds } = OptionsController.state;
58920
- state$8.search = [];
58921
- const { data: data2 } = await api.get({
58922
- path: "/getWallets",
58923
- params: {
58924
- ...ApiController._getSdkProperties(),
58925
- page: "1",
58926
- entries: "100",
58927
- search: search == null ? void 0 : search.trim(),
58928
- badge_type: badge,
58929
- chains: (_a3 = ChainController.state.activeCaipNetwork) == null ? void 0 : _a3.caipNetworkId,
58930
- include: includeWalletIds == null ? void 0 : includeWalletIds.join(","),
58931
- exclude: excludeWalletIds == null ? void 0 : excludeWalletIds.join(",")
58932
- }
58933
- });
58934
- EventsController.sendEvent({
58935
- type: "track",
58936
- event: "SEARCH_WALLET",
58937
- properties: { badge: badge ?? "", search: search ?? "" }
58938
- });
58939
- const images = data2.map((w2) => w2.image_id).filter(Boolean);
58940
- await Promise.allSettled([
58941
- ...images.map((id) => ApiController._fetchWalletImage(id)),
58942
- CoreHelperUtil.wait(300)
58943
- ]);
58944
- state$8.search = ApiController._filterOutExtensions(data2);
58945
- },
58946
- async reFetchWallets() {
58947
- state$8.page = 1;
58948
- state$8.wallets = [];
58949
- await ApiController.fetchFeaturedWallets();
58950
- await ApiController.fetchRecommendedWallets();
58951
- },
58952
- prefetch() {
58953
- var _a3;
58954
- const promises = [
58955
- ApiController.fetchFeaturedWallets(),
58956
- ApiController.fetchRecommendedWallets(),
58957
- ApiController.fetchNetworkImages(),
58958
- ApiController.fetchConnectorImages()
58959
- ];
58960
- if ((_a3 = OptionsController.state.features) == null ? void 0 : _a3.analytics) {
58961
- promises.push(ApiController.fetchAnalyticsConfig());
59279
+ }
59280
+ abortPairingAttempt() {
59281
+ this.shouldAbortPairingAttempt = true;
59282
+ }
59283
+ async checkStorage() {
59284
+ if (this.namespaces = await this.getFromStore("namespaces"), this.optionalNamespaces = await this.getFromStore("optionalNamespaces") || {}, this.client.session.length) {
59285
+ const s2 = this.client.session.keys.length - 1;
59286
+ this.session = this.client.session.get(this.client.session.keys[s2]), this.createProviders();
58962
59287
  }
58963
- state$8.prefetchPromise = Promise.race([Promise.allSettled(promises)]);
58964
- },
58965
- async fetchAnalyticsConfig() {
58966
- const { isAnalyticsEnabled } = await api.get({
58967
- path: "/getAnalyticsConfig",
58968
- params: ApiController._getSdkProperties()
59288
+ }
59289
+ async initialize() {
59290
+ this.logger.trace("Initialized"), await this.createClient(), await this.checkStorage(), this.registerEventListeners();
59291
+ }
59292
+ async createClient() {
59293
+ this.client = this.providerOpts.client || await _e.init({ core: this.providerOpts.core, logger: this.providerOpts.logger || ya, relayUrl: this.providerOpts.relayUrl || Yg, projectId: this.providerOpts.projectId, metadata: this.providerOpts.metadata, storageOptions: this.providerOpts.storageOptions, storage: this.providerOpts.storage, name: this.providerOpts.name, customStoragePrefix: this.providerOpts.customStoragePrefix, telemetryEnabled: this.providerOpts.telemetryEnabled }), this.logger.trace("SignClient Initialized");
59294
+ }
59295
+ createProviders() {
59296
+ if (!this.client)
59297
+ throw new Error("Sign Client not initialized");
59298
+ if (!this.session)
59299
+ throw new Error("Session not initialized. Please call connect() before enable()");
59300
+ const s2 = [...new Set(Object.keys(this.session.namespaces).map((i4) => xo(i4)))];
59301
+ Mi("client", this.client), Mi("events", this.events), Mi("disableProviderPing", this.disableProviderPing), s2.forEach((i4) => {
59302
+ if (!this.session)
59303
+ return;
59304
+ const p3 = rv(i4, this.session), w2 = Ta(p3), I2 = Fi(this.namespaces, this.optionalNamespaces), y3 = Bi(pr({}, I2[i4]), { accounts: p3, chains: w2 });
59305
+ switch (i4) {
59306
+ case "eip155":
59307
+ this.rpcProviders[i4] = new hv({ namespace: y3 });
59308
+ break;
59309
+ case "algorand":
59310
+ this.rpcProviders[i4] = new dv({ namespace: y3 });
59311
+ break;
59312
+ case "solana":
59313
+ this.rpcProviders[i4] = new lv({ namespace: y3 });
59314
+ break;
59315
+ case "cosmos":
59316
+ this.rpcProviders[i4] = new pv({ namespace: y3 });
59317
+ break;
59318
+ case "polkadot":
59319
+ this.rpcProviders[i4] = new sv({ namespace: y3 });
59320
+ break;
59321
+ case "cip34":
59322
+ this.rpcProviders[i4] = new gv({ namespace: y3 });
59323
+ break;
59324
+ case "elrond":
59325
+ this.rpcProviders[i4] = new vv({ namespace: y3 });
59326
+ break;
59327
+ case "multiversx":
59328
+ this.rpcProviders[i4] = new _v({ namespace: y3 });
59329
+ break;
59330
+ case "near":
59331
+ this.rpcProviders[i4] = new mv({ namespace: y3 });
59332
+ break;
59333
+ default:
59334
+ this.rpcProviders[ze] ? this.rpcProviders[ze].updateNamespace(y3) : this.rpcProviders[ze] = new wv({ namespace: y3 });
59335
+ }
58969
59336
  });
58970
- OptionsController.setFeatures({ analytics: isAnalyticsEnabled });
58971
59337
  }
58972
- };
58973
- const state$7 = proxy({
58974
- loading: false,
58975
- open: false,
58976
- shake: false
58977
- });
58978
- const ModalController = {
58979
- state: state$7,
58980
- subscribe(callback) {
58981
- return subscribe(state$7, () => callback(state$7));
58982
- },
58983
- subscribeKey(key2, callback) {
58984
- return subscribeKey(state$7, key2, callback);
58985
- },
58986
- async open(options) {
58987
- await ApiController.state.prefetchPromise;
58988
- const caipAddress = ChainController.state.activeCaipAddress;
58989
- const noAdapters = ChainController.state.noAdapters;
58990
- if (options == null ? void 0 : options.view) {
58991
- RouterController.reset(options.view);
58992
- } else if (caipAddress) {
58993
- RouterController.reset("Account");
58994
- } else if (noAdapters && !CoreHelperUtil.isMobile()) {
58995
- RouterController.reset("ConnectingWalletConnect");
58996
- } else {
58997
- RouterController.reset("Connect");
58998
- }
58999
- state$7.open = true;
59000
- PublicStateController.set({ open: true });
59001
- EventsController.sendEvent({
59002
- type: "track",
59003
- event: "MODAL_OPEN",
59004
- properties: { connected: Boolean(caipAddress) }
59338
+ registerEventListeners() {
59339
+ if (typeof this.client > "u")
59340
+ throw new Error("Sign Client is not initialized");
59341
+ this.client.on("session_ping", (s2) => {
59342
+ this.events.emit("session_ping", s2);
59343
+ }), this.client.on("session_event", (s2) => {
59344
+ const { params: i4 } = s2, { event: p3 } = i4;
59345
+ if (p3.name === "accountsChanged") {
59346
+ const w2 = p3.data;
59347
+ w2 && Nr$1(w2) && this.events.emit("accountsChanged", w2.map(iv));
59348
+ } else if (p3.name === "chainChanged") {
59349
+ const w2 = i4.chainId, I2 = i4.event.data, y3 = xo(w2), J = Wi(w2) !== Wi(I2) ? `${y3}:${Wi(I2)}` : w2;
59350
+ this.onChainChanged(J);
59351
+ } else
59352
+ this.events.emit(p3.name, p3.data);
59353
+ this.events.emit("session_event", s2);
59354
+ }), this.client.on("session_update", ({ topic: s2, params: i4 }) => {
59355
+ var p3;
59356
+ const { namespaces: w2 } = i4, I2 = (p3 = this.client) == null ? void 0 : p3.session.get(s2);
59357
+ this.session = Bi(pr({}, I2), { namespaces: w2 }), this.onSessionUpdate(), this.events.emit("session_update", { topic: s2, params: i4 });
59358
+ }), this.client.on("session_delete", async (s2) => {
59359
+ await this.cleanup(), this.events.emit("session_delete", s2), this.events.emit("disconnect", Bi(pr({}, er$1("USER_DISCONNECTED")), { data: s2.topic }));
59360
+ }), this.on(Tt.DEFAULT_CHAIN_CHANGED, (s2) => {
59361
+ this.onChainChanged(s2, true);
59005
59362
  });
59006
- },
59007
- close() {
59008
- const connected = Boolean(ChainController.state.activeCaipAddress);
59009
- state$7.open = false;
59010
- PublicStateController.set({ open: false });
59011
- EventsController.sendEvent({
59012
- type: "track",
59013
- event: "MODAL_CLOSE",
59014
- properties: { connected }
59363
+ }
59364
+ getProvider(s2) {
59365
+ return this.rpcProviders[s2] || this.rpcProviders[ze];
59366
+ }
59367
+ onSessionUpdate() {
59368
+ Object.keys(this.rpcProviders).forEach((s2) => {
59369
+ var i4;
59370
+ this.getProvider(s2).updateNamespace((i4 = this.session) == null ? void 0 : i4.namespaces[s2]);
59015
59371
  });
59016
- },
59017
- setLoading(loading) {
59018
- state$7.loading = loading;
59019
- PublicStateController.set({ loading });
59020
- },
59021
- shake() {
59022
- if (state$7.shake) {
59372
+ }
59373
+ setNamespaces(s2) {
59374
+ const { namespaces: i4, optionalNamespaces: p3, sessionProperties: w2 } = s2;
59375
+ i4 && Object.keys(i4).length && (this.namespaces = i4), p3 && Object.keys(p3).length && (this.optionalNamespaces = p3), this.sessionProperties = w2, this.persist("namespaces", i4), this.persist("optionalNamespaces", p3);
59376
+ }
59377
+ validateChain(s2) {
59378
+ const [i4, p3] = (s2 == null ? void 0 : s2.split(":")) || ["", ""];
59379
+ if (!this.namespaces || !Object.keys(this.namespaces).length)
59380
+ return [i4, p3];
59381
+ if (i4 && !Object.keys(this.namespaces || {}).map((y3) => xo(y3)).includes(i4))
59382
+ throw new Error(`Namespace '${i4}' is not configured. Please call connect() first with namespace config.`);
59383
+ if (i4 && p3)
59384
+ return [i4, p3];
59385
+ const w2 = xo(Object.keys(this.namespaces)[0]), I2 = this.rpcProviders[w2].getDefaultChain();
59386
+ return [w2, I2];
59387
+ }
59388
+ async requestAccounts() {
59389
+ const [s2] = this.validateChain();
59390
+ return await this.getProvider(s2).requestAccounts();
59391
+ }
59392
+ onChainChanged(s2, i4 = false) {
59393
+ if (!this.namespaces)
59023
59394
  return;
59024
- }
59025
- state$7.shake = true;
59026
- setTimeout(() => {
59027
- state$7.shake = false;
59028
- }, 500);
59395
+ const [p3, w2] = this.validateChain(s2);
59396
+ w2 && (i4 || this.getProvider(p3).setDefaultChain(w2), this.namespaces[p3] ? this.namespaces[p3].defaultChain = w2 : this.namespaces[`${p3}:${w2}`] ? this.namespaces[`${p3}:${w2}`].defaultChain = w2 : this.namespaces[`${p3}:${w2}`] = { defaultChain: w2 }, this.persist("namespaces", this.namespaces), this.events.emit("chainChanged", w2));
59029
59397
  }
59030
- };
59031
- const USDC_CURRENCY_DEFAULT = {
59032
- id: "2b92315d-eab7-5bef-84fa-089a131333f5",
59033
- name: "USD Coin",
59034
- symbol: "USDC",
59035
- networks: [
59036
- {
59037
- name: "ethereum-mainnet",
59038
- display_name: "Ethereum",
59039
- chain_id: "1",
59040
- contract_address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
59041
- },
59042
- {
59043
- name: "polygon-mainnet",
59044
- display_name: "Polygon",
59045
- chain_id: "137",
59046
- contract_address: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"
59047
- }
59048
- ]
59049
- };
59050
- const USD_CURRENCY_DEFAULT = {
59051
- id: "USD",
59052
- payment_method_limits: [
59053
- {
59054
- id: "card",
59055
- min: "10.00",
59056
- max: "7500.00"
59057
- },
59058
- {
59059
- id: "ach_bank_account",
59060
- min: "10.00",
59061
- max: "25000.00"
59062
- }
59063
- ]
59064
- };
59065
- const defaultState = {
59066
- providers: ONRAMP_PROVIDERS,
59067
- selectedProvider: null,
59068
- error: null,
59069
- purchaseCurrency: USDC_CURRENCY_DEFAULT,
59070
- paymentCurrency: USD_CURRENCY_DEFAULT,
59071
- purchaseCurrencies: [USDC_CURRENCY_DEFAULT],
59072
- paymentCurrencies: [],
59073
- quotesLoading: false
59074
- };
59075
- const state$6 = proxy(defaultState);
59076
- const OnRampController = {
59077
- state: state$6,
59078
- subscribe(callback) {
59079
- return subscribe(state$6, () => callback(state$6));
59080
- },
59081
- subscribeKey(key2, callback) {
59082
- return subscribeKey(state$6, key2, callback);
59083
- },
59084
- setSelectedProvider(provider) {
59085
- if (provider && provider.name === "meld") {
59086
- const pubKey = process$1.env["NODE_ENV"] === "production" ? MELD_PROD_PUBLIC_KEY : MELD_DEV_PUBLIC_KEY;
59087
- const currency = ChainController.state.activeChain === ConstantsUtil$3.CHAIN.SOLANA ? "SOL" : "USDC";
59088
- const address = AccountController.state.address ?? "";
59089
- const url = new URL(provider.url);
59090
- url.searchParams.append("publicKey", pubKey);
59091
- url.searchParams.append("destinationCurrencyCode", currency);
59092
- url.searchParams.append("walletAddress", address);
59093
- provider.url = url.toString();
59094
- }
59095
- state$6.selectedProvider = provider;
59096
- },
59097
- setPurchaseCurrency(currency) {
59098
- state$6.purchaseCurrency = currency;
59099
- },
59100
- setPaymentCurrency(currency) {
59101
- state$6.paymentCurrency = currency;
59102
- },
59103
- setPurchaseAmount(amount) {
59104
- this.state.purchaseAmount = amount;
59105
- },
59106
- setPaymentAmount(amount) {
59107
- this.state.paymentAmount = amount;
59108
- },
59109
- async getAvailableCurrencies() {
59110
- const options = await BlockchainApiController.getOnrampOptions();
59111
- state$6.purchaseCurrencies = options.purchaseCurrencies;
59112
- state$6.paymentCurrencies = options.paymentCurrencies;
59113
- state$6.paymentCurrency = options.paymentCurrencies[0] || USD_CURRENCY_DEFAULT;
59114
- state$6.purchaseCurrency = options.purchaseCurrencies[0] || USDC_CURRENCY_DEFAULT;
59115
- await ApiController.fetchCurrencyImages(options.paymentCurrencies.map((currency) => currency.id));
59116
- await ApiController.fetchTokenImages(options.purchaseCurrencies.map((currency) => currency.symbol));
59117
- },
59118
- async getQuote() {
59119
- var _a3, _b2;
59120
- state$6.quotesLoading = true;
59121
- try {
59122
- const quote = await BlockchainApiController.getOnrampQuote({
59123
- purchaseCurrency: state$6.purchaseCurrency,
59124
- paymentCurrency: state$6.paymentCurrency,
59125
- amount: ((_a3 = state$6.paymentAmount) == null ? void 0 : _a3.toString()) || "0",
59126
- network: (_b2 = state$6.purchaseCurrency) == null ? void 0 : _b2.symbol
59127
- });
59128
- state$6.quotesLoading = false;
59129
- state$6.purchaseAmount = Number(quote.purchaseAmount.amount);
59130
- return quote;
59131
- } catch (error) {
59132
- state$6.error = error.message;
59133
- state$6.quotesLoading = false;
59134
- return null;
59135
- } finally {
59136
- state$6.quotesLoading = false;
59137
- }
59138
- },
59139
- resetState() {
59140
- state$6.providers = ONRAMP_PROVIDERS;
59141
- state$6.selectedProvider = null;
59142
- state$6.error = null;
59143
- state$6.purchaseCurrency = USDC_CURRENCY_DEFAULT;
59144
- state$6.paymentCurrency = USD_CURRENCY_DEFAULT;
59145
- state$6.purchaseCurrencies = [USDC_CURRENCY_DEFAULT];
59146
- state$6.paymentCurrencies = [];
59147
- state$6.paymentAmount = void 0;
59148
- state$6.purchaseAmount = void 0;
59149
- state$6.quotesLoading = false;
59398
+ onConnect() {
59399
+ this.createProviders(), this.events.emit("connect", { session: this.session });
59150
59400
  }
59151
- };
59152
- const state$5 = proxy({
59153
- loading: false
59154
- });
59155
- const SendController = {
59156
- state: state$5,
59157
- subscribe(callback) {
59158
- return subscribe(state$5, () => callback(state$5));
59159
- },
59160
- subscribeKey(key2, callback) {
59161
- return subscribeKey(state$5, key2, callback);
59162
- },
59163
- setToken(token2) {
59164
- if (token2) {
59165
- state$5.token = ref$1(token2);
59166
- }
59167
- },
59168
- setTokenAmount(sendTokenAmount) {
59169
- state$5.sendTokenAmount = sendTokenAmount;
59170
- },
59171
- setReceiverAddress(receiverAddress) {
59172
- state$5.receiverAddress = receiverAddress;
59173
- },
59174
- setReceiverProfileImageUrl(receiverProfileImageUrl) {
59175
- state$5.receiverProfileImageUrl = receiverProfileImageUrl;
59176
- },
59177
- setReceiverProfileName(receiverProfileName) {
59178
- state$5.receiverProfileName = receiverProfileName;
59179
- },
59180
- setGasPrice(gasPrice) {
59181
- state$5.gasPrice = gasPrice;
59182
- },
59183
- setGasPriceInUsd(gasPriceInUSD) {
59184
- state$5.gasPriceInUSD = gasPriceInUSD;
59185
- },
59186
- setLoading(loading) {
59187
- state$5.loading = loading;
59401
+ async cleanup() {
59402
+ this.session = void 0, this.namespaces = void 0, this.optionalNamespaces = void 0, this.sessionProperties = void 0, this.persist("namespaces", void 0), this.persist("optionalNamespaces", void 0), this.persist("sessionProperties", void 0), await this.cleanupPendingPairings({ deletePairings: true });
59403
+ }
59404
+ persist(s2, i4) {
59405
+ this.client.core.storage.setItem(`${Sa}/${s2}`, i4);
59406
+ }
59407
+ async getFromStore(s2) {
59408
+ return await this.client.core.storage.getItem(`${Sa}/${s2}`);
59409
+ }
59410
+ }
59411
+ const Ev = dr;
59412
+ const SIWXUtil = {
59413
+ getSIWX() {
59414
+ return OptionsController.state.siwx;
59188
59415
  },
59189
- sendToken() {
59416
+ async initializeIfEnabled() {
59190
59417
  var _a3;
59191
- switch ((_a3 = ChainController.state.activeCaipNetwork) == null ? void 0 : _a3.chainNamespace) {
59192
- case "eip155":
59193
- this.sendEvmToken();
59194
- return;
59195
- case "solana":
59196
- this.sendSolanaToken();
59197
- return;
59198
- default:
59199
- throw new Error("Unsupported chain");
59418
+ const siwx = OptionsController.state.siwx;
59419
+ const caipAddress = ChainController.getActiveCaipAddress();
59420
+ if (!(siwx && caipAddress)) {
59421
+ return;
59200
59422
  }
59201
- },
59202
- sendEvmToken() {
59203
- var _a3, _b2, _c, _d, _e2;
59204
- if (((_a3 = this.state.token) == null ? void 0 : _a3.address) && this.state.sendTokenAmount && this.state.receiverAddress) {
59205
- EventsController.sendEvent({
59206
- type: "track",
59207
- event: "SEND_INITIATED",
59208
- properties: {
59209
- isSmartAccount: AccountController.state.preferredAccountType === W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
59210
- token: this.state.token.address,
59211
- amount: this.state.sendTokenAmount,
59212
- network: ((_b2 = ChainController.state.activeCaipNetwork) == null ? void 0 : _b2.caipNetworkId) || ""
59213
- }
59214
- });
59215
- this.sendERC20Token({
59216
- receiverAddress: this.state.receiverAddress,
59217
- tokenAddress: this.state.token.address,
59218
- sendTokenAmount: this.state.sendTokenAmount,
59219
- decimals: this.state.token.quantity.decimals
59423
+ const [namespace, chainId, address] = caipAddress.split(":");
59424
+ if (!ChainController.checkIfSupportedNetwork(namespace)) {
59425
+ return;
59426
+ }
59427
+ try {
59428
+ const sessions = await siwx.getSessions(`${namespace}:${chainId}`, address);
59429
+ if (sessions.length) {
59430
+ return;
59431
+ }
59432
+ await ModalController.open({
59433
+ view: "SIWXSignMessage"
59220
59434
  });
59221
- } else if (this.state.receiverAddress && this.state.sendTokenAmount && this.state.gasPrice && ((_c = this.state.token) == null ? void 0 : _c.quantity.decimals)) {
59435
+ } catch (error) {
59436
+ console.error("SIWXUtil:initializeIfEnabled", error);
59222
59437
  EventsController.sendEvent({
59223
59438
  type: "track",
59224
- event: "SEND_INITIATED",
59225
- properties: {
59226
- isSmartAccount: AccountController.state.preferredAccountType === W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
59227
- token: (_d = this.state.token) == null ? void 0 : _d.symbol,
59228
- amount: this.state.sendTokenAmount,
59229
- network: ((_e2 = ChainController.state.activeCaipNetwork) == null ? void 0 : _e2.caipNetworkId) || ""
59230
- }
59231
- });
59232
- this.sendNativeToken({
59233
- receiverAddress: this.state.receiverAddress,
59234
- sendTokenAmount: this.state.sendTokenAmount,
59235
- gasPrice: this.state.gasPrice,
59236
- decimals: this.state.token.quantity.decimals
59439
+ event: "SIWX_AUTH_ERROR",
59440
+ properties: this.getSIWXEventProperties()
59237
59441
  });
59442
+ await ((_a3 = ConnectionController._getClient()) == null ? void 0 : _a3.disconnect().catch(console.error));
59443
+ RouterController.reset("Connect");
59444
+ SnackController.showError("A problem occurred while trying initialize authentication");
59238
59445
  }
59239
59446
  },
59240
- async sendNativeToken(params) {
59241
- var _a3, _b2, _c, _d;
59242
- RouterController.pushTransactionStack({
59243
- view: "Account",
59244
- goBack: false
59245
- });
59246
- const to2 = params.receiverAddress;
59247
- const address = AccountController.state.address;
59248
- const value = ConnectionController.parseUnits(params.sendTokenAmount.toString(), Number(params.decimals));
59249
- const data2 = "0x";
59447
+ async requestSignMessage() {
59448
+ const siwx = OptionsController.state.siwx;
59449
+ const address = CoreHelperUtil.getPlainAddress(ChainController.getActiveCaipAddress());
59450
+ const network = ChainController.getActiveCaipNetwork();
59451
+ const client = ConnectionController._getClient();
59452
+ if (!siwx) {
59453
+ throw new Error("SIWX is not enabled");
59454
+ }
59455
+ if (!address) {
59456
+ throw new Error("No ActiveCaipAddress found");
59457
+ }
59458
+ if (!network) {
59459
+ throw new Error("No ActiveCaipNetwork or client found");
59460
+ }
59461
+ if (!client) {
59462
+ throw new Error("No ConnectionController client found");
59463
+ }
59250
59464
  try {
59251
- await ConnectionController.sendTransaction({
59252
- chainNamespace: "eip155",
59253
- to: to2,
59254
- address,
59255
- data: data2,
59256
- value: value ?? BigInt(0),
59257
- gasPrice: params.gasPrice
59465
+ const siwxMessage = await siwx.createMessage({
59466
+ chainId: network.caipNetworkId,
59467
+ accountAddress: address
59258
59468
  });
59259
- SnackController.showSuccess("Transaction started");
59469
+ const message = siwxMessage.toString();
59470
+ if (StorageUtil.getConnectedConnector() === "ID_AUTH") {
59471
+ RouterController.pushTransactionStack({
59472
+ view: null,
59473
+ goBack: false,
59474
+ replace: true
59475
+ });
59476
+ }
59477
+ const signature2 = await client.signMessage(message);
59478
+ await siwx.addSession({
59479
+ data: siwxMessage,
59480
+ message,
59481
+ signature: signature2
59482
+ });
59483
+ ModalController.close();
59260
59484
  EventsController.sendEvent({
59261
59485
  type: "track",
59262
- event: "SEND_SUCCESS",
59263
- properties: {
59264
- isSmartAccount: AccountController.state.preferredAccountType === W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
59265
- token: ((_a3 = this.state.token) == null ? void 0 : _a3.symbol) || "",
59266
- amount: params.sendTokenAmount,
59267
- network: ((_b2 = ChainController.state.activeCaipNetwork) == null ? void 0 : _b2.caipNetworkId) || ""
59268
- }
59486
+ event: "SIWX_AUTH_SUCCESS",
59487
+ properties: this.getSIWXEventProperties()
59269
59488
  });
59270
- this.resetSend();
59271
59489
  } catch (error) {
59490
+ const properties = this.getSIWXEventProperties();
59491
+ if (!ModalController.state.open || RouterController.state.view === "ApproveTransaction") {
59492
+ await ModalController.open({
59493
+ view: "SIWXSignMessage"
59494
+ });
59495
+ }
59496
+ if (properties.isSmartAccount) {
59497
+ SnackController.showError("This application might not support Smart Accounts");
59498
+ } else {
59499
+ SnackController.showError("Signature declined");
59500
+ }
59272
59501
  EventsController.sendEvent({
59273
59502
  type: "track",
59274
- event: "SEND_ERROR",
59275
- properties: {
59276
- isSmartAccount: AccountController.state.preferredAccountType === W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
59277
- token: ((_c = this.state.token) == null ? void 0 : _c.symbol) || "",
59278
- amount: params.sendTokenAmount,
59279
- network: ((_d = ChainController.state.activeCaipNetwork) == null ? void 0 : _d.caipNetworkId) || ""
59280
- }
59503
+ event: "SIWX_AUTH_ERROR",
59504
+ properties
59281
59505
  });
59282
- SnackController.showError("Something went wrong");
59506
+ console.error("SWIXUtil:requestSignMessage", error);
59283
59507
  }
59284
59508
  },
59285
- async sendERC20Token(params) {
59286
- RouterController.pushTransactionStack({
59287
- view: "Account",
59288
- goBack: false
59289
- });
59290
- const amount = ConnectionController.parseUnits(params.sendTokenAmount.toString(), Number(params.decimals));
59509
+ async cancelSignMessage() {
59291
59510
  try {
59292
- if (AccountController.state.address && params.sendTokenAmount && params.receiverAddress && params.tokenAddress) {
59293
- const tokenAddress = CoreHelperUtil.getPlainAddress(params.tokenAddress);
59294
- await ConnectionController.writeContract({
59295
- fromAddress: AccountController.state.address,
59296
- tokenAddress,
59297
- receiverAddress: params.receiverAddress,
59298
- tokenAmount: amount ?? BigInt(0),
59299
- method: "transfer",
59300
- abi: ContractUtil.getERC20Abi(tokenAddress)
59301
- });
59302
- SnackController.showSuccess("Transaction started");
59303
- this.resetSend();
59304
- }
59511
+ await ConnectionController.disconnect();
59512
+ RouterController.reset("Connect");
59513
+ EventsController.sendEvent({
59514
+ event: "CLICK_CANCEL_SIWX",
59515
+ type: "track",
59516
+ properties: this.getSIWXEventProperties()
59517
+ });
59305
59518
  } catch (error) {
59306
- SnackController.showError("Something went wrong");
59519
+ console.error("SIWXUtil:cancelSignMessage", error);
59307
59520
  }
59308
59521
  },
59309
- sendSolanaToken() {
59310
- if (!this.state.sendTokenAmount || !this.state.receiverAddress) {
59311
- SnackController.showError("Please enter a valid amount and receiver address");
59312
- return;
59522
+ async getSessions() {
59523
+ const siwx = OptionsController.state.siwx;
59524
+ const address = CoreHelperUtil.getPlainAddress(ChainController.getActiveCaipAddress());
59525
+ const network = ChainController.getActiveCaipNetwork();
59526
+ if (!(siwx && address && network)) {
59527
+ return [];
59313
59528
  }
59314
- RouterController.pushTransactionStack({
59315
- view: "Account",
59316
- goBack: false
59317
- });
59318
- ConnectionController.sendTransaction({
59319
- chainNamespace: "solana",
59320
- to: this.state.receiverAddress,
59321
- value: this.state.sendTokenAmount
59322
- }).then(() => {
59323
- this.resetSend();
59324
- AccountController.fetchTokenBalance();
59325
- }).catch((error) => {
59326
- SnackController.showError("Failed to send transaction. Please try again.");
59327
- console.error("SendController:sendToken - failed to send solana transaction", error);
59328
- });
59329
- },
59330
- resetSend() {
59331
- state$5.token = void 0;
59332
- state$5.sendTokenAmount = void 0;
59333
- state$5.receiverAddress = void 0;
59334
- state$5.receiverProfileImageUrl = void 0;
59335
- state$5.receiverProfileName = void 0;
59336
- state$5.loading = false;
59337
- }
59338
- };
59339
- const state$4 = proxy({
59340
- message: "",
59341
- open: false,
59342
- triggerRect: {
59343
- width: 0,
59344
- height: 0,
59345
- top: 0,
59346
- left: 0
59347
- },
59348
- variant: "shade"
59349
- });
59350
- const TooltipController = {
59351
- state: state$4,
59352
- subscribe(callback) {
59353
- return subscribe(state$4, () => callback(state$4));
59354
- },
59355
- subscribeKey(key2, callback) {
59356
- return subscribeKey(state$4, key2, callback);
59357
- },
59358
- showTooltip({ message, triggerRect, variant }) {
59359
- state$4.open = true;
59360
- state$4.message = message;
59361
- state$4.triggerRect = triggerRect;
59362
- state$4.variant = variant;
59529
+ return siwx.getSessions(network.caipNetworkId, address);
59363
59530
  },
59364
- hide() {
59365
- state$4.open = false;
59366
- state$4.message = "";
59367
- state$4.triggerRect = {
59368
- width: 0,
59369
- height: 0,
59370
- top: 0,
59371
- left: 0
59372
- };
59373
- }
59374
- };
59375
- const SLIP44_MSB = 2147483648;
59376
- const EnsUtil = {
59377
- convertEVMChainIdToCoinType(chainId) {
59378
- if (chainId >= SLIP44_MSB) {
59379
- throw new Error("Invalid chainId");
59531
+ async isSIWXCloseDisabled() {
59532
+ const siwx = this.getSIWX();
59533
+ if (siwx) {
59534
+ const isApproveSignScreen = RouterController.state.view === "ApproveTransaction";
59535
+ const isSiwxSignMessage = RouterController.state.view === "SIWXSignMessage";
59536
+ if (isApproveSignScreen || isSiwxSignMessage) {
59537
+ return (await this.getSessions()).length === 0;
59538
+ }
59380
59539
  }
59381
- return (SLIP44_MSB | chainId) >>> 0;
59382
- }
59383
- };
59384
- const state$3 = proxy({
59385
- suggestions: [],
59386
- loading: false
59387
- });
59388
- const EnsController = {
59389
- state: state$3,
59390
- subscribe(callback) {
59391
- return subscribe(state$3, () => callback(state$3));
59392
- },
59393
- subscribeKey(key2, callback) {
59394
- return subscribeKey(state$3, key2, callback);
59540
+ return false;
59395
59541
  },
59396
- async resolveName(name2) {
59542
+ async universalProviderAuthenticate({ universalProvider, chains, methods }) {
59397
59543
  var _a3, _b2;
59398
- try {
59399
- return await BlockchainApiController.lookupEnsName(name2);
59400
- } catch (e3) {
59401
- const error = e3;
59402
- throw new Error(((_b2 = (_a3 = error == null ? void 0 : error.reasons) == null ? void 0 : _a3[0]) == null ? void 0 : _b2.description) || "Error resolving name");
59403
- }
59404
- },
59405
- async isNameRegistered(name2) {
59406
- try {
59407
- await BlockchainApiController.lookupEnsName(name2);
59408
- return true;
59409
- } catch {
59544
+ const siwx = SIWXUtil.getSIWX();
59545
+ const namespaces = new Set(chains.map((chain) => chain.split(":")[0]));
59546
+ if (!siwx || namespaces.size !== 1) {
59410
59547
  return false;
59411
59548
  }
59412
- },
59413
- async getSuggestions(value) {
59414
- try {
59415
- state$3.loading = true;
59416
- state$3.suggestions = [];
59417
- const response = await BlockchainApiController.getEnsNameSuggestions(value);
59418
- state$3.suggestions = response.suggestions.map((suggestion) => ({
59419
- ...suggestion,
59420
- name: suggestion.name
59421
- })) || [];
59422
- return state$3.suggestions;
59423
- } catch (e3) {
59424
- const errorMessage = this.parseEnsApiError(e3, "Error fetching name suggestions");
59425
- throw new Error(errorMessage);
59426
- } finally {
59427
- state$3.loading = false;
59428
- }
59429
- },
59430
- async getNamesForAddress(address) {
59431
- try {
59432
- const network = ChainController.state.activeCaipNetwork;
59433
- if (!network) {
59434
- return [];
59435
- }
59436
- const response = await BlockchainApiController.reverseLookupEnsName({ address });
59437
- return response;
59438
- } catch (e3) {
59439
- const errorMessage = this.parseEnsApiError(e3, "Error fetching names for address");
59440
- throw new Error(errorMessage);
59441
- }
59442
- },
59443
- async registerName(name2) {
59444
- const network = ChainController.state.activeCaipNetwork;
59445
- if (!network) {
59446
- throw new Error("Network not found");
59447
- }
59448
- const address = AccountController.state.address;
59449
- const emailConnector = ConnectorController.getAuthConnector();
59450
- if (!address || !emailConnector) {
59451
- throw new Error("Address or auth connector not found");
59452
- }
59453
- state$3.loading = true;
59454
- try {
59455
- const message = JSON.stringify({
59456
- name: name2,
59457
- attributes: {},
59458
- // Unix timestamp
59459
- timestamp: Math.floor(Date.now() / 1e3)
59460
- });
59461
- RouterController.pushTransactionStack({
59462
- view: "RegisterAccountNameSuccess",
59463
- goBack: false,
59464
- replace: true,
59465
- onCancel() {
59466
- state$3.loading = false;
59467
- }
59549
+ const siwxMessage = await siwx.createMessage({
59550
+ chainId: ((_a3 = ChainController.getActiveCaipNetwork()) == null ? void 0 : _a3.caipNetworkId) || "",
59551
+ accountAddress: ""
59552
+ });
59553
+ const result = await universalProvider.authenticate({
59554
+ nonce: siwxMessage.nonce,
59555
+ domain: siwxMessage.domain,
59556
+ uri: siwxMessage.uri,
59557
+ exp: siwxMessage.expirationTime,
59558
+ iat: siwxMessage.issuedAt,
59559
+ nbf: siwxMessage.notBefore,
59560
+ requestId: siwxMessage.requestId,
59561
+ version: siwxMessage.version,
59562
+ resources: siwxMessage.resources,
59563
+ statement: siwxMessage.statement,
59564
+ chainId: siwxMessage.chainId,
59565
+ methods,
59566
+ chains
59567
+ });
59568
+ if ((_b2 = result == null ? void 0 : result.auths) == null ? void 0 : _b2.length) {
59569
+ const sessions = result.auths.map((cacao) => {
59570
+ const message = universalProvider.client.formatAuthMessage({
59571
+ request: cacao.p,
59572
+ iss: cacao.p.iss
59573
+ });
59574
+ return {
59575
+ data: {
59576
+ ...cacao.p,
59577
+ accountAddress: cacao.p.iss.split(":").slice(-1).join(""),
59578
+ chainId: cacao.p.iss.split(":").slice(2, 4).join(":"),
59579
+ uri: cacao.p.aud,
59580
+ version: cacao.p.version || siwxMessage.version,
59581
+ expirationTime: cacao.p.exp,
59582
+ issuedAt: cacao.p.iat,
59583
+ notBefore: cacao.p.nbf
59584
+ },
59585
+ message,
59586
+ signature: cacao.s.s,
59587
+ cacao
59588
+ };
59468
59589
  });
59469
- const signature2 = await ConnectionController.signMessage(message);
59470
- const networkId = network.id;
59471
- if (!networkId) {
59472
- throw new Error("Network not found");
59590
+ try {
59591
+ await siwx.setSessions(sessions);
59592
+ EventsController.sendEvent({
59593
+ type: "track",
59594
+ event: "SIWX_AUTH_SUCCESS",
59595
+ properties: SIWXUtil.getSIWXEventProperties()
59596
+ });
59597
+ } catch (error) {
59598
+ console.error("SIWX:universalProviderAuth - failed to set sessions", error);
59599
+ EventsController.sendEvent({
59600
+ type: "track",
59601
+ event: "SIWX_AUTH_ERROR",
59602
+ properties: SIWXUtil.getSIWXEventProperties()
59603
+ });
59604
+ await universalProvider.disconnect().catch(console.error);
59605
+ throw error;
59473
59606
  }
59474
- const coinType = EnsUtil.convertEVMChainIdToCoinType(Number(networkId));
59475
- await BlockchainApiController.registerEnsName({
59476
- coinType,
59477
- address,
59478
- signature: signature2,
59479
- message
59480
- });
59481
- AccountController.setProfileName(name2, network.chainNamespace);
59482
- RouterController.replace("RegisterAccountNameSuccess");
59483
- } catch (e3) {
59484
- const errorMessage = this.parseEnsApiError(e3, `Error registering name ${name2}`);
59485
- RouterController.replace("RegisterAccountName");
59486
- throw new Error(errorMessage);
59487
- } finally {
59488
- state$3.loading = false;
59489
- }
59490
- },
59491
- validateName(name2) {
59492
- return /^[a-zA-Z0-9-]{4,}$/u.test(name2);
59493
- },
59494
- parseEnsApiError(error, defaultError) {
59495
- var _a3, _b2;
59496
- const ensError = error;
59497
- return ((_b2 = (_a3 = ensError == null ? void 0 : ensError.reasons) == null ? void 0 : _a3[0]) == null ? void 0 : _b2.description) || defaultError;
59498
- }
59499
- };
59500
- const state$2 = proxy({
59501
- message: "",
59502
- variant: "info",
59503
- open: false
59504
- });
59505
- const AlertController = {
59506
- state: state$2,
59507
- subscribeKey(key2, callback) {
59508
- return subscribeKey(state$2, key2, callback);
59509
- },
59510
- open(message, variant) {
59511
- const { debug } = OptionsController.state;
59512
- const { shortMessage, longMessage } = message;
59513
- if (debug) {
59514
- state$2.message = shortMessage;
59515
- state$2.variant = variant;
59516
- state$2.open = true;
59517
- }
59518
- if (longMessage) {
59519
- console.error(typeof longMessage === "function" ? longMessage() : longMessage);
59520
- }
59521
- },
59522
- close() {
59523
- state$2.open = false;
59524
- state$2.message = "";
59525
- state$2.variant = "info";
59526
- }
59527
- };
59528
- const namespaceImageIds = {
59529
- // Ethereum
59530
- eip155: "ba0ba0cd-17c6-4806-ad93-f9d174f17900",
59531
- // Solana
59532
- solana: "a1b58899-f671-4276-6a5e-56ca5bd59700",
59533
- // Polkadot
59534
- polkadot: "",
59535
- // Bitcoin
59536
- bip122: ""
59537
- };
59538
- const AssetUtil = {
59539
- async fetchWalletImage(imageId) {
59540
- if (!imageId) {
59541
- return void 0;
59542
- }
59543
- await ApiController._fetchWalletImage(imageId);
59544
- return this.getWalletImageById(imageId);
59545
- },
59546
- getWalletImageById(imageId) {
59547
- if (!imageId) {
59548
- return void 0;
59549
- }
59550
- return AssetController.state.walletImages[imageId];
59551
- },
59552
- getWalletImage(wallet) {
59553
- if (wallet == null ? void 0 : wallet.image_url) {
59554
- return wallet == null ? void 0 : wallet.image_url;
59555
- }
59556
- if (wallet == null ? void 0 : wallet.image_id) {
59557
- return AssetController.state.walletImages[wallet.image_id];
59558
- }
59559
- return void 0;
59560
- },
59561
- getNetworkImage(network) {
59562
- var _a3, _b2, _c;
59563
- if ((_a3 = network == null ? void 0 : network.assets) == null ? void 0 : _a3.imageUrl) {
59564
- return (_b2 = network == null ? void 0 : network.assets) == null ? void 0 : _b2.imageUrl;
59565
- }
59566
- if ((_c = network == null ? void 0 : network.assets) == null ? void 0 : _c.imageId) {
59567
- return AssetController.state.networkImages[network.assets.imageId];
59568
- }
59569
- return void 0;
59570
- },
59571
- getNetworkImageById(imageId) {
59572
- if (!imageId) {
59573
- return void 0;
59574
- }
59575
- return AssetController.state.networkImages[imageId];
59576
- },
59577
- getConnectorImage(connector) {
59578
- if (connector == null ? void 0 : connector.imageUrl) {
59579
- return connector.imageUrl;
59580
- }
59581
- if (connector == null ? void 0 : connector.imageId) {
59582
- return AssetController.state.connectorImages[connector.imageId];
59583
59607
  }
59584
- return void 0;
59608
+ return true;
59585
59609
  },
59586
- getChainImage(chain) {
59587
- return AssetController.state.networkImages[namespaceImageIds[chain]];
59610
+ getSIWXEventProperties() {
59611
+ var _a3;
59612
+ return {
59613
+ network: ((_a3 = ChainController.state.activeCaipNetwork) == null ? void 0 : _a3.caipNetworkId) || "",
59614
+ isSmartAccount: AccountController.state.preferredAccountType === W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT
59615
+ };
59588
59616
  }
59589
59617
  };
59590
59618
  /**
@@ -78637,7 +78665,7 @@ async function call$2(client, args) {
78637
78665
  return { data: response };
78638
78666
  } catch (err) {
78639
78667
  const data3 = getRevertErrorData$1(err);
78640
- const { offchainLookup: offchainLookup2, offchainLookupSignature: offchainLookupSignature2 } = await import("./ccip-zsB2BkYF.js");
78668
+ const { offchainLookup: offchainLookup2, offchainLookupSignature: offchainLookupSignature2 } = await import("./ccip-oJ7D52h2.js");
78641
78669
  if (client.ccipRead !== false && (data3 == null ? void 0 : data3.slice(0, 10)) === offchainLookupSignature2 && to2)
78642
78670
  return { data: await offchainLookup2(client, { data: data3, to: to2 }) };
78643
78671
  if (deploylessCall && (data3 == null ? void 0 : data3.slice(0, 10)) === "0x101bb98d")
@@ -82876,6 +82904,9 @@ class AdapterBlueprint {
82876
82904
  return true;
82877
82905
  });
82878
82906
  }
82907
+ setStatus(status, chainNamespace) {
82908
+ AccountController.setStatus(status, chainNamespace);
82909
+ }
82879
82910
  /**
82880
82911
  * Adds an event listener for a specific event.
82881
82912
  * @template T
@@ -93413,6 +93444,20 @@ const bitcoin = defineChain$1({
93413
93444
  default: { http: ["https://rpc.walletconnect.org/v1"] }
93414
93445
  }
93415
93446
  });
93447
+ const bitcoinTestnet = defineChain$1({
93448
+ id: "000000000933ea01ad0ee984209779ba",
93449
+ caipNetworkId: "bip122:000000000933ea01ad0ee984209779ba",
93450
+ chainNamespace: "bip122",
93451
+ name: "Bitcoin Testnet",
93452
+ nativeCurrency: {
93453
+ name: "Bitcoin",
93454
+ symbol: "BTC",
93455
+ decimals: 8
93456
+ },
93457
+ rpcUrls: {
93458
+ default: { http: ["https://rpc.walletconnect.org/v1"] }
93459
+ }
93460
+ });
93416
93461
  const WcHelpersUtil = {
93417
93462
  getMethodsByChainNamespace(chainNamespace) {
93418
93463
  switch (chainNamespace) {
@@ -93853,6 +93898,7 @@ class AppKit {
93853
93898
  this.chainNamespaces = [];
93854
93899
  this.initPromise = void 0;
93855
93900
  this.setStatus = (status, chain) => {
93901
+ StorageUtil.setConnectionStatus(status);
93856
93902
  AccountController.setStatus(status, chain);
93857
93903
  };
93858
93904
  this.getIsConnectedState = () => Boolean(ChainController.state.activeCaipAddress);
@@ -94172,7 +94218,7 @@ class AppKit {
94172
94218
  if (options.siwx) {
94173
94219
  throw new Error("Cannot set both `siweConfig` and `siwx` options");
94174
94220
  }
94175
- const siwe = await import("./index-CddnljwX.js");
94221
+ const siwe = await import("./index-CRnsv5ja.js");
94176
94222
  if (typeof siwe.mapToSIWX !== "function") {
94177
94223
  throw new Error("Please update the `@reown/appkit-siwe` package to the latest version");
94178
94224
  }
@@ -94192,6 +94238,27 @@ class AppKit {
94192
94238
  }
94193
94239
  return null;
94194
94240
  }
94241
+ setUnsupportedNetwork(chainId) {
94242
+ const namespace = this.getActiveChainNamespace();
94243
+ if (namespace) {
94244
+ ChainController.setActiveCaipNetwork({
94245
+ id: chainId,
94246
+ caipNetworkId: `${namespace}:${chainId}`,
94247
+ name: "Unknown Network",
94248
+ chainNamespace: namespace,
94249
+ nativeCurrency: {
94250
+ name: "",
94251
+ decimals: 0,
94252
+ symbol: ""
94253
+ },
94254
+ rpcUrls: {
94255
+ default: {
94256
+ http: []
94257
+ }
94258
+ }
94259
+ });
94260
+ }
94261
+ }
94195
94262
  extendCaipNetworks(options) {
94196
94263
  const extendedNetworks = CaipNetworksUtil.extendCaipNetworks(options.networks, {
94197
94264
  customNetworkImageUrls: options.chainImages,
@@ -94263,7 +94330,9 @@ class AppKit {
94263
94330
  });
94264
94331
  }
94265
94332
  if (!((_j = this.caipNetworks) == null ? void 0 : _j.some((network) => network.id === (res == null ? void 0 : res.chainId)))) {
94266
- ChainController.showUnsupportedChainUI();
94333
+ if (res == null ? void 0 : res.chainId) {
94334
+ this.setUnsupportedNetwork(res.chainId);
94335
+ }
94267
94336
  }
94268
94337
  },
94269
94338
  reconnectExternal: async ({ id, info, type: type2, provider }) => {
@@ -94403,15 +94472,15 @@ class AppKit {
94403
94472
  });
94404
94473
  } else if (AccountController.state.address) {
94405
94474
  const providerType = ProviderUtil.state.providerIds[ChainController.state.activeChain];
94406
- if (providerType === "AUTH") {
94475
+ if (providerType === ConstantsUtil$1.CONNECTOR_TYPE_AUTH) {
94407
94476
  try {
94408
94477
  ChainController.state.activeChain = caipNetwork.chainNamespace;
94409
94478
  await ((_c = (_b2 = this.connectionControllerClient) == null ? void 0 : _b2.connectExternal) == null ? void 0 : _c.call(_b2, {
94410
- id: "ID_AUTH",
94479
+ id: ConstantsUtil$1.AUTH_CONNECTOR_ID,
94411
94480
  provider: this.authProvider,
94412
94481
  chain: caipNetwork.chainNamespace,
94413
94482
  chainId: caipNetwork.id,
94414
- type: "AUTH",
94483
+ type: ConstantsUtil$1.CONNECTOR_TYPE_AUTH,
94415
94484
  caipNetwork
94416
94485
  }));
94417
94486
  } catch (error) {
@@ -94442,12 +94511,17 @@ class AppKit {
94442
94511
  },
94443
94512
  // eslint-disable-next-line @typescript-eslint/require-await
94444
94513
  getApprovedCaipNetworksData: async () => {
94445
- var _a3, _b2;
94514
+ var _a3, _b2, _c, _d, _e2;
94446
94515
  const providerType = ProviderUtil.state.providerIds[ChainController.state.activeChain];
94447
94516
  if (providerType === ConstantsUtil$1.CONNECTOR_TYPE_WALLET_CONNECT) {
94448
94517
  const namespaces = (_b2 = (_a3 = this.universalProvider) == null ? void 0 : _a3.session) == null ? void 0 : _b2.namespaces;
94449
94518
  return {
94450
- supportsAllNetworks: false,
94519
+ /*
94520
+ * MetaMask Wallet only returns 1 namespace in the session object. This makes it imposible
94521
+ * to switch to other networks. Setting supportsAllNetworks to true for MetaMask Wallet
94522
+ * will make it possible to switch to other networks.
94523
+ */
94524
+ supportsAllNetworks: ((_e2 = (_d = (_c = this.universalProvider) == null ? void 0 : _c.session) == null ? void 0 : _d.peer) == null ? void 0 : _e2.metadata.name) === "MetaMask Wallet",
94451
94525
  approvedCaipNetworkIds: this.getChainsFromNamespaces(namespaces)
94452
94526
  };
94453
94527
  }
@@ -94467,20 +94541,10 @@ class AppKit {
94467
94541
  this.setLoading(true);
94468
94542
  const isLoginEmailUsed = provider.getLoginEmailUsed();
94469
94543
  this.setLoading(isLoginEmailUsed);
94470
- const { isConnected } = await provider.isConnected();
94471
- if (isConnected && ((_a3 = this.connectionControllerClient) == null ? void 0 : _a3.connectExternal)) {
94472
- (_c = this.connectionControllerClient) == null ? void 0 : _c.connectExternal({
94473
- id: "ID_AUTH",
94474
- info: {
94475
- name: "ID_AUTH"
94476
- },
94477
- type: "AUTH",
94478
- provider,
94479
- chainId: (_b2 = ChainController.state.activeCaipNetwork) == null ? void 0 : _b2.id
94480
- });
94481
- } else {
94482
- this.setLoading(false);
94544
+ if (isLoginEmailUsed) {
94545
+ this.setStatus("connecting", ChainController.state.activeChain);
94483
94546
  }
94547
+ const { isConnected } = await provider.isConnected();
94484
94548
  provider.onRpcRequest((request) => {
94485
94549
  if (W3mFrameHelpers.checkIfRequestExists(request)) {
94486
94550
  if (!W3mFrameHelpers.checkIfRequestIsSafe(request)) {
@@ -94520,7 +94584,7 @@ class AppKit {
94520
94584
  });
94521
94585
  provider.onNotConnected(() => {
94522
94586
  const connectedConnector = SafeLocalStorage.getItem(SafeLocalStorageKeys.CONNECTED_CONNECTOR);
94523
- const isConnectedWithAuth = connectedConnector === "ID_AUTH";
94587
+ const isConnectedWithAuth = connectedConnector === ConstantsUtil$1.AUTH_CONNECTOR_ID;
94524
94588
  if (!isConnected && isConnectedWithAuth) {
94525
94589
  this.setCaipAddress(void 0, ChainController.state.activeChain);
94526
94590
  this.setLoading(false);
@@ -94531,9 +94595,9 @@ class AppKit {
94531
94595
  });
94532
94596
  provider.onConnect(async (user) => {
94533
94597
  this.syncProvider({
94534
- type: "AUTH",
94598
+ type: ConstantsUtil$1.CONNECTOR_TYPE_AUTH,
94535
94599
  provider,
94536
- id: "ID_AUTH",
94600
+ id: ConstantsUtil$1.AUTH_CONNECTOR_ID,
94537
94601
  chainNamespace: ChainController.state.activeChain
94538
94602
  });
94539
94603
  const caipAddress = ChainController.state.activeChain === "eip155" ? `eip155:${user.chainId}:${user.address}` : `${user.chainId}:${user.address}`;
@@ -94558,6 +94622,20 @@ class AppKit {
94558
94622
  }
94559
94623
  this.setPreferredAccountType(type2, ChainController.state.activeChain);
94560
94624
  });
94625
+ if (isConnected && ((_a3 = this.connectionControllerClient) == null ? void 0 : _a3.connectExternal)) {
94626
+ await ((_c = this.connectionControllerClient) == null ? void 0 : _c.connectExternal({
94627
+ id: ConstantsUtil$1.AUTH_CONNECTOR_ID,
94628
+ info: { name: ConstantsUtil$1.AUTH_CONNECTOR_ID },
94629
+ type: ConstantsUtil$1.CONNECTOR_TYPE_AUTH,
94630
+ provider,
94631
+ chainId: (_b2 = ChainController.state.activeCaipNetwork) == null ? void 0 : _b2.id
94632
+ }));
94633
+ this.setLoading(false);
94634
+ this.setStatus("connected", ChainController.state.activeChain);
94635
+ } else {
94636
+ this.setLoading(false);
94637
+ this.setStatus("disconnected", ChainController.state.activeChain);
94638
+ }
94561
94639
  }
94562
94640
  listenWalletConnect() {
94563
94641
  if (this.universalProvider) {
@@ -94575,23 +94653,7 @@ class AppKit {
94575
94653
  );
94576
94654
  const currentCaipNetwork = this.getCaipNetwork();
94577
94655
  if (!caipNetwork) {
94578
- const namespace = this.getActiveChainNamespace() || ConstantsUtil$3.CHAIN.EVM;
94579
- ChainController.setActiveCaipNetwork({
94580
- id: chainId,
94581
- caipNetworkId: `${namespace}:${chainId}`,
94582
- name: "Unknown Network",
94583
- chainNamespace: namespace,
94584
- nativeCurrency: {
94585
- name: "",
94586
- decimals: 0,
94587
- symbol: ""
94588
- },
94589
- rpcUrls: {
94590
- default: {
94591
- http: []
94592
- }
94593
- }
94594
- });
94656
+ this.setUnsupportedNetwork(chainId);
94595
94657
  return;
94596
94658
  }
94597
94659
  if (!currentCaipNetwork || (currentCaipNetwork == null ? void 0 : currentCaipNetwork.id) !== (caipNetwork == null ? void 0 : caipNetwork.id)) {
@@ -94602,6 +94664,12 @@ class AppKit {
94602
94664
  }
94603
94665
  listenAdapter(chainNamespace) {
94604
94666
  const adapter = this.getAdapter(chainNamespace);
94667
+ const connectionStatus = StorageUtil.getConnectionStatus();
94668
+ if (connectionStatus === "connected") {
94669
+ this.setStatus("connecting", chainNamespace);
94670
+ } else {
94671
+ this.setStatus(connectionStatus, chainNamespace);
94672
+ }
94605
94673
  adapter == null ? void 0 : adapter.on("switchNetwork", ({ address, chainId }) => {
94606
94674
  var _a3;
94607
94675
  if (chainId && ((_a3 = this.caipNetworks) == null ? void 0 : _a3.find((n6) => n6.id === chainId))) {
@@ -94615,7 +94683,7 @@ class AppKit {
94615
94683
  });
94616
94684
  }
94617
94685
  } else {
94618
- ChainController.showUnsupportedChainUI();
94686
+ this.setUnsupportedNetwork(chainId);
94619
94687
  }
94620
94688
  });
94621
94689
  adapter == null ? void 0 : adapter.on("disconnect", () => {
@@ -94834,6 +94902,7 @@ class AppKit {
94834
94902
  if (connectedConnector === ConstantsUtil$1.CONNECTOR_TYPE_WALLET_CONNECT && connectedNamespace) {
94835
94903
  this.syncWalletConnectAccount();
94836
94904
  } else if (connectedConnector && connectedConnector !== ConstantsUtil$1.CONNECTOR_TYPE_W3M_AUTH && connectedNamespace) {
94905
+ this.setStatus("connecting", connectedNamespace);
94837
94906
  const adapter = this.getAdapter(connectedNamespace);
94838
94907
  const res = await (adapter == null ? void 0 : adapter.syncConnection({
94839
94908
  id: connectedConnector,
@@ -94844,10 +94913,17 @@ class AppKit {
94844
94913
  if (res) {
94845
94914
  this.syncProvider({ ...res, chainNamespace: connectedNamespace });
94846
94915
  await this.syncAccount({ ...res, chainNamespace: connectedNamespace });
94916
+ this.setStatus("connected", connectedNamespace);
94917
+ } else {
94918
+ this.setStatus("disconnected", connectedNamespace);
94847
94919
  }
94848
94920
  if (!((_f2 = this.caipNetworks) == null ? void 0 : _f2.some((network) => network.id === (res == null ? void 0 : res.chainId)))) {
94849
- ChainController.showUnsupportedChainUI();
94921
+ if (res == null ? void 0 : res.chainId) {
94922
+ this.setUnsupportedNetwork(res.chainId);
94923
+ }
94850
94924
  }
94925
+ } else if (connectedConnector !== ConstantsUtil$1.CONNECTOR_TYPE_W3M_AUTH) {
94926
+ this.setStatus("disconnected", ChainController.state.activeChain);
94851
94927
  }
94852
94928
  }
94853
94929
  getAdapter(namespace) {
@@ -94968,8 +95044,8 @@ class AppKit {
94968
95044
  isInitialized = true;
94969
95045
  this.initPromise = new Promise(async (resolve) => {
94970
95046
  await Promise.all([
94971
- import("./index-DAGjeNF9.js"),
94972
- import("./w3m-modal-Cdt8C88F.js")
95047
+ import("./index-BCD-kidI.js"),
95048
+ import("./w3m-modal-CoAkKS0G.js")
94973
95049
  ]);
94974
95050
  const modal = document.createElement("w3m-modal");
94975
95051
  if (!OptionsController.state.disableAppend) {
@@ -94981,7 +95057,7 @@ class AppKit {
94981
95057
  return this.initPromise;
94982
95058
  }
94983
95059
  }
94984
- const PACKAGE_VERSION = "1.5.3-d55ad02.0";
95060
+ const PACKAGE_VERSION = "1.5.3";
94985
95061
  var __decorate$1J = function(decorators, target, key2, desc) {
94986
95062
  var c2 = arguments.length, r4 = c2 < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key2) : desc, d4;
94987
95063
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -101973,6 +102049,13 @@ let W3mConnectingSocialView = class W3mConnectingSocialView2 extends r$3 {
101973
102049
  this.connecting = true;
101974
102050
  this.updateMessage();
101975
102051
  const uri2 = event.data.resultUri;
102052
+ if (this.socialProvider) {
102053
+ EventsController.sendEvent({
102054
+ type: "track",
102055
+ event: "SOCIAL_LOGIN_REQUEST_USER_DATA",
102056
+ properties: { provider: this.socialProvider }
102057
+ });
102058
+ }
101976
102059
  await this.authConnector.provider.connectSocial(uri2);
101977
102060
  if (this.socialProvider) {
101978
102061
  StorageUtil.setConnectedSocialProvider(this.socialProvider);
@@ -102075,6 +102158,13 @@ let W3mConnectingSocialView = class W3mConnectingSocialView2 extends r$3 {
102075
102158
  var _a3;
102076
102159
  if ((_a3 = this.socialWindow) == null ? void 0 : _a3.closed) {
102077
102160
  if (!this.connecting && RouterController.state.view === "ConnectingSocial") {
102161
+ if (this.socialProvider) {
102162
+ EventsController.sendEvent({
102163
+ type: "track",
102164
+ event: "SOCIAL_LOGIN_CANCELED",
102165
+ properties: { provider: this.socialProvider }
102166
+ });
102167
+ }
102078
102168
  RouterController.goBack();
102079
102169
  }
102080
102170
  clearInterval(interval);
@@ -112022,7 +112112,7 @@ function version4$1(parameters) {
112022
112112
  async getProvider() {
112023
112113
  if (!walletProvider) {
112024
112114
  const CoinbaseWalletSDK = await (async () => {
112025
- const { default: SDK } = await import("./index-DHyiWE9V.js").then((n6) => n6.i);
112115
+ const { default: SDK } = await import("./index-t1a7ymTD.js").then((n6) => n6.i);
112026
112116
  if (typeof SDK !== "function" && typeof SDK.default === "function")
112027
112117
  return SDK.default;
112028
112118
  return SDK;
@@ -112201,7 +112291,7 @@ function version3$1(parameters) {
112201
112291
  var _a3;
112202
112292
  if (!walletProvider) {
112203
112293
  const CoinbaseWalletSDK = await (async () => {
112204
- const { default: SDK } = await import("./index-BYpF8N_A.js").then((n6) => n6.i);
112294
+ const { default: SDK } = await import("./index-CjymKZdr.js").then((n6) => n6.i);
112205
112295
  if (typeof SDK !== "function" && typeof SDK.default === "function")
112206
112296
  return SDK.default;
112207
112297
  return SDK;
@@ -124114,6 +124204,7 @@ const AppKitNetworks = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defi
124114
124204
  bitTorrent,
124115
124205
  bitTorrentTestnet,
124116
124206
  bitcoin,
124207
+ bitcoinTestnet,
124117
124208
  bitkub,
124118
124209
  bitkubTestnet,
124119
124210
  bitlayer,
@@ -133735,7 +133826,7 @@ async function getWebSocketRpcClient(url, options = {}) {
133735
133826
  const { keepAlive, reconnect: reconnect2 } = options;
133736
133827
  return getSocketRpcClient({
133737
133828
  async getSocket({ onClose, onError, onOpen, onResponse }) {
133738
- const WebSocket2 = await import("./native-ClayS85q.js").then((module) => module.WebSocket);
133829
+ const WebSocket2 = await import("./native-k0b2Co6F.js").then((module) => module.WebSocket);
133739
133830
  const socket = new WebSocket2(url);
133740
133831
  function onClose_() {
133741
133832
  onClose();
@@ -139871,7 +139962,7 @@ function version4(parameters) {
139871
139962
  async getProvider() {
139872
139963
  if (!walletProvider) {
139873
139964
  const CoinbaseWalletSDK = await (async () => {
139874
- const { default: SDK } = await import("./index-DHyiWE9V.js").then((n6) => n6.i);
139965
+ const { default: SDK } = await import("./index-t1a7ymTD.js").then((n6) => n6.i);
139875
139966
  if (typeof SDK !== "function" && typeof SDK.default === "function")
139876
139967
  return SDK.default;
139877
139968
  return SDK;
@@ -140050,7 +140141,7 @@ function version3(parameters) {
140050
140141
  var _a3;
140051
140142
  if (!walletProvider) {
140052
140143
  const CoinbaseWalletSDK = await (async () => {
140053
- const { default: SDK } = await import("./index-BYpF8N_A.js").then((n6) => n6.i);
140144
+ const { default: SDK } = await import("./index-CjymKZdr.js").then((n6) => n6.i);
140054
140145
  if (typeof SDK !== "function" && typeof SDK.default === "function")
140055
140146
  return SDK.default;
140056
140147
  return SDK;
@@ -140256,7 +140347,7 @@ function metaMask(parameters = {}) {
140256
140347
  async getProvider() {
140257
140348
  async function initProvider() {
140258
140349
  const MetaMaskSDK = await (async () => {
140259
- const { default: SDK } = await import("./metamask-sdk-DKgosmUG.js").then((n6) => n6.m);
140350
+ const { default: SDK } = await import("./metamask-sdk-B6ijR6YT.js").then((n6) => n6.m);
140260
140351
  if (typeof SDK !== "function" && typeof SDK.default === "function")
140261
140352
  return SDK.default;
140262
140353
  return SDK;
@@ -140487,14 +140578,14 @@ function safe(parameters = {}) {
140487
140578
  if (!isIframe)
140488
140579
  return;
140489
140580
  if (!provider_) {
140490
- const { default: SDK } = await import("./index-BxOGuMA7.js");
140581
+ const { default: SDK } = await import("./index-4BL-xvPV.js");
140491
140582
  const sdk = new SDK(parameters);
140492
140583
  const safe2 = await withTimeout(() => sdk.safe.getInfo(), {
140493
140584
  timeout: parameters.unstable_getInfoTimeout ?? 10
140494
140585
  });
140495
140586
  if (!safe2)
140496
140587
  throw new Error("Could not load Safe information");
140497
- const { SafeAppProvider } = await import("./index-CFRZcZYC.js").then((n6) => n6.i);
140588
+ const { SafeAppProvider } = await import("./index-DWlvgckp.js").then((n6) => n6.i);
140498
140589
  provider_ = new SafeAppProvider(safe2, sdk);
140499
140590
  }
140500
140591
  return provider_;
@@ -140663,7 +140754,7 @@ function walletConnect(parameters) {
140663
140754
  const optionalChains = config2.chains.map((x3) => x3.id);
140664
140755
  if (!optionalChains.length)
140665
140756
  return;
140666
- const { EthereumProvider } = await import("./index.es-DWLMeaKr.js");
140757
+ const { EthereumProvider } = await import("./index.es-DznsrD1v.js");
140667
140758
  return await EthereumProvider.init({
140668
140759
  ...parameters,
140669
140760
  disableProviderPing: true,
@@ -141047,4 +141138,4 @@ export {
141047
141138
  WuiShimmer as y,
141048
141139
  WuiText as z
141049
141140
  };
141050
- //# sourceMappingURL=appkit-DzvwQvlf.js.map
141141
+ //# sourceMappingURL=appkit-DzmuJOIk.js.map