@glacislabs/stablegenie-zerodelta 2.0.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.
@@ -0,0 +1,3107 @@
1
+ import { symbolKey, normalizeDecimalText, parseUnitsDecimal, SUPPORTED_CHAIN_IDS, tokenEnabled, isDeliverable, assetDecimals, findToken, formatUnits, createEngine, routeNativeValue, checkNativeFee, nativeFeeShortLabel, nativeSymbol, nativeFeeShortMessage, allowanceCovers, validatePlannedTransaction, SUPPORTED_ASSETS, BUNDLED_RPC } from './chunk-VL5MWEY2.js';
2
+ import { createContext, useMemo, useState, useEffect, useRef, useCallback, useId, createElement, useContext } from 'react';
3
+ import { createRoot } from 'react-dom/client';
4
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
+
6
+ var ConfigContext = createContext({});
7
+ function StableGenieProvider({ children, ...config }) {
8
+ return /* @__PURE__ */ jsx(ConfigContext.Provider, { value: config, children });
9
+ }
10
+ function useMergedConfig(local) {
11
+ const ctx = useContext(ConfigContext);
12
+ return { ...ctx, ...local, theme: { ...ctx.theme, ...local.theme } };
13
+ }
14
+ function useEngine(config) {
15
+ return useMemo(
16
+ () => createEngine(config),
17
+ // eslint-disable-next-line react-hooks/exhaustive-deps
18
+ [config.apiBase, config.apiKey, config.trustedApiOrigin]
19
+ );
20
+ }
21
+
22
+ // src/provider/eip1193.ts
23
+ function discoverProviders(timeoutMs = 300) {
24
+ return new Promise((resolve) => {
25
+ if (typeof window === "undefined") return resolve([]);
26
+ const found = /* @__PURE__ */ new Map();
27
+ const onAnnounce = (event) => {
28
+ const detail = event.detail;
29
+ if (detail?.info?.uuid && detail.provider) found.set(detail.info.uuid, detail);
30
+ };
31
+ window.addEventListener("eip6963:announceProvider", onAnnounce);
32
+ window.dispatchEvent(new Event("eip6963:requestProvider"));
33
+ setTimeout(() => {
34
+ window.removeEventListener("eip6963:announceProvider", onAnnounce);
35
+ resolve([...found.values()]);
36
+ }, timeoutMs);
37
+ });
38
+ }
39
+ function legacyProvider() {
40
+ if (typeof window === "undefined") return null;
41
+ const eth = window.ethereum;
42
+ if (!eth) return null;
43
+ if (Array.isArray(eth.providers) && eth.providers.length) return eth.providers[0];
44
+ return eth;
45
+ }
46
+ async function resolveProvider(injected2) {
47
+ if (injected2) return injected2;
48
+ const details = await discoverProviders();
49
+ if (details.length) return details[0].provider;
50
+ const legacy = legacyProvider();
51
+ if (legacy) return legacy;
52
+ throw new Error("No EVM wallet found. Install MetaMask, Rabby, or another EIP-1193 wallet.");
53
+ }
54
+
55
+ // src/provider/wallet.ts
56
+ function chainHex(chainId) {
57
+ return `0x${Number(chainId).toString(16)}`;
58
+ }
59
+ function hexToChain(hex) {
60
+ if (typeof hex !== "string") return typeof hex === "number" ? hex : null;
61
+ return Number.parseInt(hex, 16);
62
+ }
63
+ async function getAccounts(provider) {
64
+ const accounts = await provider.request({ method: "eth_accounts" });
65
+ return Array.isArray(accounts) ? accounts : [];
66
+ }
67
+ async function requestAccounts(provider) {
68
+ const accounts = await provider.request({ method: "eth_requestAccounts" });
69
+ return Array.isArray(accounts) ? accounts : [];
70
+ }
71
+ async function getChainId(provider) {
72
+ return hexToChain(await provider.request({ method: "eth_chainId" }));
73
+ }
74
+ var NATIVE_CURRENCY = {
75
+ 1: { chainName: "Ethereum", name: "Ether", symbol: "ETH" },
76
+ 10: { chainName: "Optimism", name: "Ether", symbol: "ETH" },
77
+ 130: { chainName: "Unichain", name: "Ether", symbol: "ETH" },
78
+ 146: { chainName: "Sonic", name: "Sonic", symbol: "S" },
79
+ 8453: { chainName: "Base", name: "Ether", symbol: "ETH" },
80
+ 9745: { chainName: "Plasma", name: "Plasma", symbol: "XPL" },
81
+ 57073: { chainName: "Ink", name: "Ether", symbol: "ETH" },
82
+ 42161: { chainName: "Arbitrum One", name: "Ether", symbol: "ETH" }
83
+ };
84
+ function addChainParams(chainId) {
85
+ const meta = NATIVE_CURRENCY[chainId];
86
+ const rpc = BUNDLED_RPC[chainId];
87
+ if (!meta || !rpc) return null;
88
+ return {
89
+ chainId: chainHex(chainId),
90
+ chainName: meta.chainName,
91
+ nativeCurrency: { name: meta.name, symbol: meta.symbol, decimals: 18 },
92
+ rpcUrls: [rpc]
93
+ };
94
+ }
95
+ function rpcErrorCode(err) {
96
+ let cur = err;
97
+ const seen = /* @__PURE__ */ new Set();
98
+ while (cur && typeof cur === "object" && !seen.has(cur)) {
99
+ seen.add(cur);
100
+ const e = cur;
101
+ if (typeof e.data?.originalError?.code === "number") return e.data.originalError.code;
102
+ if (typeof e.code === "number") return e.code;
103
+ cur = e.cause;
104
+ }
105
+ return void 0;
106
+ }
107
+ async function switchChain(provider, chainId) {
108
+ try {
109
+ await provider.request({ method: "wallet_switchEthereumChain", params: [{ chainId: chainHex(chainId) }] });
110
+ } catch (err) {
111
+ const params = addChainParams(chainId);
112
+ if (rpcErrorCode(err) === 4902 && params) {
113
+ await provider.request({ method: "wallet_addEthereumChain", params: [params] });
114
+ await provider.request({ method: "wallet_switchEthereumChain", params: [{ chainId: chainHex(chainId) }] });
115
+ return;
116
+ }
117
+ throw err;
118
+ }
119
+ }
120
+ function shortWalletMessage(err) {
121
+ if (err && typeof err === "object") {
122
+ const e = err;
123
+ if (typeof e.shortMessage === "string" && e.shortMessage) return e.shortMessage;
124
+ if (typeof e.message === "string" && e.message) return e.message;
125
+ }
126
+ return void 0;
127
+ }
128
+ function normalizeWalletError(err, fallback = "Transaction failed.") {
129
+ if (!err) return fallback;
130
+ const code = rpcErrorCode(err);
131
+ const name = err && typeof err === "object" && "name" in err ? err.name : void 0;
132
+ if (code === -32002) return "Open your wallet \u2014 a request is already pending.";
133
+ if (code === 4001 || name === "UserRejectedRequestError") return "Request was rejected in your wallet.";
134
+ if (code === 4902) return "This chain isn't set up in your wallet. Approve adding it and try again.";
135
+ if (code === -32603) return shortWalletMessage(err) || "Your wallet returned an internal error. Try again.";
136
+ return shortWalletMessage(err) || fallback;
137
+ }
138
+ async function sendTransaction(provider, tx) {
139
+ const hash = await provider.request({
140
+ method: "eth_sendTransaction",
141
+ params: [{ from: tx.from, to: tx.to, data: tx.data, value: tx.value || "0x0" }]
142
+ });
143
+ return hash;
144
+ }
145
+ var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
146
+ async function waitForReceipt(provider, hash, opts = {}) {
147
+ const timeoutMs = opts.timeoutMs ?? 9e4;
148
+ const pollMs = opts.pollMs ?? 2500;
149
+ const deadline = Date.now() + timeoutMs;
150
+ for (; ; ) {
151
+ let receipt = null;
152
+ try {
153
+ receipt = await provider.request({ method: "eth_getTransactionReceipt", params: [hash] });
154
+ } catch {
155
+ }
156
+ if (receipt && receipt.status != null) {
157
+ const status = String(receipt.status).toLowerCase();
158
+ if (status === "0x0" || status === "0x00" || status === "0") {
159
+ throw new Error("A transaction reverted on-chain before settlement. Nothing was submitted \u2014 please try again.");
160
+ }
161
+ return;
162
+ }
163
+ if (Date.now() >= deadline) {
164
+ throw new Error("Timed out waiting for the transaction to confirm. Check your wallet and try again.");
165
+ }
166
+ await sleep(pollMs);
167
+ }
168
+ }
169
+ async function ethCall(provider, to, data) {
170
+ return await provider.request({ method: "eth_call", params: [{ to, data }, "latest"] });
171
+ }
172
+ async function nativeBalance(provider, account) {
173
+ try {
174
+ const raw = await provider.request({ method: "eth_getBalance", params: [account, "latest"] });
175
+ if (typeof raw !== "string" || !/^0x[0-9a-fA-F]*$/.test(raw)) return null;
176
+ return BigInt(raw || "0x0");
177
+ } catch {
178
+ return null;
179
+ }
180
+ }
181
+
182
+ // src/react/hooks/useWallet.ts
183
+ function useWallet(injected2) {
184
+ const [provider, setProvider] = useState(injected2 ?? null);
185
+ const [account, setAccount] = useState(null);
186
+ const [chainId, setChainId] = useState(null);
187
+ const [connecting, setConnecting] = useState(false);
188
+ const [error, setError] = useState(null);
189
+ const providerRef = useRef(injected2 ?? null);
190
+ useEffect(() => {
191
+ const p = provider;
192
+ if (!p) return;
193
+ let alive = true;
194
+ const onAccounts = (accs) => alive && setAccount(Array.isArray(accs) && accs[0] ? accs[0] : null);
195
+ const onChain = (hex) => alive && setChainId(hexToChain(hex));
196
+ p.on?.("accountsChanged", onAccounts);
197
+ p.on?.("chainChanged", onChain);
198
+ (async () => {
199
+ try {
200
+ const accs = await getAccounts(p);
201
+ if (alive && accs[0]) setAccount(accs[0]);
202
+ const cid = await getChainId(p);
203
+ if (alive) setChainId(cid);
204
+ } catch {
205
+ }
206
+ })();
207
+ return () => {
208
+ alive = false;
209
+ p.removeListener?.("accountsChanged", onAccounts);
210
+ p.removeListener?.("chainChanged", onChain);
211
+ };
212
+ }, [provider]);
213
+ useEffect(() => {
214
+ if (injected2 && injected2 !== providerRef.current) {
215
+ providerRef.current = injected2;
216
+ setProvider(injected2);
217
+ }
218
+ }, [injected2]);
219
+ const connect = useCallback(async () => {
220
+ setConnecting(true);
221
+ setError(null);
222
+ try {
223
+ const p = providerRef.current ?? await resolveProvider(injected2);
224
+ providerRef.current = p;
225
+ setProvider(p);
226
+ const accs = await requestAccounts(p);
227
+ setAccount(accs[0] ?? null);
228
+ setChainId(await getChainId(p));
229
+ } catch (e) {
230
+ setError(normalizeWalletError(e, "Could not connect a wallet."));
231
+ } finally {
232
+ setConnecting(false);
233
+ }
234
+ }, [injected2]);
235
+ return { provider, account, chainId, connecting, error, connect };
236
+ }
237
+
238
+ // src/react/txHistoryStore.ts
239
+ var TX_HISTORY_EVENT = "sg:txhistory";
240
+ var TX_HISTORY_LIMIT = 50;
241
+ function defaultStorage() {
242
+ try {
243
+ return typeof window !== "undefined" ? window.localStorage : null;
244
+ } catch {
245
+ return null;
246
+ }
247
+ }
248
+ function validAccount(account) {
249
+ return typeof account === "string" && /^0x[0-9a-fA-F]{40}$/.test(account);
250
+ }
251
+ function txHistoryKey(account) {
252
+ return `sg:txh:v1:${account.toLowerCase()}`;
253
+ }
254
+ function isEntry(v) {
255
+ if (!v || typeof v !== "object") return false;
256
+ const e = v;
257
+ return typeof e.hash === "string" && e.hash.length > 0 && typeof e.at === "string" && typeof e.status === "string";
258
+ }
259
+ function readTxHistory(account, storage2 = defaultStorage()) {
260
+ if (!storage2 || !validAccount(account)) return [];
261
+ try {
262
+ const raw = storage2.getItem(txHistoryKey(account));
263
+ if (!raw) return [];
264
+ const parsed = JSON.parse(raw);
265
+ return Array.isArray(parsed) ? parsed.filter(isEntry) : [];
266
+ } catch {
267
+ return [];
268
+ }
269
+ }
270
+ function appendTxHistory(account, entry, storage2 = defaultStorage()) {
271
+ const current = readTxHistory(account, storage2);
272
+ if (!storage2 || !validAccount(account) || !entry || !entry.hash) return current;
273
+ const next = [entry, ...current.filter((e) => e.hash !== entry.hash)].slice(0, TX_HISTORY_LIMIT);
274
+ try {
275
+ storage2.setItem(txHistoryKey(account), JSON.stringify(next));
276
+ } catch {
277
+ return current;
278
+ }
279
+ try {
280
+ if (typeof window !== "undefined") window.dispatchEvent(new CustomEvent(TX_HISTORY_EVENT, { detail: { account: account.toLowerCase() } }));
281
+ } catch {
282
+ }
283
+ return next;
284
+ }
285
+
286
+ // src/react/hooks/useFlow.ts
287
+ function useFlow(args) {
288
+ const { engine, wallet, kind, enabled, paramsKey, loadPlan, recipientFor, onQuote, onSuccess, onError } = args;
289
+ const [status, setStatus] = useState("idle");
290
+ const [plan, setPlan] = useState(null);
291
+ const [selectedId, setSelectedId] = useState(null);
292
+ const [error, setError] = useState(null);
293
+ const [insufficient, setInsufficient] = useState(false);
294
+ const [nativeShortfall, setNativeShortfall] = useState(null);
295
+ const [steps, setSteps] = useState([]);
296
+ const [verdict, setVerdict] = useState(null);
297
+ const [txHash, setTxHash] = useState(null);
298
+ const [lastTxEntry, setLastTxEntry] = useState(null);
299
+ const [nonce, setNonce] = useState(0);
300
+ const reqId = useRef(0);
301
+ const busyRef = useRef(false);
302
+ const routes = plan?.routes ?? [];
303
+ const selected = useMemo(() => routes.find((r) => r.id === selectedId) ?? routes.find((r) => r.recommended) ?? routes[0] ?? null, [routes, selectedId]);
304
+ const reload = useCallback(() => setNonce((n) => n + 1), []);
305
+ useEffect(() => {
306
+ if (busyRef.current) return;
307
+ if (!enabled || !wallet.account) {
308
+ setStatus("idle");
309
+ setPlan(null);
310
+ return;
311
+ }
312
+ const id = ++reqId.current;
313
+ setStatus("loading");
314
+ setError(null);
315
+ setVerdict(null);
316
+ setTxHash(null);
317
+ setLastTxEntry(null);
318
+ (async () => {
319
+ try {
320
+ const p = await loadPlan(engine, wallet.account, wallet.chainId ?? void 0);
321
+ if (id !== reqId.current) return;
322
+ setPlan(p);
323
+ setSelectedId(p.routes.find((r) => r.recommended)?.id ?? p.routes[0]?.id ?? null);
324
+ setStatus("ready");
325
+ onQuote?.(p);
326
+ } catch (e) {
327
+ if (id !== reqId.current) return;
328
+ setPlan(null);
329
+ setError(e?.message || "Could not price this right now.");
330
+ setStatus("error");
331
+ onError?.(e instanceof Error ? e : new Error(String(e)));
332
+ }
333
+ })();
334
+ }, [enabled, wallet.account, wallet.chainId, paramsKey, nonce]);
335
+ useEffect(() => {
336
+ let alive = true;
337
+ setInsufficient(false);
338
+ const src = selected?.source;
339
+ if (!wallet.account || !src?.tokenAddress || src.decimals == null) return;
340
+ (async () => {
341
+ try {
342
+ const key = `${Number(src.chainId)}:${String(src.tokenAddress).toLowerCase()}`;
343
+ const balances = await engine.readBalances(wallet.account, [
344
+ { chainId: Number(src.chainId), tokenAddress: src.tokenAddress, decimals: Number(src.decimals) }
345
+ ]);
346
+ const entry = balances[key];
347
+ if (!entry) return;
348
+ const need = parseUnitsDecimal(src.payAmount || src.amount, src.decimals);
349
+ if (alive) setInsufficient(BigInt(entry.raw) < need);
350
+ } catch {
351
+ }
352
+ })();
353
+ return () => {
354
+ alive = false;
355
+ };
356
+ }, [engine, wallet.account, selected]);
357
+ useEffect(() => {
358
+ let alive = true;
359
+ setNativeShortfall(null);
360
+ const account = wallet.account;
361
+ const src = selected?.source;
362
+ if (!account || !src || routeNativeValue(selected) <= 0n) return;
363
+ (async () => {
364
+ try {
365
+ const [balance, chains] = await Promise.all([
366
+ engine.readNativeBalance(Number(src.chainId), account),
367
+ engine.fetchChains().catch(() => [])
368
+ ]);
369
+ if (!alive) return;
370
+ const check = checkNativeFee(selected, balance);
371
+ setNativeShortfall(nativeFeeShortLabel(check, nativeSymbol(Number(src.chainId), chains)));
372
+ } catch {
373
+ }
374
+ })();
375
+ return () => {
376
+ alive = false;
377
+ };
378
+ }, [engine, wallet.account, selected]);
379
+ const submit = useCallback(async () => {
380
+ if (busyRef.current) return;
381
+ const route = selected;
382
+ const provider = wallet.provider;
383
+ const account = wallet.account;
384
+ if (!route || !provider || !account) return;
385
+ busyRef.current = true;
386
+ const recipient = recipientFor(account);
387
+ const sourceChainId = route.source.chainId;
388
+ const txSteps = route.transactions.map((tx) => ({ id: tx.id, label: tx.label, state: "pending" }));
389
+ txSteps.push({ id: "verify", label: "Confirm on-chain", state: "pending" });
390
+ setSteps(txSteps);
391
+ setStatus("submitting");
392
+ setError(null);
393
+ setVerdict(null);
394
+ const patch = (id, s, hash) => setSteps((prev) => prev.map((st) => st.id === id ? { ...st, state: s, ...hash ? { hash } : {} } : st));
395
+ try {
396
+ const current = await getChainId(provider);
397
+ if (current !== Number(sourceChainId)) {
398
+ await switchChain(provider, Number(sourceChainId));
399
+ const after = await getChainId(provider);
400
+ if (after !== Number(sourceChainId)) throw new Error("Wallet did not switch to the source chain.");
401
+ }
402
+ if (routeNativeValue(route) > 0n) {
403
+ const check = checkNativeFee(route, await nativeBalance(provider, account));
404
+ if (check.short) {
405
+ const chains = await engine.fetchChains().catch(() => []);
406
+ throw new Error(nativeFeeShortMessage(check, nativeSymbol(Number(sourceChainId), chains), route.source.chainName));
407
+ }
408
+ }
409
+ const minNonce = await engine.payerNonceBaseline(Number(sourceChainId), account);
410
+ const txs = route.transactions;
411
+ let settleHash = "";
412
+ let settleTx = txs[txs.length - 1];
413
+ for (let i = 0; i < txs.length; i++) {
414
+ const tx = txs[i];
415
+ const isFinal = i === txs.length - 1;
416
+ if (tx.mock) {
417
+ patch(tx.id, "done");
418
+ continue;
419
+ }
420
+ if (tx.kind === "approve" && await allowanceCovers(tx, account, (to, data) => ethCall(provider, to, data))) {
421
+ patch(tx.id, "done");
422
+ continue;
423
+ }
424
+ if (!validatePlannedTransaction(tx, route, recipient)) {
425
+ throw new Error(`Refusing to sign a ${tx.kind} that does not match the reviewed plan.`);
426
+ }
427
+ patch(tx.id, "active");
428
+ const hash = await sendTransaction(provider, { from: account, to: tx.to, data: tx.data, value: tx.value });
429
+ if (!isFinal) {
430
+ await waitForReceipt(provider, hash);
431
+ }
432
+ patch(tx.id, "done", hash);
433
+ if (tx.kind !== "approve") {
434
+ settleHash = hash;
435
+ settleTx = tx;
436
+ }
437
+ }
438
+ patch("verify", "active");
439
+ const v = settleHash ? await engine.verifySubmittedTx({ chainId: Number(sourceChainId), hash: settleHash, from: account, to: settleTx.to, data: settleTx.data, value: settleTx.value, minNonce: minNonce ?? void 0 }) : { status: "unconfirmed" };
440
+ setVerdict(v);
441
+ setTxHash(settleHash || null);
442
+ patch("verify", v.status === "confirmed" ? "done" : v.status === "mismatch" || v.status === "reverted" ? "error" : "active");
443
+ const entry = engine.recordTransaction({
444
+ kind,
445
+ hash: settleHash,
446
+ txKind: settleTx.kind,
447
+ chainId: Number(sourceChainId),
448
+ chainName: route.source.chainName,
449
+ fromAsset: route.source.asset,
450
+ toAsset: route.receive.asset,
451
+ payAmount: route.source.payAmount,
452
+ receiveAmount: route.receive.amount,
453
+ account,
454
+ recipient,
455
+ settlement: route.state === "DIRECT" ? "direct" : "escrow",
456
+ status: v.status === "confirmed" ? "confirmed" : v.status === "mismatch" || v.status === "reverted" ? "error" : "unconfirmed"
457
+ });
458
+ setLastTxEntry(entry.hash ? entry : null);
459
+ appendTxHistory(account, entry);
460
+ if (v.status === "mismatch") {
461
+ setStatus("error");
462
+ setError("The submitted transaction did not match the reviewed plan.");
463
+ onError?.(new Error("tx mismatch"));
464
+ } else if (v.status === "reverted") {
465
+ setStatus("error");
466
+ setError("The transaction reverted on-chain. Your funds were not sent \u2014 please try again.");
467
+ onError?.(new Error("tx reverted"));
468
+ } else if (v.status === "confirmed") {
469
+ setStatus("success");
470
+ onSuccess?.({ hash: settleHash, verdict: v, route });
471
+ } else {
472
+ setStatus("pending");
473
+ setError(null);
474
+ }
475
+ } catch (e) {
476
+ setStatus("error");
477
+ setError(normalizeWalletError(e));
478
+ setSteps((prev) => prev.map((st) => st.state === "active" ? { ...st, state: "error" } : st));
479
+ onError?.(e instanceof Error ? e : new Error(String(e)));
480
+ } finally {
481
+ busyRef.current = false;
482
+ }
483
+ }, [selected, wallet.provider, wallet.account, engine, kind, recipientFor, onSuccess, onError]);
484
+ return {
485
+ status,
486
+ plan,
487
+ routes,
488
+ selected,
489
+ selectRoute: setSelectedId,
490
+ error,
491
+ insufficient,
492
+ nativeShortfall,
493
+ steps,
494
+ verdict,
495
+ txHash,
496
+ lastTxEntry,
497
+ submit,
498
+ reload
499
+ };
500
+ }
501
+ function balanceKey(chainId, tokenAddress) {
502
+ return `${Number(chainId)}:${String(tokenAddress || "").toLowerCase()}`;
503
+ }
504
+ function useHoldings(engine, account, routes) {
505
+ const [balances, setBalances] = useState({});
506
+ const [loading, setLoading] = useState(false);
507
+ const reqId = useRef(0);
508
+ const targets = useMemo(() => {
509
+ const seen = /* @__PURE__ */ new Set();
510
+ const list = [];
511
+ for (const r of routes) {
512
+ const s = r.source;
513
+ if (!s?.tokenAddress || s.decimals == null) continue;
514
+ const k = balanceKey(s.chainId, s.tokenAddress);
515
+ if (seen.has(k)) continue;
516
+ seen.add(k);
517
+ list.push({ chainId: s.chainId, tokenAddress: s.tokenAddress, decimals: s.decimals });
518
+ }
519
+ return list;
520
+ }, [routes]);
521
+ const targetsKey = useMemo(() => targets.map((t) => balanceKey(t.chainId, t.tokenAddress)).join("|"), [targets]);
522
+ useEffect(() => {
523
+ if (!account || !targets.length) {
524
+ setBalances({});
525
+ setLoading(false);
526
+ return;
527
+ }
528
+ const id = ++reqId.current;
529
+ setLoading(true);
530
+ (async () => {
531
+ try {
532
+ const res = await engine.readBalances(account, targets);
533
+ if (id !== reqId.current) return;
534
+ setBalances(res);
535
+ } catch {
536
+ if (id === reqId.current) setBalances({});
537
+ } finally {
538
+ if (id === reqId.current) setLoading(false);
539
+ }
540
+ })();
541
+ }, [engine, account, targetsKey]);
542
+ return { balances, loading };
543
+ }
544
+
545
+ // src/react/styles.ts
546
+ var WIDGET_CSS = `
547
+ .sg-widget{box-sizing:border-box;width:100%;max-width:400px;margin:0 auto;padding:20px;background:var(--sg-bg);color:var(--sg-text);border:1px solid var(--sg-border);border-radius:var(--sg-radius);font-family:var(--sg-font);font-size:15px;line-height:1.5;box-shadow:0 1px 2px rgba(16,17,22,.04),0 8px 24px rgba(16,17,22,.06)}
548
+ .sg-widget *{box-sizing:border-box}
549
+ :root[data-theme="dark"] .sg-widget,.sg-widget[data-sg-mode="dark"]{box-shadow:0 8px 24px rgba(0,0,0,.4)}
550
+
551
+ .sg-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:16px}
552
+ .sg-title{font-size:15px;font-weight:600;letter-spacing:-0.01em}
553
+ .sg-brand{display:inline-flex;align-items:center;gap:5px;font-size:11px;color:var(--sg-text-muted);text-transform:uppercase;letter-spacing:0.08em}
554
+ .sg-brand-mark{flex:0 0 auto;display:block}
555
+
556
+ .sg-label{display:block;font-size:12px;color:var(--sg-text-muted);margin-bottom:6px}
557
+ .sg-panel{background:var(--sg-surface);border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);padding:16px}
558
+ .sg-panel + .sg-panel{margin-top:12px}
559
+ .sg-row{display:flex;gap:10px;align-items:center}
560
+ .sg-row>*{min-width:0}
561
+ .sg-grow{flex:1 1 auto}
562
+ .sg-muted{color:var(--sg-text-muted)}
563
+ .sg-mono{font-variant-numeric:tabular-nums}
564
+ .sg-strong{font-weight:600}
565
+
566
+ /* invariant anchor */
567
+ .sg-anchor{font-size:30px;font-weight:700;line-height:1.1;font-variant-numeric:tabular-nums;letter-spacing:-0.01em}
568
+ .sg-anchor-sub{font-size:12px;color:var(--sg-text-muted);margin-top:4px}
569
+
570
+ /* inputs */
571
+ .sg-input,.sg-select{width:100%;padding:10px 12px;background:var(--sg-bg);color:var(--sg-text);border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);font:inherit;outline:none;transition:border-color 120ms ease}
572
+ .sg-input:focus,.sg-select:focus{border-color:var(--sg-accent)}
573
+ .sg-amount{font-size:28px;font-weight:700;border:none;background:transparent;padding:0}
574
+ .sg-amount:focus{border:none}
575
+ .sg-field{margin-bottom:12px}
576
+ .sg-reverse{display:flex;align-items:center;justify-content:center;width:34px;height:34px;margin:-6px auto;position:relative;z-index:1;border-radius:var(--sg-radius-control);border:1px solid var(--sg-border);background:var(--sg-bg);color:var(--sg-text-muted);cursor:pointer;transition:color 120ms ease,border-color 120ms ease}
577
+ .sg-reverse:hover{color:var(--sg-accent);border-color:var(--sg-accent)}
578
+
579
+ /* method tabs (segmented) */
580
+ .sg-tabs{display:flex;gap:6px;margin:14px 0 10px;overflow-x:auto;scrollbar-width:none;padding-bottom:2px}
581
+ .sg-tabs::-webkit-scrollbar{display:none}
582
+ .sg-tab{flex:0 0 auto;display:inline-flex;align-items:center;gap:5px;padding:7px 12px;border:1px solid var(--sg-border);background:var(--sg-bg);color:var(--sg-text-muted);border-radius:var(--sg-radius-cta);font:inherit;font-size:13px;font-weight:500;cursor:pointer;white-space:nowrap;transition:background 120ms ease,color 120ms ease,border-color 120ms ease}
583
+ .sg-tab:hover:not([disabled]):not([data-selected="true"]){color:var(--sg-text)}
584
+ .sg-tab[data-selected="true"]{background:color-mix(in srgb,var(--sg-accent) 12%,transparent);border-color:color-mix(in srgb,var(--sg-accent) 45%,transparent);color:var(--sg-accent)}
585
+ .sg-tab[disabled]{opacity:.5;cursor:not-allowed}
586
+ .sg-soon{font-size:9px;font-weight:700;text-transform:uppercase;letter-spacing:.05em;padding:1px 5px;border-radius:999px;background:var(--sg-surface);color:var(--sg-text-muted)}
587
+
588
+ .sg-why{font-size:12px;color:var(--sg-text-muted);margin:0 2px 10px}
589
+
590
+ /* route radio list */
591
+ .sg-route{display:flex;flex-direction:column;gap:8px}
592
+ .sg-route-item{display:flex;align-items:center;gap:12px;padding:12px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);background:var(--sg-bg);cursor:pointer;transition:border-color 120ms ease,box-shadow 120ms ease}
593
+ .sg-route-item:hover{border-color:color-mix(in srgb,var(--sg-accent) 40%,var(--sg-border))}
594
+ .sg-route-item[data-selected="true"]{border-color:var(--sg-accent);box-shadow:0 0 0 1px var(--sg-accent) inset}
595
+ .sg-route-item:focus-visible{outline:2px solid var(--sg-accent);outline-offset:2px}
596
+ .sg-chip{flex:0 0 auto;width:40px;height:40px;border-radius:var(--sg-radius-control);background:var(--sg-surface);border:1px solid var(--sg-border);display:flex;flex-direction:column;align-items:center;justify-content:center;line-height:1.05}
597
+ .sg-chip b{font-size:12px;font-weight:700;font-variant-numeric:tabular-nums}
598
+ .sg-chip span{font-size:8px;color:var(--sg-text-muted);text-transform:uppercase;letter-spacing:.02em}
599
+ .sg-route-main{flex:1 1 auto;min-width:0}
600
+ .sg-route-amt{font-size:15px;font-weight:600;font-variant-numeric:tabular-nums;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
601
+ .sg-route-sub{font-size:12px;color:var(--sg-text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
602
+ .sg-route-end{flex:0 0 auto;display:flex;align-items:center;gap:6px}
603
+ .sg-radio{width:18px;height:18px;border-radius:999px;border:2px solid var(--sg-border);position:relative;transition:border-color 120ms ease}
604
+ .sg-route-item[data-selected="true"] .sg-radio{border-color:var(--sg-accent)}
605
+ .sg-route-item[data-selected="true"] .sg-radio::after{content:"";position:absolute;inset:3px;border-radius:999px;background:var(--sg-accent)}
606
+
607
+ .sg-more{width:100%;padding:9px;border:1px dashed var(--sg-border);background:transparent;color:var(--sg-text-muted);border-radius:var(--sg-radius-control);font:inherit;font-size:13px;cursor:pointer}
608
+ .sg-more:hover{color:var(--sg-text)}
609
+ .sg-collapse{overflow:hidden;transition:max-height var(--sg-motion-fast,160ms) var(--sg-ease-out-soft,ease),opacity var(--sg-motion-fast,160ms) var(--sg-ease-out-soft,ease)}
610
+
611
+ /* holdings-first checkout: your-funds section label, live balance chip, unaffordable dim, empty note */
612
+ .sg-section-label{font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:var(--sg-text-muted);margin:14px 2px 8px}
613
+ .sg-section-label:first-child{margin-top:0}
614
+ .sg-bal{font-size:11px;font-weight:600;font-variant-numeric:tabular-nums;color:var(--sg-text-muted);white-space:nowrap}
615
+ .sg-route-item[data-short="true"]{opacity:.55}
616
+ .sg-route-item[data-held="true"]{border-color:color-mix(in srgb,var(--sg-accent) 30%,var(--sg-border))}
617
+ .sg-note{font-size:12px;color:var(--sg-text-muted);margin:2px 2px 10px;line-height:1.45}
618
+
619
+ /* badges */
620
+ .sg-badge{font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:0.06em;padding:2px 7px;border-radius:999px;background:var(--sg-surface);color:var(--sg-text-muted)}
621
+ .sg-badge[data-tone="accent"]{background:color-mix(in srgb,var(--sg-accent) 16%,transparent);color:var(--sg-accent)}
622
+ .sg-badge[data-tone="ok"]{background:color-mix(in srgb,var(--sg-accent) 16%,transparent);color:var(--sg-accent)}
623
+ .sg-badge[data-tone="warn"]{background:color-mix(in srgb,var(--sg-danger) 14%,transparent);color:var(--sg-danger)}
624
+
625
+ /* CTA */
626
+ .sg-btn{width:100%;min-height:48px;padding:12px 16px;border:none;border-radius:var(--sg-radius-cta);background:var(--sg-accent);color:var(--sg-accent-text);font:inherit;font-size:15px;font-weight:600;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;gap:8px;transition:filter 120ms ease,opacity 120ms ease,transform 60ms ease}
627
+ .sg-btn:hover:not(:disabled){filter:brightness(1.06)}
628
+ .sg-btn:active:not(:disabled){transform:translateY(1px)}
629
+ .sg-btn:disabled{opacity:.5;cursor:not-allowed}
630
+ .sg-btn-ghost{background:transparent;color:var(--sg-text);border:1px solid var(--sg-border)}
631
+ .sg-btn-ghost:hover:not(:disabled){filter:none;border-color:var(--sg-accent);color:var(--sg-accent)}
632
+ .sg-cta-wrap{margin-top:14px}
633
+ .sg-cta-wrap .sg-btn+.sg-btn{margin-top:8px}
634
+
635
+ /* status / steps */
636
+ .sg-status{margin-top:12px;padding:12px 14px;border-radius:var(--sg-radius-control);background:var(--sg-surface);font-size:13px}
637
+ .sg-status[data-tone="error"]{background:color-mix(in srgb,var(--sg-danger) 12%,transparent);color:var(--sg-danger)}
638
+ .sg-status[data-tone="ok"]{background:color-mix(in srgb,var(--sg-accent) 12%,transparent);color:var(--sg-accent)}
639
+ .sg-steps{list-style:none;margin:10px 0 0;padding:0}
640
+ .sg-steps li{display:flex;align-items:center;gap:8px;padding:4px 0;font-size:13px}
641
+ .sg-dot{width:8px;height:8px;border-radius:999px;background:var(--sg-border);flex:0 0 auto}
642
+ .sg-dot[data-state="active"]{background:var(--sg-accent)}
643
+ .sg-dot[data-state="done"]{background:var(--sg-success)}
644
+ .sg-dot[data-state="error"]{background:var(--sg-danger)}
645
+
646
+ /* success (accent, not green) */
647
+ .sg-success{margin-top:14px;padding:18px;border-radius:var(--sg-radius-control);background:color-mix(in srgb,var(--sg-accent) 8%,transparent);text-align:center}
648
+ .sg-success-check{width:40px;height:40px;border-radius:999px;background:var(--sg-accent);color:var(--sg-accent-text);display:inline-flex;align-items:center;justify-content:center;margin-bottom:8px}
649
+ /* Broadcast but not receipt-confirmed: mute the disc so a pending settlement never wears the
650
+ accent-coloured "paid" affordance. Mirrors .sg-settle-disc[data-pending] in the island. */
651
+ .sg-success-check[data-pending="true"]{background:var(--sg-surface);color:var(--sg-text-muted);border:1px solid var(--sg-border)}
652
+ .sg-success-amt{font-size:20px;font-weight:700;font-variant-numeric:tabular-nums}
653
+ .sg-success-sub{font-size:12px;color:var(--sg-text-muted);margin-top:2px}
654
+
655
+ /* skeleton loading */
656
+ .sg-skel{height:64px;border-radius:var(--sg-radius-control);background:linear-gradient(90deg,var(--sg-surface) 25%,color-mix(in srgb,var(--sg-border) 50%,var(--sg-surface)) 37%,var(--sg-surface) 63%);background-size:400% 100%;animation:sg-shimmer 1.2s ease-in-out infinite;margin-bottom:8px}
657
+
658
+ /* spinner */
659
+ .sg-spinner{display:inline-block;width:14px;height:14px;border:2px solid currentColor;border-right-color:transparent;border-radius:999px;animation:sg-spin 0.7s linear infinite;vertical-align:-2px}
660
+ @keyframes sg-spin{to{transform:rotate(360deg)}}
661
+ @keyframes sg-shimmer{0%{background-position:100% 0}100%{background-position:-100% 0}}
662
+
663
+ .sg-foot{margin-top:14px;display:flex;align-items:center;justify-content:center;gap:6px;font-size:11px;color:var(--sg-text-muted);text-align:center}
664
+
665
+ /* fixed-height variant \u2014 head/foot pinned, body scrolls */
666
+ .sg-widget[data-sg-fixed="true"]{display:flex;flex-direction:column}
667
+ .sg-widget[data-sg-fixed="true"] .sg-body{flex:1 1 auto;min-height:0;overflow-y:auto;margin:0 -8px;padding:0 8px;scrollbar-width:thin}
668
+
669
+ /* head wallet pill (Connect wallet / connected address) */
670
+ .sg-wallet{display:inline-flex;align-items:center;gap:6px;padding:6px 12px;border-radius:var(--sg-radius-cta);border:1px solid var(--sg-border);background:transparent;color:var(--sg-text);font:inherit;font-size:12px;font-weight:600;cursor:pointer;transition:border-color 120ms ease,color 120ms ease}
671
+ .sg-wallet:hover{border-color:var(--sg-accent);color:var(--sg-accent)}
672
+ .sg-wallet[data-connected="true"]{cursor:default;color:var(--sg-text-muted)}
673
+ .sg-wallet[data-connected="true"]:hover{border-color:var(--sg-border);color:var(--sg-text-muted)}
674
+ .sg-wallet-dot{width:7px;height:7px;border-radius:999px;background:var(--sg-success)}
675
+
676
+ /* From/To tiles with a centered arrow (exchange layout) */
677
+ .sg-ft{position:relative;display:grid;grid-template-columns:1fr 1fr;gap:10px}
678
+ .sg-tile{display:flex;flex-direction:column;gap:10px;padding:14px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);background:var(--sg-surface);cursor:pointer;font:inherit;color:var(--sg-text);text-align:left;min-width:0;transition:border-color 120ms ease}
679
+ .sg-tile:hover:not(:disabled){border-color:color-mix(in srgb,var(--sg-accent) 45%,var(--sg-border))}
680
+ .sg-tile:disabled{cursor:default}
681
+ .sg-tile-label{font-size:12px;color:var(--sg-text-muted)}
682
+ .sg-tile-main{display:flex;align-items:center;gap:10px;min-width:0}
683
+ .sg-tile-sym{font-size:16px;font-weight:700;line-height:1.15;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
684
+ .sg-tile-chain{font-size:11px;color:var(--sg-text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
685
+ .sg-tile-empty{color:var(--sg-text-muted);font-size:15px;font-weight:600}
686
+ .sg-ft-arrow{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:30px;height:30px;border-radius:999px;background:var(--sg-bg);border:1px solid var(--sg-border);display:flex;align-items:center;justify-content:center;color:var(--sg-text-muted);z-index:1;pointer-events:none}
687
+
688
+ /* token identity: logo circle + tiny chain badge, with a letters fallback */
689
+ .sg-tok{position:relative;flex:0 0 auto;width:36px;height:36px}
690
+ .sg-tok img{width:36px;height:36px;border-radius:999px;display:block;object-fit:cover}
691
+ .sg-tok-fb{width:36px;height:36px;border-radius:999px;background:color-mix(in srgb,var(--sg-accent) 16%,transparent);color:var(--sg-accent);font-size:11px;font-weight:700;display:flex;align-items:center;justify-content:center;letter-spacing:.01em}
692
+ .sg-tok-badge{position:absolute;right:-4px;bottom:-4px;min-width:16px;height:16px;padding:0 2px;border-radius:999px;border:2px solid var(--sg-bg);background:var(--sg-surface);color:var(--sg-text-muted);font-size:7px;font-weight:700;display:flex;align-items:center;justify-content:center;text-transform:uppercase}
693
+ .sg-tok[data-size="sm"],.sg-tok[data-size="sm"] img,.sg-tok[data-size="sm"] .sg-tok-fb{width:28px;height:28px}
694
+ .sg-tok[data-size="sm"] .sg-tok-fb{font-size:9px}
695
+
696
+ /* fiat side (on/off-ramp) */
697
+ .sg-fiat{flex:0 0 auto;width:36px;height:36px;border-radius:999px;background:color-mix(in srgb,var(--sg-accent) 14%,transparent);color:var(--sg-accent);font-weight:700;font-size:15px;display:flex;align-items:center;justify-content:center}
698
+
699
+ /* send panel: inline token + big amount + percent chips */
700
+ .sg-send-row{display:flex;align-items:center;gap:12px}
701
+ .sg-send-row .sg-amount{flex:1 1 auto;min-width:0}
702
+ .sg-send-bal{font-size:11px;color:var(--sg-text-muted);margin-top:6px}
703
+ .sg-pct-row{display:flex;gap:8px;margin-top:12px}
704
+ .sg-pct{flex:1 1 0;padding:7px 0;border-radius:var(--sg-radius-cta);border:1px solid var(--sg-border);background:var(--sg-bg);color:var(--sg-text-muted);font:inherit;font-size:12px;font-weight:600;cursor:pointer;transition:color 120ms ease,border-color 120ms ease}
705
+ .sg-pct:hover:not(:disabled){color:var(--sg-accent);border-color:var(--sg-accent)}
706
+ .sg-pct:disabled{opacity:.45;cursor:not-allowed}
707
+
708
+ /* full-panel token selector (Exchange from / Exchange to) */
709
+ .sg-sel-head{display:flex;align-items:center;margin-bottom:14px}
710
+ .sg-back{width:32px;height:32px;flex:0 0 auto;border:none;border-radius:999px;background:transparent;color:var(--sg-text);cursor:pointer;font:inherit;display:flex;align-items:center;justify-content:center;transition:background 120ms ease}
711
+ .sg-back:hover{background:var(--sg-surface)}
712
+ .sg-sel-title{flex:1 1 auto;text-align:center;font-size:15px;font-weight:600;margin-right:32px}
713
+ .sg-chain-grid{display:grid;grid-template-columns:repeat(5,1fr);gap:8px;margin-bottom:12px}
714
+ .sg-chain-chip{height:44px;border-radius:var(--sg-radius-control);border:1px solid var(--sg-border);background:var(--sg-surface);color:var(--sg-text);display:flex;align-items:center;justify-content:center;cursor:pointer;font:inherit;font-size:10px;font-weight:700;letter-spacing:.02em;transition:border-color 120ms ease,background 120ms ease;overflow:hidden}
715
+ .sg-chain-chip img{width:22px;height:22px;border-radius:999px;display:block}
716
+ .sg-chain-chip:hover{border-color:color-mix(in srgb,var(--sg-accent) 45%,var(--sg-border))}
717
+ .sg-chain-chip[data-selected="true"]{border-color:var(--sg-accent);background:color-mix(in srgb,var(--sg-accent) 10%,var(--sg-surface))}
718
+ .sg-search{position:relative;margin-bottom:10px}
719
+ .sg-search svg{position:absolute;left:12px;top:50%;transform:translateY(-50%);color:var(--sg-text-muted);pointer-events:none}
720
+ .sg-search input{width:100%;padding:11px 12px 11px 38px;background:var(--sg-surface);color:var(--sg-text);border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);font:inherit;font-size:14px;outline:none;transition:border-color 120ms ease}
721
+ .sg-search input:focus{border-color:var(--sg-accent)}
722
+ .sg-toklist{display:flex;flex-direction:column;gap:2px;max-height:320px;overflow-y:auto;margin:0 -6px;padding:0 6px;scrollbar-width:thin}
723
+ .sg-tokrow{display:flex;align-items:center;gap:12px;padding:10px 8px;border:none;border-radius:var(--sg-radius-control);background:transparent;color:var(--sg-text);cursor:pointer;font:inherit;text-align:left;transition:background 120ms ease}
724
+ .sg-tokrow:hover{background:var(--sg-surface)}
725
+ .sg-tokrow-main{flex:1 1 auto;min-width:0}
726
+ .sg-tokrow-sym{display:block;font-size:15px;font-weight:700;line-height:1.2}
727
+ .sg-tokrow-name{display:block;font-size:12px;color:var(--sg-text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
728
+ .sg-tokrow-end{flex:0 0 auto;text-align:right}
729
+ .sg-tokrow-bal{display:block;font-size:13px;font-weight:600;font-variant-numeric:tabular-nums}
730
+ .sg-tokrow-chain{display:block;font-size:11px;color:var(--sg-text-muted)}
731
+ /* funding rows the wallet can't cover (zero / insufficient): greyed, non-interactive, reason hint.
732
+ Mirrors RouteList's data-short dim + warn tone; no hover lift. Theme-aware via --sg-* vars. */
733
+ .sg-tokrow--off,.sg-tokrow[disabled]{opacity:.5;cursor:not-allowed}
734
+ .sg-tokrow--off:hover,.sg-tokrow[disabled]:hover{background:transparent}
735
+ .sg-tokrow--off .sg-tokrow-sym,.sg-tokrow--off .sg-tokrow-name,.sg-tokrow--off .sg-tokrow-bal{color:var(--sg-text-muted)}
736
+ .sg-tokrow-hint{display:block;font-size:11px;font-weight:600;color:var(--sg-danger)}
737
+ .sg-sel-empty{padding:26px 10px;text-align:center;font-size:13px;color:var(--sg-text-muted)}
738
+
739
+ /* wide (duo) layout: main card + receive/routes side card. The collapse is keyed to the WIDGET'S
740
+ OWN available width (container query) \u2014 an embedded widget cannot infer the host layout from the
741
+ viewport. The viewport media query stays as a fallback for engines without container queries. */
742
+ /* width:100% is load-bearing: an inline-size container has NO intrinsic width, so as a flex/grid
743
+ item it would collapse to 0 and hide the whole widget. It fills the host slot; .sg-duo centers. */
744
+ .sg-duo-wrap{container-type:inline-size;width:100%;font-family:var(--sg-font)}
745
+ .sg-duo{display:grid;grid-template-columns:minmax(0,400px) minmax(0,380px);gap:18px;align-items:start;justify-content:center;font-family:var(--sg-font)}
746
+ @container (max-width:840px){.sg-duo{grid-template-columns:minmax(0,400px)}}
747
+ @media (max-width:920px){.sg-duo{grid-template-columns:minmax(0,400px)}}
748
+ .sg-side-title{font-size:15px;font-weight:600;letter-spacing:-0.01em;margin-bottom:14px}
749
+ .sg-noroutes{padding:34px 14px;text-align:center}
750
+ .sg-noroutes-icon{display:inline-flex;align-items:center;justify-content:center;width:44px;height:44px;border-radius:999px;background:var(--sg-surface);color:var(--sg-text-muted);margin-bottom:12px}
751
+ .sg-noroutes-title{font-size:16px;font-weight:700;margin-bottom:8px}
752
+ .sg-noroutes-sub{font-size:13px;color:var(--sg-text-muted);line-height:1.5}
753
+ .sg-meta{display:flex;flex-direction:column;gap:0;margin-top:10px}
754
+ .sg-meta-row{display:flex;align-items:center;justify-content:space-between;padding:9px 0;border-bottom:1px solid var(--sg-border);font-size:13px}
755
+ .sg-meta-row:last-child{border-bottom:none}
756
+ .sg-meta-row b{font-weight:600;font-variant-numeric:tabular-nums}
757
+ .sg-meta-label{color:var(--sg-text-muted)}
758
+ .sg-recv-amt{font-size:28px;font-weight:700;font-variant-numeric:tabular-nums;letter-spacing:-0.01em}
759
+ .sg-recv-sub{font-size:12px;color:var(--sg-text-muted);margin-top:2px}
760
+
761
+ /* head tools: history entry point beside the wallet pill / brand chip */
762
+ .sg-head-tools{display:flex;align-items:center;gap:8px}
763
+ .sg-hist{width:32px;height:32px;flex:0 0 auto;border:1px solid var(--sg-border);border-radius:999px;background:transparent;color:var(--sg-text-muted);cursor:pointer;font:inherit;display:flex;align-items:center;justify-content:center;transition:color 120ms ease,border-color 120ms ease}
764
+ .sg-hist:hover{color:var(--sg-accent);border-color:var(--sg-accent)}
765
+
766
+ /* transaction detail: copyable hash row (no external links \u2014 everything stays in-widget) */
767
+ .sg-txd-hash{display:flex;align-items:center;gap:8px;margin-top:12px;font-size:13px}
768
+ .sg-txd-hash .sg-mono{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
769
+ .sg-copy{display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;width:26px;height:26px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);background:transparent;color:var(--sg-text-muted);cursor:pointer;transition:color 120ms ease,border-color 120ms ease}
770
+ .sg-copy:hover{color:var(--sg-accent);border-color:var(--sg-accent)}
771
+
772
+ @media (prefers-reduced-motion:reduce){.sg-widget *{transition:none!important;animation:none!important}.sg-widget .sg-spinner{display:none!important}.sg-widget .sg-rm-dot{display:inline-block}}
773
+
774
+ /* \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
775
+ ZeroDelta Link \u2014 the "pill" variant (PaymentIsland). A collapsed express-checkout button that
776
+ morphs in place (Apple Dynamic-Island style) into a compact 1-click card. Everything lives on the
777
+ .sg-island root, which carries the --sg-* vars inline (the pill renders OUTSIDE .sg-widget, so it
778
+ cannot inherit vars from there \u2014 see PaymentIsland). Accent-led throughout; never a green surface.
779
+ \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 */
780
+
781
+ /* sr-only utility (none existed) \u2014 every live region + hidden state word uses it. */
782
+ .sg-sr-only{position:absolute!important;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}
783
+
784
+ /* container for the pill's own cell \u2014 densities key off the WIDGET'S width, not the viewport */
785
+ .sg-island-wrap{container-type:inline-size;width:100%;font-family:var(--sg-font);color:var(--sg-text)}
786
+
787
+ /* morph root \u2014 the persistent element the pill and card share. radius/bg/shadow tween on expand */
788
+ .sg-island{position:relative;width:100%;max-width:400px;margin:0 auto;border-radius:var(--sg-radius-cta);background:transparent;transition:border-radius var(--sg-motion-base) var(--sg-ease-in-out),box-shadow var(--sg-motion-base) var(--sg-ease-out-soft),background var(--sg-motion-base) var(--sg-ease-out-soft)}
789
+ .sg-island[data-expanded="true"]{border-radius:var(--sg-radius)}
790
+
791
+ /* collapsed express button \u2014 peer geometry (48px) to Apple Pay / PayPal siblings */
792
+ .sg-express{width:100%;min-height:48px;display:inline-flex;align-items:center;justify-content:center;gap:9px;padding:12px 18px;border:none;border-radius:var(--sg-radius-cta);background:var(--sg-accent);color:var(--sg-accent-text);font:inherit;font-family:var(--sg-font);font-size:15px;font-weight:600;line-height:1;cursor:pointer;box-shadow:0 1px 2px rgba(16,17,22,.06);transition:filter var(--sg-motion-fast) var(--sg-ease-out-soft),transform 60ms ease;animation:sg-fade-in var(--sg-motion-base) var(--sg-ease-out-soft) both}
793
+ .sg-express:hover{filter:brightness(1.06)}
794
+ .sg-express:active{transform:translateY(1px)}
795
+ .sg-express:focus-visible{outline:2px solid var(--sg-accent);outline-offset:2px}
796
+ .sg-island[data-expanded="true"] .sg-express{display:none}
797
+ .sg-express-mark{flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;font-size:15px;line-height:1}
798
+ .sg-express-label{display:inline-flex;align-items:baseline;gap:6px;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
799
+ .sg-express-verb{opacity:.9}
800
+ .sg-express-brand{font-weight:700;letter-spacing:-0.01em}
801
+ .sg-express-dot{opacity:.6}
802
+ .sg-express-amt{font-weight:700;font-variant-numeric:tabular-nums}
803
+ .sg-express-caret{flex:0 0 auto;font-size:11px;opacity:.75;margin-left:2px}
804
+ @container (max-width:210px){.sg-express-dot,.sg-express-amt{display:none}}
805
+ @container (max-width:150px){.sg-express-verb,.sg-express-caret{display:none}}
806
+
807
+ /* reveal animator \u2014 grid-rows 0fr\u21921fr height morph; inner clips; body holds the card */
808
+ .sg-island-reveal{display:grid;grid-template-rows:0fr;transition:grid-template-rows var(--sg-motion-base) var(--sg-ease-out-soft)}
809
+ .sg-island[data-expanded="true"] .sg-island-reveal{grid-template-rows:1fr}
810
+ .sg-island-reveal-inner{min-height:0;overflow:hidden}
811
+ .sg-island-body{animation:sg-fade-in-up var(--sg-motion-base) var(--sg-ease-out-soft) both}
812
+
813
+ /* compact card overrides for the expanded island (reuses the .sg-widget shell) */
814
+ .sg-widget[data-sg-express]{padding:16px;max-width:380px;box-shadow:0 1px 2px rgba(16,17,22,.05),0 12px 32px rgba(16,17,22,.10)}
815
+ .sg-widget[data-sg-express] .sg-head{margin-bottom:12px}
816
+ .sg-widget[data-sg-express] .sg-anchor{font-size:24px}
817
+ .sg-widget[data-sg-express] .sg-foot{margin-top:12px}
818
+ :root[data-theme="dark"] .sg-widget[data-sg-express],.sg-widget[data-sg-express][data-sg-mode="dark"]{box-shadow:0 12px 32px rgba(0,0,0,.5)}
819
+
820
+ /* brand mark + the "\u2026" menu in the head */
821
+ .sg-link-brand{display:inline-flex;align-items:center;gap:7px;min-width:0}
822
+ .sg-link-mono{flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center;width:22px;height:22px}
823
+ .sg-link-word{font-size:14px;font-weight:700;letter-spacing:-0.01em;color:var(--sg-text)}
824
+ .sg-link-menu-wrap{position:relative;display:inline-flex}
825
+ .sg-link-menu-btn{width:30px;height:30px;flex:0 0 auto;border:1px solid var(--sg-border);border-radius:999px;background:transparent;color:var(--sg-text-muted);cursor:pointer;font:inherit;display:flex;align-items:center;justify-content:center;letter-spacing:1px;transition:color var(--sg-motion-fast) var(--sg-ease-out-soft),border-color var(--sg-motion-fast) var(--sg-ease-out-soft)}
826
+ .sg-link-menu-btn:hover{color:var(--sg-accent);border-color:var(--sg-accent)}
827
+ .sg-link-menu{position:absolute;top:36px;right:0;z-index:20;min-width:196px;padding:6px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);background:var(--sg-bg);box-shadow:0 8px 24px rgba(16,17,22,.14);animation:sg-menu-in var(--sg-motion-fast) var(--sg-ease-out-soft) both}
828
+ .sg-link-menu-item{width:100%;display:block;padding:9px 10px;border:none;border-radius:8px;background:transparent;color:var(--sg-text);font:inherit;font-size:13px;text-align:left;cursor:pointer;transition:background var(--sg-motion-fast) var(--sg-ease-out-soft)}
829
+ .sg-link-menu-item:hover,.sg-link-menu-item:focus-visible{background:var(--sg-surface);outline:none}
830
+ .sg-link-menu-item[data-tone="danger"]{color:var(--sg-danger)}
831
+ .sg-link-menu-sep{height:1px;margin:5px 2px;background:var(--sg-border)}
832
+
833
+ /* identity line (wallet + optional saved email) */
834
+ .sg-link-id{display:flex;align-items:center;gap:10px;padding:11px 12px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);background:var(--sg-surface)}
835
+ .sg-link-id-icon{flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center;width:30px;height:30px;border-radius:999px;background:color-mix(in srgb,var(--sg-accent) 14%,transparent);color:var(--sg-accent)}
836
+ .sg-link-id-text{min-width:0;flex:1 1 auto;display:flex;flex-direction:column;line-height:1.25}
837
+ .sg-link-id-primary{font-size:13px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
838
+ .sg-link-id-secondary{font-size:11px;color:var(--sg-text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
839
+
840
+ /* method row \u2014 horizontal TokenTile variant ("Pay with \u2022\u2022\u2022\u2022 \u2304") */
841
+ .sg-tile--row{flex-direction:row;align-items:center;gap:12px;padding:12px 14px}
842
+ .sg-tile--row .sg-tile-label{flex:0 0 auto;font-size:12px;color:var(--sg-text-muted)}
843
+ .sg-tile-rowmain{flex:1 1 auto;display:flex;align-items:center;gap:10px;min-width:0;justify-content:flex-end}
844
+ .sg-tile-chev{flex:0 0 auto;color:var(--sg-text-muted);display:inline-flex;align-items:center;transition:transform var(--sg-motion-fast) var(--sg-ease-out-soft)}
845
+ .sg-tile--row:hover:not(:disabled) .sg-tile-chev{color:var(--sg-accent);transform:translateX(1px)}
846
+
847
+ /* funding-picker opt-in ("remember me" / save-email) */
848
+ .sg-remember{margin-top:12px;padding:12px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);background:var(--sg-surface)}
849
+ .sg-remember-top{display:flex;align-items:flex-start;gap:10px}
850
+ .sg-remember-copy{min-width:0}
851
+ .sg-remember-label{font-size:13px;font-weight:600}
852
+ .sg-remember-sub{font-size:11px;color:var(--sg-text-muted);margin-top:2px;line-height:1.4}
853
+ .sg-remember-body{margin-top:10px}
854
+ .sg-check{width:18px;height:18px;flex:0 0 auto;accent-color:var(--sg-accent);cursor:pointer}
855
+
856
+ /* settled receipt (accent-led, never a loud green surface) */
857
+ .sg-receipt{margin-top:14px;padding:18px;border-radius:var(--sg-radius-control);background:color-mix(in srgb,var(--sg-accent) 8%,transparent);text-align:center;animation:sg-settle-flash var(--sg-motion-slow) var(--sg-ease-out-soft) both}
858
+ .sg-receipt-eyebrow{font-size:11px;font-weight:700;text-transform:uppercase;letter-spacing:.08em;color:var(--sg-accent)}
859
+ .sg-settle-disc{position:relative;width:44px;height:44px;margin:6px auto 8px;border-radius:999px;background:var(--sg-accent);color:var(--sg-accent-text);display:inline-flex;align-items:center;justify-content:center;animation:sg-settle-pop var(--sg-motion-slow) var(--sg-ease-spring) both}
860
+ .sg-settle-disc::after{content:"";position:absolute;inset:-6px;border-radius:999px;border:2px solid color-mix(in srgb,var(--sg-accent) 45%,transparent);opacity:0;animation:sg-settle-ring var(--sg-motion-deliberate) var(--sg-ease-out-soft) both}
861
+ .sg-settle-disc[data-pending="true"]{background:var(--sg-surface);color:var(--sg-text-muted);animation:none}
862
+ .sg-settle-disc[data-pending="true"]::after{display:none}
863
+ .sg-receipt-amt{font-size:22px;font-weight:700;font-variant-numeric:tabular-nums}
864
+ .sg-receipt-sub{font-size:12px;color:var(--sg-text-muted);margin-top:3px}
865
+ .sg-link-alt{width:100%;margin-top:10px;padding:10px;border:none;background:transparent;color:var(--sg-text-muted);font:inherit;font-size:13px;cursor:pointer;border-radius:var(--sg-radius-control);transition:color var(--sg-motion-fast) var(--sg-ease-out-soft)}
866
+ .sg-link-alt:hover{color:var(--sg-accent)}
867
+
868
+ /* honest coming-soon inside the island (neutral \u2014 no orange token exists, no quote implied) */
869
+ .sg-soonpanel{margin-top:12px;padding:16px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);background:var(--sg-surface);text-align:center}
870
+ .sg-soonpanel-title{font-size:14px;font-weight:700;margin-bottom:6px}
871
+ .sg-soonpanel-sub{font-size:12px;color:var(--sg-text-muted);line-height:1.45}
872
+
873
+ /* compact merchant-receives anchor + click-to-expand "Details" disclosure (merchant-configured;
874
+ the payer never edits it). Reveal mirrors the island's grid-rows morph; reduced-motion covered by
875
+ the .sg-island guard below (it disables transitions on .sg-island *). */
876
+ .sg-merch-head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px}
877
+ .sg-merch-lead{min-width:0}
878
+ /* bank payout destination (settlement="bank") \u2014 sits in the same anchor slot as the stablecoin
879
+ amount so the two settlement modes share one layout. */
880
+ .sg-bank{display:flex;align-items:center;gap:10px;margin-top:2px;min-width:0}
881
+ .sg-bank-icon{flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center;width:32px;height:32px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);color:var(--sg-text-muted)}
882
+ .sg-bank-text{display:flex;flex-direction:column;min-width:0}
883
+ .sg-bank-name{font-size:16px;font-weight:700;color:var(--sg-text);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
884
+ .sg-bank-cur{font-size:12px;color:var(--sg-text-muted)}
885
+ .sg-details-toggle{flex:0 0 auto;display:inline-flex;align-items:center;gap:4px;padding:5px 10px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-cta);background:transparent;color:var(--sg-text-muted);font:inherit;font-size:12px;font-weight:600;cursor:pointer;white-space:nowrap;transition:color var(--sg-motion-fast) var(--sg-ease-out-soft),border-color var(--sg-motion-fast) var(--sg-ease-out-soft)}
886
+ .sg-details-toggle:hover{color:var(--sg-accent);border-color:var(--sg-accent)}
887
+ .sg-details-chev{display:inline-flex;font-size:11px;line-height:1;transition:transform var(--sg-motion-fast) var(--sg-ease-out-soft)}
888
+ .sg-details-toggle[data-open="true"] .sg-details-chev{transform:rotate(180deg)}
889
+ .sg-details-reveal{display:grid;grid-template-rows:0fr;transition:grid-template-rows var(--sg-motion-base) var(--sg-ease-out-soft)}
890
+ .sg-details-reveal[data-open="true"]{grid-template-rows:1fr}
891
+ .sg-details-reveal-inner{min-height:0;overflow:hidden}
892
+ .sg-details-body{margin-top:12px;padding-top:12px;border-top:1px solid var(--sg-border)}
893
+ .sg-details-row{display:flex;align-items:baseline;justify-content:space-between;gap:12px;padding:4px 0;font-size:12px}
894
+ .sg-details-k{flex:0 0 auto;color:var(--sg-text-muted)}
895
+ .sg-details-v{min-width:0;text-align:right;color:var(--sg-text)}
896
+ .sg-details-addr{word-break:break-all;font-size:11px}
897
+ .sg-details-note{margin-top:8px;font-size:11px;color:var(--sg-text-muted);line-height:1.45}
898
+
899
+ /* express-card compaction for the 5-tab method selector (already overflow-x:auto for narrow cells) */
900
+ .sg-widget[data-sg-express] .sg-tabs{margin:12px 0 8px}
901
+ .sg-widget[data-sg-express] .sg-tab{padding:6px 10px;font-size:12px}
902
+
903
+ /* step-done "verify" verdict word under the ticker */
904
+ .sg-step-verdict{margin-top:6px;font-size:12px;color:var(--sg-text-muted)}
905
+ .sg-steps li[data-state="error"] span{color:var(--sg-danger)}
906
+
907
+ /* static accent dot shown ONLY under reduced motion (a frozen spinner ring reads as broken) */
908
+ .sg-rm-dot{display:none;width:8px;height:8px;border-radius:999px;background:var(--sg-accent);vertical-align:-1px}
909
+
910
+ /* pill-face state tint while paying / settled (collapsed mid-flight) */
911
+ .sg-island[data-status="submitting"] .sg-express{filter:none}
912
+
913
+ @keyframes sg-fade-in{from{opacity:0}to{opacity:1}}
914
+ @keyframes sg-fade-in-up{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:translateY(0)}}
915
+ @keyframes sg-scale-in{from{opacity:0;transform:scale(.96)}to{opacity:1;transform:scale(1)}}
916
+ @keyframes sg-tick-pop{0%{transform:scale(.6);opacity:0}60%{transform:scale(1.12)}100%{transform:scale(1);opacity:1}}
917
+ @keyframes sg-settle-flash{from{opacity:0;transform:translateY(4px)}to{opacity:1;transform:translateY(0)}}
918
+ @keyframes sg-settle-pop{0%{transform:scale(.7);opacity:0}55%{transform:scale(1.08)}100%{transform:scale(1);opacity:1}}
919
+ @keyframes sg-settle-ring{0%{transform:scale(.85);opacity:.8}100%{transform:scale(1.25);opacity:0}}
920
+ @keyframes sg-menu-in{from{opacity:0;transform:translateY(-4px) scale(.98)}to{opacity:1;transform:translateY(0) scale(1)}}
921
+
922
+ /* Second reduced-motion guard \u2014 the existing guard only matches .sg-widget *; the pill lives on
923
+ .sg-island, OUTSIDE .sg-widget, so it needs its own. Also hides spinners (a frozen ring looks
924
+ broken) and shows the static accent dot instead; the label + live region carry the state. */
925
+ @media (prefers-reduced-motion:reduce){
926
+ .sg-island,.sg-island *{transition:none!important;animation:none!important}
927
+ .sg-island-reveal,.sg-details-reveal{transition:none!important}
928
+ .sg-island .sg-spinner{display:none!important}
929
+ .sg-island .sg-rm-dot{display:inline-block}
930
+ }
931
+ `;
932
+ var injected = false;
933
+ function injectStyles() {
934
+ if (injected || typeof document === "undefined") return;
935
+ if (document.getElementById("stablegenie-widget-styles")) {
936
+ injected = true;
937
+ return;
938
+ }
939
+ const style = document.createElement("style");
940
+ style.id = "stablegenie-widget-styles";
941
+ style.textContent = WIDGET_CSS;
942
+ document.head.appendChild(style);
943
+ injected = true;
944
+ }
945
+
946
+ // src/react/theme.ts
947
+ var MOTION = {
948
+ motionFast: "160ms",
949
+ motionBase: "220ms",
950
+ motionSlow: "320ms",
951
+ motionDeliberate: "480ms",
952
+ easeOutSoft: "cubic-bezier(0.22,0.61,0.36,1)",
953
+ easeInOut: "cubic-bezier(0.4,0,0.2,1)",
954
+ easeSpring: "cubic-bezier(0.34,1.56,0.64,1)"
955
+ };
956
+ var lightTheme = {
957
+ mode: "light",
958
+ accent: "#4358e1",
959
+ accentText: "#ffffff",
960
+ bg: "#ffffff",
961
+ surface: "#f7f8fc",
962
+ border: "#e6e8f0",
963
+ text: "#0e1116",
964
+ textMuted: "#6b7280",
965
+ danger: "#df1b41",
966
+ success: "#12805c",
967
+ radius: "20px",
968
+ radiusControl: "10px",
969
+ radiusCta: "999px",
970
+ font: "'Helvetica Neue', Helvetica, Arial, system-ui, sans-serif",
971
+ ...MOTION
972
+ };
973
+ var darkTheme = {
974
+ mode: "dark",
975
+ accent: "#7b8cff",
976
+ accentText: "#0b0d12",
977
+ bg: "#0e1116",
978
+ surface: "#161a22",
979
+ border: "#252b36",
980
+ text: "#eef1f6",
981
+ textMuted: "#9aa4b2",
982
+ danger: "#ff5470",
983
+ success: "#3ddc97",
984
+ radius: "20px",
985
+ radiusControl: "10px",
986
+ radiusCta: "999px",
987
+ font: "'Helvetica Neue', Helvetica, Arial, system-ui, sans-serif",
988
+ ...MOTION
989
+ };
990
+ function resolveTheme(theme) {
991
+ const base = theme?.mode === "dark" ? darkTheme : lightTheme;
992
+ return { ...base, ...theme };
993
+ }
994
+ function themeToVars(theme) {
995
+ return {
996
+ "--sg-accent": theme.accent,
997
+ "--sg-accent-text": theme.accentText,
998
+ "--sg-bg": theme.bg,
999
+ "--sg-surface": theme.surface,
1000
+ "--sg-border": theme.border,
1001
+ "--sg-text": theme.text,
1002
+ "--sg-text-muted": theme.textMuted,
1003
+ "--sg-danger": theme.danger,
1004
+ "--sg-success": theme.success,
1005
+ "--sg-radius": theme.radius,
1006
+ "--sg-radius-control": theme.radiusControl,
1007
+ "--sg-radius-cta": theme.radiusCta,
1008
+ "--sg-font": theme.font,
1009
+ "--sg-motion-fast": theme.motionFast,
1010
+ "--sg-motion-base": theme.motionBase,
1011
+ "--sg-motion-slow": theme.motionSlow,
1012
+ "--sg-motion-deliberate": theme.motionDeliberate,
1013
+ "--sg-ease-out-soft": theme.easeOutSoft,
1014
+ "--sg-ease-in-out": theme.easeInOut,
1015
+ "--sg-ease-spring": theme.easeSpring
1016
+ };
1017
+ }
1018
+ var PATHS = [
1019
+ {
1020
+ fill: "#8C9BFF",
1021
+ d: "M32.7018 21.9107C32.8383 21.9814 32.9396 22.0498 32.9946 22.0873L32.9968 22.0807C31.8896 20.2754 30.0691 17.2476 27.9119 13.3965C27.9119 13.3965 26.0871 9.95494 25.0965 8.74124C24.1059 7.52755 22.0147 7.52745 21.1342 7.74814C20.2537 7.96883 19.9235 8.1896 19.4833 8.63098C19.043 9.07236 18.8493 9.34467 18.605 10.1811C18.2528 11.3816 19.1377 13.4517 19.7364 14.5971C21.9245 18.788 22.7874 20.0658 24.2358 20.8007C25.7239 21.5576 27.4563 21.3524 28.044 21.3237C29.2899 21.2641 30.582 21.2178 31.9886 21.6503C32.3629 21.7651 32.7018 21.9107 32.7018 21.9107Z"
1022
+ },
1023
+ {
1024
+ fill: "#1A2BA3",
1025
+ d: "M1.80275 22.2019C1.99646 24.0645 2.84175 25.3181 3.59678 25.883C4.35181 26.448 5.40841 26.7128 6.06219 26.7371C9.60841 26.8651 21.1826 26.6687 22.455 26.7636C22.455 26.7636 23.7383 26.8364 24.6298 27.8096C24.9292 28.1385 25.5543 28.9881 25.671 30.1975C25.8141 31.6717 25.0502 33.029 24.0333 33.7903C24.0267 33.7948 24.0222 33.7992 24.0156 33.8036C23.3905 34.267 22.62 34.4877 21.8452 34.4811C16.593 34.4237 14.1232 34.5076 7.73954 34.4392C7.57885 34.4392 5.7364 34.4392 4.98137 34.1942C2.29583 33.3269 1.06973 32.069 0.253067 29.3567C-0.0286943 28.4232 0.0153298 27.4786 0.00432351 27.2072C-0.0727205 25.4019 0.893632 23.1001 1.80715 22.2019H1.80275Z"
1026
+ },
1027
+ {
1028
+ fill: "#4358E1",
1029
+ d: "M24.0443 7.79949C22.3327 7.04654 20.8017 7.19806 19.9133 7.61076C19.0249 8.02346 18.2359 8.86389 17.8683 9.4537C15.8774 12.6548 9.91015 23.4098 9.15356 24.5338C9.15356 24.5338 8.41019 25.679 7.09679 26.0132C6.65401 26.1244 5.58859 26.2752 4.48205 25.7779C3.13275 25.1726 2.36535 23.7907 2.24689 22.4736C2.24658 22.4653 2.2451 22.4591 2.24479 22.4508C2.17594 21.6435 2.39381 20.8237 2.81037 20.1136C5.64479 15.3065 6.88191 12.9905 10.3258 7.14707C10.411 6.99911 11.3879 5.30271 11.9999 4.73001C14.173 2.69101 15.9097 2.19106 18.6856 2.79527C19.6414 3.0026 20.434 3.51541 20.6743 3.641C22.2745 4.47269 23.7505 6.51334 24.042 7.80355L24.0443 7.79949Z"
1030
+ },
1031
+ {
1032
+ fill: "#9962FF",
1033
+ d: "M35.0154 28.2911C35.066 27.6797 35.4688 25.133 33.666 23.1335C33.3534 22.7871 32.8867 22.2751 31.0971 21.9418C28.1959 21.4011 26.3534 22.2442 24.5198 22.3766C25.2814 23.2108 26.3842 24.8682 26.7408 27.4215C26.8707 28.3462 26.9918 29.7344 26.3512 31.3388C25.3562 33.8326 24.3349 34.0422 23.7823 34.3137H23.3905C23.3905 34.3137 29.7279 34.6933 32.7767 32.1642C35.0044 30.317 34.9757 28.7898 35.0154 28.2888V28.2911Z"
1034
+ }
1035
+ ];
1036
+ function BrandMark({ size = 18, mono = false, className, style, title }) {
1037
+ return /* @__PURE__ */ jsxs(
1038
+ "svg",
1039
+ {
1040
+ className,
1041
+ width: size,
1042
+ height: size * 34.4815 / 35.0888,
1043
+ viewBox: "0 0 35.0888 34.4815",
1044
+ fill: "none",
1045
+ xmlns: "http://www.w3.org/2000/svg",
1046
+ style,
1047
+ role: title ? "img" : void 0,
1048
+ "aria-hidden": title ? void 0 : true,
1049
+ "aria-label": title,
1050
+ children: [
1051
+ title ? /* @__PURE__ */ jsx("title", { children: title }) : null,
1052
+ PATHS.map((p) => /* @__PURE__ */ jsx("path", { d: p.d, fill: mono ? "currentColor" : p.fill }, p.d))
1053
+ ]
1054
+ }
1055
+ );
1056
+ }
1057
+ function LockGlyph() {
1058
+ return /* @__PURE__ */ jsxs("svg", { width: "11", height: "11", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
1059
+ /* @__PURE__ */ jsx("rect", { x: "4", y: "11", width: "16", height: "10", rx: "2" }),
1060
+ /* @__PURE__ */ jsx("path", { d: "M8 11V8a4 4 0 0 1 8 0v3" })
1061
+ ] });
1062
+ }
1063
+ function WidgetShell(props) {
1064
+ injectStyles();
1065
+ const resolved = resolveTheme(props.theme);
1066
+ const vars = themeToVars(resolved);
1067
+ const fixed = Number.isFinite(props.heightPx) && props.heightPx > 0;
1068
+ const style = fixed ? { ...vars, height: props.heightPx } : vars;
1069
+ return /* @__PURE__ */ jsxs("div", { className: "sg-widget", "data-sg-mode": resolved.mode, "data-sg-fixed": fixed || void 0, "data-sg-express": props.variant === "express" || void 0, style, children: [
1070
+ /* @__PURE__ */ jsxs("div", { className: "sg-head", children: [
1071
+ props.brandSlot ?? /* @__PURE__ */ jsx("div", { className: "sg-title", children: props.title }),
1072
+ props.walletSlot ?? /* @__PURE__ */ jsxs("div", { className: "sg-brand", children: [
1073
+ /* @__PURE__ */ jsx(BrandMark, { size: 14, className: "sg-brand-mark" }),
1074
+ "ZeroDelta"
1075
+ ] })
1076
+ ] }),
1077
+ /* @__PURE__ */ jsx("div", { className: "sg-body", children: props.children }),
1078
+ /* @__PURE__ */ jsxs("div", { className: "sg-foot", children: [
1079
+ /* @__PURE__ */ jsx(LockGlyph, {}),
1080
+ " Your wallet signs every transaction \xB7 Powered by ZeroDelta"
1081
+ ] })
1082
+ ] });
1083
+ }
1084
+ function shortAddress(a) {
1085
+ if (!a) return "";
1086
+ return `${a.slice(0, 6)}\u2026${a.slice(-4)}`;
1087
+ }
1088
+ var CHAIN_LABELS = {
1089
+ 1: "Ethereum",
1090
+ 10: "Optimism",
1091
+ 130: "Unichain",
1092
+ 146: "Sonic",
1093
+ 8453: "Base",
1094
+ 9745: "Plasma",
1095
+ 57073: "Ink",
1096
+ 42161: "Arbitrum"
1097
+ };
1098
+ var SUPPORTED_CHAINS = [1, 10, 42161, 8453, 57073, 130, 9745, 146];
1099
+ var SUPPORTED_ASSETS2 = ["USDC", "USDT", "USDE", "XAUT"];
1100
+ function Button(props) {
1101
+ const soft = !!props.softDisabled && !props.disabled;
1102
+ const nativeDisabled = props.disabled || props.busy && !props.softDisabled;
1103
+ return (
1104
+ // type="button": a host page may wrap the widget in a <form> — the default type="submit"
1105
+ // would turn any widget CTA into a page-navigating form submission.
1106
+ /* @__PURE__ */ jsxs(
1107
+ "button",
1108
+ {
1109
+ type: "button",
1110
+ className: props.variant === "ghost" ? "sg-btn sg-btn-ghost" : "sg-btn",
1111
+ onClick: soft ? void 0 : props.onClick,
1112
+ disabled: nativeDisabled,
1113
+ "aria-disabled": soft || void 0,
1114
+ "aria-busy": props.busy || void 0,
1115
+ "aria-label": props.ariaLabel,
1116
+ children: [
1117
+ props.busy ? /* @__PURE__ */ jsxs(Fragment, { children: [
1118
+ /* @__PURE__ */ jsx("span", { className: "sg-spinner", "aria-hidden": "true" }),
1119
+ /* @__PURE__ */ jsx("span", { className: "sg-rm-dot", "aria-hidden": "true" })
1120
+ ] }) : null,
1121
+ props.children
1122
+ ]
1123
+ }
1124
+ )
1125
+ );
1126
+ }
1127
+ function Select(props) {
1128
+ return /* @__PURE__ */ jsx("div", { className: "sg-field", children: /* @__PURE__ */ jsxs("label", { className: "sg-label-wrap", children: [
1129
+ props.label ? /* @__PURE__ */ jsx("span", { className: "sg-label", children: props.label }) : null,
1130
+ /* @__PURE__ */ jsx("select", { className: "sg-select", value: props.value, disabled: props.disabled, onChange: (e) => props.onChange(e.target.value), children: props.options.map((o) => /* @__PURE__ */ jsx("option", { value: o.value, children: o.label }, String(o.value))) })
1131
+ ] }) });
1132
+ }
1133
+ function AmountInput(props) {
1134
+ return /* @__PURE__ */ jsx(
1135
+ "input",
1136
+ {
1137
+ className: "sg-input sg-amount sg-mono",
1138
+ inputMode: "decimal",
1139
+ placeholder: props.placeholder ?? "0.0",
1140
+ value: props.value,
1141
+ disabled: props.disabled,
1142
+ onChange: (e) => props.onChange(e.target.value.replace(/[^0-9.,]/g, ""))
1143
+ }
1144
+ );
1145
+ }
1146
+ function StatusPanel(props) {
1147
+ const tone = props.tone ?? "neutral";
1148
+ return (
1149
+ // Errors must be announced assertively; neutral/ok stay polite.
1150
+ /* @__PURE__ */ jsx("div", { className: "sg-status", "data-tone": tone, role: tone === "error" ? "alert" : "status", children: props.children })
1151
+ );
1152
+ }
1153
+ var STEP_STATE_WORD = {
1154
+ pending: "pending",
1155
+ active: "in progress",
1156
+ done: "done",
1157
+ error: "failed"
1158
+ };
1159
+ function StepList(props) {
1160
+ if (!props.steps.length) return null;
1161
+ const rich = props.variant === "rich";
1162
+ const verifyDone = props.steps.some((s) => s.id === "verify" && s.state === "done");
1163
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1164
+ /* @__PURE__ */ jsx("ul", { className: "sg-steps", children: props.steps.map((s) => /* @__PURE__ */ jsxs("li", { "data-state": s.state, children: [
1165
+ /* @__PURE__ */ jsx("span", { className: "sg-dot", "data-state": s.state, "aria-hidden": "true" }),
1166
+ " ",
1167
+ /* @__PURE__ */ jsx("span", { className: s.state === "done" ? "sg-muted" : "", children: s.label }),
1168
+ rich ? /* @__PURE__ */ jsx("span", { className: "sg-sr-only", children: ` \u2014 ${STEP_STATE_WORD[s.state]}` }) : null
1169
+ ] }, s.id)) }),
1170
+ rich && props.verdict && verifyDone ? /* @__PURE__ */ jsx("div", { className: "sg-step-verdict", children: props.verdict.status === "confirmed" ? "Confirmed on-chain \u2014 the merchant has been settled." : props.verdict.status === "mismatch" ? "The submitted transaction did not match the reviewed plan." : "Payment sent \u2014 confirmation is still pending." }) : null
1171
+ ] });
1172
+ }
1173
+ var SHOW_ROADMAP_METHODS = true;
1174
+ var METHODS = [
1175
+ { id: "recommended", label: "Recommended", live: true },
1176
+ { id: "stablecoin", label: "Stablecoin", live: true },
1177
+ { id: "anyasset", label: "Any asset", live: true },
1178
+ { id: "card", label: "Card", live: false },
1179
+ { id: "bank", label: "Bank", live: false }
1180
+ ];
1181
+ function isLiveMethod(m) {
1182
+ return m === "recommended" || m === "stablecoin" || m === "anyasset";
1183
+ }
1184
+ function MethodTabs(props) {
1185
+ const showRoadmap = props.showRoadmap ?? SHOW_ROADMAP_METHODS;
1186
+ return /* @__PURE__ */ jsx("div", { className: "sg-tabs", role: "tablist", "aria-label": "Payment method", children: METHODS.filter((m) => m.live || showRoadmap).map((m) => /* @__PURE__ */ jsxs(
1187
+ "button",
1188
+ {
1189
+ type: "button",
1190
+ className: "sg-tab",
1191
+ role: "tab",
1192
+ "aria-selected": props.value === m.id,
1193
+ "data-selected": props.value === m.id,
1194
+ "aria-disabled": !m.live,
1195
+ style: m.live ? void 0 : { opacity: 0.55 },
1196
+ onClick: () => props.onChange(m.id),
1197
+ children: [
1198
+ m.label,
1199
+ !m.live ? /* @__PURE__ */ jsx("span", { className: "sg-soon", children: "Soon" }) : null
1200
+ ]
1201
+ },
1202
+ m.id
1203
+ )) });
1204
+ }
1205
+ function routeBalanceKey(r) {
1206
+ return `${Number(r.source.chainId)}:${String(r.source.tokenAddress || "").toLowerCase()}`;
1207
+ }
1208
+ function RouteList(props) {
1209
+ const [expanded, setExpanded] = useState(false);
1210
+ const maxVisible = props.maxVisible ?? 5;
1211
+ if (!props.routes.length) return null;
1212
+ const hiddenCount = props.routes.length - maxVisible;
1213
+ const visible = expanded || hiddenCount <= 0 ? props.routes : props.routes.slice(0, maxVisible);
1214
+ return /* @__PURE__ */ jsxs("div", { className: "sg-route", role: "radiogroup", "aria-label": props.ariaLabel ?? "Pay from", children: [
1215
+ visible.map((r) => {
1216
+ const selected = props.selectedId === r.id;
1217
+ const bal = props.balances?.[routeBalanceKey(r)];
1218
+ const short = props.shortIds?.has(r.id) ?? false;
1219
+ const held = props.heldIds?.has(r.id) ?? false;
1220
+ return (
1221
+ // a11y note: a native radio cannot contain the rich
1222
+ // multi-line route summary (token glyphs, chain badges, amounts) this row renders, and
1223
+ // restyling one away from its UA appearance across every host page is worse. The
1224
+ // keyboard contract is implemented explicitly below (Enter/Space + tabIndex).
1225
+ /* @__PURE__ */ jsxs(
1226
+ "div",
1227
+ {
1228
+ className: "sg-route-item",
1229
+ "data-selected": selected,
1230
+ "data-short": short || void 0,
1231
+ "data-held": held || void 0,
1232
+ role: "radio",
1233
+ "aria-checked": selected,
1234
+ tabIndex: 0,
1235
+ onClick: () => props.onSelect(r.id),
1236
+ onKeyDown: (e) => {
1237
+ if (e.key === "Enter" || e.key === " ") {
1238
+ e.preventDefault();
1239
+ props.onSelect(r.id);
1240
+ }
1241
+ },
1242
+ children: [
1243
+ /* @__PURE__ */ jsxs("div", { className: "sg-chip", children: [
1244
+ /* @__PURE__ */ jsx("b", { children: r.source.asset }),
1245
+ /* @__PURE__ */ jsx("span", { children: CHAIN_LABELS[r.source.chainId] || r.source.chainName })
1246
+ ] }),
1247
+ /* @__PURE__ */ jsxs("div", { className: "sg-route-main", children: [
1248
+ /* @__PURE__ */ jsxs("div", { className: "sg-route-amt", children: [
1249
+ r.source.payAmount,
1250
+ " ",
1251
+ r.source.asset
1252
+ ] }),
1253
+ /* @__PURE__ */ jsxs("div", { className: "sg-route-sub", children: [
1254
+ "from ",
1255
+ CHAIN_LABELS[r.source.chainId] || r.source.chainName,
1256
+ " \xB7 ",
1257
+ r.deltaLabel
1258
+ ] })
1259
+ ] }),
1260
+ /* @__PURE__ */ jsxs("div", { className: "sg-route-end", children: [
1261
+ bal ? /* @__PURE__ */ jsxs("span", { className: "sg-bal", children: [
1262
+ "bal ",
1263
+ bal.formatted
1264
+ ] }) : null,
1265
+ short ? /* @__PURE__ */ jsx("span", { className: "sg-badge", "data-tone": "warn", children: "Short" }) : r.state === "DIRECT" ? /* @__PURE__ */ jsx("span", { className: "sg-badge", "data-tone": "ok", children: "Direct" }) : r.recommended ? /* @__PURE__ */ jsx("span", { className: "sg-badge", "data-tone": "accent", children: "Best" }) : null,
1266
+ /* @__PURE__ */ jsx("span", { className: "sg-radio", "aria-hidden": "true" })
1267
+ ] })
1268
+ ]
1269
+ },
1270
+ r.id
1271
+ )
1272
+ );
1273
+ }),
1274
+ hiddenCount > 0 && !expanded ? /* @__PURE__ */ jsxs("button", { type: "button", className: "sg-more", onClick: () => setExpanded(true), children: [
1275
+ "More (",
1276
+ hiddenCount,
1277
+ ")"
1278
+ ] }) : null
1279
+ ] });
1280
+ }
1281
+ var CHAIN_SHORT = {
1282
+ 1: "ETH",
1283
+ 10: "OP",
1284
+ 130: "UNI",
1285
+ 146: "SON",
1286
+ 8453: "BASE",
1287
+ 9745: "PLS",
1288
+ 57073: "INK",
1289
+ 42161: "ARB"
1290
+ };
1291
+ function isHttpsUrl(u) {
1292
+ return typeof u === "string" && /^https:\/\//i.test(u);
1293
+ }
1294
+ function TokenGlyph(props) {
1295
+ const [broken, setBroken] = useState(false);
1296
+ const showImg = isHttpsUrl(props.logoUrl) && !broken;
1297
+ return /* @__PURE__ */ jsxs("span", { className: "sg-tok", "data-size": props.size === "sm" ? "sm" : void 0, children: [
1298
+ showImg ? /* @__PURE__ */ jsx("img", { src: props.logoUrl, alt: "", loading: "lazy", onError: () => setBroken(true) }) : /* @__PURE__ */ jsx("span", { className: "sg-tok-fb", children: props.symbol.slice(0, 4) }),
1299
+ props.chainId ? /* @__PURE__ */ jsx("span", { className: "sg-tok-badge", children: CHAIN_SHORT[props.chainId] || "?" }) : null
1300
+ ] });
1301
+ }
1302
+ function ChevronGlyph() {
1303
+ return /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "m9 18 6-6-6-6" }) });
1304
+ }
1305
+ function TokenTile(props) {
1306
+ const glyph = props.pick ? /* @__PURE__ */ jsxs(Fragment, { children: [
1307
+ /* @__PURE__ */ jsx(TokenGlyph, { symbol: props.pick.symbol, logoUrl: props.token?.logoUrl, chainId: props.pick.chainId }),
1308
+ /* @__PURE__ */ jsxs("span", { style: { minWidth: 0 }, children: [
1309
+ /* @__PURE__ */ jsx("span", { className: "sg-tile-sym", children: props.pick.symbol }),
1310
+ /* @__PURE__ */ jsx("span", { className: "sg-tile-chain", children: CHAIN_LABELS[props.pick.chainId] || `Chain ${props.pick.chainId}` })
1311
+ ] })
1312
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
1313
+ /* @__PURE__ */ jsx("span", { className: "sg-tok", children: /* @__PURE__ */ jsx("span", { className: "sg-tok-fb", children: "?" }) }),
1314
+ /* @__PURE__ */ jsx("span", { className: "sg-tile-empty", children: "Select\u2026" })
1315
+ ] });
1316
+ const ariaLabel = `${props.label}: ${props.pick ? `${props.pick.symbol} on ${CHAIN_LABELS[props.pick.chainId] || props.pick.chainId}` : "select token"}`;
1317
+ if (props.row) {
1318
+ return /* @__PURE__ */ jsxs("button", { type: "button", ref: props.btnRef, className: "sg-tile sg-tile--row", disabled: props.disabled, onClick: props.onClick, "aria-label": ariaLabel, children: [
1319
+ /* @__PURE__ */ jsx("span", { className: "sg-tile-label", children: props.label }),
1320
+ /* @__PURE__ */ jsx("span", { className: "sg-tile-rowmain", children: glyph }),
1321
+ /* @__PURE__ */ jsx("span", { className: "sg-tile-chev", children: /* @__PURE__ */ jsx(ChevronGlyph, {}) })
1322
+ ] });
1323
+ }
1324
+ return /* @__PURE__ */ jsxs("button", { type: "button", ref: props.btnRef, className: "sg-tile", disabled: props.disabled, onClick: props.onClick, "aria-label": ariaLabel, children: [
1325
+ /* @__PURE__ */ jsx("span", { className: "sg-tile-label", children: props.label }),
1326
+ /* @__PURE__ */ jsx("span", { className: "sg-tile-main", children: glyph })
1327
+ ] });
1328
+ }
1329
+ function ChainChip(props) {
1330
+ const [broken, setBroken] = useState(false);
1331
+ const logo = props.chain?.logoUrl;
1332
+ const showImg = isHttpsUrl(logo) && !broken;
1333
+ return /* @__PURE__ */ jsx("button", { type: "button", className: "sg-chain-chip", "data-selected": props.selected, title: props.label, "aria-pressed": props.selected, onClick: props.onClick, children: showImg ? /* @__PURE__ */ jsx("img", { src: logo, alt: props.label, loading: "lazy", onError: () => setBroken(true) }) : props.label });
1334
+ }
1335
+ function SearchGlyph() {
1336
+ return /* @__PURE__ */ jsxs("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", "aria-hidden": "true", children: [
1337
+ /* @__PURE__ */ jsx("circle", { cx: "11", cy: "11", r: "7" }),
1338
+ /* @__PURE__ */ jsx("path", { d: "m20 20-3.5-3.5" })
1339
+ ] });
1340
+ }
1341
+ function BackGlyph() {
1342
+ return /* @__PURE__ */ jsxs("svg", { width: "17", height: "17", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
1343
+ /* @__PURE__ */ jsx("path", { d: "M19 12H5" }),
1344
+ /* @__PURE__ */ jsx("path", { d: "m12 19-7-7 7-7" })
1345
+ ] });
1346
+ }
1347
+ function TokenSelect(props) {
1348
+ const [chainFilter, setChainFilter] = useState(null);
1349
+ const [query, setQuery] = useState("");
1350
+ const rows = useMemo(() => {
1351
+ const q = query.trim().toLowerCase();
1352
+ const filtered = props.tokens.filter((t) => chainFilter == null ? true : Number(t.chainId) === chainFilter).filter((t) => {
1353
+ if (!q) return true;
1354
+ return String(t.symbol || "").toLowerCase().includes(q) || String(t.name || "").toLowerCase().includes(q) || String(t.address || "").toLowerCase().includes(q);
1355
+ });
1356
+ if (!props.balances) return filtered;
1357
+ const balNum = (t) => {
1358
+ const n = Number(props.balances?.[`${Number(t.chainId)}:${String(t.address || "").toLowerCase()}`]?.formatted);
1359
+ return Number.isFinite(n) ? n : 0;
1360
+ };
1361
+ return [...filtered].sort((a, b) => balNum(b) - balNum(a));
1362
+ }, [props.tokens, chainFilter, query, props.balances]);
1363
+ return /* @__PURE__ */ jsxs("div", { children: [
1364
+ /* @__PURE__ */ jsxs("div", { className: "sg-sel-head", children: [
1365
+ /* @__PURE__ */ jsx("button", { type: "button", className: "sg-back", onClick: props.onBack, "aria-label": "Back", children: /* @__PURE__ */ jsx(BackGlyph, {}) }),
1366
+ /* @__PURE__ */ jsx("div", { className: "sg-sel-title", children: props.title })
1367
+ ] }),
1368
+ /* @__PURE__ */ jsxs("div", { className: "sg-chain-grid", role: "group", "aria-label": "Filter by chain", children: [
1369
+ /* @__PURE__ */ jsx(ChainChip, { label: "All", selected: chainFilter == null, onClick: () => setChainFilter(null) }),
1370
+ props.chains.map((c) => /* @__PURE__ */ jsx(
1371
+ ChainChip,
1372
+ {
1373
+ chain: c,
1374
+ label: CHAIN_SHORT[Number(c.chainId)] || String(c.chainId),
1375
+ selected: chainFilter === Number(c.chainId),
1376
+ onClick: () => setChainFilter(Number(c.chainId))
1377
+ },
1378
+ c.chainId
1379
+ ))
1380
+ ] }),
1381
+ /* @__PURE__ */ jsxs("div", { className: "sg-search", children: [
1382
+ /* @__PURE__ */ jsx(SearchGlyph, {}),
1383
+ /* @__PURE__ */ jsx("input", { autoFocus: true, placeholder: "Search by token or address", value: query, onChange: (e) => setQuery(e.target.value), spellCheck: false, "aria-label": "Search by token or address" })
1384
+ ] }),
1385
+ /* @__PURE__ */ jsx("div", { className: "sg-toklist", role: "group", "aria-label": props.title, children: rows.length ? rows.map((t) => {
1386
+ const chainId = Number(t.chainId);
1387
+ const key = `${chainId}:${String(t.address || "").toLowerCase()}`;
1388
+ const bal = props.balances?.[key];
1389
+ const st = props.optionStates?.[key];
1390
+ const disabled = !!st?.disabled;
1391
+ return /* @__PURE__ */ jsxs(
1392
+ "button",
1393
+ {
1394
+ type: "button",
1395
+ className: `sg-tokrow${disabled ? " sg-tokrow--off" : ""}`,
1396
+ disabled,
1397
+ "aria-disabled": disabled || void 0,
1398
+ "data-disabled": disabled || void 0,
1399
+ onClick: disabled ? void 0 : () => props.onPick({ chainId, symbol: t.symbol }),
1400
+ children: [
1401
+ /* @__PURE__ */ jsx(TokenGlyph, { symbol: t.symbol, logoUrl: t.logoUrl, chainId }),
1402
+ /* @__PURE__ */ jsxs("span", { className: "sg-tokrow-main", children: [
1403
+ /* @__PURE__ */ jsx("span", { className: "sg-tokrow-sym", children: t.symbol }),
1404
+ /* @__PURE__ */ jsx("span", { className: "sg-tokrow-name", children: t.name || t.symbol })
1405
+ ] }),
1406
+ /* @__PURE__ */ jsxs("span", { className: "sg-tokrow-end", children: [
1407
+ bal ? /* @__PURE__ */ jsx("span", { className: "sg-tokrow-bal sg-mono", children: bal.formatted }) : null,
1408
+ disabled && st?.hint ? /* @__PURE__ */ jsx("span", { className: "sg-tokrow-hint", children: st.hint }) : null,
1409
+ /* @__PURE__ */ jsx("span", { className: "sg-tokrow-chain", children: CHAIN_LABELS[chainId] || `Chain ${chainId}` })
1410
+ ] })
1411
+ ]
1412
+ },
1413
+ `${chainId}:${t.address}`
1414
+ );
1415
+ }) : /* @__PURE__ */ jsx("div", { className: "sg-sel-empty", children: "No tokens match \u2014 try another chain or search." }) })
1416
+ ] });
1417
+ }
1418
+ function useTxHistory(account) {
1419
+ const [entries, setEntries] = useState(() => readTxHistory(account));
1420
+ useEffect(() => {
1421
+ setEntries(readTxHistory(account));
1422
+ if (typeof window === "undefined" || !account) return;
1423
+ const key = txHistoryKey(account);
1424
+ const onLocal = (e) => {
1425
+ const detail = e.detail;
1426
+ if (!detail?.account || detail.account === account.toLowerCase()) setEntries(readTxHistory(account));
1427
+ };
1428
+ const onStorage = (e) => {
1429
+ if (e.key === key) setEntries(readTxHistory(account));
1430
+ };
1431
+ window.addEventListener(TX_HISTORY_EVENT, onLocal);
1432
+ window.addEventListener("storage", onStorage);
1433
+ return () => {
1434
+ window.removeEventListener(TX_HISTORY_EVENT, onLocal);
1435
+ window.removeEventListener("storage", onStorage);
1436
+ };
1437
+ }, [account]);
1438
+ return entries;
1439
+ }
1440
+ function BackGlyph2() {
1441
+ return /* @__PURE__ */ jsxs("svg", { width: "17", height: "17", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
1442
+ /* @__PURE__ */ jsx("path", { d: "M19 12H5" }),
1443
+ /* @__PURE__ */ jsx("path", { d: "m12 19-7-7 7-7" })
1444
+ ] });
1445
+ }
1446
+ function HistoryGlyph() {
1447
+ return /* @__PURE__ */ jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
1448
+ /* @__PURE__ */ jsx("path", { d: "M3 12a9 9 0 1 0 3-6.7" }),
1449
+ /* @__PURE__ */ jsx("path", { d: "M3 4v5h5" }),
1450
+ /* @__PURE__ */ jsx("path", { d: "M12 8v4l3 2" })
1451
+ ] });
1452
+ }
1453
+ function CopyGlyph() {
1454
+ return /* @__PURE__ */ jsxs("svg", { width: "13", height: "13", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
1455
+ /* @__PURE__ */ jsx("rect", { x: "9", y: "9", width: "12", height: "12", rx: "2" }),
1456
+ /* @__PURE__ */ jsx("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" })
1457
+ ] });
1458
+ }
1459
+ function CheckGlyph() {
1460
+ return /* @__PURE__ */ jsx("svg", { width: "13", height: "13", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" }) });
1461
+ }
1462
+ function HistoryButton(props) {
1463
+ return /* @__PURE__ */ jsx("button", { type: "button", ref: props.btnRef, className: "sg-hist", disabled: props.disabled, onClick: props.onClick, "aria-label": "Transaction history", title: "Transaction history", children: /* @__PURE__ */ jsx(HistoryGlyph, {}) });
1464
+ }
1465
+ function chainLabel(entry) {
1466
+ return entry.chainId != null && CHAIN_LABELS[entry.chainId] || entry.chainName || (entry.chainId != null ? `Chain ${entry.chainId}` : "Unknown chain");
1467
+ }
1468
+ function statusBadge(status) {
1469
+ if (status === "confirmed")
1470
+ return /* @__PURE__ */ jsx("span", { className: "sg-badge", "data-tone": "ok", children: "Confirmed" });
1471
+ if (status === "error")
1472
+ return /* @__PURE__ */ jsx("span", { className: "sg-badge", "data-tone": "warn", children: "Failed" });
1473
+ return /* @__PURE__ */ jsx("span", { className: "sg-badge", children: "Pending" });
1474
+ }
1475
+ function whenLabel(at) {
1476
+ const d = new Date(at);
1477
+ return Number.isNaN(d.getTime()) ? "" : d.toLocaleString();
1478
+ }
1479
+ function logoFor(tokens, symbol, chainId) {
1480
+ if (!tokens?.length) return void 0;
1481
+ const key = symbolKey(symbol);
1482
+ if (!key) return void 0;
1483
+ const sameChain = chainId == null ? void 0 : tokens.find((t) => Number(t.chainId) === chainId && symbolKey(t.symbol) === key);
1484
+ return (sameChain ?? tokens.find((t) => symbolKey(t.symbol) === key))?.logoUrl;
1485
+ }
1486
+ function TxHistoryList(props) {
1487
+ if (!props.entries.length) {
1488
+ return /* @__PURE__ */ jsx("div", { className: "sg-sel-empty", children: "No transactions yet \u2014 activity from this wallet will appear here." });
1489
+ }
1490
+ return /* @__PURE__ */ jsx("section", { className: "sg-toklist", "aria-label": "Transaction history", children: props.entries.map((e) => /* @__PURE__ */ jsxs("button", { type: "button", className: "sg-tokrow", onClick: () => props.onPick(e), children: [
1491
+ /* @__PURE__ */ jsx(TokenGlyph, { symbol: e.fromAsset || e.toAsset || "?", logoUrl: logoFor(props.tokens, e.fromAsset, e.chainId), chainId: e.chainId ?? void 0 }),
1492
+ /* @__PURE__ */ jsxs("span", { className: "sg-tokrow-main", children: [
1493
+ /* @__PURE__ */ jsxs("span", { className: "sg-tokrow-sym sg-mono", children: [
1494
+ e.payAmount,
1495
+ " ",
1496
+ e.fromAsset,
1497
+ " \u2192 ",
1498
+ e.receiveAmount,
1499
+ " ",
1500
+ e.toAsset
1501
+ ] }),
1502
+ /* @__PURE__ */ jsxs("span", { className: "sg-tokrow-name", children: [
1503
+ e.kind === "payment" ? "Payment" : "Swap",
1504
+ " \xB7 ",
1505
+ chainLabel(e),
1506
+ whenLabel(e.at) ? ` \xB7 ${whenLabel(e.at)}` : ""
1507
+ ] })
1508
+ ] }),
1509
+ /* @__PURE__ */ jsx("span", { className: "sg-tokrow-end", children: statusBadge(e.status) })
1510
+ ] }, `${e.hash}:${e.at}`)) });
1511
+ }
1512
+ function TxDetail(props) {
1513
+ const e = props.entry;
1514
+ const [copied, setCopied] = useState(false);
1515
+ const copyTimer = useRef(null);
1516
+ useEffect(
1517
+ () => () => {
1518
+ if (copyTimer.current) clearTimeout(copyTimer.current);
1519
+ },
1520
+ []
1521
+ );
1522
+ const copyHash = async () => {
1523
+ try {
1524
+ if (!navigator.clipboard?.writeText) return;
1525
+ await navigator.clipboard.writeText(e.hash);
1526
+ setCopied(true);
1527
+ if (copyTimer.current) clearTimeout(copyTimer.current);
1528
+ copyTimer.current = setTimeout(() => setCopied(false), 1500);
1529
+ } catch {
1530
+ }
1531
+ };
1532
+ return /* @__PURE__ */ jsxs("div", { className: "sg-panel", children: [
1533
+ /* @__PURE__ */ jsxs("div", { className: "sg-anchor sg-mono", children: [
1534
+ e.receiveAmount,
1535
+ " ",
1536
+ e.toAsset
1537
+ ] }),
1538
+ /* @__PURE__ */ jsxs("div", { className: "sg-anchor-sub", children: [
1539
+ e.kind === "payment" ? "Payment" : "Swap",
1540
+ whenLabel(e.at) ? ` \xB7 ${whenLabel(e.at)}` : ""
1541
+ ] }),
1542
+ /* @__PURE__ */ jsxs("div", { className: "sg-meta", children: [
1543
+ /* @__PURE__ */ jsxs("div", { className: "sg-meta-row", children: [
1544
+ /* @__PURE__ */ jsx("span", { className: "sg-meta-label", children: "Status" }),
1545
+ statusBadge(e.status)
1546
+ ] }),
1547
+ /* @__PURE__ */ jsxs("div", { className: "sg-meta-row", children: [
1548
+ /* @__PURE__ */ jsx("span", { className: "sg-meta-label", children: "You sent" }),
1549
+ /* @__PURE__ */ jsxs("b", { className: "sg-mono", children: [
1550
+ e.payAmount,
1551
+ " ",
1552
+ e.fromAsset
1553
+ ] })
1554
+ ] }),
1555
+ /* @__PURE__ */ jsxs("div", { className: "sg-meta-row", children: [
1556
+ /* @__PURE__ */ jsx("span", { className: "sg-meta-label", children: "Chain" }),
1557
+ /* @__PURE__ */ jsx("b", { children: chainLabel(e) })
1558
+ ] }),
1559
+ e.recipient ? /* @__PURE__ */ jsxs("div", { className: "sg-meta-row", children: [
1560
+ /* @__PURE__ */ jsx("span", { className: "sg-meta-label", children: "Recipient" }),
1561
+ /* @__PURE__ */ jsx("b", { className: "sg-mono", children: shortAddress(e.recipient) })
1562
+ ] }) : null,
1563
+ /* @__PURE__ */ jsxs("div", { className: "sg-meta-row", children: [
1564
+ /* @__PURE__ */ jsx("span", { className: "sg-meta-label", children: "Settlement" }),
1565
+ /* @__PURE__ */ jsx("b", { children: e.settlement === "direct" ? "Direct" : "Escrow" })
1566
+ ] })
1567
+ ] }),
1568
+ /* @__PURE__ */ jsxs("div", { className: "sg-txd-hash", children: [
1569
+ /* @__PURE__ */ jsx("span", { className: "sg-meta-label", children: "Tx hash" }),
1570
+ /* @__PURE__ */ jsx("span", { className: "sg-mono", children: `${e.hash.slice(0, 10)}\u2026${e.hash.slice(-8)}` }),
1571
+ /* @__PURE__ */ jsx("button", { type: "button", className: "sg-copy", onClick: copyHash, "aria-label": copied ? "Copied" : "Copy transaction hash", "aria-live": "polite", title: "Copy transaction hash", children: copied ? /* @__PURE__ */ jsx(CheckGlyph, {}) : /* @__PURE__ */ jsx(CopyGlyph, {}) })
1572
+ ] })
1573
+ ] });
1574
+ }
1575
+ function displayableHistory(entries) {
1576
+ return entries.filter((e) => e.txKind !== "approve");
1577
+ }
1578
+ function TxHistoryPanel(props) {
1579
+ const entries = displayableHistory(useTxHistory(props.account));
1580
+ const [selected, setSelected] = useState(props.initialEntry ?? null);
1581
+ const backRef = useRef(null);
1582
+ useEffect(() => setSelected(props.initialEntry ?? null), [props.initialEntry]);
1583
+ const pick = (entry) => {
1584
+ setSelected(entry);
1585
+ requestAnimationFrame(() => backRef.current?.focus());
1586
+ };
1587
+ return /* @__PURE__ */ jsxs("div", { children: [
1588
+ /* @__PURE__ */ jsxs("div", { className: "sg-sel-head", children: [
1589
+ /* @__PURE__ */ jsx("button", { type: "button", autoFocus: true, ref: backRef, className: "sg-back", onClick: selected ? () => setSelected(null) : props.onBack, "aria-label": "Back", children: /* @__PURE__ */ jsx(BackGlyph2, {}) }),
1590
+ /* @__PURE__ */ jsx("div", { className: "sg-sel-title", children: selected ? "Transaction" : "Transaction history" })
1591
+ ] }),
1592
+ selected ? /* @__PURE__ */ jsx(TxDetail, { entry: selected }) : /* @__PURE__ */ jsx(TxHistoryList, { entries, tokens: props.tokens, onPick: pick })
1593
+ ] });
1594
+ }
1595
+ var IDENTITY_KEY_PREFIX = "sg:link:v1:";
1596
+ var LEGACY_IDENTITY_KEY = "zd-link-identity";
1597
+ var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
1598
+ var EMAIL_RE = /^[^\s@]{1,64}@[^\s@]{1,190}$/;
1599
+ function identityKey(account) {
1600
+ return `${IDENTITY_KEY_PREFIX}${account.toLowerCase()}`;
1601
+ }
1602
+ function storage() {
1603
+ try {
1604
+ return typeof window !== "undefined" ? window.localStorage : null;
1605
+ } catch {
1606
+ return null;
1607
+ }
1608
+ }
1609
+ function parseIdentity(raw) {
1610
+ if (!raw) return null;
1611
+ try {
1612
+ const p = JSON.parse(raw);
1613
+ if (!p || typeof p !== "object") return null;
1614
+ const walletAddress = typeof p.walletAddress === "string" ? p.walletAddress : "";
1615
+ if (!ADDRESS_RE.test(walletAddress)) return null;
1616
+ const preferredChainId = Number(p.preferredChainId);
1617
+ if (!Number.isFinite(preferredChainId) || !SUPPORTED_CHAIN_IDS.has(preferredChainId)) return null;
1618
+ const preferredAsset = String(p.preferredAsset || "").toUpperCase();
1619
+ if (!SUPPORTED_ASSETS.has(preferredAsset)) return null;
1620
+ const email = typeof p.email === "string" && EMAIL_RE.test(p.email) ? p.email : void 0;
1621
+ const lastUsedAt = typeof p.lastUsedAt === "string" ? p.lastUsedAt.slice(0, 40) : "";
1622
+ return { email, walletAddress, preferredAsset, preferredChainId, lastUsedAt };
1623
+ } catch {
1624
+ return null;
1625
+ }
1626
+ }
1627
+ function loadIdentity(account) {
1628
+ const s = storage();
1629
+ if (!s || !account || !ADDRESS_RE.test(account)) return null;
1630
+ try {
1631
+ return parseIdentity(s.getItem(identityKey(account)));
1632
+ } catch {
1633
+ return null;
1634
+ }
1635
+ }
1636
+ function saveIdentity(id) {
1637
+ const s = storage();
1638
+ if (!s || !ADDRESS_RE.test(id.walletAddress)) return;
1639
+ try {
1640
+ s.setItem(identityKey(id.walletAddress), JSON.stringify(id));
1641
+ s.removeItem(LEGACY_IDENTITY_KEY);
1642
+ } catch {
1643
+ }
1644
+ }
1645
+ function forgetIdentity(account) {
1646
+ const s = storage();
1647
+ if (!s) return;
1648
+ try {
1649
+ if (account && ADDRESS_RE.test(account)) s.removeItem(identityKey(account));
1650
+ s.removeItem(LEGACY_IDENTITY_KEY);
1651
+ } catch {
1652
+ }
1653
+ }
1654
+ var addrEq = (a, b) => String(a || "").toLowerCase() === String(b || "").toLowerCase();
1655
+ var chainName = (id) => id != null ? CHAIN_LABELS[id] || `Chain ${id}` : "";
1656
+ var STABLES = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE"]);
1657
+ function MerchantReceives(props) {
1658
+ const [open, setOpen] = useState(false);
1659
+ const bodyId = useId();
1660
+ const hasDetails = Boolean(props.recipient);
1661
+ return /* @__PURE__ */ jsxs("div", { className: "sg-panel sg-merch", children: [
1662
+ /* @__PURE__ */ jsxs("div", { className: "sg-merch-head", children: [
1663
+ /* @__PURE__ */ jsxs("div", { className: "sg-merch-lead", children: [
1664
+ /* @__PURE__ */ jsx("div", { className: "sg-label", children: "Merchant receives exactly" }),
1665
+ /* @__PURE__ */ jsxs("div", { className: "sg-anchor sg-mono", children: [
1666
+ props.amount,
1667
+ " ",
1668
+ props.asset
1669
+ ] })
1670
+ ] }),
1671
+ hasDetails ? /* @__PURE__ */ jsxs(
1672
+ "button",
1673
+ {
1674
+ type: "button",
1675
+ className: "sg-details-toggle",
1676
+ "data-open": open,
1677
+ "aria-expanded": open,
1678
+ "aria-controls": bodyId,
1679
+ onClick: () => setOpen((o) => !o),
1680
+ children: [
1681
+ "Details",
1682
+ /* @__PURE__ */ jsx("span", { className: "sg-details-chev", "aria-hidden": "true", children: "\u2304" })
1683
+ ]
1684
+ }
1685
+ ) : null
1686
+ ] }),
1687
+ hasDetails ? /* @__PURE__ */ jsx("div", { className: "sg-details-reveal", "data-open": open, children: /* @__PURE__ */ jsx("div", { className: "sg-details-reveal-inner", children: /* @__PURE__ */ jsxs("div", { className: "sg-details-body", id: bodyId, children: [
1688
+ /* @__PURE__ */ jsxs("div", { className: "sg-details-row", children: [
1689
+ /* @__PURE__ */ jsx("span", { className: "sg-details-k", children: "Network" }),
1690
+ /* @__PURE__ */ jsx("span", { className: "sg-details-v", children: chainName(props.chainId) })
1691
+ ] }),
1692
+ /* @__PURE__ */ jsxs("div", { className: "sg-details-row", children: [
1693
+ /* @__PURE__ */ jsx("span", { className: "sg-details-k", children: "Recipient" }),
1694
+ /* @__PURE__ */ jsx("span", { className: "sg-details-v sg-mono sg-details-addr", children: props.recipient })
1695
+ ] }),
1696
+ /* @__PURE__ */ jsxs("div", { className: "sg-details-note", children: [
1697
+ "Settled like a card \u2014 the merchant always receives exactly ",
1698
+ props.amount,
1699
+ " ",
1700
+ props.asset,
1701
+ ". You pay a little more to cover the network cost."
1702
+ ] })
1703
+ ] }) }) }) : null
1704
+ ] });
1705
+ }
1706
+ function BankGlyph() {
1707
+ return /* @__PURE__ */ jsx("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M3 10h18M5 10v8M10 10v8M14 10v8M19 10v8M3 19h18M12 3 3 8h18Z" }) });
1708
+ }
1709
+ function MerchantBankPayout(props) {
1710
+ const bankName = props.account?.bankName?.trim() || "Bank account";
1711
+ const last4 = props.account?.last4?.trim();
1712
+ const currency = props.account?.currency?.trim();
1713
+ return /* @__PURE__ */ jsx("div", { className: "sg-panel sg-merch", children: /* @__PURE__ */ jsx("div", { className: "sg-merch-head", children: /* @__PURE__ */ jsxs("div", { className: "sg-merch-lead", children: [
1714
+ /* @__PURE__ */ jsx("div", { className: "sg-label", children: "Merchant receives" }),
1715
+ /* @__PURE__ */ jsxs("div", { className: "sg-bank", children: [
1716
+ /* @__PURE__ */ jsx("span", { className: "sg-bank-icon", "aria-hidden": "true", children: /* @__PURE__ */ jsx(BankGlyph, {}) }),
1717
+ /* @__PURE__ */ jsxs("span", { className: "sg-bank-text", children: [
1718
+ /* @__PURE__ */ jsxs("span", { className: "sg-bank-name", children: [
1719
+ bankName,
1720
+ last4 ? /* @__PURE__ */ jsxs("span", { className: "sg-mono", children: [
1721
+ " \xB7\xB7\xB7\xB7",
1722
+ last4
1723
+ ] }) : null
1724
+ ] }),
1725
+ currency ? /* @__PURE__ */ jsxs("span", { className: "sg-bank-cur", children: [
1726
+ "Paid out in ",
1727
+ currency
1728
+ ] }) : null
1729
+ ] })
1730
+ ] })
1731
+ ] }) }) });
1732
+ }
1733
+ function CheckGlyph2() {
1734
+ return /* @__PURE__ */ jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "3", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" }) });
1735
+ }
1736
+ function ArrowGlyph() {
1737
+ return /* @__PURE__ */ jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
1738
+ /* @__PURE__ */ jsx("path", { d: "M5 12h14" }),
1739
+ /* @__PURE__ */ jsx("path", { d: "m13 6 6 6-6 6" })
1740
+ ] });
1741
+ }
1742
+ function ClockGlyph() {
1743
+ return /* @__PURE__ */ jsxs("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
1744
+ /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "9" }),
1745
+ /* @__PURE__ */ jsx("path", { d: "M12 7v5l3 2" })
1746
+ ] });
1747
+ }
1748
+ function WalletGlyph() {
1749
+ return /* @__PURE__ */ jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
1750
+ /* @__PURE__ */ jsx("rect", { x: "3", y: "6", width: "18", height: "13", rx: "2" }),
1751
+ /* @__PURE__ */ jsx("path", { d: "M16 12h.01M3 9h18" })
1752
+ ] });
1753
+ }
1754
+ function LinkMenu(props) {
1755
+ const [open, setOpen] = useState(false);
1756
+ const [active, setActive] = useState(0);
1757
+ const btnRef = useRef(null);
1758
+ const menuRef = useRef(null);
1759
+ const itemRefs = useRef([]);
1760
+ const menuId = useId();
1761
+ const close = (restoreFocus = true) => {
1762
+ setOpen(false);
1763
+ if (restoreFocus) requestAnimationFrame(() => btnRef.current?.focus());
1764
+ };
1765
+ useEffect(() => {
1766
+ if (!open) return;
1767
+ setActive(0);
1768
+ const onDoc = (e) => {
1769
+ if (!menuRef.current?.contains(e.target) && !btnRef.current?.contains(e.target)) setOpen(false);
1770
+ };
1771
+ document.addEventListener("mousedown", onDoc);
1772
+ requestAnimationFrame(() => itemRefs.current[0]?.focus());
1773
+ return () => document.removeEventListener("mousedown", onDoc);
1774
+ }, [open]);
1775
+ const focusAt = (i) => {
1776
+ const n = props.items.length;
1777
+ const idx = (i % n + n) % n;
1778
+ setActive(idx);
1779
+ itemRefs.current[idx]?.focus();
1780
+ };
1781
+ return /* @__PURE__ */ jsxs("div", { className: "sg-link-menu-wrap", children: [
1782
+ /* @__PURE__ */ jsx(
1783
+ "button",
1784
+ {
1785
+ ref: btnRef,
1786
+ type: "button",
1787
+ className: "sg-link-menu-btn",
1788
+ "aria-haspopup": "menu",
1789
+ "aria-expanded": open,
1790
+ "aria-controls": open ? menuId : void 0,
1791
+ "aria-label": "ZeroDelta Link options",
1792
+ onClick: () => setOpen((o) => !o),
1793
+ children: "\u22EF"
1794
+ }
1795
+ ),
1796
+ open ? /* @__PURE__ */ jsx(
1797
+ "div",
1798
+ {
1799
+ ref: menuRef,
1800
+ id: menuId,
1801
+ className: "sg-link-menu",
1802
+ role: "menu",
1803
+ "aria-label": "ZeroDelta Link options",
1804
+ onKeyDown: (e) => {
1805
+ if (e.key === "Escape") {
1806
+ e.preventDefault();
1807
+ close();
1808
+ } else if (e.key === "Tab") {
1809
+ close(false);
1810
+ }
1811
+ },
1812
+ children: props.items.map((it, i) => /* @__PURE__ */ jsx(
1813
+ "button",
1814
+ {
1815
+ ref: (el) => {
1816
+ itemRefs.current[i] = el;
1817
+ },
1818
+ type: "button",
1819
+ role: "menuitem",
1820
+ tabIndex: i === active ? 0 : -1,
1821
+ className: "sg-link-menu-item",
1822
+ "data-tone": it.tone,
1823
+ onClick: () => {
1824
+ close(!it.collapses);
1825
+ it.onSelect();
1826
+ },
1827
+ onKeyDown: (e) => {
1828
+ if (e.key === "ArrowDown") {
1829
+ e.preventDefault();
1830
+ focusAt(i + 1);
1831
+ } else if (e.key === "ArrowUp") {
1832
+ e.preventDefault();
1833
+ focusAt(i - 1);
1834
+ } else if (e.key === "Home") {
1835
+ e.preventDefault();
1836
+ focusAt(0);
1837
+ } else if (e.key === "End") {
1838
+ e.preventDefault();
1839
+ focusAt(props.items.length - 1);
1840
+ }
1841
+ },
1842
+ children: it.label
1843
+ },
1844
+ it.label
1845
+ ))
1846
+ }
1847
+ ) : null
1848
+ ] });
1849
+ }
1850
+ function IdentityLine(props) {
1851
+ return /* @__PURE__ */ jsxs("div", { className: "sg-link-id", children: [
1852
+ /* @__PURE__ */ jsx("span", { className: "sg-link-id-icon", children: /* @__PURE__ */ jsx(WalletGlyph, {}) }),
1853
+ /* @__PURE__ */ jsxs("span", { className: "sg-link-id-text", children: [
1854
+ /* @__PURE__ */ jsx("span", { className: "sg-link-id-primary", children: props.account ? shortAddress(props.account) : "ZeroDelta Link" }),
1855
+ /* @__PURE__ */ jsx("span", { className: "sg-link-id-secondary", children: props.email ? props.email : props.account ? "Connected wallet" : "Connect your wallet to continue" })
1856
+ ] }),
1857
+ props.account ? /* @__PURE__ */ jsx("span", { className: "sg-wallet-dot", "aria-hidden": "true" }) : null
1858
+ ] });
1859
+ }
1860
+ function PaymentIsland(props) {
1861
+ injectStyles();
1862
+ const config = useMergedConfig(props);
1863
+ const engine = useEngine({ apiBase: config.apiBase, apiKey: config.apiKey, trustedApiOrigin: config.trustedApiOrigin, rpcOverrides: config.rpcOverrides, onTransaction: config.onTransaction });
1864
+ const wallet = useWallet(config.provider);
1865
+ const kind = props.kind;
1866
+ const isPay = kind === "pay";
1867
+ const mode = props.mode ?? "exchange";
1868
+ const rampMode = kind === "exchange" && mode !== "exchange";
1869
+ const bankSettlement = isPay && props.settlement === "bank";
1870
+ const exAllowed = useMemo(
1871
+ () => (props.assets?.length ? props.assets : ["USDC", "USDT", "USDE"]).map((a) => symbolKey(a)),
1872
+ [props.assets]
1873
+ );
1874
+ const [exFrom, setExFrom] = useState(() => {
1875
+ const chainId = props.defaultFromChainId ?? (kind === "swap" ? 42161 : void 0);
1876
+ const asset = props.defaultFromAsset ?? (kind === "swap" ? "USDT" : void 0);
1877
+ return chainId && asset && exAllowed.includes(symbolKey(asset)) ? { chainId, symbol: symbolKey(asset) } : null;
1878
+ });
1879
+ const [exTo, setExTo] = useState(() => {
1880
+ const chainId = props.defaultToChainId ?? (kind === "swap" ? 8453 : void 0);
1881
+ const asset = props.defaultToAsset ?? (kind === "swap" ? "USDC" : void 0);
1882
+ return chainId && asset && exAllowed.includes(symbolKey(asset)) ? { chainId, symbol: symbolKey(asset) } : null;
1883
+ });
1884
+ const [exAmount, setExAmount] = useState(props.defaultAmount ?? "");
1885
+ const exFromChainId = exFrom?.chainId;
1886
+ const exFromAsset = exFrom?.symbol;
1887
+ const exToChainId = exTo?.chainId;
1888
+ const exToAsset = exTo?.symbol;
1889
+ const normEx = normalizeDecimalText(exAmount);
1890
+ const exAmountValid = /^\d+(\.\d+)?$/.test(normEx) && Number(normEx) > 0 && Number(normEx) <= 1e9;
1891
+ const exQuotable = !rampMode && exAmountValid && Boolean(exFromChainId && exFromAsset && exToChainId && exToAsset);
1892
+ const payParamsKey = `pay|${props.recipient}|${props.toChainId}|${props.toAsset}|${props.amount}`;
1893
+ const exParamsKey = `${kind}|${mode}|${exFromChainId}|${exFromAsset}|${exToChainId}|${exToAsset}|${normEx}|${props.recipient ?? ""}`;
1894
+ const flow = useFlow({
1895
+ engine,
1896
+ wallet,
1897
+ kind: isPay ? "payment" : "swap",
1898
+ // Bank settlement parks the card, so gate the network work off too — otherwise the island would
1899
+ // quote (and fire onQuote) for a payment whose CTA it never shows.
1900
+ enabled: isPay ? Boolean(props.recipient && props.amount) && !bankSettlement : exQuotable,
1901
+ paramsKey: isPay ? payParamsKey : exParamsKey,
1902
+ loadPlan: isPay ? (e, payer, chainId) => e.fetchPaymentPlan({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, payer, { chainId }) : (e, payer) => e.buildSwapPlan({ fromChainId: exFromChainId, toChainId: exToChainId, fromToken: exFromAsset, toToken: exToAsset, amountIn: normEx, recipient: props.recipient }, payer),
1903
+ recipientFor: (account) => isPay ? props.recipient : props.recipient || account,
1904
+ onQuote: config.onQuote,
1905
+ onSuccess: config.onSuccess,
1906
+ onError: config.onError
1907
+ });
1908
+ const [method, setMethod] = useState("recommended");
1909
+ const parked = isPay && !isLiveMethod(method);
1910
+ const fundingSet = useMemo(
1911
+ () => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null,
1912
+ [props.fundingAssets]
1913
+ );
1914
+ const visibleRoutes = useMemo(() => {
1915
+ const base = fundingSet ? flow.routes.filter((r) => fundingSet.has(r.source.asset.toUpperCase()) || r.state === "DIRECT") : flow.routes;
1916
+ return isPay && method === "stablecoin" ? base.filter((r) => STABLES.has(r.source.asset)) : base;
1917
+ }, [flow.routes, fundingSet, isPay, method]);
1918
+ const holdings = useHoldings(engine, wallet.account, flow.routes);
1919
+ const annotated = useMemo(
1920
+ () => visibleRoutes.map((r) => {
1921
+ const balance = holdings.balances[balanceKey(r.source.chainId, r.source.tokenAddress)];
1922
+ let affordable;
1923
+ if (balance && r.source.decimals != null) {
1924
+ try {
1925
+ affordable = BigInt(balance.raw) >= parseUnitsDecimal(r.source.payAmount || r.source.amount, r.source.decimals);
1926
+ } catch {
1927
+ affordable = void 0;
1928
+ }
1929
+ }
1930
+ return { route: r, balance, affordable };
1931
+ }),
1932
+ [visibleRoutes, holdings.balances]
1933
+ );
1934
+ const held = useMemo(() => annotated.filter((a) => a.affordable === true), [annotated]);
1935
+ const heldIds = useMemo(() => new Set(held.map((a) => a.route.id)), [held]);
1936
+ const optionStates = useMemo(() => {
1937
+ const map = {};
1938
+ for (const a of annotated) {
1939
+ const key = balanceKey(a.route.source.chainId, a.route.source.tokenAddress);
1940
+ if (!a.balance || holdings.loading) {
1941
+ map[key] = { disabled: false, reason: "checking" };
1942
+ continue;
1943
+ }
1944
+ let zero = false;
1945
+ try {
1946
+ zero = BigInt(a.balance.raw) === 0n;
1947
+ } catch {
1948
+ zero = false;
1949
+ }
1950
+ if (zero) map[key] = { disabled: true, reason: "no-balance", hint: "No balance on this chain" };
1951
+ else if (a.affordable === false) map[key] = { disabled: true, reason: "insufficient", hint: `Need ${a.route.source.payAmount} ${a.route.source.asset}` };
1952
+ else map[key] = { disabled: false };
1953
+ }
1954
+ return map;
1955
+ }, [annotated, holdings.loading]);
1956
+ const [chains, setChains] = useState([]);
1957
+ const [registryTokens, setRegistryTokens] = useState([]);
1958
+ useEffect(() => {
1959
+ if (bankSettlement || !isPay && rampMode) return;
1960
+ let alive = true;
1961
+ Promise.all([engine.fetchChains().catch(() => []), engine.fetchTokens().catch(() => [])]).then(([cs, ts]) => {
1962
+ if (!alive) return;
1963
+ const order = new Map(SUPPORTED_CHAINS.map((id, i) => [id, i]));
1964
+ setChains(
1965
+ cs.filter((c) => SUPPORTED_CHAIN_IDS.has(Number(c.chainId)) && c.isEnabled !== false).sort((a, b) => (order.get(Number(a.chainId)) ?? 99) - (order.get(Number(b.chainId)) ?? 99))
1966
+ );
1967
+ setRegistryTokens(ts.filter((t) => tokenEnabled(t) && SUPPORTED_CHAIN_IDS.has(Number(t.chainId))));
1968
+ });
1969
+ return () => {
1970
+ alive = false;
1971
+ };
1972
+ }, [engine, isPay, rampMode, bankSettlement]);
1973
+ const exchangeTokens = useMemo(
1974
+ () => isPay ? [] : registryTokens.filter((t) => exAllowed.includes(symbolKey(t.symbol)) && isDeliverable(symbolKey(t.symbol), Number(t.chainId))),
1975
+ [isPay, registryTokens, exAllowed]
1976
+ );
1977
+ const [exBalances, setExBalances] = useState({});
1978
+ const exBalReq = useRef(0);
1979
+ useEffect(() => {
1980
+ if (isPay) return;
1981
+ setExBalances({});
1982
+ if (!wallet.account || !exchangeTokens.length) return;
1983
+ const id = ++exBalReq.current;
1984
+ const targets = [];
1985
+ for (const t of exchangeTokens) {
1986
+ try {
1987
+ targets.push({ chainId: Number(t.chainId), tokenAddress: t.address, decimals: assetDecimals(t) });
1988
+ } catch {
1989
+ }
1990
+ }
1991
+ if (!targets.length) return;
1992
+ engine.readBalances(wallet.account, targets).then((res) => {
1993
+ if (id === exBalReq.current) setExBalances(res);
1994
+ });
1995
+ }, [engine, isPay, wallet.account, exchangeTokens]);
1996
+ const exFromToken = useMemo(() => exFrom ? findToken(exchangeTokens, exFrom.chainId, exFrom.symbol) : null, [exchangeTokens, exFrom]);
1997
+ const exToToken = useMemo(() => exTo ? findToken(exchangeTokens, exTo.chainId, exTo.symbol) : null, [exchangeTokens, exTo]);
1998
+ const exFromBal = exFrom && exFromToken ? exBalances[balanceKey(exFrom.chainId, exFromToken.address)] : void 0;
1999
+ const fundingTokens = useMemo(() => {
2000
+ const seen = /* @__PURE__ */ new Set();
2001
+ const list = [];
2002
+ for (const r of visibleRoutes) {
2003
+ const key = balanceKey(r.source.chainId, r.source.tokenAddress);
2004
+ if (seen.has(key)) continue;
2005
+ seen.add(key);
2006
+ const reg = registryTokens.find((t) => Number(t.chainId) === r.source.chainId && addrEq(t.address, r.source.tokenAddress));
2007
+ list.push(reg ?? { symbol: r.source.asset, name: r.source.asset, chainId: r.source.chainId, address: r.source.tokenAddress ?? "", decimals: r.source.decimals ?? 18 });
2008
+ }
2009
+ return list;
2010
+ }, [visibleRoutes, registryTokens]);
2011
+ const fundingChains = useMemo(() => {
2012
+ const ids = new Set(fundingTokens.map((t) => Number(t.chainId)));
2013
+ return chains.filter((c) => ids.has(Number(c.chainId)));
2014
+ }, [chains, fundingTokens]);
2015
+ const userPicked = useRef(false);
2016
+ const selectRoute = useCallback(
2017
+ (id) => {
2018
+ userPicked.current = true;
2019
+ flow.selectRoute(id);
2020
+ },
2021
+ [flow.selectRoute]
2022
+ );
2023
+ useEffect(() => {
2024
+ userPicked.current = false;
2025
+ }, [wallet.account, payParamsKey, method]);
2026
+ useEffect(() => {
2027
+ if (!isPay || !isLiveMethod(method) || !visibleRoutes.length) return;
2028
+ const inFilter = visibleRoutes.some((r) => r.id === flow.selected?.id);
2029
+ if (!inFilter) {
2030
+ const next = held[0]?.route ?? visibleRoutes.find((r) => r.recommended) ?? visibleRoutes[0];
2031
+ if (next) flow.selectRoute(next.id);
2032
+ return;
2033
+ }
2034
+ if (!userPicked.current && held.length && !heldIds.has(flow.selected?.id ?? "")) {
2035
+ flow.selectRoute(held[0].route.id);
2036
+ }
2037
+ }, [isPay, method, visibleRoutes, held, heldIds, flow.selected?.id]);
2038
+ const [identity, setIdentity] = useState(null);
2039
+ useEffect(() => {
2040
+ setIdentity(loadIdentity(wallet.account));
2041
+ }, [wallet.account]);
2042
+ const identityMatchesWallet = Boolean(identity && wallet.account && addrEq(identity.walletAddress, wallet.account));
2043
+ useEffect(() => {
2044
+ if (!isPay || !identityMatchesWallet || !identity || userPicked.current) return;
2045
+ const match = visibleRoutes.find((r) => r.source.chainId === identity.preferredChainId && symbolKey(r.source.asset) === symbolKey(identity.preferredAsset));
2046
+ if (match) {
2047
+ userPicked.current = true;
2048
+ if (flow.selected?.id !== match.id) flow.selectRoute(match.id);
2049
+ }
2050
+ }, [isPay, identityMatchesWallet, visibleRoutes]);
2051
+ const [rememberChecked, setRememberChecked] = useState(false);
2052
+ const [emailInput, setEmailInput] = useState("");
2053
+ const persistIdentity = () => {
2054
+ if (!wallet.account) return;
2055
+ const src = flow.selected?.source;
2056
+ const preferredChainId = src?.chainId ?? props.toChainId ?? exFromChainId ?? 0;
2057
+ if (!SUPPORTED_CHAIN_IDS.has(Number(preferredChainId))) return;
2058
+ const id = {
2059
+ email: emailInput.trim() || void 0,
2060
+ walletAddress: wallet.account,
2061
+ preferredAsset: src?.asset ?? props.toAsset ?? exFromAsset ?? "USDC",
2062
+ preferredChainId,
2063
+ lastUsedAt: (/* @__PURE__ */ new Date()).toISOString()
2064
+ };
2065
+ saveIdentity(id);
2066
+ setIdentity(id);
2067
+ props.onIdentitySave?.(id);
2068
+ };
2069
+ const forget = () => {
2070
+ forgetIdentity(wallet.account);
2071
+ setIdentity(null);
2072
+ setRememberChecked(false);
2073
+ };
2074
+ const [expanded, setExpanded] = useState(() => Boolean(props.defaultExpanded) || rampMode);
2075
+ const [view, setView] = useState("main");
2076
+ const [hist, setHist] = useState(null);
2077
+ const pillRef = useRef(null);
2078
+ const methodRowRef = useRef(null);
2079
+ const exFromTileRef = useRef(null);
2080
+ const exToTileRef = useRef(null);
2081
+ const regionRef = useRef(null);
2082
+ const panelId = useId();
2083
+ useEffect(() => setView("main"), [wallet.account, payParamsKey]);
2084
+ const firstRender = useRef(true);
2085
+ useEffect(() => {
2086
+ if (firstRender.current) {
2087
+ firstRender.current = false;
2088
+ return;
2089
+ }
2090
+ if (expanded) requestAnimationFrame(() => (methodRowRef.current ?? regionRef.current)?.focus());
2091
+ else requestAnimationFrame(() => pillRef.current?.focus());
2092
+ }, [expanded]);
2093
+ const prevStatus = useRef(flow.status);
2094
+ useEffect(() => {
2095
+ const was = prevStatus.current;
2096
+ prevStatus.current = flow.status;
2097
+ if (expanded && was === "submitting" && (flow.status === "success" || flow.status === "pending" || flow.status === "error")) {
2098
+ requestAnimationFrame(() => regionRef.current?.focus());
2099
+ }
2100
+ }, [flow.status, expanded]);
2101
+ const closeSelector = (opener) => {
2102
+ setView("main");
2103
+ requestAnimationFrame(() => (opener?.current ?? methodRowRef.current ?? regionRef.current)?.focus());
2104
+ };
2105
+ const closeHistory = () => {
2106
+ setHist(null);
2107
+ requestAnimationFrame(() => (methodRowRef.current ?? regionRef.current)?.focus());
2108
+ };
2109
+ const pickFunding = (pick) => {
2110
+ const r = visibleRoutes.find((x) => x.source.chainId === pick.chainId && symbolKey(x.source.asset) === symbolKey(pick.symbol));
2111
+ if (r) selectRoute(r.id);
2112
+ closeSelector();
2113
+ };
2114
+ const submitting = flow.status === "submitting";
2115
+ const sel = flow.selected;
2116
+ const selectedVisible = Boolean(sel && visibleRoutes.some((r) => r.id === sel.id));
2117
+ const selPick = sel && selectedVisible ? { chainId: sel.source.chainId, symbol: sel.source.asset } : null;
2118
+ const selToken = sel ? registryTokens.find((t) => Number(t.chainId) === sel.source.chainId && addrEq(t.address, sel.source.tokenAddress)) ?? null : null;
2119
+ const selBal = sel ? holdings.balances[balanceKey(sel.source.chainId, sel.source.tokenAddress)] : void 0;
2120
+ const lastTxOwned = Boolean(flow.lastTxEntry?.hash && wallet.account && flow.lastTxEntry.account === wallet.account.toLowerCase());
2121
+ const mismatch = flow.status === "error" && flow.verdict?.status === "mismatch";
2122
+ const destAsset = isPay ? props.toAsset : exToAsset;
2123
+ const destChainId = isPay ? props.toChainId : exToChainId;
2124
+ const anchorLabel = isPay ? "Merchant receives exactly" : "You receive (estimated)";
2125
+ const anchorAmount = isPay ? props.amount : sel?.receive.amount ?? (flow.status === "loading" ? "\u2026" : "\u2014");
2126
+ const successAmount = isPay ? props.amount : sel?.receive.amount;
2127
+ const money = props.moneyDisplay ?? (isPay ? props.amount ? `${props.amount} ${props.toAsset}` : "" : exAmount ? `${exAmount} ${exFromAsset ?? ""}`.trim() : "");
2128
+ const verb = isPay ? { present: "Pay", gerund: "Paying", past: "Paid" } : kind === "swap" ? { present: "Swap", gerund: "Swapping", past: "Swapped" } : { present: "Exchange", gerund: "Exchanging", past: "Exchanged" };
2129
+ const paid = flow.status === "success";
2130
+ const settling = flow.status === "pending";
2131
+ const pillAria = `${paid ? verb.past : settling ? "Submitted, awaiting confirmation \u2014" : submitting ? verb.gerund : verb.present} ${money} with ZeroDelta`.replace(/\s+/g, " ").trim();
2132
+ const pillFace = /* @__PURE__ */ jsxs(
2133
+ "button",
2134
+ {
2135
+ ref: pillRef,
2136
+ type: "button",
2137
+ className: "sg-express",
2138
+ "aria-expanded": expanded,
2139
+ "aria-controls": panelId,
2140
+ "aria-label": pillAria,
2141
+ onClick: () => setExpanded((e) => !e),
2142
+ children: [
2143
+ /* @__PURE__ */ jsx("span", { className: "sg-express-mark", "aria-hidden": "true", children: paid ? /* @__PURE__ */ jsx(CheckGlyph2, {}) : settling ? /* @__PURE__ */ jsx(ClockGlyph, {}) : submitting ? /* @__PURE__ */ jsxs(Fragment, { children: [
2144
+ /* @__PURE__ */ jsx("span", { className: "sg-spinner" }),
2145
+ /* @__PURE__ */ jsx("span", { className: "sg-rm-dot" })
2146
+ ] }) : /* @__PURE__ */ jsx(BrandMark, { mono: true, size: 18 }) }),
2147
+ /* @__PURE__ */ jsx("span", { className: "sg-express-label", children: paid ? /* @__PURE__ */ jsx("span", { className: "sg-express-brand", children: verb.past }) : settling ? /* @__PURE__ */ jsx("span", { className: "sg-express-brand", children: "Confirming\u2026" }) : submitting ? /* @__PURE__ */ jsxs("span", { className: "sg-express-brand", children: [
2148
+ verb.gerund,
2149
+ "\u2026"
2150
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2151
+ /* @__PURE__ */ jsxs("span", { className: "sg-express-verb", children: [
2152
+ verb.present,
2153
+ " with"
2154
+ ] }),
2155
+ /* @__PURE__ */ jsx("span", { className: "sg-express-brand", children: "ZeroDelta" })
2156
+ ] }) }),
2157
+ money ? /* @__PURE__ */ jsxs(Fragment, { children: [
2158
+ /* @__PURE__ */ jsx("span", { className: "sg-express-dot", "aria-hidden": "true", children: "\xB7" }),
2159
+ /* @__PURE__ */ jsx("span", { className: "sg-express-amt", children: money })
2160
+ ] }) : null,
2161
+ /* @__PURE__ */ jsx("span", { className: "sg-express-caret", "aria-hidden": "true", children: "\u2304" })
2162
+ ]
2163
+ }
2164
+ );
2165
+ const menuItems = [];
2166
+ if (!rampMode) menuItems.push({ label: isPay ? "Pay another way" : "Close", onSelect: () => setExpanded(false), collapses: true });
2167
+ if (identity) menuItems.push({ label: "Log out of ZeroDelta Link", onSelect: forget, tone: "danger" });
2168
+ const brandSlot = /* @__PURE__ */ jsxs("span", { className: "sg-link-brand", children: [
2169
+ /* @__PURE__ */ jsx("span", { className: "sg-link-mono", "aria-hidden": "true", children: /* @__PURE__ */ jsx(BrandMark, { size: 18 }) }),
2170
+ /* @__PURE__ */ jsx("span", { className: "sg-link-word", children: "ZeroDelta" }),
2171
+ /* @__PURE__ */ jsx("span", { className: "sg-badge", "data-tone": "accent", children: "Link" })
2172
+ ] });
2173
+ const walletSlot = menuItems.length ? /* @__PURE__ */ jsx(LinkMenu, { items: menuItems }) : void 0;
2174
+ const activeStep = flow.steps.find((s) => s.state === "active");
2175
+ const liveMsg = flow.status === "loading" ? isPay ? "Finding the best way to pay." : "Finding the best route." : flow.status === "submitting" ? `${activeStep?.label ?? (isPay ? "Processing your payment" : `Processing your ${verb.present.toLowerCase()}`)} \u2014 in progress.` : flow.status === "success" || flow.status === "pending" ? flow.verdict?.status === "confirmed" ? isPay ? "Payment confirmed on-chain \u2014 the merchant has been settled." : `${verb.past} \u2014 confirmed on-chain.` : isPay ? "Payment sent \u2014 confirmation is still pending." : "Submitted \u2014 confirmation is still pending." : "";
2176
+ const loading = flow.status === "loading";
2177
+ const payReady = isPay ? Boolean(sel && selectedVisible) : Boolean(sel);
2178
+ const ctaLabel = submitting ? isPay ? "Paying\u2026" : kind === "swap" ? "Swapping\u2026" : "Exchanging\u2026" : flow.insufficient ? "Insufficient balance" : flow.nativeShortfall ? flow.nativeShortfall : loading ? "Getting a price\u2026" : isPay ? sel && selectedVisible ? `Pay ${sel.source.payAmount} ${sel.source.asset}` : "Pay" : kind === "swap" ? "Swap" : "Exchange";
2179
+ const exPct = (p) => {
2180
+ if (!exFromBal || !exFromToken) return;
2181
+ const raw = BigInt(exFromBal.raw);
2182
+ setExAmount(formatUnits(p === 100 ? raw : raw * BigInt(p) / 100n, assetDecimals(exFromToken)));
2183
+ };
2184
+ const exchangeControls = /* @__PURE__ */ jsxs(Fragment, { children: [
2185
+ /* @__PURE__ */ jsxs("div", { className: "sg-ft", style: { marginTop: 12 }, children: [
2186
+ /* @__PURE__ */ jsx(TokenTile, { label: "From", pick: exFrom, token: exFromToken, disabled: submitting, btnRef: exFromTileRef, onClick: () => setView("from") }),
2187
+ /* @__PURE__ */ jsx("span", { className: "sg-ft-arrow", "aria-hidden": "true", children: /* @__PURE__ */ jsx(ArrowGlyph, {}) }),
2188
+ /* @__PURE__ */ jsx(TokenTile, { label: "To", pick: exTo, token: exToToken, disabled: submitting, btnRef: exToTileRef, onClick: () => setView("to") })
2189
+ ] }),
2190
+ /* @__PURE__ */ jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
2191
+ /* @__PURE__ */ jsx("div", { className: "sg-label", children: "Send" }),
2192
+ /* @__PURE__ */ jsxs("div", { className: "sg-send-row", children: [
2193
+ exFrom ? /* @__PURE__ */ jsx(TokenGlyph, { symbol: exFrom.symbol, logoUrl: exFromToken?.logoUrl, chainId: exFrom.chainId, size: "sm" }) : null,
2194
+ /* @__PURE__ */ jsx(AmountInput, { value: exAmount, onChange: setExAmount, disabled: submitting })
2195
+ ] }),
2196
+ exFromBal ? /* @__PURE__ */ jsxs("div", { className: "sg-send-bal sg-mono", children: [
2197
+ "Balance: ",
2198
+ exFromBal.formatted,
2199
+ " ",
2200
+ exFrom?.symbol
2201
+ ] }) : null,
2202
+ /* @__PURE__ */ jsx("div", { className: "sg-pct-row", role: "group", "aria-label": "Amount shortcuts", children: [25, 50, 75, 100].map((p) => /* @__PURE__ */ jsx("button", { type: "button", className: "sg-pct", disabled: !exFromBal || submitting, onClick: () => exPct(p), children: p === 100 ? "MAX" : `${p}%` }, p)) })
2203
+ ] })
2204
+ ] });
2205
+ let body;
2206
+ if (hist && wallet.account) {
2207
+ body = /* @__PURE__ */ jsx(TxHistoryPanel, { account: wallet.account, tokens: registryTokens, initialEntry: hist.entry ?? null, onBack: closeHistory });
2208
+ } else if (isPay && view === "select" && wallet.account) {
2209
+ body = /* @__PURE__ */ jsx(TokenSelect, { title: "Pay with", chains: fundingChains, tokens: fundingTokens, balances: holdings.balances, optionStates, onBack: () => closeSelector(), onPick: pickFunding });
2210
+ } else if (!isPay && (view === "from" || view === "to")) {
2211
+ const isFrom = view === "from";
2212
+ const openerRef = isFrom ? exFromTileRef : exToTileRef;
2213
+ body = /* @__PURE__ */ jsx(
2214
+ TokenSelect,
2215
+ {
2216
+ title: isFrom ? "Exchange from" : "Exchange to",
2217
+ chains,
2218
+ tokens: exchangeTokens,
2219
+ balances: exBalances,
2220
+ onBack: () => closeSelector(openerRef),
2221
+ onPick: (pick) => {
2222
+ (isFrom ? setExFrom : setExTo)({ chainId: pick.chainId, symbol: symbolKey(pick.symbol) });
2223
+ closeSelector(openerRef);
2224
+ }
2225
+ }
2226
+ );
2227
+ } else if (rampMode) {
2228
+ body = /* @__PURE__ */ jsxs("div", { className: "sg-soonpanel", children: [
2229
+ /* @__PURE__ */ jsx("div", { className: "sg-soonpanel-title", children: mode === "onramp" ? "Buying with fiat is coming soon" : "Cashing out to fiat is coming soon" }),
2230
+ /* @__PURE__ */ jsx("div", { className: "sg-soonpanel-sub", children: "Fiat on/off-ramps are on the roadmap. ZeroDelta settles crypto-to-crypto today \u2014 connect a wallet to pay with stablecoins." })
2231
+ ] });
2232
+ } else if (bankSettlement) {
2233
+ const payingByRoadmapRail = !isLiveMethod(method);
2234
+ const soonTitle = method === "card" ? "Card payments are coming soon" : method === "bank" ? "Bank transfers are coming soon" : "Bank payout is coming soon";
2235
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
2236
+ /* @__PURE__ */ jsx("div", { style: { marginTop: 12 }, children: /* @__PURE__ */ jsx(MerchantBankPayout, { account: props.bankAccount }) }),
2237
+ /* @__PURE__ */ jsx(MethodTabs, { value: method, onChange: setMethod }),
2238
+ /* @__PURE__ */ jsxs("div", { className: "sg-soonpanel", children: [
2239
+ /* @__PURE__ */ jsx("div", { className: "sg-soonpanel-title", children: soonTitle }),
2240
+ /* @__PURE__ */ jsx("div", { className: "sg-soonpanel-sub", children: payingByRoadmapRail ? `Two roadmap rails at once \u2014 paying by ${method === "card" ? "card" : "bank transfer"} and settling the merchant to a bank. ZeroDelta settles crypto-to-crypto today.` : "Paying a merchant out to a bank account is on the roadmap. ZeroDelta settles crypto-to-crypto today \u2014 switch settlement to a stablecoin to take this payment now." })
2241
+ ] }),
2242
+ /* @__PURE__ */ jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsx(Button, { disabled: true, children: method === "card" ? "Card \u2014 coming soon" : method === "bank" ? "Bank transfer \u2014 coming soon" : "Bank payout \u2014 coming soon" }) })
2243
+ ] });
2244
+ } else if (!wallet.account) {
2245
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
2246
+ /* @__PURE__ */ jsx(IdentityLine, { account: null, email: identity?.email }),
2247
+ isPay ? /* @__PURE__ */ jsx("div", { style: { marginTop: 12 }, children: /* @__PURE__ */ jsx(MerchantReceives, { amount: props.amount, asset: destAsset, chainId: destChainId, recipient: props.recipient }) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2248
+ exchangeControls,
2249
+ /* @__PURE__ */ jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
2250
+ /* @__PURE__ */ jsx("div", { className: "sg-label", children: "You receive (estimated)" }),
2251
+ /* @__PURE__ */ jsxs("div", { className: "sg-anchor sg-mono", children: [
2252
+ "\u2014 ",
2253
+ exToAsset ?? ""
2254
+ ] }),
2255
+ /* @__PURE__ */ jsx("div", { className: "sg-anchor-sub", children: "Connect your wallet to see the estimated receive amount." })
2256
+ ] })
2257
+ ] }),
2258
+ /* @__PURE__ */ jsxs("div", { className: "sg-cta-wrap", children: [
2259
+ /* @__PURE__ */ jsx(Button, { onClick: wallet.connect, busy: wallet.connecting, children: "Connect wallet" }),
2260
+ wallet.error ? /* @__PURE__ */ jsx(StatusPanel, { tone: "error", children: wallet.error }) : null
2261
+ ] })
2262
+ ] });
2263
+ } else if (paid || settling) {
2264
+ const confirmed = flow.verdict?.status === "confirmed";
2265
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
2266
+ /* @__PURE__ */ jsx(IdentityLine, { account: wallet.account, email: identity?.email }),
2267
+ /* @__PURE__ */ jsxs("div", { className: "sg-receipt", children: [
2268
+ /* @__PURE__ */ jsx("div", { className: "sg-receipt-eyebrow", children: isPay ? confirmed ? "Merchant settled" : "Payment sent" : confirmed ? `${verb.past} on-chain` : "Submitted" }),
2269
+ /* @__PURE__ */ jsx("div", { className: "sg-settle-disc", "data-pending": confirmed ? void 0 : "true", children: confirmed ? /* @__PURE__ */ jsx(CheckGlyph2, {}) : /* @__PURE__ */ jsx(ClockGlyph, {}) }),
2270
+ /* @__PURE__ */ jsxs("div", { className: "sg-receipt-amt sg-mono", children: [
2271
+ successAmount,
2272
+ " ",
2273
+ destAsset
2274
+ ] }),
2275
+ /* @__PURE__ */ jsxs("div", { className: "sg-receipt-sub", children: [
2276
+ confirmed ? "Confirmed on-chain" : "Confirmation pending",
2277
+ isPay && props.recipient ? ` \xB7 ${shortAddress(props.recipient)}` : ""
2278
+ ] })
2279
+ ] }),
2280
+ !identityMatchesWallet ? /* @__PURE__ */ jsxs("div", { className: "sg-remember", children: [
2281
+ /* @__PURE__ */ jsxs("label", { className: "sg-remember-top", children: [
2282
+ /* @__PURE__ */ jsx("input", { className: "sg-check", type: "checkbox", checked: rememberChecked, onChange: (e) => setRememberChecked(e.target.checked) }),
2283
+ /* @__PURE__ */ jsxs("span", { className: "sg-remember-copy", children: [
2284
+ /* @__PURE__ */ jsx("span", { className: "sg-remember-label", children: "Save for 1-click next time" }),
2285
+ /* @__PURE__ */ jsx("span", { className: "sg-remember-sub", children: "Remembers this wallet + your preferred stablecoin on ZeroDelta Link. Crypto only \u2014 forgettable anytime." })
2286
+ ] })
2287
+ ] }),
2288
+ rememberChecked ? /* @__PURE__ */ jsxs("div", { className: "sg-remember-body", children: [
2289
+ /* @__PURE__ */ jsx(
2290
+ "input",
2291
+ {
2292
+ className: "sg-input",
2293
+ type: "email",
2294
+ inputMode: "email",
2295
+ placeholder: "Email (optional)",
2296
+ value: emailInput,
2297
+ onChange: (e) => setEmailInput(e.target.value),
2298
+ "aria-label": "Email for ZeroDelta Link (optional)"
2299
+ }
2300
+ ),
2301
+ /* @__PURE__ */ jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsx(Button, { onClick: persistIdentity, children: "Save" }) })
2302
+ ] }) : null
2303
+ ] }) : null,
2304
+ /* @__PURE__ */ jsx("div", { className: "sg-cta-wrap", children: lastTxOwned ? /* @__PURE__ */ jsx(Button, { variant: "ghost", onClick: () => setHist({ entry: flow.lastTxEntry }), children: "View transaction" }) : null }),
2305
+ /* @__PURE__ */ jsx("button", { type: "button", className: "sg-link-alt", onClick: () => props.onDone ? props.onDone() : setExpanded(false), children: "Done" })
2306
+ ] });
2307
+ } else if (mismatch) {
2308
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
2309
+ /* @__PURE__ */ jsx(IdentityLine, { account: wallet.account, email: identity?.email }),
2310
+ /* @__PURE__ */ jsx(StatusPanel, { tone: "error", children: "Payment stopped for review \u2014 the submitted transaction did not match the reviewed plan. Do not retry." }),
2311
+ lastTxOwned ? /* @__PURE__ */ jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsx(Button, { variant: "ghost", onClick: () => setHist({ entry: flow.lastTxEntry }), children: "View transaction" }) }) : null
2312
+ ] });
2313
+ } else {
2314
+ const quoteError = flow.status === "error" && flow.steps.length === 0;
2315
+ const walletError = flow.status === "error" && flow.steps.length > 0;
2316
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
2317
+ /* @__PURE__ */ jsx(IdentityLine, { account: wallet.account, email: identity?.email }),
2318
+ isPay ? /* @__PURE__ */ jsx("div", { style: { marginTop: 12 }, children: /* @__PURE__ */ jsx(MerchantReceives, { amount: props.amount, asset: destAsset, chainId: destChainId, recipient: props.recipient }) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2319
+ exchangeControls,
2320
+ /* @__PURE__ */ jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
2321
+ /* @__PURE__ */ jsx("div", { className: "sg-label", children: anchorLabel }),
2322
+ /* @__PURE__ */ jsxs("div", { className: "sg-anchor sg-mono", children: [
2323
+ anchorAmount,
2324
+ " ",
2325
+ destAsset
2326
+ ] })
2327
+ ] })
2328
+ ] }),
2329
+ isPay ? /* @__PURE__ */ jsx(MethodTabs, { value: method, onChange: setMethod }) : null,
2330
+ parked ? (
2331
+ // Honest roadmap park — Card / Bank are not live. No quote, no funding row, no Pay CTA.
2332
+ /* @__PURE__ */ jsxs(Fragment, { children: [
2333
+ /* @__PURE__ */ jsxs("div", { className: "sg-soonpanel", children: [
2334
+ /* @__PURE__ */ jsx("div", { className: "sg-soonpanel-title", children: method === "card" ? "Card payments are coming soon" : "Bank transfers are coming soon" }),
2335
+ /* @__PURE__ */ jsxs("div", { className: "sg-soonpanel-sub", children: [
2336
+ "Today ZeroDelta settles from your connected wallet. Fiat ",
2337
+ method === "card" ? "card" : "bank",
2338
+ " rails are on the roadmap \u2014 crypto-to-crypto is live now."
2339
+ ] })
2340
+ ] }),
2341
+ /* @__PURE__ */ jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsx(Button, { disabled: true, children: method === "card" ? "Card \u2014 coming soon" : "Bank \u2014 coming soon" }) })
2342
+ ] })
2343
+ ) : /* @__PURE__ */ jsxs(Fragment, { children: [
2344
+ isPay ? /* @__PURE__ */ jsx("div", { style: { marginTop: 12 }, children: /* @__PURE__ */ jsx(TokenTile, { row: true, label: "Pay with", pick: selPick, token: selToken, disabled: submitting || !visibleRoutes.length, btnRef: methodRowRef, onClick: () => setView("select") }) }) : null,
2345
+ loading ? /* @__PURE__ */ jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
2346
+ /* @__PURE__ */ jsx("div", { className: "sg-skel" }),
2347
+ /* @__PURE__ */ jsxs("div", { className: "sg-muted", style: { fontSize: 13 }, children: [
2348
+ /* @__PURE__ */ jsx("span", { className: "sg-spinner" }),
2349
+ /* @__PURE__ */ jsx("span", { className: "sg-rm-dot" }),
2350
+ " Finding the best way to pay\u2026"
2351
+ ] })
2352
+ ] }) : null,
2353
+ isPay && sel && selectedVisible && !loading ? /* @__PURE__ */ jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
2354
+ /* @__PURE__ */ jsx("div", { className: "sg-label", children: "You pay" }),
2355
+ /* @__PURE__ */ jsxs("div", { className: "sg-anchor sg-mono", children: [
2356
+ sel.source.payAmount,
2357
+ " ",
2358
+ sel.source.asset
2359
+ ] }),
2360
+ /* @__PURE__ */ jsxs("div", { className: "sg-anchor-sub", children: [
2361
+ "on ",
2362
+ chainName(sel.source.chainId),
2363
+ selBal ? ` \xB7 balance ${selBal.formatted}` : ""
2364
+ ] })
2365
+ ] }) : null,
2366
+ !isPay && sel && !loading ? /* @__PURE__ */ jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
2367
+ /* @__PURE__ */ jsx("div", { className: "sg-label", children: "You pay" }),
2368
+ /* @__PURE__ */ jsxs("div", { className: "sg-anchor sg-mono", children: [
2369
+ sel.source.payAmount,
2370
+ " ",
2371
+ sel.source.asset
2372
+ ] }),
2373
+ /* @__PURE__ */ jsxs("div", { className: "sg-anchor-sub", children: [
2374
+ "on ",
2375
+ chainName(sel.source.chainId)
2376
+ ] })
2377
+ ] }) : null,
2378
+ quoteError ? /* @__PURE__ */ jsx(StatusPanel, { tone: "error", children: flow.error || "Couldn't get a price right now." }) : null,
2379
+ walletError ? /* @__PURE__ */ jsx(StatusPanel, { tone: "error", children: flow.error || "The wallet could not complete this payment." }) : null,
2380
+ submitting || walletError ? /* @__PURE__ */ jsx(StepList, { variant: "rich", steps: flow.steps, verdict: flow.verdict }) : null,
2381
+ /* @__PURE__ */ jsx("div", { className: "sg-cta-wrap", children: quoteError ? /* @__PURE__ */ jsx(Button, { onClick: flow.reload, children: "Try again" }) : walletError ? /* @__PURE__ */ jsx(Button, { onClick: payReady ? flow.submit : void 0, disabled: !payReady, children: "Try again" }) : /* @__PURE__ */ jsx(
2382
+ Button,
2383
+ {
2384
+ onClick: payReady && !submitting && !flow.insufficient && !flow.nativeShortfall && !loading ? flow.submit : void 0,
2385
+ busy: submitting || loading,
2386
+ softDisabled: submitting,
2387
+ disabled: !submitting && (!payReady || flow.insufficient || !!flow.nativeShortfall || loading),
2388
+ children: ctaLabel
2389
+ }
2390
+ ) })
2391
+ ] })
2392
+ ] });
2393
+ }
2394
+ const resolved = resolveTheme(config.theme);
2395
+ const islandVars = themeToVars(resolved);
2396
+ return /* @__PURE__ */ jsx("div", { className: "sg-island-wrap", children: /* @__PURE__ */ jsxs("div", { className: "sg-island", "data-sg-mode": resolved.mode, "data-expanded": expanded, "data-status": flow.status, style: islandVars, children: [
2397
+ pillFace,
2398
+ /* @__PURE__ */ jsx("div", { className: "sg-island-reveal", children: /* @__PURE__ */ jsx("div", { className: "sg-island-reveal-inner", children: /* @__PURE__ */ jsx("div", { className: "sg-island-body", id: panelId, ref: regionRef, role: "region", "aria-label": isPay ? "ZeroDelta Link checkout" : `ZeroDelta Link ${verb.present.toLowerCase()}`, tabIndex: -1, children: expanded ? /* @__PURE__ */ jsxs(WidgetShell, { variant: "express", title: "ZeroDelta Link", theme: config.theme, heightPx: props.heightPx, brandSlot, walletSlot, children: [
2399
+ /* @__PURE__ */ jsx("span", { className: "sg-sr-only", role: "status", "aria-live": "polite", children: liveMsg }),
2400
+ body
2401
+ ] }) : null }) }) })
2402
+ ] }) });
2403
+ }
2404
+ var STABLES2 = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE"]);
2405
+ function CheckGlyph3() {
2406
+ return /* @__PURE__ */ jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "3", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" }) });
2407
+ }
2408
+ var addrEq2 = (a, b) => String(a || "").toLowerCase() === String(b || "").toLowerCase();
2409
+ function StableGeniePay(props) {
2410
+ const config = useMergedConfig(props);
2411
+ const engine = useEngine({ apiBase: config.apiBase, apiKey: config.apiKey, trustedApiOrigin: config.trustedApiOrigin, rpcOverrides: config.rpcOverrides, onTransaction: config.onTransaction });
2412
+ const wallet = useWallet(config.provider);
2413
+ const paramsKey = `${props.recipient}|${props.toChainId}|${props.toAsset}|${props.amount}`;
2414
+ const flow = useFlow({
2415
+ engine,
2416
+ wallet,
2417
+ kind: "payment",
2418
+ // When variant="pill" this component delegates to PaymentIsland (which runs its OWN flow) — do no
2419
+ // network work here, or every quote / balance read fires twice and onQuote/onError double-fire.
2420
+ enabled: Boolean(props.recipient && props.amount) && props.variant !== "pill",
2421
+ paramsKey,
2422
+ loadPlan: (e, payer, chainId) => e.fetchPaymentPlan({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, payer, { chainId }),
2423
+ recipientFor: () => props.recipient,
2424
+ onQuote: config.onQuote,
2425
+ onSuccess: config.onSuccess,
2426
+ onError: config.onError
2427
+ });
2428
+ const [method, setMethod] = useState("recommended");
2429
+ const fundingSet = useMemo(
2430
+ () => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null,
2431
+ [props.fundingAssets]
2432
+ );
2433
+ const visibleRoutes = useMemo(() => {
2434
+ const base = fundingSet ? flow.routes.filter((r) => fundingSet.has(r.source.asset.toUpperCase()) || r.state === "DIRECT") : flow.routes;
2435
+ return method === "stablecoin" ? base.filter((r) => STABLES2.has(r.source.asset)) : base;
2436
+ }, [flow.routes, method, fundingSet]);
2437
+ const holdings = useHoldings(engine, wallet.account, flow.routes);
2438
+ const annotated = useMemo(
2439
+ () => visibleRoutes.map((r) => {
2440
+ const balance = holdings.balances[balanceKey(r.source.chainId, r.source.tokenAddress)];
2441
+ let affordable;
2442
+ if (balance && r.source.decimals != null) {
2443
+ try {
2444
+ affordable = BigInt(balance.raw) >= parseUnitsDecimal(r.source.payAmount || r.source.amount, r.source.decimals);
2445
+ } catch {
2446
+ affordable = void 0;
2447
+ }
2448
+ }
2449
+ return { route: r, balance, affordable };
2450
+ }),
2451
+ [visibleRoutes, holdings.balances]
2452
+ );
2453
+ const held = useMemo(() => annotated.filter((a) => a.affordable === true), [annotated]);
2454
+ const heldIds = useMemo(() => new Set(held.map((a) => a.route.id)), [held]);
2455
+ const scannedEmpty = !holdings.loading && Object.keys(holdings.balances).length > 0 && held.length === 0;
2456
+ const optionStates = useMemo(() => {
2457
+ const map = {};
2458
+ for (const a of annotated) {
2459
+ const key = balanceKey(a.route.source.chainId, a.route.source.tokenAddress);
2460
+ if (!a.balance || holdings.loading) {
2461
+ map[key] = { disabled: false, reason: "checking" };
2462
+ continue;
2463
+ }
2464
+ let zero = false;
2465
+ try {
2466
+ zero = BigInt(a.balance.raw) === 0n;
2467
+ } catch {
2468
+ zero = false;
2469
+ }
2470
+ if (zero) {
2471
+ map[key] = { disabled: true, reason: "no-balance", hint: "No balance on this chain" };
2472
+ } else if (a.affordable === false) {
2473
+ map[key] = { disabled: true, reason: "insufficient", hint: `Need ${a.route.source.payAmount} ${a.route.source.asset}` };
2474
+ } else {
2475
+ map[key] = { disabled: false };
2476
+ }
2477
+ }
2478
+ return map;
2479
+ }, [annotated, holdings.loading]);
2480
+ const [chains, setChains] = useState([]);
2481
+ const [registryTokens, setRegistryTokens] = useState([]);
2482
+ useEffect(() => {
2483
+ if (props.variant === "pill") return;
2484
+ let alive = true;
2485
+ Promise.all([engine.fetchChains().catch(() => []), engine.fetchTokens().catch(() => [])]).then(([cs, ts]) => {
2486
+ if (!alive) return;
2487
+ const order = new Map(SUPPORTED_CHAINS.map((id, i) => [id, i]));
2488
+ setChains(
2489
+ cs.filter((c) => SUPPORTED_CHAIN_IDS.has(Number(c.chainId)) && c.isEnabled !== false).sort((a, b) => (order.get(Number(a.chainId)) ?? 99) - (order.get(Number(b.chainId)) ?? 99))
2490
+ );
2491
+ setRegistryTokens(ts.filter((t) => tokenEnabled(t) && SUPPORTED_CHAIN_IDS.has(Number(t.chainId))));
2492
+ });
2493
+ return () => {
2494
+ alive = false;
2495
+ };
2496
+ }, [engine]);
2497
+ const fundingTokens = useMemo(() => {
2498
+ const seen = /* @__PURE__ */ new Set();
2499
+ const list = [];
2500
+ for (const r of visibleRoutes) {
2501
+ const key = balanceKey(r.source.chainId, r.source.tokenAddress);
2502
+ if (seen.has(key)) continue;
2503
+ seen.add(key);
2504
+ const reg = registryTokens.find((t) => Number(t.chainId) === r.source.chainId && addrEq2(t.address, r.source.tokenAddress));
2505
+ list.push(reg ?? { symbol: r.source.asset, name: r.source.asset, chainId: r.source.chainId, address: r.source.tokenAddress ?? "", decimals: r.source.decimals ?? 18 });
2506
+ }
2507
+ return list;
2508
+ }, [visibleRoutes, registryTokens]);
2509
+ const fundingChains = useMemo(() => {
2510
+ const ids = new Set(fundingTokens.map((t) => Number(t.chainId)));
2511
+ return chains.filter((c) => ids.has(Number(c.chainId)));
2512
+ }, [chains, fundingTokens]);
2513
+ const userPicked = useRef(false);
2514
+ const selectRoute = useCallback(
2515
+ (id) => {
2516
+ userPicked.current = true;
2517
+ flow.selectRoute(id);
2518
+ },
2519
+ [flow.selectRoute]
2520
+ );
2521
+ useEffect(() => {
2522
+ userPicked.current = false;
2523
+ }, [method, wallet.account, paramsKey]);
2524
+ useEffect(() => {
2525
+ if (!isLiveMethod(method) || !visibleRoutes.length) return;
2526
+ const inFilter = visibleRoutes.some((r) => r.id === flow.selected?.id);
2527
+ if (!inFilter) {
2528
+ const next = held[0]?.route ?? visibleRoutes.find((r) => r.recommended) ?? visibleRoutes[0];
2529
+ if (next) flow.selectRoute(next.id);
2530
+ return;
2531
+ }
2532
+ if (!userPicked.current && held.length && !heldIds.has(flow.selected?.id ?? "")) {
2533
+ flow.selectRoute(held[0].route.id);
2534
+ }
2535
+ }, [method, visibleRoutes, held, heldIds, flow.selected?.id]);
2536
+ const [view, setView] = useState("main");
2537
+ const payTileRef = useRef(null);
2538
+ const closeSelector = () => {
2539
+ setView("main");
2540
+ requestAnimationFrame(() => payTileRef.current?.focus());
2541
+ };
2542
+ useEffect(() => setView("main"), [wallet.account, paramsKey]);
2543
+ const [hist, setHist] = useState(null);
2544
+ const histBtnRef = useRef(null);
2545
+ const closeHistory = () => {
2546
+ setHist(null);
2547
+ requestAnimationFrame(() => histBtnRef.current?.focus());
2548
+ };
2549
+ useEffect(() => setHist(null), [wallet.account]);
2550
+ const lastTxOwned = Boolean(flow.lastTxEntry?.hash && wallet.account && flow.lastTxEntry.account === wallet.account.toLowerCase());
2551
+ const pickFunding = (pick) => {
2552
+ const r = visibleRoutes.find((x) => x.source.chainId === pick.chainId && symbolKey(x.source.asset) === symbolKey(pick.symbol));
2553
+ if (r) selectRoute(r.id);
2554
+ closeSelector();
2555
+ };
2556
+ const chainName2 = CHAIN_LABELS[props.toChainId] || `Chain ${props.toChainId}`;
2557
+ const parked = !isLiveMethod(method);
2558
+ const submitting = flow.status === "submitting";
2559
+ const sel = flow.selected;
2560
+ const selectedVisible = Boolean(sel && visibleRoutes.some((r) => r.id === sel.id));
2561
+ const selPick = sel && selectedVisible ? { chainId: sel.source.chainId, symbol: sel.source.asset } : null;
2562
+ const selToken = sel ? registryTokens.find((t) => Number(t.chainId) === sel.source.chainId && addrEq2(t.address, sel.source.tokenAddress)) ?? null : null;
2563
+ const selBal = sel ? holdings.balances[balanceKey(sel.source.chainId, sel.source.tokenAddress)] : void 0;
2564
+ const why = parked ? "" : sel && selectedVisible ? sel.state === "DIRECT" ? `Direct ${sel.source.asset} transfer on ${CHAIN_LABELS[sel.source.chainId] || sel.source.chainName} \xB7 lowest cost` : `Routed through ZeroDelta \u2014 the merchant still receives exactly ${props.amount} ${props.toAsset}` : method === "stablecoin" ? "Pay with USDC, USDT, or USDE from your wallet." : method === "anyasset" ? "Pay with any supported asset \u2014 we route it to exactly what the merchant needs." : "Best route \xB7 picked for you";
2565
+ const comingSoon = method === "card" ? "Card payments are coming soon. Today StableGenie pays from your connected wallet." : "Bank transfers are coming soon.";
2566
+ const payLabel = parked ? method === "card" ? "Card \u2014 coming soon" : "Bank \u2014 coming soon" : submitting ? "Paying\u2026" : flow.insufficient ? "Insufficient balance" : flow.nativeShortfall ? flow.nativeShortfall : sel && selectedVisible ? `Pay ${sel.source.payAmount} ${sel.source.asset}` : "Pay";
2567
+ const walletSlot = wallet.account ? /* @__PURE__ */ jsxs("div", { className: "sg-head-tools", children: [
2568
+ /* @__PURE__ */ jsx(HistoryButton, { btnRef: histBtnRef, disabled: submitting, onClick: () => setHist({}) }),
2569
+ /* @__PURE__ */ jsxs("div", { className: "sg-brand", children: [
2570
+ /* @__PURE__ */ jsx(BrandMark, { size: 14, className: "sg-brand-mark" }),
2571
+ "ZeroDelta"
2572
+ ] })
2573
+ ] }) : void 0;
2574
+ if (props.variant === "pill") return /* @__PURE__ */ jsx(PaymentIsland, { kind: "pay", ...props });
2575
+ return /* @__PURE__ */ jsx(WidgetShell, { title: config.title || "Complete payment", theme: config.theme, heightPx: props.heightPx, walletSlot, children: hist && wallet.account ? /* @__PURE__ */ jsx(TxHistoryPanel, { account: wallet.account, tokens: registryTokens, initialEntry: hist.entry ?? null, onBack: closeHistory }) : view === "select" && wallet.account ? /* @__PURE__ */ jsx(TokenSelect, { title: "Pay with", chains: fundingChains, tokens: fundingTokens, balances: holdings.balances, optionStates, onBack: closeSelector, onPick: pickFunding }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2576
+ /* @__PURE__ */ jsxs("div", { className: "sg-panel", children: [
2577
+ /* @__PURE__ */ jsx("div", { className: "sg-label", children: "Merchant receives exactly" }),
2578
+ /* @__PURE__ */ jsxs("div", { className: "sg-anchor sg-mono", children: [
2579
+ props.amount,
2580
+ " ",
2581
+ props.toAsset
2582
+ ] }),
2583
+ /* @__PURE__ */ jsxs("div", { className: "sg-anchor-sub", children: [
2584
+ "on ",
2585
+ chainName2,
2586
+ " \xB7 ",
2587
+ shortAddress(props.recipient)
2588
+ ] })
2589
+ ] }),
2590
+ !wallet.account ? /* @__PURE__ */ jsxs("div", { className: "sg-cta-wrap", children: [
2591
+ /* @__PURE__ */ jsx(Button, { onClick: wallet.connect, busy: wallet.connecting, children: "Connect wallet" }),
2592
+ wallet.error ? /* @__PURE__ */ jsx(StatusPanel, { tone: "error", children: wallet.error }) : null
2593
+ ] }) : flow.status === "success" || flow.status === "pending" ? /* @__PURE__ */ jsxs(Fragment, { children: [
2594
+ /* @__PURE__ */ jsxs("div", { className: "sg-success", children: [
2595
+ /* @__PURE__ */ jsx("div", { className: "sg-success-check", "data-pending": flow.verdict?.status !== "confirmed", children: /* @__PURE__ */ jsx(CheckGlyph3, {}) }),
2596
+ /* @__PURE__ */ jsxs("div", { className: "sg-success-amt sg-mono", children: [
2597
+ props.amount,
2598
+ " ",
2599
+ props.toAsset
2600
+ ] }),
2601
+ /* @__PURE__ */ jsxs("div", { className: "sg-success-sub", children: [
2602
+ flow.verdict?.status === "confirmed" ? "Confirmed on-chain" : "Submitted \u2014 awaiting confirmation",
2603
+ " \xB7 ",
2604
+ shortAddress(props.recipient)
2605
+ ] })
2606
+ ] }),
2607
+ lastTxOwned ? /* @__PURE__ */ jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsx(Button, { variant: "ghost", onClick: () => setHist({ entry: flow.lastTxEntry }), children: "View transaction" }) }) : null
2608
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2609
+ /* @__PURE__ */ jsx(MethodTabs, { value: method, onChange: setMethod }),
2610
+ parked ? /* @__PURE__ */ jsx(StatusPanel, { children: comingSoon }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2611
+ /* @__PURE__ */ jsx("div", { style: { marginTop: 12 }, children: /* @__PURE__ */ jsx(
2612
+ TokenTile,
2613
+ {
2614
+ label: "Pay with",
2615
+ pick: selPick,
2616
+ token: selToken,
2617
+ disabled: submitting || !visibleRoutes.length,
2618
+ btnRef: payTileRef,
2619
+ onClick: () => setView("select")
2620
+ }
2621
+ ) }),
2622
+ flow.status === "loading" ? /* @__PURE__ */ jsxs("div", { className: "sg-route", style: { marginTop: 12 }, children: [
2623
+ /* @__PURE__ */ jsx("div", { className: "sg-skel" }),
2624
+ /* @__PURE__ */ jsxs("div", { className: "sg-muted", style: { fontSize: 13 }, children: [
2625
+ /* @__PURE__ */ jsx("span", { className: "sg-spinner" }),
2626
+ " Finding the best way to pay\u2026"
2627
+ ] })
2628
+ ] }) : null,
2629
+ flow.status === "error" && flow.error ? /* @__PURE__ */ jsx(StatusPanel, { tone: "error", children: flow.error }) : null,
2630
+ sel && selectedVisible && flow.status !== "loading" ? /* @__PURE__ */ jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
2631
+ /* @__PURE__ */ jsx("div", { className: "sg-label", children: "You pay" }),
2632
+ /* @__PURE__ */ jsxs("div", { className: "sg-anchor sg-mono", children: [
2633
+ sel.source.payAmount,
2634
+ " ",
2635
+ sel.source.asset
2636
+ ] }),
2637
+ /* @__PURE__ */ jsxs("div", { className: "sg-anchor-sub", children: [
2638
+ "on ",
2639
+ CHAIN_LABELS[sel.source.chainId] || sel.source.chainName,
2640
+ selBal ? ` \xB7 balance ${selBal.formatted}` : ""
2641
+ ] })
2642
+ ] }) : null,
2643
+ why ? /* @__PURE__ */ jsx("div", { className: "sg-why", style: { marginTop: 10 }, children: why }) : null,
2644
+ scannedEmpty ? /* @__PURE__ */ jsx("div", { className: "sg-note", children: "None of your balances can cover this yet \u2014 pick a different asset to fund with." }) : null,
2645
+ flow.status === "ready" && !visibleRoutes.length ? /* @__PURE__ */ jsx(StatusPanel, { children: "No funding route matches the accepted assets for this payment." }) : null
2646
+ ] }),
2647
+ submitting ? /* @__PURE__ */ jsx(StepList, { steps: flow.steps }) : null,
2648
+ /* @__PURE__ */ jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsx(Button, { onClick: parked || !selectedVisible ? void 0 : flow.submit, busy: submitting, disabled: parked || !selectedVisible || flow.insufficient || !!flow.nativeShortfall || flow.status === "loading", children: payLabel }) })
2649
+ ] })
2650
+ ] }) });
2651
+ }
2652
+ var chainOptions = SUPPORTED_CHAINS.map((c) => ({ value: c, label: CHAIN_LABELS[c] || `Chain ${c}` }));
2653
+ var assetOptions = SUPPORTED_ASSETS2.map((a) => ({ value: a, label: a }));
2654
+ function CheckGlyph4() {
2655
+ return /* @__PURE__ */ jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "3", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" }) });
2656
+ }
2657
+ function StableGenieSwap(props) {
2658
+ const config = useMergedConfig(props);
2659
+ const engine = useEngine({ apiBase: config.apiBase, apiKey: config.apiKey, trustedApiOrigin: config.trustedApiOrigin, rpcOverrides: config.rpcOverrides, onTransaction: config.onTransaction });
2660
+ const wallet = useWallet(config.provider);
2661
+ const [fromChainId, setFromChainId] = useState(props.defaultFromChainId ?? 42161);
2662
+ const [fromAsset, setFromAsset] = useState(props.defaultFromAsset ?? "USDT");
2663
+ const [toChainId, setToChainId] = useState(props.defaultToChainId ?? 8453);
2664
+ const [toAsset, setToAsset] = useState(props.defaultToAsset ?? "USDC");
2665
+ const [amount, setAmount] = useState(props.defaultAmount ?? "");
2666
+ const amountValid = /^\d+(\.\d+)?$/.test(amount.replace(",", ".")) && Number(amount.replace(",", ".")) > 0;
2667
+ const enabled = amountValid && props.variant !== "pill";
2668
+ const paramsKey = `${fromChainId}|${fromAsset}|${toChainId}|${toAsset}|${amount}|${props.recipient ?? ""}`;
2669
+ const flow = useFlow({
2670
+ engine,
2671
+ wallet,
2672
+ kind: "swap",
2673
+ enabled,
2674
+ paramsKey,
2675
+ loadPlan: (e, payer) => e.buildSwapPlan({ fromChainId, toChainId, fromToken: fromAsset, toToken: toAsset, amountIn: amount, recipient: props.recipient }, payer),
2676
+ recipientFor: (account) => props.recipient || account,
2677
+ onQuote: config.onQuote,
2678
+ onSuccess: config.onSuccess,
2679
+ onError: config.onError
2680
+ });
2681
+ const reverse = () => {
2682
+ setFromChainId(toChainId);
2683
+ setFromAsset(toAsset);
2684
+ setToChainId(fromChainId);
2685
+ setToAsset(fromAsset);
2686
+ };
2687
+ const receive = flow.selected?.receive.amount;
2688
+ const submitting = flow.status === "submitting";
2689
+ const swapLabel = submitting ? "Swapping\u2026" : flow.insufficient ? "Insufficient balance" : flow.nativeShortfall || "Swap";
2690
+ const toValue = useMemo(() => receive ? `${receive}` : flow.status === "loading" ? "\u2026" : "\u2014", [receive, flow.status]);
2691
+ const [hist, setHist] = useState(null);
2692
+ const histBtnRef = useRef(null);
2693
+ const closeHistory = () => {
2694
+ setHist(null);
2695
+ requestAnimationFrame(() => histBtnRef.current?.focus());
2696
+ };
2697
+ useEffect(() => setHist(null), [wallet.account]);
2698
+ const [registryTokens, setRegistryTokens] = useState([]);
2699
+ useEffect(() => {
2700
+ if (props.variant === "pill" || !hist) return;
2701
+ let alive = true;
2702
+ engine.fetchTokens().then((ts) => {
2703
+ if (alive) setRegistryTokens(ts);
2704
+ }).catch(() => {
2705
+ });
2706
+ return () => {
2707
+ alive = false;
2708
+ };
2709
+ }, [engine, props.variant, hist]);
2710
+ const lastTxOwned = Boolean(flow.lastTxEntry?.hash && wallet.account && flow.lastTxEntry.account === wallet.account.toLowerCase());
2711
+ if (props.variant === "pill") return /* @__PURE__ */ jsx(PaymentIsland, { kind: "swap", ...props });
2712
+ const walletSlot = wallet.account ? /* @__PURE__ */ jsxs("div", { className: "sg-head-tools", children: [
2713
+ /* @__PURE__ */ jsx(HistoryButton, { btnRef: histBtnRef, disabled: submitting, onClick: () => setHist({}) }),
2714
+ /* @__PURE__ */ jsx("div", { className: "sg-brand", children: "ZeroDelta" })
2715
+ ] }) : void 0;
2716
+ if (hist && wallet.account) {
2717
+ return /* @__PURE__ */ jsx(WidgetShell, { title: config.title || "Swap", theme: config.theme, walletSlot, children: /* @__PURE__ */ jsx(TxHistoryPanel, { account: wallet.account, tokens: registryTokens, initialEntry: hist.entry ?? null, onBack: closeHistory }) });
2718
+ }
2719
+ if (flow.status === "success" || flow.status === "pending") {
2720
+ return /* @__PURE__ */ jsxs(WidgetShell, { title: config.title || "Swap", theme: config.theme, walletSlot, children: [
2721
+ /* @__PURE__ */ jsxs("div", { className: "sg-success", children: [
2722
+ /* @__PURE__ */ jsx("div", { className: "sg-success-check", "data-pending": flow.verdict?.status !== "confirmed", children: /* @__PURE__ */ jsx(CheckGlyph4, {}) }),
2723
+ /* @__PURE__ */ jsxs("div", { className: "sg-success-amt sg-mono", children: [
2724
+ receive,
2725
+ " ",
2726
+ toAsset
2727
+ ] }),
2728
+ /* @__PURE__ */ jsxs("div", { className: "sg-success-sub", children: [
2729
+ flow.verdict?.status === "confirmed" ? "Confirmed on-chain" : "Submitted \u2014 awaiting confirmation",
2730
+ props.recipient ? ` \xB7 ${shortAddress(props.recipient)}` : ""
2731
+ ] })
2732
+ ] }),
2733
+ lastTxOwned ? /* @__PURE__ */ jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsx(Button, { variant: "ghost", onClick: () => setHist({ entry: flow.lastTxEntry }), children: "View transaction" }) }) : null
2734
+ ] });
2735
+ }
2736
+ return /* @__PURE__ */ jsxs(WidgetShell, { title: config.title || "Swap", theme: config.theme, walletSlot, children: [
2737
+ /* @__PURE__ */ jsxs("div", { className: "sg-panel", children: [
2738
+ /* @__PURE__ */ jsx("div", { className: "sg-label", children: "You pay" }),
2739
+ /* @__PURE__ */ jsx(AmountInput, { value: amount, onChange: setAmount, disabled: submitting }),
2740
+ /* @__PURE__ */ jsxs("div", { className: "sg-row", style: { marginTop: 8 }, children: [
2741
+ /* @__PURE__ */ jsx("div", { className: "sg-grow", children: /* @__PURE__ */ jsx(Select, { value: fromAsset, onChange: setFromAsset, options: assetOptions, disabled: submitting }) }),
2742
+ /* @__PURE__ */ jsx("div", { className: "sg-grow", children: /* @__PURE__ */ jsx(Select, { value: fromChainId, onChange: (v) => setFromChainId(Number(v)), options: chainOptions, disabled: submitting }) })
2743
+ ] })
2744
+ ] }),
2745
+ /* @__PURE__ */ jsx("button", { type: "button", className: "sg-reverse", onClick: reverse, "aria-label": "Reverse", disabled: submitting, children: "\u2193" }),
2746
+ /* @__PURE__ */ jsxs("div", { className: "sg-panel", children: [
2747
+ /* @__PURE__ */ jsx("div", { className: "sg-label", children: "You receive (estimated)" }),
2748
+ /* @__PURE__ */ jsx("div", { className: "sg-anchor sg-mono", children: toValue }),
2749
+ /* @__PURE__ */ jsxs("div", { className: "sg-row", style: { marginTop: 8 }, children: [
2750
+ /* @__PURE__ */ jsx("div", { className: "sg-grow", children: /* @__PURE__ */ jsx(Select, { value: toAsset, onChange: setToAsset, options: assetOptions, disabled: submitting }) }),
2751
+ /* @__PURE__ */ jsx("div", { className: "sg-grow", children: /* @__PURE__ */ jsx(Select, { value: toChainId, onChange: (v) => setToChainId(Number(v)), options: chainOptions, disabled: submitting }) })
2752
+ ] })
2753
+ ] }),
2754
+ flow.status === "error" && flow.error ? /* @__PURE__ */ jsx(StatusPanel, { tone: "error", children: flow.error }) : null,
2755
+ flow.routes.length ? /* @__PURE__ */ jsx(RouteList, { routes: flow.routes, selectedId: flow.selected?.id ?? null, onSelect: flow.selectRoute }) : null,
2756
+ submitting ? /* @__PURE__ */ jsx(StepList, { steps: flow.steps }) : null,
2757
+ /* @__PURE__ */ jsxs("div", { className: "sg-cta-wrap", children: [
2758
+ !wallet.account ? /* @__PURE__ */ jsx(Button, { onClick: wallet.connect, busy: wallet.connecting, children: "Connect wallet" }) : /* @__PURE__ */ jsx(Button, { onClick: flow.submit, busy: submitting, disabled: !flow.selected || flow.insufficient || !!flow.nativeShortfall || !enabled || flow.status === "loading", children: swapLabel }),
2759
+ wallet.error ? /* @__PURE__ */ jsx(StatusPanel, { tone: "error", children: wallet.error }) : null
2760
+ ] })
2761
+ ] });
2762
+ }
2763
+ var STABLE_ASSETS = ["USDC", "USDT", "USDE"];
2764
+ var FIAT = [
2765
+ { code: "USD", glyph: "$", label: "US Dollar" },
2766
+ { code: "EUR", glyph: "\u20AC", label: "Euro" },
2767
+ { code: "GBP", glyph: "\xA3", label: "British Pound" },
2768
+ { code: "CHF", glyph: "\u20A3", label: "Swiss Franc" }
2769
+ ];
2770
+ function ArrowGlyph2() {
2771
+ return /* @__PURE__ */ jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
2772
+ /* @__PURE__ */ jsx("path", { d: "M5 12h14" }),
2773
+ /* @__PURE__ */ jsx("path", { d: "m13 6 6 6-6 6" })
2774
+ ] });
2775
+ }
2776
+ function RouteGlyph() {
2777
+ return /* @__PURE__ */ jsxs("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", "aria-hidden": "true", children: [
2778
+ /* @__PURE__ */ jsx("circle", { cx: "6", cy: "19", r: "2.4" }),
2779
+ /* @__PURE__ */ jsx("circle", { cx: "18", cy: "5", r: "2.4" }),
2780
+ /* @__PURE__ */ jsx("path", { d: "M8.4 19H15a3 3 0 0 0 0-6H9a3 3 0 0 1 0-6h6.6" })
2781
+ ] });
2782
+ }
2783
+ function CheckGlyph5() {
2784
+ return /* @__PURE__ */ jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "3", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" }) });
2785
+ }
2786
+ function FiatTile(props) {
2787
+ const fiat = FIAT.find((f) => f.code === props.currency) ?? FIAT[0];
2788
+ return /* @__PURE__ */ jsxs("div", { className: "sg-tile", style: { cursor: "default" }, children: [
2789
+ /* @__PURE__ */ jsx("span", { className: "sg-tile-label", children: props.label }),
2790
+ /* @__PURE__ */ jsxs("span", { className: "sg-tile-main", children: [
2791
+ /* @__PURE__ */ jsx("span", { className: "sg-fiat", children: fiat.glyph }),
2792
+ /* @__PURE__ */ jsxs("span", { style: { minWidth: 0, flex: 1 }, children: [
2793
+ /* @__PURE__ */ jsx("select", { className: "sg-select", style: { padding: "6px 8px", fontSize: 14, fontWeight: 700 }, value: fiat.code, disabled: props.disabled, onChange: (e) => props.onCurrency(e.target.value), "aria-label": `${props.label} currency`, children: FIAT.map((f) => /* @__PURE__ */ jsx("option", { value: f.code, children: f.code }, f.code)) }),
2794
+ /* @__PURE__ */ jsx("span", { className: "sg-tile-chain", children: fiat.label })
2795
+ ] })
2796
+ ] })
2797
+ ] });
2798
+ }
2799
+ function StableGenieExchange(props) {
2800
+ const config = useMergedConfig(props);
2801
+ const engine = useEngine({ apiBase: config.apiBase, apiKey: config.apiKey, trustedApiOrigin: config.trustedApiOrigin, rpcOverrides: config.rpcOverrides, onTransaction: config.onTransaction });
2802
+ const wallet = useWallet(config.provider);
2803
+ const mode = props.mode ?? "exchange";
2804
+ const wide = props.variant === "wide";
2805
+ const isPill = props.variant === "pill";
2806
+ const allowed = useMemo(() => (props.assets?.length ? props.assets : STABLE_ASSETS).map((a) => symbolKey(a)), [props.assets]);
2807
+ const [chains, setChains] = useState([]);
2808
+ const [tokens, setTokens] = useState([]);
2809
+ useEffect(() => {
2810
+ if (isPill) return;
2811
+ let alive = true;
2812
+ Promise.all([engine.fetchChains().catch(() => []), engine.fetchTokens().catch(() => [])]).then(([cs, ts]) => {
2813
+ if (!alive) return;
2814
+ const order = new Map(SUPPORTED_CHAINS.map((id, i) => [id, i]));
2815
+ setChains(
2816
+ cs.filter((c) => SUPPORTED_CHAIN_IDS.has(Number(c.chainId)) && c.isEnabled !== false).sort((a, b) => (order.get(Number(a.chainId)) ?? 99) - (order.get(Number(b.chainId)) ?? 99))
2817
+ );
2818
+ setTokens(ts.filter((t) => tokenEnabled(t) && SUPPORTED_CHAIN_IDS.has(Number(t.chainId)) && allowed.includes(symbolKey(t.symbol)) && isDeliverable(symbolKey(t.symbol), Number(t.chainId))));
2819
+ });
2820
+ return () => {
2821
+ alive = false;
2822
+ };
2823
+ }, [engine, allowed]);
2824
+ const [view, setView] = useState("main");
2825
+ const [hist, setHist] = useState(null);
2826
+ const histBtnRef = useRef(null);
2827
+ const closeHistory = () => {
2828
+ setHist(null);
2829
+ requestAnimationFrame(() => histBtnRef.current?.focus());
2830
+ };
2831
+ useEffect(() => setHist(null), [wallet.account]);
2832
+ const [from, setFrom] = useState(
2833
+ () => props.defaultFromChainId && props.defaultFromAsset && allowed.includes(symbolKey(props.defaultFromAsset)) ? { chainId: props.defaultFromChainId, symbol: symbolKey(props.defaultFromAsset) } : null
2834
+ );
2835
+ const [to, setTo] = useState(
2836
+ () => props.defaultToChainId && props.defaultToAsset && allowed.includes(symbolKey(props.defaultToAsset)) ? { chainId: props.defaultToChainId, symbol: symbolKey(props.defaultToAsset) } : null
2837
+ );
2838
+ const [amount, setAmount] = useState(props.defaultAmount ?? "");
2839
+ const [fiatCurrency, setFiatCurrency] = useState(props.fiatCurrency ?? "EUR");
2840
+ const fromToken = useMemo(() => from ? findToken(tokens, from.chainId, from.symbol) : null, [tokens, from]);
2841
+ const toToken = useMemo(() => to ? findToken(tokens, to.chainId, to.symbol) : null, [tokens, to]);
2842
+ const normalizedAmount = normalizeDecimalText(amount);
2843
+ const amountValid = /^\d+(\.\d+)?$/.test(normalizedAmount) && Number(normalizedAmount) > 0 && Number(normalizedAmount) <= 1e9;
2844
+ const rampMode = mode !== "exchange";
2845
+ const inUniverse = (p) => Boolean(p && allowed.includes(p.symbol));
2846
+ const cryptoReady = rampMode ? inUniverse(mode === "onramp" ? to : from) : inUniverse(from) && inUniverse(to);
2847
+ const quotable = mode === "exchange" && inUniverse(from) && inUniverse(to) && amountValid;
2848
+ const [balances, setBalances] = useState({});
2849
+ const balReq = useRef(0);
2850
+ useEffect(() => {
2851
+ if (isPill) return;
2852
+ setBalances({});
2853
+ if (!wallet.account || !tokens.length) return;
2854
+ const id = ++balReq.current;
2855
+ const targets = [];
2856
+ for (const t of tokens) {
2857
+ try {
2858
+ targets.push({ chainId: Number(t.chainId), tokenAddress: t.address, decimals: assetDecimals(t) });
2859
+ } catch {
2860
+ }
2861
+ }
2862
+ if (!targets.length) return;
2863
+ engine.readBalances(wallet.account, targets).then((res) => {
2864
+ if (id === balReq.current) setBalances(res);
2865
+ });
2866
+ }, [engine, wallet.account, tokens]);
2867
+ const fromBal = from && fromToken ? balances[balanceKey(from.chainId, fromToken.address)] : void 0;
2868
+ const paramsKey = `${mode}|${from?.chainId}|${from?.symbol}|${to?.chainId}|${to?.symbol}|${normalizedAmount}|${props.recipient ?? ""}`;
2869
+ const flow = useFlow({
2870
+ engine,
2871
+ wallet,
2872
+ kind: "swap",
2873
+ enabled: quotable && !isPill,
2874
+ paramsKey,
2875
+ loadPlan: (e, payer) => e.buildSwapPlan({ fromChainId: from.chainId, toChainId: to.chainId, fromToken: from.symbol, toToken: to.symbol, amountIn: normalizedAmount, recipient: props.recipient }, payer),
2876
+ recipientFor: (account) => props.recipient || account,
2877
+ onQuote: config.onQuote,
2878
+ onSuccess: config.onSuccess,
2879
+ onError: config.onError
2880
+ });
2881
+ const [preview, setPreview] = useState({ status: "idle" });
2882
+ const prevReq = useRef(0);
2883
+ useEffect(() => {
2884
+ if (isPill || wallet.account || !quotable) {
2885
+ prevReq.current += 1;
2886
+ setPreview({ status: "idle" });
2887
+ return;
2888
+ }
2889
+ const id = ++prevReq.current;
2890
+ setPreview({ status: "loading" });
2891
+ const timer = setTimeout(() => {
2892
+ engine.quoteSwapPreview({ fromChainId: from.chainId, toChainId: to.chainId, fromToken: from.symbol, toToken: to.symbol, amountIn: normalizedAmount, recipient: props.recipient }).then((data) => {
2893
+ if (id === prevReq.current) setPreview({ status: "ready", data });
2894
+ }).catch((e) => {
2895
+ if (id === prevReq.current) setPreview({ status: "error", error: e instanceof Error ? e.message : String(e) });
2896
+ });
2897
+ }, 350);
2898
+ return () => clearTimeout(timer);
2899
+ }, [engine, wallet.account, quotable, paramsKey]);
2900
+ const connected = Boolean(wallet.account);
2901
+ const submitting = flow.status === "submitting";
2902
+ const lastTxOwned = Boolean(flow.lastTxEntry?.hash && wallet.account && flow.lastTxEntry.account === wallet.account.toLowerCase());
2903
+ const quoting = connected ? flow.status === "loading" : preview.status === "loading";
2904
+ const quoteError = !quotable ? null : connected ? flow.status === "error" ? flow.error : null : preview.status === "error" ? preview.error ?? "No route." : null;
2905
+ const receive = connected ? flow.selected?.receive.amount : preview.data?.receive;
2906
+ const meta = connected ? flow.selected ? { bridge: flow.selected.quote.bridge || "ZeroDelta", feeBps: Number(flow.selected.quote.feeBps || 0), duration: Number(flow.selected.quote.estimatedDuration || 0) } : null : preview.data ? { bridge: preview.data.bridge || "ZeroDelta", feeBps: preview.data.feeBps, duration: preview.data.estimatedDuration } : null;
2907
+ const pct = (p) => {
2908
+ if (!fromBal || !fromToken) return;
2909
+ const raw = BigInt(fromBal.raw);
2910
+ setAmount(formatUnits(p === 100 ? raw : raw * BigInt(p) / 100n, assetDecimals(fromToken)));
2911
+ };
2912
+ const title = config.title || (mode === "onramp" ? "Buy stablecoins" : mode === "offramp" ? "Cash out" : "Exchange");
2913
+ const soonLabel = mode === "onramp" ? "On-ramp coming soon" : "Off-ramp coming soon";
2914
+ const ctaLabel = rampMode ? soonLabel : submitting ? "Exchanging\u2026" : flow.insufficient ? "Insufficient balance" : flow.nativeShortfall || "Exchange";
2915
+ const walletSlot = /* @__PURE__ */ jsxs("div", { className: "sg-head-tools", children: [
2916
+ connected ? /* @__PURE__ */ jsx(HistoryButton, { btnRef: histBtnRef, disabled: submitting, onClick: () => setHist({}) }) : null,
2917
+ /* @__PURE__ */ jsx("button", { type: "button", className: "sg-wallet", "data-connected": connected || void 0, onClick: connected ? void 0 : wallet.connect, disabled: wallet.connecting, children: connected ? /* @__PURE__ */ jsxs(Fragment, { children: [
2918
+ /* @__PURE__ */ jsx("span", { className: "sg-wallet-dot", "aria-hidden": "true" }),
2919
+ " ",
2920
+ shortAddress(wallet.account)
2921
+ ] }) : wallet.connecting ? "Connecting\u2026" : "Connect wallet" })
2922
+ ] });
2923
+ const fromTileRef = useRef(null);
2924
+ const toTileRef = useRef(null);
2925
+ const closeSelector = (isFrom) => {
2926
+ setView("main");
2927
+ requestAnimationFrame(() => (isFrom ? fromTileRef : toTileRef).current?.focus());
2928
+ };
2929
+ if (props.variant === "pill") return /* @__PURE__ */ jsx(PaymentIsland, { kind: "exchange", ...props });
2930
+ let body;
2931
+ if (hist && connected) {
2932
+ body = /* @__PURE__ */ jsx(TxHistoryPanel, { account: wallet.account, tokens, initialEntry: hist.entry ?? null, onBack: closeHistory });
2933
+ } else if (view === "from" || view === "to") {
2934
+ const isFrom = view === "from";
2935
+ body = /* @__PURE__ */ jsx(
2936
+ TokenSelect,
2937
+ {
2938
+ title: isFrom ? "Exchange from" : "Exchange to",
2939
+ chains,
2940
+ tokens,
2941
+ balances,
2942
+ onBack: () => closeSelector(isFrom),
2943
+ onPick: (pick) => {
2944
+ (isFrom ? setFrom : setTo)({ chainId: pick.chainId, symbol: symbolKey(pick.symbol) });
2945
+ closeSelector(isFrom);
2946
+ }
2947
+ }
2948
+ );
2949
+ } else if (flow.status === "success" || flow.status === "pending") {
2950
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
2951
+ /* @__PURE__ */ jsxs("div", { className: "sg-success", children: [
2952
+ /* @__PURE__ */ jsx("div", { className: "sg-success-check", "data-pending": flow.verdict?.status !== "confirmed", children: /* @__PURE__ */ jsx(CheckGlyph5, {}) }),
2953
+ /* @__PURE__ */ jsxs("div", { className: "sg-success-amt sg-mono", children: [
2954
+ receive,
2955
+ " ",
2956
+ to?.symbol
2957
+ ] }),
2958
+ /* @__PURE__ */ jsxs("div", { className: "sg-success-sub", children: [
2959
+ flow.verdict?.status === "confirmed" ? "Confirmed on-chain" : "Submitted \u2014 awaiting confirmation",
2960
+ props.recipient ? ` \xB7 ${shortAddress(props.recipient)}` : ""
2961
+ ] })
2962
+ ] }),
2963
+ /* @__PURE__ */ jsxs("div", { className: "sg-cta-wrap", children: [
2964
+ lastTxOwned ? /* @__PURE__ */ jsx(Button, { variant: "ghost", onClick: () => setHist({ entry: flow.lastTxEntry }), children: "View transaction" }) : null,
2965
+ /* @__PURE__ */ jsx(Button, { variant: "ghost", onClick: flow.reload, children: "Start a new exchange" })
2966
+ ] })
2967
+ ] });
2968
+ } else {
2969
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
2970
+ /* @__PURE__ */ jsxs("div", { className: "sg-ft", children: [
2971
+ mode === "onramp" ? /* @__PURE__ */ jsx(FiatTile, { label: "From", currency: fiatCurrency, onCurrency: setFiatCurrency }) : /* @__PURE__ */ jsx(TokenTile, { label: "From", pick: from, token: fromToken, disabled: submitting, btnRef: fromTileRef, onClick: () => setView("from") }),
2972
+ /* @__PURE__ */ jsx("span", { className: "sg-ft-arrow", "aria-hidden": "true", children: /* @__PURE__ */ jsx(ArrowGlyph2, {}) }),
2973
+ mode === "offramp" ? /* @__PURE__ */ jsx(FiatTile, { label: "To", currency: fiatCurrency, onCurrency: setFiatCurrency }) : /* @__PURE__ */ jsx(TokenTile, { label: "To", pick: to, token: toToken, disabled: submitting, btnRef: toTileRef, onClick: () => setView("to") })
2974
+ ] }),
2975
+ /* @__PURE__ */ jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
2976
+ /* @__PURE__ */ jsx("div", { className: "sg-label", children: mode === "onramp" ? `You pay (${fiatCurrency})` : "Send" }),
2977
+ /* @__PURE__ */ jsxs("div", { className: "sg-send-row", children: [
2978
+ mode === "onramp" ? /* @__PURE__ */ jsx("span", { className: "sg-fiat", children: FIAT.find((f) => f.code === fiatCurrency)?.glyph ?? "$" }) : from ? /* @__PURE__ */ jsx(TokenGlyph, { symbol: from.symbol, logoUrl: fromToken?.logoUrl, chainId: from.chainId, size: "sm" }) : null,
2979
+ /* @__PURE__ */ jsx(AmountInput, { value: amount, onChange: setAmount, disabled: submitting })
2980
+ ] }),
2981
+ mode !== "onramp" && fromBal ? /* @__PURE__ */ jsxs("div", { className: "sg-send-bal sg-mono", children: [
2982
+ "Balance: ",
2983
+ fromBal.formatted,
2984
+ " ",
2985
+ from?.symbol
2986
+ ] }) : null,
2987
+ mode !== "onramp" ? (
2988
+ // a11y note: <fieldset> carries UA styling that would
2989
+ // have to be reset on every host page; role="group" gives the same semantics.
2990
+ /* @__PURE__ */ jsx("div", { className: "sg-pct-row", role: "group", "aria-label": "Amount shortcuts", children: [25, 50, 75, 100].map((p) => /* @__PURE__ */ jsx("button", { type: "button", className: "sg-pct", disabled: !fromBal || submitting, onClick: () => pct(p), children: p === 100 ? "MAX" : `${p}%` }, p)) })
2991
+ ) : null
2992
+ ] }),
2993
+ rampMode ? /* @__PURE__ */ jsx(StatusPanel, { children: mode === "onramp" ? "Buy supported stablecoins with card or bank transfer \u2014 coming soon. Today the widget settles crypto-to-crypto." : "Cash out supported stablecoins to your bank \u2014 coming soon. Today the widget settles crypto-to-crypto." }) : null,
2994
+ !rampMode && quoteError && !wide ? /* @__PURE__ */ jsx(StatusPanel, { tone: "error", children: quoteError }) : null,
2995
+ !rampMode && !wide && quotable && !quoteError ? /* @__PURE__ */ jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
2996
+ /* @__PURE__ */ jsx("div", { className: "sg-label", children: "You receive (estimated)" }),
2997
+ /* @__PURE__ */ jsx("div", { className: "sg-anchor sg-mono", children: quoting ? "\u2026" : receive ? `${receive} ${to?.symbol}` : "\u2014" }),
2998
+ meta && !quoting ? /* @__PURE__ */ jsxs("div", { className: "sg-recv-sub", children: [
2999
+ "via ",
3000
+ meta.bridge,
3001
+ " \xB7 fee ",
3002
+ meta.feeBps,
3003
+ " bps",
3004
+ meta.duration ? ` \xB7 ~${meta.duration}s` : ""
3005
+ ] }) : null
3006
+ ] }) : null,
3007
+ submitting ? /* @__PURE__ */ jsx(StepList, { steps: flow.steps }) : null,
3008
+ /* @__PURE__ */ jsxs("div", { className: "sg-cta-wrap", children: [
3009
+ !connected && !rampMode ? /* @__PURE__ */ jsx(Button, { onClick: wallet.connect, busy: wallet.connecting, children: "Connect wallet" }) : /* @__PURE__ */ jsx(Button, { onClick: rampMode ? void 0 : flow.submit, busy: submitting, disabled: rampMode || !quotable || !cryptoReady || connected && (!flow.selected || flow.insufficient || !!flow.nativeShortfall || flow.status === "loading"), children: ctaLabel }),
3010
+ wallet.error ? /* @__PURE__ */ jsx(StatusPanel, { tone: "error", children: wallet.error }) : null
3011
+ ] })
3012
+ ] });
3013
+ }
3014
+ const card = /* @__PURE__ */ jsx(WidgetShell, { title, theme: config.theme, heightPx: props.heightPx, walletSlot, children: body });
3015
+ if (!wide) return card;
3016
+ const resolved = resolveTheme(config.theme);
3017
+ const vars = themeToVars(resolved);
3018
+ let side;
3019
+ if (rampMode) {
3020
+ side = /* @__PURE__ */ jsxs("div", { className: "sg-noroutes", children: [
3021
+ /* @__PURE__ */ jsx("span", { className: "sg-noroutes-icon", children: /* @__PURE__ */ jsx(RouteGlyph, {}) }),
3022
+ /* @__PURE__ */ jsx("div", { className: "sg-noroutes-title", children: soonLabel }),
3023
+ /* @__PURE__ */ jsx("div", { className: "sg-noroutes-sub", children: "Fiat rails are on the roadmap. Crypto-to-crypto exchange is live today." })
3024
+ ] });
3025
+ } else if (quoting) {
3026
+ side = /* @__PURE__ */ jsxs("div", { children: [
3027
+ /* @__PURE__ */ jsx("div", { className: "sg-skel" }),
3028
+ /* @__PURE__ */ jsx("div", { className: "sg-skel" }),
3029
+ /* @__PURE__ */ jsxs("div", { className: "sg-muted", style: { fontSize: 13 }, children: [
3030
+ /* @__PURE__ */ jsx("span", { className: "sg-spinner" }),
3031
+ " Finding routes\u2026"
3032
+ ] })
3033
+ ] });
3034
+ } else if (quoteError) {
3035
+ side = /* @__PURE__ */ jsxs("div", { className: "sg-noroutes", children: [
3036
+ /* @__PURE__ */ jsx("span", { className: "sg-noroutes-icon", children: /* @__PURE__ */ jsx(RouteGlyph, {}) }),
3037
+ /* @__PURE__ */ jsx("div", { className: "sg-noroutes-title", children: "No routes available" }),
3038
+ /* @__PURE__ */ jsx("div", { className: "sg-noroutes-sub", children: "Reasons for that could be: low liquidity, amount selected is too low, gas costs are too high or there are no routes for the selected combination." })
3039
+ ] });
3040
+ } else if (receive && quotable) {
3041
+ side = /* @__PURE__ */ jsxs("div", { children: [
3042
+ /* @__PURE__ */ jsxs("div", { className: "sg-recv-amt sg-mono", children: [
3043
+ receive,
3044
+ " ",
3045
+ to?.symbol
3046
+ ] }),
3047
+ /* @__PURE__ */ jsxs("div", { className: "sg-recv-sub", children: [
3048
+ "on ",
3049
+ CHAIN_LABELS[to?.chainId ?? 0] || `Chain ${to?.chainId}`
3050
+ ] }),
3051
+ /* @__PURE__ */ jsxs("div", { className: "sg-meta", children: [
3052
+ /* @__PURE__ */ jsxs("div", { className: "sg-meta-row", children: [
3053
+ /* @__PURE__ */ jsx("span", { className: "sg-meta-label", children: "You send" }),
3054
+ /* @__PURE__ */ jsxs("b", { className: "sg-mono", children: [
3055
+ normalizedAmount,
3056
+ " ",
3057
+ from?.symbol
3058
+ ] })
3059
+ ] }),
3060
+ /* @__PURE__ */ jsxs("div", { className: "sg-meta-row", children: [
3061
+ /* @__PURE__ */ jsx("span", { className: "sg-meta-label", children: "Route" }),
3062
+ /* @__PURE__ */ jsx("b", { children: meta?.bridge || "ZeroDelta" })
3063
+ ] }),
3064
+ /* @__PURE__ */ jsxs("div", { className: "sg-meta-row", children: [
3065
+ /* @__PURE__ */ jsx("span", { className: "sg-meta-label", children: "Fee" }),
3066
+ /* @__PURE__ */ jsxs("b", { children: [
3067
+ meta?.feeBps ?? 0,
3068
+ " bps"
3069
+ ] })
3070
+ ] }),
3071
+ meta?.duration ? /* @__PURE__ */ jsxs("div", { className: "sg-meta-row", children: [
3072
+ /* @__PURE__ */ jsx("span", { className: "sg-meta-label", children: "Est. time" }),
3073
+ /* @__PURE__ */ jsxs("b", { children: [
3074
+ "~",
3075
+ meta.duration,
3076
+ "s"
3077
+ ] })
3078
+ ] }) : null
3079
+ ] })
3080
+ ] });
3081
+ } else {
3082
+ side = /* @__PURE__ */ jsxs("div", { className: "sg-noroutes", children: [
3083
+ /* @__PURE__ */ jsx("span", { className: "sg-noroutes-icon", children: /* @__PURE__ */ jsx(RouteGlyph, {}) }),
3084
+ /* @__PURE__ */ jsx("div", { className: "sg-noroutes-title", children: "Routes appear here" }),
3085
+ /* @__PURE__ */ jsx("div", { className: "sg-noroutes-sub", children: "Pick the tokens and enter an amount to see how ZeroDelta will route it." })
3086
+ ] });
3087
+ }
3088
+ return /* @__PURE__ */ jsx("div", { className: "sg-duo-wrap", "data-sg-mode": resolved.mode, style: vars, children: /* @__PURE__ */ jsxs("div", { className: "sg-duo", children: [
3089
+ card,
3090
+ /* @__PURE__ */ jsxs("div", { className: "sg-widget", "data-sg-mode": resolved.mode, style: props.heightPx ? { height: props.heightPx } : void 0, children: [
3091
+ /* @__PURE__ */ jsx("div", { className: "sg-side-title", children: "Receive" }),
3092
+ side
3093
+ ] })
3094
+ ] }) });
3095
+ }
3096
+
3097
+ // src/mount.ts
3098
+ function mount(el, config) {
3099
+ const root = createRoot(el);
3100
+ const variant = config.variant ?? "pay";
3101
+ const Comp = variant === "swap" ? StableGenieSwap : variant === "exchange" ? StableGenieExchange : StableGeniePay;
3102
+ const { variant: _variant, ...props } = config;
3103
+ root.render(createElement(Comp, props));
3104
+ return () => root.unmount();
3105
+ }
3106
+
3107
+ export { PaymentIsland, StableGenieExchange, StableGeniePay, StableGenieProvider, StableGenieSwap, darkTheme, lightTheme, mount, resolveTheme };