@sodax/wallet-sdk-react 0.0.1-rc.4 → 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.cjs CHANGED
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ var types = require('@sodax/types');
3
4
  var viem = require('viem');
4
5
  var actions = require('wagmi/actions');
5
6
  var wagmi = require('wagmi');
6
7
  var chains = require('wagmi/chains');
7
- var types = require('@sodax/types');
8
8
  var IconSdkRaw = require('icon-sdk-js');
9
9
  var networks = require('@injectivelabs/networks');
10
10
  var sdkTs = require('@injectivelabs/sdk-ts');
@@ -17,18 +17,18 @@ var web3_js = require('@solana/web3.js');
17
17
  var splToken = require('@solana/spl-token');
18
18
  var stellarWalletsKit = require('@creit.tech/stellar-wallets-kit');
19
19
  var StellarSdk = require('@stellar/stellar-sdk');
20
- var React3 = require('react');
20
+ var React2 = require('react');
21
21
  var dappKit = require('@mysten/dapp-kit');
22
22
  var walletAdapterReact = require('@solana/wallet-adapter-react');
23
23
  var zustand = require('zustand');
24
24
  var middleware = require('zustand/middleware');
25
25
  var immer = require('zustand/middleware/immer');
26
- var anchor = require('@coral-xyz/anchor');
27
26
  var reactQuery = require('@tanstack/react-query');
28
27
  var chains$1 = require('viem/chains');
29
28
  var walletSdkCore = require('@sodax/wallet-sdk-core');
30
29
  var client = require('@mysten/sui/client');
31
30
  var walletAdapterWallets = require('@solana/wallet-adapter-wallets');
31
+ var anchor = require('@coral-xyz/anchor');
32
32
 
33
33
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
34
34
 
@@ -52,139 +52,14 @@ function _interopNamespace(e) {
52
52
 
53
53
  var IconSdkRaw__namespace = /*#__PURE__*/_interopNamespace(IconSdkRaw);
54
54
  var StellarSdk__namespace = /*#__PURE__*/_interopNamespace(StellarSdk);
55
- var React3__default = /*#__PURE__*/_interopDefault(React3);
56
-
57
- // src/constants/xChains.ts
58
- var icon = {
59
- id: 1,
60
- name: "ICON",
61
- xChainId: "0x1.icon",
62
- xChainType: "ICON",
63
- testnet: false
64
- };
65
- var avalanche = {
66
- id: 43114,
67
- name: "Avalanche",
68
- xChainId: "0xa86a.avax",
69
- xChainType: "EVM",
70
- testnet: false
71
- };
72
- var bsc = {
73
- id: 56,
74
- name: "BNB Chain",
75
- xChainId: "0x38.bsc",
76
- xChainType: "EVM",
77
- testnet: false
78
- };
79
- var arbitrum = {
80
- id: 42161,
81
- name: "Arbitrum",
82
- xChainId: "0xa4b1.arbitrum",
83
- xChainType: "EVM",
84
- testnet: false
85
- };
86
- var base = {
87
- id: 8453,
88
- name: "Base",
89
- xChainId: "0x2105.base",
90
- xChainType: "EVM",
91
- testnet: false
92
- };
93
- var injective = {
94
- id: "injective-1",
95
- name: "Injective",
96
- xChainId: "injective-1",
97
- xChainType: "INJECTIVE",
98
- testnet: false
99
- };
100
- var stellar = {
101
- id: "stellar",
102
- name: "Stellar",
103
- xChainId: "stellar",
104
- xChainType: "STELLAR",
105
- testnet: false
106
- };
107
- var sui = {
108
- id: "sui",
109
- name: "Sui",
110
- xChainId: "sui",
111
- xChainType: "SUI",
112
- testnet: false
113
- };
114
- var solana = {
115
- id: "solana",
116
- name: "Solana",
117
- xChainId: "solana",
118
- xChainType: "SOLANA",
119
- testnet: false
120
- };
121
- var optimism = {
122
- id: 10,
123
- name: "Optimism",
124
- xChainId: "0xa.optimism",
125
- xChainType: "EVM",
126
- testnet: false
127
- };
128
- var sonic = {
129
- id: 146,
130
- name: "Sonic",
131
- xChainId: "sonic",
132
- xChainType: "EVM",
133
- testnet: false
134
- };
135
- var polygon = {
136
- id: 137,
137
- name: "Polygon",
138
- xChainId: "0x89.polygon",
139
- xChainType: "EVM",
140
- testnet: false
141
- };
142
- var nibiru = {
143
- id: 6900,
144
- name: "Nibiru",
145
- xChainId: "nibiru",
146
- xChainType: "EVM",
147
- testnet: false
148
- };
149
- var hyper = {
150
- id: 999,
151
- name: "HyperEVM",
152
- xChainId: "hyper",
153
- xChainType: "EVM",
154
- testnet: false
155
- };
156
- var lightlink = {
157
- id: 1890,
158
- name: "Lightlink",
159
- xChainId: "lightlink",
160
- xChainType: "EVM",
161
- testnet: false
162
- };
163
- var xChainMap = {
164
- "0x1.icon": icon,
165
- "0xa4b1.arbitrum": arbitrum,
166
- "0xa86a.avax": avalanche,
167
- "0x38.bsc": bsc,
168
- "0x2105.base": base,
169
- "0xa.optimism": optimism,
170
- "injective-1": injective,
171
- stellar,
172
- sui,
173
- solana,
174
- sonic,
175
- "0x89.polygon": polygon,
176
- nibiru,
177
- hyper,
178
- lightlink
179
- };
180
- var xChains = Object.values(xChainMap);
55
+ var React2__default = /*#__PURE__*/_interopDefault(React2);
181
56
 
182
57
  // src/actions/getXChainType.ts
183
58
  function getXChainType(xChainId) {
184
59
  if (!xChainId) {
185
60
  return void 0;
186
61
  }
187
- return xChainMap[xChainId].xChainType;
62
+ return types.baseChainInfo[xChainId].type;
188
63
  }
189
64
 
190
65
  // src/actions/getXService.ts
@@ -218,23 +93,21 @@ var XService = class {
218
93
  * Gets the balance of a specific token for an address
219
94
  * @param address The wallet address to check
220
95
  * @param xToken The token to get the balance for
221
- * @param xChainId The chain ID to query
222
96
  * @returns Promise resolving to the token balance as a bigint
223
97
  */
224
- async getBalance(address, xToken, xChainId) {
98
+ async getBalance(address, xToken) {
225
99
  return 0n;
226
100
  }
227
101
  /**
228
102
  * Gets balances for multiple tokens for an address
229
103
  * @param address The wallet address to check
230
104
  * @param xTokens Array of tokens to get balances for
231
- * @param xChainId The chain ID to query
232
105
  * @returns Promise resolving to object mapping token addresses to balances
233
106
  */
234
- async getBalances(address, xTokens, xChainId) {
107
+ async getBalances(address, xTokens) {
235
108
  if (!address) return {};
236
109
  const balancePromises = xTokens.map(async (xToken) => {
237
- const balance = await this.getBalance(address, xToken, xChainId);
110
+ const balance = await this.getBalance(address, xToken);
238
111
  return { address: xToken.address, balance };
239
112
  });
240
113
  const balances = await Promise.all(balancePromises);
@@ -281,8 +154,6 @@ var XConnector = class {
281
154
  return this._icon;
282
155
  }
283
156
  };
284
-
285
- // src/utils/index.ts
286
157
  var isNativeToken = (xToken) => {
287
158
  const nativeAddresses = [
288
159
  "cx0000000000000000000000000000000000000000",
@@ -298,22 +169,9 @@ var isNativeToken = (xToken) => {
298
169
  return nativeAddresses.includes(xToken.address);
299
170
  };
300
171
  var getWagmiChainId = (xChainId) => {
301
- const xChainMap2 = {
302
- "0xa869.fuji": 43113,
303
- "sonic-blaze": 57054,
304
- sonic: 146,
305
- "0xa86a.avax": 43114,
306
- "0x38.bsc": 56,
307
- "0xa4b1.arbitrum": 42161,
308
- "0x2105.base": 8453,
309
- "0xa.optimism": 10,
310
- "0x89.polygon": 137,
311
- hyper: 999,
312
- lightlink: 1890
313
- };
314
- return xChainMap2[xChainId] ?? 0;
172
+ return types.baseChainInfo[xChainId].chainId;
315
173
  };
316
- var hyper2 = /* @__PURE__ */ viem.defineChain({
174
+ var hyper = /* @__PURE__ */ viem.defineChain({
317
175
  id: 999,
318
176
  name: "HyperEVM",
319
177
  nativeCurrency: {
@@ -337,32 +195,22 @@ var hyper2 = /* @__PURE__ */ viem.defineChain({
337
195
  }
338
196
  }
339
197
  });
340
- var evmChainMap = {
341
- [types.AVALANCHE_MAINNET_CHAIN_ID]: chains.avalanche,
342
- [types.ARBITRUM_MAINNET_CHAIN_ID]: chains.arbitrum,
343
- [types.BASE_MAINNET_CHAIN_ID]: chains.base,
344
- [types.BSC_MAINNET_CHAIN_ID]: chains.bsc,
345
- [types.SONIC_MAINNET_CHAIN_ID]: chains.sonic,
346
- [types.OPTIMISM_MAINNET_CHAIN_ID]: chains.optimism,
347
- [types.POLYGON_MAINNET_CHAIN_ID]: chains.polygon,
348
- [types.NIBIRU_MAINNET_CHAIN_ID]: chains.nibiru,
349
- [types.HYPEREVM_MAINNET_CHAIN_ID]: hyper2,
350
- [types.LIGHTLINK_MAINNET_CHAIN_ID]: chains.lightlinkPhoenix
351
- };
352
- var getWagmiConfig = (chains$1) => {
353
- const mappedChains = chains$1.map((chain) => evmChainMap[chain]);
354
- const finalChains = mappedChains.length > 0 ? mappedChains : [chains.mainnet];
355
- const transports = finalChains.reduce(
356
- (acc, chain) => {
357
- acc[chain.id] = wagmi.http();
358
- return acc;
359
- },
360
- {}
361
- );
198
+ var createWagmiConfig = (config) => {
362
199
  return wagmi.createConfig({
363
- chains: finalChains,
364
- transports
365
- // ssr: true,
200
+ chains: [chains.mainnet, chains.avalanche, chains.arbitrum, chains.base, chains.bsc, chains.sonic, chains.optimism, chains.polygon, chains.nibiru, hyper, chains.lightlinkPhoenix],
201
+ transports: {
202
+ [chains.mainnet.id]: wagmi.http(config["mainnet"]),
203
+ [chains.avalanche.id]: wagmi.http(config["avalanche"]),
204
+ [chains.arbitrum.id]: wagmi.http(config["arbitrum"]),
205
+ [chains.base.id]: wagmi.http(config["base"]),
206
+ [chains.bsc.id]: wagmi.http(config["bsc"]),
207
+ [chains.sonic.id]: wagmi.http(config["sonic"]),
208
+ [chains.optimism.id]: wagmi.http(config["optimism"]),
209
+ [chains.polygon.id]: wagmi.http(config["polygon"]),
210
+ [chains.nibiru.id]: wagmi.http(config["nibiru"]),
211
+ [hyper.id]: wagmi.http(config["hyper"]),
212
+ [chains.lightlinkPhoenix.id]: wagmi.http(config["lightlinkPhoenix"])
213
+ }
366
214
  });
367
215
  };
368
216
  var EvmXService = class _EvmXService extends XService {
@@ -378,34 +226,23 @@ var EvmXService = class _EvmXService extends XService {
378
226
  }
379
227
  return _EvmXService.instance;
380
228
  }
381
- setConfig(config) {
382
- this.config = config;
383
- }
384
- getPublicClient(chainId) {
385
- if (!this.config) {
386
- throw new Error("EvmXService: config is not initialized yet");
387
- }
388
- return actions.getPublicClient(getWagmiConfig(this.config.chains), { chainId });
389
- }
390
- async getWalletClient(chainId) {
391
- if (!this.config) {
392
- throw new Error("EvmXService: config is not initialized yet");
393
- }
394
- return await actions.getWalletClient(getWagmiConfig(this.config.chains), { chainId });
395
- }
396
- async getBalance(address, xToken, xChainId) {
229
+ async getBalance(address, xToken) {
397
230
  if (!address) return 0n;
398
- const chainId = getWagmiChainId(xChainId);
231
+ if (!this.wagmiConfig) return 0n;
232
+ const chainId = getWagmiChainId(xToken.xChainId);
399
233
  if (isNativeToken(xToken)) {
400
- const balance = await this.getPublicClient(chainId)?.getBalance({ address });
234
+ const balance = await actions.getPublicClient(this.wagmiConfig, { chainId })?.getBalance({
235
+ address
236
+ });
401
237
  return balance || 0n;
402
238
  }
403
239
  throw new Error(`Unsupported token: ${xToken.symbol}`);
404
240
  }
405
- async getBalances(address, xTokens, xChainId) {
241
+ async getBalances(address, xTokens) {
406
242
  if (!address) return {};
243
+ if (!this.wagmiConfig) return {};
407
244
  const balancePromises = xTokens.filter((xToken) => isNativeToken(xToken)).map(async (xToken) => {
408
- const balance = await this.getBalance(address, xToken, xChainId);
245
+ const balance = await this.getBalance(address, xToken);
409
246
  return { symbol: xToken.symbol, address: xToken.address, balance };
410
247
  });
411
248
  const balances = await Promise.all(balancePromises);
@@ -414,7 +251,8 @@ var EvmXService = class _EvmXService extends XService {
414
251
  return map;
415
252
  }, {});
416
253
  const nonNativeXTokens = xTokens.filter((xToken) => !isNativeToken(xToken));
417
- const result = await this.getPublicClient(getWagmiChainId(xChainId))?.multicall({
254
+ const xChainId = xTokens[0].xChainId;
255
+ const result = await actions.getPublicClient(this.wagmiConfig, { chainId: getWagmiChainId(xChainId) })?.multicall({
418
256
  contracts: nonNativeXTokens.map((token) => ({
419
257
  abi: viem.erc20Abi,
420
258
  address: token.address,
@@ -489,7 +327,7 @@ var IconXService = class _IconXService extends XService {
489
327
  return Array(calls.length).fill(null);
490
328
  }
491
329
  }
492
- async getBalances(address, xTokens, xChainId) {
330
+ async getBalances(address, xTokens) {
493
331
  if (!address) return {};
494
332
  const balances = {};
495
333
  const nativeXToken = xTokens.find((xToken) => isNativeToken(xToken));
@@ -603,7 +441,7 @@ var InjectiveXService = class _InjectiveXService extends XService {
603
441
  };
604
442
  var InjectiveKelprXConnector = class extends XConnector {
605
443
  constructor() {
606
- super("INJECTIVE", "Keplr", "keplr");
444
+ super("INJECTIVE", "Keplr", walletBase.Wallet.Keplr);
607
445
  }
608
446
  getXService() {
609
447
  return InjectiveXService.getInstance();
@@ -628,7 +466,7 @@ var InjectiveKelprXConnector = class extends XConnector {
628
466
  };
629
467
  var InjectiveMetamaskXConnector = class extends XConnector {
630
468
  constructor() {
631
- super("INJECTIVE", "MetaMask", "metamask");
469
+ super("INJECTIVE", "MetaMask", walletBase.Wallet.Metamask);
632
470
  }
633
471
  getXService() {
634
472
  return InjectiveXService.getInstance();
@@ -815,7 +653,6 @@ var StellarXService = class _StellarXService extends XService {
815
653
  super("STELLAR");
816
654
  this.walletsKit = new stellarWalletsKit.StellarWalletsKit({
817
655
  network: stellarWalletsKit.WalletNetwork.PUBLIC,
818
- selectedWalletId: stellarWalletsKit.FREIGHTER_ID,
819
656
  modules: stellarWalletsKit.allowAllModules()
820
657
  });
821
658
  this.server = new StellarSdk__namespace.Horizon.Server("https://horizon.stellar.org", { allowHttp: true });
@@ -937,70 +774,14 @@ var SuiXConnector = class extends XConnector {
937
774
  return this.wallet?.icon;
938
775
  }
939
776
  };
940
- function useAnchorProvider() {
941
- const { connection } = walletAdapterReact.useConnection();
942
- const wallet = walletAdapterReact.useWallet();
943
- return new anchor.AnchorProvider(connection, wallet, { commitment: "confirmed" });
944
- }
945
- var useXWagmiStore = zustand.create()(
946
- middleware.persist(
947
- immer.immer((set, get) => ({
948
- xServices: {},
949
- xConnections: {},
950
- setXConnection: (xChainType, xConnection) => {
951
- set((state) => {
952
- state.xConnections[xChainType] = xConnection;
953
- });
954
- },
955
- unsetXConnection: (xChainType) => {
956
- set((state) => {
957
- delete state.xConnections[xChainType];
958
- });
959
- }
960
- })),
961
- {
962
- name: "xwagmi-store",
963
- storage: middleware.createJSONStorage(() => localStorage),
964
- partialize: (state) => ({ xConnections: state.xConnections }),
965
- // TODO: better way to handle rehydration of xConnections?
966
- onRehydrateStorage: (state) => {
967
- console.log("hydration starts");
968
- return (state2, error) => {
969
- if (state2?.xConnections) {
970
- console.log("rehydrating xConnections", state2.xConnections);
971
- Object.entries(state2.xConnections).forEach(([xChainType, xConnection]) => {
972
- const xConnector = getXService(xChainType).getXConnectorById(xConnection.xConnectorId);
973
- xConnector?.connect();
974
- });
975
- }
976
- if (error) {
977
- console.log("an error happened during hydration", error);
978
- } else {
979
- console.log("hydration finished");
980
- }
981
- };
982
- }
983
- }
984
- )
985
- );
986
- var initXServices = (config) => {
777
+ var initXServices = () => {
987
778
  const xServices = {};
988
- Object.keys(config).forEach((key) => {
779
+ ["EVM", "INJECTIVE", "STELLAR", "SUI", "SOLANA", "ICON"].forEach((key) => {
989
780
  const xChainType = key;
990
781
  switch (xChainType) {
782
+ // EVM, SUI, Solana wallet connectors are supported by their own sdks. wagmi, @mysten/dapp-kit, @solana/wallet-adapter-react.
991
783
  case "EVM":
992
- if (config[xChainType]) {
993
- xServices[xChainType] = EvmXService.getInstance();
994
- xServices[xChainType].setXConnectors([]);
995
- xServices[xChainType].setConfig(config[xChainType]);
996
- }
997
- break;
998
- case "INJECTIVE":
999
- xServices[xChainType] = InjectiveXService.getInstance();
1000
- xServices[xChainType].setXConnectors([new InjectiveMetamaskXConnector(), new InjectiveKelprXConnector()]);
1001
- break;
1002
- case "STELLAR":
1003
- xServices[xChainType] = StellarXService.getInstance();
784
+ xServices[xChainType] = EvmXService.getInstance();
1004
785
  xServices[xChainType].setXConnectors([]);
1005
786
  break;
1006
787
  case "SUI":
@@ -1011,6 +792,15 @@ var initXServices = (config) => {
1011
792
  xServices[xChainType] = SolanaXService.getInstance();
1012
793
  xServices[xChainType].setXConnectors([]);
1013
794
  break;
795
+ // Injective, Stellar, Icon wallet connectors are supported by sodax wallet-sdk-react sdk.
796
+ case "INJECTIVE":
797
+ xServices[xChainType] = InjectiveXService.getInstance();
798
+ xServices[xChainType].setXConnectors([new InjectiveMetamaskXConnector(), new InjectiveKelprXConnector()]);
799
+ break;
800
+ case "STELLAR":
801
+ xServices[xChainType] = StellarXService.getInstance();
802
+ xServices[xChainType].setXConnectors([]);
803
+ break;
1014
804
  case "ICON":
1015
805
  xServices[xChainType] = IconXService.getInstance();
1016
806
  xServices[xChainType].setXConnectors([new IconHanaXConnector()]);
@@ -1019,50 +809,32 @@ var initXServices = (config) => {
1019
809
  });
1020
810
  return xServices;
1021
811
  };
1022
- var initXWagmiStore = (config) => {
1023
- useXWagmiStore.setState({
1024
- xServices: initXServices(config)
1025
- });
1026
- };
1027
- var InitXWagmiStore = () => {
1028
- const suiClient = dappKit.useSuiClient();
1029
- React3.useEffect(() => {
1030
- if (suiClient) {
1031
- SuiXService.getInstance().suiClient = suiClient;
1032
- }
1033
- }, [suiClient]);
1034
- const { currentWallet: suiWallet } = dappKit.useCurrentWallet();
1035
- React3.useEffect(() => {
1036
- if (suiWallet) {
1037
- SuiXService.getInstance().suiWallet = suiWallet;
1038
- }
1039
- }, [suiWallet]);
1040
- const suiAccount = dappKit.useCurrentAccount();
1041
- React3.useEffect(() => {
1042
- if (suiAccount) {
1043
- SuiXService.getInstance().suiAccount = suiAccount;
1044
- }
1045
- }, [suiAccount]);
1046
- const { connection: solanaConnection } = walletAdapterReact.useConnection();
1047
- const solanaWallet = walletAdapterReact.useWallet();
1048
- const solanaProvider = useAnchorProvider();
1049
- React3.useEffect(() => {
1050
- if (solanaConnection) {
1051
- SolanaXService.getInstance().connection = solanaConnection;
1052
- }
1053
- }, [solanaConnection]);
1054
- React3.useEffect(() => {
1055
- if (solanaWallet) {
1056
- SolanaXService.getInstance().wallet = solanaWallet;
1057
- }
1058
- }, [solanaWallet]);
1059
- React3.useEffect(() => {
1060
- if (solanaProvider) {
1061
- SolanaXService.getInstance().provider = solanaProvider;
1062
- }
1063
- }, [solanaProvider]);
1064
- return /* @__PURE__ */ React3__default.default.createElement(React3__default.default.Fragment, null);
1065
- };
812
+ var useXWagmiStore = zustand.create()(
813
+ middleware.devtools(
814
+ middleware.persist(
815
+ immer.immer((set, get) => ({
816
+ xServices: initXServices(),
817
+ xConnections: {},
818
+ setXConnection: (xChainType, xConnection) => {
819
+ set((state) => {
820
+ state.xConnections[xChainType] = xConnection;
821
+ });
822
+ },
823
+ unsetXConnection: (xChainType) => {
824
+ set((state) => {
825
+ delete state.xConnections[xChainType];
826
+ });
827
+ }
828
+ })),
829
+ {
830
+ name: "xwagmi-store",
831
+ storage: middleware.createJSONStorage(() => localStorage),
832
+ partialize: (state) => ({ xConnections: state.xConnections })
833
+ }
834
+ ),
835
+ { name: "xwagmi-store" }
836
+ )
837
+ );
1066
838
 
1067
839
  // src/hooks/useXConnection.ts
1068
840
  function useXConnection(xChainType) {
@@ -1072,7 +844,7 @@ function useXConnection(xChainType) {
1072
844
  const suiAccount = dappKit.useCurrentAccount();
1073
845
  const suiCurrentWallet = dappKit.useCurrentWallet();
1074
846
  const solanaWallet = walletAdapterReact.useWallet();
1075
- const xConnection2 = React3.useMemo(() => {
847
+ const xConnection2 = React2.useMemo(() => {
1076
848
  if (!xChainType) {
1077
849
  return void 0;
1078
850
  }
@@ -1112,7 +884,7 @@ function isChainType(chainIdentifier) {
1112
884
  function useXAccount(chainIdentifier) {
1113
885
  const resolvedChainType = chainIdentifier ? isChainType(chainIdentifier) ? chainIdentifier : getXChainType(chainIdentifier) : void 0;
1114
886
  const xConnection = useXConnection(resolvedChainType);
1115
- const xAccount = React3.useMemo(() => {
887
+ const xAccount = React2.useMemo(() => {
1116
888
  if (!resolvedChainType) {
1117
889
  return {
1118
890
  address: void 0,
@@ -1129,7 +901,7 @@ function useXAccounts() {
1129
901
  const { address: evmAddress } = wagmi.useAccount();
1130
902
  const suiAccount = dappKit.useCurrentAccount();
1131
903
  const solanaWallet = walletAdapterReact.useWallet();
1132
- const xAccounts = React3.useMemo(() => {
904
+ const xAccounts = React2.useMemo(() => {
1133
905
  const result = {};
1134
906
  for (const xChainType of xChainTypes) {
1135
907
  const xConnection = xConnections[xChainType];
@@ -1168,7 +940,7 @@ function useXConnect() {
1168
940
  const setXConnection = useXWagmiStore((state) => state.setXConnection);
1169
941
  const { connectAsync: evmConnectAsync } = wagmi.useConnect();
1170
942
  const { mutateAsync: suiConnectAsync } = dappKit.useConnectWallet();
1171
- const { select, connect, connected } = walletAdapterReact.useWallet();
943
+ const { select, connect } = walletAdapterReact.useWallet();
1172
944
  return reactQuery.useMutation({
1173
945
  mutationFn: async (xConnector) => {
1174
946
  const xChainType = xConnector.xChainType;
@@ -1182,7 +954,7 @@ function useXConnect() {
1182
954
  break;
1183
955
  case "SOLANA": {
1184
956
  const walletName = xConnector.wallet.adapter.name;
1185
- await select(walletName);
957
+ select(walletName);
1186
958
  const adapter = xConnector.wallet.adapter;
1187
959
  if (!adapter) throw new Error("No adapter found for Solana wallet");
1188
960
  if (walletName === "MetaMask") {
@@ -1255,7 +1027,7 @@ function useXConnectors(xChainType) {
1255
1027
  const suiWallets = dappKit.useWallets();
1256
1028
  const { data: stellarXConnectors } = useStellarXConnectors();
1257
1029
  const { wallets: solanaWallets } = walletAdapterReact.useWallet();
1258
- const xConnectors = React3.useMemo(() => {
1030
+ const xConnectors = React2.useMemo(() => {
1259
1031
  if (!xChainType || !xService) {
1260
1032
  return [];
1261
1033
  }
@@ -1280,7 +1052,7 @@ function useXDisconnect() {
1280
1052
  const { disconnectAsync } = wagmi.useDisconnect();
1281
1053
  const { mutateAsync: suiDisconnectAsync } = dappKit.useDisconnectWallet();
1282
1054
  const solanaWallet = walletAdapterReact.useWallet();
1283
- return React3.useCallback(
1055
+ return React2.useCallback(
1284
1056
  async (xChainType) => {
1285
1057
  switch (xChainType) {
1286
1058
  case "EVM":
@@ -1317,7 +1089,7 @@ function useXBalances({
1317
1089
  if (!xService) {
1318
1090
  return {};
1319
1091
  }
1320
- const balances = await xService.getBalances(address, xTokens, xChainId);
1092
+ const balances = await xService.getBalances(address, xTokens);
1321
1093
  return balances;
1322
1094
  },
1323
1095
  enabled: !!xService,
@@ -1325,46 +1097,10 @@ function useXBalances({
1325
1097
  refetchInterval: 5e3
1326
1098
  });
1327
1099
  }
1328
- function useWalletProviderOptions(xChainId) {
1329
- const xChainType = getXChainType(xChainId);
1330
- const evmPublicClient = wagmi.usePublicClient({
1331
- chainId: xChainId ? getWagmiChainId(xChainId) : void 0
1332
- });
1333
- const { data: evmWalletClient } = wagmi.useWalletClient({
1334
- chainId: xChainId ? getWagmiChainId(xChainId) : void 0
1335
- });
1336
- const xService = useXService(getXChainType(xChainId));
1337
- const xAccount = useXAccount(xChainId);
1338
- return React3.useMemo(() => {
1339
- switch (xChainType) {
1340
- case "EVM": {
1341
- return { walletClient: evmWalletClient, publicClient: evmPublicClient };
1342
- }
1343
- case "SUI": {
1344
- const suiXService = xService;
1345
- return { client: suiXService.suiClient, wallet: suiXService.suiWallet, account: suiXService.suiAccount };
1346
- }
1347
- case "ICON": {
1348
- return { walletAddress: xAccount.address, rpcUrl: CHAIN_INFO[1 /* MAINNET */].APIEndpoint };
1349
- }
1350
- case "INJECTIVE": {
1351
- const injectiveXService = xService;
1352
- const endpoints = networks.getNetworkEndpoints(networks.Network.Mainnet);
1353
- return {
1354
- walletAddress: xAccount.address,
1355
- msgBroadcaster: injectiveXService.msgBroadcaster,
1356
- rpcUrl: endpoints.rpc
1357
- };
1358
- }
1359
- default:
1360
- return void 0;
1361
- }
1362
- }, [xChainType, evmPublicClient, evmWalletClient, xService, xAccount]);
1363
- }
1364
1100
  function useEthereumChainId() {
1365
1101
  const injectiveXService = useXService("INJECTIVE");
1366
- const [ethereumChainId, setEthereumChainId] = React3__default.default.useState(null);
1367
- React3.useEffect(() => {
1102
+ const [ethereumChainId, setEthereumChainId] = React2__default.default.useState(null);
1103
+ React2.useEffect(() => {
1368
1104
  if (!injectiveXService?.walletStrategy?.getWallet()) return;
1369
1105
  const walletStrategy = injectiveXService.walletStrategy;
1370
1106
  if (walletStrategy.getWallet() !== walletBase.Wallet.Metamask) return;
@@ -1395,22 +1131,22 @@ var switchEthereumChain2 = async () => {
1395
1131
  };
1396
1132
  var useEvmSwitchChain = (expectedXChainId) => {
1397
1133
  const xChainType = getXChainType(expectedXChainId);
1398
- const expectedChainId = xChainMap[expectedXChainId].id;
1134
+ const expectedChainId = types.baseChainInfo[expectedXChainId].chainId;
1399
1135
  const injectiveXService = useXService("INJECTIVE");
1400
1136
  const ethereumChainId = useEthereumChainId();
1401
1137
  const { chainId } = wagmi.useAccount();
1402
- const isWrongChain = React3.useMemo(() => {
1138
+ const isWrongChain = React2.useMemo(() => {
1403
1139
  return xChainType === "EVM" && chainId !== expectedChainId || xChainType === "INJECTIVE" && injectiveXService && injectiveXService.walletStrategy.getWallet() === walletBase.Wallet.Metamask && ethereumChainId !== chains$1.mainnet.id;
1404
1140
  }, [xChainType, chainId, expectedChainId, ethereumChainId, injectiveXService]);
1405
1141
  const { switchChain } = wagmi.useSwitchChain();
1406
- const handleSwitchChain = React3.useCallback(() => {
1142
+ const handleSwitchChain = React2.useCallback(() => {
1407
1143
  if (xChainType === "INJECTIVE") {
1408
1144
  switchEthereumChain2();
1409
1145
  } else {
1410
1146
  switchChain({ chainId: expectedChainId });
1411
1147
  }
1412
1148
  }, [switchChain, expectedChainId, xChainType]);
1413
- return React3.useMemo(
1149
+ return React2.useMemo(
1414
1150
  () => ({
1415
1151
  isWrongChain,
1416
1152
  handleSwitchChain
@@ -1420,15 +1156,11 @@ var useEvmSwitchChain = (expectedXChainId) => {
1420
1156
  };
1421
1157
  function useWalletProvider(spokeChainId) {
1422
1158
  const xChainType = getXChainType(spokeChainId);
1423
- const evmPublicClient = wagmi.usePublicClient({
1424
- chainId: spokeChainId ? getWagmiChainId(spokeChainId) : void 0
1425
- });
1426
- const { data: evmWalletClient } = wagmi.useWalletClient({
1427
- chainId: spokeChainId ? getWagmiChainId(spokeChainId) : void 0
1428
- });
1159
+ const evmPublicClient = wagmi.usePublicClient();
1160
+ const { data: evmWalletClient } = wagmi.useWalletClient();
1429
1161
  const xService = useXService(getXChainType(spokeChainId));
1430
1162
  const xAccount = useXAccount(spokeChainId);
1431
- return React3.useMemo(() => {
1163
+ return React2.useMemo(() => {
1432
1164
  switch (xChainType) {
1433
1165
  case "EVM": {
1434
1166
  if (!evmWalletClient) {
@@ -1466,17 +1198,15 @@ function useWalletProvider(spokeChainId) {
1466
1198
  if (!injectiveXService) {
1467
1199
  return void 0;
1468
1200
  }
1469
- const { walletAddress, msgBroadcaster } = {
1470
- walletAddress: xAccount.address,
1471
- msgBroadcaster: injectiveXService.msgBroadcaster
1472
- };
1473
1201
  return new walletSdkCore.InjectiveWalletProvider({
1474
- walletAddress,
1475
- msgBroadcaster
1202
+ msgBroadcaster: injectiveXService.msgBroadcaster
1476
1203
  });
1477
1204
  }
1478
1205
  case "STELLAR": {
1479
1206
  const stellarXService = xService;
1207
+ if (!stellarXService.walletsKit) {
1208
+ return void 0;
1209
+ }
1480
1210
  return new walletSdkCore.StellarWalletProvider({
1481
1211
  type: "BROWSER_EXTENSION",
1482
1212
  walletsKit: stellarXService.walletsKit,
@@ -1486,10 +1216,10 @@ function useWalletProvider(spokeChainId) {
1486
1216
  case "SOLANA": {
1487
1217
  const solanaXService = xService;
1488
1218
  if (!solanaXService.wallet) {
1489
- throw new Error("Wallet is not initialized");
1219
+ return void 0;
1490
1220
  }
1491
1221
  if (!solanaXService.connection) {
1492
- throw new Error("Connection is not initialized");
1222
+ return void 0;
1493
1223
  }
1494
1224
  return new walletSdkCore.SolanaWalletProvider({
1495
1225
  wallet: solanaXService.wallet,
@@ -1501,20 +1231,167 @@ function useWalletProvider(spokeChainId) {
1501
1231
  }
1502
1232
  }, [xChainType, evmPublicClient, evmWalletClient, xService, xAccount]);
1503
1233
  }
1504
- var SodaxWalletProvider = ({ children, config }) => {
1505
- React3.useEffect(() => {
1506
- initXWagmiStore(config);
1507
- }, [config]);
1508
- const {
1509
- EVM: { chains },
1510
- SOLANA: { endpoint }
1511
- } = config;
1512
- const wallets = React3.useMemo(() => [new walletAdapterWallets.UnsafeBurnerWalletAdapter()], []);
1513
- const wagmiConfig = React3.useMemo(() => {
1514
- return getWagmiConfig(chains);
1515
- }, [chains]);
1516
- return /* @__PURE__ */ React3__default.default.createElement(wagmi.WagmiProvider, { config: wagmiConfig }, /* @__PURE__ */ React3__default.default.createElement(dappKit.SuiClientProvider, { networks: { mainnet: { url: client.getFullnodeUrl("mainnet") } }, defaultNetwork: "mainnet" }, /* @__PURE__ */ React3__default.default.createElement(dappKit.WalletProvider, { autoConnect: true }, /* @__PURE__ */ React3__default.default.createElement(walletAdapterReact.ConnectionProvider, { endpoint }, /* @__PURE__ */ React3__default.default.createElement(walletAdapterReact.WalletProvider, { wallets, autoConnect: true }, /* @__PURE__ */ React3__default.default.createElement(InitXWagmiStore, null), children)))));
1234
+ function useXSignMessage() {
1235
+ const { signMessage } = walletAdapterReact.useWallet();
1236
+ const { signMessageAsync: evmSignMessage } = wagmi.useSignMessage();
1237
+ const { mutateAsync: signPersonalMessage } = dappKit.useSignPersonalMessage();
1238
+ const { address: injectiveAddress } = useXAccount("INJECTIVE");
1239
+ return reactQuery.useMutation({
1240
+ mutationFn: async ({ xChainType, message }) => {
1241
+ let signature;
1242
+ switch (xChainType) {
1243
+ case "EVM": {
1244
+ signature = await evmSignMessage({ message });
1245
+ break;
1246
+ }
1247
+ case "SUI": {
1248
+ const res = await signPersonalMessage({ message: new Uint8Array(new TextEncoder().encode(message)) });
1249
+ signature = res.signature;
1250
+ break;
1251
+ }
1252
+ case "SOLANA": {
1253
+ if (!signMessage) {
1254
+ throw new Error("Solana wallet not connected");
1255
+ }
1256
+ signature = await signMessage(new TextEncoder().encode(message));
1257
+ break;
1258
+ }
1259
+ case "STELLAR": {
1260
+ const res = await StellarXService.getInstance().walletsKit.signMessage(message);
1261
+ signature = res.signedMessage;
1262
+ break;
1263
+ }
1264
+ case "INJECTIVE": {
1265
+ if (!injectiveAddress) {
1266
+ throw new Error("Injective address not found");
1267
+ }
1268
+ const ethereumAddress = sdkTs.getEthereumAddress(injectiveAddress);
1269
+ const walletStrategy = InjectiveXService.getInstance().walletStrategy;
1270
+ const res = await walletStrategy.signArbitrary(
1271
+ walletStrategy.getWallet() === walletBase.Wallet.Metamask ? ethereumAddress : injectiveAddress,
1272
+ message
1273
+ );
1274
+ if (!res) {
1275
+ throw new Error("Injective signature not found");
1276
+ }
1277
+ signature = res;
1278
+ break;
1279
+ }
1280
+ default:
1281
+ console.warn("Unsupported chain type");
1282
+ break;
1283
+ }
1284
+ return signature;
1285
+ }
1286
+ });
1287
+ }
1288
+ function useAnchorProvider() {
1289
+ const { connection } = walletAdapterReact.useConnection();
1290
+ const wallet = walletAdapterReact.useWallet();
1291
+ return new anchor.AnchorProvider(connection, wallet, { commitment: "confirmed" });
1292
+ }
1293
+ var Hydrate = () => {
1294
+ const suiClient = dappKit.useSuiClient();
1295
+ React2.useEffect(() => {
1296
+ if (suiClient) {
1297
+ SuiXService.getInstance().suiClient = suiClient;
1298
+ }
1299
+ }, [suiClient]);
1300
+ const { currentWallet: suiWallet } = dappKit.useCurrentWallet();
1301
+ React2.useEffect(() => {
1302
+ if (suiWallet) {
1303
+ SuiXService.getInstance().suiWallet = suiWallet;
1304
+ }
1305
+ }, [suiWallet]);
1306
+ const suiAccount = dappKit.useCurrentAccount();
1307
+ React2.useEffect(() => {
1308
+ if (suiAccount) {
1309
+ SuiXService.getInstance().suiAccount = suiAccount;
1310
+ }
1311
+ }, [suiAccount]);
1312
+ const { connection: solanaConnection } = walletAdapterReact.useConnection();
1313
+ const solanaWallet = walletAdapterReact.useWallet();
1314
+ const solanaProvider = useAnchorProvider();
1315
+ React2.useEffect(() => {
1316
+ if (solanaConnection) {
1317
+ SolanaXService.getInstance().connection = solanaConnection;
1318
+ }
1319
+ }, [solanaConnection]);
1320
+ React2.useEffect(() => {
1321
+ if (solanaWallet) {
1322
+ SolanaXService.getInstance().wallet = solanaWallet;
1323
+ }
1324
+ }, [solanaWallet]);
1325
+ React2.useEffect(() => {
1326
+ if (solanaProvider) {
1327
+ SolanaXService.getInstance().provider = solanaProvider;
1328
+ }
1329
+ }, [solanaProvider]);
1330
+ const wagmiConfig = wagmi.useConfig();
1331
+ React2.useEffect(() => {
1332
+ if (wagmiConfig) {
1333
+ EvmXService.getInstance().wagmiConfig = wagmiConfig;
1334
+ }
1335
+ }, [wagmiConfig]);
1336
+ return null;
1337
+ };
1338
+
1339
+ // src/xchains/icon/actions.ts
1340
+ var reconnectIcon = async () => {
1341
+ const iconConnection = useXWagmiStore.getState().xConnections.ICON;
1342
+ if (!iconConnection) return;
1343
+ const recentXConnectorId = iconConnection.xConnectorId;
1344
+ const detail = await request({
1345
+ type: "REQUEST_ADDRESS" /* REQUEST_ADDRESS */
1346
+ });
1347
+ if (detail?.type === "RESPONSE_ADDRESS" /* RESPONSE_ADDRESS */) {
1348
+ useXWagmiStore.setState({
1349
+ xConnections: {
1350
+ ...useXWagmiStore.getState().xConnections,
1351
+ ICON: {
1352
+ xAccount: {
1353
+ address: detail?.payload,
1354
+ xChainType: "ICON"
1355
+ },
1356
+ xConnectorId: recentXConnectorId
1357
+ }
1358
+ }
1359
+ });
1360
+ }
1361
+ };
1362
+
1363
+ // src/xchains/stellar/actions.ts
1364
+ var reconnectStellar = async () => {
1365
+ const stellarConnection = useXWagmiStore.getState().xConnections.STELLAR;
1366
+ if (!stellarConnection) return;
1367
+ const recentXConnectorId = stellarConnection.xConnectorId;
1368
+ const stellarWalletKit = StellarXService.getInstance().walletsKit;
1369
+ stellarWalletKit.setWallet(recentXConnectorId);
1370
+ const { address } = await stellarWalletKit.getAddress();
1371
+ useXWagmiStore.setState({
1372
+ xConnections: {
1373
+ ...useXWagmiStore.getState().xConnections,
1374
+ STELLAR: {
1375
+ xAccount: {
1376
+ address,
1377
+ xChainType: "STELLAR"
1378
+ },
1379
+ xConnectorId: recentXConnectorId
1380
+ }
1381
+ }
1382
+ });
1383
+ };
1384
+
1385
+ // src/SodaxWalletProvider.tsx
1386
+ var SodaxWalletProvider = ({ children, rpcConfig }) => {
1387
+ const wagmiConfig = React2.useMemo(() => {
1388
+ return createWagmiConfig(rpcConfig);
1389
+ }, [rpcConfig]);
1390
+ const wallets = React2.useMemo(() => [new walletAdapterWallets.UnsafeBurnerWalletAdapter()], []);
1391
+ return /* @__PURE__ */ React2__default.default.createElement(wagmi.WagmiProvider, { config: wagmiConfig, reconnectOnMount: true }, /* @__PURE__ */ React2__default.default.createElement(dappKit.SuiClientProvider, { networks: { mainnet: { url: client.getFullnodeUrl("mainnet") } }, defaultNetwork: "mainnet" }, /* @__PURE__ */ React2__default.default.createElement(dappKit.WalletProvider, { autoConnect: true }, /* @__PURE__ */ React2__default.default.createElement(walletAdapterReact.ConnectionProvider, { endpoint: rpcConfig["solana"] ?? "" }, /* @__PURE__ */ React2__default.default.createElement(walletAdapterReact.WalletProvider, { wallets, autoConnect: true }, /* @__PURE__ */ React2__default.default.createElement(Hydrate, null), children)))));
1517
1392
  };
1393
+ reconnectIcon();
1394
+ reconnectStellar();
1518
1395
 
1519
1396
  // src/types/index.ts
1520
1397
  var WalletId = /* @__PURE__ */ ((WalletId2) => {
@@ -1530,7 +1407,6 @@ exports.EvmXConnector = EvmXConnector;
1530
1407
  exports.EvmXService = EvmXService;
1531
1408
  exports.IconHanaXConnector = IconHanaXConnector;
1532
1409
  exports.IconXService = IconXService;
1533
- exports.InitXWagmiStore = InitXWagmiStore;
1534
1410
  exports.InjectiveKelprXConnector = InjectiveKelprXConnector;
1535
1411
  exports.InjectiveMetamaskXConnector = InjectiveMetamaskXConnector;
1536
1412
  exports.InjectiveXService = InjectiveXService;
@@ -1544,30 +1420,13 @@ exports.SuiXService = SuiXService;
1544
1420
  exports.WalletId = WalletId;
1545
1421
  exports.XConnector = XConnector;
1546
1422
  exports.XService = XService;
1547
- exports.arbitrum = arbitrum;
1548
- exports.avalanche = avalanche;
1549
- exports.base = base;
1550
- exports.bsc = bsc;
1551
1423
  exports.getWagmiChainId = getWagmiChainId;
1552
1424
  exports.getXChainType = getXChainType;
1553
1425
  exports.getXService = getXService;
1554
- exports.hyper = hyper;
1555
- exports.icon = icon;
1556
- exports.initXWagmiStore = initXWagmiStore;
1557
- exports.injective = injective;
1558
1426
  exports.isNativeToken = isNativeToken;
1559
- exports.lightlink = lightlink;
1560
- exports.nibiru = nibiru;
1561
- exports.optimism = optimism;
1562
- exports.polygon = polygon;
1563
- exports.solana = solana;
1564
- exports.sonic = sonic;
1565
- exports.stellar = stellar;
1566
- exports.sui = sui;
1567
1427
  exports.switchEthereumChain = switchEthereumChain;
1568
1428
  exports.useEvmSwitchChain = useEvmSwitchChain;
1569
1429
  exports.useWalletProvider = useWalletProvider;
1570
- exports.useWalletProviderOptions = useWalletProviderOptions;
1571
1430
  exports.useXAccount = useXAccount;
1572
1431
  exports.useXAccounts = useXAccounts;
1573
1432
  exports.useXBalances = useXBalances;
@@ -1576,8 +1435,7 @@ exports.useXConnection = useXConnection;
1576
1435
  exports.useXConnectors = useXConnectors;
1577
1436
  exports.useXDisconnect = useXDisconnect;
1578
1437
  exports.useXService = useXService;
1438
+ exports.useXSignMessage = useXSignMessage;
1579
1439
  exports.useXWagmiStore = useXWagmiStore;
1580
- exports.xChainMap = xChainMap;
1581
- exports.xChains = xChains;
1582
1440
  //# sourceMappingURL=index.cjs.map
1583
1441
  //# sourceMappingURL=index.cjs.map