@sodax/wallet-sdk-react 0.0.1-rc.5 → 0.0.1-rc.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,11 +1,11 @@
1
+ import { baseChainInfo } from '@sodax/types';
1
2
  import { erc20Abi, defineChain } from 'viem';
2
- import { getPublicClient, getWalletClient } from 'wagmi/actions';
3
- import { http, createConfig, useConnections, useAccount, useConnect, useConnectors, useDisconnect, usePublicClient, useWalletClient, useSwitchChain, WagmiProvider } from 'wagmi';
4
- import { mainnet, lightlinkPhoenix, nibiru as nibiru$1, polygon as polygon$1, optimism as optimism$1, sonic as sonic$1, bsc as bsc$1, base as base$1, arbitrum as arbitrum$1, avalanche as avalanche$1 } from 'wagmi/chains';
5
- import { LIGHTLINK_MAINNET_CHAIN_ID, HYPEREVM_MAINNET_CHAIN_ID, NIBIRU_MAINNET_CHAIN_ID, POLYGON_MAINNET_CHAIN_ID, OPTIMISM_MAINNET_CHAIN_ID, SONIC_MAINNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, BASE_MAINNET_CHAIN_ID, ARBITRUM_MAINNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID } from '@sodax/types';
3
+ import { getPublicClient } from 'wagmi/actions';
4
+ import { useConnections, useAccount, useConnect, useConnectors, useDisconnect, useSwitchChain, usePublicClient, useWalletClient, useSignMessage, WagmiProvider, createConfig, http, useConfig } from 'wagmi';
5
+ import { mainnet, avalanche, arbitrum, base, bsc, sonic, optimism, polygon, nibiru, lightlinkPhoenix } from 'wagmi/chains';
6
6
  import * as IconSdkRaw from 'icon-sdk-js';
7
7
  import { getNetworkEndpoints, Network } from '@injectivelabs/networks';
8
- import { IndexerGrpcAccountPortfolioApi, ChainGrpcWasmApi, getInjectiveAddress } from '@injectivelabs/sdk-ts';
8
+ import { IndexerGrpcAccountPortfolioApi, ChainGrpcWasmApi, getInjectiveAddress, getEthereumAddress } from '@injectivelabs/sdk-ts';
9
9
  import { ChainId } from '@injectivelabs/ts-types';
10
10
  import { MsgBroadcaster } from '@injectivelabs/wallet-core';
11
11
  import { WalletStrategy } from '@injectivelabs/wallet-strategy';
@@ -13,153 +13,28 @@ import { Wallet, isEvmBrowserWallet } from '@injectivelabs/wallet-base';
13
13
  import { isCosmosWalletInstalled } from '@injectivelabs/wallet-cosmos';
14
14
  import { PublicKey } from '@solana/web3.js';
15
15
  import { getAssociatedTokenAddressSync, getAccount } from '@solana/spl-token';
16
- import { StellarWalletsKit, allowAllModules, FREIGHTER_ID, WalletNetwork } from '@creit.tech/stellar-wallets-kit';
16
+ import { StellarWalletsKit, allowAllModules, WalletNetwork } from '@creit.tech/stellar-wallets-kit';
17
17
  import * as StellarSdk from '@stellar/stellar-sdk';
18
18
  import { SorobanRpc, Address, Contract, TimeoutInfinite, scValToBigInt, xdr } from '@stellar/stellar-sdk';
19
- import React3, { useEffect, useMemo, useCallback } from 'react';
20
- import { useSuiClient, useCurrentWallet, useCurrentAccount, useConnectWallet, useWallets, useDisconnectWallet, SuiClientProvider, WalletProvider } from '@mysten/dapp-kit';
21
- import { useConnection, useWallet, ConnectionProvider, WalletProvider as WalletProvider$1 } from '@solana/wallet-adapter-react';
19
+ import React2, { useMemo, useCallback, useEffect } from 'react';
20
+ import { useCurrentAccount, useCurrentWallet, useConnectWallet, useWallets, useDisconnectWallet, useSignPersonalMessage, SuiClientProvider, WalletProvider, useSuiClient } from '@mysten/dapp-kit';
21
+ import { useWallet, ConnectionProvider, WalletProvider as WalletProvider$1, useConnection } from '@solana/wallet-adapter-react';
22
22
  import { create } from 'zustand';
23
- import { persist, createJSONStorage } from 'zustand/middleware';
23
+ import { devtools, persist, createJSONStorage } from 'zustand/middleware';
24
24
  import { immer } from 'zustand/middleware/immer';
25
- import { AnchorProvider } from '@coral-xyz/anchor';
26
25
  import { useMutation, useQuery, keepPreviousData } from '@tanstack/react-query';
27
26
  import { mainnet as mainnet$1 } from 'viem/chains';
28
27
  import { SolanaWalletProvider, StellarWalletProvider, InjectiveWalletProvider, IconWalletProvider, SuiWalletProvider, EvmWalletProvider } from '@sodax/wallet-sdk-core';
29
28
  import { getFullnodeUrl } from '@mysten/sui/client';
30
29
  import { UnsafeBurnerWalletAdapter } from '@solana/wallet-adapter-wallets';
31
-
32
- // src/constants/xChains.ts
33
- var icon = {
34
- id: 1,
35
- name: "ICON",
36
- xChainId: "0x1.icon",
37
- xChainType: "ICON",
38
- testnet: false
39
- };
40
- var avalanche = {
41
- id: 43114,
42
- name: "Avalanche",
43
- xChainId: "0xa86a.avax",
44
- xChainType: "EVM",
45
- testnet: false
46
- };
47
- var bsc = {
48
- id: 56,
49
- name: "BNB Chain",
50
- xChainId: "0x38.bsc",
51
- xChainType: "EVM",
52
- testnet: false
53
- };
54
- var arbitrum = {
55
- id: 42161,
56
- name: "Arbitrum",
57
- xChainId: "0xa4b1.arbitrum",
58
- xChainType: "EVM",
59
- testnet: false
60
- };
61
- var base = {
62
- id: 8453,
63
- name: "Base",
64
- xChainId: "0x2105.base",
65
- xChainType: "EVM",
66
- testnet: false
67
- };
68
- var injective = {
69
- id: "injective-1",
70
- name: "Injective",
71
- xChainId: "injective-1",
72
- xChainType: "INJECTIVE",
73
- testnet: false
74
- };
75
- var stellar = {
76
- id: "stellar",
77
- name: "Stellar",
78
- xChainId: "stellar",
79
- xChainType: "STELLAR",
80
- testnet: false
81
- };
82
- var sui = {
83
- id: "sui",
84
- name: "Sui",
85
- xChainId: "sui",
86
- xChainType: "SUI",
87
- testnet: false
88
- };
89
- var solana = {
90
- id: "solana",
91
- name: "Solana",
92
- xChainId: "solana",
93
- xChainType: "SOLANA",
94
- testnet: false
95
- };
96
- var optimism = {
97
- id: 10,
98
- name: "Optimism",
99
- xChainId: "0xa.optimism",
100
- xChainType: "EVM",
101
- testnet: false
102
- };
103
- var sonic = {
104
- id: 146,
105
- name: "Sonic",
106
- xChainId: "sonic",
107
- xChainType: "EVM",
108
- testnet: false
109
- };
110
- var polygon = {
111
- id: 137,
112
- name: "Polygon",
113
- xChainId: "0x89.polygon",
114
- xChainType: "EVM",
115
- testnet: false
116
- };
117
- var nibiru = {
118
- id: 6900,
119
- name: "Nibiru",
120
- xChainId: "nibiru",
121
- xChainType: "EVM",
122
- testnet: false
123
- };
124
- var hyper = {
125
- id: 999,
126
- name: "HyperEVM",
127
- xChainId: "hyper",
128
- xChainType: "EVM",
129
- testnet: false
130
- };
131
- var lightlink = {
132
- id: 1890,
133
- name: "Lightlink",
134
- xChainId: "lightlink",
135
- xChainType: "EVM",
136
- testnet: false
137
- };
138
- var xChainMap = {
139
- "0x1.icon": icon,
140
- "0xa4b1.arbitrum": arbitrum,
141
- "0xa86a.avax": avalanche,
142
- "0x38.bsc": bsc,
143
- "0x2105.base": base,
144
- "0xa.optimism": optimism,
145
- "injective-1": injective,
146
- stellar,
147
- sui,
148
- solana,
149
- sonic,
150
- "0x89.polygon": polygon,
151
- nibiru,
152
- hyper,
153
- lightlink
154
- };
155
- var xChains = Object.values(xChainMap);
30
+ import { AnchorProvider } from '@coral-xyz/anchor';
156
31
 
157
32
  // src/actions/getXChainType.ts
158
33
  function getXChainType(xChainId) {
159
34
  if (!xChainId) {
160
35
  return void 0;
161
36
  }
162
- return xChainMap[xChainId].xChainType;
37
+ return baseChainInfo[xChainId].type;
163
38
  }
164
39
 
165
40
  // src/actions/getXService.ts
@@ -193,23 +68,21 @@ var XService = class {
193
68
  * Gets the balance of a specific token for an address
194
69
  * @param address The wallet address to check
195
70
  * @param xToken The token to get the balance for
196
- * @param xChainId The chain ID to query
197
71
  * @returns Promise resolving to the token balance as a bigint
198
72
  */
199
- async getBalance(address, xToken, xChainId) {
73
+ async getBalance(address, xToken) {
200
74
  return 0n;
201
75
  }
202
76
  /**
203
77
  * Gets balances for multiple tokens for an address
204
78
  * @param address The wallet address to check
205
79
  * @param xTokens Array of tokens to get balances for
206
- * @param xChainId The chain ID to query
207
80
  * @returns Promise resolving to object mapping token addresses to balances
208
81
  */
209
- async getBalances(address, xTokens, xChainId) {
82
+ async getBalances(address, xTokens) {
210
83
  if (!address) return {};
211
84
  const balancePromises = xTokens.map(async (xToken) => {
212
- const balance = await this.getBalance(address, xToken, xChainId);
85
+ const balance = await this.getBalance(address, xToken);
213
86
  return { address: xToken.address, balance };
214
87
  });
215
88
  const balances = await Promise.all(balancePromises);
@@ -256,8 +129,6 @@ var XConnector = class {
256
129
  return this._icon;
257
130
  }
258
131
  };
259
-
260
- // src/utils/index.ts
261
132
  var isNativeToken = (xToken) => {
262
133
  const nativeAddresses = [
263
134
  "cx0000000000000000000000000000000000000000",
@@ -273,22 +144,9 @@ var isNativeToken = (xToken) => {
273
144
  return nativeAddresses.includes(xToken.address);
274
145
  };
275
146
  var getWagmiChainId = (xChainId) => {
276
- const xChainMap2 = {
277
- "0xa869.fuji": 43113,
278
- "sonic-blaze": 57054,
279
- sonic: 146,
280
- "0xa86a.avax": 43114,
281
- "0x38.bsc": 56,
282
- "0xa4b1.arbitrum": 42161,
283
- "0x2105.base": 8453,
284
- "0xa.optimism": 10,
285
- "0x89.polygon": 137,
286
- hyper: 999,
287
- lightlink: 1890
288
- };
289
- return xChainMap2[xChainId] ?? 0;
147
+ return baseChainInfo[xChainId].chainId;
290
148
  };
291
- var hyper2 = /* @__PURE__ */ defineChain({
149
+ var hyper = /* @__PURE__ */ defineChain({
292
150
  id: 999,
293
151
  name: "HyperEVM",
294
152
  nativeCurrency: {
@@ -312,32 +170,22 @@ var hyper2 = /* @__PURE__ */ defineChain({
312
170
  }
313
171
  }
314
172
  });
315
- var evmChainMap = {
316
- [AVALANCHE_MAINNET_CHAIN_ID]: avalanche$1,
317
- [ARBITRUM_MAINNET_CHAIN_ID]: arbitrum$1,
318
- [BASE_MAINNET_CHAIN_ID]: base$1,
319
- [BSC_MAINNET_CHAIN_ID]: bsc$1,
320
- [SONIC_MAINNET_CHAIN_ID]: sonic$1,
321
- [OPTIMISM_MAINNET_CHAIN_ID]: optimism$1,
322
- [POLYGON_MAINNET_CHAIN_ID]: polygon$1,
323
- [NIBIRU_MAINNET_CHAIN_ID]: nibiru$1,
324
- [HYPEREVM_MAINNET_CHAIN_ID]: hyper2,
325
- [LIGHTLINK_MAINNET_CHAIN_ID]: lightlinkPhoenix
326
- };
327
- var getWagmiConfig = (chains) => {
328
- const mappedChains = chains.map((chain) => evmChainMap[chain]);
329
- const finalChains = mappedChains.length > 0 ? mappedChains : [mainnet];
330
- const transports = finalChains.reduce(
331
- (acc, chain) => {
332
- acc[chain.id] = http();
333
- return acc;
334
- },
335
- {}
336
- );
173
+ var createWagmiConfig = (config) => {
337
174
  return createConfig({
338
- chains: finalChains,
339
- transports
340
- // ssr: true,
175
+ chains: [mainnet, avalanche, arbitrum, base, bsc, sonic, optimism, polygon, nibiru, hyper, lightlinkPhoenix],
176
+ transports: {
177
+ [mainnet.id]: http(config["mainnet"]),
178
+ [avalanche.id]: http(config["avalanche"]),
179
+ [arbitrum.id]: http(config["arbitrum"]),
180
+ [base.id]: http(config["base"]),
181
+ [bsc.id]: http(config["bsc"]),
182
+ [sonic.id]: http(config["sonic"]),
183
+ [optimism.id]: http(config["optimism"]),
184
+ [polygon.id]: http(config["polygon"]),
185
+ [nibiru.id]: http(config["nibiru"]),
186
+ [hyper.id]: http(config["hyper"]),
187
+ [lightlinkPhoenix.id]: http(config["lightlinkPhoenix"])
188
+ }
341
189
  });
342
190
  };
343
191
  var EvmXService = class _EvmXService extends XService {
@@ -353,34 +201,23 @@ var EvmXService = class _EvmXService extends XService {
353
201
  }
354
202
  return _EvmXService.instance;
355
203
  }
356
- setConfig(config) {
357
- this.config = config;
358
- }
359
- getPublicClient(chainId) {
360
- if (!this.config) {
361
- throw new Error("EvmXService: config is not initialized yet");
362
- }
363
- return getPublicClient(getWagmiConfig(this.config.chains), { chainId });
364
- }
365
- async getWalletClient(chainId) {
366
- if (!this.config) {
367
- throw new Error("EvmXService: config is not initialized yet");
368
- }
369
- return await getWalletClient(getWagmiConfig(this.config.chains), { chainId });
370
- }
371
- async getBalance(address, xToken, xChainId) {
204
+ async getBalance(address, xToken) {
372
205
  if (!address) return 0n;
373
- const chainId = getWagmiChainId(xChainId);
206
+ if (!this.wagmiConfig) return 0n;
207
+ const chainId = getWagmiChainId(xToken.xChainId);
374
208
  if (isNativeToken(xToken)) {
375
- const balance = await this.getPublicClient(chainId)?.getBalance({ address });
209
+ const balance = await getPublicClient(this.wagmiConfig, { chainId })?.getBalance({
210
+ address
211
+ });
376
212
  return balance || 0n;
377
213
  }
378
214
  throw new Error(`Unsupported token: ${xToken.symbol}`);
379
215
  }
380
- async getBalances(address, xTokens, xChainId) {
216
+ async getBalances(address, xTokens) {
381
217
  if (!address) return {};
218
+ if (!this.wagmiConfig) return {};
382
219
  const balancePromises = xTokens.filter((xToken) => isNativeToken(xToken)).map(async (xToken) => {
383
- const balance = await this.getBalance(address, xToken, xChainId);
220
+ const balance = await this.getBalance(address, xToken);
384
221
  return { symbol: xToken.symbol, address: xToken.address, balance };
385
222
  });
386
223
  const balances = await Promise.all(balancePromises);
@@ -389,7 +226,8 @@ var EvmXService = class _EvmXService extends XService {
389
226
  return map;
390
227
  }, {});
391
228
  const nonNativeXTokens = xTokens.filter((xToken) => !isNativeToken(xToken));
392
- const result = await this.getPublicClient(getWagmiChainId(xChainId))?.multicall({
229
+ const xChainId = xTokens[0].xChainId;
230
+ const result = await getPublicClient(this.wagmiConfig, { chainId: getWagmiChainId(xChainId) })?.multicall({
393
231
  contracts: nonNativeXTokens.map((token) => ({
394
232
  abi: erc20Abi,
395
233
  address: token.address,
@@ -464,7 +302,7 @@ var IconXService = class _IconXService extends XService {
464
302
  return Array(calls.length).fill(null);
465
303
  }
466
304
  }
467
- async getBalances(address, xTokens, xChainId) {
305
+ async getBalances(address, xTokens) {
468
306
  if (!address) return {};
469
307
  const balances = {};
470
308
  const nativeXToken = xTokens.find((xToken) => isNativeToken(xToken));
@@ -578,7 +416,7 @@ var InjectiveXService = class _InjectiveXService extends XService {
578
416
  };
579
417
  var InjectiveKelprXConnector = class extends XConnector {
580
418
  constructor() {
581
- super("INJECTIVE", "Keplr", "keplr");
419
+ super("INJECTIVE", "Keplr", Wallet.Keplr);
582
420
  }
583
421
  getXService() {
584
422
  return InjectiveXService.getInstance();
@@ -603,7 +441,7 @@ var InjectiveKelprXConnector = class extends XConnector {
603
441
  };
604
442
  var InjectiveMetamaskXConnector = class extends XConnector {
605
443
  constructor() {
606
- super("INJECTIVE", "MetaMask", "metamask");
444
+ super("INJECTIVE", "MetaMask", Wallet.Metamask);
607
445
  }
608
446
  getXService() {
609
447
  return InjectiveXService.getInstance();
@@ -790,7 +628,6 @@ var StellarXService = class _StellarXService extends XService {
790
628
  super("STELLAR");
791
629
  this.walletsKit = new StellarWalletsKit({
792
630
  network: WalletNetwork.PUBLIC,
793
- selectedWalletId: FREIGHTER_ID,
794
631
  modules: allowAllModules()
795
632
  });
796
633
  this.server = new StellarSdk.Horizon.Server("https://horizon.stellar.org", { allowHttp: true });
@@ -912,70 +749,14 @@ var SuiXConnector = class extends XConnector {
912
749
  return this.wallet?.icon;
913
750
  }
914
751
  };
915
- function useAnchorProvider() {
916
- const { connection } = useConnection();
917
- const wallet = useWallet();
918
- return new AnchorProvider(connection, wallet, { commitment: "confirmed" });
919
- }
920
- var useXWagmiStore = create()(
921
- persist(
922
- immer((set, get) => ({
923
- xServices: {},
924
- xConnections: {},
925
- setXConnection: (xChainType, xConnection) => {
926
- set((state) => {
927
- state.xConnections[xChainType] = xConnection;
928
- });
929
- },
930
- unsetXConnection: (xChainType) => {
931
- set((state) => {
932
- delete state.xConnections[xChainType];
933
- });
934
- }
935
- })),
936
- {
937
- name: "xwagmi-store",
938
- storage: createJSONStorage(() => localStorage),
939
- partialize: (state) => ({ xConnections: state.xConnections }),
940
- // TODO: better way to handle rehydration of xConnections?
941
- onRehydrateStorage: (state) => {
942
- console.log("hydration starts");
943
- return (state2, error) => {
944
- if (state2?.xConnections) {
945
- console.log("rehydrating xConnections", state2.xConnections);
946
- Object.entries(state2.xConnections).forEach(([xChainType, xConnection]) => {
947
- const xConnector = getXService(xChainType).getXConnectorById(xConnection.xConnectorId);
948
- xConnector?.connect();
949
- });
950
- }
951
- if (error) {
952
- console.log("an error happened during hydration", error);
953
- } else {
954
- console.log("hydration finished");
955
- }
956
- };
957
- }
958
- }
959
- )
960
- );
961
- var initXServices = (config) => {
752
+ var initXServices = () => {
962
753
  const xServices = {};
963
- Object.keys(config).forEach((key) => {
754
+ ["EVM", "INJECTIVE", "STELLAR", "SUI", "SOLANA", "ICON"].forEach((key) => {
964
755
  const xChainType = key;
965
756
  switch (xChainType) {
757
+ // EVM, SUI, Solana wallet connectors are supported by their own sdks. wagmi, @mysten/dapp-kit, @solana/wallet-adapter-react.
966
758
  case "EVM":
967
- if (config[xChainType]) {
968
- xServices[xChainType] = EvmXService.getInstance();
969
- xServices[xChainType].setXConnectors([]);
970
- xServices[xChainType].setConfig(config[xChainType]);
971
- }
972
- break;
973
- case "INJECTIVE":
974
- xServices[xChainType] = InjectiveXService.getInstance();
975
- xServices[xChainType].setXConnectors([new InjectiveMetamaskXConnector(), new InjectiveKelprXConnector()]);
976
- break;
977
- case "STELLAR":
978
- xServices[xChainType] = StellarXService.getInstance();
759
+ xServices[xChainType] = EvmXService.getInstance();
979
760
  xServices[xChainType].setXConnectors([]);
980
761
  break;
981
762
  case "SUI":
@@ -986,6 +767,15 @@ var initXServices = (config) => {
986
767
  xServices[xChainType] = SolanaXService.getInstance();
987
768
  xServices[xChainType].setXConnectors([]);
988
769
  break;
770
+ // Injective, Stellar, Icon wallet connectors are supported by sodax wallet-sdk-react sdk.
771
+ case "INJECTIVE":
772
+ xServices[xChainType] = InjectiveXService.getInstance();
773
+ xServices[xChainType].setXConnectors([new InjectiveMetamaskXConnector(), new InjectiveKelprXConnector()]);
774
+ break;
775
+ case "STELLAR":
776
+ xServices[xChainType] = StellarXService.getInstance();
777
+ xServices[xChainType].setXConnectors([]);
778
+ break;
989
779
  case "ICON":
990
780
  xServices[xChainType] = IconXService.getInstance();
991
781
  xServices[xChainType].setXConnectors([new IconHanaXConnector()]);
@@ -994,50 +784,32 @@ var initXServices = (config) => {
994
784
  });
995
785
  return xServices;
996
786
  };
997
- var initXWagmiStore = (config) => {
998
- useXWagmiStore.setState({
999
- xServices: initXServices(config)
1000
- });
1001
- };
1002
- var InitXWagmiStore = () => {
1003
- const suiClient = useSuiClient();
1004
- useEffect(() => {
1005
- if (suiClient) {
1006
- SuiXService.getInstance().suiClient = suiClient;
1007
- }
1008
- }, [suiClient]);
1009
- const { currentWallet: suiWallet } = useCurrentWallet();
1010
- useEffect(() => {
1011
- if (suiWallet) {
1012
- SuiXService.getInstance().suiWallet = suiWallet;
1013
- }
1014
- }, [suiWallet]);
1015
- const suiAccount = useCurrentAccount();
1016
- useEffect(() => {
1017
- if (suiAccount) {
1018
- SuiXService.getInstance().suiAccount = suiAccount;
1019
- }
1020
- }, [suiAccount]);
1021
- const { connection: solanaConnection } = useConnection();
1022
- const solanaWallet = useWallet();
1023
- const solanaProvider = useAnchorProvider();
1024
- useEffect(() => {
1025
- if (solanaConnection) {
1026
- SolanaXService.getInstance().connection = solanaConnection;
1027
- }
1028
- }, [solanaConnection]);
1029
- useEffect(() => {
1030
- if (solanaWallet) {
1031
- SolanaXService.getInstance().wallet = solanaWallet;
1032
- }
1033
- }, [solanaWallet]);
1034
- useEffect(() => {
1035
- if (solanaProvider) {
1036
- SolanaXService.getInstance().provider = solanaProvider;
1037
- }
1038
- }, [solanaProvider]);
1039
- return /* @__PURE__ */ React3.createElement(React3.Fragment, null);
1040
- };
787
+ var useXWagmiStore = create()(
788
+ devtools(
789
+ persist(
790
+ immer((set, get) => ({
791
+ xServices: initXServices(),
792
+ xConnections: {},
793
+ setXConnection: (xChainType, xConnection) => {
794
+ set((state) => {
795
+ state.xConnections[xChainType] = xConnection;
796
+ });
797
+ },
798
+ unsetXConnection: (xChainType) => {
799
+ set((state) => {
800
+ delete state.xConnections[xChainType];
801
+ });
802
+ }
803
+ })),
804
+ {
805
+ name: "xwagmi-store",
806
+ storage: createJSONStorage(() => localStorage),
807
+ partialize: (state) => ({ xConnections: state.xConnections })
808
+ }
809
+ ),
810
+ { name: "xwagmi-store" }
811
+ )
812
+ );
1041
813
 
1042
814
  // src/hooks/useXConnection.ts
1043
815
  function useXConnection(xChainType) {
@@ -1143,7 +915,7 @@ function useXConnect() {
1143
915
  const setXConnection = useXWagmiStore((state) => state.setXConnection);
1144
916
  const { connectAsync: evmConnectAsync } = useConnect();
1145
917
  const { mutateAsync: suiConnectAsync } = useConnectWallet();
1146
- const { select, connect, connected } = useWallet();
918
+ const { select, connect } = useWallet();
1147
919
  return useMutation({
1148
920
  mutationFn: async (xConnector) => {
1149
921
  const xChainType = xConnector.xChainType;
@@ -1292,7 +1064,7 @@ function useXBalances({
1292
1064
  if (!xService) {
1293
1065
  return {};
1294
1066
  }
1295
- const balances = await xService.getBalances(address, xTokens, xChainId);
1067
+ const balances = await xService.getBalances(address, xTokens);
1296
1068
  return balances;
1297
1069
  },
1298
1070
  enabled: !!xService,
@@ -1300,45 +1072,9 @@ function useXBalances({
1300
1072
  refetchInterval: 5e3
1301
1073
  });
1302
1074
  }
1303
- function useWalletProviderOptions(xChainId) {
1304
- const xChainType = getXChainType(xChainId);
1305
- const evmPublicClient = usePublicClient({
1306
- chainId: xChainId ? getWagmiChainId(xChainId) : void 0
1307
- });
1308
- const { data: evmWalletClient } = useWalletClient({
1309
- chainId: xChainId ? getWagmiChainId(xChainId) : void 0
1310
- });
1311
- const xService = useXService(getXChainType(xChainId));
1312
- const xAccount = useXAccount(xChainId);
1313
- return useMemo(() => {
1314
- switch (xChainType) {
1315
- case "EVM": {
1316
- return { walletClient: evmWalletClient, publicClient: evmPublicClient };
1317
- }
1318
- case "SUI": {
1319
- const suiXService = xService;
1320
- return { client: suiXService.suiClient, wallet: suiXService.suiWallet, account: suiXService.suiAccount };
1321
- }
1322
- case "ICON": {
1323
- return { walletAddress: xAccount.address, rpcUrl: CHAIN_INFO[1 /* MAINNET */].APIEndpoint };
1324
- }
1325
- case "INJECTIVE": {
1326
- const injectiveXService = xService;
1327
- const endpoints = getNetworkEndpoints(Network.Mainnet);
1328
- return {
1329
- walletAddress: xAccount.address,
1330
- msgBroadcaster: injectiveXService.msgBroadcaster,
1331
- rpcUrl: endpoints.rpc
1332
- };
1333
- }
1334
- default:
1335
- return void 0;
1336
- }
1337
- }, [xChainType, evmPublicClient, evmWalletClient, xService, xAccount]);
1338
- }
1339
1075
  function useEthereumChainId() {
1340
1076
  const injectiveXService = useXService("INJECTIVE");
1341
- const [ethereumChainId, setEthereumChainId] = React3.useState(null);
1077
+ const [ethereumChainId, setEthereumChainId] = React2.useState(null);
1342
1078
  useEffect(() => {
1343
1079
  if (!injectiveXService?.walletStrategy?.getWallet()) return;
1344
1080
  const walletStrategy = injectiveXService.walletStrategy;
@@ -1370,7 +1106,7 @@ var switchEthereumChain2 = async () => {
1370
1106
  };
1371
1107
  var useEvmSwitchChain = (expectedXChainId) => {
1372
1108
  const xChainType = getXChainType(expectedXChainId);
1373
- const expectedChainId = xChainMap[expectedXChainId].id;
1109
+ const expectedChainId = baseChainInfo[expectedXChainId].chainId;
1374
1110
  const injectiveXService = useXService("INJECTIVE");
1375
1111
  const ethereumChainId = useEthereumChainId();
1376
1112
  const { chainId } = useAccount();
@@ -1395,12 +1131,8 @@ var useEvmSwitchChain = (expectedXChainId) => {
1395
1131
  };
1396
1132
  function useWalletProvider(spokeChainId) {
1397
1133
  const xChainType = getXChainType(spokeChainId);
1398
- const evmPublicClient = usePublicClient({
1399
- chainId: spokeChainId ? getWagmiChainId(spokeChainId) : void 0
1400
- });
1401
- const { data: evmWalletClient } = useWalletClient({
1402
- chainId: spokeChainId ? getWagmiChainId(spokeChainId) : void 0
1403
- });
1134
+ const evmPublicClient = usePublicClient();
1135
+ const { data: evmWalletClient } = useWalletClient();
1404
1136
  const xService = useXService(getXChainType(spokeChainId));
1405
1137
  const xAccount = useXAccount(spokeChainId);
1406
1138
  return useMemo(() => {
@@ -1447,6 +1179,9 @@ function useWalletProvider(spokeChainId) {
1447
1179
  }
1448
1180
  case "STELLAR": {
1449
1181
  const stellarXService = xService;
1182
+ if (!stellarXService.walletsKit) {
1183
+ return void 0;
1184
+ }
1450
1185
  return new StellarWalletProvider({
1451
1186
  type: "BROWSER_EXTENSION",
1452
1187
  walletsKit: stellarXService.walletsKit,
@@ -1456,10 +1191,10 @@ function useWalletProvider(spokeChainId) {
1456
1191
  case "SOLANA": {
1457
1192
  const solanaXService = xService;
1458
1193
  if (!solanaXService.wallet) {
1459
- throw new Error("Wallet is not initialized");
1194
+ return void 0;
1460
1195
  }
1461
1196
  if (!solanaXService.connection) {
1462
- throw new Error("Connection is not initialized");
1197
+ return void 0;
1463
1198
  }
1464
1199
  return new SolanaWalletProvider({
1465
1200
  wallet: solanaXService.wallet,
@@ -1471,20 +1206,167 @@ function useWalletProvider(spokeChainId) {
1471
1206
  }
1472
1207
  }, [xChainType, evmPublicClient, evmWalletClient, xService, xAccount]);
1473
1208
  }
1474
- var SodaxWalletProvider = ({ children, config }) => {
1209
+ function useXSignMessage() {
1210
+ const { signMessage } = useWallet();
1211
+ const { signMessageAsync: evmSignMessage } = useSignMessage();
1212
+ const { mutateAsync: signPersonalMessage } = useSignPersonalMessage();
1213
+ const { address: injectiveAddress } = useXAccount("INJECTIVE");
1214
+ return useMutation({
1215
+ mutationFn: async ({ xChainType, message }) => {
1216
+ let signature;
1217
+ switch (xChainType) {
1218
+ case "EVM": {
1219
+ signature = await evmSignMessage({ message });
1220
+ break;
1221
+ }
1222
+ case "SUI": {
1223
+ const res = await signPersonalMessage({ message: new Uint8Array(new TextEncoder().encode(message)) });
1224
+ signature = res.signature;
1225
+ break;
1226
+ }
1227
+ case "SOLANA": {
1228
+ if (!signMessage) {
1229
+ throw new Error("Solana wallet not connected");
1230
+ }
1231
+ signature = await signMessage(new TextEncoder().encode(message));
1232
+ break;
1233
+ }
1234
+ case "STELLAR": {
1235
+ const res = await StellarXService.getInstance().walletsKit.signMessage(message);
1236
+ signature = res.signedMessage;
1237
+ break;
1238
+ }
1239
+ case "INJECTIVE": {
1240
+ if (!injectiveAddress) {
1241
+ throw new Error("Injective address not found");
1242
+ }
1243
+ const ethereumAddress = getEthereumAddress(injectiveAddress);
1244
+ const walletStrategy = InjectiveXService.getInstance().walletStrategy;
1245
+ const res = await walletStrategy.signArbitrary(
1246
+ walletStrategy.getWallet() === Wallet.Metamask ? ethereumAddress : injectiveAddress,
1247
+ message
1248
+ );
1249
+ if (!res) {
1250
+ throw new Error("Injective signature not found");
1251
+ }
1252
+ signature = res;
1253
+ break;
1254
+ }
1255
+ default:
1256
+ console.warn("Unsupported chain type");
1257
+ break;
1258
+ }
1259
+ return signature;
1260
+ }
1261
+ });
1262
+ }
1263
+ function useAnchorProvider() {
1264
+ const { connection } = useConnection();
1265
+ const wallet = useWallet();
1266
+ return new AnchorProvider(connection, wallet, { commitment: "confirmed" });
1267
+ }
1268
+ var Hydrate = () => {
1269
+ const suiClient = useSuiClient();
1475
1270
  useEffect(() => {
1476
- initXWagmiStore(config);
1477
- }, [config]);
1478
- const {
1479
- EVM: { chains },
1480
- SOLANA: { endpoint }
1481
- } = config;
1482
- const wallets = useMemo(() => [new UnsafeBurnerWalletAdapter()], []);
1271
+ if (suiClient) {
1272
+ SuiXService.getInstance().suiClient = suiClient;
1273
+ }
1274
+ }, [suiClient]);
1275
+ const { currentWallet: suiWallet } = useCurrentWallet();
1276
+ useEffect(() => {
1277
+ if (suiWallet) {
1278
+ SuiXService.getInstance().suiWallet = suiWallet;
1279
+ }
1280
+ }, [suiWallet]);
1281
+ const suiAccount = useCurrentAccount();
1282
+ useEffect(() => {
1283
+ if (suiAccount) {
1284
+ SuiXService.getInstance().suiAccount = suiAccount;
1285
+ }
1286
+ }, [suiAccount]);
1287
+ const { connection: solanaConnection } = useConnection();
1288
+ const solanaWallet = useWallet();
1289
+ const solanaProvider = useAnchorProvider();
1290
+ useEffect(() => {
1291
+ if (solanaConnection) {
1292
+ SolanaXService.getInstance().connection = solanaConnection;
1293
+ }
1294
+ }, [solanaConnection]);
1295
+ useEffect(() => {
1296
+ if (solanaWallet) {
1297
+ SolanaXService.getInstance().wallet = solanaWallet;
1298
+ }
1299
+ }, [solanaWallet]);
1300
+ useEffect(() => {
1301
+ if (solanaProvider) {
1302
+ SolanaXService.getInstance().provider = solanaProvider;
1303
+ }
1304
+ }, [solanaProvider]);
1305
+ const wagmiConfig = useConfig();
1306
+ useEffect(() => {
1307
+ if (wagmiConfig) {
1308
+ EvmXService.getInstance().wagmiConfig = wagmiConfig;
1309
+ }
1310
+ }, [wagmiConfig]);
1311
+ return null;
1312
+ };
1313
+
1314
+ // src/xchains/icon/actions.ts
1315
+ var reconnectIcon = async () => {
1316
+ const iconConnection = useXWagmiStore.getState().xConnections.ICON;
1317
+ if (!iconConnection) return;
1318
+ const recentXConnectorId = iconConnection.xConnectorId;
1319
+ const detail = await request({
1320
+ type: "REQUEST_ADDRESS" /* REQUEST_ADDRESS */
1321
+ });
1322
+ if (detail?.type === "RESPONSE_ADDRESS" /* RESPONSE_ADDRESS */) {
1323
+ useXWagmiStore.setState({
1324
+ xConnections: {
1325
+ ...useXWagmiStore.getState().xConnections,
1326
+ ICON: {
1327
+ xAccount: {
1328
+ address: detail?.payload,
1329
+ xChainType: "ICON"
1330
+ },
1331
+ xConnectorId: recentXConnectorId
1332
+ }
1333
+ }
1334
+ });
1335
+ }
1336
+ };
1337
+
1338
+ // src/xchains/stellar/actions.ts
1339
+ var reconnectStellar = async () => {
1340
+ const stellarConnection = useXWagmiStore.getState().xConnections.STELLAR;
1341
+ if (!stellarConnection) return;
1342
+ const recentXConnectorId = stellarConnection.xConnectorId;
1343
+ const stellarWalletKit = StellarXService.getInstance().walletsKit;
1344
+ stellarWalletKit.setWallet(recentXConnectorId);
1345
+ const { address } = await stellarWalletKit.getAddress();
1346
+ useXWagmiStore.setState({
1347
+ xConnections: {
1348
+ ...useXWagmiStore.getState().xConnections,
1349
+ STELLAR: {
1350
+ xAccount: {
1351
+ address,
1352
+ xChainType: "STELLAR"
1353
+ },
1354
+ xConnectorId: recentXConnectorId
1355
+ }
1356
+ }
1357
+ });
1358
+ };
1359
+
1360
+ // src/SodaxWalletProvider.tsx
1361
+ var SodaxWalletProvider = ({ children, rpcConfig }) => {
1483
1362
  const wagmiConfig = useMemo(() => {
1484
- return getWagmiConfig(chains);
1485
- }, [chains]);
1486
- return /* @__PURE__ */ React3.createElement(WagmiProvider, { config: wagmiConfig }, /* @__PURE__ */ React3.createElement(SuiClientProvider, { networks: { mainnet: { url: getFullnodeUrl("mainnet") } }, defaultNetwork: "mainnet" }, /* @__PURE__ */ React3.createElement(WalletProvider, { autoConnect: true }, /* @__PURE__ */ React3.createElement(ConnectionProvider, { endpoint }, /* @__PURE__ */ React3.createElement(WalletProvider$1, { wallets, autoConnect: true }, /* @__PURE__ */ React3.createElement(InitXWagmiStore, null), children)))));
1363
+ return createWagmiConfig(rpcConfig);
1364
+ }, [rpcConfig]);
1365
+ const wallets = useMemo(() => [new UnsafeBurnerWalletAdapter()], []);
1366
+ return /* @__PURE__ */ React2.createElement(WagmiProvider, { config: wagmiConfig, reconnectOnMount: true }, /* @__PURE__ */ React2.createElement(SuiClientProvider, { networks: { mainnet: { url: getFullnodeUrl("mainnet") } }, defaultNetwork: "mainnet" }, /* @__PURE__ */ React2.createElement(WalletProvider, { autoConnect: true }, /* @__PURE__ */ React2.createElement(ConnectionProvider, { endpoint: rpcConfig["solana"] ?? "" }, /* @__PURE__ */ React2.createElement(WalletProvider$1, { wallets, autoConnect: true }, /* @__PURE__ */ React2.createElement(Hydrate, null), children)))));
1487
1367
  };
1368
+ reconnectIcon();
1369
+ reconnectStellar();
1488
1370
 
1489
1371
  // src/types/index.ts
1490
1372
  var WalletId = /* @__PURE__ */ ((WalletId2) => {
@@ -1496,6 +1378,6 @@ var WalletId = /* @__PURE__ */ ((WalletId2) => {
1496
1378
  return WalletId2;
1497
1379
  })(WalletId || {});
1498
1380
 
1499
- export { EvmXConnector, EvmXService, IconHanaXConnector, IconXService, InitXWagmiStore, InjectiveKelprXConnector, InjectiveMetamaskXConnector, InjectiveXService, SodaxWalletProvider, SolanaXConnector, SolanaXService, StellarWalletsKitXConnector, StellarXService, SuiXConnector, SuiXService, WalletId, XConnector, XService, arbitrum, avalanche, base, bsc, getWagmiChainId, getXChainType, getXService, hyper, icon, initXWagmiStore, injective, isNativeToken, lightlink, nibiru, optimism, polygon, solana, sonic, stellar, sui, switchEthereumChain, useEvmSwitchChain, useWalletProvider, useWalletProviderOptions, useXAccount, useXAccounts, useXBalances, useXConnect, useXConnection, useXConnectors, useXDisconnect, useXService, useXWagmiStore, xChainMap, xChains };
1381
+ export { EvmXConnector, EvmXService, IconHanaXConnector, IconXService, InjectiveKelprXConnector, InjectiveMetamaskXConnector, InjectiveXService, SodaxWalletProvider, SolanaXConnector, SolanaXService, StellarWalletsKitXConnector, StellarXService, SuiXConnector, SuiXService, WalletId, XConnector, XService, getWagmiChainId, getXChainType, getXService, isNativeToken, switchEthereumChain, useEvmSwitchChain, useWalletProvider, useXAccount, useXAccounts, useXBalances, useXConnect, useXConnection, useXConnectors, useXDisconnect, useXService, useXSignMessage, useXWagmiStore };
1500
1382
  //# sourceMappingURL=index.mjs.map
1501
1383
  //# sourceMappingURL=index.mjs.map