@sodax/wallet-sdk-react 1.5.6-beta → 2.0.0-rc.1

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 +34 -9
  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
@@ -0,0 +1,278 @@
1
+ # Reference: Hook Signature Map
2
+
3
+ Per-hook signature changes for v1 → v2. See [`../breaking-changes.md`](../breaking-changes.md) §3 for the WHY.
4
+
5
+ ---
6
+
7
+ ## Quick rule
8
+
9
+ | Pattern | v1 (positional) | v2 (options object) |
10
+ |---|---|---|
11
+ | Pass chain family | `useX('EVM')` | `useX({ xChainType: 'EVM' })` |
12
+ | Pass chain id | `useX('0x1.eth')` | `useX({ xChainId: ChainKeys.ETHEREUM_MAINNET })` |
13
+ | Cannot pass both | (runtime detected) | TypeScript-enforced (`xChainType: never` on the chain-id branch and vice versa) |
14
+
15
+ `xChainId` in v2 is typed as `SpokeChainKey` (the enum from `@sodax/types`), not the raw string id. The narrower type lets v2 hooks return chain-typed providers (e.g. `IEvmWalletProvider | undefined`) instead of the v1 union.
16
+
17
+ ---
18
+
19
+ ## `useXAccount`
20
+
21
+ ```ts
22
+ // v1 ❌
23
+ const { address } = useXAccount('EVM');
24
+ const { address } = useXAccount('0x1.eth');
25
+
26
+ // v2 ✅
27
+ import { ChainKeys } from '@sodax/types';
28
+
29
+ const { address } = useXAccount({ xChainType: 'EVM' });
30
+ const { address } = useXAccount({ xChainId: ChainKeys.ETHEREUM_MAINNET });
31
+ ```
32
+
33
+ **Decision rule (positional value → field name):** v1 accepted both `ChainType` and `ChainId` and detected at runtime. In v2 you must choose the right field:
34
+
35
+ - v1 value is a family literal (`'EVM'`, `'SOLANA'`, …) → v2 `xChainType`.
36
+ - v1 value is a chain-key string (`'0x1.eth'`, `XToken.xChainId`, …) → v2 `xChainId` typed as `SpokeChainKey`.
37
+ - v1 value comes from `getXChainType(...)` (returns `ChainType | undefined`) → v2 `xChainType`, but **guard against `undefined`** — see below.
38
+
39
+ **v2 asserts at runtime that exactly one of `xChainId` / `xChainType` is present.** Both undefined throws `'[useXAccount] pass xChainId or xChainType'`; both present throws `'[useXAccount] pass either xChainId or xChainType, not both'`. v1 was permissive (called with `undefined`, it returned an empty account). v2 is strict.
40
+
41
+ **Common nullable patterns and their fixes:**
42
+
43
+ ```ts
44
+ // ❌ v1 idiom — returns empty account when nothing selected, runs every render
45
+ const { address } = useXAccount(selectedChainId ?? undefined);
46
+
47
+ // ✅ v2 fix 1 — index a snapshot from useXAccounts (no per-key hook call)
48
+ const xAccounts = useXAccounts();
49
+ const chainType = selectedChainId ? getXChainType(selectedChainId) : undefined;
50
+ const address = chainType ? xAccounts[chainType]?.address : undefined;
51
+
52
+ // ✅ v2 fix 2 — supply a sensible default chain key so the hook always has input
53
+ const { address } = useXAccount({
54
+ xChainId: selectedChainId ?? ChainKeys.SONIC_MAINNET,
55
+ });
56
+
57
+ // ✅ v2 fix 3 — split into a child component that only mounts when input is known
58
+ {selectedChainId ? <Account xChainId={selectedChainId} /> : null}
59
+ function Account({ xChainId }: { xChainId: SpokeChainKey }) {
60
+ const { address } = useXAccount({ xChainId });
61
+ // ...
62
+ }
63
+ ```
64
+
65
+ The other "options-object" hooks (`useXConnection`, `useXConnectors`, `useXService`, `useWalletProvider`) are **lenient** — passing no field returns the empty/undefined value silently. `useXAccount` is the only one that asserts.
66
+
67
+ **Other notes:**
68
+ - Return shape unchanged: `XAccount = { address, xChainType, publicKey? }`.
69
+ - When a valid chain is supplied but no wallet is connected, `address` is `undefined` while `xChainType` is filled — same as v1's connected-empty state.
70
+
71
+ ---
72
+
73
+ ## `useXConnectors`
74
+
75
+ ```ts
76
+ // v1 ❌
77
+ const connectors = useXConnectors('EVM');
78
+
79
+ // v2 ✅
80
+ const connectors = useXConnectors({ xChainType: 'EVM' });
81
+ ```
82
+
83
+ **Other notes:**
84
+ - Return type changed from `XConnector[]` to `IXConnector[]` (interface). For most consumers this is invisible — both expose `id`, `name`, `icon`, `xChainType`, `connect()`, `disconnect()`.
85
+ - v2 enriches each connector with `isInstalled`, `installUrl`, `icon` (read at access time from `window.*`).
86
+ - v2 returns `[]` and logs a one-time warning if the chain isn't in `enabledChains`. v1 returned `[]` silently.
87
+
88
+ ---
89
+
90
+ ## `useXConnection`
91
+
92
+ ```ts
93
+ // v1 ❌
94
+ const connection = useXConnection('EVM');
95
+
96
+ // v2 ✅
97
+ const connection = useXConnection({ xChainType: 'EVM' });
98
+ ```
99
+
100
+ Return shape unchanged: `XConnection | undefined = { xAccount, xConnectorId } | undefined`.
101
+
102
+ ---
103
+
104
+ ## `useXService`
105
+
106
+ ```ts
107
+ // v1 ❌
108
+ const service = useXService('EVM');
109
+
110
+ // v2 ✅
111
+ const service = useXService({ xChainType: 'EVM' });
112
+ ```
113
+
114
+ Return type unchanged.
115
+
116
+ ---
117
+
118
+ ## `useWalletProvider`
119
+
120
+ ```ts
121
+ // v1 ❌ — positional spokeChainId, returns wide union
122
+ const wp = useWalletProvider('sui');
123
+
124
+ // v2 ✅ — options object, narrowest type when xChainId is passed
125
+ import { ChainKeys } from '@sodax/types';
126
+
127
+ const wp = useWalletProvider({ xChainId: ChainKeys.SUI_MAINNET });
128
+ // ^ inferred as ISuiWalletProvider | undefined
129
+
130
+ const wp2 = useWalletProvider({ xChainType: 'EVM' });
131
+ // ^ inferred as IEvmWalletProvider | undefined
132
+
133
+ const wp3 = useWalletProvider();
134
+ // ^ inferred as IWalletProvider | undefined (any)
135
+ ```
136
+
137
+ **Other notes:**
138
+ - Pass either `xChainId` (`SpokeChainKey`) or `xChainType` (`ChainType`), never both. Chain key gives narrower TypeScript inference.
139
+ - Returns `undefined` when the chain isn't enabled in `walletConfig` (logs a one-time warning) or when no wallet is connected.
140
+
141
+ ---
142
+
143
+ ## `useXConnect`
144
+
145
+ ```ts
146
+ // v1 ✅ AND v2 ✅ — same signature
147
+ const { mutateAsync: connect } = useXConnect();
148
+ await connect(connector);
149
+ ```
150
+
151
+ No change in shape. The `connector` argument type is `IXConnector` in v2 (was `XConnector` abstract class in v1) — runtime behavior identical for any connector returned by `useXConnectors`.
152
+
153
+ ---
154
+
155
+ ## `useXDisconnect`
156
+
157
+ ```ts
158
+ // v1 ❌ — returned function takes positional ChainType
159
+ const disconnect = useXDisconnect();
160
+ await disconnect('EVM');
161
+
162
+ // v2 ✅ — returned function takes options object
163
+ const disconnect = useXDisconnect();
164
+ await disconnect({ xChainType: 'EVM' });
165
+ ```
166
+
167
+ The hook itself takes no args in both versions. The **returned function** changed: v1 was positional `(xChainType: ChainType) => Promise<void>`; v2 is `(args: UseXDisconnectArgs) => Promise<void>` where `UseXDisconnectArgs = { xChainType: ChainType }`. Same forward-compat reason as the other hooks — see [`../breaking-changes.md`](../breaking-changes.md) §3.
168
+
169
+ **Common breakage:** `await disconnect(xChainType)` raises `TS2345: Argument of type 'string' is not assignable to parameter of type 'UseXDisconnectArgs'`. Wrap in an object.
170
+
171
+ ---
172
+
173
+ ## `useXSignMessage`
174
+
175
+ ```ts
176
+ // v1 ✅ AND v2 ✅ — same signature
177
+ const { mutateAsync: signMessage } = useXSignMessage();
178
+ const sig = await signMessage({ xChainType: 'EVM', message: 'hello' });
179
+ ```
180
+
181
+ No change.
182
+
183
+ ---
184
+
185
+ ## `useXAccounts`
186
+
187
+ ```ts
188
+ // v1
189
+ const accounts = useXAccounts();
190
+
191
+ // v2 — return type is now strictly typed
192
+ const accounts = useXAccounts();
193
+ // → Partial<Record<ChainType, XAccount>>
194
+ ```
195
+
196
+ Call signature unchanged. **Indexing tightened**: `accounts[chainType]` returns `XAccount | undefined`. The index variable must be typed as `ChainType` (not `string` or `any`) — otherwise you'll see `TS7053: Element implicitly has an 'any' type`.
197
+
198
+ ```ts
199
+ // ❌ FAILS — chainType is `string`, can't index Partial<Record<ChainType, ...>>
200
+ const chainType = someStringFromConfig;
201
+ const account = accounts[chainType];
202
+
203
+ // ✅ FIX 1 — narrow with getXChainType (returns ChainType | undefined)
204
+ import { getXChainType } from '@sodax/wallet-sdk-react';
205
+ const chainType = getXChainType(chainId);
206
+ const account = chainType ? accounts[chainType] : undefined;
207
+
208
+ // ✅ FIX 2 — call useXAccount per-chain instead of indexing
209
+ const account = useXAccount({ xChainType: 'EVM' });
210
+ ```
211
+
212
+ ---
213
+
214
+ ## `useEvmSwitchChain`
215
+
216
+ ```ts
217
+ // v1 ❌ — positional `expectedXChainId: ChainId`
218
+ const { isWrongChain, handleSwitchChain } = useEvmSwitchChain(chainId);
219
+
220
+ // v2 ✅ — options object; `xChainId: SpokeChainKey`
221
+ import { ChainKeys } from '@sodax/types';
222
+
223
+ const { isWrongChain, handleSwitchChain } = useEvmSwitchChain({
224
+ xChainId: ChainKeys.ETHEREUM_MAINNET,
225
+ });
226
+
227
+ if (isWrongChain) handleSwitchChain();
228
+ ```
229
+
230
+ **Breaking changes:**
231
+
232
+ - **Call shape**: positional → options object. Same forward-compat reason as the other hooks.
233
+ - **Parameter type**: `ChainId` → `SpokeChainKey` (rename in `@sodax/types`). If the chain key value comes from `XToken.chainKey` (v2) or any `ChainKeys.*` constant, no value change is needed — the rename is type-only.
234
+
235
+ **Return shape is unchanged** — both v1 and v2 return `{ isWrongChain: boolean, handleSwitchChain: () => void }`. The hook compares the connected EVM chain to the chain expected by `xChainId` and exposes `isWrongChain` so UI can render a "switch network" CTA without recomputing.
236
+
237
+ **Behavior added in v2:**
238
+
239
+ - **Injective + MetaMask auto-switch.** When the user connects to Injective via MetaMask, v2 automatically targets Ethereum mainnet underneath. v1 had no Injective awareness.
240
+ - **Safe when EVM is disabled.** v2 returns no-op values (`isWrongChain: false`, `handleSwitchChain: () => {}`) if `walletConfig.EVM` is absent, so UI doesn't need to branch.
241
+
242
+ ---
243
+
244
+ ## `useEthereumChainId`
245
+
246
+ **Removed from the public barrel in v2.** Despite the generic-sounding name, the v1 hook was **Injective + MetaMask specific** — it read the underlying Ethereum chain ID exposed by Injective's wallet strategy and was almost always used to drive the "switch back to Ethereum mainnet" UX. v2 makes the hook internal because `useEvmSwitchChain` now handles that Injective auto-switch case directly.
247
+
248
+ Migration:
249
+
250
+ ```diff
251
+ - // v1 ❌ — manual chain-ID comparison for Injective + MetaMask UX
252
+ - import { useEthereumChainId } from '@sodax/wallet-sdk-react';
253
+ - const chainId = useEthereumChainId();
254
+ - if (chainId !== 1) /* prompt user to switch to Ethereum mainnet */;
255
+ + // v2 ✅ — useEvmSwitchChain auto-handles Injective + MetaMask underneath
256
+ + import { useEvmSwitchChain } from '@sodax/wallet-sdk-react';
257
+ + import { ChainKeys } from '@sodax/types';
258
+ + const { isWrongChain, handleSwitchChain } = useEvmSwitchChain({
259
+ + xChainId: ChainKeys.INJECTIVE_MAINNET,
260
+ + });
261
+ + if (isWrongChain) handleSwitchChain();
262
+ ```
263
+
264
+ If you genuinely need the raw EVM chain ID (rare — almost no usage outside the Injective case), wagmi's `useAccount().chainId` is the underlying source. Prefer staying inside `@sodax/wallet-sdk-react` hooks where possible.
265
+
266
+ ---
267
+
268
+ ## Removed in v2
269
+
270
+ | Hook | Replacement |
271
+ |---|---|
272
+ | `useXBalances` | Moved to `@sodax/dapp-kit`. See [`../breaking-changes.md`](../breaking-changes.md) §10. |
273
+
274
+ ---
275
+
276
+ ## Added in v2 (no v1 equivalent)
277
+
278
+ See [`imports.md`](./imports.md) § "Added in v2" for the full list (`useWalletModal`, `useChainGroups`, `useBatchConnect`, etc.). These are not migration items — they are new capabilities you may opt into.
@@ -0,0 +1,157 @@
1
+ # Reference: Import Path Map
2
+
3
+ Mechanical import-path replacements for v1 → v2. The package name (`@sodax/wallet-sdk-react`) is unchanged. See [`../breaking-changes.md`](../breaking-changes.md) §5 for the WHY behind concrete-class sub-path imports.
4
+
5
+ ---
6
+
7
+ ## Store hook removed from the public API
8
+
9
+ v1 exported the Zustand store hook (`useXWagmiStore`) from the package barrel. **v2 does not export the store hook at all** — direct store access is no longer supported. The localStorage key (`xwagmi-store`) is unchanged, so user connections survive the upgrade.
10
+
11
+ For each `useXWagmiStore(state => state.X)` selector, replace with the equivalent public hook below. **Do not rename to `useXWalletStore`** — the v2 barrel does not export it.
12
+
13
+ ### Field-to-hook map
14
+
15
+ | v1 selector | v2 replacement |
16
+ |---|---|
17
+ | `state.xServices` (whole map) | `useXServices()` |
18
+ | `state.xServices[chainType]` (per chain) | `useXService({ xChainType })` |
19
+ | `state.xConnections` (whole map) | `useXConnections()` |
20
+ | `state.xConnections[chainType]` (per chain) | `useXConnection({ xChainType })` |
21
+ | `state.setXConnection` | not a public mutation — use `useXConnect()` (mutation hook) |
22
+ | `state.unsetXConnection` | not a public mutation — use `useXDisconnect()` |
23
+
24
+ ```diff
25
+ - // v1 ❌
26
+ - import { useXWagmiStore } from '@sodax/wallet-sdk-react';
27
+ - const xServices = useXWagmiStore(state => state.xServices);
28
+ + // v2 ✅ — public hook, no store access
29
+ + import { useXServices } from '@sodax/wallet-sdk-react';
30
+ + const xServices = useXServices();
31
+ ```
32
+
33
+ ### Decision tree — `useXWagmiStore` selector handling
34
+
35
+ For each occurrence of `useXWagmiStore(state => state.X)`:
36
+
37
+ 1. **Is `X` a public-hook-equivalent read** (`xServices`, `xConnections`, or per-chain access of either)?
38
+ → Replace with the public hook from the table. Drop the `useXWagmiStore` import.
39
+ 2. **Is `X` a mutation** (`setXConnection`, `unsetXConnection`) **or a v2-internal field** (`enabledChains`, `chainActions`, `walletProviders`, `xConnectorsByChain`)?
40
+ → STOP. The user's code is poking at internal API or was hand-edited mid-migration. Ask the user before changing.
41
+ 3. **Anything else** (typo, removed v1 field)?
42
+ → STOP. Ask user.
43
+
44
+ ### Worked example
45
+
46
+ ```ts
47
+ // v1 ❌ — direct store read
48
+ const xServices = useXWagmiStore(state => state.xServices);
49
+
50
+ // v2 ✅ — public hook (no store access)
51
+ const xServices = useXServices();
52
+
53
+ // 🛑 STOP — mutation through store; v2 does not expose this on a hook
54
+ const setConn = useXWagmiStore(state => state.setXConnection);
55
+ // → Ask user. Likely they want useXConnect()'s mutation instead.
56
+ ```
57
+
58
+ Always prefer public hooks (`useXService`, `useXServices`, `useXConnection`, `useXConnections`, `useEnabledChains`, `useWalletProvider`) over store reads — see [`../../integration/reference/hooks.md`](../../integration/reference/hooks.md).
59
+
60
+ ---
61
+
62
+ ## Concrete chain classes — moved behind sub-path imports
63
+
64
+ v1 re-exported every concrete `XService` / `XConnector` subclass from the package barrel. v2's barrel exports only types, hooks, abstractions, and `SodaxWalletProvider`.
65
+
66
+ | Concrete class | v1 import path | v2 import path |
67
+ |---|---|---|
68
+ | `EvmXService`, `EvmXConnector` | `@sodax/wallet-sdk-react` | `@sodax/wallet-sdk-react/xchains/evm` |
69
+ | `SolanaXService`, `SolanaXConnector` | `@sodax/wallet-sdk-react` | `@sodax/wallet-sdk-react/xchains/solana` |
70
+ | `SuiXService`, `SuiXConnector` | `@sodax/wallet-sdk-react` | `@sodax/wallet-sdk-react/xchains/sui` |
71
+ | `BitcoinXService`, `UnisatXConnector`, `XverseXConnector`, `OKXXConnector` | `@sodax/wallet-sdk-react` | `@sodax/wallet-sdk-react/xchains/bitcoin` |
72
+ | `StellarXService`, `StellarWalletsKitXConnector` | `@sodax/wallet-sdk-react` | `@sodax/wallet-sdk-react/xchains/stellar` |
73
+ | `InjectiveXService`, `InjectiveXConnector` | `@sodax/wallet-sdk-react` | `@sodax/wallet-sdk-react/xchains/injective` |
74
+ | `IconXService`, `IconHanaXConnector` | `@sodax/wallet-sdk-react` | `@sodax/wallet-sdk-react/xchains/icon` |
75
+ | `NearXService`, `NearXConnector` | `@sodax/wallet-sdk-react` | `@sodax/wallet-sdk-react/xchains/near` |
76
+ | `StacksXService`, `StacksXConnector`, `STACKS_PROVIDERS` | `@sodax/wallet-sdk-react` | `@sodax/wallet-sdk-react/xchains/stacks` |
77
+
78
+ ### Examples
79
+
80
+ ```diff
81
+ - // v1 ❌ — all concrete classes from barrel
82
+ - import {
83
+ - EvmXService,
84
+ - XverseXConnector,
85
+ - IconHanaXConnector,
86
+ - } from '@sodax/wallet-sdk-react';
87
+ + // v2 ✅ — sub-path per chain
88
+ + import { EvmXService } from '@sodax/wallet-sdk-react/xchains/evm';
89
+ + import { XverseXConnector } from '@sodax/wallet-sdk-react/xchains/bitcoin';
90
+ + import { IconHanaXConnector } from '@sodax/wallet-sdk-react/xchains/icon';
91
+ ```
92
+
93
+ ### Type imports also use sub-path
94
+
95
+ Even when you only need a **type** (not the runtime class), the v2 barrel does not re-export concrete chain types. Use the sub-path import with `import type`:
96
+
97
+ ```diff
98
+ - // v1 ❌
99
+ - import { type StellarXService, useXService } from '@sodax/wallet-sdk-react';
100
+ + // v2 ✅ — sub-path import for both type and runtime
101
+ + import type { StellarXService } from '@sodax/wallet-sdk-react/xchains/stellar';
102
+ + import type { XverseXConnector, BtcWalletAddressType } from '@sodax/wallet-sdk-react/xchains/bitcoin';
103
+ + import { useXService } from '@sodax/wallet-sdk-react';
104
+ ```
105
+
106
+ `import type` from sub-paths is **erased at build time** — no runtime cost. Use it freely for type annotations, `as`, generics, etc.
107
+
108
+ ---
109
+
110
+ ## Hooks — same package, same names (signatures changed)
111
+
112
+ | Hook | v1 path | v2 path | Signature changed? |
113
+ |---|---|---|---|
114
+ | `useXAccount` | `@sodax/wallet-sdk-react` | `@sodax/wallet-sdk-react` | yes — see [`hooks.md`](./hooks.md) |
115
+ | `useXAccounts` | `@sodax/wallet-sdk-react` | `@sodax/wallet-sdk-react` | no |
116
+ | `useXConnect` | `@sodax/wallet-sdk-react` | `@sodax/wallet-sdk-react` | no |
117
+ | `useXConnection` | `@sodax/wallet-sdk-react` | `@sodax/wallet-sdk-react` | yes |
118
+ | `useXConnectors` | `@sodax/wallet-sdk-react` | `@sodax/wallet-sdk-react` | yes |
119
+ | `useXDisconnect` | `@sodax/wallet-sdk-react` | `@sodax/wallet-sdk-react` | yes — returned function now takes `{ xChainType }` object (was positional) |
120
+ | `useXService` | `@sodax/wallet-sdk-react` | `@sodax/wallet-sdk-react` | yes |
121
+ | `useWalletProvider` | `@sodax/wallet-sdk-react` | `@sodax/wallet-sdk-react` | yes |
122
+ | `useXSignMessage` | `@sodax/wallet-sdk-react` | `@sodax/wallet-sdk-react` | no |
123
+ | `useEvmSwitchChain` | `@sodax/wallet-sdk-react` | `@sodax/wallet-sdk-react` | yes — now takes `{ xChainId }`, returns `{ isWrongChain, handleSwitchChain }` |
124
+
125
+ For signature changes see [`hooks.md`](./hooks.md).
126
+
127
+ ---
128
+
129
+ ## Removed in v2
130
+
131
+ | Symbol | v1 path | Replacement |
132
+ |---|---|---|
133
+ | `useXBalances` | `@sodax/wallet-sdk-react` | Moved to `@sodax/dapp-kit` with a new signature (`{ params: { xService, xChainId, xTokens, address } }`). See [`../breaking-changes.md`](../breaking-changes.md) §10. |
134
+ | `useEthereumChainId` | `@sodax/wallet-sdk-react` | Internal in v2. Use `useAccount().chainId` from `wagmi` for the raw EVM chain ID, or `useEvmSwitchChain({ xChainId })` if you only needed it for "wrong network" UX. See [`hooks.md`](./hooks.md) § `useEthereumChainId`. |
135
+
136
+ ---
137
+
138
+ ## Added in v2 (informational — no v1 to migrate from)
139
+
140
+ These are new exports — no v1 import to replace, but knowing they exist may let you simplify hand-rolled v1 code during migration:
141
+
142
+ | New hook / utility | Path | Purpose |
143
+ |---|---|---|
144
+ | `useWalletModal` | `@sodax/wallet-sdk-react` | Headless modal state machine |
145
+ | `useConnectionFlow` | `@sodax/wallet-sdk-react` | `connect + status + retry` without modal |
146
+ | `useBatchConnect` | `@sodax/wallet-sdk-react` | Sequential connect across multiple connectors |
147
+ | `useBatchDisconnect` | `@sodax/wallet-sdk-react` | Mirror of `useBatchConnect` |
148
+ | `useChainGroups` | `@sodax/wallet-sdk-react` | One row per enabled chain (EVM collapses) |
149
+ | `useConnectedChains` | `@sodax/wallet-sdk-react` | Aggregate connected view + hydration `status` |
150
+ | `useEnabledChains` | `@sodax/wallet-sdk-react` | List of chain types enabled in config |
151
+ | `useIsWalletInstalled` | `@sodax/wallet-sdk-react` | Cross-chain install check |
152
+ | `useXConnections` | `@sodax/wallet-sdk-react` | All connections (plural) |
153
+ | `useXConnectorsByChain` | `@sodax/wallet-sdk-react` | Multi-chain connector list (no per-chain warnings) |
154
+ | `useXServices` | `@sodax/wallet-sdk-react` | All services (plural) |
155
+ | `sortConnectors` | `@sodax/wallet-sdk-react` | Helper: preferred → installed → original |
156
+ | `getXChainType` | `@sodax/wallet-sdk-react` | Imperative: map a `SpokeChainKey` to its `ChainType` family. Common pattern: `useXService({ xChainType: getXChainType(srcChainKey) })` when you only have a chain key on hand. |
157
+ | `getXService` | `@sodax/wallet-sdk-react` | Imperative variant of `useXService` for non-React call sites (e.g. inside event handlers that don't re-render). Prefer `useXService` in component bodies. |
@@ -0,0 +1,146 @@
1
+ import { ChainType, IXServiceBase, XToken } from '@sodax/types';
2
+
3
+ type XAccount = {
4
+ address: string | undefined;
5
+ xChainType: ChainType | undefined;
6
+ publicKey?: string;
7
+ };
8
+ type XConnection = {
9
+ xAccount: XAccount;
10
+ xConnectorId: string;
11
+ };
12
+
13
+ /**
14
+ * Public interface for chain service implementations.
15
+ *
16
+ * Consumer code should depend on this interface instead of the concrete XService class.
17
+ * Extends the shared `IXServiceBase` from `@sodax/types` with wallet-sdk-react
18
+ * specific connector methods.
19
+ */
20
+ interface IXService extends IXServiceBase {
21
+ getXConnectors(): IXConnector[];
22
+ getXConnectorById(xConnectorId: string): IXConnector | undefined;
23
+ }
24
+ /**
25
+ * Public interface for wallet connector implementations.
26
+ *
27
+ * `isInstalled` reads `window.*` at getter-call time (render time); no extra
28
+ * subscription is installed. Components get fresh values through normal React
29
+ * render triggers (store updates, parent rerenders).
30
+ */
31
+ interface IXConnector {
32
+ readonly xChainType: ChainType;
33
+ readonly name: string;
34
+ /** Unique identifier for the connector */
35
+ readonly _id: string;
36
+ /** Optional icon URL for the wallet provider */
37
+ readonly _icon?: string;
38
+ readonly id: string;
39
+ readonly icon: string | undefined;
40
+ /** True when the wallet extension backing this connector is installed. */
41
+ readonly isInstalled: boolean;
42
+ /** URL where users can install the wallet extension if missing. */
43
+ readonly installUrl: string | undefined;
44
+ connect(): Promise<XAccount | undefined>;
45
+ disconnect(): Promise<void>;
46
+ }
47
+
48
+ /**
49
+ * Abstract base class for blockchain service implementations.
50
+ *
51
+ * The XService class serves as a foundation for implementing blockchain-specific services
52
+ * in a multi-chain environment. It provides a standardized interface for:
53
+ * 1. Managing wallet connectors for different blockchain types
54
+ * 2. Querying token balances across different chains
55
+ *
56
+ * Each blockchain implementation (e.g., Solana, EVM chains) extends this class
57
+ * to provide chain-specific functionality while maintaining a consistent interface.
58
+ *
59
+ * @abstract
60
+ * @class XService
61
+ * @property {ChainType} xChainType - The blockchain type this service handles (e.g., 'SOLANA', 'EVM')
62
+ * @property {XConnector[]} xConnectors - Available wallet connectors for this chain
63
+ *
64
+ */
65
+ declare abstract class XService implements IXServiceBase {
66
+ /** The blockchain type this service handles */
67
+ readonly xChainType: ChainType;
68
+ /** Available wallet connectors for this chain */
69
+ private xConnectors;
70
+ constructor(xChainType: ChainType);
71
+ /**
72
+ * Gets the balance of a specific token for an address
73
+ * @param address The wallet address to check
74
+ * @param xToken The token to get the balance for
75
+ * @returns Promise resolving to the token balance as a bigint
76
+ */
77
+ getBalance(address: string | undefined, xToken: XToken): Promise<bigint>;
78
+ /**
79
+ * Gets balances for multiple tokens for an address
80
+ * @param address The wallet address to check
81
+ * @param xTokens Array of tokens to get balances for
82
+ * @returns Promise resolving to object mapping token addresses to balances
83
+ */
84
+ getBalances(address: string | undefined, xTokens: readonly XToken[]): Promise<Record<string, bigint>>;
85
+ /**
86
+ * Gets all available connectors for this chain
87
+ */
88
+ getXConnectors(): IXConnector[];
89
+ /**
90
+ * Sets the available connectors for this chain
91
+ */
92
+ setXConnectors(xConnectors: IXConnector[]): void;
93
+ /**
94
+ * Gets a specific connector by its ID
95
+ * @param xConnectorId The connector ID to look up
96
+ * @returns The matching connector or undefined if not found
97
+ */
98
+ getXConnectorById(xConnectorId: string): IXConnector | undefined;
99
+ }
100
+
101
+ /**
102
+ * Base class for wallet provider connectors that handles connection management and wallet interactions
103
+ *
104
+ * @abstract
105
+ * @class XConnector
106
+ * @property {ChainType} xChainType - The blockchain type this connector supports
107
+ * @property {string} name - Display name of the wallet provider
108
+ * @property {string} _id - Unique identifier for the connector
109
+ * @property {string | undefined} _icon - Optional icon URL for the wallet provider
110
+ */
111
+ declare abstract class XConnector implements IXConnector {
112
+ /** The blockchain type this connector supports */
113
+ readonly xChainType: ChainType;
114
+ /** Display name of the wallet provider */
115
+ readonly name: string;
116
+ /** Unique identifier for the connector */
117
+ readonly _id: string;
118
+ /** Optional icon URL for the wallet provider */
119
+ readonly _icon?: string;
120
+ constructor(xChainType: ChainType, name: string, id: string);
121
+ /**
122
+ * Connects to the wallet provider
123
+ * @returns Promise resolving to the connected account, or undefined if connection fails
124
+ */
125
+ abstract connect(): Promise<XAccount | undefined>;
126
+ /**
127
+ * Disconnects from the wallet provider
128
+ */
129
+ abstract disconnect(): Promise<void>;
130
+ /** Get the unique identifier for this connector */
131
+ get id(): string;
132
+ /** Get the optional icon URL for this wallet provider */
133
+ get icon(): string | undefined;
134
+ /**
135
+ * True when the wallet extension backing this connector is installed.
136
+ * Default: true (for provider-managed chains where connector presence already
137
+ * implies install — EVM via EIP-6963, Solana/Sui via adapter discovery).
138
+ * Subclasses backed by extension injection (Bitcoin, ICON, Stacks) override
139
+ * this with a window probe.
140
+ */
141
+ get isInstalled(): boolean;
142
+ /** URL to install the wallet extension when missing. Subclasses override. */
143
+ get installUrl(): string | undefined;
144
+ }
145
+
146
+ export { type IXConnector as I, type XAccount as X, type XConnection as a, XService as b, XConnector as c, type IXService as d };