@glacislabs/stablegenie-zerodelta 3.0.1 → 3.1.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.
package/README.md CHANGED
@@ -12,7 +12,7 @@ submits silently. Every ZeroDelta quote is re-validated (`assertQuoteMatchesSele
12
12
  planned transaction is re-decoded before signing (`validatePlannedTransaction`), and the settling
13
13
  transaction is confirmed on-chain in a trusted realm (`verifySubmittedTx`).
14
14
 
15
- Supported chains: Ethereum, Optimism, Arbitrum, Base, Ink, Unichain, Plasma, Sonic.
15
+ Supported chains: Ethereum, Optimism, Arbitrum, Base, Ink, Unichain, Plasma, Sonic, Plume.
16
16
  Supported assets: USDC, USDT, USDE, XAUT. (Card/fiat rails are roadmap, not shipped.)
17
17
 
18
18
  ## Install (React host)
@@ -1,4 +1,4 @@
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';
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-OOURZ5DL.js';
2
2
  import { createContext, useMemo, useState, useEffect, useRef, useCallback, useId, createElement, useContext } from 'react';
3
3
  import { createRoot } from 'react-dom/client';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -501,7 +501,7 @@ function useFlow(args) {
501
501
  function balanceKey(chainId, tokenAddress) {
502
502
  return `${Number(chainId)}:${String(tokenAddress || "").toLowerCase()}`;
503
503
  }
504
- function useHoldings(engine, account, routes) {
504
+ function useHoldings(engine, account, routes, initialBalances) {
505
505
  const [balances, setBalances] = useState({});
506
506
  const [loading, setLoading] = useState(false);
507
507
  const reqId = useRef(0);
@@ -526,19 +526,32 @@ function useHoldings(engine, account, routes) {
526
526
  return;
527
527
  }
528
528
  const id = ++reqId.current;
529
+ const seeded = {};
530
+ const missing = [];
531
+ for (const target of targets) {
532
+ const key = balanceKey(target.chainId, target.tokenAddress);
533
+ const balance = initialBalances?.[key];
534
+ if (balance) seeded[key] = balance;
535
+ else missing.push(target);
536
+ }
537
+ setBalances(seeded);
538
+ if (!missing.length) {
539
+ setLoading(false);
540
+ return;
541
+ }
529
542
  setLoading(true);
530
543
  (async () => {
531
544
  try {
532
- const res = await engine.readBalances(account, targets);
545
+ const res = await engine.readBalances(account, missing);
533
546
  if (id !== reqId.current) return;
534
- setBalances(res);
547
+ setBalances({ ...seeded, ...res });
535
548
  } catch {
536
- if (id === reqId.current) setBalances({});
549
+ if (id === reqId.current) setBalances(seeded);
537
550
  } finally {
538
551
  if (id === reqId.current) setLoading(false);
539
552
  }
540
553
  })();
541
- }, [engine, account, targetsKey]);
554
+ }, [engine, account, targetsKey, initialBalances]);
542
555
  return { balances, loading };
543
556
  }
544
557
 
@@ -1082,9 +1095,10 @@ var CHAIN_LABELS = {
1082
1095
  8453: "Base",
1083
1096
  9745: "Plasma",
1084
1097
  57073: "Ink",
1085
- 42161: "Arbitrum"
1098
+ 42161: "Arbitrum",
1099
+ 98866: "Plume"
1086
1100
  };
1087
- var SUPPORTED_CHAINS = [1, 10, 42161, 8453, 57073, 130, 9745, 146];
1101
+ var SUPPORTED_CHAINS = [1, 10, 42161, 8453, 57073, 130, 9745, 146, 98866];
1088
1102
  var SUPPORTED_ASSETS2 = ["USDC", "USDT", "USDE", "XAUT"];
1089
1103
  function Button(props) {
1090
1104
  const soft = !!props.softDisabled && !props.disabled;
@@ -1283,7 +1297,8 @@ var CHAIN_SHORT = {
1283
1297
  8453: "BASE",
1284
1298
  9745: "PLS",
1285
1299
  57073: "INK",
1286
- 42161: "ARB"
1300
+ 42161: "ARB",
1301
+ 98866: "PLM"
1287
1302
  };
1288
1303
  function isHttpsUrl(u) {
1289
1304
  return typeof u === "string" && /^https:\/\//i.test(u);
@@ -1677,7 +1692,21 @@ var addrEq = (a, b) => String(a || "").toLowerCase() === String(b || "").toLower
1677
1692
  var chainName = (id) => id != null ? CHAIN_LABELS[id] || `Chain ${id}` : "";
1678
1693
  var STABLES = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE"]);
1679
1694
  function BankGlyph() {
1680
- 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" }) });
1695
+ return /* @__PURE__ */ jsx(
1696
+ "svg",
1697
+ {
1698
+ width: "18",
1699
+ height: "18",
1700
+ viewBox: "0 0 24 24",
1701
+ fill: "none",
1702
+ stroke: "currentColor",
1703
+ strokeWidth: "2",
1704
+ strokeLinecap: "round",
1705
+ strokeLinejoin: "round",
1706
+ "aria-hidden": "true",
1707
+ children: /* @__PURE__ */ jsx("path", { d: "M3 10h18M5 10v8M10 10v8M14 10v8M19 10v8M3 19h18M12 3 3 8h18Z" })
1708
+ }
1709
+ );
1681
1710
  }
1682
1711
  function MerchantBankPayout(props) {
1683
1712
  const bankName = props.account?.bankName?.trim() || "Bank account";
@@ -1704,25 +1733,81 @@ function MerchantBankPayout(props) {
1704
1733
  ] }) }) });
1705
1734
  }
1706
1735
  function CheckGlyph2() {
1707
- 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" }) });
1736
+ return /* @__PURE__ */ jsx(
1737
+ "svg",
1738
+ {
1739
+ width: "20",
1740
+ height: "20",
1741
+ viewBox: "0 0 24 24",
1742
+ fill: "none",
1743
+ stroke: "currentColor",
1744
+ strokeWidth: "3",
1745
+ strokeLinecap: "round",
1746
+ strokeLinejoin: "round",
1747
+ "aria-hidden": "true",
1748
+ children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" })
1749
+ }
1750
+ );
1708
1751
  }
1709
1752
  function ArrowGlyph() {
1710
- 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: [
1711
- /* @__PURE__ */ jsx("path", { d: "M5 12h14" }),
1712
- /* @__PURE__ */ jsx("path", { d: "m13 6 6 6-6 6" })
1713
- ] });
1753
+ return /* @__PURE__ */ jsxs(
1754
+ "svg",
1755
+ {
1756
+ width: "14",
1757
+ height: "14",
1758
+ viewBox: "0 0 24 24",
1759
+ fill: "none",
1760
+ stroke: "currentColor",
1761
+ strokeWidth: "2.4",
1762
+ strokeLinecap: "round",
1763
+ strokeLinejoin: "round",
1764
+ "aria-hidden": "true",
1765
+ children: [
1766
+ /* @__PURE__ */ jsx("path", { d: "M5 12h14" }),
1767
+ /* @__PURE__ */ jsx("path", { d: "m13 6 6 6-6 6" })
1768
+ ]
1769
+ }
1770
+ );
1714
1771
  }
1715
1772
  function ClockGlyph() {
1716
- 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: [
1717
- /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "9" }),
1718
- /* @__PURE__ */ jsx("path", { d: "M12 7v5l3 2" })
1719
- ] });
1773
+ return /* @__PURE__ */ jsxs(
1774
+ "svg",
1775
+ {
1776
+ width: "20",
1777
+ height: "20",
1778
+ viewBox: "0 0 24 24",
1779
+ fill: "none",
1780
+ stroke: "currentColor",
1781
+ strokeWidth: "2.2",
1782
+ strokeLinecap: "round",
1783
+ strokeLinejoin: "round",
1784
+ "aria-hidden": "true",
1785
+ children: [
1786
+ /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "9" }),
1787
+ /* @__PURE__ */ jsx("path", { d: "M12 7v5l3 2" })
1788
+ ]
1789
+ }
1790
+ );
1720
1791
  }
1721
1792
  function WalletGlyph() {
1722
- 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: [
1723
- /* @__PURE__ */ jsx("rect", { x: "3", y: "6", width: "18", height: "13", rx: "2" }),
1724
- /* @__PURE__ */ jsx("path", { d: "M16 12h.01M3 9h18" })
1725
- ] });
1793
+ return /* @__PURE__ */ jsxs(
1794
+ "svg",
1795
+ {
1796
+ width: "16",
1797
+ height: "16",
1798
+ viewBox: "0 0 24 24",
1799
+ fill: "none",
1800
+ stroke: "currentColor",
1801
+ strokeWidth: "2",
1802
+ strokeLinecap: "round",
1803
+ strokeLinejoin: "round",
1804
+ "aria-hidden": "true",
1805
+ children: [
1806
+ /* @__PURE__ */ jsx("rect", { x: "3", y: "6", width: "18", height: "13", rx: "2" }),
1807
+ /* @__PURE__ */ jsx("path", { d: "M16 12h.01M3 9h18" })
1808
+ ]
1809
+ }
1810
+ );
1726
1811
  }
1727
1812
  function LinkMenu(props) {
1728
1813
  const [open, setOpen] = useState(false);
@@ -1833,7 +1918,13 @@ function IdentityLine(props) {
1833
1918
  function PaymentIsland(props) {
1834
1919
  injectStyles();
1835
1920
  const config = useMergedConfig(props);
1836
- const engine = useEngine({ apiBase: config.apiBase, apiKey: config.apiKey, trustedApiOrigin: config.trustedApiOrigin, rpcOverrides: config.rpcOverrides, onTransaction: config.onTransaction });
1921
+ const engine = useEngine({
1922
+ apiBase: config.apiBase,
1923
+ apiKey: config.apiKey,
1924
+ trustedApiOrigin: config.trustedApiOrigin,
1925
+ rpcOverrides: config.rpcOverrides,
1926
+ onTransaction: config.onTransaction
1927
+ });
1837
1928
  const wallet = useWallet(config.provider);
1838
1929
  const kind = props.kind;
1839
1930
  const isPay = kind === "pay";
@@ -1862,7 +1953,8 @@ function PaymentIsland(props) {
1862
1953
  const normEx = normalizeDecimalText(exAmount);
1863
1954
  const exAmountValid = /^\d+(\.\d+)?$/.test(normEx) && Number(normEx) > 0 && Number(normEx) <= 1e9;
1864
1955
  const exQuotable = !rampMode && exAmountValid && Boolean(exFromChainId && exFromAsset && exToChainId && exToAsset);
1865
- const payParamsKey = `pay|${props.recipient}|${props.toChainId}|${props.toAsset}|${props.amount}`;
1956
+ const payFundingAssets = props.fundingAssets?.length ? props.fundingAssets : ["USDC", "USDT", "USDE"];
1957
+ const payParamsKey = `pay|${props.recipient}|${props.toChainId}|${props.toAsset}|${props.amount}|${payFundingAssets.join(",")}`;
1866
1958
  const exParamsKey = `${kind}|${mode}|${exFromChainId}|${exFromAsset}|${exToChainId}|${exToAsset}|${normEx}|${props.recipient ?? ""}`;
1867
1959
  const flow = useFlow({
1868
1960
  engine,
@@ -1872,7 +1964,20 @@ function PaymentIsland(props) {
1872
1964
  // quote (and fire onQuote) for a payment whose CTA it never shows.
1873
1965
  enabled: isPay ? Boolean(props.recipient && props.amount) && !bankSettlement : exQuotable,
1874
1966
  paramsKey: isPay ? payParamsKey : exParamsKey,
1875
- 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),
1967
+ loadPlan: isPay ? (e, payer, chainId) => e.fetchPaymentPlan({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, payer, {
1968
+ chainId,
1969
+ fundingAssets: payFundingAssets
1970
+ }) : (e, payer) => e.buildSwapPlan(
1971
+ {
1972
+ fromChainId: exFromChainId,
1973
+ toChainId: exToChainId,
1974
+ fromToken: exFromAsset,
1975
+ toToken: exToAsset,
1976
+ amountIn: normEx,
1977
+ recipient: props.recipient
1978
+ },
1979
+ payer
1980
+ ),
1876
1981
  recipientFor: (account) => isPay ? props.recipient : props.recipient || account,
1877
1982
  onQuote: config.onQuote,
1878
1983
  onSuccess: config.onSuccess,
@@ -1880,15 +1985,14 @@ function PaymentIsland(props) {
1880
1985
  });
1881
1986
  const [method, setMethod] = useState("stablecoin");
1882
1987
  const parked = isPay && !isLiveMethod(method);
1883
- const fundingSet = useMemo(
1884
- () => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null,
1885
- [props.fundingAssets]
1886
- );
1988
+ const fundingSet = useMemo(() => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null, [props.fundingAssets]);
1887
1989
  const visibleRoutes = useMemo(() => {
1888
1990
  const base = fundingSet ? flow.routes.filter((r) => fundingSet.has(r.source.asset.toUpperCase()) || r.state === "DIRECT") : flow.routes;
1889
- return isPay && method === "stablecoin" ? base.filter((r) => STABLES.has(r.source.asset)) : base;
1991
+ return isPay && method === "stablecoin" ? base.filter((r) => STABLES.has(symbolKey(r.source.asset))) : base;
1890
1992
  }, [flow.routes, fundingSet, isPay, method]);
1891
- const holdings = useHoldings(engine, wallet.account, flow.routes);
1993
+ const paymentPlan = flow.plan;
1994
+ const prefetchedBalances = paymentPlan && paymentPlan.fundingAccount === wallet.account?.toLowerCase() ? paymentPlan.fundingBalances : void 0;
1995
+ const holdings = useHoldings(engine, wallet.account, flow.routes, prefetchedBalances);
1892
1996
  const annotated = useMemo(
1893
1997
  () => visibleRoutes.map((r) => {
1894
1998
  const balance = holdings.balances[balanceKey(r.source.chainId, r.source.tokenAddress)];
@@ -1983,7 +2087,15 @@ function PaymentIsland(props) {
1983
2087
  if (seen.has(key)) continue;
1984
2088
  seen.add(key);
1985
2089
  const reg = registryTokens.find((t) => Number(t.chainId) === r.source.chainId && addrEq(t.address, r.source.tokenAddress));
1986
- list.push(reg ?? { symbol: r.source.asset, name: r.source.asset, chainId: r.source.chainId, address: r.source.tokenAddress ?? "", decimals: r.source.decimals ?? 18 });
2090
+ list.push(
2091
+ reg ?? {
2092
+ symbol: r.source.asset,
2093
+ name: r.source.asset,
2094
+ chainId: r.source.chainId,
2095
+ address: r.source.tokenAddress ?? "",
2096
+ decimals: r.source.decimals ?? 18
2097
+ }
2098
+ );
1987
2099
  }
1988
2100
  return list;
1989
2101
  }, [visibleRoutes, registryTokens]);
@@ -2193,7 +2305,18 @@ function PaymentIsland(props) {
2193
2305
  if (hist && wallet.account) {
2194
2306
  body = /* @__PURE__ */ jsx(TxHistoryPanel, { account: wallet.account, tokens: registryTokens, initialEntry: hist.entry ?? null, onBack: closeHistory });
2195
2307
  } else if (isPay && view === "select" && wallet.account) {
2196
- body = /* @__PURE__ */ jsx(TokenSelect, { title: "Pay with", chains: fundingChains, tokens: fundingTokens, balances: holdings.balances, optionStates, onBack: () => closeSelector(), onPick: pickFunding });
2308
+ body = /* @__PURE__ */ jsx(
2309
+ TokenSelect,
2310
+ {
2311
+ title: "Pay with",
2312
+ chains: fundingChains,
2313
+ tokens: fundingTokens,
2314
+ balances: holdings.balances,
2315
+ optionStates,
2316
+ onBack: () => closeSelector(),
2317
+ onPick: pickFunding
2318
+ }
2319
+ );
2197
2320
  } else if (!isPay && (view === "from" || view === "to")) {
2198
2321
  const isFrom = view === "from";
2199
2322
  const openerRef = isFrom ? exFromTileRef : exToTileRef;
@@ -2393,22 +2516,66 @@ function PaymentIsland(props) {
2393
2516
  const islandVars = themeToVars(resolved);
2394
2517
  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: [
2395
2518
  pillFace,
2396
- /* @__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: [
2397
- /* @__PURE__ */ jsx("span", { className: "sg-sr-only", role: "status", "aria-live": "polite", children: liveMsg }),
2398
- body
2399
- ] }) : null }) }) })
2519
+ /* @__PURE__ */ jsx("div", { className: "sg-island-reveal", children: /* @__PURE__ */ jsx("div", { className: "sg-island-reveal-inner", children: /* @__PURE__ */ jsx(
2520
+ "div",
2521
+ {
2522
+ className: "sg-island-body",
2523
+ id: panelId,
2524
+ ref: regionRef,
2525
+ role: "region",
2526
+ "aria-label": isPay ? "ZeroDelta Link checkout" : `ZeroDelta Link ${verb.present.toLowerCase()}`,
2527
+ tabIndex: -1,
2528
+ children: expanded ? /* @__PURE__ */ jsxs(
2529
+ WidgetShell,
2530
+ {
2531
+ variant: "express",
2532
+ title: "ZeroDelta Link",
2533
+ theme: config.theme,
2534
+ heightPx: props.heightPx,
2535
+ brandSlot,
2536
+ walletSlot,
2537
+ children: [
2538
+ /* @__PURE__ */ jsx("span", { className: "sg-sr-only", role: "status", "aria-live": "polite", children: liveMsg }),
2539
+ body
2540
+ ]
2541
+ }
2542
+ ) : null
2543
+ }
2544
+ ) }) })
2400
2545
  ] }) });
2401
2546
  }
2402
2547
  var STABLES2 = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE"]);
2548
+ var DEFAULT_FUNDING_ASSETS = ["USDC", "USDT", "USDE"];
2403
2549
  function CheckGlyph3() {
2404
- 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" }) });
2550
+ return /* @__PURE__ */ jsx(
2551
+ "svg",
2552
+ {
2553
+ width: "20",
2554
+ height: "20",
2555
+ viewBox: "0 0 24 24",
2556
+ fill: "none",
2557
+ stroke: "currentColor",
2558
+ strokeWidth: "3",
2559
+ strokeLinecap: "round",
2560
+ strokeLinejoin: "round",
2561
+ "aria-hidden": "true",
2562
+ children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" })
2563
+ }
2564
+ );
2405
2565
  }
2406
2566
  var addrEq2 = (a, b) => String(a || "").toLowerCase() === String(b || "").toLowerCase();
2407
2567
  function StableGeniePay(props) {
2408
2568
  const config = useMergedConfig(props);
2409
- const engine = useEngine({ apiBase: config.apiBase, apiKey: config.apiKey, trustedApiOrigin: config.trustedApiOrigin, rpcOverrides: config.rpcOverrides, onTransaction: config.onTransaction });
2569
+ const engine = useEngine({
2570
+ apiBase: config.apiBase,
2571
+ apiKey: config.apiKey,
2572
+ trustedApiOrigin: config.trustedApiOrigin,
2573
+ rpcOverrides: config.rpcOverrides,
2574
+ onTransaction: config.onTransaction
2575
+ });
2410
2576
  const wallet = useWallet(config.provider);
2411
- const paramsKey = `${props.recipient}|${props.toChainId}|${props.toAsset}|${props.amount}`;
2577
+ const planFundingAssets = props.fundingAssets?.length ? props.fundingAssets : DEFAULT_FUNDING_ASSETS;
2578
+ const paramsKey = `${props.recipient}|${props.toChainId}|${props.toAsset}|${props.amount}|${planFundingAssets.join(",")}`;
2412
2579
  const flow = useFlow({
2413
2580
  engine,
2414
2581
  wallet,
@@ -2417,22 +2584,24 @@ function StableGeniePay(props) {
2417
2584
  // network work here, or every quote / balance read fires twice and onQuote/onError double-fire.
2418
2585
  enabled: Boolean(props.recipient && props.amount) && props.variant !== "pill",
2419
2586
  paramsKey,
2420
- loadPlan: (e, payer, chainId) => e.fetchPaymentPlan({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, payer, { chainId }),
2587
+ loadPlan: (e, payer, chainId) => e.fetchPaymentPlan({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, payer, {
2588
+ chainId,
2589
+ fundingAssets: planFundingAssets
2590
+ }),
2421
2591
  recipientFor: () => props.recipient,
2422
2592
  onQuote: config.onQuote,
2423
2593
  onSuccess: config.onSuccess,
2424
2594
  onError: config.onError
2425
2595
  });
2426
2596
  const [method, setMethod] = useState("stablecoin");
2427
- const fundingSet = useMemo(
2428
- () => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null,
2429
- [props.fundingAssets]
2430
- );
2597
+ const fundingSet = useMemo(() => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null, [props.fundingAssets]);
2431
2598
  const visibleRoutes = useMemo(() => {
2432
2599
  const base = fundingSet ? flow.routes.filter((r) => fundingSet.has(r.source.asset.toUpperCase()) || r.state === "DIRECT") : flow.routes;
2433
- return method === "stablecoin" ? base.filter((r) => STABLES2.has(r.source.asset)) : base;
2600
+ return method === "stablecoin" ? base.filter((r) => STABLES2.has(symbolKey(r.source.asset))) : base;
2434
2601
  }, [flow.routes, method, fundingSet]);
2435
- const holdings = useHoldings(engine, wallet.account, flow.routes);
2602
+ const paymentPlan = flow.plan;
2603
+ const prefetchedBalances = paymentPlan && paymentPlan.fundingAccount === wallet.account?.toLowerCase() ? paymentPlan.fundingBalances : void 0;
2604
+ const holdings = useHoldings(engine, wallet.account, flow.routes, prefetchedBalances);
2436
2605
  const annotated = useMemo(
2437
2606
  () => visibleRoutes.map((r) => {
2438
2607
  const balance = holdings.balances[balanceKey(r.source.chainId, r.source.tokenAddress)];
@@ -2506,7 +2675,15 @@ function StableGeniePay(props) {
2506
2675
  if (seen.has(key)) continue;
2507
2676
  seen.add(key);
2508
2677
  const reg = registryTokens.find((t) => Number(t.chainId) === r.source.chainId && addrEq2(t.address, r.source.tokenAddress));
2509
- list.push(reg ?? { symbol: r.source.asset, name: r.source.asset, chainId: r.source.chainId, address: r.source.tokenAddress ?? "", decimals: r.source.decimals ?? 18 });
2678
+ list.push(
2679
+ reg ?? {
2680
+ symbol: r.source.asset,
2681
+ name: r.source.asset,
2682
+ chainId: r.source.chainId,
2683
+ address: r.source.tokenAddress ?? "",
2684
+ decimals: r.source.decimals ?? 18
2685
+ }
2686
+ );
2510
2687
  }
2511
2688
  return list;
2512
2689
  }, [visibleRoutes, registryTokens]);
@@ -2588,7 +2765,18 @@ function StableGeniePay(props) {
2588
2765
  ] })
2589
2766
  ] }) : void 0;
2590
2767
  if (props.variant === "pill") return /* @__PURE__ */ jsx(PaymentIsland, { kind: "pay", ...props });
2591
- 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__ */ jsx(Fragment, { children: !wallet.account ? /* @__PURE__ */ jsxs("div", { className: "sg-cta-wrap", children: [
2768
+ 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(
2769
+ TokenSelect,
2770
+ {
2771
+ title: "Pay with",
2772
+ chains: fundingChains,
2773
+ tokens: fundingTokens,
2774
+ balances: holdings.balances,
2775
+ optionStates,
2776
+ onBack: closeSelector,
2777
+ onPick: pickFunding
2778
+ }
2779
+ ) : /* @__PURE__ */ jsx(Fragment, { children: !wallet.account ? /* @__PURE__ */ jsxs("div", { className: "sg-cta-wrap", children: [
2592
2780
  /* @__PURE__ */ jsx(Button, { onClick: wallet.connect, busy: wallet.connecting, children: "Connect wallet" }),
2593
2781
  wallet.error ? /* @__PURE__ */ jsx(StatusPanel, { tone: "error", children: wallet.error }) : null
2594
2782
  ] }) : flow.status === "success" || flow.status === "pending" ? /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -2646,7 +2834,15 @@ function StableGeniePay(props) {
2646
2834
  flow.status === "ready" && !visibleRoutes.length ? /* @__PURE__ */ jsx(StatusPanel, { children: "No funding route matches the accepted assets for this payment." }) : null
2647
2835
  ] }),
2648
2836
  submitting ? /* @__PURE__ */ jsx(StepList, { steps: flow.steps }) : null,
2649
- /* @__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 }) })
2837
+ /* @__PURE__ */ jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsx(
2838
+ Button,
2839
+ {
2840
+ onClick: parked || !selectedVisible ? void 0 : flow.submit,
2841
+ busy: submitting,
2842
+ disabled: parked || !selectedVisible || flow.insufficient || !!flow.nativeShortfall || flow.status === "loading",
2843
+ children: payLabel
2844
+ }
2845
+ ) })
2650
2846
  ] }) }) });
2651
2847
  }
2652
2848
  var chainOptions = SUPPORTED_CHAINS.map((c) => ({ value: c, label: CHAIN_LABELS[c] || `Chain ${c}` }));