@sodax/wallet-sdk-react 1.5.7-beta → 2.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/README.md +103 -145
  2. package/ai-exported/AGENTS.md +122 -0
  3. package/ai-exported/integration/README.md +102 -0
  4. package/ai-exported/integration/ai-rules.md +136 -0
  5. package/ai-exported/integration/architecture.md +181 -0
  6. package/ai-exported/integration/examples/01-minimal-evm.tsx +75 -0
  7. package/ai-exported/integration/examples/02-multi-chain-modal.tsx +169 -0
  8. package/ai-exported/integration/examples/03-nextjs-app-router.tsx +99 -0
  9. package/ai-exported/integration/examples/04-walletconnect-setup.tsx +89 -0
  10. package/ai-exported/integration/examples/README.md +29 -0
  11. package/ai-exported/integration/recipes/batch-operations.md +223 -0
  12. package/ai-exported/integration/recipes/bridge-to-sdk.md +164 -0
  13. package/ai-exported/integration/recipes/chain-detection.md +254 -0
  14. package/ai-exported/integration/recipes/connect-button.md +156 -0
  15. package/ai-exported/integration/recipes/multi-chain-modal.md +199 -0
  16. package/ai-exported/integration/recipes/setup.md +158 -0
  17. package/ai-exported/integration/recipes/sign-message.md +137 -0
  18. package/ai-exported/integration/recipes/sub-path-imports.md +95 -0
  19. package/ai-exported/integration/recipes/switch-chain.md +141 -0
  20. package/ai-exported/integration/recipes/walletconnect-setup.md +139 -0
  21. package/ai-exported/integration/reference/api-surface.md +175 -0
  22. package/ai-exported/integration/reference/chain-support.md +78 -0
  23. package/ai-exported/integration/reference/connectors.md +74 -0
  24. package/ai-exported/integration/reference/hooks.md +204 -0
  25. package/ai-exported/integration/reference/wallet-brands.md +106 -0
  26. package/ai-exported/migration/README.md +49 -0
  27. package/ai-exported/migration/ai-rules.md +144 -0
  28. package/ai-exported/migration/breaking-changes.md +305 -0
  29. package/ai-exported/migration/checklist.md +159 -0
  30. package/ai-exported/migration/recipes/connect-button.md +166 -0
  31. package/ai-exported/migration/recipes/multi-chain-modal.md +244 -0
  32. package/ai-exported/migration/recipes/ssr-setup.md +162 -0
  33. package/ai-exported/migration/recipes/walletconnect-migration.md +168 -0
  34. package/ai-exported/migration/reference/components.md +73 -0
  35. package/ai-exported/migration/reference/config.md +307 -0
  36. package/ai-exported/migration/reference/hooks.md +278 -0
  37. package/ai-exported/migration/reference/imports.md +157 -0
  38. package/dist/XConnector-B9YQTVJ4.d.ts +146 -0
  39. package/dist/chunk-2BOUGCJ7.mjs +150 -0
  40. package/dist/chunk-2BOUGCJ7.mjs.map +1 -0
  41. package/dist/chunk-66BAUK56.mjs +202 -0
  42. package/dist/chunk-66BAUK56.mjs.map +1 -0
  43. package/dist/chunk-7ULB6DW4.mjs +102 -0
  44. package/dist/chunk-7ULB6DW4.mjs.map +1 -0
  45. package/dist/chunk-BKJB527E.mjs +125 -0
  46. package/dist/chunk-BKJB527E.mjs.map +1 -0
  47. package/dist/chunk-BXJLBR4G.mjs +88 -0
  48. package/dist/chunk-BXJLBR4G.mjs.map +1 -0
  49. package/dist/chunk-E5IAZ7E6.mjs +186 -0
  50. package/dist/chunk-E5IAZ7E6.mjs.map +1 -0
  51. package/dist/chunk-MAQ47Q52.mjs +33 -0
  52. package/dist/chunk-MAQ47Q52.mjs.map +1 -0
  53. package/dist/chunk-MXZVF5HR.mjs +34 -0
  54. package/dist/chunk-MXZVF5HR.mjs.map +1 -0
  55. package/dist/chunk-N5A2TMF6.mjs +33 -0
  56. package/dist/chunk-N5A2TMF6.mjs.map +1 -0
  57. package/dist/chunk-NY7U7OJW.mjs +64 -0
  58. package/dist/chunk-NY7U7OJW.mjs.map +1 -0
  59. package/dist/chunk-PJLEJVAU.mjs +140 -0
  60. package/dist/chunk-PJLEJVAU.mjs.map +1 -0
  61. package/dist/chunk-PLCA4ZDJ.mjs +1585 -0
  62. package/dist/chunk-PLCA4ZDJ.mjs.map +1 -0
  63. package/dist/chunk-TZMKDXFA.mjs +3 -0
  64. package/dist/chunk-TZMKDXFA.mjs.map +1 -0
  65. package/dist/chunk-X2MHIWXO.mjs +100 -0
  66. package/dist/chunk-X2MHIWXO.mjs.map +1 -0
  67. package/dist/chunk-XZ7CHO2S.mjs +41 -0
  68. package/dist/chunk-XZ7CHO2S.mjs.map +1 -0
  69. package/dist/config-OlnzyEUE.d.ts +146 -0
  70. package/dist/index.cjs +2784 -1594
  71. package/dist/index.cjs.map +1 -1
  72. package/dist/index.d.ts +768 -1498
  73. package/dist/index.mjs +463 -2004
  74. package/dist/index.mjs.map +1 -1
  75. package/dist/xchains/bitcoin/index.cjs +1927 -0
  76. package/dist/xchains/bitcoin/index.cjs.map +1 -0
  77. package/dist/xchains/bitcoin/index.d.ts +125 -0
  78. package/dist/xchains/bitcoin/index.mjs +16 -0
  79. package/dist/xchains/bitcoin/index.mjs.map +1 -0
  80. package/dist/xchains/evm/index.cjs +316 -0
  81. package/dist/xchains/evm/index.cjs.map +1 -0
  82. package/dist/xchains/evm/index.d.ts +39 -0
  83. package/dist/xchains/evm/index.mjs +5 -0
  84. package/dist/xchains/evm/index.mjs.map +1 -0
  85. package/dist/xchains/icon/index.cjs +311 -0
  86. package/dist/xchains/icon/index.cjs.map +1 -0
  87. package/dist/xchains/icon/index.d.ts +37 -0
  88. package/dist/xchains/icon/index.mjs +7 -0
  89. package/dist/xchains/icon/index.mjs.map +1 -0
  90. package/dist/xchains/injective/index.cjs +223 -0
  91. package/dist/xchains/injective/index.cjs.map +1 -0
  92. package/dist/xchains/injective/index.d.ts +35 -0
  93. package/dist/xchains/injective/index.mjs +5 -0
  94. package/dist/xchains/injective/index.mjs.map +1 -0
  95. package/dist/xchains/near/index.cjs +190 -0
  96. package/dist/xchains/near/index.cjs.map +1 -0
  97. package/dist/xchains/near/index.d.ts +34 -0
  98. package/dist/xchains/near/index.mjs +6 -0
  99. package/dist/xchains/near/index.mjs.map +1 -0
  100. package/dist/xchains/solana/index.cjs +186 -0
  101. package/dist/xchains/solana/index.cjs.map +1 -0
  102. package/dist/xchains/solana/index.d.ts +26 -0
  103. package/dist/xchains/solana/index.mjs +7 -0
  104. package/dist/xchains/solana/index.mjs.map +1 -0
  105. package/dist/xchains/stacks/index.cjs +240 -0
  106. package/dist/xchains/stacks/index.cjs.map +1 -0
  107. package/dist/xchains/stacks/index.d.ts +36 -0
  108. package/dist/xchains/stacks/index.mjs +5 -0
  109. package/dist/xchains/stacks/index.mjs.map +1 -0
  110. package/dist/xchains/stellar/index.cjs +322 -0
  111. package/dist/xchains/stellar/index.cjs.map +1 -0
  112. package/dist/xchains/stellar/index.d.ts +44 -0
  113. package/dist/xchains/stellar/index.mjs +6 -0
  114. package/dist/xchains/stellar/index.mjs.map +1 -0
  115. package/dist/xchains/sui/index.cjs +248 -0
  116. package/dist/xchains/sui/index.cjs.map +1 -0
  117. package/dist/xchains/sui/index.d.ts +37 -0
  118. package/dist/xchains/sui/index.mjs +7 -0
  119. package/dist/xchains/sui/index.mjs.map +1 -0
  120. package/docs/ADDING_A_NEW_CHAIN.md +440 -0
  121. package/docs/ARCHITECTURE.md +291 -0
  122. package/docs/BATCH_OPERATIONS.md +267 -0
  123. package/docs/CHAIN_DETECTION.md +216 -0
  124. package/docs/CONFIGURE_PROVIDER.md +360 -0
  125. package/docs/CONNECTORS.md +247 -0
  126. package/docs/CONNECT_FLOW.md +276 -0
  127. package/docs/EVM_SWITCH_CHAIN.md +161 -0
  128. package/docs/SIGN_MESSAGE.md +213 -0
  129. package/docs/SUB_PATH_EXPORTS.md +246 -0
  130. package/docs/WALLETCONNECT.md +154 -0
  131. package/docs/WALLET_MODAL.md +331 -0
  132. package/docs/WALLET_PROVIDER_BRIDGE.md +226 -0
  133. package/package.json +37 -12
  134. package/skills/SKILLS.md +84 -0
  135. package/skills/bridge-to-sdk.md +148 -0
  136. package/skills/connect-button.md +116 -0
  137. package/skills/evm-only-walletconnect.md +111 -0
  138. package/skills/multi-chain-modal.md +178 -0
  139. package/skills/setup.md +107 -0
  140. package/dist/index.d.cts +0 -1579
  141. package/src/Hydrate.ts +0 -65
  142. package/src/SodaxWalletProvider.tsx +0 -97
  143. package/src/actions/getXChainType.ts +0 -8
  144. package/src/actions/getXService.ts +0 -33
  145. package/src/actions/index.ts +0 -2
  146. package/src/assets/wallets/hana.svg +0 -6
  147. package/src/assets/wallets/havah.svg +0 -76
  148. package/src/assets/wallets/keplr.svg +0 -30
  149. package/src/assets/wallets/metamask.svg +0 -60
  150. package/src/assets/wallets/phantom.svg +0 -4
  151. package/src/assets/wallets/sui.svg +0 -20
  152. package/src/core/XConnector.ts +0 -54
  153. package/src/core/XService.ts +0 -85
  154. package/src/core/index.ts +0 -2
  155. package/src/hooks/index.ts +0 -11
  156. package/src/hooks/useEthereumChainId.ts +0 -44
  157. package/src/hooks/useEvmSwitchChain.ts +0 -91
  158. package/src/hooks/useWalletProvider.ts +0 -206
  159. package/src/hooks/useXAccount.ts +0 -51
  160. package/src/hooks/useXAccounts.ts +0 -56
  161. package/src/hooks/useXBalances.ts +0 -65
  162. package/src/hooks/useXConnect.ts +0 -118
  163. package/src/hooks/useXConnection.ts +0 -72
  164. package/src/hooks/useXConnectors.ts +0 -72
  165. package/src/hooks/useXDisconnect.ts +0 -73
  166. package/src/hooks/useXService.ts +0 -8
  167. package/src/hooks/useXSignMessage.ts +0 -82
  168. package/src/index.ts +0 -19
  169. package/src/types/index.ts +0 -22
  170. package/src/useXWagmiStore.ts +0 -116
  171. package/src/utils/index.ts +0 -21
  172. package/src/xchains/bitcoin/BitcoinXConnector.ts +0 -34
  173. package/src/xchains/bitcoin/BitcoinXService.ts +0 -40
  174. package/src/xchains/bitcoin/OKXXConnector.ts +0 -117
  175. package/src/xchains/bitcoin/UnisatXConnector.ts +0 -117
  176. package/src/xchains/bitcoin/XverseXConnector.ts +0 -232
  177. package/src/xchains/bitcoin/index.ts +0 -7
  178. package/src/xchains/bitcoin/useBitcoinXConnectors.ts +0 -14
  179. package/src/xchains/evm/EvmXConnector.ts +0 -27
  180. package/src/xchains/evm/EvmXService.ts +0 -211
  181. package/src/xchains/evm/index.ts +0 -3
  182. package/src/xchains/icon/IconHanaXConnector.ts +0 -39
  183. package/src/xchains/icon/IconXService.ts +0 -117
  184. package/src/xchains/icon/actions.ts +0 -28
  185. package/src/xchains/icon/iconex/index.tsx +0 -46
  186. package/src/xchains/icon/index.ts +0 -2
  187. package/src/xchains/injective/InjectiveXConnector.ts +0 -60
  188. package/src/xchains/injective/InjectiveXService.ts +0 -62
  189. package/src/xchains/injective/actions.ts +0 -32
  190. package/src/xchains/injective/index.ts +0 -2
  191. package/src/xchains/near/NearXConnector.ts +0 -42
  192. package/src/xchains/near/NearXService.ts +0 -46
  193. package/src/xchains/near/useNearXConnectors.ts +0 -23
  194. package/src/xchains/solana/SolanaXConnector.ts +0 -26
  195. package/src/xchains/solana/SolanaXService.ts +0 -46
  196. package/src/xchains/solana/index.ts +0 -2
  197. package/src/xchains/stacks/StacksXConnector.ts +0 -63
  198. package/src/xchains/stacks/StacksXService.ts +0 -59
  199. package/src/xchains/stacks/constants.ts +0 -42
  200. package/src/xchains/stacks/index.ts +0 -4
  201. package/src/xchains/stacks/useStacksXConnectors.ts +0 -7
  202. package/src/xchains/stellar/CustomSorobanServer.ts +0 -93
  203. package/src/xchains/stellar/StellarWalletsKitXConnector.ts +0 -53
  204. package/src/xchains/stellar/StellarXService.ts +0 -93
  205. package/src/xchains/stellar/actions.ts +0 -24
  206. package/src/xchains/stellar/index.tsx +0 -2
  207. package/src/xchains/stellar/useStellarXConnectors.ts +0 -21
  208. package/src/xchains/stellar/utils.ts +0 -49
  209. package/src/xchains/sui/SuiXConnector.ts +0 -28
  210. package/src/xchains/sui/SuiXService.ts +0 -66
  211. package/src/xchains/sui/index.ts +0 -2
@@ -1,118 +0,0 @@
1
- import type { XAccount } from '@/types';
2
- import { useConnectWallet } from '@mysten/dapp-kit';
3
- import { useWallet } from '@solana/wallet-adapter-react';
4
- import { useMutation, type UseMutationResult } from '@tanstack/react-query';
5
- import { useConnect } from 'wagmi';
6
- import type { XConnector } from '../core/XConnector';
7
- import { useXWagmiStore } from '../useXWagmiStore';
8
- import type { EvmXConnector } from '../xchains/evm';
9
- import type { SolanaXConnector } from '../xchains/solana';
10
- import type { SuiXConnector } from '../xchains/sui';
11
-
12
- /**
13
- * Hook for connecting to various blockchain wallets across different chains
14
- *
15
- * Handles connection logic for EVM, SUI, Solana and other supported chains.
16
- * Sets up wallet connections and stores connection state in XWagmiStore.
17
- *
18
- * @param {void} - No parameters required
19
- * @returns {UseMutationResult<XAccount | undefined, Error, XConnector>} Mutation result containing:
20
- * - mutateAsync: Function to connect a wallet
21
- * - isPending: Boolean indicating if connection is in progress
22
- * - error: Any error that occurred
23
- * - data: Connected account data if successful
24
- *
25
- * @example
26
- * ```ts
27
- * const { mutateAsync: connect, isPending } = useXConnect();
28
- *
29
- * const handleConnect = async (connector: XConnector) => {
30
- * try {
31
- * await connect(connector);
32
- * } catch (err) {
33
- * console.error(err);
34
- * }
35
- * };
36
- * ```
37
- */
38
- export function useXConnect(): UseMutationResult<XAccount | undefined, Error, XConnector> {
39
- const setXConnection = useXWagmiStore(state => state.setXConnection);
40
-
41
- const { connectAsync: evmConnectAsync } = useConnect();
42
- const { mutateAsync: suiConnectAsync } = useConnectWallet();
43
-
44
- const { select, connect } = useWallet();
45
-
46
- return useMutation({
47
- mutationFn: async (xConnector: XConnector) => {
48
- const xChainType = xConnector.xChainType;
49
- let xAccount: XAccount | undefined;
50
-
51
- switch (xChainType) {
52
- case 'EVM':
53
- await evmConnectAsync({ connector: (xConnector as EvmXConnector).connector });
54
- break;
55
- case 'SUI':
56
- await suiConnectAsync({ wallet: (xConnector as SuiXConnector).wallet });
57
- break;
58
- case 'SOLANA': {
59
- const walletName = (xConnector as SolanaXConnector).wallet.adapter.name;
60
-
61
- select(walletName);
62
-
63
- const adapter = (xConnector as SolanaXConnector).wallet.adapter;
64
-
65
- if (!adapter) throw new Error('No adapter found for Solana wallet');
66
-
67
- if (walletName === 'MetaMask') {
68
- await new Promise<void>((resolve, reject) => {
69
- const timeout = setTimeout(() => {
70
- cleanup();
71
- reject(new Error('Wallet connection timeout'));
72
- }, 30000);
73
-
74
- const handleConnect = () => {
75
- cleanup();
76
- resolve();
77
- };
78
-
79
- const handleError = (error: Error) => {
80
- cleanup();
81
- reject(error);
82
- };
83
-
84
- const cleanup = () => {
85
- clearTimeout(timeout);
86
- adapter.off('connect', handleConnect);
87
- adapter.off('error', handleError);
88
- };
89
-
90
- adapter.on('connect', handleConnect);
91
- adapter.on('error', handleError);
92
-
93
- connect().catch(err => {
94
- cleanup();
95
- reject(err);
96
- });
97
- });
98
- }
99
-
100
- break;
101
- }
102
-
103
- default:
104
- xAccount = await xConnector.connect();
105
- break;
106
- }
107
-
108
- if (xAccount) {
109
- setXConnection(xConnector.xChainType, {
110
- xAccount,
111
- xConnectorId: xConnector.id,
112
- });
113
- }
114
-
115
- return xAccount;
116
- },
117
- });
118
- }
@@ -1,72 +0,0 @@
1
- import type { ChainType } from '@sodax/types';
2
- import { useCurrentAccount, useCurrentWallet } from '@mysten/dapp-kit';
3
- import { useWallet } from '@solana/wallet-adapter-react';
4
- import { useMemo } from 'react';
5
- import { useAccount, useConnections } from 'wagmi';
6
- import type { XConnection } from '../types';
7
- import { useXWagmiStore } from '../useXWagmiStore';
8
-
9
- /**
10
- * Hook for accessing connection details for a specific blockchain
11
- *
12
- * Retrieves the current connection state for the specified chain type,
13
- * including the connected account and connector ID.
14
- *
15
- * @param {ChainType} xChainType - The type of blockchain to get connection details for
16
- * @returns {XConnection | undefined} Connection details including account and connector ID, or undefined if not connected
17
- *
18
- * @example
19
- * ```ts
20
- * const connection = useXConnection('EVM');
21
- *
22
- * if (connection) {
23
- * console.log('Connected account:', connection.xAccount.address);
24
- * console.log('Using connector:', connection.xConnectorId);
25
- * }
26
- * ```
27
- */
28
- export function useXConnection(xChainType: ChainType | undefined): XConnection | undefined {
29
- const xConnection = useXWagmiStore(state => (xChainType ? state.xConnections?.[xChainType] : undefined));
30
-
31
- const evmConnections = useConnections();
32
- const { address: evmAddress } = useAccount();
33
- const suiAccount = useCurrentAccount();
34
- const suiCurrentWallet = useCurrentWallet();
35
- const solanaWallet = useWallet();
36
-
37
- const xConnection2 = useMemo(() => {
38
- if (!xChainType) {
39
- return undefined;
40
- }
41
-
42
- switch (xChainType) {
43
- case 'EVM':
44
- return {
45
- xAccount: { address: evmAddress as string, xChainType },
46
- xConnectorId: evmConnections?.[0]?.connector.id,
47
- };
48
-
49
- case 'SUI':
50
- if (suiCurrentWallet.currentWallet && suiCurrentWallet.connectionStatus === 'connected') {
51
- return {
52
- xAccount: { address: suiAccount?.address, xChainType },
53
- xConnectorId: suiCurrentWallet.currentWallet.name,
54
- };
55
- }
56
- return undefined;
57
-
58
- case 'SOLANA':
59
- if (solanaWallet.connected) {
60
- return {
61
- xAccount: { address: solanaWallet.publicKey?.toString(), xChainType },
62
- xConnectorId: `${solanaWallet.wallet?.adapter.name}`,
63
- };
64
- }
65
- return undefined;
66
- default:
67
- return xConnection;
68
- }
69
- }, [xChainType, xConnection, evmAddress, suiAccount, evmConnections, suiCurrentWallet, solanaWallet]);
70
-
71
- return xConnection2;
72
- }
@@ -1,72 +0,0 @@
1
- import type { ChainType } from '@sodax/types';
2
- import { useWallets } from '@mysten/dapp-kit';
3
- import { useWallet } from '@solana/wallet-adapter-react';
4
- import { useMemo } from 'react';
5
- import { useConnectors } from 'wagmi';
6
- import type { XConnector } from '../core';
7
- import { EvmXConnector } from '../xchains/evm';
8
- import { SolanaXConnector } from '../xchains/solana';
9
- import { useStellarXConnectors } from '../xchains/stellar/useStellarXConnectors';
10
- import { SuiXConnector } from '../xchains/sui';
11
- import { useXService } from './useXService';
12
- import { useNearXConnectors } from '../xchains/near/useNearXConnectors';
13
- import { useStacksXConnectors } from '../xchains/stacks/useStacksXConnectors';
14
-
15
- /**
16
- * Hook to retrieve available wallet connectors for a specific blockchain type.
17
- *
18
- * This hook aggregates wallet connectors from different blockchain ecosystems:
19
- * - EVM: Uses wagmi connectors
20
- * - Sui: Uses Sui wallet adapters
21
- * - Stellar: Uses custom Stellar connectors
22
- * - Solana: Uses Solana wallet adapters (filtered to installed wallets only)
23
- *
24
- * @param xChainType - The blockchain type to get connectors for ('EVM' | 'SUI' | 'STELLAR' | 'SOLANA' | 'NEAR' | 'STACKS')
25
- * @returns An array of XConnector instances compatible with the specified chain type
26
- */
27
-
28
- export function useXConnectors(xChainType: ChainType | undefined): XConnector[] {
29
- const xService = useXService(xChainType);
30
- const evmConnectors = useConnectors();
31
- const suiWallets = useWallets();
32
- const { data: stellarXConnectors } = useStellarXConnectors();
33
- const { data: nearXConnectors } = useNearXConnectors();
34
- const stacksXConnectors = useStacksXConnectors();
35
- const { wallets: solanaWallets } = useWallet();
36
-
37
- const xConnectors = useMemo((): XConnector[] => {
38
- if (!xChainType || !xService) {
39
- return [];
40
- }
41
-
42
- switch (xChainType) {
43
- case 'EVM':
44
- return evmConnectors.map(connector => new EvmXConnector(connector));
45
- case 'SUI':
46
- return suiWallets.map(wallet => new SuiXConnector(wallet));
47
- case 'STELLAR':
48
- return stellarXConnectors || [];
49
- case 'SOLANA':
50
- return solanaWallets
51
- .filter(wallet => wallet.readyState === 'Installed')
52
- .map(wallet => new SolanaXConnector(wallet));
53
- case 'NEAR':
54
- return nearXConnectors || [];
55
- case 'STACKS':
56
- return stacksXConnectors;
57
- default:
58
- return xService.getXConnectors();
59
- }
60
- }, [
61
- xService,
62
- xChainType,
63
- evmConnectors,
64
- suiWallets,
65
- stellarXConnectors,
66
- solanaWallets,
67
- nearXConnectors,
68
- stacksXConnectors,
69
- ]);
70
-
71
- return xConnectors;
72
- }
@@ -1,73 +0,0 @@
1
- import type { ChainType } from '@sodax/types';
2
- import { useDisconnectWallet } from '@mysten/dapp-kit';
3
- import { useWallet } from '@solana/wallet-adapter-react';
4
- import { useCallback } from 'react';
5
- import { useDisconnect } from 'wagmi';
6
- import { getXService } from '../actions';
7
- import { useXWagmiStore } from '../useXWagmiStore';
8
- import type { NearXService } from '@/xchains/near/NearXService';
9
-
10
- /**
11
- * Hook for disconnecting from a specific blockchain wallet
12
- *
13
- * Handles disconnection logic for EVM, SUI, Solana and other supported chains.
14
- * Clears connection state from XWagmiStore.
15
- *
16
- * @param {void} - No parameters required
17
- * @returns {(xChainType: ChainType) => Promise<void>} Async function that disconnects from the specified chain
18
- *
19
- * @example
20
- * ```ts
21
- * const disconnect = useXDisconnect();
22
- *
23
- * const handleDisconnect = async (xChainType: ChainType) => {
24
- * await disconnect(xChainType);
25
- * };
26
- * ```
27
- */
28
- export function useXDisconnect(): (xChainType: ChainType) => Promise<void> {
29
- // Get connection state and disconnect handler from store
30
- const xConnections = useXWagmiStore(state => state.xConnections);
31
- const unsetXConnection = useXWagmiStore(state => state.unsetXConnection);
32
-
33
- // Get chain-specific disconnect handlers
34
- const { disconnectAsync } = useDisconnect();
35
- const { mutateAsync: suiDisconnectAsync } = useDisconnectWallet();
36
- const solanaWallet = useWallet();
37
-
38
- return useCallback(
39
- async (xChainType: ChainType) => {
40
- // Handle disconnection based on chain type
41
- switch (xChainType) {
42
- case 'EVM':
43
- await disconnectAsync();
44
- break;
45
- case 'SUI':
46
- await suiDisconnectAsync();
47
- break;
48
- case 'SOLANA':
49
- await solanaWallet.disconnect();
50
- break;
51
-
52
- case 'NEAR': {
53
- const nearXService = getXService('NEAR') as NearXService;
54
- nearXService.walletSelector.disconnect();
55
- break;
56
- }
57
-
58
- default: {
59
- // Handle other chain types
60
- const xService = getXService(xChainType);
61
- const xConnectorId = xConnections[xChainType]?.xConnectorId;
62
- const xConnector = xConnectorId ? xService.getXConnectorById(xConnectorId) : undefined;
63
- await xConnector?.disconnect();
64
- break;
65
- }
66
- }
67
-
68
- // Clear connection state from store
69
- unsetXConnection(xChainType);
70
- },
71
- [xConnections, unsetXConnection, disconnectAsync, suiDisconnectAsync, solanaWallet],
72
- );
73
- }
@@ -1,8 +0,0 @@
1
- import type { ChainType } from '@sodax/types';
2
- import type { XService } from '../core';
3
- import { useXWagmiStore } from '../useXWagmiStore';
4
-
5
- export function useXService(xChainType: ChainType | undefined): XService | undefined {
6
- const xService = useXWagmiStore(state => (xChainType ? state.xServices[xChainType] : undefined));
7
- return xService;
8
- }
@@ -1,82 +0,0 @@
1
- import { useWallet } from '@solana/wallet-adapter-react';
2
- import { useMutation, type UseMutationResult } from '@tanstack/react-query';
3
- import type { ChainType } from '@sodax/types';
4
- import { useSignMessage } from 'wagmi';
5
- import { useSignPersonalMessage } from '@mysten/dapp-kit';
6
- import { StellarXService } from '@/xchains/stellar';
7
- import { InjectiveXService } from '@/xchains/injective';
8
- import { useXAccount } from './useXAccount';
9
- import { getEthereumAddress } from '@injectivelabs/sdk-ts';
10
- import { Wallet } from '@injectivelabs/wallet-base';
11
-
12
- type SignMessageReturnType = `0x${string}` | Uint8Array | string | undefined;
13
-
14
- export function useXSignMessage(): UseMutationResult<
15
- SignMessageReturnType,
16
- Error,
17
- { xChainType: ChainType; message: string },
18
- unknown
19
- > {
20
- const { signMessage } = useWallet();
21
- const { signMessageAsync: evmSignMessage } = useSignMessage();
22
-
23
- const { mutateAsync: signPersonalMessage } = useSignPersonalMessage();
24
-
25
- const { address: injectiveAddress } = useXAccount('INJECTIVE');
26
-
27
- return useMutation({
28
- mutationFn: async ({ xChainType, message }: { xChainType: ChainType; message: string }) => {
29
- let signature: SignMessageReturnType;
30
-
31
- switch (xChainType) {
32
- case 'EVM': {
33
- signature = await evmSignMessage({ message });
34
- break;
35
- }
36
- case 'SUI': {
37
- const res = await signPersonalMessage({ message: new Uint8Array(new TextEncoder().encode(message)) });
38
- signature = res.signature;
39
- break;
40
- }
41
- case 'SOLANA': {
42
- if (!signMessage) {
43
- throw new Error('Solana wallet not connected');
44
- }
45
- signature = await signMessage(new TextEncoder().encode(message));
46
- break;
47
- }
48
-
49
- case 'STELLAR': {
50
- const res = await StellarXService.getInstance().walletsKit.signMessage(message);
51
- signature = res.signedMessage;
52
- break;
53
- }
54
-
55
- case 'INJECTIVE': {
56
- if (!injectiveAddress) {
57
- throw new Error('Injective address not found');
58
- }
59
-
60
- const ethereumAddress = getEthereumAddress(injectiveAddress);
61
- const walletStrategy = InjectiveXService.getInstance().walletStrategy;
62
- const res = await walletStrategy.signArbitrary(
63
- walletStrategy.getWallet() === Wallet.Metamask ? ethereumAddress : injectiveAddress,
64
- message,
65
- );
66
-
67
- if (!res) {
68
- throw new Error('Injective signature not found');
69
- }
70
- signature = res;
71
- break;
72
- }
73
-
74
- default:
75
- console.warn('Unsupported chain type');
76
- break;
77
- }
78
-
79
- return signature;
80
- },
81
- });
82
- }
package/src/index.ts DELETED
@@ -1,19 +0,0 @@
1
- export * from './actions';
2
- export * from './core';
3
-
4
- export * from './utils';
5
-
6
- export * from './xchains/bitcoin';
7
- export * from './xchains/evm';
8
- export * from './xchains/icon';
9
- export * from './xchains/injective';
10
- export * from './xchains/solana';
11
- export * from './xchains/stellar';
12
- export * from './xchains/sui';
13
- export * from './xchains/stacks';
14
- export * from './hooks';
15
- export * from './useXWagmiStore';
16
- export * from './SodaxWalletProvider';
17
-
18
- export * from './types';
19
- export type * from './types';
@@ -1,22 +0,0 @@
1
- import type { ChainType } from '@sodax/types';
2
-
3
- export type XAccount = {
4
- address: string | undefined;
5
- xChainType: ChainType | undefined;
6
- publicKey?: string;
7
- };
8
-
9
- export type XConnection = {
10
- xAccount: XAccount;
11
- xConnectorId: string;
12
- };
13
-
14
- export type CurrencyKey = string;
15
-
16
- export enum WalletId {
17
- METAMASK = 'metamask',
18
- HANA = 'hana',
19
- PHANTOM = 'phantom',
20
- SUI = 'sui',
21
- KEPLR = 'keplr',
22
- }
@@ -1,116 +0,0 @@
1
- 'use client';
2
-
3
- import type { ChainType } from '@sodax/types';
4
- import { create } from 'zustand';
5
- import { createJSONStorage, persist, devtools } from 'zustand/middleware';
6
- import { immer } from 'zustand/middleware/immer';
7
- import type { XService } from './core';
8
- import type { XConnection } from './types';
9
- import { EvmXService } from './xchains/evm';
10
- import { InjectiveXConnector, InjectiveXService } from './xchains/injective';
11
- import { Wallet } from '@injectivelabs/wallet-base';
12
- import { SolanaXService } from './xchains/solana/SolanaXService';
13
- import { StellarXService } from './xchains/stellar';
14
- import { SuiXService } from './xchains/sui';
15
- import { IconXService } from './xchains/icon';
16
- import { IconHanaXConnector } from './xchains/icon/IconHanaXConnector';
17
- import { BitcoinXService } from './xchains/bitcoin';
18
- import { UnisatXConnector } from './xchains/bitcoin/UnisatXConnector';
19
- import { XverseXConnector } from './xchains/bitcoin/XverseXConnector';
20
- import { OKXXConnector } from './xchains/bitcoin/OKXXConnector';
21
- import { NearXService } from './xchains/near/NearXService';
22
- import { StacksXService, StacksXConnector, STACKS_PROVIDERS } from './xchains/stacks';
23
-
24
- type XWagmiStore = {
25
- xServices: Partial<Record<ChainType, XService>>;
26
- xConnections: Partial<Record<ChainType, XConnection>>;
27
-
28
- setXConnection: (xChainType: ChainType, xConnection: XConnection) => void;
29
- unsetXConnection: (xChainType: ChainType) => void;
30
- };
31
-
32
- const initXServices = () => {
33
- const xServices = {};
34
- ['EVM', 'BITCOIN', 'INJECTIVE', 'STELLAR', 'SUI', 'SOLANA', 'ICON', 'NEAR', 'STACKS'].forEach(key => {
35
- const xChainType = key as ChainType;
36
-
37
- switch (xChainType) {
38
- // EVM, SUI, Solana wallet connectors are supported by their own sdks. wagmi, @mysten/dapp-kit, @solana/wallet-adapter-react.
39
- case 'EVM':
40
- xServices[xChainType] = EvmXService.getInstance();
41
- xServices[xChainType].setXConnectors([]);
42
- break;
43
- case 'SUI':
44
- xServices[xChainType] = SuiXService.getInstance();
45
- xServices[xChainType].setXConnectors([]);
46
- break;
47
- case 'SOLANA':
48
- xServices[xChainType] = SolanaXService.getInstance();
49
- xServices[xChainType].setXConnectors([]);
50
- break;
51
- case 'BITCOIN':
52
- xServices[xChainType] = BitcoinXService.getInstance();
53
- xServices[xChainType].setXConnectors([new UnisatXConnector(), new XverseXConnector(), new OKXXConnector()]);
54
- break;
55
-
56
- // Injective, Stellar, Icon wallet connectors are supported by sodax wallet-sdk-react sdk.
57
- case 'INJECTIVE':
58
- xServices[xChainType] = InjectiveXService.getInstance();
59
- xServices[xChainType].setXConnectors([
60
- // EVM wallets (auto-detected via EIP-6963)
61
- new InjectiveXConnector('MetaMask', Wallet.Metamask),
62
- // Cosmos wallets (detected via window globals)
63
- new InjectiveXConnector('Keplr', Wallet.Keplr),
64
- new InjectiveXConnector('Leap', Wallet.Leap),
65
- ]);
66
- break;
67
- case 'STELLAR':
68
- xServices[xChainType] = StellarXService.getInstance();
69
- xServices[xChainType].setXConnectors([]);
70
- break;
71
- case 'ICON':
72
- xServices[xChainType] = IconXService.getInstance();
73
- xServices[xChainType].setXConnectors([new IconHanaXConnector()]);
74
- break;
75
- case 'NEAR':
76
- xServices[xChainType] = NearXService.getInstance();
77
- xServices[xChainType].setXConnectors([]);
78
- break;
79
- case 'STACKS':
80
- xServices[xChainType] = StacksXService.getInstance();
81
- xServices[xChainType].setXConnectors(STACKS_PROVIDERS.map(config => new StacksXConnector(config)));
82
- break;
83
- default:
84
- break;
85
- }
86
- });
87
-
88
- return xServices;
89
- };
90
-
91
- export const useXWagmiStore = create<XWagmiStore>()(
92
- devtools(
93
- persist(
94
- immer((set, get) => ({
95
- xServices: initXServices(),
96
- xConnections: {},
97
- setXConnection: (xChainType: ChainType, xConnection: XConnection) => {
98
- set(state => {
99
- state.xConnections[xChainType] = xConnection;
100
- });
101
- },
102
- unsetXConnection: (xChainType: ChainType) => {
103
- set(state => {
104
- delete state.xConnections[xChainType];
105
- });
106
- },
107
- })),
108
- {
109
- name: 'xwagmi-store',
110
- storage: createJSONStorage(() => localStorage),
111
- partialize: state => ({ xConnections: state.xConnections }),
112
- },
113
- ),
114
- { name: 'xwagmi-store' },
115
- ),
116
- );
@@ -1,21 +0,0 @@
1
- import { baseChainInfo, type ChainId, type XToken } from '@sodax/types';
2
-
3
- export const isNativeToken = (xToken: XToken) => {
4
- const nativeAddresses = [
5
- 'cx0000000000000000000000000000000000000000',
6
- '0x0000000000000000000000000000000000000000',
7
- 'inj',
8
- '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI',
9
- 'hx0000000000000000000000000000000000000000',
10
- '11111111111111111111111111111111', // solana
11
- 'CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA', // stellar
12
- 'ST000000000000000000002AMW42H.nativetoken', // stacks
13
- '0:0', // bitcoin
14
- ];
15
-
16
- return nativeAddresses.includes(xToken.address);
17
- };
18
-
19
- export const getWagmiChainId = (xChainId: ChainId): number => {
20
- return baseChainInfo[xChainId].chainId as number;
21
- };
@@ -1,34 +0,0 @@
1
- import { XConnector } from '@/core';
2
- import type { XAccount } from '@/types';
3
- import type { IBitcoinWalletProvider } from '@sodax/types';
4
- import { BitcoinXService } from './BitcoinXService';
5
-
6
- /**
7
- * Abstract base class for Bitcoin wallet connectors.
8
- * Subclasses implement wallet-specific connection logic (Unisat, Xverse, OKX).
9
- */
10
- export abstract class BitcoinXConnector extends XConnector {
11
- constructor(name: string, id: string) {
12
- super('BITCOIN', name, id);
13
- }
14
-
15
- getXService(): BitcoinXService {
16
- return BitcoinXService.getInstance();
17
- }
18
-
19
- abstract connect(): Promise<XAccount | undefined>;
20
- abstract disconnect(): Promise<void>;
21
-
22
- /**
23
- * Returns an IBitcoinWalletProvider instance after connecting.
24
- * Used by useSpokeProvider to build BitcoinSpokeProvider.
25
- */
26
- abstract getWalletProvider(): IBitcoinWalletProvider | undefined;
27
-
28
- /**
29
- * Recreates a walletProvider from the browser extension window object
30
- * and stored xAccount data (no connect() call, no popup).
31
- * Used to restore provider after page reload without requiring reconnect.
32
- */
33
- abstract recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined;
34
- }
@@ -1,40 +0,0 @@
1
- import { XService } from '@/core/XService';
2
- import { isNativeToken } from '@/utils';
3
- import type { XToken } from '@sodax/types';
4
-
5
- export class BitcoinXService extends XService {
6
- private static instance: BitcoinXService;
7
- private rpcUrl: string;
8
-
9
- private constructor(rpcUrl = 'https://mempool.space/api') {
10
- super('BITCOIN');
11
- this.rpcUrl = rpcUrl;
12
- }
13
-
14
- public static getInstance(rpcUrl?: string): BitcoinXService {
15
- if (!BitcoinXService.instance) {
16
- BitcoinXService.instance = new BitcoinXService(rpcUrl);
17
- } else if (rpcUrl && rpcUrl !== BitcoinXService.instance.rpcUrl) {
18
- BitcoinXService.instance.rpcUrl = rpcUrl;
19
- }
20
- return BitcoinXService.instance;
21
- }
22
-
23
- async getBalance(address: string | undefined, xToken: XToken): Promise<bigint> {
24
- if (!address) return 0n;
25
-
26
- try {
27
- if (isNativeToken(xToken)) {
28
- const response = await fetch(`${this.rpcUrl}/address/${address}/utxo`);
29
- if (!response.ok) return 0n;
30
- const utxos: Array<{ value: number }> = await response.json();
31
- const totalBalance = utxos.reduce((sum, utxo) => sum + utxo.value, 0);
32
- return BigInt(totalBalance);
33
- }
34
- } catch {
35
- return 0n;
36
- }
37
-
38
- return 0n;
39
- }
40
- }