@sodax/wallet-sdk-react 2.0.0-rc.3 → 2.0.0-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -5
- package/dist/{XConnector-B9YQTVJ4.d.ts → XConnector-12q0OVe5.d.ts} +1 -1
- package/dist/{chunk-NY7U7OJW.mjs → chunk-7V7O3Q7Y.mjs} +0 -2
- package/dist/{chunk-BXJLBR4G.mjs → chunk-C6M34IVL.mjs} +2 -4
- package/dist/{chunk-XZ7CHO2S.mjs → chunk-FSOGMSJH.mjs} +2 -4
- package/dist/{chunk-X2MHIWXO.mjs → chunk-IFXZQW4C.mjs} +0 -2
- package/dist/{chunk-7ULB6DW4.mjs → chunk-JQ4H4GJ5.mjs} +3 -5
- package/dist/{chunk-N5A2TMF6.mjs → chunk-LKSSME2J.mjs} +2 -4
- package/dist/{chunk-BKJB527E.mjs → chunk-MWWVB7TD.mjs} +2 -4
- package/dist/{chunk-MXZVF5HR.mjs → chunk-NAKCAL2M.mjs} +0 -2
- package/dist/{chunk-PJLEJVAU.mjs → chunk-OPYSVPRW.mjs} +10 -6
- package/dist/chunk-QMXBY3UI.mjs +1 -0
- package/dist/{chunk-MAQ47Q52.mjs → chunk-TACW7Z4D.mjs} +0 -2
- package/dist/{chunk-PLCA4ZDJ.mjs → chunk-VCESC6QT.mjs} +54 -30
- package/dist/{chunk-2BOUGCJ7.mjs → chunk-WPZOLGVB.mjs} +4 -6
- package/dist/{chunk-66BAUK56.mjs → chunk-X7BHR7WS.mjs} +4 -6
- package/dist/{chunk-E5IAZ7E6.mjs → chunk-Z5GXDHGL.mjs} +11 -7
- package/dist/{config-OlnzyEUE.d.ts → config-DEsqgrG1.d.ts} +10 -5
- package/dist/index.d.ts +6 -6
- package/dist/index.mjs +20 -31
- package/dist/xchains/bitcoin/index.d.ts +1 -1
- package/dist/xchains/bitcoin/index.mjs +14 -16
- package/dist/xchains/evm/index.d.ts +3 -3
- package/dist/xchains/evm/index.mjs +3 -5
- package/dist/xchains/icon/index.d.ts +1 -1
- package/dist/xchains/icon/index.mjs +5 -7
- package/dist/xchains/injective/index.d.ts +2 -2
- package/dist/xchains/injective/index.mjs +3 -5
- package/dist/xchains/near/index.d.ts +1 -1
- package/dist/xchains/near/index.mjs +4 -6
- package/dist/xchains/solana/index.d.ts +1 -1
- package/dist/xchains/solana/index.mjs +5 -7
- package/dist/xchains/stacks/index.d.ts +10 -4
- package/dist/xchains/stacks/index.mjs +3 -5
- package/dist/xchains/stellar/index.d.ts +1 -1
- package/dist/xchains/stellar/index.mjs +4 -6
- package/dist/xchains/sui/index.d.ts +1 -1
- package/dist/xchains/sui/index.mjs +5 -7
- package/docs/ADDING_A_NEW_CHAIN.md +1 -1
- package/docs/SUB_PATH_EXPORTS.md +14 -42
- package/package.json +35 -28
- package/ai-exported/AGENTS.md +0 -122
- package/ai-exported/integration/README.md +0 -102
- package/ai-exported/integration/ai-rules.md +0 -136
- package/ai-exported/integration/architecture.md +0 -181
- package/ai-exported/integration/examples/01-minimal-evm.tsx +0 -75
- package/ai-exported/integration/examples/02-multi-chain-modal.tsx +0 -169
- package/ai-exported/integration/examples/03-nextjs-app-router.tsx +0 -99
- package/ai-exported/integration/examples/04-walletconnect-setup.tsx +0 -89
- package/ai-exported/integration/examples/README.md +0 -29
- package/ai-exported/integration/recipes/batch-operations.md +0 -223
- package/ai-exported/integration/recipes/bridge-to-sdk.md +0 -164
- package/ai-exported/integration/recipes/chain-detection.md +0 -254
- package/ai-exported/integration/recipes/connect-button.md +0 -156
- package/ai-exported/integration/recipes/multi-chain-modal.md +0 -199
- package/ai-exported/integration/recipes/setup.md +0 -160
- package/ai-exported/integration/recipes/sign-message.md +0 -137
- package/ai-exported/integration/recipes/sub-path-imports.md +0 -95
- package/ai-exported/integration/recipes/switch-chain.md +0 -141
- package/ai-exported/integration/recipes/walletconnect-setup.md +0 -139
- package/ai-exported/integration/reference/api-surface.md +0 -175
- package/ai-exported/integration/reference/chain-support.md +0 -78
- package/ai-exported/integration/reference/connectors.md +0 -74
- package/ai-exported/integration/reference/hooks.md +0 -204
- package/ai-exported/integration/reference/wallet-brands.md +0 -106
- package/ai-exported/migration/README.md +0 -49
- package/ai-exported/migration/ai-rules.md +0 -144
- package/ai-exported/migration/breaking-changes.md +0 -305
- package/ai-exported/migration/checklist.md +0 -159
- package/ai-exported/migration/recipes/connect-button.md +0 -166
- package/ai-exported/migration/recipes/multi-chain-modal.md +0 -244
- package/ai-exported/migration/recipes/ssr-setup.md +0 -164
- package/ai-exported/migration/recipes/walletconnect-migration.md +0 -168
- package/ai-exported/migration/reference/components.md +0 -73
- package/ai-exported/migration/reference/config.md +0 -325
- package/ai-exported/migration/reference/hooks.md +0 -323
- package/ai-exported/migration/reference/imports.md +0 -157
- package/dist/chunk-2BOUGCJ7.mjs.map +0 -1
- package/dist/chunk-66BAUK56.mjs.map +0 -1
- package/dist/chunk-7ULB6DW4.mjs.map +0 -1
- package/dist/chunk-BKJB527E.mjs.map +0 -1
- package/dist/chunk-BXJLBR4G.mjs.map +0 -1
- package/dist/chunk-E5IAZ7E6.mjs.map +0 -1
- package/dist/chunk-MAQ47Q52.mjs.map +0 -1
- package/dist/chunk-MXZVF5HR.mjs.map +0 -1
- package/dist/chunk-N5A2TMF6.mjs.map +0 -1
- package/dist/chunk-NY7U7OJW.mjs.map +0 -1
- package/dist/chunk-PJLEJVAU.mjs.map +0 -1
- package/dist/chunk-PLCA4ZDJ.mjs.map +0 -1
- package/dist/chunk-TZMKDXFA.mjs +0 -3
- package/dist/chunk-TZMKDXFA.mjs.map +0 -1
- package/dist/chunk-X2MHIWXO.mjs.map +0 -1
- package/dist/chunk-XZ7CHO2S.mjs.map +0 -1
- package/dist/index.cjs +0 -3337
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/xchains/bitcoin/index.cjs +0 -1927
- package/dist/xchains/bitcoin/index.cjs.map +0 -1
- package/dist/xchains/bitcoin/index.mjs.map +0 -1
- package/dist/xchains/evm/index.cjs +0 -316
- package/dist/xchains/evm/index.cjs.map +0 -1
- package/dist/xchains/evm/index.mjs.map +0 -1
- package/dist/xchains/icon/index.cjs +0 -311
- package/dist/xchains/icon/index.cjs.map +0 -1
- package/dist/xchains/icon/index.mjs.map +0 -1
- package/dist/xchains/injective/index.cjs +0 -223
- package/dist/xchains/injective/index.cjs.map +0 -1
- package/dist/xchains/injective/index.mjs.map +0 -1
- package/dist/xchains/near/index.cjs +0 -190
- package/dist/xchains/near/index.cjs.map +0 -1
- package/dist/xchains/near/index.mjs.map +0 -1
- package/dist/xchains/solana/index.cjs +0 -186
- package/dist/xchains/solana/index.cjs.map +0 -1
- package/dist/xchains/solana/index.mjs.map +0 -1
- package/dist/xchains/stacks/index.cjs +0 -240
- package/dist/xchains/stacks/index.cjs.map +0 -1
- package/dist/xchains/stacks/index.mjs.map +0 -1
- package/dist/xchains/stellar/index.cjs +0 -322
- package/dist/xchains/stellar/index.cjs.map +0 -1
- package/dist/xchains/stellar/index.mjs.map +0 -1
- package/dist/xchains/sui/index.cjs +0 -248
- package/dist/xchains/sui/index.cjs.map +0 -1
- package/dist/xchains/sui/index.mjs.map +0 -1
- package/skills/SKILLS.md +0 -84
- package/skills/bridge-to-sdk.md +0 -148
- package/skills/connect-button.md +0 -116
- package/skills/evm-only-walletconnect.md +0 -111
- package/skills/multi-chain-modal.md +0 -178
- package/skills/setup.md +0 -107
|
@@ -1,323 +0,0 @@
|
|
|
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
|
-
## Canonical rule — `xChainId` is non-nullable
|
|
20
|
-
|
|
21
|
-
Hooks that take `xChainId` declare it via overloads as required `SpokeChainKey`. Passing a nullable value (e.g. `token?.chainKey`) does not compile.
|
|
22
|
-
|
|
23
|
-
The exported `UseWalletProviderOptions` (and similar) is the *implementation* type and looks permissive — but calls resolve against the overloads, which are stricter. Casting around the error is unsafe: it either fails to bypass the overload at all, or silently strips the nullable from the type while the runtime value stays `undefined` (some hooks tolerate that and return `undefined`; `useXAccount` throws).
|
|
24
|
-
|
|
25
|
-
Handle the nullable **before** the hook call:
|
|
26
|
-
|
|
27
|
-
```ts
|
|
28
|
-
// Narrow, default-fallback, or split into a child component — pick the one that fits.
|
|
29
|
-
if (!chainKey) return null;
|
|
30
|
-
const wp = useWalletProvider({ xChainId: chainKey });
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
## `useXAccount`
|
|
36
|
-
|
|
37
|
-
```ts
|
|
38
|
-
// v1 ❌
|
|
39
|
-
const { address } = useXAccount('EVM');
|
|
40
|
-
const { address } = useXAccount('0x1.eth');
|
|
41
|
-
|
|
42
|
-
// v2 ✅
|
|
43
|
-
import { ChainKeys } from '@sodax/types';
|
|
44
|
-
|
|
45
|
-
const { address } = useXAccount({ xChainType: 'EVM' });
|
|
46
|
-
const { address } = useXAccount({ xChainId: ChainKeys.ETHEREUM_MAINNET });
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
**Decision rule (positional value → field name):** v1 accepted both `ChainType` and `ChainId` and detected at runtime. In v2 you must choose the right field:
|
|
50
|
-
|
|
51
|
-
- v1 value is a family literal (`'EVM'`, `'SOLANA'`, …) → v2 `xChainType`.
|
|
52
|
-
- v1 value is a chain-key string (`'0x1.eth'`, `XToken.xChainId`, …) → v2 `xChainId` typed as `SpokeChainKey`.
|
|
53
|
-
- v1 value comes from `getXChainType(...)` (returns `ChainType | undefined`) → v2 `xChainType`, but **guard against `undefined`** — see below.
|
|
54
|
-
|
|
55
|
-
**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.
|
|
56
|
-
|
|
57
|
-
**Common nullable patterns and their fixes:**
|
|
58
|
-
|
|
59
|
-
```ts
|
|
60
|
-
// ❌ v1 idiom — returns empty account when nothing selected, runs every render
|
|
61
|
-
const { address } = useXAccount(selectedChainId ?? undefined);
|
|
62
|
-
|
|
63
|
-
// ✅ v2 fix 1 — index a snapshot from useXAccounts (no per-key hook call)
|
|
64
|
-
const xAccounts = useXAccounts();
|
|
65
|
-
const chainType = selectedChainId ? getXChainType(selectedChainId) : undefined;
|
|
66
|
-
const address = chainType ? xAccounts[chainType]?.address : undefined;
|
|
67
|
-
|
|
68
|
-
// ✅ v2 fix 2 — supply a sensible default chain key so the hook always has input
|
|
69
|
-
const { address } = useXAccount({
|
|
70
|
-
xChainId: selectedChainId ?? ChainKeys.SONIC_MAINNET,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// ✅ v2 fix 3 — split into a child component that only mounts when input is known
|
|
74
|
-
{selectedChainId ? <Account xChainId={selectedChainId} /> : null}
|
|
75
|
-
function Account({ xChainId }: { xChainId: SpokeChainKey }) {
|
|
76
|
-
const { address } = useXAccount({ xChainId });
|
|
77
|
-
// ...
|
|
78
|
-
}
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
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.
|
|
82
|
-
|
|
83
|
-
**Other notes:**
|
|
84
|
-
- Return shape unchanged: `XAccount = { address, xChainType, publicKey? }`.
|
|
85
|
-
- 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.
|
|
86
|
-
|
|
87
|
-
---
|
|
88
|
-
|
|
89
|
-
## `useXConnectors`
|
|
90
|
-
|
|
91
|
-
```ts
|
|
92
|
-
// v1 ❌
|
|
93
|
-
const connectors = useXConnectors('EVM');
|
|
94
|
-
|
|
95
|
-
// v2 ✅
|
|
96
|
-
const connectors = useXConnectors({ xChainType: 'EVM' });
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
**Other notes:**
|
|
100
|
-
- Return type changed from `XConnector[]` to `IXConnector[]` (interface). For most consumers this is invisible — both expose `id`, `name`, `icon`, `xChainType`, `connect()`, `disconnect()`.
|
|
101
|
-
- v2 enriches each connector with `isInstalled`, `installUrl`, `icon` (read at access time from `window.*`).
|
|
102
|
-
- v2 returns `[]` and logs a one-time warning if the chain isn't in `enabledChains`. v1 returned `[]` silently.
|
|
103
|
-
|
|
104
|
-
---
|
|
105
|
-
|
|
106
|
-
## `useXConnection`
|
|
107
|
-
|
|
108
|
-
```ts
|
|
109
|
-
// v1 ❌
|
|
110
|
-
const connection = useXConnection('EVM');
|
|
111
|
-
|
|
112
|
-
// v2 ✅
|
|
113
|
-
const connection = useXConnection({ xChainType: 'EVM' });
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
Return shape unchanged: `XConnection | undefined = { xAccount, xConnectorId } | undefined`.
|
|
117
|
-
|
|
118
|
-
---
|
|
119
|
-
|
|
120
|
-
## `useXService`
|
|
121
|
-
|
|
122
|
-
```ts
|
|
123
|
-
// v1 ❌
|
|
124
|
-
const service = useXService('EVM');
|
|
125
|
-
|
|
126
|
-
// v2 ✅
|
|
127
|
-
const service = useXService({ xChainType: 'EVM' });
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
Return type unchanged.
|
|
131
|
-
|
|
132
|
-
> **Need the typed concrete class** (e.g. `EvmXService.publicClient`, `StellarXService.server`, `BitcoinXService` for `instanceof` checks)? The concrete classes (`EvmXService`, `SolanaXService`, `StellarXService`, etc.) are **still exported in v2**, but moved from the package barrel to per-chain sub-paths: `@sodax/wallet-sdk-react/xchains/<chain>`. See [`imports.md` § Concrete chain classes](./imports.md#concrete-chain-classes--moved-behind-sub-path-imports) for the full per-chain table. The TS error `TS2724: '"@sodax/wallet-sdk-react"' has no exported member named 'StellarXService'. Did you mean 'useXService'?` is misleading when you actually need the class — the class is at the sub-path, not the hook.
|
|
133
|
-
|
|
134
|
-
---
|
|
135
|
-
|
|
136
|
-
## `useWalletProvider`
|
|
137
|
-
|
|
138
|
-
```ts
|
|
139
|
-
// v1 ❌ — positional spokeChainId, returns wide union
|
|
140
|
-
const wp = useWalletProvider('sui');
|
|
141
|
-
|
|
142
|
-
// v2 ✅ — options object, narrowest type when xChainId is passed
|
|
143
|
-
import { ChainKeys } from '@sodax/types';
|
|
144
|
-
|
|
145
|
-
const wp = useWalletProvider({ xChainId: ChainKeys.SUI_MAINNET });
|
|
146
|
-
// ^ inferred as ISuiWalletProvider | undefined
|
|
147
|
-
|
|
148
|
-
const wp2 = useWalletProvider({ xChainType: 'EVM' });
|
|
149
|
-
// ^ inferred as IEvmWalletProvider | undefined
|
|
150
|
-
|
|
151
|
-
const wp3 = useWalletProvider();
|
|
152
|
-
// ^ inferred as IWalletProvider | undefined (any)
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
**Other notes:**
|
|
156
|
-
- Pass either `xChainId` (`SpokeChainKey`) or `xChainType` (`ChainType`), never both. Chain key gives narrower TypeScript inference.
|
|
157
|
-
- Returns `undefined` when the chain isn't enabled in `walletConfig` (logs a one-time warning) or when no wallet is connected.
|
|
158
|
-
|
|
159
|
-
---
|
|
160
|
-
|
|
161
|
-
## `useXConnect`
|
|
162
|
-
|
|
163
|
-
```ts
|
|
164
|
-
// v1 ✅ AND v2 ✅ — same signature
|
|
165
|
-
const { mutateAsync: connect } = useXConnect();
|
|
166
|
-
await connect(connector);
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
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`.
|
|
170
|
-
|
|
171
|
-
---
|
|
172
|
-
|
|
173
|
-
## `useXDisconnect`
|
|
174
|
-
|
|
175
|
-
```ts
|
|
176
|
-
// v1 ❌ — returned function takes positional ChainType
|
|
177
|
-
const disconnect = useXDisconnect();
|
|
178
|
-
await disconnect('EVM');
|
|
179
|
-
|
|
180
|
-
// v2 ✅ — returned function takes options object
|
|
181
|
-
const disconnect = useXDisconnect();
|
|
182
|
-
await disconnect({ xChainType: 'EVM' });
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
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.
|
|
186
|
-
|
|
187
|
-
**Common breakage:** `await disconnect(xChainType)` raises `TS2345: Argument of type 'string' is not assignable to parameter of type 'UseXDisconnectArgs'`. Wrap in an object.
|
|
188
|
-
|
|
189
|
-
---
|
|
190
|
-
|
|
191
|
-
## `useXSignMessage`
|
|
192
|
-
|
|
193
|
-
```ts
|
|
194
|
-
// v1 ✅ AND v2 ✅ — same signature
|
|
195
|
-
const { mutateAsync: signMessage } = useXSignMessage();
|
|
196
|
-
const sig = await signMessage({ xChainType: 'EVM', message: 'hello' });
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
No change.
|
|
200
|
-
|
|
201
|
-
---
|
|
202
|
-
|
|
203
|
-
## `useXAccounts`
|
|
204
|
-
|
|
205
|
-
```ts
|
|
206
|
-
// v1
|
|
207
|
-
const accounts = useXAccounts();
|
|
208
|
-
|
|
209
|
-
// v2 — return type is now strictly typed
|
|
210
|
-
const accounts = useXAccounts();
|
|
211
|
-
// → Partial<Record<ChainType, XAccount>>
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
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`.
|
|
215
|
-
|
|
216
|
-
```ts
|
|
217
|
-
// ❌ FAILS — chainType is `string`, can't index Partial<Record<ChainType, ...>>
|
|
218
|
-
const chainType = someStringFromConfig;
|
|
219
|
-
const account = accounts[chainType];
|
|
220
|
-
|
|
221
|
-
// ✅ FIX 1 — narrow with getXChainType (returns ChainType | undefined)
|
|
222
|
-
import { getXChainType } from '@sodax/wallet-sdk-react';
|
|
223
|
-
const chainType = getXChainType(chainId);
|
|
224
|
-
const account = chainType ? accounts[chainType] : undefined;
|
|
225
|
-
|
|
226
|
-
// ✅ FIX 2 — call useXAccount per-chain instead of indexing
|
|
227
|
-
const account = useXAccount({ xChainType: 'EVM' });
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
---
|
|
231
|
-
|
|
232
|
-
## `useEvmSwitchChain`
|
|
233
|
-
|
|
234
|
-
```ts
|
|
235
|
-
// v1 ❌ — positional `expectedXChainId: ChainId`
|
|
236
|
-
const { isWrongChain, handleSwitchChain } = useEvmSwitchChain(chainId);
|
|
237
|
-
|
|
238
|
-
// v2 ✅ — options object; `xChainId: SpokeChainKey`
|
|
239
|
-
import { ChainKeys } from '@sodax/types';
|
|
240
|
-
|
|
241
|
-
const { isWrongChain, handleSwitchChain } = useEvmSwitchChain({
|
|
242
|
-
xChainId: ChainKeys.ETHEREUM_MAINNET,
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
if (isWrongChain) handleSwitchChain();
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
**Breaking changes:**
|
|
249
|
-
|
|
250
|
-
- **Call shape**: positional → options object. Same forward-compat reason as the other hooks.
|
|
251
|
-
- **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.
|
|
252
|
-
|
|
253
|
-
**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.
|
|
254
|
-
|
|
255
|
-
**Behavior added in v2:**
|
|
256
|
-
|
|
257
|
-
- **Injective + MetaMask auto-switch.** When the user connects to Injective via MetaMask, v2 automatically targets Ethereum mainnet underneath. v1 had no Injective awareness.
|
|
258
|
-
- **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.
|
|
259
|
-
|
|
260
|
-
---
|
|
261
|
-
|
|
262
|
-
## `useEthereumChainId`
|
|
263
|
-
|
|
264
|
-
**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.
|
|
265
|
-
|
|
266
|
-
Migration:
|
|
267
|
-
|
|
268
|
-
```diff
|
|
269
|
-
- // v1 ❌ — manual chain-ID comparison for Injective + MetaMask UX
|
|
270
|
-
- import { useEthereumChainId } from '@sodax/wallet-sdk-react';
|
|
271
|
-
- const chainId = useEthereumChainId();
|
|
272
|
-
- if (chainId !== 1) /* prompt user to switch to Ethereum mainnet */;
|
|
273
|
-
+ // v2 ✅ — useEvmSwitchChain auto-handles Injective + MetaMask underneath
|
|
274
|
-
+ import { useEvmSwitchChain } from '@sodax/wallet-sdk-react';
|
|
275
|
-
+ import { ChainKeys } from '@sodax/types';
|
|
276
|
-
+ const { isWrongChain, handleSwitchChain } = useEvmSwitchChain({
|
|
277
|
-
+ xChainId: ChainKeys.INJECTIVE_MAINNET,
|
|
278
|
-
+ });
|
|
279
|
-
+ if (isWrongChain) handleSwitchChain();
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
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.
|
|
283
|
-
|
|
284
|
-
---
|
|
285
|
-
|
|
286
|
-
## Removed in v2
|
|
287
|
-
|
|
288
|
-
| Hook / symbol | Replacement |
|
|
289
|
-
|---|---|
|
|
290
|
-
| `useXBalances` | Moved to `@sodax/dapp-kit` **AND signature changed**. See note below. |
|
|
291
|
-
| `useXWagmiStore` | Removed entirely — direct store reads are not part of the v2 API. Use public hooks (`useXServices`, `useXConnections`, `useXService({ xChainType })`, `useXConnection({ xChainType })`, etc.). See note below. |
|
|
292
|
-
| Concrete X-service / X-connector classes (`EvmXService`, `SolanaXService`, `StellarXService`, `BitcoinXService`, `IconXService`, `InjectiveXService`, `SuiXService`, `NearXService`, `StacksXService`, `XverseXConnector`, `UnisatXConnector`, `OKXXConnector`, `IconHanaXConnector`, …) | **Not removed — moved to per-chain sub-paths.** TS error `TS2724: '"@sodax/wallet-sdk-react"' has no exported member named 'StellarXService'. Did you mean 'useXService'?` is misleading — the hint points at `useXService` (which returns the abstract `XService \| undefined`), but the typed class itself lives at `@sodax/wallet-sdk-react/xchains/<chain>`. See [`imports.md` § "Concrete chain classes — moved behind sub-path imports"](./imports.md#concrete-chain-classes--moved-behind-sub-path-imports) for the per-chain table. |
|
|
293
|
-
|
|
294
|
-
### `useXBalances` — moved + reshaped
|
|
295
|
-
|
|
296
|
-
Not a simple package-rename. The v2 hook also wraps params and adds a required `xService` field:
|
|
297
|
-
|
|
298
|
-
```diff
|
|
299
|
-
- // v1 — flat args from @sodax/wallet-sdk-react
|
|
300
|
-
- import { useXBalances } from '@sodax/wallet-sdk-react';
|
|
301
|
-
- const { data } = useXBalances({ xChainId, xTokens, address });
|
|
302
|
-
|
|
303
|
-
+ // v2 — from @sodax/dapp-kit; params wrapped; xService required
|
|
304
|
-
+ import { useXBalances } from '@sodax/dapp-kit';
|
|
305
|
-
+ import { useXService, getXChainType } from '@sodax/wallet-sdk-react';
|
|
306
|
-
+
|
|
307
|
-
+ const xService = useXService({ xChainType: getXChainType(xChainId) });
|
|
308
|
-
+ const { data } = useXBalances({
|
|
309
|
-
+ params: { xService, xChainId, xTokens, address },
|
|
310
|
-
+ });
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
The `xService` injection is part of dapp-kit's "no implicit wallet-sdk dependency" design — dapp-kit doesn't import from `wallet-sdk-react`, so the consumer wires the service across at the call site. See `@sodax/dapp-kit/ai-exported/integration/architecture.md` § "Decoupling from wallet-sdk-react".
|
|
314
|
-
|
|
315
|
-
### `useXWagmiStore` — removed (store reads moved to public hooks)
|
|
316
|
-
|
|
317
|
-
The v1 Zustand store hook is gone from the v2 barrel. Direct store access is no longer supported. Every `useXWagmiStore(state => state.X)` selector maps to a public hook — see [`imports.md` § "Store hook removed from the public API"](./imports.md#store-hook-removed-from-the-public-api) for the full field-to-hook map and decision tree (`state.xServices` → `useXServices()`, `state.xConnections[chainType]` → `useXConnection({ xChainType })`, etc.). The localStorage key (`xwagmi-store`) is unchanged, so user connections survive the upgrade.
|
|
318
|
-
|
|
319
|
-
---
|
|
320
|
-
|
|
321
|
-
## Added in v2 (no v1 equivalent)
|
|
322
|
-
|
|
323
|
-
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.
|
|
@@ -1,157 +0,0 @@
|
|
|
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. |
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/xchains/icon/IconXService.ts","../src/xchains/icon/iconex/index.tsx","../src/xchains/icon/IconHanaXConnector.ts"],"names":["SupportedChainId"],"mappings":";;;;;;AAMA,IAAM,OAAA,GAAW,SAAA,IAAwB,UAAA,CAAA,OAAA,GAAqB,UAAA,CAAA,OAAA,GAAU,UAAA;AACxE,IAAM,EAAE,WAAA,EAAa,sBAAA,EAAwB,SAAS,WAAA,EAAa,SAAA,EAAW,eAAc,GAAI,OAAA;AAOzF,IAAK,gBAAA,qBAAAA,iBAAAA,KAAL;AACL,EAAAA,iBAAAA,CAAAA,iBAAAA,CAAA,aAAU,CAAA,CAAA,GAAV,SAAA;AADU,EAAA,OAAAA,iBAAAA;AAAA,CAAA,EAAA,gBAAA,IAAA,EAAA;AAaL,IAAM,UAAA,GAAwD;AAAA,EACnE,CAAC,kBAA2B;AAAA,IAC1B,IAAA,EAAM,cAAA;AAAA,IACN,IAAA,EAAM,4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ACjC,IAAA,OAAO,gBAAgB,IAAA,CAAK,IAAA;AAAA,EAC9B;AACF","file":"chunk-2BOUGCJ7.mjs","sourcesContent":["import { XService } from '@/core/XService.js';\nimport type { IconService } from 'icon-sdk-js';\nimport * as IconSdkRaw from 'icon-sdk-js';\nimport type { XToken } from '@sodax/types';\nimport { isNativeToken } from '@/utils/index.js';\n\nconst IconSdk = ('default' in IconSdkRaw.default ? IconSdkRaw.default : IconSdkRaw) as typeof IconSdkRaw;\nconst { IconService: IconServiceConstructor, Builder: IconBuilder, Converter: IconConverter } = IconSdk;\nexport interface CallData {\n target: string;\n method: string;\n params: string[];\n}\n\nexport enum SupportedChainId {\n MAINNET = 1,\n}\n\ninterface ChainInfo {\n readonly name: string;\n readonly node: string;\n readonly APIEndpoint: string;\n readonly debugAPIEndpoint: string;\n readonly chainId: number;\n readonly tracker: string;\n}\n\nexport const CHAIN_INFO: { readonly [chainId: number]: ChainInfo } = {\n [SupportedChainId.MAINNET]: {\n name: 'ICON Mainnet',\n node: 'https://ctz.solidwallet.io',\n APIEndpoint: 'https://ctz.solidwallet.io/api/v3',\n debugAPIEndpoint: 'https://api.icon.community/api/v3d',\n chainId: 1,\n tracker: 'https://tracker.icon.community',\n },\n};\n\nexport class IconXService extends XService {\n private static instance: IconXService;\n\n public iconService: IconService;\n\n private constructor(rpcUrl?: string) {\n super('ICON');\n const mainnetInfo = CHAIN_INFO[SupportedChainId.MAINNET];\n if (!mainnetInfo) throw new Error('ICON mainnet chain info not found');\n this.iconService = new IconServiceConstructor(\n new IconServiceConstructor.HttpProvider(rpcUrl ?? mainnetInfo.APIEndpoint),\n );\n }\n\n public static getInstance(rpcUrl?: string): IconXService {\n if (!IconXService.instance) {\n IconXService.instance = new IconXService(rpcUrl);\n }\n return IconXService.instance;\n }\n\n private async getAggregateData(requireSuccess: boolean, calls: CallData[]) {\n const rawTx = new IconBuilder.CallBuilder()\n // muticall address on mainnet\n .to('cxa4aa9185e23558cff990f494c1fd2845f6cbf741')\n .method('tryAggregate')\n .params({ requireSuccess: IconConverter.toHex(requireSuccess ? 1 : 0), calls })\n .build();\n\n try {\n const result = await this.iconService.call(rawTx).execute();\n const aggs = result['returnData'];\n\n const data = aggs.map((agg: Record<string, string>) => {\n if (agg['success'] === '0x0') {\n return null;\n }\n return agg['returnData'];\n });\n\n return data;\n } catch (err) {\n console.error(err);\n return Array(calls.length).fill(null);\n }\n }\n\n override async getBalances(address: string | undefined, xTokens: XToken[]) {\n if (!address) return {};\n\n const balances: Record<string, bigint> = {};\n\n const nativeXToken = xTokens.find(xToken => isNativeToken(xToken));\n const nonNativeXTokens = xTokens.filter(xToken => !isNativeToken(xToken));\n\n if (nativeXToken) {\n const balance = await this.iconService.getBalance(address).execute();\n balances[nativeXToken.address] = BigInt(balance.toFixed());\n }\n\n const cds: CallData[] = nonNativeXTokens.map(token => {\n return {\n target: token.address,\n method: 'balanceOf',\n params: [address],\n };\n });\n\n const data: (string | null)[] = await this.getAggregateData(\n false,\n cds.filter(cd => cd.target.startsWith('cx')),\n );\n\n return nonNativeXTokens.reduce((agg, token, idx) => {\n const balance = data[idx];\n if (balance) {\n balances[token.address] = BigInt(balance);\n }\n\n return agg;\n }, balances);\n }\n}\n","const ICONEX_RELAY_RESPONSE = 'ICONEX_RELAY_RESPONSE';\nconst ICONEX_RELAY_REQUEST = 'ICONEX_RELAY_REQUEST';\n\nexport enum ICONexRequestEventType {\n REQUEST_HAS_ACCOUNT = 'REQUEST_HAS_ACCOUNT',\n REQUEST_HAS_ADDRESS = 'REQUEST_HAS_ADDRESS',\n REQUEST_ADDRESS = 'REQUEST_ADDRESS',\n REQUEST_JSON = 'REQUEST_JSON',\n REQUEST_SIGNING = 'REQUEST_SIGNING',\n}\n\nexport enum ICONexResponseEventType {\n RESPONSE_HAS_ACCOUNT = 'RESPONSE_HAS_ACCOUNT',\n RESPONSE_HAS_ADDRESS = 'RESPONSE_HAS_ADDRESS',\n RESPONSE_ADDRESS = 'RESPONSE_ADDRESS',\n RESPONSE_JSON = 'RESPONSE_JSON',\n RESPONSE_SIGNING = 'RESPONSE_SIGNING',\n}\n\nexport interface ICONexRequestEvent {\n type: ICONexRequestEventType;\n // Request payload varies by event type (JSON-RPC params, signing data, etc).\n // `unknown` forces callers to validate before using — safer than `any`.\n payload?: unknown;\n}\n\nexport interface ICONexResponseEvent {\n type: ICONexResponseEventType;\n // Response payload is always a string: wallet address, tx hash, or signature.\n payload?: string;\n}\n\nexport type ICONexEvent = ICONexRequestEvent | ICONexResponseEvent;\n\nexport const request = (event: ICONexRequestEvent): Promise<ICONexResponseEvent> => {\n return new Promise((resolve, reject) => {\n // evt is a CustomEvent dispatched by the ICONex/Hana extension. Type the handler\n // param so evt.detail is properly typed instead of implicit `any`.\n const handler = (evt: Event) => {\n window.removeEventListener(ICONEX_RELAY_RESPONSE, handler);\n resolve((evt as CustomEvent<ICONexResponseEvent>).detail);\n };\n\n window.addEventListener(ICONEX_RELAY_RESPONSE, handler);\n window.dispatchEvent(\n new CustomEvent(ICONEX_RELAY_REQUEST, {\n detail: event,\n }),\n );\n });\n};\n","import type { XAccount } from '@/types/index.js';\nimport { ICONexRequestEventType, ICONexResponseEventType, request } from './iconex/index.js';\n\nimport { XConnector } from '@/core/XConnector.js';\nimport { assert, hasBooleanProperty, isRecord } from '@/shared/guards.js';\nimport { WALLET_METADATA } from '@/constants.js';\n\nconst isHanaWallet = (value: unknown): value is { available?: boolean } => {\n return isRecord(value) && (value.available === undefined || hasBooleanProperty(value, 'available'));\n};\n\nexport class IconHanaXConnector extends XConnector {\n constructor() {\n super('ICON', 'Hana Wallet', 'hana');\n }\n\n public override get isInstalled(): boolean {\n if (typeof window === 'undefined') return false;\n const hanaWallet = (window as unknown as Record<string, unknown>).hanaWallet;\n return isHanaWallet(hanaWallet) && hanaWallet.available === true;\n }\n\n public override get installUrl(): string {\n return WALLET_METADATA.hana.installUrl;\n }\n\n async connect(): Promise<XAccount | undefined> {\n const hanaWallet = (window as unknown as Record<string, unknown>).hanaWallet;\n assert(isHanaWallet(hanaWallet) || hanaWallet === undefined, '[IconHanaXConnector] invalid window.hanaWallet type');\n\n if (!hanaWallet || !hanaWallet.available) {\n window.open(WALLET_METADATA.hana.installUrl, '_blank', 'noopener,noreferrer');\n return;\n }\n\n const detail = await request({\n type: ICONexRequestEventType.REQUEST_ADDRESS,\n });\n\n if (detail?.type === ICONexResponseEventType.RESPONSE_ADDRESS) {\n return {\n address: detail?.payload,\n xChainType: this.xChainType,\n };\n }\n\n console.warn('[IconHanaXConnector] connect: unexpected response from Hana wallet', detail);\n return undefined;\n }\n\n async disconnect(): Promise<void> {\n console.log('HanaIconXConnector disconnected');\n }\n\n public override get icon(): string {\n return WALLET_METADATA.hana.icon;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/xchains/stellar/CustomSorobanServer.ts","../src/xchains/stellar/utils.ts","../src/xchains/stellar/StellarXService.ts","../src/xchains/stellar/StellarWalletsKitXConnector.ts"],"names":["rpc"],"mappings":";;;;;;AASA,IAAM,mBAAA,GAAN,cAAkC,GAAA,CAAI,MAAA,CAAO;AAAA,EAC1B,aAAA;AAAA,EAEjB,WAAA,CAAY,WAAmB,aAAA,EAAuC;AACpE,IAAA,KAAA,CAAM,SAAA,EAAW;AAAA,MACf,SAAA,EAAW;AAAA,KACZ,CAAA;AACD,IAAA,IAAA,CAAK,aAAA,GAAgB,aAAA;AAAA,EACvB;AAAA,EAEA,MAAe,oBACb,EAAA,EAC8C;AAC9C,IAAA,MAAM,cAAA,GAAiB;AAAA,MACrB,MAAA,EAAQ,MAAA;AAAA,MACR,OAAA,EAAS;AAAA,QACP,cAAA,EAAgB,kBAAA;AAAA,QAChB,GAAG,IAAA,CAAK;AAAA,OACV;AAAA,MACA,IAAA,EAAM,KAAK,SAAA,CAAU;AAAA,QACnB,EAAA,EAAI,CAAA;AAAA,QACJ,OAAA,EAAS,KAAA;AAAA,QACT,MAAA,EAAQ,qBAAA;AAAA,QACR,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n type Operation,\n rpc,\n type Transaction,\n} from '@stellar/stellar-sdk';\n\nclass CustomSorobanServer extends rpc.Server {\n private readonly customHeaders: Record<string, string>;\n\n constructor(serverUrl: string, customHeaders: Record<string, string>) {\n super(serverUrl, {\n allowHttp: true,\n });\n this.customHeaders = customHeaders;\n }\n\n override async simulateTransaction(\n tx: Transaction<Memo<MemoType>, Operation[]>,\n ): Promise<rpc.Api.SimulateTransactionResponse> {\n const requestOptions = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...this.customHeaders,\n },\n body: JSON.stringify({\n id: 1,\n jsonrpc: '2.0',\n method: 'simulateTransaction',\n params: {\n transaction: tx.toXDR(),\n },\n }),\n };\n\n const response = await fetch(`${this.serverURL}`, requestOptions);\n if (!response.ok) {\n throw new Error(`HTTP error simulating TX! status: ${response.status}`);\n }\n // Parse raw JSON-RPC payload into the discriminated union expected by callers\n return response.json().then(json => rpc.parseRawSimulation(json.result));\n }\n\n override async sendTransaction(tx: Transaction | FeeBumpTransaction): Promise<rpc.Api.SendTransactionResponse> {\n const requestOptions = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...this.customHeaders,\n },\n body: JSON.stringify({\n id: 1,\n jsonrpc: '2.0',\n method: 'sendTransaction',\n params: {\n transaction: tx.toXDR(),\n },\n }),\n };\n\n const response = await fetch(`${this.serverURL}`, requestOptions);\n if (!response.ok) {\n throw new Error(`HTTP error submitting TX! status: ${response.status}`);\n }\n return response.json().then(json => json.result);\n }\n\n override async getTransaction(hash: string): Promise<rpc.Api.GetTransactionResponse> {\n const requestOptions = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...this.customHeaders,\n },\n body: JSON.stringify({\n id: 1,\n jsonrpc: '2.0',\n method: 'getTransaction',\n params: { hash },\n }),\n };\n\n const response = await fetch(`${this.serverURL}`, requestOptions);\n if (!response.ok) {\n throw new Error(`HTTP error getting TX! status: ${response.status}`);\n }\n return response.json().then(json => json.result);\n }\n}\n\nexport default CustomSorobanServer;\n","import {\n Address,\n Contract,\n type Memo,\n type MemoType,\n type Operation,\n rpc,\n TimeoutInfinite,\n type Transaction,\n type TransactionBuilder,\n scValToBigInt,\n} from '@stellar/stellar-sdk';\nimport type CustomSorobanServer from './CustomSorobanServer.js';\n\nexport const STELLAR_RLP_MSG_TYPE = { type: 'symbol' };\n\n// Can be used whenever you need an Address argument for a contract method\nexport const accountToScVal = (account: string) => new Address(account).toScVal();\n\nexport const simulateTx = (\n tx: Transaction<Memo<MemoType>, Operation[]>,\n server: CustomSorobanServer,\n): Promise<rpc.Api.SimulateTransactionResponse> => server.simulateTransaction(tx);\n\nexport const getTokenBalance = async (\n address: string,\n tokenId: string,\n txBuilder: TransactionBuilder,\n server: CustomSorobanServer,\n) => {\n const params = [accountToScVal(address)];\n const contract = new Contract(tokenId);\n const tx = txBuilder\n .addOperation(contract.call('balance', ...params))\n .setTimeout(TimeoutInfinite)\n .build();\n\n const result = await simulateTx(tx, server);\n\n // Also throws on restore responses — invalid for read-only balance simulation\n if (!rpc.Api.isSimulationSuccess(result)) {\n throw new Error(`Simulation failed: ${JSON.stringify(result)}`);\n }\n\n return result.result ? scValToBigInt(result.result.retval) : 0n;\n};\n","import { XService } from '@/core/XService.js';\nimport { StellarWalletsKit, WalletNetwork, allowAllModules } from '@creit.tech/stellar-wallets-kit';\nimport * as StellarSdk from '@stellar/stellar-sdk';\nimport CustomSorobanServer from './CustomSorobanServer.js';\nimport { getTokenBalance } from './utils.js';\nimport type { XToken } from '@sodax/types';\nimport { STELLAR_DEFAULT_HORIZON_RPC_URL, STELLAR_DEFAULT_SOROBAN_RPC_URL } from '@/constants.js';\n\n/** Base reserve in stroops (0.5 XLM). Each subentry (trustline, signer, data entry, offer) adds one base reserve. */\nconst STELLAR_BASE_RESERVE_STROOPS = 5_000_000;\n\n/** Horizon account fields used for minimum balance. Minimum = (2 + subentry_count + num_sponsoring - num_sponsored) * base_reserve + selling_liabilities. */\ninterface StellarAccountReserveFields {\n subentry_count?: number;\n num_sponsoring?: number;\n num_sponsored?: number;\n}\n\n/** Parse XLM balance string (e.g. \"198.8944970\") to stroops (1 XLM = 10^7 stroops). */\nfunction parseXlmBalanceToStroops(balanceStr: string): bigint {\n const parts = balanceStr.split('.');\n const whole = parts[0] ?? '0';\n const frac = (parts[1] ?? '').padEnd(7, '0').slice(0, 7);\n return BigInt(whole + frac);\n}\n\nexport class StellarXService extends XService {\n private static instance: StellarXService;\n\n public walletsKit: StellarWalletsKit;\n public server: StellarSdk.Horizon.Server;\n public sorobanServer: CustomSorobanServer;\n\n private constructor(horizonRpcUrl?: string, sorobanRpcUrl?: string) {\n super('STELLAR');\n\n this.walletsKit = new StellarWalletsKit({\n network: WalletNetwork.PUBLIC,\n modules: allowAllModules(),\n });\n\n this.server = new StellarSdk.Horizon.Server(horizonRpcUrl ?? STELLAR_DEFAULT_HORIZON_RPC_URL, { allowHttp: true });\n this.sorobanServer = new CustomSorobanServer(sorobanRpcUrl ?? STELLAR_DEFAULT_SOROBAN_RPC_URL, {});\n }\n\n public static getInstance(horizonRpcUrl?: string, sorobanRpcUrl?: string): StellarXService {\n if (!StellarXService.instance) {\n StellarXService.instance = new StellarXService(horizonRpcUrl, sorobanRpcUrl);\n } else {\n if (horizonRpcUrl) {\n StellarXService.instance.server = new StellarSdk.Horizon.Server(horizonRpcUrl, { allowHttp: true });\n }\n if (sorobanRpcUrl) {\n StellarXService.instance.sorobanServer = new CustomSorobanServer(sorobanRpcUrl, {});\n }\n }\n return StellarXService.instance;\n }\n\n override async getBalance(address: string | undefined, xToken: XToken): Promise<bigint> {\n if (!address) return BigInt(0);\n\n const stellarAccount = await this.server.loadAccount(address);\n\n if (xToken.symbol === 'XLM') {\n const xlmBalance = stellarAccount.balances.find(balance => balance.asset_type === 'native');\n if (xlmBalance) {\n const rawBalanceStroops = parseXlmBalanceToStroops(xlmBalance.balance);\n const sellingLiabilitiesStroops = (xlmBalance as { selling_liabilities?: string }).selling_liabilities\n ? parseXlmBalanceToStroops((xlmBalance as { selling_liabilities: string }).selling_liabilities)\n : BigInt(0);\n const reserveFields = stellarAccount as unknown as StellarAccountReserveFields;\n const subentryCount = reserveFields.subentry_count ?? 0;\n const numSponsoring = reserveFields.num_sponsoring ?? 0;\n const numSponsored = reserveFields.num_sponsored ?? 0;\n // Minimum balance = (2 + subentry_count + num_sponsoring - num_sponsored) * base_reserve + selling_liabilities.\n // When account has sponsored reserves (num_sponsored > 0), those reserves are paid by the sponsor, so we don't subtract them.\n const reserveCount = Math.max(0, 2 + subentryCount + numSponsoring - numSponsored);\n const minBalanceStroops =\n BigInt(reserveCount) * BigInt(STELLAR_BASE_RESERVE_STROOPS) + sellingLiabilitiesStroops;\n const availableStroops =\n rawBalanceStroops > minBalanceStroops ? rawBalanceStroops - minBalanceStroops : BigInt(0);\n return availableStroops;\n }\n } else {\n try {\n const txBuilder = new StellarSdk.TransactionBuilder(stellarAccount, {\n fee: StellarSdk.BASE_FEE,\n networkPassphrase: StellarSdk.Networks.PUBLIC,\n });\n\n const balance = await getTokenBalance(address, xToken.address, txBuilder, this.sorobanServer);\n return balance;\n } catch (e) {\n console.error(`Error while fetching token on Stellar: ${xToken.symbol}, Error: ${e}`);\n }\n }\n\n return BigInt(0);\n }\n}\n","import type { XAccount } from '@/types/index.js';\n\nimport { XConnector } from '@/core/index.js';\nimport { StellarXService } from './StellarXService.js';\n\nexport type StellarWalletType = {\n icon: string;\n id: string;\n isAvailable: boolean;\n name: string;\n type: string;\n url: string;\n};\n\nexport class StellarWalletsKitXConnector extends XConnector {\n _wallet: StellarWalletType;\n\n constructor(wallet: StellarWalletType) {\n super('STELLAR', wallet.name, wallet.id);\n this._wallet = wallet;\n }\n\n getXService(): StellarXService {\n return StellarXService.getInstance();\n }\n\n async connect(): Promise<XAccount | undefined> {\n const kit = this.getXService().walletsKit;\n\n if (!this._wallet) {\n return;\n }\n\n if (!this._wallet.isAvailable) {\n // Throw instead of silently navigating to the install URL — callers\n // that bypass `useWalletModal.selectWallet`'s pre-check otherwise\n // see a tab open with no surfaced error. Consumers read\n // `connector.installUrl` to render the install CTA on the caught\n // error.\n throw new Error(`${this._wallet.name} is not installed. Install the wallet and reload the page.`);\n }\n\n kit.setWallet(this._wallet.id);\n const { address } = await kit.getAddress();\n\n return {\n address: address,\n xChainType: this.xChainType,\n };\n }\n\n async disconnect(): Promise<void> {}\n\n public override get icon(): string {\n return this._wallet.icon;\n }\n\n public override get isInstalled(): boolean {\n return this._wallet.isAvailable;\n }\n\n public override get installUrl(): string | undefined {\n return this._wallet.url;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/xchains/sui/SuiXService.ts","../src/xchains/sui/SuiXConnector.ts"],"names":[],"mappings":";;;;;AAcO,IAAM,WAAA,GAAN,MAAM,YAAA,SAAoB,QAAA,CAAS;AAAA,EACxC,OAAe,QAAA;AAAA;AAAA;AAAA;AAAA,EAKR,SAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EAEC,WAAA,GAAc;AACpB,IAAA,KAAA,CAAM,KAAK,CAAA;AAAA,EACb;AAAA,EAEA,OAAc,WAAA,GAA2B;AACvC,IAAA,IAAI,CAAC,aAAY,QAAA,EAAU;AACzB,MAAA,YAAA,CAAY,QAAA,GAAW,IAAI,YAAA,EAAY;AAAA,IACzC;AACA,IAAA,OAAO,YAAA,CAAY,QAAA;AAAA,EACrB;AAAA,EAEA,oBAAA,GAAuD;AACrD,IAAA,IAAI,CAAC,KAAK,SAAA,IAAa,CAAC,KAAK,SAAA,IAAa,CAAC,KAAK,UAAA,EAAY;AAC1D,MAAA,OAAA,CAAQ,IAAA;AAAA,QACN,0FAAA;AAAA,QACA,EAAE,SAAA,EAAW,CAAC,CAAC,KAAK,SAAA,EAAW,SAAA,EAAW,CAAC,CAAC,KAAK,SAAA,EAAW,UAAA,EAAY,CAAC,CAAC,KAAK,UAAA;AAAW,OAC5F;AACA,MAAA,OAAO,MAAA;AAAA,IACT;AAIA,I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K,MAAA,CAAO,IAAA;AAAA,EACrB;AACF","file":"chunk-7ULB6DW4.mjs","sourcesContent":["import { XService } from '@/core/XService.js';\nimport type { XToken, ISuiWalletProvider } from '@sodax/types';\nimport { SuiWalletProvider } from '@sodax/wallet-sdk-core';\nimport { isNativeToken } from '@/utils/index.js';\nimport { assertSuiProviderShape } from '@/shared/guards.js';\n\n// These fields are hydrated by SuiHydrator from @mysten/dapp-kit hooks.\n// We use structural interfaces instead of importing nominal types from @mysten/wallet-standard\n// because dapp-kit may resolve a different version than wallet-sdk-core, causing nominal mismatch.\n// The `getBalance` method is the only field we call directly — the rest are passed through.\ninterface SuiClientLike {\n getBalance(input: { owner: string; coinType: string }): Promise<{ totalBalance: string }>;\n}\n\nexport class SuiXService extends XService {\n private static instance: SuiXService;\n\n // Hydrated by SuiHydrator. Start undefined because wallet may not be connected yet.\n // suiClient is typed structurally for the methods we call directly.\n // suiWallet/suiAccount are opaque — stored and passed through to SuiWalletProvider.\n public suiClient: SuiClientLike | undefined;\n public suiWallet: unknown;\n public suiAccount: unknown;\n\n private constructor() {\n super('SUI');\n }\n\n public static getInstance(): SuiXService {\n if (!SuiXService.instance) {\n SuiXService.instance = new SuiXService();\n }\n return SuiXService.instance;\n }\n\n createWalletProvider(): ISuiWalletProvider | undefined {\n if (!this.suiClient || !this.suiWallet || !this.suiAccount) {\n console.warn(\n '[SuiXService] createWalletProvider: missing dependencies — wallet not connected yet',\n { hasClient: !!this.suiClient, hasWallet: !!this.suiWallet, hasAccount: !!this.suiAccount },\n );\n return undefined;\n }\n\n // Runtime validation before passing data to wallet-sdk-core. This avoids \"trust me bro\" casting.\n // Note: we validate the minimum shape we rely on; the exact nominal types may differ by package version.\n assertSuiProviderShape('SuiXService', this.suiClient, this.suiWallet, this.suiAccount);\n\n // Version mismatch cast: dapp-kit hooks return types from their bundled @mysten/wallet-standard,\n // which differs nominally from wallet-sdk-core's version. Structurally identical at runtime.\n type SuiWalletProviderConfig = ConstructorParameters<typeof SuiWalletProvider>[0];\n return new SuiWalletProvider({\n client: this.suiClient,\n wallet: this.suiWallet,\n account: this.suiAccount,\n } as unknown as SuiWalletProviderConfig);\n }\n\n // getBalance is not used because getBalances uses getAllBalances which returns all balances\n\n override async getBalances(address: string | undefined, xTokens: readonly XToken[]): Promise<Record<string, bigint>> {\n if (!address || !this.suiClient) return {};\n // Capture in local so the closure sees a narrowed (non-undefined) reference.\n const client = this.suiClient;\n try {\n const balancePromises = xTokens.map(async xToken => {\n let coinType = isNativeToken(xToken) ? '0x2::sui::SUI' : xToken.address;\n\n // TODO: hard coded for getting legacy bnUSD balance\n if (\n coinType ===\n '0x03917a812fe4a6d6bc779c5ab53f8a80ba741f8af04121193fc44e0f662e2ceb::balanced_dollar::BALANCED_DOLLAR'\n ) {\n coinType =\n '0x3917a812fe4a6d6bc779c5ab53f8a80ba741f8af04121193fc44e0f662e2ceb::balanced_dollar::BALANCED_DOLLAR';\n }\n\n const balance = await client.getBalance({\n owner: address,\n coinType: coinType,\n });\n\n return {\n address: xToken.address,\n balance: balance ? BigInt(balance.totalBalance) : undefined,\n };\n });\n\n const results = await Promise.all(balancePromises);\n\n const tokenMap: Record<string, bigint> = {};\n results.forEach(result => {\n if (result.balance !== undefined) {\n tokenMap[result.address] = result.balance;\n }\n });\n\n return tokenMap;\n } catch (error) {\n console.error('[wallet-sdk-react] SUI getBalances failed:', error);\n return {};\n }\n }\n}\n","import type { XAccount } from '@/types/index.js';\n\nimport { XConnector } from '@/core/index.js';\nimport { SuiXService } from './SuiXService.js';\nimport { assert, hasOptionalStringProperty, hasStringProperty, isRecord } from '@/shared/guards.js';\n\n// Structural interface for what we actually use from a Sui wallet.\n// We don't import the nominal type from @mysten/wallet-standard because\n// @mysten/dapp-kit may resolve a different version, causing nominal mismatch.\n// Structural typing avoids this: as long as the object has these fields, it works.\ninterface SuiWalletInfo {\n id?: string;\n name: string;\n icon?: string;\n}\n\nconst isSuiWalletInfo = (value: unknown): value is SuiWalletInfo => {\n return (\n isRecord(value) &&\n hasStringProperty(value, 'name') &&\n // Some wallets may not expose `id` — in that case we fall back to `name` for stability.\n // We still validate if it exists.\n hasOptionalStringProperty(value, 'id') &&\n hasOptionalStringProperty(value, 'icon')\n );\n};\n\nexport class SuiXConnector extends XConnector {\n public readonly wallet: SuiWalletInfo;\n\n constructor(wallet: unknown) {\n assert(isSuiWalletInfo(wallet), '[SuiXConnector] invalid wallet object');\n\n const id = wallet.id ?? wallet.name;\n // After the fallback, `id` is always defined.\n assert(typeof id === 'string' && id.length > 0, '[SuiXConnector] invalid wallet id');\n\n super('SUI', wallet.name, id);\n this.wallet = { id, name: wallet.name, icon: wallet.icon };\n }\n\n getXService(): SuiXService {\n return SuiXService.getInstance();\n }\n\n async connect(): Promise<XAccount | undefined> {\n return;\n }\n\n async disconnect(): Promise<void> {}\n\n public override get icon(): string | undefined {\n return this.wallet.icon;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/xchains/injective/InjectiveXService.ts","../src/xchains/injective/InjectiveXConnector.ts"],"names":["InjectiveChainId"],"mappings":";;;;;;;;;;AASO,IAAM,iBAAA,GAAN,MAAM,kBAAA,SAA0B,QAAA,CAAS;AAAA,EAC9C,OAAe,QAAA;AAAA,EAER,cAAA;AAAA,EACA,8BAAA;AAAA,EACA,gBAAA;AAAA,EACA,cAAA;AAAA,EAEC,YAAY,SAAA,EAAgC;AAClD,IAAA,KAAA,CAAM,WAAW,CAAA;AAEjB,IAAA,MAAM,QAAA,GAAW,mBAAA,CAAoB,OAAA,CAAQ,OAAO,CAAA;AAIpD,IAAA,MAAM,SAAA,GAAY;AAAA,MAChB,GAAG,QAAA;AAAA,MACH,OAAA,EAAS,SAAA,EAAW,OAAA,IAAW,QAAA,CAAS,OAAA;AAAA,MACxC,IAAA,EAAM,SAAA,EAAW,IAAA,IAAQ,QAAA,CAAS;AAAA,KACpC;AAEA,IAAA,IAAA,CAAK,cAAA,GAAiB,IAAI,cAAA,CAA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AAAA,IACT;AAEA,IAAA,MAAM,YAAA,GAAe,UAAU,CAAC,CAAA;AAChC,IAAA,IAAI,CAAC,YAAA,EAAc;AACjB,MAAA,OAAA,CAAQ,IAAA,CAAK,CAAA,+BAAA,EAAkC,IAAA,CAAK,MAAM,CAAA,+BAAA,CAAiC,CAAA;AAC3F,MAAA,OAAO,MAAA;AAAA,IACT;AACA,IAAA,MAAM,UAAU,kBAAA,CAAmB,IAAA,CAAK,MAAM,CAAA,GAAI,mBAAA,CAAoB,YAAY,CAAA,GAAI,YAAA;AAEtF,IAAA,OAAO;AAAA,MACL,OAAA;AAAA,MACA,YAAY,IAAA,CAAK;AAAA,KACnB;AAAA,EACF;AAAA,EAEA,MAAM,UAAA,GAA4B;AAChC,IAAA,IAAI,kBAAA,CAAmB,IAAA,CAAK,MAAM,CAAA,EAAG;AACnC,MAAA,MAAM,cAAA,GAAiB,IAAA,CAAK,WAAA,EAAY,CAAE,cAAA;AAC1C,MAAA,MAAM,cAAA,CAAe,SAAA,CAAU,IAAA,CAAK,MAAM,CAAA;AAC1C,MAAA,MAAM,eAAe,UAAA,EAAW;AAAA,IAClC;AAAA,EACF;AAAA,EAEA,IAAoB,IAAA,GAA2B;AAC7C,IAAA,OAAO,YAAA,CAAa,KAAK,MAAM,CAAA;AAAA,EACjC;AAAA,EAEA,IAAoB,WAAA,GAAuB;AACzC,IAAA,IAAI,qBAAA,CAAsB,IAAA,CAAK,MAAM,CAAA,EAAG;AACtC,MAAA,OAAO,uBAAA,CAAwB,KAAK,MAAM,CAAA;AAAA,IAC5C;AAGA,IAAA,OAAO,IAAA;AAAA,EACT;AACF","file":"chunk-BKJB527E.mjs","sourcesContent":["import { XService } from '@/core/XService.js';\nimport { Network, getNetworkEndpoints } from '@injectivelabs/networks';\nimport { ChainGrpcWasmApi, IndexerGrpcAccountPortfolioApi } from '@injectivelabs/sdk-ts';\nimport { ChainId as InjectiveChainId } from '@injectivelabs/ts-types';\nimport { MsgBroadcaster } from '@injectivelabs/wallet-core';\nimport type { InjectiveRpcConfig, XToken } from '@sodax/types';\nimport { mainnet } from 'wagmi/chains';\nimport { WalletStrategy } from '@injectivelabs/wallet-strategy';\n\nexport class InjectiveXService extends XService {\n private static instance: InjectiveXService;\n\n public walletStrategy: WalletStrategy;\n public indexerGrpcAccountPortfolioApi: IndexerGrpcAccountPortfolioApi;\n public chainGrpcWasmApi: ChainGrpcWasmApi;\n public msgBroadcaster: MsgBroadcaster;\n\n private constructor(rpcConfig?: InjectiveRpcConfig) {\n super('INJECTIVE');\n\n const defaults = getNetworkEndpoints(Network.Mainnet);\n // Only `indexer` + `grpc` are overridable — the rest of the endpoints object\n // (rest, rpc, explorer, …) keeps the @injectivelabs/networks mainnet defaults.\n // Extend `InjectiveRpcConfig` if more endpoints need to be consumer-configurable.\n const endpoints = {\n ...defaults,\n indexer: rpcConfig?.indexer || defaults.indexer,\n grpc: rpcConfig?.grpc || defaults.grpc,\n };\n\n this.walletStrategy = new WalletStrategy({\n chainId: InjectiveChainId.Mainnet,\n strategies: {},\n evmOptions: {\n evmChainId: mainnet.id,\n rpcUrl: mainnet.rpcUrls.default.http[0],\n },\n });\n\n this.indexerGrpcAccountPortfolioApi = new IndexerGrpcAccountPortfolioApi(endpoints.indexer);\n this.chainGrpcWasmApi = new ChainGrpcWasmApi(endpoints.grpc);\n this.msgBroadcaster = new MsgBroadcaster({\n walletStrategy: this.walletStrategy,\n network: Network.Mainnet,\n endpoints,\n });\n }\n\n /**\n * @param rpcConfig - Only applied on first call. Subsequent calls return the\n * existing instance unchanged — gRPC/Indexer clients are built in the\n * constructor and can't be rebuilt at runtime. Pass the desired endpoints\n * via `SodaxWalletProvider.config.rpcConfig` once at app init.\n */\n public static getInstance(rpcConfig?: InjectiveRpcConfig): InjectiveXService {\n if (!InjectiveXService.instance) {\n InjectiveXService.instance = new InjectiveXService(rpcConfig);\n }\n return InjectiveXService.instance;\n }\n\n override async getBalance(address: string | undefined, xToken: XToken) {\n if (!address) return 0n;\n\n const portfolio = await this.indexerGrpcAccountPortfolioApi.fetchAccountPortfolioBalances(address);\n\n const xTokenAddress = xToken.address;\n\n const balance = portfolio.bankBalancesList.find(_balance => _balance.denom === xTokenAddress);\n if (balance) {\n return BigInt(balance.amount);\n }\n\n return 0n;\n }\n}\n","import type { XAccount } from '@/types/index.js';\nimport { XConnector } from '@/core/index.js';\nimport { getInjectiveAddress } from '@injectivelabs/sdk-ts';\nimport { type Wallet, isEvmBrowserWallet, isCosmosBrowserWallet } from '@injectivelabs/wallet-base';\nimport { isCosmosWalletInstalled } from '@injectivelabs/wallet-cosmos';\nimport { InjectiveXService } from './InjectiveXService.js';\n\nconst WALLET_ICONS: Partial<Record<Wallet, string>> = {\n metamask: 'https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/metamask.svg',\n keplr: 'https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/keplr.svg',\n leap: 'https://assets.leapwallet.io/logos/leap-cosmos-logo.svg',\n rabby: 'https://raw.githubusercontent.com/RabbyHub/logo/master/symbol.svg',\n phantom: 'https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/phantom.svg',\n 'okx-wallet': 'https://static.okx.com/cdn/assets/imgs/247/58E63FEA47A2B7D7.png',\n 'trust-wallet': 'https://trustwallet.com/assets/images/media/assets/twLogo.svg',\n};\n\nexport class InjectiveXConnector extends XConnector {\n private wallet: Wallet;\n\n constructor(name: string, wallet: Wallet) {\n super('INJECTIVE', name, wallet);\n this.wallet = wallet;\n }\n\n getXService(): InjectiveXService {\n return InjectiveXService.getInstance();\n }\n\n async connect(): Promise<XAccount | undefined> {\n if (isCosmosBrowserWallet(this.wallet) && !isCosmosWalletInstalled(this.wallet)) {\n console.warn(`[InjectiveXConnector] connect: ${this.wallet} cosmos wallet not installed`);\n return undefined;\n }\n\n const walletStrategy = this.getXService().walletStrategy;\n await walletStrategy.setWallet(this.wallet);\n const addresses = await walletStrategy.getAddresses();\n\n if (!addresses?.length) {\n console.warn(`[InjectiveXConnector] connect: ${this.wallet} returned no addresses`);\n return undefined;\n }\n\n const firstAddress = addresses[0];\n if (!firstAddress) {\n console.warn(`[InjectiveXConnector] connect: ${this.wallet} returned empty addresses array`);\n return undefined;\n }\n const address = isEvmBrowserWallet(this.wallet) ? getInjectiveAddress(firstAddress) : firstAddress;\n\n return {\n address,\n xChainType: this.xChainType,\n };\n }\n\n async disconnect(): Promise<void> {\n if (isEvmBrowserWallet(this.wallet)) {\n const walletStrategy = this.getXService().walletStrategy;\n await walletStrategy.setWallet(this.wallet);\n await walletStrategy.disconnect();\n }\n }\n\n public override get icon(): string | undefined {\n return WALLET_ICONS[this.wallet];\n }\n\n public override get isInstalled(): boolean {\n if (isCosmosBrowserWallet(this.wallet)) {\n return isCosmosWalletInstalled(this.wallet);\n }\n // EVM / other injective wallets: wallet-strategy handles install errors at connect time.\n // Default to true so users can attempt connect — Phase 3 classifier will surface walletNotInstalled if it fails.\n return true;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/xchains/near/NearXService.ts","../src/xchains/near/NearXConnector.ts"],"names":[],"mappings":";;;;;AAMO,IAAM,YAAA,GAAN,MAAM,aAAA,SAAqB,QAAA,CAAS;AAAA,EACzC,OAAe,QAAA;AAAA,EAER,cAAA;AAAA,EACA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQC,WAAA,CAAY,SAAiB,oBAAA,EAAsB;AACzD,IAAA,KAAA,CAAM,MAAM,CAAA;AAEZ,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,cAAA,GAAiB,IAAI,aAAA,CAAc;AAAA,MACtC,OAAA,EAAS,SAAA;AAAA,MACT,MAAA,EAAQ,OAAA;AAAA,MACR,WAAA,EAAa,IAAA;AAAA,MACb,eAAA,EAAiB,CAAC,YAAY;AAAA,KAC/B,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAc,YAAY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GAAyC;AAC7C,IAAA,MAAM,cAAA,GAAiB,IAAA,CAAK,WAAA,EAAY,CAAE,cAAA;AAC1C,IAAA,MAAM,MAAA,GAAS,MAAM,cAAA,CAAe,OAAA,CAAQ,EAAE,UAAU,IAAA,CAAK,OAAA,CAAQ,QAAA,CAAS,EAAA,EAAI,CAAA;AAClF,IAAA,MAAM,QAAA,GAAW,MAAM,MAAA,CAAO,WAAA,EAAY;AAE1C,IAAA,IAAI,SAAS,MAAA,KAAW,CAAA,IAAK,QAAA,CAAS,CAAC,MAAM,MAAA,EAAW;AACtD,MAAA,OAAA,CAAQ,KAAK,CAAA,0BAAA,EAA6B,IAAA,CAAK,OAAA,CAAQ,QAAA,CAAS,IAAI,CAAA,qBAAA,CAAuB,CAAA;AAC3F,MAAA,OAAO,MAAA;AAAA,IACT;AAEA,IAAA,OAAO;AAAA,MACL,OAAA,EAAS,QAAA,CAAS,CAAC,CAAA,CAAE,SAAA;AAAA,MACrB,YAAY,IAAA,CAAK;AAAA,KACnB;AAAA,EACF;AAAA,EAEA,MAAM,UAAA,GAA4B;AAChC,IAAA,MAAM,cAAA,GAAiB,IAAA,CAAK,WAAA,EAAY,CAAE,cAAA;AAC1C,IAAA,MAAM,cAAA,CAAe,UAAA,CAAW,IAAA,CAAK,OAAO,CAAA;AAAA,EAC9C;AAAA,EAEA,IAAoB,IAAA,GAAe;AACjC,IAAA,OAAO,IAAA,CAAK,QAAQ,QAAA,CAAS,IAAA;AAAA,EAC/B;AACF","file":"chunk-BXJLBR4G.mjs","sourcesContent":["import { XService } from '@/core/XService.js';\nimport type { XToken } from '@sodax/types';\nimport { NearConnector } from '@hot-labs/near-connect';\nimport { JsonRpcProvider } from 'near-api-js';\nimport { NEAR_DEFAULT_RPC_URL } from '@/constants.js';\n\nexport class NearXService extends XService {\n private static instance: NearXService;\n\n public walletSelector: NearConnector;\n public rpcUrl: string;\n\n /**\n * @param rpcUrl - Used by `getBalance` via `JsonRpcProvider({ url: rpcUrl })`.\n * Does NOT affect `walletSelector` — `@hot-labs/near-connect` only accepts\n * the network preset name (`'mainnet'`/`'testnet'`) and fetches RPC internally.\n * Custom RPC is therefore read-only for balance queries.\n */\n private constructor(rpcUrl: string = NEAR_DEFAULT_RPC_URL) {\n super('NEAR');\n\n this.rpcUrl = rpcUrl;\n this.walletSelector = new NearConnector({\n network: 'mainnet',\n logger: console,\n autoConnect: true,\n excludedWallets: ['okx-wallet'],\n });\n }\n\n /**\n * @param rpcUrl - Re-applied on every call (matches StacksXService semantics).\n * `rpcUrl` only drives `getBalance` via a per-call `JsonRpcProvider`, so it's\n * safe to update at runtime — no persistent chain client to rebuild.\n */\n public static getInstance(rpcUrl?: string): NearXService {\n if (!NearXService.instance) {\n NearXService.instance = new NearXService(rpcUrl);\n } else if (rpcUrl) {\n NearXService.instance.rpcUrl = rpcUrl;\n }\n return NearXService.instance;\n }\n\n override async getBalance(address: string | undefined, xToken: XToken): Promise<bigint> {\n // reference: https://near.github.io/near-api-js/classes/_near-js_providers.json-rpc-provider.JsonRpcProvider.html\n const provider = new JsonRpcProvider({ url: this.rpcUrl });\n\n // get native balance\n if (xToken.symbol === 'NEAR') {\n const account = await provider.viewAccount({ accountId: address ?? '' });\n return BigInt(account.amount);\n }\n\n // Near Fungible Token Standard(https://github.com/near/NEPs/blob/master/neps/nep-0141.md)\n // get balance of the token\n\n const res = await provider.callFunction<number>({\n contractId: xToken.address,\n method: 'ft_balance_of',\n args: { account_id: address },\n });\n return BigInt(res ?? 0);\n }\n}\n","import type { XAccount } from '@/types/index.js';\n\nimport { XConnector } from '@/core/index.js';\nimport type { NearWalletBase } from '@hot-labs/near-connect';\nimport { NearXService } from './NearXService.js';\n\nexport class NearXConnector extends XConnector {\n _wallet: NearWalletBase;\n\n constructor(wallet: NearWalletBase) {\n super('NEAR', wallet.manifest.name, wallet.manifest.id);\n this._wallet = wallet;\n }\n\n getXService(): NearXService {\n return NearXService.getInstance();\n }\n\n async connect(): Promise<XAccount | undefined> {\n const walletSelector = this.getXService().walletSelector;\n const wallet = await walletSelector.connect({ walletId: this._wallet.manifest.id });\n const accounts = await wallet.getAccounts();\n\n if (accounts.length === 0 || accounts[0] === undefined) {\n console.warn(`[NearXConnector] connect: ${this._wallet.manifest.name} returned no accounts`);\n return undefined;\n }\n\n return {\n address: accounts[0].accountId,\n xChainType: this.xChainType,\n };\n }\n\n async disconnect(): Promise<void> {\n const walletSelector = this.getXService().walletSelector;\n await walletSelector.disconnect(this._wallet);\n }\n\n public override get icon(): string {\n return this._wallet.manifest.icon;\n }\n}\n"]}
|