@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.
@@ -1,11 +1,10 @@
1
1
  import { XService } from '@/core/XService';
2
- import type { ChainId, XToken } from '@sodax/types';
3
- import type { EVMConfig } from '@/types';
2
+ import type { RpcConfig, XToken } from '@sodax/types';
4
3
  import { getWagmiChainId, isNativeToken } from '@/utils';
5
4
 
6
- import { type Address, type PublicClient, type WalletClient, defineChain, erc20Abi } from 'viem';
7
- import { getPublicClient, getWalletClient } from 'wagmi/actions';
8
- import { createConfig, http, type Transport } from 'wagmi';
5
+ import { type Address, defineChain, erc20Abi } from 'viem';
6
+ import { getPublicClient } from 'wagmi/actions';
7
+ import { type Config, createConfig, http } from 'wagmi';
9
8
  import {
10
9
  mainnet,
11
10
  avalanche,
@@ -19,19 +18,6 @@ import {
19
18
  lightlinkPhoenix,
20
19
  } from 'wagmi/chains';
21
20
 
22
- import {
23
- AVALANCHE_MAINNET_CHAIN_ID,
24
- ARBITRUM_MAINNET_CHAIN_ID,
25
- BASE_MAINNET_CHAIN_ID,
26
- BSC_MAINNET_CHAIN_ID,
27
- SONIC_MAINNET_CHAIN_ID,
28
- OPTIMISM_MAINNET_CHAIN_ID,
29
- POLYGON_MAINNET_CHAIN_ID,
30
- NIBIRU_MAINNET_CHAIN_ID,
31
- HYPEREVM_MAINNET_CHAIN_ID,
32
- LIGHTLINK_MAINNET_CHAIN_ID,
33
- } from '@sodax/types';
34
-
35
21
  // HyperEVM chain is not supported by viem, so we need to define it manually
36
22
  export const hyper = /*#__PURE__*/ defineChain({
37
23
  id: 999,
@@ -58,37 +44,22 @@ export const hyper = /*#__PURE__*/ defineChain({
58
44
  },
59
45
  });
60
46
 
61
- const evmChainMap = {
62
- [AVALANCHE_MAINNET_CHAIN_ID]: avalanche,
63
- [ARBITRUM_MAINNET_CHAIN_ID]: arbitrum,
64
- [BASE_MAINNET_CHAIN_ID]: base,
65
- [BSC_MAINNET_CHAIN_ID]: bsc,
66
- [SONIC_MAINNET_CHAIN_ID]: sonic,
67
- [OPTIMISM_MAINNET_CHAIN_ID]: optimism,
68
- [POLYGON_MAINNET_CHAIN_ID]: polygon,
69
- [NIBIRU_MAINNET_CHAIN_ID]: nibiru,
70
- [HYPEREVM_MAINNET_CHAIN_ID]: hyper,
71
- [LIGHTLINK_MAINNET_CHAIN_ID]: lightlinkPhoenix,
72
- } as const;
73
-
74
- export type EvmChainId = keyof typeof evmChainMap;
75
-
76
- export const getWagmiConfig = (chains: EvmChainId[]) => {
77
- const mappedChains = chains.map(chain => evmChainMap[chain]);
78
- const finalChains = mappedChains.length > 0 ? mappedChains : [mainnet];
79
-
80
- const transports = finalChains.reduce(
81
- (acc, chain) => {
82
- acc[chain.id] = http();
83
- return acc;
84
- },
85
- {} as Record<number, Transport>,
86
- );
87
-
47
+ export const createWagmiConfig = (config: RpcConfig) => {
88
48
  return createConfig({
89
- chains: finalChains as [typeof mainnet, ...(typeof mainnet)[]],
90
- transports,
91
- // ssr: true,
49
+ chains: [mainnet, avalanche, arbitrum, base, bsc, sonic, optimism, polygon, nibiru, hyper, lightlinkPhoenix],
50
+ transports: {
51
+ [mainnet.id]: http(config['mainnet']),
52
+ [avalanche.id]: http(config['avalanche']),
53
+ [arbitrum.id]: http(config['arbitrum']),
54
+ [base.id]: http(config['base']),
55
+ [bsc.id]: http(config['bsc']),
56
+ [sonic.id]: http(config['sonic']),
57
+ [optimism.id]: http(config['optimism']),
58
+ [polygon.id]: http(config['polygon']),
59
+ [nibiru.id]: http(config['nibiru']),
60
+ [hyper.id]: http(config['hyper']),
61
+ [lightlinkPhoenix.id]: http(config['lightlinkPhoenix']),
62
+ },
92
63
  });
93
64
  };
94
65
 
@@ -99,7 +70,8 @@ export const getWagmiConfig = (chains: EvmChainId[]) => {
99
70
 
100
71
  export class EvmXService extends XService {
101
72
  private static instance: EvmXService;
102
- private config: EVMConfig | undefined;
73
+ public wagmiConfig: Config | undefined;
74
+
103
75
  private constructor() {
104
76
  super('EVM');
105
77
  }
@@ -115,46 +87,30 @@ export class EvmXService extends XService {
115
87
  return EvmXService.instance;
116
88
  }
117
89
 
118
- public setConfig(config: EVMConfig) {
119
- this.config = config;
120
- }
121
-
122
- getPublicClient(chainId: number): PublicClient | undefined {
123
- if (!this.config) {
124
- throw new Error('EvmXService: config is not initialized yet');
125
- }
126
-
127
- // @ts-ignore
128
- return getPublicClient(getWagmiConfig(this.config.chains), { chainId });
129
- }
130
-
131
- public async getWalletClient(chainId: number): Promise<WalletClient> {
132
- if (!this.config) {
133
- throw new Error('EvmXService: config is not initialized yet');
134
- }
135
- return await getWalletClient(getWagmiConfig(this.config.chains), { chainId });
136
- }
137
-
138
- async getBalance(address: string | undefined, xToken: XToken, xChainId: ChainId): Promise<bigint> {
90
+ async getBalance(address: string | undefined, xToken: XToken): Promise<bigint> {
139
91
  if (!address) return 0n;
92
+ if (!this.wagmiConfig) return 0n;
140
93
 
141
- const chainId = getWagmiChainId(xChainId);
94
+ const chainId = getWagmiChainId(xToken.xChainId);
142
95
 
143
96
  if (isNativeToken(xToken)) {
144
- const balance = await this.getPublicClient(chainId)?.getBalance({ address: address as Address });
97
+ const balance = await getPublicClient(this.wagmiConfig, { chainId: chainId })?.getBalance({
98
+ address: address as Address,
99
+ });
145
100
  return balance || 0n;
146
101
  }
147
102
 
148
103
  throw new Error(`Unsupported token: ${xToken.symbol}`);
149
104
  }
150
105
 
151
- async getBalances(address: string | undefined, xTokens: XToken[], xChainId: ChainId) {
106
+ async getBalances(address: string | undefined, xTokens: XToken[]) {
152
107
  if (!address) return {};
108
+ if (!this.wagmiConfig) return {};
153
109
 
154
110
  const balancePromises = xTokens
155
111
  .filter(xToken => isNativeToken(xToken))
156
112
  .map(async xToken => {
157
- const balance = await this.getBalance(address, xToken, xChainId);
113
+ const balance = await this.getBalance(address, xToken);
158
114
  return { symbol: xToken.symbol, address: xToken.address, balance };
159
115
  });
160
116
 
@@ -165,7 +121,8 @@ export class EvmXService extends XService {
165
121
  }, {});
166
122
 
167
123
  const nonNativeXTokens = xTokens.filter(xToken => !isNativeToken(xToken));
168
- const result = await this.getPublicClient(getWagmiChainId(xChainId))?.multicall({
124
+ const xChainId = xTokens[0].xChainId;
125
+ const result = await getPublicClient(this.wagmiConfig, { chainId: getWagmiChainId(xChainId) })?.multicall({
169
126
  contracts: nonNativeXTokens.map(token => ({
170
127
  abi: erc20Abi,
171
128
  address: token.address as `0x${string}`,
@@ -1,7 +1,7 @@
1
1
  import { XService } from '@/core/XService';
2
2
  import type { IconService } from 'icon-sdk-js';
3
3
  import * as IconSdkRaw from 'icon-sdk-js';
4
- import type { ChainId, XToken } from '@sodax/types';
4
+ import type { XToken } from '@sodax/types';
5
5
  import { isNativeToken } from '@/utils';
6
6
 
7
7
  const IconSdk = ('default' in IconSdkRaw.default ? IconSdkRaw.default : IconSdkRaw) as typeof IconSdkRaw;
@@ -81,7 +81,7 @@ export class IconXService extends XService {
81
81
  }
82
82
  }
83
83
 
84
- async getBalances(address: string | undefined, xTokens: XToken[], xChainId: ChainId) {
84
+ async getBalances(address: string | undefined, xTokens: XToken[]) {
85
85
  if (!address) return {};
86
86
 
87
87
  const balances = {};
@@ -0,0 +1,28 @@
1
+ import { useXWagmiStore } from '@/useXWagmiStore';
2
+ import { ICONexRequestEventType, ICONexResponseEventType, request } from './iconex';
3
+
4
+ export const reconnectIcon = async () => {
5
+ const iconConnection = useXWagmiStore.getState().xConnections.ICON;
6
+ if (!iconConnection) return;
7
+
8
+ const recentXConnectorId = iconConnection.xConnectorId;
9
+
10
+ const detail = await request({
11
+ type: ICONexRequestEventType.REQUEST_ADDRESS,
12
+ });
13
+
14
+ if (detail?.type === ICONexResponseEventType.RESPONSE_ADDRESS) {
15
+ useXWagmiStore.setState({
16
+ xConnections: {
17
+ ...useXWagmiStore.getState().xConnections,
18
+ ICON: {
19
+ xAccount: {
20
+ address: detail?.payload,
21
+ xChainType: 'ICON',
22
+ },
23
+ xConnectorId: recentXConnectorId,
24
+ },
25
+ },
26
+ });
27
+ }
28
+ };
@@ -7,7 +7,7 @@ import { InjectiveXService } from './InjectiveXService';
7
7
 
8
8
  export class InjectiveKelprXConnector extends XConnector {
9
9
  constructor() {
10
- super('INJECTIVE', 'Keplr', 'keplr');
10
+ super('INJECTIVE', 'Keplr', Wallet.Keplr);
11
11
  }
12
12
 
13
13
  getXService(): InjectiveXService {
@@ -7,7 +7,7 @@ import { InjectiveXService } from './InjectiveXService';
7
7
 
8
8
  export class InjectiveMetamaskXConnector extends XConnector {
9
9
  constructor() {
10
- super('INJECTIVE', 'MetaMask', 'metamask');
10
+ super('INJECTIVE', 'MetaMask', Wallet.Metamask);
11
11
  }
12
12
 
13
13
  getXService(): InjectiveXService {
@@ -0,0 +1,25 @@
1
+ import { useXWagmiStore } from '@/useXWagmiStore';
2
+ import { InjectiveXService } from './InjectiveXService';
3
+ import type { Wallet } from '@injectivelabs/wallet-base';
4
+
5
+ export const reconnectInjective = async () => {
6
+ const injectiveConnection = useXWagmiStore.getState().xConnections.INJECTIVE;
7
+ if (!injectiveConnection) return;
8
+
9
+ const recentXConnectorId = injectiveConnection.xConnectorId;
10
+ const walletStrategy = InjectiveXService.getInstance().walletStrategy;
11
+ walletStrategy.setWallet(recentXConnectorId as Wallet);
12
+ const addresses = await walletStrategy.getAddresses();
13
+ useXWagmiStore.setState({
14
+ xConnections: {
15
+ ...useXWagmiStore.getState().xConnections,
16
+ INJECTIVE: {
17
+ xAccount: {
18
+ address: addresses?.[0],
19
+ xChainType: 'INJECTIVE',
20
+ },
21
+ xConnectorId: recentXConnectorId,
22
+ },
23
+ },
24
+ });
25
+ };
@@ -1,5 +1,5 @@
1
1
  import { XService } from '@/core/XService';
2
- import { FREIGHTER_ID, StellarWalletsKit, WalletNetwork, allowAllModules } from '@creit.tech/stellar-wallets-kit';
2
+ import { StellarWalletsKit, WalletNetwork, allowAllModules } from '@creit.tech/stellar-wallets-kit';
3
3
  import * as StellarSdk from '@stellar/stellar-sdk';
4
4
  import CustomSorobanServer from './CustomSorobanServer';
5
5
  import { getTokenBalance } from './utils';
@@ -17,7 +17,6 @@ export class StellarXService extends XService {
17
17
 
18
18
  this.walletsKit = new StellarWalletsKit({
19
19
  network: WalletNetwork.PUBLIC,
20
- selectedWalletId: FREIGHTER_ID,
21
20
  modules: allowAllModules(),
22
21
  });
23
22
 
@@ -0,0 +1,24 @@
1
+ import { useXWagmiStore } from '@/useXWagmiStore';
2
+ import { StellarXService } from './StellarXService';
3
+
4
+ export const reconnectStellar = async () => {
5
+ const stellarConnection = useXWagmiStore.getState().xConnections.STELLAR;
6
+ if (!stellarConnection) return;
7
+
8
+ const recentXConnectorId = stellarConnection.xConnectorId;
9
+ const stellarWalletKit = StellarXService.getInstance().walletsKit;
10
+ stellarWalletKit.setWallet(recentXConnectorId);
11
+ const { address } = await stellarWalletKit.getAddress();
12
+ useXWagmiStore.setState({
13
+ xConnections: {
14
+ ...useXWagmiStore.getState().xConnections,
15
+ STELLAR: {
16
+ xAccount: {
17
+ address,
18
+ xChainType: 'STELLAR',
19
+ },
20
+ xConnectorId: recentXConnectorId,
21
+ },
22
+ },
23
+ });
24
+ };
@@ -1 +0,0 @@
1
- export * from './xChains';
@@ -1,164 +0,0 @@
1
- import type { XChain, ChainId } from '@sodax/types';
2
-
3
- export const icon: XChain = {
4
- id: 1,
5
- name: 'ICON',
6
- xChainId: '0x1.icon',
7
- xChainType: 'ICON',
8
- testnet: false,
9
- };
10
-
11
- export const avalanche: XChain = {
12
- id: 43_114,
13
- name: 'Avalanche',
14
- xChainId: '0xa86a.avax',
15
- xChainType: 'EVM',
16
- testnet: false,
17
- };
18
-
19
- export const bsc: XChain = {
20
- id: 56,
21
- name: 'BNB Chain',
22
- xChainId: '0x38.bsc',
23
- xChainType: 'EVM',
24
- testnet: false,
25
- };
26
-
27
- export const arbitrum: XChain = {
28
- id: 42161,
29
- name: 'Arbitrum',
30
- xChainId: '0xa4b1.arbitrum',
31
- xChainType: 'EVM',
32
- testnet: false,
33
- };
34
-
35
- export const base: XChain = {
36
- id: 8453,
37
- name: 'Base',
38
- xChainId: '0x2105.base',
39
- xChainType: 'EVM',
40
- testnet: false,
41
- };
42
-
43
- export const injective: XChain = {
44
- id: 'injective-1',
45
- name: 'Injective',
46
- xChainId: 'injective-1',
47
- xChainType: 'INJECTIVE',
48
- testnet: false,
49
- };
50
-
51
- export const stellar: XChain = {
52
- id: 'stellar',
53
- name: 'Stellar',
54
- xChainId: 'stellar',
55
- xChainType: 'STELLAR',
56
- testnet: false,
57
- };
58
-
59
- export const sui: XChain = {
60
- id: 'sui',
61
- name: 'Sui',
62
- xChainId: 'sui',
63
- xChainType: 'SUI',
64
- testnet: false,
65
- };
66
-
67
- export const solana: XChain = {
68
- id: 'solana',
69
- name: 'Solana',
70
- xChainId: 'solana',
71
- xChainType: 'SOLANA',
72
- testnet: false,
73
- };
74
-
75
- export const optimism: XChain = {
76
- id: 10,
77
- name: 'Optimism',
78
- xChainId: '0xa.optimism',
79
- xChainType: 'EVM',
80
- testnet: false,
81
- };
82
-
83
- export const sonic: XChain = {
84
- id: 146,
85
- name: 'Sonic',
86
- xChainId: 'sonic',
87
- xChainType: 'EVM',
88
- testnet: false,
89
- };
90
-
91
- export const polygon: XChain = {
92
- id: 137,
93
- name: 'Polygon',
94
- xChainId: '0x89.polygon',
95
- xChainType: 'EVM',
96
- testnet: false,
97
- };
98
-
99
- export const nibiru: XChain = {
100
- id: 6900,
101
- name: 'Nibiru',
102
- xChainId: 'nibiru',
103
- xChainType: 'EVM',
104
- testnet: false,
105
- };
106
-
107
- export const hyper: XChain = {
108
- id: 999,
109
- name: 'HyperEVM',
110
- xChainId: 'hyper',
111
- xChainType: 'EVM',
112
- testnet: false,
113
- };
114
-
115
- export const lightlink: XChain = {
116
- id: 1890,
117
- name: 'Lightlink',
118
- xChainId: 'lightlink',
119
- xChainType: 'EVM',
120
- testnet: false,
121
- };
122
-
123
- // the order is important, using manual order to display in the UI
124
- export const xChainMap: { [key in ChainId]: XChain } = {
125
- '0x1.icon': icon,
126
- '0xa4b1.arbitrum': arbitrum,
127
- '0xa86a.avax': avalanche,
128
- '0x38.bsc': bsc,
129
- '0x2105.base': base,
130
- '0xa.optimism': optimism,
131
- 'injective-1': injective,
132
- stellar: stellar,
133
- sui: sui,
134
- solana: solana,
135
- sonic: sonic,
136
- '0x89.polygon': polygon,
137
- nibiru: nibiru,
138
- hyper: hyper,
139
- lightlink: lightlink,
140
- };
141
-
142
- /**
143
- * List of all supported chains in Sodax ecosystem
144
- *
145
- * Currently supported chains:
146
- * - EVM chains:
147
- * - Arbitrum (0xa4b1.arbitrum)
148
- * - Avalanche (0xa86a.avax)
149
- * - Base (0x2105.base)
150
- * - BSC (0x38.bsc)
151
- * - Optimism (0xa.optimism)
152
- * - Polygon (0x89.polygon)
153
- * - Sonic (sonic)
154
- * - Nibiru (nibiru)
155
- * - ICON chain: 0x1.icon
156
- * - Sui chain: sui
157
- * - Solana chain: solana
158
- * - Stellar chain: stellar
159
- * - Injective chain: injective-1
160
- * - Nibiru chain: nibiru
161
- * - HyperEVM chain: hyper
162
- */
163
-
164
- export const xChains = Object.values(xChainMap);
@@ -1,51 +0,0 @@
1
- import { getXChainType } from '@/actions';
2
- import { useMemo } from 'react';
3
- import { usePublicClient, useWalletClient } from 'wagmi';
4
- import type { ChainId } from '@sodax/types';
5
- import { getWagmiChainId } from '../utils';
6
- import { useXAccount, useXService } from '..';
7
- import type { SuiXService } from '../xchains/sui/SuiXService';
8
- import { CHAIN_INFO, SupportedChainId } from '../xchains/icon/IconXService';
9
- import type { InjectiveXService } from '../xchains/injective/InjectiveXService';
10
- import { getNetworkEndpoints, Network } from '@injectivelabs/networks';
11
-
12
- export function useWalletProviderOptions(xChainId: ChainId | undefined) {
13
- const xChainType = getXChainType(xChainId);
14
-
15
- const evmPublicClient = usePublicClient({
16
- chainId: xChainId ? getWagmiChainId(xChainId) : undefined,
17
- });
18
- const { data: evmWalletClient } = useWalletClient({
19
- chainId: xChainId ? getWagmiChainId(xChainId) : undefined,
20
- });
21
-
22
- const xService = useXService(getXChainType(xChainId));
23
- const xAccount = useXAccount(xChainId);
24
-
25
- return useMemo(() => {
26
- switch (xChainType) {
27
- case 'EVM': {
28
- return { walletClient: evmWalletClient, publicClient: evmPublicClient };
29
- }
30
- case 'SUI': {
31
- const suiXService = xService as SuiXService;
32
- return { client: suiXService.suiClient, wallet: suiXService.suiWallet, account: suiXService.suiAccount };
33
- }
34
- case 'ICON': {
35
- return { walletAddress: xAccount.address, rpcUrl: CHAIN_INFO[SupportedChainId.MAINNET].APIEndpoint };
36
- }
37
- case 'INJECTIVE': {
38
- const injectiveXService = xService as InjectiveXService;
39
- const endpoints = getNetworkEndpoints(Network.Mainnet);
40
-
41
- return {
42
- walletAddress: xAccount.address,
43
- msgBroadcaster: injectiveXService.msgBroadcaster,
44
- rpcUrl: endpoints.rpc,
45
- };
46
- }
47
- default:
48
- return undefined;
49
- }
50
- }, [xChainType, evmPublicClient, evmWalletClient, xService, xAccount]);
51
- }
@@ -1,164 +0,0 @@
1
- 'use client';
2
-
3
- import type { ChainType } from '@sodax/types';
4
- import type { XConfig } from './types';
5
- import { useCurrentAccount, useCurrentWallet, useSuiClient } from '@mysten/dapp-kit';
6
- import React, { useEffect } from 'react';
7
- import { create } from 'zustand';
8
- import { createJSONStorage, persist } from 'zustand/middleware';
9
- import { immer } from 'zustand/middleware/immer';
10
- import { getXService } from '.';
11
- import type { XService } from './core';
12
- import type { XConnection } from './types';
13
- import { EvmXService } from './xchains/evm';
14
- import { InjectiveKelprXConnector, InjectiveMetamaskXConnector, InjectiveXService } from './xchains/injective';
15
- import { SolanaXService } from './xchains/solana/SolanaXService';
16
- import { StellarXService } from './xchains/stellar';
17
- import { SuiXService } from './xchains/sui';
18
- import { IconXService } from './xchains/icon';
19
- import { IconHanaXConnector } from './xchains/icon/IconHanaXConnector';
20
- import { useAnchorProvider } from './xchains/solana/hooks/useAnchorProvider';
21
- import { useConnection, useWallet } from '@solana/wallet-adapter-react';
22
-
23
- type XWagmiStore = {
24
- xServices: Partial<Record<ChainType, XService>>;
25
- xConnections: Partial<Record<ChainType, XConnection>>;
26
-
27
- setXConnection: (xChainType: ChainType, xConnection: XConnection) => void;
28
- unsetXConnection: (xChainType: ChainType) => void;
29
- };
30
-
31
- export const useXWagmiStore = create<XWagmiStore>()(
32
- persist(
33
- immer((set, get) => ({
34
- xServices: {},
35
- xConnections: {},
36
- setXConnection: (xChainType: ChainType, xConnection: XConnection) => {
37
- set(state => {
38
- state.xConnections[xChainType] = xConnection;
39
- });
40
- },
41
- unsetXConnection: (xChainType: ChainType) => {
42
- set(state => {
43
- delete state.xConnections[xChainType];
44
- });
45
- },
46
- })),
47
- {
48
- name: 'xwagmi-store',
49
- storage: createJSONStorage(() => localStorage),
50
- partialize: state => ({ xConnections: state.xConnections }),
51
-
52
- // TODO: better way to handle rehydration of xConnections?
53
- onRehydrateStorage: state => {
54
- console.log('hydration starts');
55
-
56
- return (state, error) => {
57
- if (state?.xConnections) {
58
- console.log('rehydrating xConnections', state.xConnections);
59
- Object.entries(state.xConnections).forEach(([xChainType, xConnection]) => {
60
- const xConnector = getXService(xChainType as ChainType).getXConnectorById(xConnection.xConnectorId);
61
- xConnector?.connect();
62
- });
63
- }
64
- if (error) {
65
- console.log('an error happened during hydration', error);
66
- } else {
67
- console.log('hydration finished');
68
- }
69
- };
70
- },
71
- },
72
- ),
73
- );
74
-
75
- const initXServices = (config: XConfig) => {
76
- const xServices = {};
77
- Object.keys(config).forEach(key => {
78
- const xChainType = key as ChainType;
79
-
80
- switch (xChainType) {
81
- case 'EVM':
82
- if (config[xChainType]) {
83
- xServices[xChainType] = EvmXService.getInstance();
84
- xServices[xChainType].setXConnectors([]);
85
- xServices[xChainType].setConfig(config[xChainType]);
86
- }
87
- break;
88
- case 'INJECTIVE':
89
- xServices[xChainType] = InjectiveXService.getInstance();
90
- xServices[xChainType].setXConnectors([new InjectiveMetamaskXConnector(), new InjectiveKelprXConnector()]);
91
- break;
92
- case 'STELLAR':
93
- xServices[xChainType] = StellarXService.getInstance();
94
- xServices[xChainType].setXConnectors([]);
95
- break;
96
- case 'SUI':
97
- xServices[xChainType] = SuiXService.getInstance();
98
- xServices[xChainType].setXConnectors([]);
99
- break;
100
- case 'SOLANA':
101
- xServices[xChainType] = SolanaXService.getInstance();
102
- xServices[xChainType].setXConnectors([]);
103
- break;
104
- case 'ICON':
105
- xServices[xChainType] = IconXService.getInstance();
106
- xServices[xChainType].setXConnectors([new IconHanaXConnector()]);
107
- break;
108
- default:
109
- break;
110
- }
111
- });
112
-
113
- return xServices;
114
- };
115
-
116
- export const initXWagmiStore = (config: XConfig) => {
117
- useXWagmiStore.setState({
118
- xServices: initXServices(config),
119
- });
120
- };
121
-
122
- export const InitXWagmiStore = () => {
123
- // sui
124
- const suiClient = useSuiClient();
125
- useEffect(() => {
126
- if (suiClient) {
127
- SuiXService.getInstance().suiClient = suiClient;
128
- }
129
- }, [suiClient]);
130
- const { currentWallet: suiWallet } = useCurrentWallet();
131
- useEffect(() => {
132
- if (suiWallet) {
133
- SuiXService.getInstance().suiWallet = suiWallet;
134
- }
135
- }, [suiWallet]);
136
- const suiAccount = useCurrentAccount();
137
- useEffect(() => {
138
- if (suiAccount) {
139
- SuiXService.getInstance().suiAccount = suiAccount;
140
- }
141
- }, [suiAccount]);
142
-
143
- // solana
144
- const { connection: solanaConnection } = useConnection();
145
- const solanaWallet = useWallet();
146
- const solanaProvider = useAnchorProvider();
147
- useEffect(() => {
148
- if (solanaConnection) {
149
- SolanaXService.getInstance().connection = solanaConnection;
150
- }
151
- }, [solanaConnection]);
152
- useEffect(() => {
153
- if (solanaWallet) {
154
- SolanaXService.getInstance().wallet = solanaWallet;
155
- }
156
- }, [solanaWallet]);
157
- useEffect(() => {
158
- if (solanaProvider) {
159
- SolanaXService.getInstance().provider = solanaProvider;
160
- }
161
- }, [solanaProvider]);
162
-
163
- return <></>;
164
- };