@agg-build/hooks 4.26.0 → 4.27.0

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 (45) hide show
  1. package/dist/deposit.d.mts +142 -138
  2. package/dist/deposit.d.mts.map +1 -0
  3. package/dist/deposit.d.ts +142 -138
  4. package/dist/deposit.d.ts.map +1 -0
  5. package/dist/deposit.js +751 -2414
  6. package/dist/deposit.mjs +744 -727
  7. package/dist/deposit.mjs.map +1 -0
  8. package/dist/index-CbNR3EIA.d.mts +341 -0
  9. package/dist/index-CbNR3EIA.d.mts.map +1 -0
  10. package/dist/index-CsP1jRMD.d.ts +341 -0
  11. package/dist/index-CsP1jRMD.d.ts.map +1 -0
  12. package/dist/index-D0fXU85a.d.mts +743 -0
  13. package/dist/index-D0fXU85a.d.mts.map +1 -0
  14. package/dist/index-D0fXU85a.d.ts +743 -0
  15. package/dist/index-D0fXU85a.d.ts.map +1 -0
  16. package/dist/index.d.mts +6458 -7514
  17. package/dist/index.d.mts.map +1 -0
  18. package/dist/index.d.ts +6458 -7514
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +7451 -11416
  21. package/dist/index.mjs +7154 -5220
  22. package/dist/index.mjs.map +1 -0
  23. package/dist/use-ramp-session-7RAG9tvY.js +30 -0
  24. package/dist/use-ramp-session-BFWHCtuc.mjs +21 -0
  25. package/dist/use-ramp-session-BFWHCtuc.mjs.map +1 -0
  26. package/dist/use-sync-balances-BkcqInJh.mjs +1779 -0
  27. package/dist/use-sync-balances-BkcqInJh.mjs.map +1 -0
  28. package/dist/{use-sync-balances-CeD8qZWP.d.ts → use-sync-balances-CVEg__2V.d.mts} +7 -8
  29. package/dist/use-sync-balances-CVEg__2V.d.mts.map +1 -0
  30. package/dist/{use-sync-balances-CeD8qZWP.d.mts → use-sync-balances-CVEg__2V.d.ts} +7 -8
  31. package/dist/use-sync-balances-CVEg__2V.d.ts.map +1 -0
  32. package/dist/use-sync-balances-HryB8Q7F.js +1974 -0
  33. package/dist/withdraw--f5kYKJA.mjs +1474 -0
  34. package/dist/withdraw--f5kYKJA.mjs.map +1 -0
  35. package/dist/withdraw-BXWZYmJa.js +1591 -0
  36. package/dist/withdraw.d.mts +3 -351
  37. package/dist/withdraw.d.ts +3 -351
  38. package/dist/withdraw.js +10 -2229
  39. package/dist/withdraw.mjs +3 -20
  40. package/package.json +7 -6
  41. package/dist/chunk-JFJNW2PD.mjs +0 -5649
  42. package/dist/chunk-LNIAMJTZ.mjs +0 -505
  43. package/dist/chunk-OZQ3K47U.mjs +0 -31
  44. package/dist/use-deposit-addresses-B9ICS-3U.d.mts +0 -236
  45. package/dist/use-deposit-addresses-B9ICS-3U.d.ts +0 -236
package/dist/deposit.mjs CHANGED
@@ -1,750 +1,767 @@
1
- import {
2
- useRampQuotes,
3
- useRampSession
4
- } from "./chunk-OZQ3K47U.mjs";
5
- import {
6
- __async,
7
- useAggAuthState,
8
- useAggBalanceState,
9
- useAggClient,
10
- useAggUiConfig,
11
- useDepositAddresses,
12
- useOptionalAggClient,
13
- useSyncBalances
14
- } from "./chunk-JFJNW2PD.mjs";
15
-
16
- // src/deposit/normalize-wallet-error.ts
1
+ import { a as useAggAuthState, c as useAggBalanceState, d as useAggUiConfig, l as useAggClient, p as useOptionalAggClient, r as useDepositAddresses, t as useSyncBalances } from "./use-sync-balances-BkcqInJh.mjs";
2
+ import { n as useRampQuotes, t as useRampSession } from "./use-ramp-session-BFWHCtuc.mjs";
3
+ import { useQuery } from "@tanstack/react-query";
4
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
5
+ import { Connection, Keypair, PublicKey, SystemProgram, Transaction, TransactionInstruction } from "@solana/web3.js";
6
+ import { formatEther, formatUnits, parseUnits } from "viem";
7
+ import { useAccount, useReadContract, useSwitchChain, useWaitForTransactionReceipt, useWriteContract } from "wagmi";
8
+ import { useWallet } from "@solana/wallet-adapter-react";
9
+ //#region src/deposit/normalize-wallet-error.ts
17
10
  function normalizeWalletError(error, supportedChains) {
18
- var _a, _b;
19
- const message = error instanceof Error ? error.message : String(error);
20
- const lower = message.toLowerCase();
21
- if (lower.includes("user rejected") || lower.includes("user denied") || lower.includes("rejected the request") || lower.includes("denied transaction signature")) {
22
- return { message: "Wallet request rejected.", tone: "error" };
23
- }
24
- const chainMismatch = message.includes("does not match the target chain") || message.includes("Expected Chain ID:");
25
- if (chainMismatch) {
26
- const match = message.match(/Expected Chain ID:\s*(\d+)/i);
27
- const targetChainId = match ? Number(match[1]) : void 0;
28
- const targetChainName = (_b = (_a = supportedChains == null ? void 0 : supportedChains.find((chain) => chain.chainId === targetChainId)) == null ? void 0 : _a.name) != null ? _b : targetChainId ? `chain ${targetChainId}` : "the selected chain";
29
- return {
30
- message: `Wallet chain does not match. Please switch your wallet to ${targetChainName}.`,
31
- tone: "warning"
32
- };
33
- }
34
- return { message, tone: "error" };
11
+ const message = error instanceof Error ? error.message : String(error);
12
+ const lower = message.toLowerCase();
13
+ if (lower.includes("user rejected") || lower.includes("user denied") || lower.includes("rejected the request") || lower.includes("denied transaction signature")) return {
14
+ message: "Wallet request rejected.",
15
+ tone: "error"
16
+ };
17
+ if (message.includes("does not match the target chain") || message.includes("Expected Chain ID:")) {
18
+ const match = message.match(/Expected Chain ID:\s*(\d+)/i);
19
+ const targetChainId = match ? Number(match[1]) : void 0;
20
+ return {
21
+ message: `Wallet chain does not match. Please switch your wallet to ${supportedChains?.find((chain) => chain.chainId === targetChainId)?.name ?? (targetChainId ? `chain ${targetChainId}` : "the selected chain")}.`,
22
+ tone: "warning"
23
+ };
24
+ }
25
+ return {
26
+ message,
27
+ tone: "error"
28
+ };
35
29
  }
36
-
37
- // src/deposit/use-wallet-token-balance.ts
38
- import { PublicKey } from "@solana/web3.js";
39
- import { useQuery as useQuery2 } from "@tanstack/react-query";
40
- import { formatUnits } from "viem";
41
- import { useAccount, useReadContract } from "wagmi";
42
-
43
- // src/deposit/constants.ts
44
- var DEFAULT_SOLANA_RPC_ENDPOINTS = [
45
- "https://solana-mainnet.g.alchemy.com/v2",
46
- "https://solana-rpc.publicnode.com",
47
- "https://api.mainnet.solana.com",
48
- "https://rpc.ankr.com/solana"
30
+ //#endregion
31
+ //#region src/deposit/constants.ts
32
+ /**
33
+ * Priority-ordered list of Solana RPC endpoints the deposit hooks fall back
34
+ * through when the previous endpoint errors or times out. The partner-supplied
35
+ * `solanaRpcUrl` (when present) is prepended at runtime; these are the
36
+ * always-on safety net so a single provider outage never strands users on a
37
+ * "0 balance" screen.
38
+ */
39
+ const DEFAULT_SOLANA_RPC_ENDPOINTS = [
40
+ "https://solana-mainnet.g.alchemy.com/v2",
41
+ "https://solana-rpc.publicnode.com",
42
+ "https://api.mainnet.solana.com",
43
+ "https://rpc.ankr.com/solana"
49
44
  ];
50
- var DEFAULT_SOLANA_RPC_ENDPOINT = "https://solana-rpc.publicnode.com";
51
- var SVM_CHAIN_IDS = /* @__PURE__ */ new Set([792703809]);
52
- var MULTI_CHAIN_SOLANA_WALLET_NAMES = /* @__PURE__ */ new Set(["Phantom"]);
53
-
54
- // src/deposit/use-svm-address.ts
55
- import { useEffect, useState } from "react";
56
- import { useWallet } from "@solana/wallet-adapter-react";
57
- function getPhantomProvider() {
58
- var _a, _b;
59
- if (typeof window === "undefined") return void 0;
60
- const w = window;
61
- return (_b = (_a = w.phantom) == null ? void 0 : _a.solana) != null ? _b : w.solana;
45
+ /**
46
+ * Back-compat alias for callers that still want a single default endpoint.
47
+ * New code should prefer the full list and the failover helper.
48
+ */
49
+ const DEFAULT_SOLANA_RPC_ENDPOINT = "https://solana-rpc.publicnode.com";
50
+ const SVM_CHAIN_IDS = /* @__PURE__ */ new Set([792703809]);
51
+ const MULTI_CHAIN_SOLANA_WALLET_NAMES = /* @__PURE__ */ new Set(["Phantom"]);
52
+ //#endregion
53
+ //#region src/deposit/use-svm-address.ts
54
+ function getPhantomProvider$1() {
55
+ if (typeof window === "undefined") return void 0;
56
+ const w = window;
57
+ return w.phantom?.solana ?? w.solana;
62
58
  }
63
59
  function useSvmAddress() {
64
- var _a;
65
- const { publicKey: adapterPublicKey } = useWallet();
66
- const [phantomAddress, setPhantomAddress] = useState(void 0);
67
- useEffect(() => {
68
- var _a2;
69
- const provider = getPhantomProvider();
70
- if (!provider) return;
71
- const existing = (_a2 = provider.publicKey) == null ? void 0 : _a2.toBase58();
72
- if (existing) {
73
- setPhantomAddress(existing);
74
- return;
75
- }
76
- provider.connect({ onlyIfTrusted: true }).then((res) => setPhantomAddress(res.publicKey.toString())).catch(() => {
77
- });
78
- }, []);
79
- return (_a = adapterPublicKey == null ? void 0 : adapterPublicKey.toBase58()) != null ? _a : phantomAddress;
60
+ const { publicKey: adapterPublicKey } = useWallet();
61
+ const [phantomAddress, setPhantomAddress] = useState(void 0);
62
+ useEffect(() => {
63
+ const provider = getPhantomProvider$1();
64
+ if (!provider) return;
65
+ const existing = provider.publicKey?.toBase58();
66
+ if (existing) {
67
+ setPhantomAddress(existing);
68
+ return;
69
+ }
70
+ provider.connect({ onlyIfTrusted: true }).then((res) => setPhantomAddress(res.publicKey.toString())).catch(() => {});
71
+ }, []);
72
+ return adapterPublicKey?.toBase58() ?? phantomAddress;
80
73
  }
81
-
82
- // src/deposit/svm-connections.ts
83
- import { Connection } from "@solana/web3.js";
84
- import { useMemo } from "react";
85
- import { useQuery } from "@tanstack/react-query";
74
+ //#endregion
75
+ //#region src/deposit/svm-connections.ts
76
+ /**
77
+ * Resolves the priority-ordered list of Solana RPC URLs to try, with the
78
+ * partner-supplied URL first (when present) and the built-in defaults as a
79
+ * safety net. De-duplicated so we never hit the same endpoint twice in a
80
+ * single failover round.
81
+ */
86
82
  function resolveSvmRpcEndpoints(partnerUrl) {
87
- const seen = /* @__PURE__ */ new Set();
88
- const out = [];
89
- const candidates = partnerUrl ? [partnerUrl, ...DEFAULT_SOLANA_RPC_ENDPOINTS] : DEFAULT_SOLANA_RPC_ENDPOINTS;
90
- for (const url of candidates) {
91
- if (!seen.has(url)) {
92
- seen.add(url);
93
- out.push(url);
94
- }
95
- }
96
- return out;
83
+ const seen = /* @__PURE__ */ new Set();
84
+ const out = [];
85
+ const candidates = partnerUrl ? [partnerUrl, ...DEFAULT_SOLANA_RPC_ENDPOINTS] : DEFAULT_SOLANA_RPC_ENDPOINTS;
86
+ for (const url of candidates) if (!seen.has(url)) {
87
+ seen.add(url);
88
+ out.push(url);
89
+ }
90
+ return out;
97
91
  }
92
+ /**
93
+ * Returns a memoized list of `Connection` instances, one per resolved RPC
94
+ * endpoint, in failover priority order. The primary connection is
95
+ * `connections[0]`; subsequent entries are tried only when an operation
96
+ * against the previous entry throws.
97
+ *
98
+ * `new Connection(...)` is lazy (no socket is opened), so eagerly building
99
+ * fallback connections has negligible cost.
100
+ */
98
101
  function useSvmConnections(commitment) {
99
- const { solanaRpcUrl } = useAggUiConfig();
100
- const client = useOptionalAggClient();
101
- const { data: tokenData } = useQuery({
102
- queryKey: ["alchemy-rpc-token"],
103
- queryFn: () => client ? client.getRpcToken() : Promise.resolve({ token: "", expiresAt: 0 }),
104
- enabled: !!client,
105
- staleTime: 50 * 60 * 1e3
106
- // 50 minutes cache (token is valid for 1h)
107
- });
108
- const token = tokenData == null ? void 0 : tokenData.token;
109
- return useMemo(() => {
110
- const endpoints = resolveSvmRpcEndpoints(solanaRpcUrl);
111
- return endpoints.map((url) => {
112
- const headers = {};
113
- if (url.includes("alchemy.com") && token) {
114
- headers["Authorization"] = `Bearer ${token}`;
115
- }
116
- return new Connection(url, {
117
- commitment,
118
- httpHeaders: Object.keys(headers).length > 0 ? headers : void 0
119
- });
120
- });
121
- }, [solanaRpcUrl, commitment, token]);
102
+ const { solanaRpcUrl } = useAggUiConfig();
103
+ const client = useOptionalAggClient();
104
+ const { data: tokenData } = useQuery({
105
+ queryKey: ["alchemy-rpc-token"],
106
+ queryFn: () => client ? client.getRpcToken() : Promise.resolve({
107
+ token: "",
108
+ expiresAt: 0
109
+ }),
110
+ enabled: !!client,
111
+ staleTime: 3e6
112
+ });
113
+ const token = tokenData?.token;
114
+ return useMemo(() => {
115
+ return resolveSvmRpcEndpoints(solanaRpcUrl).map((url) => {
116
+ const headers = {};
117
+ if (url.includes("alchemy.com") && token) headers["Authorization"] = `Bearer ${token}`;
118
+ return new Connection(url, {
119
+ commitment,
120
+ httpHeaders: Object.keys(headers).length > 0 ? headers : void 0
121
+ });
122
+ });
123
+ }, [
124
+ solanaRpcUrl,
125
+ commitment,
126
+ token
127
+ ]);
122
128
  }
123
- function withSvmFailover(connections, operation) {
124
- return __async(this, null, function* () {
125
- if (connections.length === 0) {
126
- throw new Error("No Solana RPC connections configured");
127
- }
128
- let lastError;
129
- for (const connection of connections) {
130
- try {
131
- return yield operation(connection);
132
- } catch (err) {
133
- lastError = err;
134
- }
135
- }
136
- throw lastError instanceof Error ? lastError : new Error(typeof lastError === "string" ? lastError : "All Solana RPC endpoints failed");
137
- });
129
+ /**
130
+ * Runs `operation` against the first connection that returns successfully.
131
+ * Connections are tried in priority order; on any thrown error (network
132
+ * failure, timeout, RPC error) we advance to the next.
133
+ *
134
+ * The happy path issues exactly one underlying RPC call — we only fan out
135
+ * when the previous endpoint failed. If every endpoint fails, the last
136
+ * error is rethrown so the caller (and `useQuery`) sees the real cause.
137
+ */
138
+ async function withSvmFailover(connections, operation) {
139
+ if (connections.length === 0) throw new Error("No Solana RPC connections configured");
140
+ let lastError;
141
+ for (const connection of connections) try {
142
+ return await operation(connection);
143
+ } catch (err) {
144
+ lastError = err;
145
+ }
146
+ throw lastError instanceof Error ? lastError : new Error(typeof lastError === "string" ? lastError : "All Solana RPC endpoints failed");
138
147
  }
139
-
140
- // src/deposit/use-wallet-token-balance.ts
141
- var ERC20_BALANCE_OF_ABI = [
142
- {
143
- name: "balanceOf",
144
- type: "function",
145
- stateMutability: "view",
146
- inputs: [{ name: "account", type: "address" }],
147
- outputs: [{ name: "", type: "uint256" }]
148
- }
149
- ];
150
- var SVM_BALANCE_RPC_TIMEOUT_MS = 2e3;
151
- var SVM_BALANCE_STALE_TIME_MS = 3e4;
148
+ //#endregion
149
+ //#region src/deposit/use-wallet-token-balance.ts
150
+ const ERC20_BALANCE_OF_ABI = [{
151
+ name: "balanceOf",
152
+ type: "function",
153
+ stateMutability: "view",
154
+ inputs: [{
155
+ name: "account",
156
+ type: "address"
157
+ }],
158
+ outputs: [{
159
+ name: "",
160
+ type: "uint256"
161
+ }]
162
+ }];
163
+ const SVM_BALANCE_RPC_TIMEOUT_MS = 2e3;
164
+ const SVM_BALANCE_STALE_TIME_MS = 3e4;
152
165
  var SvmBalanceTimeoutError = class extends Error {
153
- constructor() {
154
- super("Solana balance request timed out");
155
- this.name = "SvmBalanceTimeoutError";
156
- }
166
+ constructor() {
167
+ super("Solana balance request timed out");
168
+ this.name = "SvmBalanceTimeoutError";
169
+ }
157
170
  };
158
171
  function withTimeout(promise, timeoutMs) {
159
- return new Promise((resolve, reject) => {
160
- const timer = setTimeout(() => reject(new SvmBalanceTimeoutError()), timeoutMs);
161
- promise.then(
162
- (value) => {
163
- clearTimeout(timer);
164
- resolve(value);
165
- },
166
- (err) => {
167
- clearTimeout(timer);
168
- reject(err);
169
- }
170
- );
171
- });
172
+ return new Promise((resolve, reject) => {
173
+ const timer = setTimeout(() => reject(new SvmBalanceTimeoutError()), timeoutMs);
174
+ promise.then((value) => {
175
+ clearTimeout(timer);
176
+ resolve(value);
177
+ }, (err) => {
178
+ clearTimeout(timer);
179
+ reject(err);
180
+ });
181
+ });
172
182
  }
173
- function fetchSvmTokenBalance(connections, owner, mint) {
174
- return __async(this, null, function* () {
175
- var _a, _b, _c;
176
- const accounts = yield withSvmFailover(
177
- connections,
178
- (connection) => withTimeout(
179
- connection.getParsedTokenAccountsByOwner(owner, { mint }),
180
- SVM_BALANCE_RPC_TIMEOUT_MS
181
- )
182
- );
183
- let total = 0;
184
- for (const entry of accounts.value) {
185
- const uiAmount = (_c = (_b = (_a = entry.account.data.parsed) == null ? void 0 : _a.info) == null ? void 0 : _b.tokenAmount) == null ? void 0 : _c.uiAmount;
186
- if (typeof uiAmount === "number" && Number.isFinite(uiAmount)) {
187
- total += uiAmount;
188
- }
189
- }
190
- return total;
191
- });
183
+ /**
184
+ * Reads the connected wallet's SPL token balance for `mint`.
185
+ *
186
+ * A Solana wallet routinely owns multiple SPL accounts for the same mint —
187
+ * the canonical ATA plus dust accounts created by dApps (each with their
188
+ * own `closeAuthority`). The RPC does not order them deterministically, so
189
+ * picking `accounts.value[0]` and calling `getTokenAccountBalance` for it
190
+ * (the previous implementation) frequently returned 0 even when the user
191
+ * was funded on a sibling account. Phantom/Solflare display the sum across
192
+ * every account on the mint; we match that here.
193
+ *
194
+ * Uses `getParsedTokenAccountsByOwner` so `uiAmount` arrives on the first
195
+ * response — one RPC round-trip per refetch instead of two. The per-endpoint
196
+ * timeout caps how long we wait before falling over to the next RPC.
197
+ */
198
+ async function fetchSvmTokenBalance(connections, owner, mint) {
199
+ const accounts = await withSvmFailover(connections, (connection) => withTimeout(connection.getParsedTokenAccountsByOwner(owner, { mint }), SVM_BALANCE_RPC_TIMEOUT_MS));
200
+ let total = 0;
201
+ for (const entry of accounts.value) {
202
+ const uiAmount = entry.account.data.parsed?.info?.tokenAmount?.uiAmount;
203
+ if (typeof uiAmount === "number" && Number.isFinite(uiAmount)) total += uiAmount;
204
+ }
205
+ return total;
192
206
  }
193
- function useWalletTokenBalance({
194
- isOpen = true,
195
- chainId,
196
- tokenAddress,
197
- decimals,
198
- svmAddress
199
- }) {
200
- var _a;
201
- const isSvm = chainId !== void 0 && SVM_CHAIN_IDS.has(chainId);
202
- const { address: evmAddress } = useAccount();
203
- const evmEnabled = isOpen && !isSvm && !!chainId && !!tokenAddress && !!evmAddress && decimals !== void 0;
204
- const { data: rawEvmBalance, isLoading: evmLoading } = useReadContract({
205
- address: tokenAddress,
206
- chainId,
207
- abi: ERC20_BALANCE_OF_ABI,
208
- functionName: "balanceOf",
209
- args: evmAddress ? [evmAddress] : void 0,
210
- query: { enabled: evmEnabled, staleTime: 0, refetchOnMount: true }
211
- });
212
- const detectedSvmAddress = useSvmAddress();
213
- const resolvedSvmAddress = detectedSvmAddress != null ? detectedSvmAddress : svmAddress;
214
- const svmEnabled = isOpen && isSvm && !!resolvedSvmAddress && !!tokenAddress;
215
- const svmConnections = useSvmConnections();
216
- const svmQuery = useQuery2({
217
- queryKey: ["svm-token-balance", resolvedSvmAddress != null ? resolvedSvmAddress : null, tokenAddress != null ? tokenAddress : null, isOpen],
218
- enabled: svmEnabled,
219
- staleTime: SVM_BALANCE_STALE_TIME_MS,
220
- retry: false,
221
- refetchOnWindowFocus: "always",
222
- refetchOnReconnect: "always",
223
- queryFn: () => __async(null, null, function* () {
224
- if (!resolvedSvmAddress || !tokenAddress) return 0;
225
- const owner = new PublicKey(resolvedSvmAddress);
226
- const mint = new PublicKey(tokenAddress);
227
- return yield fetchSvmTokenBalance(svmConnections, owner, mint);
228
- })
229
- });
230
- if (isSvm) {
231
- const awaitingSelection2 = isOpen && !!chainId && !tokenAddress;
232
- return {
233
- balance: (_a = svmQuery.data) != null ? _a : 0,
234
- isLoading: awaitingSelection2 || svmQuery.isLoading || svmQuery.isFetching
235
- };
236
- }
237
- const evmBalance = rawEvmBalance !== void 0 && decimals !== void 0 ? Number(formatUnits(rawEvmBalance, decimals)) : 0;
238
- const awaitingSelection = isOpen && !!chainId && !tokenAddress;
239
- return { balance: evmBalance, isLoading: awaitingSelection || evmLoading };
207
+ /**
208
+ * Reads the connected wallet's on-chain balance for a given token on a given chain.
209
+ * Dispatches to wagmi (EVM) or @solana/web3.js (SVM) based on chainId.
210
+ */
211
+ function useWalletTokenBalance({ isOpen = true, chainId, tokenAddress, decimals, svmAddress }) {
212
+ const isSvm = chainId !== void 0 && SVM_CHAIN_IDS.has(chainId);
213
+ const { address: evmAddress } = useAccount();
214
+ const { data: rawEvmBalance, isLoading: evmLoading } = useReadContract({
215
+ address: tokenAddress,
216
+ chainId,
217
+ abi: ERC20_BALANCE_OF_ABI,
218
+ functionName: "balanceOf",
219
+ args: evmAddress ? [evmAddress] : void 0,
220
+ query: {
221
+ enabled: isOpen && !isSvm && !!chainId && !!tokenAddress && !!evmAddress && decimals !== void 0,
222
+ staleTime: 0,
223
+ refetchOnMount: true
224
+ }
225
+ });
226
+ const resolvedSvmAddress = useSvmAddress() ?? svmAddress;
227
+ const svmEnabled = isOpen && isSvm && !!resolvedSvmAddress && !!tokenAddress;
228
+ const svmConnections = useSvmConnections();
229
+ const svmQuery = useQuery({
230
+ queryKey: [
231
+ "svm-token-balance",
232
+ resolvedSvmAddress ?? null,
233
+ tokenAddress ?? null,
234
+ isOpen
235
+ ],
236
+ enabled: svmEnabled,
237
+ staleTime: SVM_BALANCE_STALE_TIME_MS,
238
+ retry: false,
239
+ refetchOnWindowFocus: "always",
240
+ refetchOnReconnect: "always",
241
+ queryFn: async () => {
242
+ if (!resolvedSvmAddress || !tokenAddress) return 0;
243
+ const owner = new PublicKey(resolvedSvmAddress);
244
+ const mint = new PublicKey(tokenAddress);
245
+ return await fetchSvmTokenBalance(svmConnections, owner, mint);
246
+ }
247
+ });
248
+ if (isSvm) {
249
+ const awaitingSelection = isOpen && !!chainId && !tokenAddress;
250
+ return {
251
+ balance: svmQuery.data ?? 0,
252
+ isLoading: awaitingSelection || svmQuery.isLoading || svmQuery.isFetching
253
+ };
254
+ }
255
+ return {
256
+ balance: rawEvmBalance !== void 0 && decimals !== void 0 ? Number(formatUnits(rawEvmBalance, decimals)) : 0,
257
+ isLoading: isOpen && !!chainId && !tokenAddress || evmLoading
258
+ };
240
259
  }
241
-
242
- // src/deposit/use-wallet-send-token.ts
243
- import { useCallback } from "react";
244
- import { parseUnits } from "viem";
245
- import { useWriteContract } from "wagmi";
246
- import { useWallet as useWallet2 } from "@solana/wallet-adapter-react";
247
- import {
248
- Keypair,
249
- PublicKey as PublicKey2,
250
- SystemProgram,
251
- Transaction,
252
- TransactionInstruction
253
- } from "@solana/web3.js";
254
- function getPhantomProvider2() {
255
- var _a, _b;
256
- if (typeof window === "undefined") return void 0;
257
- const w = window;
258
- return (_b = (_a = w.phantom) == null ? void 0 : _a.solana) != null ? _b : w.solana;
260
+ //#endregion
261
+ //#region src/deposit/use-wallet-send-token.ts
262
+ function getPhantomProvider() {
263
+ if (typeof window === "undefined") return void 0;
264
+ const w = window;
265
+ return w.phantom?.solana ?? w.solana;
259
266
  }
260
- var ERC20_TRANSFER_ABI = [
261
- {
262
- constant: false,
263
- inputs: [
264
- { name: "to", type: "address" },
265
- { name: "amount", type: "uint256" }
266
- ],
267
- name: "transfer",
268
- outputs: [{ name: "", type: "bool" }],
269
- type: "function"
270
- }
271
- ];
267
+ const ERC20_TRANSFER_ABI = [{
268
+ constant: false,
269
+ inputs: [{
270
+ name: "to",
271
+ type: "address"
272
+ }, {
273
+ name: "amount",
274
+ type: "uint256"
275
+ }],
276
+ name: "transfer",
277
+ outputs: [{
278
+ name: "",
279
+ type: "bool"
280
+ }],
281
+ type: "function"
282
+ }];
283
+ /**
284
+ * Dual-chain sendToken implementation:
285
+ * - EVM: uses wagmi writeContract to call ERC-20 transfer
286
+ * - SVM: uses wallet-adapter (or injected Phantom) to submit an SPL TransferChecked tx
287
+ *
288
+ * Matches the `WalletActions.sendToken` signature so it can be passed into
289
+ * `AggProvider` config directly, or composed inside `useDepositFlow`.
290
+ */
272
291
  function useWalletSendToken() {
273
- const svmConnections = useSvmConnections("confirmed");
274
- const { writeContractAsync } = useWriteContract();
275
- const { publicKey, sendTransaction } = useWallet2();
276
- return useCallback(
277
- (params) => __async(null, null, function* () {
278
- const isSvm = SVM_CHAIN_IDS.has(params.chainId);
279
- if (!isSvm) {
280
- const tokenAddress = params.token.address;
281
- if (!tokenAddress) {
282
- throw new Error("Missing ERC-20 token address for EVM transfer");
283
- }
284
- const value = parseUnits(params.amount || "0", params.token.decimals);
285
- const txHash = yield writeContractAsync({
286
- chainId: params.chainId,
287
- address: tokenAddress,
288
- abi: ERC20_TRANSFER_ABI,
289
- functionName: "transfer",
290
- args: [params.to, value]
291
- });
292
- return { txId: txHash };
293
- }
294
- if (!params.token.address) {
295
- throw new Error("Missing SPL token mint address for Solana transfer");
296
- }
297
- const phantom = getPhantomProvider2();
298
- let ownerBase58 = publicKey == null ? void 0 : publicKey.toBase58();
299
- if (!ownerBase58 && phantom) {
300
- try {
301
- const res = yield phantom.connect();
302
- ownerBase58 = res.publicKey.toString();
303
- } catch (err) {
304
- throw new Error(
305
- `Failed to connect Phantom: ${err instanceof Error ? err.message : String(err)}`
306
- );
307
- }
308
- }
309
- if (!ownerBase58) {
310
- throw new Error("No Solana wallet connected");
311
- }
312
- const TOKEN_PROGRAM_ID = new PublicKey2("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
313
- const ASSOCIATED_TOKEN_PROGRAM_ID = new PublicKey2(
314
- "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
315
- );
316
- const owner = new PublicKey2(ownerBase58);
317
- const mint = new PublicKey2(params.token.address);
318
- const destinationOwner = new PublicKey2(params.to);
319
- const getAta = (walletPk, mintPk) => {
320
- const [ata] = PublicKey2.findProgramAddressSync(
321
- [walletPk.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), mintPk.toBuffer()],
322
- ASSOCIATED_TOKEN_PROGRAM_ID
323
- );
324
- return ata;
325
- };
326
- const sourceAta = getAta(owner, mint);
327
- const destinationAta = getAta(destinationOwner, mint);
328
- const signature = yield withSvmFailover(svmConnections, (sendConnection) => __async(null, null, function* () {
329
- var _a, _b;
330
- const tx = new Transaction();
331
- let destinationTokenAccountSigner = null;
332
- const destinationOwnerInfo = yield sendConnection.getAccountInfo(destinationOwner);
333
- const destinationInfo = yield sendConnection.getAccountInfo(destinationAta);
334
- let destinationTokenAccount = destinationAta;
335
- if (!destinationInfo) {
336
- const rentExemptLamports = yield sendConnection.getMinimumBalanceForRentExemption(165);
337
- const payerLamports = yield sendConnection.getBalance(owner, "confirmed");
338
- const feeBufferLamports = 1e4;
339
- const requiredLamports = rentExemptLamports + feeBufferLamports;
340
- if (payerLamports < requiredLamports) {
341
- const requiredSol = (requiredLamports / 1e9).toFixed(6);
342
- const currentSol = (payerLamports / 1e9).toFixed(6);
343
- throw new Error(
344
- `This Solana deposit needs about ${requiredSol} SOL to create the destination token account, but the connected wallet only has ${currentSol} SOL available.`
345
- );
346
- }
347
- const canCreateAta = (_b = (_a = destinationOwnerInfo == null ? void 0 : destinationOwnerInfo.owner) == null ? void 0 : _a.equals(SystemProgram.programId)) != null ? _b : false;
348
- if (canCreateAta) {
349
- const createIx = new TransactionInstruction({
350
- programId: ASSOCIATED_TOKEN_PROGRAM_ID,
351
- keys: [
352
- { pubkey: owner, isSigner: true, isWritable: true },
353
- { pubkey: destinationAta, isSigner: false, isWritable: true },
354
- { pubkey: destinationOwner, isSigner: false, isWritable: false },
355
- { pubkey: mint, isSigner: false, isWritable: false },
356
- { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
357
- { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }
358
- ],
359
- data: Buffer.alloc(0)
360
- });
361
- tx.add(createIx);
362
- } else {
363
- destinationTokenAccountSigner = Keypair.generate();
364
- destinationTokenAccount = destinationTokenAccountSigner.publicKey;
365
- tx.add(
366
- SystemProgram.createAccount({
367
- fromPubkey: owner,
368
- newAccountPubkey: destinationTokenAccount,
369
- lamports: rentExemptLamports,
370
- space: 165,
371
- programId: TOKEN_PROGRAM_ID
372
- })
373
- );
374
- const initAccountData = Buffer.concat([
375
- Buffer.from([18]),
376
- // InitializeAccount3
377
- destinationOwner.toBuffer()
378
- ]);
379
- tx.add(
380
- new TransactionInstruction({
381
- programId: TOKEN_PROGRAM_ID,
382
- keys: [
383
- { pubkey: destinationTokenAccount, isSigner: false, isWritable: true },
384
- { pubkey: mint, isSigner: false, isWritable: false }
385
- ],
386
- data: initAccountData
387
- })
388
- );
389
- }
390
- }
391
- let factor = BigInt(1);
392
- for (let i = 0; i < params.token.decimals; i += 1) {
393
- factor *= BigInt(10);
394
- }
395
- const amountRaw = BigInt(Math.trunc(Number(params.amount || "0") * Number(factor)));
396
- const data = new Uint8Array(10);
397
- data[0] = 12;
398
- let remaining = amountRaw;
399
- const mask = BigInt(255);
400
- for (let i = 0; i < 8; i += 1) {
401
- data[1 + i] = Number(remaining & mask);
402
- remaining >>= BigInt(8);
403
- }
404
- data[9] = params.token.decimals;
405
- const transferIx = new TransactionInstruction({
406
- programId: TOKEN_PROGRAM_ID,
407
- keys: [
408
- { pubkey: sourceAta, isSigner: false, isWritable: true },
409
- { pubkey: mint, isSigner: false, isWritable: false },
410
- { pubkey: destinationTokenAccount, isSigner: false, isWritable: true },
411
- { pubkey: owner, isSigner: true, isWritable: false }
412
- ],
413
- data: Buffer.from(data)
414
- });
415
- tx.add(transferIx);
416
- tx.feePayer = owner;
417
- const { blockhash } = yield sendConnection.getLatestBlockhash("confirmed");
418
- tx.recentBlockhash = blockhash;
419
- if (destinationTokenAccountSigner) {
420
- tx.partialSign(destinationTokenAccountSigner);
421
- }
422
- if (publicKey && sendTransaction) {
423
- return yield sendTransaction(tx, sendConnection);
424
- }
425
- if (phantom) {
426
- const res = yield phantom.signAndSendTransaction(tx);
427
- return res.signature;
428
- }
429
- throw new Error("No Solana signer available");
430
- }));
431
- return { txId: signature };
432
- }),
433
- [publicKey, sendTransaction, svmConnections, writeContractAsync]
434
- );
292
+ const svmConnections = useSvmConnections("confirmed");
293
+ const { writeContractAsync } = useWriteContract();
294
+ const { publicKey, sendTransaction } = useWallet();
295
+ return useCallback(async (params) => {
296
+ if (!SVM_CHAIN_IDS.has(params.chainId)) {
297
+ const tokenAddress = params.token.address;
298
+ if (!tokenAddress) throw new Error("Missing ERC-20 token address for EVM transfer");
299
+ const value = parseUnits(params.amount || "0", params.token.decimals);
300
+ return { txId: await writeContractAsync({
301
+ chainId: params.chainId,
302
+ address: tokenAddress,
303
+ abi: ERC20_TRANSFER_ABI,
304
+ functionName: "transfer",
305
+ args: [params.to, value]
306
+ }) };
307
+ }
308
+ if (!params.token.address) throw new Error("Missing SPL token mint address for Solana transfer");
309
+ const phantom = getPhantomProvider();
310
+ let ownerBase58 = publicKey?.toBase58();
311
+ if (!ownerBase58 && phantom) try {
312
+ ownerBase58 = (await phantom.connect()).publicKey.toString();
313
+ } catch (err) {
314
+ throw new Error(`Failed to connect Phantom: ${err instanceof Error ? err.message : String(err)}`);
315
+ }
316
+ if (!ownerBase58) throw new Error("No Solana wallet connected");
317
+ const TOKEN_PROGRAM_ID = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
318
+ const ASSOCIATED_TOKEN_PROGRAM_ID = new PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
319
+ const owner = new PublicKey(ownerBase58);
320
+ const mint = new PublicKey(params.token.address);
321
+ const destinationOwner = new PublicKey(params.to);
322
+ const getAta = (walletPk, mintPk) => {
323
+ const [ata] = PublicKey.findProgramAddressSync([
324
+ walletPk.toBuffer(),
325
+ TOKEN_PROGRAM_ID.toBuffer(),
326
+ mintPk.toBuffer()
327
+ ], ASSOCIATED_TOKEN_PROGRAM_ID);
328
+ return ata;
329
+ };
330
+ const sourceAta = getAta(owner, mint);
331
+ const destinationAta = getAta(destinationOwner, mint);
332
+ return { txId: await withSvmFailover(svmConnections, async (sendConnection) => {
333
+ const tx = new Transaction();
334
+ let destinationTokenAccountSigner = null;
335
+ const destinationOwnerInfo = await sendConnection.getAccountInfo(destinationOwner);
336
+ const destinationInfo = await sendConnection.getAccountInfo(destinationAta);
337
+ let destinationTokenAccount = destinationAta;
338
+ if (!destinationInfo) {
339
+ const rentExemptLamports = await sendConnection.getMinimumBalanceForRentExemption(165);
340
+ const payerLamports = await sendConnection.getBalance(owner, "confirmed");
341
+ const requiredLamports = rentExemptLamports + 1e4;
342
+ if (payerLamports < requiredLamports) {
343
+ const requiredSol = (requiredLamports / 1e9).toFixed(6);
344
+ const currentSol = (payerLamports / 1e9).toFixed(6);
345
+ throw new Error(`This Solana deposit needs about ${requiredSol} SOL to create the destination token account, but the connected wallet only has ${currentSol} SOL available.`);
346
+ }
347
+ if (destinationOwnerInfo?.owner?.equals(SystemProgram.programId) ?? false) {
348
+ const createIx = new TransactionInstruction({
349
+ programId: ASSOCIATED_TOKEN_PROGRAM_ID,
350
+ keys: [
351
+ {
352
+ pubkey: owner,
353
+ isSigner: true,
354
+ isWritable: true
355
+ },
356
+ {
357
+ pubkey: destinationAta,
358
+ isSigner: false,
359
+ isWritable: true
360
+ },
361
+ {
362
+ pubkey: destinationOwner,
363
+ isSigner: false,
364
+ isWritable: false
365
+ },
366
+ {
367
+ pubkey: mint,
368
+ isSigner: false,
369
+ isWritable: false
370
+ },
371
+ {
372
+ pubkey: SystemProgram.programId,
373
+ isSigner: false,
374
+ isWritable: false
375
+ },
376
+ {
377
+ pubkey: TOKEN_PROGRAM_ID,
378
+ isSigner: false,
379
+ isWritable: false
380
+ }
381
+ ],
382
+ data: Buffer.alloc(0)
383
+ });
384
+ tx.add(createIx);
385
+ } else {
386
+ destinationTokenAccountSigner = Keypair.generate();
387
+ destinationTokenAccount = destinationTokenAccountSigner.publicKey;
388
+ tx.add(SystemProgram.createAccount({
389
+ fromPubkey: owner,
390
+ newAccountPubkey: destinationTokenAccount,
391
+ lamports: rentExemptLamports,
392
+ space: 165,
393
+ programId: TOKEN_PROGRAM_ID
394
+ }));
395
+ const initAccountData = Buffer.concat([Buffer.from([18]), destinationOwner.toBuffer()]);
396
+ tx.add(new TransactionInstruction({
397
+ programId: TOKEN_PROGRAM_ID,
398
+ keys: [{
399
+ pubkey: destinationTokenAccount,
400
+ isSigner: false,
401
+ isWritable: true
402
+ }, {
403
+ pubkey: mint,
404
+ isSigner: false,
405
+ isWritable: false
406
+ }],
407
+ data: initAccountData
408
+ }));
409
+ }
410
+ }
411
+ let factor = BigInt(1);
412
+ for (let i = 0; i < params.token.decimals; i += 1) factor *= BigInt(10);
413
+ const amountRaw = BigInt(Math.trunc(Number(params.amount || "0") * Number(factor)));
414
+ const data = /* @__PURE__ */ new Uint8Array(10);
415
+ data[0] = 12;
416
+ let remaining = amountRaw;
417
+ const mask = BigInt(255);
418
+ for (let i = 0; i < 8; i += 1) {
419
+ data[1 + i] = Number(remaining & mask);
420
+ remaining >>= BigInt(8);
421
+ }
422
+ data[9] = params.token.decimals;
423
+ const transferIx = new TransactionInstruction({
424
+ programId: TOKEN_PROGRAM_ID,
425
+ keys: [
426
+ {
427
+ pubkey: sourceAta,
428
+ isSigner: false,
429
+ isWritable: true
430
+ },
431
+ {
432
+ pubkey: mint,
433
+ isSigner: false,
434
+ isWritable: false
435
+ },
436
+ {
437
+ pubkey: destinationTokenAccount,
438
+ isSigner: false,
439
+ isWritable: true
440
+ },
441
+ {
442
+ pubkey: owner,
443
+ isSigner: true,
444
+ isWritable: false
445
+ }
446
+ ],
447
+ data: Buffer.from(data)
448
+ });
449
+ tx.add(transferIx);
450
+ tx.feePayer = owner;
451
+ const { blockhash } = await sendConnection.getLatestBlockhash("confirmed");
452
+ tx.recentBlockhash = blockhash;
453
+ if (destinationTokenAccountSigner) tx.partialSign(destinationTokenAccountSigner);
454
+ if (publicKey && sendTransaction) return await sendTransaction(tx, sendConnection);
455
+ if (phantom) return (await phantom.signAndSendTransaction(tx)).signature;
456
+ throw new Error("No Solana signer available");
457
+ }) };
458
+ }, [
459
+ publicKey,
460
+ sendTransaction,
461
+ svmConnections,
462
+ writeContractAsync
463
+ ]);
435
464
  }
436
-
437
- // src/deposit/use-wallet-transaction-status.ts
438
- import { useQuery as useQuery3 } from "@tanstack/react-query";
439
- import { formatEther } from "viem";
440
- import { useWaitForTransactionReceipt } from "wagmi";
441
- function useWalletTransactionStatus({
442
- chainId,
443
- txId
444
- }) {
445
- var _a;
446
- const isSvm = chainId !== void 0 && SVM_CHAIN_IDS.has(chainId);
447
- const evmHash = !isSvm && txId ? txId : void 0;
448
- const evmReceipt = useWaitForTransactionReceipt({
449
- chainId,
450
- hash: evmHash,
451
- query: {
452
- enabled: !!evmHash && !!chainId,
453
- refetchInterval: 2e3
454
- }
455
- });
456
- const svmConnections = useSvmConnections("confirmed");
457
- const svmQuery = useQuery3({
458
- queryKey: ["wallet-transaction-status", chainId != null ? chainId : null, txId != null ? txId : null],
459
- enabled: isSvm && !!txId,
460
- refetchInterval: (query) => query.state.data === "settled" || query.state.data === "error" ? false : 2e3,
461
- queryFn: () => __async(null, null, function* () {
462
- if (!txId) return "submitted";
463
- const [status] = (yield withSvmFailover(
464
- svmConnections,
465
- (connection) => connection.getSignatureStatuses([txId], { searchTransactionHistory: true })
466
- )).value;
467
- if (!status) return "submitted";
468
- if (status.err) return "error";
469
- if (status.confirmationStatus === "confirmed" || status.confirmationStatus === "finalized") {
470
- return "settled";
471
- }
472
- return "confirming";
473
- })
474
- });
475
- if (isSvm) {
476
- return { status: txId ? (_a = svmQuery.data) != null ? _a : "submitted" : null, gasFee: "" };
477
- }
478
- if (!txId) {
479
- return { status: null, gasFee: "" };
480
- }
481
- if (evmReceipt.isError) {
482
- return { status: "error", gasFee: "" };
483
- }
484
- if (!evmReceipt.data) {
485
- return { status: evmReceipt.isPending ? "confirming" : "submitted", gasFee: "" };
486
- }
487
- const effectiveGasPrice = evmReceipt.data.effectiveGasPrice;
488
- const gasFeeWei = effectiveGasPrice * evmReceipt.data.gasUsed;
489
- const gasFeeEth = Number(formatEther(gasFeeWei));
490
- const gasFee = gasFeeEth > 0 ? `${gasFeeEth.toFixed(6)} ETH` : "";
491
- return { status: "settled", gasFee };
465
+ //#endregion
466
+ //#region src/deposit/use-wallet-transaction-status.ts
467
+ function useWalletTransactionStatus({ chainId, txId }) {
468
+ const isSvm = chainId !== void 0 && SVM_CHAIN_IDS.has(chainId);
469
+ const evmHash = !isSvm && txId ? txId : void 0;
470
+ const evmReceipt = useWaitForTransactionReceipt({
471
+ chainId,
472
+ hash: evmHash,
473
+ query: {
474
+ enabled: !!evmHash && !!chainId,
475
+ refetchInterval: 2e3
476
+ }
477
+ });
478
+ const svmConnections = useSvmConnections("confirmed");
479
+ const svmQuery = useQuery({
480
+ queryKey: [
481
+ "wallet-transaction-status",
482
+ chainId ?? null,
483
+ txId ?? null
484
+ ],
485
+ enabled: isSvm && !!txId,
486
+ refetchInterval: (query) => query.state.data === "settled" || query.state.data === "error" ? false : 2e3,
487
+ queryFn: async () => {
488
+ if (!txId) return "submitted";
489
+ const [status] = (await withSvmFailover(svmConnections, (connection) => connection.getSignatureStatuses([txId], { searchTransactionHistory: true }))).value;
490
+ if (!status) return "submitted";
491
+ if (status.err) return "error";
492
+ if (status.confirmationStatus === "confirmed" || status.confirmationStatus === "finalized") return "settled";
493
+ return "confirming";
494
+ }
495
+ });
496
+ if (isSvm) return {
497
+ status: txId ? svmQuery.data ?? "submitted" : null,
498
+ gasFee: ""
499
+ };
500
+ if (!txId) return {
501
+ status: null,
502
+ gasFee: ""
503
+ };
504
+ if (evmReceipt.isError) return {
505
+ status: "error",
506
+ gasFee: ""
507
+ };
508
+ if (!evmReceipt.data) return {
509
+ status: evmReceipt.isPending ? "confirming" : "submitted",
510
+ gasFee: ""
511
+ };
512
+ const gasFeeWei = evmReceipt.data.effectiveGasPrice * evmReceipt.data.gasUsed;
513
+ const gasFeeEth = Number(formatEther(gasFeeWei));
514
+ return {
515
+ status: "settled",
516
+ gasFee: gasFeeEth > 0 ? `${gasFeeEth.toFixed(6)} ETH` : ""
517
+ };
492
518
  }
493
-
494
- // src/deposit/use-deposit-flow.ts
495
- import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo2, useRef, useState as useState2 } from "react";
496
- import { useAccount as useAccount2, useSwitchChain } from "wagmi";
497
- import { useWallet as useSolanaWallet } from "@solana/wallet-adapter-react";
498
- var DEFAULT_WALLET_CHAIN_ID = 1;
499
- var DEFAULT_WALLET_TOKEN_SYMBOL = "USDC";
519
+ //#endregion
520
+ //#region src/deposit/use-deposit-flow.ts
521
+ const DEFAULT_WALLET_CHAIN_ID = 1;
522
+ const DEFAULT_WALLET_TOKEN_SYMBOL = "USDC";
523
+ /**
524
+ * Orchestrator hook that encapsulates all wallet + card deposit state and
525
+ * glue previously hand-wired inside partner apps. Spread the return value
526
+ * onto `<DepositModal>` to get the full plug-and-play deposit experience.
527
+ *
528
+ * Requires wagmi + @solana/wallet-adapter-react providers in the React tree.
529
+ */
500
530
  function useDepositFlow(options) {
501
- var _a, _b, _c;
502
- const { open, onOpenChange } = options;
503
- const client = useAggClient();
504
- const { user } = useAggAuthState();
505
- const { walletActions } = useAggUiConfig();
506
- const { totalBalance } = useAggBalanceState();
507
- const deposit = useDepositAddresses({ enabled: !!user });
508
- const { supportedChains } = deposit;
509
- const { mutate: syncBalancesMutate } = useSyncBalances();
510
- const defaultSendToken = useWalletSendToken();
511
- const sendToken = (_a = walletActions == null ? void 0 : walletActions.sendToken) != null ? _a : defaultSendToken;
512
- const { mutateAsync: getRampQuotes } = useRampQuotes();
513
- const { mutateAsync: createRampSession } = useRampSession();
514
- const [depositAmount, setDepositAmount] = useState2("");
515
- const [cardAmount, setCardAmount] = useState2("");
516
- const [cardNetwork, setCardNetwork] = useState2("solana");
517
- const [walletModalChainId, setWalletModalChainId] = useState2(null);
518
- const [walletModalTokenSymbol, setWalletModalTokenSymbol] = useState2(null);
519
- const [walletTransaction, setWalletTransaction] = useState2(null);
520
- const [walletTransactionError, setWalletTransactionError] = useState2(null);
521
- const [walletTransactionErrorTone, setWalletTransactionErrorTone] = useState2(
522
- "error"
523
- );
524
- const [pendingCardPurchaseSummary, setPendingCardPurchaseSummary] = useState2(null);
525
- const rampRedirectHandled = useRef(false);
526
- useEffect2(() => {
527
- var _a2, _b2;
528
- if (rampRedirectHandled.current) return;
529
- if (typeof window === "undefined") return;
530
- const url = new URL(window.location.href);
531
- const cryptoAmount = url.searchParams.get("cryptoAmount");
532
- const cryptoCurrency = url.searchParams.get("cryptoCurrency");
533
- if (!cryptoAmount) return;
534
- rampRedirectHandled.current = true;
535
- const network = (_a2 = url.searchParams.get("network")) != null ? _a2 : "";
536
- const totalFee = (_b2 = url.searchParams.get("totalFeeInFiat")) != null ? _b2 : "";
537
- setPendingCardPurchaseSummary({
538
- amountReceived: `+${cryptoAmount} ${cryptoCurrency != null ? cryptoCurrency : "USDC"}`,
539
- network: network.charAt(0).toUpperCase() + network.slice(1),
540
- fees: totalFee ? `$${totalFee}` : ""
541
- });
542
- onOpenChange(true);
543
- }, []);
544
- const { chainId: connectedChainId, address: connectedAddress } = useAccount2();
545
- const { switchChainAsync } = useSwitchChain();
546
- const { wallet: solanaWallet } = useSolanaWallet();
547
- const resolvedSvmAddress = useSvmAddress();
548
- const solanaAdapterName = (_b = solanaWallet == null ? void 0 : solanaWallet.adapter) == null ? void 0 : _b.name;
549
- const isMultiChainSolanaWallet = Boolean(
550
- solanaAdapterName && MULTI_CHAIN_SOLANA_WALLET_NAMES.has(solanaAdapterName)
551
- );
552
- const hasSolanaCapability = Boolean(resolvedSvmAddress || (solanaWallet == null ? void 0 : solanaWallet.adapter));
553
- const hasEvmCapability = Boolean(connectedAddress) || isMultiChainSolanaWallet;
554
- const defaultBalanceChainId = hasEvmCapability && (supportedChains == null ? void 0 : supportedChains.some((chain) => chain.chainId === DEFAULT_WALLET_CHAIN_ID)) ? DEFAULT_WALLET_CHAIN_ID : connectedChainId;
555
- const balanceChainId = walletModalChainId ? Number(walletModalChainId) : defaultBalanceChainId;
556
- const selectedChainTokens = useMemo2(() => {
557
- var _a2;
558
- if (!supportedChains || !balanceChainId) return [];
559
- const chain = supportedChains.find((c) => c.chainId === balanceChainId);
560
- return (_a2 = chain == null ? void 0 : chain.tokens) != null ? _a2 : [];
561
- }, [supportedChains, balanceChainId]);
562
- const selectedTokenMeta = useMemo2(() => {
563
- const preferredTokenSymbol = walletModalTokenSymbol != null ? walletModalTokenSymbol : DEFAULT_WALLET_TOKEN_SYMBOL;
564
- const match = selectedChainTokens.find((t) => t.symbol === preferredTokenSymbol);
565
- return match ? { address: match.address, decimals: match.decimals } : void 0;
566
- }, [selectedChainTokens, walletModalTokenSymbol]);
567
- const isSvmBalanceChain = balanceChainId !== void 0 && SVM_CHAIN_IDS.has(balanceChainId);
568
- const walletAddress = useMemo2(() => {
569
- if (isSvmBalanceChain) {
570
- return resolvedSvmAddress != null ? resolvedSvmAddress : "";
571
- }
572
- return connectedAddress != null ? connectedAddress : "";
573
- }, [connectedAddress, isSvmBalanceChain, resolvedSvmAddress]);
574
- const walletLabel = useMemo2(() => {
575
- return walletAddress ? `${walletAddress.slice(0, 6)}...${walletAddress.slice(-4)}` : "\u2014";
576
- }, [walletAddress]);
577
- const { balance: walletBalance, isLoading: isWalletBalanceLoading } = useWalletTokenBalance({
578
- isOpen: open,
579
- chainId: balanceChainId,
580
- tokenAddress: selectedTokenMeta == null ? void 0 : selectedTokenMeta.address,
581
- decimals: selectedTokenMeta == null ? void 0 : selectedTokenMeta.decimals
582
- });
583
- const { status: observedWalletTransactionStatus, gasFee: walletTransactionGasFee } = useWalletTransactionStatus({
584
- chainId: walletTransaction == null ? void 0 : walletTransaction.chainId,
585
- txId: (_c = walletTransaction == null ? void 0 : walletTransaction.txId) != null ? _c : null
586
- });
587
- const walletTransactionStatus = walletTransactionError ? "error" : walletTransaction ? observedWalletTransactionStatus != null ? observedWalletTransactionStatus : "submitted" : void 0;
588
- const syncedDepositTxIdRef = useRef(null);
589
- useEffect2(() => {
590
- if (walletTransactionStatus !== "settled" || !(walletTransaction == null ? void 0 : walletTransaction.txId)) return;
591
- if (syncedDepositTxIdRef.current === walletTransaction.txId) return;
592
- syncedDepositTxIdRef.current = walletTransaction.txId;
593
- syncBalancesMutate();
594
- }, [syncBalancesMutate, walletTransaction == null ? void 0 : walletTransaction.txId, walletTransactionStatus]);
595
- const handleDepositModalOpenChange = useCallback2(
596
- (isOpen) => {
597
- if (!isOpen) {
598
- setDepositAmount("");
599
- setCardAmount("");
600
- setCardNetwork("solana");
601
- setWalletModalChainId(null);
602
- setWalletModalTokenSymbol(null);
603
- setWalletTransaction(null);
604
- setWalletTransactionError(null);
605
- setWalletTransactionErrorTone("error");
606
- setPendingCardPurchaseSummary(null);
607
- syncedDepositTxIdRef.current = null;
608
- }
609
- onOpenChange(isOpen);
610
- },
611
- [onOpenChange]
612
- );
613
- const handleCancelWalletDeposit = useCallback2(() => {
614
- setWalletTransaction(null);
615
- setWalletTransactionError(null);
616
- setWalletTransactionErrorTone("error");
617
- syncedDepositTxIdRef.current = null;
618
- }, []);
619
- const handleConfirmWalletDeposit = useCallback2(
620
- (params) => __async(null, null, function* () {
621
- var _a2, _b2, _c2;
622
- const { address, amount, chainId, token } = params;
623
- const chain = (_a2 = supportedChains == null ? void 0 : supportedChains.find((c) => c.chainId === chainId)) != null ? _a2 : null;
624
- const tokenMeta = (_b2 = chain == null ? void 0 : chain.tokens.find((t) => t.symbol === token)) != null ? _b2 : null;
625
- try {
626
- setWalletTransactionError(null);
627
- setWalletTransactionErrorTone("error");
628
- const isEvmTarget = !SVM_CHAIN_IDS.has(chainId);
629
- if (isEvmTarget && connectedChainId && connectedChainId !== chainId) {
630
- yield switchChainAsync({ chainId });
631
- }
632
- const { txId } = yield sendToken({
633
- chainId,
634
- token: {
635
- symbol: token,
636
- address: tokenMeta == null ? void 0 : tokenMeta.address,
637
- decimals: (_c2 = tokenMeta == null ? void 0 : tokenMeta.decimals) != null ? _c2 : 6
638
- },
639
- to: address,
640
- amount
641
- });
642
- setWalletTransaction({ chainId, txId });
643
- void client.recordDepositIntent({ chainId, txHash: txId }).catch(() => {
644
- });
645
- } catch (err) {
646
- setWalletTransaction(null);
647
- const normalizedError = normalizeWalletError(err, supportedChains);
648
- setWalletTransactionError(normalizedError.message);
649
- setWalletTransactionErrorTone(normalizedError.tone);
650
- throw err;
651
- }
652
- }),
653
- [client, connectedChainId, sendToken, supportedChains, switchChainAsync]
654
- );
655
- const handleGetCardQuotes = useCallback2(
656
- (params) => __async(null, null, function* () {
657
- const quotes = yield getRampQuotes(params);
658
- return quotes.map(
659
- (q, i) => ({
660
- id: q.serviceProvider,
661
- name: q.serviceProvider,
662
- quote: `~ ${q.destinationAmount.toFixed(2)} USDC`,
663
- fee: `$${q.totalFee.toFixed(2)}`,
664
- badge: i === 0 ? "best" : q.lowKyc ? "low-kyc" : void 0
665
- })
666
- );
667
- }),
668
- [getRampQuotes]
669
- );
670
- const handleCreateCardSession = useCallback2(
671
- (params) => __async(null, null, function* () {
672
- if (!params.walletAddress) {
673
- throw new Error("Deposit address not available for the selected network");
674
- }
675
- const session = yield createRampSession(params);
676
- return {
677
- id: session.id,
678
- widgetUrl: session.widgetUrl,
679
- serviceProviderWidgetUrl: session.serviceProviderWidgetUrl
680
- };
681
- }),
682
- [createRampSession]
683
- );
684
- const cardRedirectUrl = typeof window !== "undefined" ? `${window.location.origin}/profile?tab=activity` : void 0;
685
- return {
686
- open,
687
- onOpenChange: handleDepositModalOpenChange,
688
- pendingCardPurchaseSummary,
689
- walletFlow: {
690
- balance: totalBalance != null ? totalBalance : 0,
691
- walletLabel,
692
- walletBalance,
693
- isWalletBalanceLoading,
694
- amount: depositAmount,
695
- formErrorMessage: walletTransaction ? void 0 : walletTransactionError != null ? walletTransactionError : void 0,
696
- formErrorTone: walletTransactionErrorTone,
697
- transactionStatus: walletTransactionStatus,
698
- transactionErrorMessage: walletTransactionError != null ? walletTransactionError : void 0,
699
- successSummary: {
700
- fromWallet: walletLabel,
701
- gasFee: walletTransactionGasFee
702
- }
703
- },
704
- onWalletAmountChange: setDepositAmount,
705
- onWalletMax: useCallback2(() => setDepositAmount(String(walletBalance)), [walletBalance]),
706
- onConfirmWalletDeposit: handleConfirmWalletDeposit,
707
- onCancelWalletDeposit: handleCancelWalletDeposit,
708
- onWalletNetworkChange: setWalletModalChainId,
709
- onWalletTokenChange: setWalletModalTokenSymbol,
710
- initialWalletChainId: connectedChainId ? String(connectedChainId) : void 0,
711
- connectedWalletKind: hasEvmCapability && !hasSolanaCapability ? "evm" : hasSolanaCapability && !hasEvmCapability ? "solana" : void 0,
712
- sendCryptoConfig: { minDeposit: "$1", eta: "~30s" },
713
- onDoneSendCrypto: useCallback2(
714
- () => handleDepositModalOpenChange(false),
715
- [handleDepositModalOpenChange]
716
- ),
717
- cardFlow: {
718
- amount: cardAmount,
719
- currency: "USD",
720
- tokenOptions: [{ value: "USDC", label: "USDC" }],
721
- selectedToken: "USDC",
722
- selectedNetwork: cardNetwork,
723
- providers: [],
724
- purchaseSummary: { amountReceived: "", network: "", fees: "" },
725
- minAmount: 11
726
- },
727
- onCardAmountChange: setCardAmount,
728
- onCardNetworkChange: setCardNetwork,
729
- onDoneCardPurchase: useCallback2(() => {
730
- syncBalancesMutate();
731
- if (typeof window !== "undefined") {
732
- window.history.replaceState({}, "", window.location.pathname);
733
- }
734
- }, [syncBalancesMutate]),
735
- cardRedirectUrl,
736
- onGetCardQuotes: handleGetCardQuotes,
737
- onCreateCardSession: handleCreateCardSession
738
- };
531
+ const { open, onOpenChange } = options;
532
+ const client = useAggClient();
533
+ const { user } = useAggAuthState();
534
+ const { walletActions } = useAggUiConfig();
535
+ const { totalBalance } = useAggBalanceState();
536
+ const { supportedChains } = useDepositAddresses({ enabled: !!user });
537
+ const { mutate: syncBalancesMutate } = useSyncBalances();
538
+ const defaultSendToken = useWalletSendToken();
539
+ const sendToken = walletActions?.sendToken ?? defaultSendToken;
540
+ const { mutateAsync: getRampQuotes } = useRampQuotes();
541
+ const { mutateAsync: createRampSession } = useRampSession();
542
+ const [depositAmount, setDepositAmount] = useState("");
543
+ const [cardAmount, setCardAmount] = useState("");
544
+ const [cardNetwork, setCardNetwork] = useState("solana");
545
+ const [walletModalChainId, setWalletModalChainId] = useState(null);
546
+ const [walletModalTokenSymbol, setWalletModalTokenSymbol] = useState(null);
547
+ const [walletTransaction, setWalletTransaction] = useState(null);
548
+ const [walletTransactionError, setWalletTransactionError] = useState(null);
549
+ const [walletTransactionErrorTone, setWalletTransactionErrorTone] = useState("error");
550
+ const [pendingCardPurchaseSummary, setPendingCardPurchaseSummary] = useState(null);
551
+ const rampRedirectHandled = useRef(false);
552
+ useEffect(() => {
553
+ if (rampRedirectHandled.current) return;
554
+ if (typeof window === "undefined") return;
555
+ const url = new URL(window.location.href);
556
+ const cryptoAmount = url.searchParams.get("cryptoAmount");
557
+ const cryptoCurrency = url.searchParams.get("cryptoCurrency");
558
+ if (!cryptoAmount) return;
559
+ rampRedirectHandled.current = true;
560
+ const network = url.searchParams.get("network") ?? "";
561
+ const totalFee = url.searchParams.get("totalFeeInFiat") ?? "";
562
+ setPendingCardPurchaseSummary({
563
+ amountReceived: `+${cryptoAmount} ${cryptoCurrency ?? "USDC"}`,
564
+ network: network.charAt(0).toUpperCase() + network.slice(1),
565
+ fees: totalFee ? `$${totalFee}` : ""
566
+ });
567
+ onOpenChange(true);
568
+ }, []);
569
+ const { chainId: connectedChainId, address: connectedAddress } = useAccount();
570
+ const { switchChainAsync } = useSwitchChain();
571
+ const { wallet: solanaWallet } = useWallet();
572
+ const resolvedSvmAddress = useSvmAddress();
573
+ const solanaAdapterName = solanaWallet?.adapter?.name;
574
+ const isMultiChainSolanaWallet = Boolean(solanaAdapterName && MULTI_CHAIN_SOLANA_WALLET_NAMES.has(solanaAdapterName));
575
+ const hasSolanaCapability = Boolean(resolvedSvmAddress || solanaWallet?.adapter);
576
+ const hasEvmCapability = Boolean(connectedAddress) || isMultiChainSolanaWallet;
577
+ const defaultBalanceChainId = hasEvmCapability && supportedChains?.some((chain) => chain.chainId === DEFAULT_WALLET_CHAIN_ID) ? DEFAULT_WALLET_CHAIN_ID : connectedChainId;
578
+ const balanceChainId = walletModalChainId ? Number(walletModalChainId) : defaultBalanceChainId;
579
+ const selectedChainTokens = useMemo(() => {
580
+ if (!supportedChains || !balanceChainId) return [];
581
+ return supportedChains.find((c) => c.chainId === balanceChainId)?.tokens ?? [];
582
+ }, [supportedChains, balanceChainId]);
583
+ const selectedTokenMeta = useMemo(() => {
584
+ const preferredTokenSymbol = walletModalTokenSymbol ?? DEFAULT_WALLET_TOKEN_SYMBOL;
585
+ const match = selectedChainTokens.find((t) => t.symbol === preferredTokenSymbol);
586
+ return match ? {
587
+ address: match.address,
588
+ decimals: match.decimals
589
+ } : void 0;
590
+ }, [selectedChainTokens, walletModalTokenSymbol]);
591
+ const isSvmBalanceChain = balanceChainId !== void 0 && SVM_CHAIN_IDS.has(balanceChainId);
592
+ const walletAddress = useMemo(() => {
593
+ if (isSvmBalanceChain) return resolvedSvmAddress ?? "";
594
+ return connectedAddress ?? "";
595
+ }, [
596
+ connectedAddress,
597
+ isSvmBalanceChain,
598
+ resolvedSvmAddress
599
+ ]);
600
+ const walletLabel = useMemo(() => {
601
+ return walletAddress ? `${walletAddress.slice(0, 6)}...${walletAddress.slice(-4)}` : "—";
602
+ }, [walletAddress]);
603
+ const { balance: walletBalance, isLoading: isWalletBalanceLoading } = useWalletTokenBalance({
604
+ isOpen: open,
605
+ chainId: balanceChainId,
606
+ tokenAddress: selectedTokenMeta?.address,
607
+ decimals: selectedTokenMeta?.decimals
608
+ });
609
+ const { status: observedWalletTransactionStatus, gasFee: walletTransactionGasFee } = useWalletTransactionStatus({
610
+ chainId: walletTransaction?.chainId,
611
+ txId: walletTransaction?.txId ?? null
612
+ });
613
+ const walletTransactionStatus = walletTransactionError ? "error" : walletTransaction ? observedWalletTransactionStatus ?? "submitted" : void 0;
614
+ const syncedDepositTxIdRef = useRef(null);
615
+ useEffect(() => {
616
+ if (walletTransactionStatus !== "settled" || !walletTransaction?.txId) return;
617
+ if (syncedDepositTxIdRef.current === walletTransaction.txId) return;
618
+ syncedDepositTxIdRef.current = walletTransaction.txId;
619
+ syncBalancesMutate();
620
+ }, [
621
+ syncBalancesMutate,
622
+ walletTransaction?.txId,
623
+ walletTransactionStatus
624
+ ]);
625
+ const handleDepositModalOpenChange = useCallback((isOpen) => {
626
+ if (!isOpen) {
627
+ setDepositAmount("");
628
+ setCardAmount("");
629
+ setCardNetwork("solana");
630
+ setWalletModalChainId(null);
631
+ setWalletModalTokenSymbol(null);
632
+ setWalletTransaction(null);
633
+ setWalletTransactionError(null);
634
+ setWalletTransactionErrorTone("error");
635
+ setPendingCardPurchaseSummary(null);
636
+ syncedDepositTxIdRef.current = null;
637
+ }
638
+ onOpenChange(isOpen);
639
+ }, [onOpenChange]);
640
+ const handleCancelWalletDeposit = useCallback(() => {
641
+ setWalletTransaction(null);
642
+ setWalletTransactionError(null);
643
+ setWalletTransactionErrorTone("error");
644
+ syncedDepositTxIdRef.current = null;
645
+ }, []);
646
+ const handleConfirmWalletDeposit = useCallback(async (params) => {
647
+ const { address, amount, chainId, token } = params;
648
+ const tokenMeta = (supportedChains?.find((c) => c.chainId === chainId) ?? null)?.tokens.find((t) => t.symbol === token) ?? null;
649
+ try {
650
+ setWalletTransactionError(null);
651
+ setWalletTransactionErrorTone("error");
652
+ if (!SVM_CHAIN_IDS.has(chainId) && connectedChainId && connectedChainId !== chainId) await switchChainAsync({ chainId });
653
+ const { txId } = await sendToken({
654
+ chainId,
655
+ token: {
656
+ symbol: token,
657
+ address: tokenMeta?.address,
658
+ decimals: tokenMeta?.decimals ?? 6
659
+ },
660
+ to: address,
661
+ amount
662
+ });
663
+ setWalletTransaction({
664
+ chainId,
665
+ txId
666
+ });
667
+ client.recordDepositIntent({
668
+ chainId,
669
+ txHash: txId
670
+ }).catch(() => {});
671
+ } catch (err) {
672
+ setWalletTransaction(null);
673
+ const normalizedError = normalizeWalletError(err, supportedChains);
674
+ setWalletTransactionError(normalizedError.message);
675
+ setWalletTransactionErrorTone(normalizedError.tone);
676
+ throw err;
677
+ }
678
+ }, [
679
+ client,
680
+ connectedChainId,
681
+ sendToken,
682
+ supportedChains,
683
+ switchChainAsync
684
+ ]);
685
+ const handleGetCardQuotes = useCallback(async (params) => {
686
+ return (await getRampQuotes(params)).map((q, i) => ({
687
+ id: q.serviceProvider,
688
+ name: q.serviceProvider,
689
+ quote: `~ ${q.destinationAmount.toFixed(2)} USDC`,
690
+ fee: `$${q.totalFee.toFixed(2)}`,
691
+ badge: i === 0 ? "best" : q.lowKyc ? "low-kyc" : void 0
692
+ }));
693
+ }, [getRampQuotes]);
694
+ const handleCreateCardSession = useCallback(async (params) => {
695
+ if (!params.walletAddress) throw new Error("Deposit address not available for the selected network");
696
+ const session = await createRampSession(params);
697
+ return {
698
+ id: session.id,
699
+ widgetUrl: session.widgetUrl,
700
+ serviceProviderWidgetUrl: session.serviceProviderWidgetUrl
701
+ };
702
+ }, [createRampSession]);
703
+ const cardRedirectUrl = typeof window !== "undefined" ? `${window.location.origin}/profile?tab=activity` : void 0;
704
+ return {
705
+ open,
706
+ onOpenChange: handleDepositModalOpenChange,
707
+ pendingCardPurchaseSummary,
708
+ walletFlow: {
709
+ balance: totalBalance ?? 0,
710
+ walletLabel,
711
+ walletBalance,
712
+ isWalletBalanceLoading,
713
+ amount: depositAmount,
714
+ formErrorMessage: walletTransaction ? void 0 : walletTransactionError ?? void 0,
715
+ formErrorTone: walletTransactionErrorTone,
716
+ transactionStatus: walletTransactionStatus,
717
+ transactionErrorMessage: walletTransactionError ?? void 0,
718
+ successSummary: {
719
+ fromWallet: walletLabel,
720
+ gasFee: walletTransactionGasFee
721
+ }
722
+ },
723
+ onWalletAmountChange: setDepositAmount,
724
+ onWalletMax: useCallback(() => setDepositAmount(String(walletBalance)), [walletBalance]),
725
+ onConfirmWalletDeposit: handleConfirmWalletDeposit,
726
+ onCancelWalletDeposit: handleCancelWalletDeposit,
727
+ onWalletNetworkChange: setWalletModalChainId,
728
+ onWalletTokenChange: setWalletModalTokenSymbol,
729
+ initialWalletChainId: connectedChainId ? String(connectedChainId) : void 0,
730
+ connectedWalletKind: hasEvmCapability && !hasSolanaCapability ? "evm" : hasSolanaCapability && !hasEvmCapability ? "solana" : void 0,
731
+ sendCryptoConfig: {
732
+ minDeposit: "$1",
733
+ eta: "~30s"
734
+ },
735
+ onDoneSendCrypto: useCallback(() => handleDepositModalOpenChange(false), [handleDepositModalOpenChange]),
736
+ cardFlow: {
737
+ amount: cardAmount,
738
+ currency: "USD",
739
+ tokenOptions: [{
740
+ value: "USDC",
741
+ label: "USDC"
742
+ }],
743
+ selectedToken: "USDC",
744
+ selectedNetwork: cardNetwork,
745
+ providers: [],
746
+ purchaseSummary: {
747
+ amountReceived: "",
748
+ network: "",
749
+ fees: ""
750
+ },
751
+ minAmount: 11
752
+ },
753
+ onCardAmountChange: setCardAmount,
754
+ onCardNetworkChange: setCardNetwork,
755
+ onDoneCardPurchase: useCallback(() => {
756
+ syncBalancesMutate();
757
+ if (typeof window !== "undefined") window.history.replaceState({}, "", window.location.pathname);
758
+ }, [syncBalancesMutate]),
759
+ cardRedirectUrl,
760
+ onGetCardQuotes: handleGetCardQuotes,
761
+ onCreateCardSession: handleCreateCardSession
762
+ };
739
763
  }
740
- export {
741
- DEFAULT_SOLANA_RPC_ENDPOINT,
742
- SVM_CHAIN_IDS,
743
- normalizeWalletError,
744
- useDepositAddresses,
745
- useDepositFlow,
746
- useSyncBalances,
747
- useWalletSendToken,
748
- useWalletTokenBalance,
749
- useWalletTransactionStatus
750
- };
764
+ //#endregion
765
+ export { DEFAULT_SOLANA_RPC_ENDPOINT, SVM_CHAIN_IDS, normalizeWalletError, useDepositAddresses, useDepositFlow, useSyncBalances, useWalletSendToken, useWalletTokenBalance, useWalletTransactionStatus };
766
+
767
+ //# sourceMappingURL=deposit.mjs.map