@glacislabs/stablegenie-zerodelta 4.10.0 → 4.12.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/dist/mount.cjs CHANGED
@@ -1717,7 +1717,7 @@ var CHANNEL_HEADER = "x-zd-channel";
1717
1717
  var CHANNEL_VERSION_HEADER = "x-zd-channel-version";
1718
1718
  var CHANNEL_ORIGIN_HEADER = "x-zd-channel-origin";
1719
1719
  var WIDGET_CHANNEL = "widget";
1720
- var WIDGET_VERSION = "4.10.0" ;
1720
+ var WIDGET_VERSION = "4.12.0" ;
1721
1721
  var MAX_CHANNEL_VERSION_LEN = 32;
1722
1722
  function sanitizeVersion(raw) {
1723
1723
  const v = String(raw).trim();
@@ -1988,6 +1988,7 @@ function createApiClient(cfg) {
1988
1988
  const missing = wanted.filter((s) => !nowFresh(priceCache.get(s) ?? null));
1989
1989
  if (missing.length) {
1990
1990
  let prices = {};
1991
+ let answered = true;
1991
1992
  try {
1992
1993
  const snapshot = await apiRequest(`/prices?symbols=${encodeURIComponent(missing.join(","))}`, {
1993
1994
  timeoutMs: 8e3
@@ -1995,9 +1996,10 @@ function createApiClient(cfg) {
1995
1996
  prices = snapshot && typeof snapshot === "object" && !snapshot.stale && snapshot.prices && typeof snapshot.prices === "object" ? snapshot.prices : {};
1996
1997
  } catch {
1997
1998
  prices = {};
1999
+ answered = false;
1998
2000
  }
1999
2001
  const at = Date.now();
2000
- for (const s of missing) {
2002
+ for (const s of answered ? missing : []) {
2001
2003
  const n = Number(prices[s]);
2002
2004
  priceCache.set(s, { at, value: Number.isFinite(n) && n > 0 ? n : null });
2003
2005
  }
@@ -2180,9 +2182,11 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}, readBalances)
2180
2182
  perChainBest.push(option);
2181
2183
  }
2182
2184
  }
2183
- for (const option of [...heldOptions, ...perChainBest, ...leftovers].slice(0, MAX_QUOTE_CANDIDATES)) {
2185
+ const ranked = [...heldOptions, ...perChainBest, ...leftovers];
2186
+ for (const option of ranked.slice(0, MAX_QUOTE_CANDIDATES)) {
2184
2187
  candidates.push(option);
2185
2188
  }
2189
+ const unquotedOptions = ranked.slice(MAX_QUOTE_CANDIDATES);
2186
2190
  const routeErrors = [];
2187
2191
  const routePromises = candidates.map(
2188
2192
  (option) => buildRoute({
@@ -2224,6 +2228,7 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}, readBalances)
2224
2228
  expiresAt: new Date(Date.now() + 2 * 60 * 1e3).toISOString(),
2225
2229
  apiBase: api.apiBase,
2226
2230
  routes: routesBuilt,
2231
+ unquotedOptions,
2227
2232
  fundingBalances: walletBalances,
2228
2233
  fundingAccount: payer.toLowerCase(),
2229
2234
  destination: {
@@ -2237,6 +2242,21 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}, readBalances)
2237
2242
  }
2238
2243
  };
2239
2244
  }
2245
+ async function quotePayOption(api, request, payer, picked, wallet = {}) {
2246
+ validateDestination(request);
2247
+ assertAddress(payer, "Payer wallet");
2248
+ const [chains, tokens, routes, health] = await Promise.all([api.fetchChains(), api.fetchTokens(), api.fetchRoutes(), api.fetchRouteHealth()]);
2249
+ const catalogue = buildCatalogue({ chains, tokens, routes, product: "stable", supportedChainIds: SUPPORTED_CHAIN_IDS, brokenLanes: suppressedLanes(health) });
2250
+ const destination = { ...request, chainId: Number(request.chainId), asset: symbolKey(request.asset) };
2251
+ const destinationToken = findToken(tokens, destination.chainId, destination.asset);
2252
+ if (!destinationToken) throw new Error(`${destination.asset} is not enabled on ${chainNameOf(destination.chainId, chains)}.`);
2253
+ const allowedFunding = wallet.fundingAssets?.length ? new Set(wallet.fundingAssets.map(symbolKey)) : null;
2254
+ const option = buildPayOptions({ invoiceAsset: destination.asset, invoiceChainId: destination.chainId, tokens, routes, chains, walletChainId: wallet.chainId, catalogue }).find(
2255
+ (o) => !o.direct && Number(o.chainId) === Number(picked.chainId) && o.address.toLowerCase() === String(picked.address).toLowerCase() && (!allowedFunding || allowedFunding.has(o.symbolKey))
2256
+ );
2257
+ if (!option) throw new Error("That funding option is not available for this payment right now.");
2258
+ return buildRoute({ option, destination, destinationToken, chains, tokens, payer, fetchQuote: api.fetchQuote });
2259
+ }
2240
2260
 
2241
2261
  // src/core/swap.ts
2242
2262
  function validateSwap(swap = {}) {
@@ -2758,6 +2778,7 @@ function createEngine(config = {}) {
2758
2778
  });
2759
2779
  },
2760
2780
  fetchPaymentPlan: (request, payer, wallet) => fetchPaymentPlan(api, request, payer, wallet, verifier.readBalances),
2781
+ quotePayOption: (request, payer, option, wallet) => quotePayOption(api, request, payer, option, wallet),
2761
2782
  quoteSwapPreview: (swap, owner) => quoteSwapPreview(api, swap, owner),
2762
2783
  buildSwapPlan: (swap, payer, wallet) => buildSwapPlan(api, swap, payer, wallet),
2763
2784
  payerNonceBaseline: verifier.payerNonceBaseline,
@@ -3149,6 +3170,10 @@ function useFlow(args) {
3149
3170
  const routes = plan?.routes ?? [];
3150
3171
  const selected = react.useMemo(() => routes.find((r) => r.id === selectedId) ?? routes.find((r) => r.recommended) ?? routes[0] ?? null, [routes, selectedId]);
3151
3172
  const reload = react.useCallback(() => setNonce((n) => n + 1), []);
3173
+ const addRoute = react.useCallback((route) => {
3174
+ setPlan((p) => p ? { ...p, routes: [...p.routes.filter((r) => r.id !== route.id), route] } : p);
3175
+ setSelectedId(route.id);
3176
+ }, []);
3152
3177
  react.useEffect(() => {
3153
3178
  if (busyRef.current) return;
3154
3179
  setFieldError(null);
@@ -3371,7 +3396,8 @@ function useFlow(args) {
3371
3396
  quotePaused,
3372
3397
  quoteStale,
3373
3398
  submit,
3374
- reload
3399
+ reload,
3400
+ addRoute
3375
3401
  };
3376
3402
  }
3377
3403
  function balanceKey(chainId, tokenAddress) {
@@ -3633,6 +3659,11 @@ var WIDGET_CSS = `
3633
3659
  /* skeleton loading */
3634
3660
  .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}
3635
3661
 
3662
+ .sg-skel--amt{display:inline-block;width:112px;height:30px;margin:0;vertical-align:middle;border-radius:10px}
3663
+ .sg-skel--row{height:48px}
3664
+ .sg-pay-loading{display:flex;flex-direction:column}
3665
+ .sg-pay-loading-line{display:flex;align-items:center;gap:8px;font-size:13px;line-height:16px;padding:2px 2px 0}
3666
+
3636
3667
  /* spinner */
3637
3668
  .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}
3638
3669
  @keyframes sg-spin{to{transform:rotate(360deg)}}
@@ -3708,46 +3739,79 @@ img.sg-tok-badge{width:16px;padding:0;object-fit:cover;background:var(--sg-bg)}
3708
3739
  .sg-pct:hover:not(:disabled){color:var(--sg-accent)}
3709
3740
  .sg-pct:disabled{opacity:.55;cursor:not-allowed}
3710
3741
 
3711
- /* full-panel token selector (Exchange from / Exchange to) */
3742
+ /* full-panel takeover head (transaction history) */
3712
3743
  .sg-sel-head{display:flex;align-items:center;margin-bottom:14px}
3713
3744
  .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}
3714
3745
  .sg-back:hover{background:var(--sg-surface)}
3715
3746
  .sg-sel-title{flex:1 1 auto;min-width:0;text-align:center;font-size:15px;font-weight:600;margin-right:32px}
3716
3747
  /* Whose transactions these are \u2014 history is per wallet, and the takeover hides the header's pill. */
3717
3748
  .sg-sel-sub{display:block;font-size:11px;font-weight:600;color:var(--sg-text-muted);margin-top:1px}
3718
- /* Scrolls at ~2.5 rows. The catalogue's destination chains outnumber its source chains three to one
3719
- (9 escrow chains, ~37 total), so an ungated grid was eight rows tall and pushed the token list \u2014
3720
- the thing the panel exists for \u2014 below the fold. The fade is a scroll affordance, not decoration. */
3721
- .sg-chain-grid{display:grid;grid-template-columns:repeat(5,1fr);gap:8px;margin-bottom:12px;max-height:124px;overflow-y:auto;scrollbar-width:thin;padding-bottom:2px;mask-image:linear-gradient(to bottom,#000 calc(100% - 14px),transparent);-webkit-mask-image:linear-gradient(to bottom,#000 calc(100% - 14px),transparent)}
3722
- /* No mask once everything fits \u2014 a fade under a grid with nothing below it reads as a rendering bug. */
3723
- .sg-chain-grid[data-scroll="false"]{mask-image:none;-webkit-mask-image:none;overflow-y:visible;max-height:none}
3724
- .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}
3725
- .sg-chain-chip img{width:22px;height:22px;border-radius:999px;display:block}
3726
- .sg-chain-chip:hover{border-color:color-mix(in srgb,var(--sg-accent) 45%,var(--sg-border))}
3727
- .sg-chain-chip[data-selected="true"]{border-color:var(--sg-accent);background:color-mix(in srgb,var(--sg-accent) 10%,var(--sg-surface))}
3728
- .sg-search{position:relative;margin-bottom:10px}
3729
- .sg-search svg{position:absolute;left:12px;top:50%;transform:translateY(-50%);color:var(--sg-text-muted);pointer-events:none}
3730
- .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}
3731
- .sg-search input:focus{border-color:var(--sg-accent)}
3732
3749
  .sg-toklist{display:flex;flex-direction:column;gap:2px;max-height:320px;overflow-y:auto;margin:0 -6px;padding:0 6px;scrollbar-width:thin}
3733
- .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}
3734
- .sg-tokrow:hover{background:var(--sg-surface)}
3735
- .sg-tokrow-main{flex:1 1 auto;min-width:0}
3736
- .sg-tokrow-sym{display:block;font-size:15px;font-weight:700;line-height:1.2}
3737
- .sg-tokrow-name{display:block;font-size:12px;color:var(--sg-text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
3738
- .sg-tokrow-end{flex:0 0 auto;text-align:right}
3739
- .sg-tokrow-bal{display:block;font-size:13px;font-weight:600;font-variant-numeric:tabular-nums}
3740
- .sg-tokrow-chain{display:block;font-size:11px;color:var(--sg-text-muted)}
3741
- /* funding rows the wallet can't cover (zero / insufficient): greyed, non-interactive, reason hint.
3742
- Mirrors RouteList's data-short dim + warn tone; no hover lift. Theme-aware via --sg-* vars. */
3743
- .sg-tokrow--off,.sg-tokrow[disabled]{opacity:.5;cursor:not-allowed}
3744
- .sg-tokrow--off:hover,.sg-tokrow[disabled]:hover{background:transparent}
3745
- .sg-tokrow--off .sg-tokrow-sym,.sg-tokrow--off .sg-tokrow-name,.sg-tokrow--off .sg-tokrow-bal{color:var(--sg-text-muted)}
3746
- .sg-tokrow-hint{display:block;font-size:11px;font-weight:600;color:var(--sg-danger)}
3747
- /* on a row that stays selectable (a limited lane): a caveat, not a refusal */
3748
- .sg-tokrow-hint[data-tone="note"]{color:var(--sg-text-muted)}
3749
3750
  .sg-sel-empty{padding:26px 10px;text-align:center;font-size:13px;color:var(--sg-text-muted)}
3750
3751
 
3752
+ /* Token picker, token first then network \u2014 the ZeroDelta dapp's TokenSelectModal (Figma 708:27430,
3753
+ 2517:52576), drawn in the widget's own theme: the dapp's brand tint is the accent, its green the
3754
+ success token. Geometry is the dapp's: 32px plates, 24px row plates, 16px chain marks, 20px gaps. The list keeps
3755
+ the previous picker's 320px cap so opening it does not grow the card. */
3756
+ .sg-pk{display:flex;flex-direction:column;gap:20px}
3757
+ .sg-pk-head{display:flex;align-items:center;justify-content:space-between;gap:8px}
3758
+ .sg-pk-title{font-family:var(--sg-font-display);font-size:16px;font-weight:600;line-height:1.2;letter-spacing:.32px;color:var(--sg-t90)}
3759
+ .sg-pk-close,.sg-pk-clear{display:grid;place-items:center;flex:0 0 auto;padding:6px;border:none;border-radius:8px;background:transparent;color:var(--sg-text-muted);cursor:pointer}
3760
+ .sg-pk-clear{padding:2px}
3761
+ .sg-pk-close:hover,.sg-pk-clear:hover{color:var(--sg-text)}
3762
+ .sg-pk-backlink{display:flex;align-items:center;gap:10px;padding:0;border:none;border-radius:8px;background:transparent;color:var(--sg-t60);font:inherit;font-size:16px;font-weight:500;line-height:1.2;cursor:pointer}
3763
+ .sg-pk-backlink:hover{color:var(--sg-text)}
3764
+ .sg-pk-intro{display:flex;flex-direction:column;gap:4px}
3765
+ .sg-pk-lead{margin:0;font-size:14px;line-height:1.3;color:var(--sg-text-muted)}
3766
+ .sg-pk-search{display:flex;align-items:center;gap:16px;width:100%;padding:16px;border:1px solid color-mix(in srgb,var(--sg-accent) 12%,transparent);border-radius:16px;background:var(--sg-surface);color:var(--sg-text-muted);cursor:text;transition:border-color 120ms ease}
3767
+ .sg-pk-search:focus-within{border-color:var(--sg-accent);color:var(--sg-accent)}
3768
+ .sg-pk-search input{flex:1 1 auto;min-width:0;padding:0;border:none;background:transparent;color:var(--sg-t90);font:inherit;font-size:15px;line-height:1.2;outline:none}
3769
+ .sg-pk-search input::placeholder{color:var(--sg-text-muted)}
3770
+ .sg-pk-body{display:flex;flex-direction:column;gap:8px}
3771
+ .sg-pk-selected{display:flex;flex-direction:column;gap:8px;margin-bottom:8px}
3772
+ .sg-pk-cap{margin:0;font-size:12px;line-height:1.2;color:var(--sg-text-muted)}
3773
+ .sg-pk-list{display:flex;flex-direction:column;gap:4px;max-height:320px;overflow-y:auto;margin:-1px;padding:1px;scrollbar-width:thin}
3774
+ .sg-pk-row{display:flex;align-items:center;justify-content:space-between;gap:12px;width:100%;padding:16px;border:none;border-radius:24px;background:color-mix(in srgb,var(--sg-accent) 4%,transparent);color:var(--sg-text);font:inherit;text-align:left;cursor:pointer;transition:background 120ms ease}
3775
+ .sg-pk-row:hover{background:color-mix(in srgb,var(--sg-accent) 8%,transparent)}
3776
+ .sg-pk-row--net{padding:20px 16px}
3777
+ .sg-pk-row[data-zero]{background:color-mix(in srgb,var(--sg-text) 4%,transparent)}
3778
+ .sg-pk-row[data-zero]:hover{background:color-mix(in srgb,var(--sg-accent) 4%,transparent)}
3779
+ .sg-pk-row[data-selected]{background:color-mix(in srgb,var(--sg-success) 6%,transparent)}
3780
+ .sg-pk-row[data-selected]:hover{background:color-mix(in srgb,var(--sg-success) 8%,transparent)}
3781
+ .sg-pk-row--off{opacity:.6;cursor:default}
3782
+ .sg-pk-row--off:hover{background:color-mix(in srgb,var(--sg-accent) 4%,transparent)}
3783
+ .sg-pk-row:focus-visible,.sg-pk-close:focus-visible,.sg-pk-backlink:focus-visible,.sg-pk-clear:focus-visible{outline:2px solid color-mix(in srgb,var(--sg-accent) 30%,transparent);outline-offset:2px}
3784
+ .sg-pk-left{display:flex;align-items:center;gap:12px;flex:1 1 auto;min-width:0}
3785
+ .sg-pk-text{display:flex;flex-direction:column;align-items:flex-start;gap:2px;flex:1 1 auto;min-width:0;overflow:hidden}
3786
+ .sg-pk-label{font-size:16px;font-weight:500;line-height:1.2;color:var(--sg-t90);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%}
3787
+ .sg-pk-alt{margin-left:8px;font-size:14px;font-weight:400;color:var(--sg-text-muted)}
3788
+ .sg-pk-line{display:flex;align-items:center;gap:4px;min-width:0;max-width:100%}
3789
+ .sg-pk-sub{flex:0 1 auto;font-size:14px;line-height:1.3;color:var(--sg-text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0}
3790
+ .sg-pk-note{font-size:13px;line-height:1.3;color:var(--sg-text-muted)}
3791
+ .sg-pk-plate,.sg-pk-chainwrap{position:relative;display:grid;place-items:center;flex:0 0 auto;width:32px;height:32px}
3792
+ .sg-pk-plate-in{display:grid;place-items:center;width:32px;height:32px;overflow:hidden;border-radius:16px;background:var(--sg-surface)}
3793
+ .sg-pk-plate-in img{width:32px;height:32px;display:block;object-fit:cover}
3794
+ .sg-pk-plate-fb{font-size:10px;font-weight:700;color:var(--sg-accent)}
3795
+ .sg-pk-plate[data-muted] .sg-pk-plate-in{filter:grayscale(1)}
3796
+ .sg-pk-tick{position:absolute;right:-1px;bottom:-1px;display:grid;place-items:center;width:14px;height:14px;border-radius:999px;background:var(--sg-surface);color:var(--sg-success)}
3797
+ .sg-pk-chain{display:grid;place-items:center;width:32px;height:32px;overflow:hidden;border-radius:999px;background:var(--sg-surface);font-size:9px;font-weight:700;color:var(--sg-text-muted)}
3798
+ .sg-pk-chain img{width:32px;height:32px;display:block;object-fit:cover}
3799
+ .sg-pk-marks{display:flex;align-items:center;gap:4px;flex:0 0 auto}
3800
+ .sg-pk-stack{display:flex;align-items:center;height:18px}
3801
+ .sg-pk-markwrap{display:grid;flex:0 0 auto}
3802
+ .sg-pk-markwrap+.sg-pk-markwrap{margin-left:-2px}
3803
+ .sg-pk-mark{display:grid;place-items:center;width:16px;height:16px;overflow:hidden;border-radius:999px;background:var(--sg-surface);font-size:5px;font-weight:700;color:var(--sg-text-muted)}
3804
+ .sg-pk-mark img{width:16px;height:16px;display:block;object-fit:cover}
3805
+ .sg-pk-more{font-size:14px;line-height:1.3;color:var(--sg-text-muted)}
3806
+ .sg-pk-chev{display:grid;place-items:center;flex:0 0 auto;width:16px;height:16px;color:var(--sg-text-muted)}
3807
+ .sg-pk-chev svg{width:16px;height:16px}
3808
+ .sg-pk-chev--sm,.sg-pk-chev--sm svg{width:14px;height:14px}
3809
+ .sg-pk-bal{display:flex;flex-direction:column;align-items:flex-end;justify-content:center;gap:4px;min-height:36px;flex:0 0 auto;text-align:right}
3810
+ .sg-pk-bal-usd{font-size:16px;font-weight:500;line-height:1.2;color:var(--sg-t90)}
3811
+ .sg-pk-bal-amt{font-size:13px;line-height:1.4;color:var(--sg-text-muted)}
3812
+ .sg-pk-bal-zero{flex:0 0 auto;font-size:16px;font-weight:700;color:var(--sg-t35)}
3813
+ .sg-pk-empty{margin:0;padding:32px 0;text-align:center;font-size:14px;color:var(--sg-text-muted)}
3814
+
3751
3815
  /* wide (duo) layout: main card + receive/routes side card. The collapse is keyed to the WIDGET'S
3752
3816
  OWN available width (container query) \u2014 an embedded widget cannot infer the host layout from the
3753
3817
  viewport. The viewport media query stays as a fallback for engines without container queries. */
@@ -4694,6 +4758,200 @@ function chainLogoCandidates(chainId, logoUrl) {
4694
4758
  if (bundled) out.push(bundled);
4695
4759
  return out;
4696
4760
  }
4761
+
4762
+ // src/react/ui/tokenGroups.ts
4763
+ var rowKey = (t) => `${Number(t.chainId)}:${String(t.address || "").toLowerCase()}`;
4764
+ var CHAIN_TVL_ORDER = [
4765
+ 1,
4766
+ 1151111081099710,
4767
+ 8453,
4768
+ 56,
4769
+ 42161,
4770
+ 999,
4771
+ 143,
4772
+ 4663,
4773
+ 137,
4774
+ 9745,
4775
+ 43114,
4776
+ 10,
4777
+ 196,
4778
+ 57073,
4779
+ 14,
4780
+ 5e3,
4781
+ 2818,
4782
+ 30,
4783
+ 4217,
4784
+ 747474,
4785
+ 1672,
4786
+ 988,
4787
+ 480,
4788
+ 81457,
4789
+ 1329,
4790
+ 80094,
4791
+ 130,
4792
+ 4326,
4793
+ 59144,
4794
+ 2222,
4795
+ 252,
4796
+ 146,
4797
+ 324,
4798
+ 1776,
4799
+ 534352,
4800
+ 1030,
4801
+ 1868,
4802
+ 98866,
4803
+ 169,
4804
+ 1088,
4805
+ 50,
4806
+ 34443,
4807
+ 1135,
4808
+ 88,
4809
+ 48900,
4810
+ 151,
4811
+ 7777777,
4812
+ 1923,
4813
+ 3343,
4814
+ 81224,
4815
+ 21e6
4816
+ ];
4817
+ var TOKEN_MARKET_CAP_ORDER = ["USDT", "USDC", "USDS", "DAI", "USDE", "USD1", "USDG", "PYUSD", "XAUT", "RLUSD", "USDF", "GHO", "USD0", "USDTB", "AUSD", "WM"];
4818
+ var CHAIN_RANK = new Map(CHAIN_TVL_ORDER.map((chainId, index) => [chainId, index]));
4819
+ var TOKEN_RANK = new Map(TOKEN_MARKET_CAP_ORDER.map((symbol, index) => [symbol, index]));
4820
+ function chainTvlRank(chainId) {
4821
+ return CHAIN_RANK.get(Number(chainId)) ?? CHAIN_TVL_ORDER.length;
4822
+ }
4823
+ function tokenMarketCapRank(symbol) {
4824
+ return TOKEN_RANK.get(String(symbol).toUpperCase()) ?? TOKEN_MARKET_CAP_ORDER.length;
4825
+ }
4826
+ function dominantSymbol(tokens) {
4827
+ const counts = /* @__PURE__ */ new Map();
4828
+ for (const t of tokens) counts.set(t.symbol, (counts.get(t.symbol) ?? 0) + 1);
4829
+ let best = tokens[0].symbol;
4830
+ for (const [symbol, count] of counts) if (count > (counts.get(best) ?? 0)) best = symbol;
4831
+ return best;
4832
+ }
4833
+ function priceOf(prices, symbol) {
4834
+ const p = prices?.[String(symbol).toUpperCase()];
4835
+ return typeof p === "number" && Number.isFinite(p) ? p : void 0;
4836
+ }
4837
+ function buildGroup(key, members, prices) {
4838
+ const tokens = members.map((m) => m.token);
4839
+ let amount = null;
4840
+ let usd2 = null;
4841
+ for (const m of members) {
4842
+ if (m.balance == null) continue;
4843
+ amount = (amount ?? 0) + m.balance;
4844
+ const price = priceOf(prices, m.token.symbol);
4845
+ if (price !== void 0) usd2 = (usd2 ?? 0) + m.balance * price;
4846
+ }
4847
+ const first = members[0].token;
4848
+ return {
4849
+ key,
4850
+ symbol: dominantSymbol(tokens),
4851
+ name: String(first.name || first.symbol),
4852
+ logoUrl: first.logoUrl,
4853
+ deployments: members,
4854
+ unavailable: members.every((m) => m.disabled) ? { reason: members.find((m) => m.reason)?.reason } : null,
4855
+ amount,
4856
+ usd: usd2
4857
+ };
4858
+ }
4859
+ function byDeployment(a, b) {
4860
+ return Number(a.disabled) - Number(b.disabled) || (b.balance ?? 0) - (a.balance ?? 0) || chainTvlRank(a.token.chainId) - chainTvlRank(b.token.chainId);
4861
+ }
4862
+ function byPickability(a, b) {
4863
+ const zero = (g) => g.amount === 0 ? 1 : 0;
4864
+ return Number(!!a.unavailable) - Number(!!b.unavailable) || zero(a) - zero(b) || (b.usd ?? b.amount ?? 0) - (a.usd ?? a.amount ?? 0) || tokenMarketCapRank(a.symbol) - tokenMarketCapRank(b.symbol);
4865
+ }
4866
+ function groupDeployments(deployments, prices) {
4867
+ const order = [];
4868
+ const members = /* @__PURE__ */ new Map();
4869
+ for (const d of [...deployments].sort(byDeployment)) {
4870
+ const key = String(d.token.symbol).toUpperCase();
4871
+ const list = members.get(key);
4872
+ if (list) list.push(d);
4873
+ else {
4874
+ members.set(key, [d]);
4875
+ order.push(key);
4876
+ }
4877
+ }
4878
+ return order.map((key) => buildGroup(key, members.get(key), prices)).sort(byPickability);
4879
+ }
4880
+ var CHAIN_ALIASES = {
4881
+ 56: ["bsc", "binance"],
4882
+ 137: ["matic"],
4883
+ 43114: ["avax"]
4884
+ };
4885
+ function labelForms(label) {
4886
+ const lower2 = label.trim().toLowerCase();
4887
+ if (!lower2) return [];
4888
+ const compact = lower2.replace(/[^a-z0-9]/g, "");
4889
+ return compact && compact !== lower2 ? [lower2, compact] : [lower2];
4890
+ }
4891
+ function buildChainSearchTerms(chains) {
4892
+ const byId = /* @__PURE__ */ new Map();
4893
+ const ids = /* @__PURE__ */ new Set([...chains.map((c) => Number(c.chainId)), ...Object.keys(CHAIN_LABELS).map(Number)]);
4894
+ for (const id of ids) {
4895
+ const chain = chains.find((c) => Number(c.chainId) === id);
4896
+ const terms = /* @__PURE__ */ new Set();
4897
+ for (const label of [chain?.displayName, chain?.name, typeof chain?.slug === "string" ? chain.slug : void 0, CHAIN_LABELS[id]]) {
4898
+ if (label) for (const form of labelForms(label)) terms.add(form);
4899
+ }
4900
+ for (const alias of CHAIN_ALIASES[id] ?? []) terms.add(alias);
4901
+ byId.set(id, [...terms]);
4902
+ }
4903
+ return byId;
4904
+ }
4905
+ function splitSearchTerms(query) {
4906
+ return query.trim().toLowerCase().split(/\s+/).filter(Boolean);
4907
+ }
4908
+ function looksLikeAddress(term) {
4909
+ return /^(0x)?[0-9a-f]{4,}$/.test(term);
4910
+ }
4911
+ function chainMatches(term, token, chainTerms) {
4912
+ if (term === String(Number(token.chainId))) return true;
4913
+ return chainTerms.some((chainTerm) => chainTerm.includes(term));
4914
+ }
4915
+ function tokenMatches(term, token, asset) {
4916
+ return asset.symbol.toLowerCase().includes(term) || asset.name.toLowerCase().includes(term) || String(token.symbol || "").toLowerCase().includes(term) || // `₮` is not on a keyboard: both sides fold it to `T`, so "usdt0" finds USD₮0.
4917
+ foldTicker(tokenTicker(token)).includes(foldTicker(term)) || String(token.name || "").toLowerCase().includes(term) || looksLikeAddress(term) && String(token.address || "").toLowerCase().includes(term);
4918
+ }
4919
+ function matchingDeployments(terms, group, chainTerms) {
4920
+ if (terms.length === 0) return group.deployments;
4921
+ return group.deployments.filter((d) => {
4922
+ const ct = chainTerms.get(Number(d.token.chainId)) ?? [];
4923
+ return terms.every((term) => tokenMatches(term, d.token, group) || chainMatches(term, d.token, ct));
4924
+ });
4925
+ }
4926
+ function searchGroups(groups, query, chainTerms, prices) {
4927
+ const terms = splitSearchTerms(query);
4928
+ if (terms.length === 0) return groups;
4929
+ const rows = [];
4930
+ for (const g of groups) {
4931
+ const members = matchingDeployments(terms, g, chainTerms);
4932
+ if (members.length === 0) continue;
4933
+ rows.push(members.length === g.deployments.length ? g : buildGroup(g.key, members, prices));
4934
+ }
4935
+ return rows.sort(byPickability);
4936
+ }
4937
+ function groupDecimal2(value) {
4938
+ const match = value.match(/^([+-]?)(\d+)(\.\d+)?$/);
4939
+ if (!match) return value;
4940
+ return `${match[1]}${match[2].replace(/\B(?=(\d{3})+(?!\d))/g, ",")}${match[3] ?? ""}`;
4941
+ }
4942
+ function humanAmount(n, maxFrac = 6) {
4943
+ if (!Number.isFinite(n)) return String(n);
4944
+ if (n === 0) return "0";
4945
+ const digits = Math.min(Math.max(0, Math.trunc(maxFrac)), 8);
4946
+ const fixed = n.toFixed(digits);
4947
+ const out = fixed.includes(".") ? fixed.replace(/\.?0+$/, "") : fixed;
4948
+ if (Number(out) === 0) return `<${digits > 0 ? `0.${"0".repeat(digits - 1)}1` : "1"}`;
4949
+ return groupDecimal2(out);
4950
+ }
4951
+ function formatBalanceUsd(value) {
4952
+ if (!Number.isFinite(value) || value <= 0) return "$0.00";
4953
+ return value < 0.01 ? "<$0.01" : `$${value.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
4954
+ }
4697
4955
  var CHAIN_SHORT = {
4698
4956
  1: "ETH",
4699
4957
  10: "OP",
@@ -4775,103 +5033,280 @@ function FundingTile(props) {
4775
5033
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tile-main", children: main })
4776
5034
  ] });
4777
5035
  }
4778
- function ChainChip(props) {
5036
+ function ChainMark(props) {
5037
+ const [failed, setFailed] = react.useState([]);
5038
+ const src = chainLogoCandidates(props.chainId, props.chain?.logoUrl).find((u) => !failed.includes(u));
5039
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className: props.size === "row" ? "sg-pk-chain" : "sg-pk-mark", "aria-hidden": "true", children: src ? /* @__PURE__ */ jsxRuntime.jsx("img", { src, alt: "", loading: "lazy", onError: () => setFailed((f) => [...f, src]) }) : /* @__PURE__ */ jsxRuntime.jsx("span", { children: chainBadge(props.chainId) }) });
5040
+ }
5041
+ var MARK_LIMIT = 3;
5042
+ function ChainMarks(props) {
5043
+ const ids = props.chainIds;
5044
+ if (!ids.length) return null;
5045
+ const shown = ids.slice(0, MARK_LIMIT);
5046
+ const overflow = ids.length - shown.length;
5047
+ const marks = shown.map((id) => /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pk-markwrap", children: /* @__PURE__ */ jsxRuntime.jsx(ChainMark, { chainId: id, chain: props.chainById.get(id), size: "mini" }) }, id));
5048
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-pk-marks", children: [
5049
+ props.decorative ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pk-stack", "aria-hidden": "true", children: marks }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pk-stack", role: "img", "aria-label": `${ids.length} ${ids.length === 1 ? "network" : "networks"}`, children: marks }),
5050
+ overflow > 0 ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-pk-more", "aria-hidden": "true", children: [
5051
+ "+",
5052
+ overflow
5053
+ ] }) : null
5054
+ ] });
5055
+ }
5056
+ function TokenPlate(props) {
4779
5057
  const [failed, setFailed] = react.useState([]);
4780
- const src = chainLogoCandidates(props.chain?.chainId, props.chain?.logoUrl).find((u) => !failed.includes(u));
4781
- const name = props.name ?? props.label;
4782
- return /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "sg-chain-chip", "data-selected": props.selected, title: name, "aria-label": name, "aria-pressed": props.selected, onClick: props.onClick, children: src ? /* @__PURE__ */ jsxRuntime.jsx("img", { src, alt: "", loading: "lazy", onError: () => setFailed((f) => [...f, src]) }) : props.label });
5058
+ const src = tokenLogoCandidates(props.symbol, props.logoUrl).find((u) => !failed.includes(u));
5059
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-pk-plate", "data-muted": props.muted || void 0, children: [
5060
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pk-plate-in", children: src ? /* @__PURE__ */ jsxRuntime.jsx("img", { src, alt: "", loading: "lazy", onError: () => setFailed((f) => [...f, src]) }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pk-plate-fb", children: props.symbol.slice(0, 4) }) }),
5061
+ props.checked ? /* @__PURE__ */ jsxRuntime.jsx(TickBadge, {}) : null
5062
+ ] });
5063
+ }
5064
+ function TickBadge() {
5065
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pk-tick", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: [
5066
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "11", fill: "currentColor" }),
5067
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m7 12.5 3.2 3.2L17 9", stroke: "#fff", strokeWidth: "2.6", strokeLinecap: "round", strokeLinejoin: "round" })
5068
+ ] }) });
5069
+ }
5070
+ function BalanceColumn(props) {
5071
+ if (props.amount == null) return null;
5072
+ if (props.amount === 0) return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pk-bal-zero", children: "0.00" });
5073
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-pk-bal", children: [
5074
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pk-bal-usd sg-mono", children: props.usd == null ? "\u2014" : formatBalanceUsd(props.usd) }),
5075
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-pk-bal-amt sg-mono", children: [
5076
+ humanAmount(props.amount, 6),
5077
+ " ",
5078
+ props.symbol
5079
+ ] })
5080
+ ] });
5081
+ }
5082
+ var WALLET_STATE_REASONS = /* @__PURE__ */ new Set(["no-balance", "insufficient"]);
5083
+ function isPick(sel, t) {
5084
+ return !!sel && Number(sel.chainId) === Number(t.chainId) && String(sel.symbol).toUpperCase() === String(t.symbol).toUpperCase();
5085
+ }
5086
+ function usdOf(balance, prices, symbol) {
5087
+ const price = priceOf(prices, symbol);
5088
+ return balance == null || price === void 0 ? null : balance * price;
5089
+ }
5090
+ function UnavailableRow(props) {
5091
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-pk-row sg-pk-row--off", "data-testid": props.testId, "data-label": props.label, title: props.label, "aria-disabled": "true", children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-pk-left", children: [
5092
+ props.icon,
5093
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-pk-text", children: [
5094
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pk-label", children: props.label }),
5095
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pk-sub", children: props.reason || "Not available right now" })
5096
+ ] })
5097
+ ] }) });
4783
5098
  }
4784
5099
  function SearchGlyph() {
4785
- return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", "aria-hidden": "true", children: [
5100
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", "aria-hidden": "true", children: [
4786
5101
  /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "11", cy: "11", r: "7" }),
4787
5102
  /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m20 20-3.5-3.5" })
4788
5103
  ] });
4789
5104
  }
4790
- function BackGlyph() {
4791
- return /* @__PURE__ */ jsxRuntime.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: [
5105
+ function CloseGlyph() {
5106
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", "aria-hidden": "true", children: [
5107
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M18 6 6 18" }),
5108
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m6 6 12 12" })
5109
+ ] });
5110
+ }
5111
+ function ArrowLeftGlyph() {
5112
+ return /* @__PURE__ */ jsxRuntime.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: [
4792
5113
  /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M19 12H5" }),
4793
5114
  /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m12 19-7-7 7-7" })
4794
5115
  ] });
4795
5116
  }
4796
- var rowKey = (t) => `${Number(t.chainId)}:${String(t.address || "").toLowerCase()}`;
4797
5117
  function TokenSelect(props) {
4798
- const [chainFilter, setChainFilter] = react.useState(null);
5118
+ const side = props.side ?? "from";
4799
5119
  const [query, setQuery] = react.useState("");
4800
- const chains = react.useMemo(() => {
4801
- const live = new Set(props.tokens.filter((t) => !props.optionStates?.[rowKey(t)]?.disabled).map((t) => Number(t.chainId)));
4802
- return props.chains.filter((c) => live.has(Number(c.chainId)));
4803
- }, [props.chains, props.tokens, props.optionStates]);
4804
- const activeFilter = chainFilter != null && chains.some((c) => Number(c.chainId) === chainFilter) ? chainFilter : null;
4805
- const rows = react.useMemo(() => {
4806
- const q = query.trim().toLowerCase();
4807
- const filtered = props.tokens.filter((t) => activeFilter == null ? true : Number(t.chainId) === activeFilter).filter((t) => {
4808
- if (!q) return true;
4809
- return String(t.symbol || "").toLowerCase().includes(q) || // The chain's own ticker too, with `₮` read as `T`: "usdt0" finds USD₮0.
4810
- foldTicker(tokenTicker(t)).includes(foldTicker(q)) || String(t.name || "").toLowerCase().includes(q) || String(t.address || "").toLowerCase().includes(q) || // Chain name too (2026-09-08): with ~37 destination chains most have no bundled mark and
4811
- // show a three-letter badge, so "Katana" or "Berachain" has to be findable by typing it.
4812
- String(CHAIN_LABELS[Number(t.chainId)] || "").toLowerCase().includes(q);
4813
- });
4814
- const off = (t) => props.optionStates?.[rowKey(t)]?.disabled ? 1 : 0;
4815
- const balNum = (t) => {
4816
- const n = Number(props.balances?.[rowKey(t)]?.formatted);
4817
- return Number.isFinite(n) ? n : 0;
5120
+ const [openKey, setOpenKey] = react.useState(null);
5121
+ const listRef = react.useRef(null);
5122
+ const savedScroll = react.useRef(0);
5123
+ const chainById2 = react.useMemo(() => new Map(props.chains.map((c) => [Number(c.chainId), c])), [props.chains]);
5124
+ const chainName3 = (chainId) => CHAIN_LABELS[chainId] || chainById2.get(chainId)?.displayName || chainById2.get(chainId)?.name || `Chain ${chainId}`;
5125
+ const showBalances = side === "from" && !!props.balances && Object.keys(props.balances).length > 0;
5126
+ const [prices, setPrices] = react.useState({});
5127
+ const symbolKey2 = react.useMemo(() => [...new Set(props.tokens.map((t) => String(t.symbol).toUpperCase()))].sort().join(","), [props.tokens]);
5128
+ const fetchPrices = props.fetchPrices;
5129
+ react.useEffect(() => {
5130
+ if (!showBalances || !fetchPrices || !symbolKey2) return;
5131
+ let alive = true;
5132
+ let timer2;
5133
+ const ask = (retriesLeft) => {
5134
+ fetchPrices(symbolKey2.split(",")).then((next) => {
5135
+ if (!alive) return;
5136
+ setPrices(next);
5137
+ if (!Object.keys(next).length && retriesLeft > 0) timer2 = setTimeout(() => ask(retriesLeft - 1), retriesLeft > 1 ? 5e3 : 2e4);
5138
+ }).catch(() => {
5139
+ });
4818
5140
  };
4819
- return [...filtered].sort((a, b) => off(a) - off(b) || balNum(b) - balNum(a));
4820
- }, [props.tokens, activeFilter, query, props.balances, props.optionStates]);
4821
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4822
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-sel-head", children: [
4823
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "sg-back", onClick: props.onBack, "aria-label": "Back", children: /* @__PURE__ */ jsxRuntime.jsx(BackGlyph, {}) }),
4824
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-sel-title", children: props.title })
4825
- ] }),
4826
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-chain-grid", "data-scroll": chains.length > 14 ? void 0 : "false", role: "group", "aria-label": "Filter by chain", children: [
4827
- /* @__PURE__ */ jsxRuntime.jsx(ChainChip, { label: "All", selected: activeFilter == null, onClick: () => setChainFilter(null) }),
4828
- chains.map((c) => /* @__PURE__ */ jsxRuntime.jsx(
4829
- ChainChip,
4830
- {
4831
- chain: c,
4832
- label: chainBadge(Number(c.chainId)),
4833
- name: CHAIN_LABELS[Number(c.chainId)] || c.displayName || c.name || `Chain ${c.chainId}`,
4834
- selected: activeFilter === Number(c.chainId),
4835
- onClick: () => setChainFilter(Number(c.chainId))
4836
- },
4837
- c.chainId
4838
- ))
4839
- ] }),
4840
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-search", children: [
4841
- /* @__PURE__ */ jsxRuntime.jsx(SearchGlyph, {}),
4842
- /* @__PURE__ */ jsxRuntime.jsx("input", { autoFocus: true, placeholder: "Search by token, network or address", value: query, onChange: (e) => setQuery(e.target.value), spellCheck: false, "aria-label": "Search by token, network or address" })
4843
- ] }),
4844
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-toklist", role: "group", "aria-label": props.title, children: rows.length ? rows.map((t) => {
4845
- const chainId = Number(t.chainId);
4846
- const key = rowKey(t);
4847
- const bal = props.balances?.[key];
5141
+ ask(2);
5142
+ return () => {
5143
+ alive = false;
5144
+ if (timer2) clearTimeout(timer2);
5145
+ };
5146
+ }, [showBalances, fetchPrices, symbolKey2]);
5147
+ const groups = react.useMemo(() => {
5148
+ const deployments = [];
5149
+ for (const token of props.tokens) {
5150
+ const key = rowKey(token);
5151
+ const n = Number(props.balances?.[key]?.formatted);
4848
5152
  const st = props.optionStates?.[key];
4849
- const disabled = !!st?.disabled;
4850
- return /* @__PURE__ */ jsxRuntime.jsxs(
4851
- "button",
4852
- {
4853
- type: "button",
4854
- className: `sg-tokrow${disabled ? " sg-tokrow--off" : ""}`,
4855
- disabled,
4856
- "aria-disabled": disabled || void 0,
4857
- "data-disabled": disabled || void 0,
4858
- onClick: disabled ? void 0 : () => props.onPick({ chainId, symbol: t.symbol }),
4859
- children: [
4860
- /* @__PURE__ */ jsxRuntime.jsx(TokenGlyph, { symbol: t.symbol, logoUrl: t.logoUrl, chainId }),
4861
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-tokrow-main", children: [
4862
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tokrow-sym", children: tokenTicker(t) }),
4863
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tokrow-name", children: t.name || t.symbol })
5153
+ if (st?.disabled && !WALLET_STATE_REASONS.has(String(st.reason))) continue;
5154
+ deployments.push({
5155
+ token,
5156
+ key,
5157
+ balance: showBalances && props.balances?.[key] && Number.isFinite(n) ? n : null,
5158
+ disabled: !!st?.disabled,
5159
+ // The line under a greyed row says why. Callers send either a sentence in `reason` (the
5160
+ // exchange's "cannot be delivered on this chain") or a machine code there with the words in
5161
+ // `hint` (the deposit card's "no-balance" / "No balance on this chain").
5162
+ reason: st?.disabled ? st.reason && /\s/.test(st.reason) ? st.reason : st.hint || st.reason : void 0,
5163
+ hint: st?.disabled ? void 0 : st?.hint
5164
+ });
5165
+ }
5166
+ return groupDeployments(deployments, prices);
5167
+ }, [props.tokens, props.balances, props.optionStates, showBalances, prices]);
5168
+ const chainTerms = react.useMemo(() => buildChainSearchTerms(props.chains), [props.chains]);
5169
+ const visible = react.useMemo(() => searchGroups(groups, query, chainTerms, prices), [groups, query, chainTerms, prices]);
5170
+ const openGroup = openKey ? visible.find((g) => g.key === openKey) ?? null : null;
5171
+ react.useEffect(() => {
5172
+ if (openKey && !openGroup) setOpenKey(null);
5173
+ }, [openKey, openGroup]);
5174
+ react.useLayoutEffect(() => {
5175
+ if (!openKey && listRef.current) listRef.current.scrollTop = savedScroll.current;
5176
+ }, [openKey]);
5177
+ const selected = props.selected;
5178
+ const isSelected = (t) => isPick(selected, t);
5179
+ const pick = (t) => props.onPick({ chainId: Number(t.chainId), symbol: t.symbol });
5180
+ const selectedRow = react.useMemo(() => {
5181
+ if (!selected) return null;
5182
+ for (const g of groups) for (const d of g.deployments) if (!d.disabled && isPick(selected, d.token)) return d;
5183
+ return null;
5184
+ }, [groups, selected]);
5185
+ const head = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-pk-head", children: [
5186
+ openGroup ? /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", className: "sg-pk-backlink", onClick: () => setOpenKey(null), children: [
5187
+ /* @__PURE__ */ jsxRuntime.jsx(ArrowLeftGlyph, {}),
5188
+ "Tokens"
5189
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-pk-title", children: props.title }),
5190
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "sg-pk-close", onClick: props.onBack, "aria-label": "Close", children: /* @__PURE__ */ jsxRuntime.jsx(CloseGlyph, {}) })
5191
+ ] });
5192
+ if (openGroup) {
5193
+ const sym = openGroup.symbol;
5194
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-pk", "data-step": "network", children: [
5195
+ head,
5196
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-pk-intro", children: [
5197
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-pk-title", children: [
5198
+ side === "from" ? "Pay with" : "Receive",
5199
+ " ",
5200
+ sym
5201
+ ] }),
5202
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "sg-pk-lead", children: side === "from" ? "Choose the network to pay from" : `Choose the network to receive ${sym} on` })
5203
+ ] }),
5204
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-pk-list", role: "group", "aria-label": "Select network", children: openGroup.deployments.map((d) => {
5205
+ const id = Number(d.token.chainId);
5206
+ const name = chainName3(id);
5207
+ if (d.disabled) {
5208
+ return /* @__PURE__ */ jsxRuntime.jsx(UnavailableRow, { icon: /* @__PURE__ */ jsxRuntime.jsx(ChainMark, { chainId: id, chain: chainById2.get(id), size: "row" }), label: name, reason: d.reason, testId: "network-row-unavailable" }, d.key);
5209
+ }
5210
+ const sel = isSelected(d.token);
5211
+ const ticker = tokenTicker(d.token);
5212
+ return /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", className: "sg-pk-row sg-pk-row--net", "data-testid": "network-row", "data-selected": sel || void 0, "aria-pressed": sel, title: name, onClick: () => pick(d.token), children: [
5213
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-pk-left", children: [
5214
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-pk-chainwrap", children: [
5215
+ /* @__PURE__ */ jsxRuntime.jsx(ChainMark, { chainId: id, chain: chainById2.get(id), size: "row" }),
5216
+ sel ? /* @__PURE__ */ jsxRuntime.jsx(TickBadge, {}) : null
4864
5217
  ] }),
4865
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-tokrow-end", children: [
4866
- bal ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tokrow-bal sg-mono", children: bal.formatted }) : null,
4867
- st?.hint ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tokrow-hint", "data-tone": disabled ? void 0 : "note", children: st.hint }) : null,
4868
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tokrow-chain", children: CHAIN_LABELS[chainId] || `Chain ${chainId}` })
5218
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-pk-text", children: [
5219
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-pk-label", children: [
5220
+ name,
5221
+ ticker !== sym ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pk-alt", children: ticker }) : null
5222
+ ] }),
5223
+ d.hint ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pk-note", "data-testid": "lane-limit", children: d.hint }) : null
4869
5224
  ] })
4870
- ]
4871
- },
4872
- `${chainId}:${t.address}`
4873
- );
4874
- }) : props.loading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-sel-empty", children: "Loading the token list\u2026" }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-sel-empty", children: "No tokens match \u2014 try another chain or search." }) })
5225
+ ] }),
5226
+ showBalances ? /* @__PURE__ */ jsxRuntime.jsx(BalanceColumn, { amount: d.balance, usd: usdOf(d.balance, prices, d.token.symbol), symbol: ticker }) : null
5227
+ ] }, d.key);
5228
+ }) })
5229
+ ] });
5230
+ }
5231
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-pk", "data-step": "token", children: [
5232
+ head,
5233
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "sg-pk-search", children: [
5234
+ /* @__PURE__ */ jsxRuntime.jsx(SearchGlyph, {}),
5235
+ /* @__PURE__ */ jsxRuntime.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" }),
5236
+ query ? /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "sg-pk-clear", onClick: () => setQuery(""), "aria-label": "Clear token search", children: /* @__PURE__ */ jsxRuntime.jsx(CloseGlyph, {}) }) : null
5237
+ ] }),
5238
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-pk-body", children: [
5239
+ selectedRow ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-pk-selected", children: [
5240
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "sg-pk-cap", children: "Selected" }),
5241
+ /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", className: "sg-pk-row", "data-testid": "selected-row", "data-selected": "true", "aria-pressed": "true", onClick: () => pick(selectedRow.token), children: [
5242
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-pk-left", children: [
5243
+ /* @__PURE__ */ jsxRuntime.jsx(TokenPlate, { symbol: selectedRow.token.symbol, logoUrl: selectedRow.token.logoUrl, checked: true }),
5244
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-pk-text", children: [
5245
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pk-label", children: tokenTicker(selectedRow.token) }),
5246
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-pk-line", children: [
5247
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-pk-sub", children: [
5248
+ "On ",
5249
+ chainName3(Number(selectedRow.token.chainId))
5250
+ ] }),
5251
+ /* @__PURE__ */ jsxRuntime.jsx(ChainMarks, { chainIds: [Number(selectedRow.token.chainId)], chainById: chainById2, decorative: true })
5252
+ ] })
5253
+ ] })
5254
+ ] }),
5255
+ showBalances ? /* @__PURE__ */ jsxRuntime.jsx(
5256
+ BalanceColumn,
5257
+ {
5258
+ amount: selectedRow.balance,
5259
+ usd: usdOf(selectedRow.balance, prices, selectedRow.token.symbol),
5260
+ symbol: tokenTicker(selectedRow.token)
5261
+ }
5262
+ ) : null
5263
+ ] })
5264
+ ] }) : null,
5265
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "sg-pk-cap", children: side === "from" ? "Your tokens \xB7 All networks" : "Popular tokens \xB7 All networks" }),
5266
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-pk-list", ref: listRef, role: "group", "aria-label": props.title, children: visible.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "sg-pk-empty", children: props.loading ? "Loading the token list\u2026" : "No tokens found." }) : visible.map((g) => {
5267
+ const members = g.deployments;
5268
+ const multi = members.length > 1;
5269
+ const single = members[0];
5270
+ const label = multi ? g.symbol : tokenTicker(single.token);
5271
+ const blocked = !!g.unavailable;
5272
+ const opensNetworks = multi || blocked;
5273
+ const zero = showBalances && g.amount === 0 || blocked;
5274
+ return /* @__PURE__ */ jsxRuntime.jsxs(
5275
+ "button",
5276
+ {
5277
+ type: "button",
5278
+ className: "sg-pk-row",
5279
+ "data-testid": "token-row",
5280
+ "data-symbol": g.symbol,
5281
+ "data-networks": members.length,
5282
+ "data-zero": zero || void 0,
5283
+ "data-unavailable": blocked || void 0,
5284
+ onClick: () => {
5285
+ if (opensNetworks) {
5286
+ savedScroll.current = listRef.current?.scrollTop ?? 0;
5287
+ setOpenKey(g.key);
5288
+ } else pick(single.token);
5289
+ },
5290
+ children: [
5291
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-pk-left", children: [
5292
+ /* @__PURE__ */ jsxRuntime.jsx(TokenPlate, { symbol: g.symbol, logoUrl: g.logoUrl }),
5293
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-pk-text", children: [
5294
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pk-label", children: label }),
5295
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-pk-line", children: [
5296
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pk-sub", children: multi ? showBalances ? "Total across" : "Available on" : `On ${chainName3(Number(single.token.chainId))}` }),
5297
+ /* @__PURE__ */ jsxRuntime.jsx(ChainMarks, { chainIds: members.map((m) => Number(m.token.chainId)), chainById: chainById2, decorative: !multi }),
5298
+ opensNetworks && showBalances ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pk-chev sg-pk-chev--sm", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(ChevronGlyph, {}) }) : null
5299
+ ] }),
5300
+ !multi && single.hint ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pk-note", "data-testid": "lane-limit", children: single.hint }) : null
5301
+ ] })
5302
+ ] }),
5303
+ showBalances ? /* @__PURE__ */ jsxRuntime.jsx(BalanceColumn, { amount: g.amount, usd: g.usd, symbol: label }) : opensNetworks ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pk-chev", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(ChevronGlyph, {}) }) : null
5304
+ ]
5305
+ },
5306
+ g.key
5307
+ );
5308
+ }) })
5309
+ ] })
4875
5310
  ] });
4876
5311
  }
4877
5312
  function ChevronRight({ size = 16 }) {
@@ -4889,7 +5324,7 @@ function ArrowDown({ size = 16 }) {
4889
5324
  /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12.667 8L8 12.667 3.333 8", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })
4890
5325
  ] });
4891
5326
  }
4892
- function CloseGlyph() {
5327
+ function CloseGlyph2() {
4893
5328
  return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M18 6L6 18M6 6l12 12", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) });
4894
5329
  }
4895
5330
  function ShieldTickGlyph({ size = 16 }) {
@@ -4929,7 +5364,7 @@ function AmountText({ value, suffix, exact }) {
4929
5364
  suffix ? ` ${suffix}` : null
4930
5365
  ] });
4931
5366
  }
4932
- function usdOf(amount, price) {
5367
+ function usdOf2(amount, price) {
4933
5368
  const n = typeof amount === "number" ? amount : Number(amount);
4934
5369
  if (!Number.isFinite(n) || n <= 0 || price === void 0 || !Number.isFinite(price) || price <= 0) return null;
4935
5370
  const usd2 = n * price;
@@ -5059,7 +5494,7 @@ function WidgetShell(props) {
5059
5494
  ] }),
5060
5495
  props.onClose ? (
5061
5496
  // type="button": a host page may wrap the widget in a <form>.
5062
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "sg-close", onClick: props.onClose, "aria-label": "Close", children: /* @__PURE__ */ jsxRuntime.jsx(CloseGlyph, {}) })
5497
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "sg-close", onClick: props.onClose, "aria-label": "Close", children: /* @__PURE__ */ jsxRuntime.jsx(CloseGlyph2, {}) })
5063
5498
  ) : null
5064
5499
  ] })
5065
5500
  ] }),
@@ -5355,7 +5790,7 @@ function useTxHistory(account) {
5355
5790
  }, [account]);
5356
5791
  return entries;
5357
5792
  }
5358
- function BackGlyph2() {
5793
+ function BackGlyph() {
5359
5794
  return /* @__PURE__ */ jsxRuntime.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: [
5360
5795
  /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M19 12H5" }),
5361
5796
  /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m12 19-7-7 7-7" })
@@ -5597,7 +6032,7 @@ function TxHistoryPanel(props) {
5597
6032
  };
5598
6033
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
5599
6034
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-sel-head", children: [
5600
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", autoFocus: true, ref: backRef, className: "sg-back", onClick: selected ? () => setSelected(null) : props.onBack, "aria-label": "Back", children: /* @__PURE__ */ jsxRuntime.jsx(BackGlyph2, {}) }),
6035
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", autoFocus: true, ref: backRef, className: "sg-back", onClick: selected ? () => setSelected(null) : props.onBack, "aria-label": "Back", children: /* @__PURE__ */ jsxRuntime.jsx(BackGlyph, {}) }),
5601
6036
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-sel-title", children: [
5602
6037
  selected ? "Transaction" : "Transaction history",
5603
6038
  account ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-sel-sub sg-mono", children: shortAddress2(account) }) : null
@@ -6353,6 +6788,9 @@ function PaymentIsland(props) {
6353
6788
  TokenSelect,
6354
6789
  {
6355
6790
  title: "Pay with",
6791
+ side: "from",
6792
+ selected: sel ? { chainId: sel.source.chainId, symbol: sel.source.asset } : null,
6793
+ fetchPrices: engine.fetchPrices,
6356
6794
  chains: fundingChains,
6357
6795
  tokens: fundingTokens,
6358
6796
  balances: holdings.balances,
@@ -6368,6 +6806,9 @@ function PaymentIsland(props) {
6368
6806
  TokenSelect,
6369
6807
  {
6370
6808
  title: isFrom ? "Exchange from" : "Exchange to",
6809
+ side: isFrom ? "from" : "to",
6810
+ selected: isFrom ? exFrom : exTo,
6811
+ fetchPrices: engine.fetchPrices,
6371
6812
  chains,
6372
6813
  tokens: isFrom ? exFromPicker : exToPicker,
6373
6814
  balances: exBalances,
@@ -6717,6 +7158,21 @@ function PayCard(props) {
6717
7158
  );
6718
7159
  const heldIds = react.useMemo(() => new Set(held.map((a) => a.route.id)), [held]);
6719
7160
  const scannedEmpty = !holdings.loading && Object.keys(holdings.balances).length > 0 && held.length === 0;
7161
+ const [failedOptions, setFailedOptions] = react.useState(/* @__PURE__ */ new Set());
7162
+ const [pricing, setPricing] = react.useState(null);
7163
+ const [pickError, setPickError] = react.useState(null);
7164
+ react.useEffect(() => {
7165
+ setFailedOptions(/* @__PURE__ */ new Set());
7166
+ setPricing(null);
7167
+ setPickError(null);
7168
+ }, [wallet.account, paramsKey]);
7169
+ const unquoted = react.useMemo(
7170
+ () => (paymentPlan?.unquotedOptions ?? []).filter(
7171
+ (o) => (!fundingSet || fundingSet.has(o.symbolKey)) && (STABLES2.has(o.symbolKey)) && !failedOptions.has(balanceKey(o.chainId, o.address))
7172
+ ),
7173
+ [paymentPlan, fundingSet, method, failedOptions]
7174
+ );
7175
+ const listBalances = react.useMemo(() => ({ ...prefetchedBalances ?? {}, ...holdings.balances }), [prefetchedBalances, holdings.balances]);
6720
7176
  const optionStates = react.useMemo(() => {
6721
7177
  const map = {};
6722
7178
  for (const a of annotated) {
@@ -6739,8 +7195,19 @@ function PayCard(props) {
6739
7195
  map[key] = { disabled: false };
6740
7196
  }
6741
7197
  }
7198
+ for (const o of unquoted) {
7199
+ const key = balanceKey(o.chainId, o.address);
7200
+ if (map[key]) continue;
7201
+ let zero = false;
7202
+ try {
7203
+ zero = BigInt(listBalances[key]?.raw ?? "x") === 0n;
7204
+ } catch {
7205
+ zero = false;
7206
+ }
7207
+ map[key] = zero ? { disabled: true, reason: "no-balance", hint: "No balance on this chain" } : { disabled: false };
7208
+ }
6742
7209
  return map;
6743
- }, [annotated, holdings.loading]);
7210
+ }, [annotated, holdings.loading, unquoted, listBalances]);
6744
7211
  const [catalogue, setCatalogue] = react.useState(null);
6745
7212
  const chains = react.useMemo(() => {
6746
7213
  const order = new Map(SUPPORTED_CHAINS.map((id, i) => [id, i]));
@@ -6760,24 +7227,27 @@ function PayCard(props) {
6760
7227
  const fundingTokens = react.useMemo(() => {
6761
7228
  const seen = /* @__PURE__ */ new Set();
6762
7229
  const list = [];
6763
- for (const r of visibleRoutes) {
6764
- const key = balanceKey(r.source.chainId, r.source.tokenAddress);
6765
- if (seen.has(key)) continue;
7230
+ const push = (chainId, address, fallback) => {
7231
+ const key = balanceKey(chainId, address);
7232
+ if (seen.has(key)) return;
6766
7233
  seen.add(key);
6767
- const reg = registryTokens.find((t) => Number(t.chainId) === r.source.chainId && addrEq2(t.address, r.source.tokenAddress));
6768
- list.push(
6769
- reg ?? {
6770
- symbol: r.source.asset,
6771
- displaySymbol: r.source.ticker,
6772
- name: r.source.asset,
6773
- chainId: r.source.chainId,
6774
- address: r.source.tokenAddress ?? "",
6775
- decimals: r.source.decimals ?? 18
6776
- }
6777
- );
7234
+ list.push(registryTokens.find((t) => Number(t.chainId) === chainId && addrEq2(t.address, address)) ?? fallback);
7235
+ };
7236
+ for (const r of visibleRoutes) {
7237
+ push(r.source.chainId, r.source.tokenAddress, {
7238
+ symbol: r.source.asset,
7239
+ displaySymbol: r.source.ticker,
7240
+ name: r.source.asset,
7241
+ chainId: r.source.chainId,
7242
+ address: r.source.tokenAddress ?? "",
7243
+ decimals: r.source.decimals ?? 18
7244
+ });
7245
+ }
7246
+ for (const o of unquoted) {
7247
+ push(o.chainId, o.address, { symbol: o.symbol, displaySymbol: o.ticker, name: o.name, chainId: o.chainId, address: o.address, decimals: o.decimals, logoUrl: o.logoUrl });
6778
7248
  }
6779
7249
  return list;
6780
- }, [visibleRoutes, registryTokens]);
7250
+ }, [visibleRoutes, unquoted, registryTokens]);
6781
7251
  const fundingChains = react.useMemo(() => {
6782
7252
  const ids = new Set(fundingTokens.map((t) => Number(t.chainId)));
6783
7253
  return chains.filter((c) => ids.has(Number(c.chainId)));
@@ -6821,9 +7291,23 @@ function PayCard(props) {
6821
7291
  react.useEffect(() => setHist(null), [wallet.account]);
6822
7292
  const lastTxOwned = Boolean(flow.lastTxEntry?.hash && wallet.account && flow.lastTxEntry.account === wallet.account.toLowerCase());
6823
7293
  const pickFunding = (pick) => {
7294
+ setPickError(null);
6824
7295
  const r = visibleRoutes.find((x) => x.source.chainId === pick.chainId && symbolKey(x.source.asset) === symbolKey(pick.symbol));
6825
- if (r) selectRoute(r.id);
7296
+ if (r) {
7297
+ selectRoute(r.id);
7298
+ closeSelector();
7299
+ return;
7300
+ }
7301
+ const option = unquoted.find((o) => o.chainId === pick.chainId && o.symbolKey === symbolKey(pick.symbol));
6826
7302
  closeSelector();
7303
+ if (!option || !wallet.account) return;
7304
+ const key = balanceKey(option.chainId, option.address);
7305
+ setPricing(key);
7306
+ userPicked.current = true;
7307
+ engine.quotePayOption({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, wallet.account, { chainId: option.chainId, address: option.address }, { chainId: wallet.chainId ?? void 0, fundingAssets: planFundingAssets }).then((route) => flow.addRoute(route)).catch(() => {
7308
+ setFailedOptions((prev) => /* @__PURE__ */ new Set([...prev, key]));
7309
+ setPickError(`${option.ticker || option.symbol} on ${option.chainName} cannot settle this payment right now. Pick another way to pay.`);
7310
+ }).finally(() => setPricing((cur) => cur === key ? null : cur));
6827
7311
  };
6828
7312
  const parked = !isLiveMethod(method);
6829
7313
  const submitting = flow.status === "submitting";
@@ -6850,7 +7334,7 @@ function PayCard(props) {
6850
7334
  setSheet(false);
6851
7335
  requestAnimationFrame(() => complianceBtnRef.current?.focus());
6852
7336
  };
6853
- const payLabel = parked ? "Coming soon" : submitting ? "Paying\u2026" : flow.quoteStale ? flow.quotePaused ? "Refresh quote" : "Refreshing quote\u2026" : flow.insufficient ? "Insufficient balance" : flow.nativeShortfall ? flow.nativeShortfall : sel && selectedVisible ? `Pay ${groupDecimal(atLeastCents(sel.source.payAmount))} ${sel.source.ticker || sel.source.asset}` : "Pay";
7337
+ const payLabel = parked ? "Coming soon" : wallet.account && (flow.status === "loading" || pricing !== null) ? "Finding the best way to pay\u2026" : submitting ? "Paying\u2026" : flow.quoteStale ? flow.quotePaused ? "Refresh quote" : "Refreshing quote\u2026" : flow.insufficient ? "Insufficient balance" : flow.nativeShortfall ? flow.nativeShortfall : sel && selectedVisible ? `Pay ${groupDecimal(atLeastCents(sel.source.payAmount))} ${sel.source.ticker || sel.source.asset}` : "Pay";
6854
7338
  const walletSlot = wallet.account ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-head-tools", children: [
6855
7339
  /* @__PURE__ */ jsxRuntime.jsx(HistoryButton, { btnRef: histBtnRef, disabled: submitting, onClick: () => setHist({}) }),
6856
7340
  /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-wallet", "data-connected": "true", children: [
@@ -6864,14 +7348,17 @@ function PayCard(props) {
6864
7348
  { label: "Network fee", value: nativeWei > 0n ? `~${formatNative(nativeWei)} ${nativeSymbol(sel.source.chainId)}` : "Gas only" },
6865
7349
  ...durationLabel(sel.quote.estimatedDuration) ? [{ label: "Estimated time", value: durationLabel(sel.quote.estimatedDuration) }] : []
6866
7350
  ] : [];
6867
- const loadingPlan = flow.status === "loading" || holdings.loading && !sel;
7351
+ const loadingPlan = flow.status === "loading" || holdings.loading && !sel || pricing !== null;
6868
7352
  return /* @__PURE__ */ jsxRuntime.jsx(WidgetShell, { title: config.title || "Complete payment", theme: config.theme, heightPx: props.heightPx, walletSlot, onClose: props.onClose, children: hist && wallet.account ? /* @__PURE__ */ jsxRuntime.jsx(TxHistoryPanel, { account: wallet.account, tokens: registryTokens, vaultIcons: catalogue?.vaultIcons, initialEntry: hist.entry ?? null, onBack: closeHistory }) : view === "select" && wallet.account ? /* @__PURE__ */ jsxRuntime.jsx(
6869
7353
  TokenSelect,
6870
7354
  {
6871
7355
  title: "Pay with",
7356
+ side: "from",
7357
+ selected: sel ? { chainId: sel.source.chainId, symbol: sel.source.asset } : null,
7358
+ fetchPrices: engine.fetchPrices,
6872
7359
  chains: fundingChains,
6873
7360
  tokens: fundingTokens,
6874
- balances: holdings.balances,
7361
+ balances: listBalances,
6875
7362
  optionStates,
6876
7363
  onBack: closeSelector,
6877
7364
  onPick: pickFunding
@@ -6902,7 +7389,7 @@ function PayCard(props) {
6902
7389
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-pane", "data-kind": "pay", children: [
6903
7390
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pane-label", children: "You pay" }),
6904
7391
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-pane-mid", children: [
6905
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-out", "aria-live": "polite", children: loadingPlan ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "\u2026" }) : sel && selectedVisible ? /* @__PURE__ */ jsxRuntime.jsx(AmountText, { value: groupDecimal(atLeastCents(sel.source.payAmount)) }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "\u2014" }) }),
7392
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-out", "aria-live": "polite", children: loadingPlan ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-skel sg-skel--amt", "data-testid": "pay-loading-amount", "aria-hidden": "true" }) : sel && selectedVisible ? /* @__PURE__ */ jsxRuntime.jsx(AmountText, { value: groupDecimal(atLeastCents(sel.source.payAmount)) }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "\u2014" }) }),
6906
7393
  /* @__PURE__ */ jsxRuntime.jsx(
6907
7394
  TokenButton,
6908
7395
  {
@@ -6916,12 +7403,22 @@ function PayCard(props) {
6916
7403
  }
6917
7404
  )
6918
7405
  ] }),
6919
- /* @__PURE__ */ jsxRuntime.jsx(PaneFoot, { usd: sel && selectedVisible ? usdOf(sel.source.payAmount, prices[selSymbol]) : null, balance: selBal ? shortBalance(selBal.formatted) : null })
7406
+ /* @__PURE__ */ jsxRuntime.jsx(PaneFoot, { usd: sel && selectedVisible ? usdOf2(sel.source.payAmount, prices[selSymbol]) : null, balance: selBal ? shortBalance(selBal.formatted) : null })
6920
7407
  ] }),
7408
+ loadingPlan ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-pay-loading", "data-testid": "pay-loading", role: "status", children: [
7409
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-skel sg-skel--row" }),
7410
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-skel sg-skel--row" }),
7411
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-muted sg-pay-loading-line", children: [
7412
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-spinner", "aria-hidden": "true" }),
7413
+ " ",
7414
+ pricing ? "Pricing this option\u2026" : "Checking your balances and finding the best way to pay\u2026"
7415
+ ] })
7416
+ ] }) : null,
7417
+ pickError ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { tone: "error", children: pickError }) : null,
6921
7418
  flow.status === "error" && flow.error ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { tone: "error", children: flow.error }) : null,
6922
7419
  scannedEmpty ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-note", children: "None of your balances can cover this yet \u2014 pick a different asset to fund with." }) : null,
6923
7420
  flow.status === "ready" && !visibleRoutes.length ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { children: "No funding route matches the accepted assets for this payment." }) : null,
6924
- sel && flow.status !== "loading" ? /* @__PURE__ */ jsxRuntime.jsx(
7421
+ sel && !loadingPlan ? /* @__PURE__ */ jsxRuntime.jsx(
6925
7422
  DetailButton,
6926
7423
  {
6927
7424
  btnRef: complianceBtnRef,
@@ -6933,7 +7430,7 @@ function PayCard(props) {
6933
7430
  onClick: () => setSheet(true)
6934
7431
  }
6935
7432
  ) : null,
6936
- sel && selectedVisible && flow.status !== "loading" ? /* @__PURE__ */ jsxRuntime.jsx(RateBox, { rowsOnly: true, rate: null, fromSymbol: "", toTicker: "", rows: feeRows }) : null
7433
+ sel && selectedVisible && !loadingPlan ? /* @__PURE__ */ jsxRuntime.jsx(RateBox, { rowsOnly: true, rate: null, fromSymbol: "", toTicker: "", rows: feeRows }) : null
6937
7434
  ] }),
6938
7435
  submitting ? /* @__PURE__ */ jsxRuntime.jsx(StepList, { steps: flow.steps }) : null,
6939
7436
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -6941,7 +7438,7 @@ function PayCard(props) {
6941
7438
  {
6942
7439
  onClick: parked || !selectedVisible ? void 0 : flow.submit,
6943
7440
  busy: submitting,
6944
- disabled: parked || !selectedVisible || flow.insufficient || !!flow.nativeShortfall || flow.status === "loading",
7441
+ disabled: parked || !selectedVisible || flow.insufficient || !!flow.nativeShortfall || loadingPlan,
6945
7442
  children: payLabel
6946
7443
  }
6947
7444
  ) })
@@ -7279,6 +7776,10 @@ function ExchangeCard(props) {
7279
7776
  }
7280
7777
  return states;
7281
7778
  }, [catalogue, fromToken]);
7779
+ const toPickerVisible = react.useMemo(
7780
+ () => destinationStates ? toPickerTokens.filter((t) => !destinationStates[`${Number(t.chainId)}:${String(t.address || "").toLowerCase()}`]?.disabled) : toPickerTokens,
7781
+ [toPickerTokens, destinationStates]
7782
+ );
7282
7783
  const normalizedAmount = normalizeDecimalText(amount);
7283
7784
  const amountValid = /^\d+(\.\d+)?$/.test(normalizedAmount) && Number(normalizedAmount) > 0 && Number(normalizedAmount) <= 1e9;
7284
7785
  const rampMode = mode !== "exchange";
@@ -7414,8 +7915,8 @@ function ExchangeCard(props) {
7414
7915
  const routeShape = via === null ? "Direct" : via ? `Via ${via}` : "Two steps";
7415
7916
  const compliance = selected?.quote.compliance;
7416
7917
  const complianceHasQuote = Boolean(selected && flow.status !== "loading");
7417
- const fromUsd = usdOf(normalizedAmount, prices[from?.symbol ?? ""]);
7418
- const toUsd = usdOf(receive, prices[to?.symbol ?? ""]);
7918
+ const fromUsd = usdOf2(normalizedAmount, prices[from?.symbol ?? ""]);
7919
+ const toUsd = usdOf2(receive, prices[to?.symbol ?? ""]);
7419
7920
  const flippable = !rampMode && !submitting && Boolean(to && sourceTokens.some((t) => Number(t.chainId) === to.chainId && symbolKey(t.symbol) === to.symbol));
7420
7921
  const flip = () => {
7421
7922
  if (!flippable) return;
@@ -7498,8 +7999,11 @@ function ExchangeCard(props) {
7498
7999
  TokenSelect,
7499
8000
  {
7500
8001
  title: isFrom ? "Exchange from" : "Exchange to",
8002
+ side: isFrom ? "from" : "to",
8003
+ selected: isFrom ? from : to,
8004
+ fetchPrices: engine.fetchPrices,
7501
8005
  chains,
7502
- tokens: isFrom ? fromPickerTokens : toPickerTokens,
8006
+ tokens: isFrom ? fromPickerTokens : toPickerVisible,
7503
8007
  balances,
7504
8008
  optionStates: isFrom ? void 0 : destinationStates,
7505
8009
  loading: !catalogue?.ready,