@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.
@@ -1,5 +1,5 @@
1
- import { CHAIN_DISPLAY_NAMES, EXECUTABLE_STABLE_ASSETS, STABLE_ASSETS, SUPPORTED_ASSETS, complianceView, complianceTagOf, symbolKey, normalizeDecimalText, findToken, laneLimitFor, laneLimitSymbol, tokenTicker, exceedsLaneLimit, assetDecimals, parseUnitsDecimal, counterpartTokens, assetClassOf, brokenLaneFor, brokenLaneReason, destinationAvailability, laneLimitHint, tickerOn, laneLimitError, routeNativeValue, formatNative, nativeSymbol, amountFieldError, SUPPORTED_CHAIN_IDS, formatUnits, complianceChecks, DIRECT_CHECK_IDS, createEngine, checkNativeFee, nativeFeeShortLabel, nativeFeeShortMessage, allowanceCovers, validatePlannedTransaction, foldTicker, unattributedComplianceReasons, distinctScreenedWallets, formatJurisdiction, humanizeComplianceReason, DIRECT_SCOPE_NOTE, categoryLabel, SCREENING_BUCKETS, BUNDLED_RPC } from './chunk-BOEY6DG5.js';
2
- import { createContext, useState, useRef, useMemo, useEffect, useCallback, useId, createElement, useContext, useSyncExternalStore, useLayoutEffect, useReducer } from 'react';
1
+ import { CHAIN_DISPLAY_NAMES, EXECUTABLE_STABLE_ASSETS, STABLE_ASSETS, SUPPORTED_ASSETS, complianceView, complianceTagOf, symbolKey, normalizeDecimalText, findToken, laneLimitFor, laneLimitSymbol, tokenTicker, exceedsLaneLimit, assetDecimals, parseUnitsDecimal, counterpartTokens, assetClassOf, brokenLaneFor, brokenLaneReason, destinationAvailability, laneLimitHint, tickerOn, laneLimitError, routeNativeValue, formatNative, nativeSymbol, amountFieldError, SUPPORTED_CHAIN_IDS, formatUnits, complianceChecks, DIRECT_CHECK_IDS, createEngine, checkNativeFee, nativeFeeShortLabel, nativeFeeShortMessage, allowanceCovers, validatePlannedTransaction, unattributedComplianceReasons, distinctScreenedWallets, formatJurisdiction, humanizeComplianceReason, DIRECT_SCOPE_NOTE, categoryLabel, SCREENING_BUCKETS, BUNDLED_RPC, foldTicker } from './chunk-A7ADZJXA.js';
2
+ import { createContext, useState, useRef, useMemo, useEffect, useCallback, useId, createElement, useContext, useLayoutEffect, useSyncExternalStore, useReducer } from 'react';
3
3
  import { createRoot } from 'react-dom/client';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
 
@@ -383,6 +383,10 @@ function useFlow(args) {
383
383
  const routes = plan?.routes ?? [];
384
384
  const selected = useMemo(() => routes.find((r) => r.id === selectedId) ?? routes.find((r) => r.recommended) ?? routes[0] ?? null, [routes, selectedId]);
385
385
  const reload = useCallback(() => setNonce((n) => n + 1), []);
386
+ const addRoute = useCallback((route) => {
387
+ setPlan((p) => p ? { ...p, routes: [...p.routes.filter((r) => r.id !== route.id), route] } : p);
388
+ setSelectedId(route.id);
389
+ }, []);
386
390
  useEffect(() => {
387
391
  if (busyRef.current) return;
388
392
  setFieldError(null);
@@ -605,7 +609,8 @@ function useFlow(args) {
605
609
  quotePaused,
606
610
  quoteStale,
607
611
  submit,
608
- reload
612
+ reload,
613
+ addRoute
609
614
  };
610
615
  }
611
616
  function balanceKey(chainId, tokenAddress) {
@@ -867,6 +872,11 @@ var WIDGET_CSS = `
867
872
  /* skeleton loading */
868
873
  .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}
869
874
 
875
+ .sg-skel--amt{display:inline-block;width:112px;height:30px;margin:0;vertical-align:middle;border-radius:10px}
876
+ .sg-skel--row{height:48px}
877
+ .sg-pay-loading{display:flex;flex-direction:column}
878
+ .sg-pay-loading-line{display:flex;align-items:center;gap:8px;font-size:13px;line-height:16px;padding:2px 2px 0}
879
+
870
880
  /* spinner */
871
881
  .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}
872
882
  @keyframes sg-spin{to{transform:rotate(360deg)}}
@@ -942,46 +952,79 @@ img.sg-tok-badge{width:16px;padding:0;object-fit:cover;background:var(--sg-bg)}
942
952
  .sg-pct:hover:not(:disabled){color:var(--sg-accent)}
943
953
  .sg-pct:disabled{opacity:.55;cursor:not-allowed}
944
954
 
945
- /* full-panel token selector (Exchange from / Exchange to) */
955
+ /* full-panel takeover head (transaction history) */
946
956
  .sg-sel-head{display:flex;align-items:center;margin-bottom:14px}
947
957
  .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}
948
958
  .sg-back:hover{background:var(--sg-surface)}
949
959
  .sg-sel-title{flex:1 1 auto;min-width:0;text-align:center;font-size:15px;font-weight:600;margin-right:32px}
950
960
  /* Whose transactions these are \u2014 history is per wallet, and the takeover hides the header's pill. */
951
961
  .sg-sel-sub{display:block;font-size:11px;font-weight:600;color:var(--sg-text-muted);margin-top:1px}
952
- /* Scrolls at ~2.5 rows. The catalogue's destination chains outnumber its source chains three to one
953
- (9 escrow chains, ~37 total), so an ungated grid was eight rows tall and pushed the token list \u2014
954
- the thing the panel exists for \u2014 below the fold. The fade is a scroll affordance, not decoration. */
955
- .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)}
956
- /* No mask once everything fits \u2014 a fade under a grid with nothing below it reads as a rendering bug. */
957
- .sg-chain-grid[data-scroll="false"]{mask-image:none;-webkit-mask-image:none;overflow-y:visible;max-height:none}
958
- .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}
959
- .sg-chain-chip img{width:22px;height:22px;border-radius:999px;display:block}
960
- .sg-chain-chip:hover{border-color:color-mix(in srgb,var(--sg-accent) 45%,var(--sg-border))}
961
- .sg-chain-chip[data-selected="true"]{border-color:var(--sg-accent);background:color-mix(in srgb,var(--sg-accent) 10%,var(--sg-surface))}
962
- .sg-search{position:relative;margin-bottom:10px}
963
- .sg-search svg{position:absolute;left:12px;top:50%;transform:translateY(-50%);color:var(--sg-text-muted);pointer-events:none}
964
- .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}
965
- .sg-search input:focus{border-color:var(--sg-accent)}
966
962
  .sg-toklist{display:flex;flex-direction:column;gap:2px;max-height:320px;overflow-y:auto;margin:0 -6px;padding:0 6px;scrollbar-width:thin}
967
- .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}
968
- .sg-tokrow:hover{background:var(--sg-surface)}
969
- .sg-tokrow-main{flex:1 1 auto;min-width:0}
970
- .sg-tokrow-sym{display:block;font-size:15px;font-weight:700;line-height:1.2}
971
- .sg-tokrow-name{display:block;font-size:12px;color:var(--sg-text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
972
- .sg-tokrow-end{flex:0 0 auto;text-align:right}
973
- .sg-tokrow-bal{display:block;font-size:13px;font-weight:600;font-variant-numeric:tabular-nums}
974
- .sg-tokrow-chain{display:block;font-size:11px;color:var(--sg-text-muted)}
975
- /* funding rows the wallet can't cover (zero / insufficient): greyed, non-interactive, reason hint.
976
- Mirrors RouteList's data-short dim + warn tone; no hover lift. Theme-aware via --sg-* vars. */
977
- .sg-tokrow--off,.sg-tokrow[disabled]{opacity:.5;cursor:not-allowed}
978
- .sg-tokrow--off:hover,.sg-tokrow[disabled]:hover{background:transparent}
979
- .sg-tokrow--off .sg-tokrow-sym,.sg-tokrow--off .sg-tokrow-name,.sg-tokrow--off .sg-tokrow-bal{color:var(--sg-text-muted)}
980
- .sg-tokrow-hint{display:block;font-size:11px;font-weight:600;color:var(--sg-danger)}
981
- /* on a row that stays selectable (a limited lane): a caveat, not a refusal */
982
- .sg-tokrow-hint[data-tone="note"]{color:var(--sg-text-muted)}
983
963
  .sg-sel-empty{padding:26px 10px;text-align:center;font-size:13px;color:var(--sg-text-muted)}
984
964
 
965
+ /* Token picker, token first then network \u2014 the ZeroDelta dapp's TokenSelectModal (Figma 708:27430,
966
+ 2517:52576), drawn in the widget's own theme: the dapp's brand tint is the accent, its green the
967
+ success token. Geometry is the dapp's: 32px plates, 24px row plates, 16px chain marks, 20px gaps. The list keeps
968
+ the previous picker's 320px cap so opening it does not grow the card. */
969
+ .sg-pk{display:flex;flex-direction:column;gap:20px}
970
+ .sg-pk-head{display:flex;align-items:center;justify-content:space-between;gap:8px}
971
+ .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)}
972
+ .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}
973
+ .sg-pk-clear{padding:2px}
974
+ .sg-pk-close:hover,.sg-pk-clear:hover{color:var(--sg-text)}
975
+ .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}
976
+ .sg-pk-backlink:hover{color:var(--sg-text)}
977
+ .sg-pk-intro{display:flex;flex-direction:column;gap:4px}
978
+ .sg-pk-lead{margin:0;font-size:14px;line-height:1.3;color:var(--sg-text-muted)}
979
+ .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}
980
+ .sg-pk-search:focus-within{border-color:var(--sg-accent);color:var(--sg-accent)}
981
+ .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}
982
+ .sg-pk-search input::placeholder{color:var(--sg-text-muted)}
983
+ .sg-pk-body{display:flex;flex-direction:column;gap:8px}
984
+ .sg-pk-selected{display:flex;flex-direction:column;gap:8px;margin-bottom:8px}
985
+ .sg-pk-cap{margin:0;font-size:12px;line-height:1.2;color:var(--sg-text-muted)}
986
+ .sg-pk-list{display:flex;flex-direction:column;gap:4px;max-height:320px;overflow-y:auto;margin:-1px;padding:1px;scrollbar-width:thin}
987
+ .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}
988
+ .sg-pk-row:hover{background:color-mix(in srgb,var(--sg-accent) 8%,transparent)}
989
+ .sg-pk-row--net{padding:20px 16px}
990
+ .sg-pk-row[data-zero]{background:color-mix(in srgb,var(--sg-text) 4%,transparent)}
991
+ .sg-pk-row[data-zero]:hover{background:color-mix(in srgb,var(--sg-accent) 4%,transparent)}
992
+ .sg-pk-row[data-selected]{background:color-mix(in srgb,var(--sg-success) 6%,transparent)}
993
+ .sg-pk-row[data-selected]:hover{background:color-mix(in srgb,var(--sg-success) 8%,transparent)}
994
+ .sg-pk-row--off{opacity:.6;cursor:default}
995
+ .sg-pk-row--off:hover{background:color-mix(in srgb,var(--sg-accent) 4%,transparent)}
996
+ .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}
997
+ .sg-pk-left{display:flex;align-items:center;gap:12px;flex:1 1 auto;min-width:0}
998
+ .sg-pk-text{display:flex;flex-direction:column;align-items:flex-start;gap:2px;flex:1 1 auto;min-width:0;overflow:hidden}
999
+ .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%}
1000
+ .sg-pk-alt{margin-left:8px;font-size:14px;font-weight:400;color:var(--sg-text-muted)}
1001
+ .sg-pk-line{display:flex;align-items:center;gap:4px;min-width:0;max-width:100%}
1002
+ .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}
1003
+ .sg-pk-note{font-size:13px;line-height:1.3;color:var(--sg-text-muted)}
1004
+ .sg-pk-plate,.sg-pk-chainwrap{position:relative;display:grid;place-items:center;flex:0 0 auto;width:32px;height:32px}
1005
+ .sg-pk-plate-in{display:grid;place-items:center;width:32px;height:32px;overflow:hidden;border-radius:16px;background:var(--sg-surface)}
1006
+ .sg-pk-plate-in img{width:32px;height:32px;display:block;object-fit:cover}
1007
+ .sg-pk-plate-fb{font-size:10px;font-weight:700;color:var(--sg-accent)}
1008
+ .sg-pk-plate[data-muted] .sg-pk-plate-in{filter:grayscale(1)}
1009
+ .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)}
1010
+ .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)}
1011
+ .sg-pk-chain img{width:32px;height:32px;display:block;object-fit:cover}
1012
+ .sg-pk-marks{display:flex;align-items:center;gap:4px;flex:0 0 auto}
1013
+ .sg-pk-stack{display:flex;align-items:center;height:18px}
1014
+ .sg-pk-markwrap{display:grid;flex:0 0 auto}
1015
+ .sg-pk-markwrap+.sg-pk-markwrap{margin-left:-2px}
1016
+ .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)}
1017
+ .sg-pk-mark img{width:16px;height:16px;display:block;object-fit:cover}
1018
+ .sg-pk-more{font-size:14px;line-height:1.3;color:var(--sg-text-muted)}
1019
+ .sg-pk-chev{display:grid;place-items:center;flex:0 0 auto;width:16px;height:16px;color:var(--sg-text-muted)}
1020
+ .sg-pk-chev svg{width:16px;height:16px}
1021
+ .sg-pk-chev--sm,.sg-pk-chev--sm svg{width:14px;height:14px}
1022
+ .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}
1023
+ .sg-pk-bal-usd{font-size:16px;font-weight:500;line-height:1.2;color:var(--sg-t90)}
1024
+ .sg-pk-bal-amt{font-size:13px;line-height:1.4;color:var(--sg-text-muted)}
1025
+ .sg-pk-bal-zero{flex:0 0 auto;font-size:16px;font-weight:700;color:var(--sg-t35)}
1026
+ .sg-pk-empty{margin:0;padding:32px 0;text-align:center;font-size:14px;color:var(--sg-text-muted)}
1027
+
985
1028
  /* wide (duo) layout: main card + receive/routes side card. The collapse is keyed to the WIDGET'S
986
1029
  OWN available width (container query) \u2014 an embedded widget cannot infer the host layout from the
987
1030
  viewport. The viewport media query stays as a fallback for engines without container queries. */
@@ -1928,6 +1971,200 @@ function chainLogoCandidates(chainId, logoUrl) {
1928
1971
  if (bundled) out.push(bundled);
1929
1972
  return out;
1930
1973
  }
1974
+
1975
+ // src/react/ui/tokenGroups.ts
1976
+ var rowKey = (t) => `${Number(t.chainId)}:${String(t.address || "").toLowerCase()}`;
1977
+ var CHAIN_TVL_ORDER = [
1978
+ 1,
1979
+ 1151111081099710,
1980
+ 8453,
1981
+ 56,
1982
+ 42161,
1983
+ 999,
1984
+ 143,
1985
+ 4663,
1986
+ 137,
1987
+ 9745,
1988
+ 43114,
1989
+ 10,
1990
+ 196,
1991
+ 57073,
1992
+ 14,
1993
+ 5e3,
1994
+ 2818,
1995
+ 30,
1996
+ 4217,
1997
+ 747474,
1998
+ 1672,
1999
+ 988,
2000
+ 480,
2001
+ 81457,
2002
+ 1329,
2003
+ 80094,
2004
+ 130,
2005
+ 4326,
2006
+ 59144,
2007
+ 2222,
2008
+ 252,
2009
+ 146,
2010
+ 324,
2011
+ 1776,
2012
+ 534352,
2013
+ 1030,
2014
+ 1868,
2015
+ 98866,
2016
+ 169,
2017
+ 1088,
2018
+ 50,
2019
+ 34443,
2020
+ 1135,
2021
+ 88,
2022
+ 48900,
2023
+ 151,
2024
+ 7777777,
2025
+ 1923,
2026
+ 3343,
2027
+ 81224,
2028
+ 21e6
2029
+ ];
2030
+ var TOKEN_MARKET_CAP_ORDER = ["USDT", "USDC", "USDS", "DAI", "USDE", "USD1", "USDG", "PYUSD", "XAUT", "RLUSD", "USDF", "GHO", "USD0", "USDTB", "AUSD", "WM"];
2031
+ var CHAIN_RANK = new Map(CHAIN_TVL_ORDER.map((chainId, index) => [chainId, index]));
2032
+ var TOKEN_RANK = new Map(TOKEN_MARKET_CAP_ORDER.map((symbol, index) => [symbol, index]));
2033
+ function chainTvlRank(chainId) {
2034
+ return CHAIN_RANK.get(Number(chainId)) ?? CHAIN_TVL_ORDER.length;
2035
+ }
2036
+ function tokenMarketCapRank(symbol) {
2037
+ return TOKEN_RANK.get(String(symbol).toUpperCase()) ?? TOKEN_MARKET_CAP_ORDER.length;
2038
+ }
2039
+ function dominantSymbol(tokens) {
2040
+ const counts = /* @__PURE__ */ new Map();
2041
+ for (const t of tokens) counts.set(t.symbol, (counts.get(t.symbol) ?? 0) + 1);
2042
+ let best = tokens[0].symbol;
2043
+ for (const [symbol, count] of counts) if (count > (counts.get(best) ?? 0)) best = symbol;
2044
+ return best;
2045
+ }
2046
+ function priceOf(prices, symbol) {
2047
+ const p = prices?.[String(symbol).toUpperCase()];
2048
+ return typeof p === "number" && Number.isFinite(p) ? p : void 0;
2049
+ }
2050
+ function buildGroup(key, members, prices) {
2051
+ const tokens = members.map((m) => m.token);
2052
+ let amount = null;
2053
+ let usd = null;
2054
+ for (const m of members) {
2055
+ if (m.balance == null) continue;
2056
+ amount = (amount ?? 0) + m.balance;
2057
+ const price = priceOf(prices, m.token.symbol);
2058
+ if (price !== void 0) usd = (usd ?? 0) + m.balance * price;
2059
+ }
2060
+ const first = members[0].token;
2061
+ return {
2062
+ key,
2063
+ symbol: dominantSymbol(tokens),
2064
+ name: String(first.name || first.symbol),
2065
+ logoUrl: first.logoUrl,
2066
+ deployments: members,
2067
+ unavailable: members.every((m) => m.disabled) ? { reason: members.find((m) => m.reason)?.reason } : null,
2068
+ amount,
2069
+ usd
2070
+ };
2071
+ }
2072
+ function byDeployment(a, b) {
2073
+ return Number(a.disabled) - Number(b.disabled) || (b.balance ?? 0) - (a.balance ?? 0) || chainTvlRank(a.token.chainId) - chainTvlRank(b.token.chainId);
2074
+ }
2075
+ function byPickability(a, b) {
2076
+ const zero = (g) => g.amount === 0 ? 1 : 0;
2077
+ 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);
2078
+ }
2079
+ function groupDeployments(deployments, prices) {
2080
+ const order = [];
2081
+ const members = /* @__PURE__ */ new Map();
2082
+ for (const d of [...deployments].sort(byDeployment)) {
2083
+ const key = String(d.token.symbol).toUpperCase();
2084
+ const list = members.get(key);
2085
+ if (list) list.push(d);
2086
+ else {
2087
+ members.set(key, [d]);
2088
+ order.push(key);
2089
+ }
2090
+ }
2091
+ return order.map((key) => buildGroup(key, members.get(key), prices)).sort(byPickability);
2092
+ }
2093
+ var CHAIN_ALIASES = {
2094
+ 56: ["bsc", "binance"],
2095
+ 137: ["matic"],
2096
+ 43114: ["avax"]
2097
+ };
2098
+ function labelForms(label) {
2099
+ const lower = label.trim().toLowerCase();
2100
+ if (!lower) return [];
2101
+ const compact = lower.replace(/[^a-z0-9]/g, "");
2102
+ return compact && compact !== lower ? [lower, compact] : [lower];
2103
+ }
2104
+ function buildChainSearchTerms(chains) {
2105
+ const byId = /* @__PURE__ */ new Map();
2106
+ const ids = /* @__PURE__ */ new Set([...chains.map((c) => Number(c.chainId)), ...Object.keys(CHAIN_LABELS).map(Number)]);
2107
+ for (const id of ids) {
2108
+ const chain = chains.find((c) => Number(c.chainId) === id);
2109
+ const terms = /* @__PURE__ */ new Set();
2110
+ for (const label of [chain?.displayName, chain?.name, typeof chain?.slug === "string" ? chain.slug : void 0, CHAIN_LABELS[id]]) {
2111
+ if (label) for (const form of labelForms(label)) terms.add(form);
2112
+ }
2113
+ for (const alias of CHAIN_ALIASES[id] ?? []) terms.add(alias);
2114
+ byId.set(id, [...terms]);
2115
+ }
2116
+ return byId;
2117
+ }
2118
+ function splitSearchTerms(query) {
2119
+ return query.trim().toLowerCase().split(/\s+/).filter(Boolean);
2120
+ }
2121
+ function looksLikeAddress(term) {
2122
+ return /^(0x)?[0-9a-f]{4,}$/.test(term);
2123
+ }
2124
+ function chainMatches(term, token, chainTerms) {
2125
+ if (term === String(Number(token.chainId))) return true;
2126
+ return chainTerms.some((chainTerm) => chainTerm.includes(term));
2127
+ }
2128
+ function tokenMatches(term, token, asset) {
2129
+ 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.
2130
+ foldTicker(tokenTicker(token)).includes(foldTicker(term)) || String(token.name || "").toLowerCase().includes(term) || looksLikeAddress(term) && String(token.address || "").toLowerCase().includes(term);
2131
+ }
2132
+ function matchingDeployments(terms, group, chainTerms) {
2133
+ if (terms.length === 0) return group.deployments;
2134
+ return group.deployments.filter((d) => {
2135
+ const ct = chainTerms.get(Number(d.token.chainId)) ?? [];
2136
+ return terms.every((term) => tokenMatches(term, d.token, group) || chainMatches(term, d.token, ct));
2137
+ });
2138
+ }
2139
+ function searchGroups(groups, query, chainTerms, prices) {
2140
+ const terms = splitSearchTerms(query);
2141
+ if (terms.length === 0) return groups;
2142
+ const rows = [];
2143
+ for (const g of groups) {
2144
+ const members = matchingDeployments(terms, g, chainTerms);
2145
+ if (members.length === 0) continue;
2146
+ rows.push(members.length === g.deployments.length ? g : buildGroup(g.key, members, prices));
2147
+ }
2148
+ return rows.sort(byPickability);
2149
+ }
2150
+ function groupDecimal2(value) {
2151
+ const match = value.match(/^([+-]?)(\d+)(\.\d+)?$/);
2152
+ if (!match) return value;
2153
+ return `${match[1]}${match[2].replace(/\B(?=(\d{3})+(?!\d))/g, ",")}${match[3] ?? ""}`;
2154
+ }
2155
+ function humanAmount(n, maxFrac = 6) {
2156
+ if (!Number.isFinite(n)) return String(n);
2157
+ if (n === 0) return "0";
2158
+ const digits = Math.min(Math.max(0, Math.trunc(maxFrac)), 8);
2159
+ const fixed = n.toFixed(digits);
2160
+ const out = fixed.includes(".") ? fixed.replace(/\.?0+$/, "") : fixed;
2161
+ if (Number(out) === 0) return `<${digits > 0 ? `0.${"0".repeat(digits - 1)}1` : "1"}`;
2162
+ return groupDecimal2(out);
2163
+ }
2164
+ function formatBalanceUsd(value) {
2165
+ if (!Number.isFinite(value) || value <= 0) return "$0.00";
2166
+ return value < 0.01 ? "<$0.01" : `$${value.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
2167
+ }
1931
2168
  var CHAIN_SHORT = {
1932
2169
  1: "ETH",
1933
2170
  10: "OP",
@@ -2009,103 +2246,280 @@ function FundingTile(props) {
2009
2246
  /* @__PURE__ */ jsx("span", { className: "sg-tile-main", children: main })
2010
2247
  ] });
2011
2248
  }
2012
- function ChainChip(props) {
2249
+ function ChainMark(props) {
2013
2250
  const [failed, setFailed] = useState([]);
2014
- const src = chainLogoCandidates(props.chain?.chainId, props.chain?.logoUrl).find((u) => !failed.includes(u));
2015
- const name = props.name ?? props.label;
2016
- return /* @__PURE__ */ 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__ */ jsx("img", { src, alt: "", loading: "lazy", onError: () => setFailed((f) => [...f, src]) }) : props.label });
2251
+ const src = chainLogoCandidates(props.chainId, props.chain?.logoUrl).find((u) => !failed.includes(u));
2252
+ return /* @__PURE__ */ jsx("span", { className: props.size === "row" ? "sg-pk-chain" : "sg-pk-mark", "aria-hidden": "true", children: src ? /* @__PURE__ */ jsx("img", { src, alt: "", loading: "lazy", onError: () => setFailed((f) => [...f, src]) }) : /* @__PURE__ */ jsx("span", { children: chainBadge(props.chainId) }) });
2253
+ }
2254
+ var MARK_LIMIT = 3;
2255
+ function ChainMarks(props) {
2256
+ const ids = props.chainIds;
2257
+ if (!ids.length) return null;
2258
+ const shown = ids.slice(0, MARK_LIMIT);
2259
+ const overflow = ids.length - shown.length;
2260
+ const marks = shown.map((id) => /* @__PURE__ */ jsx("span", { className: "sg-pk-markwrap", children: /* @__PURE__ */ jsx(ChainMark, { chainId: id, chain: props.chainById.get(id), size: "mini" }) }, id));
2261
+ return /* @__PURE__ */ jsxs("span", { className: "sg-pk-marks", children: [
2262
+ props.decorative ? /* @__PURE__ */ jsx("span", { className: "sg-pk-stack", "aria-hidden": "true", children: marks }) : /* @__PURE__ */ jsx("span", { className: "sg-pk-stack", role: "img", "aria-label": `${ids.length} ${ids.length === 1 ? "network" : "networks"}`, children: marks }),
2263
+ overflow > 0 ? /* @__PURE__ */ jsxs("span", { className: "sg-pk-more", "aria-hidden": "true", children: [
2264
+ "+",
2265
+ overflow
2266
+ ] }) : null
2267
+ ] });
2268
+ }
2269
+ function TokenPlate(props) {
2270
+ const [failed, setFailed] = useState([]);
2271
+ const src = tokenLogoCandidates(props.symbol, props.logoUrl).find((u) => !failed.includes(u));
2272
+ return /* @__PURE__ */ jsxs("span", { className: "sg-pk-plate", "data-muted": props.muted || void 0, children: [
2273
+ /* @__PURE__ */ jsx("span", { className: "sg-pk-plate-in", children: src ? /* @__PURE__ */ jsx("img", { src, alt: "", loading: "lazy", onError: () => setFailed((f) => [...f, src]) }) : /* @__PURE__ */ jsx("span", { className: "sg-pk-plate-fb", children: props.symbol.slice(0, 4) }) }),
2274
+ props.checked ? /* @__PURE__ */ jsx(TickBadge, {}) : null
2275
+ ] });
2276
+ }
2277
+ function TickBadge() {
2278
+ return /* @__PURE__ */ jsx("span", { className: "sg-pk-tick", "aria-hidden": "true", children: /* @__PURE__ */ jsxs("svg", { width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: [
2279
+ /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "11", fill: "currentColor" }),
2280
+ /* @__PURE__ */ jsx("path", { d: "m7 12.5 3.2 3.2L17 9", stroke: "#fff", strokeWidth: "2.6", strokeLinecap: "round", strokeLinejoin: "round" })
2281
+ ] }) });
2282
+ }
2283
+ function BalanceColumn(props) {
2284
+ if (props.amount == null) return null;
2285
+ if (props.amount === 0) return /* @__PURE__ */ jsx("span", { className: "sg-pk-bal-zero", children: "0.00" });
2286
+ return /* @__PURE__ */ jsxs("span", { className: "sg-pk-bal", children: [
2287
+ /* @__PURE__ */ jsx("span", { className: "sg-pk-bal-usd sg-mono", children: props.usd == null ? "\u2014" : formatBalanceUsd(props.usd) }),
2288
+ /* @__PURE__ */ jsxs("span", { className: "sg-pk-bal-amt sg-mono", children: [
2289
+ humanAmount(props.amount, 6),
2290
+ " ",
2291
+ props.symbol
2292
+ ] })
2293
+ ] });
2294
+ }
2295
+ var WALLET_STATE_REASONS = /* @__PURE__ */ new Set(["no-balance", "insufficient"]);
2296
+ function isPick(sel, t) {
2297
+ return !!sel && Number(sel.chainId) === Number(t.chainId) && String(sel.symbol).toUpperCase() === String(t.symbol).toUpperCase();
2298
+ }
2299
+ function usdOf(balance, prices, symbol) {
2300
+ const price = priceOf(prices, symbol);
2301
+ return balance == null || price === void 0 ? null : balance * price;
2302
+ }
2303
+ function UnavailableRow(props) {
2304
+ return /* @__PURE__ */ 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__ */ jsxs("span", { className: "sg-pk-left", children: [
2305
+ props.icon,
2306
+ /* @__PURE__ */ jsxs("span", { className: "sg-pk-text", children: [
2307
+ /* @__PURE__ */ jsx("span", { className: "sg-pk-label", children: props.label }),
2308
+ /* @__PURE__ */ jsx("span", { className: "sg-pk-sub", children: props.reason || "Not available right now" })
2309
+ ] })
2310
+ ] }) });
2017
2311
  }
2018
2312
  function SearchGlyph() {
2019
- return /* @__PURE__ */ jsxs("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", "aria-hidden": "true", children: [
2313
+ return /* @__PURE__ */ jsxs("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", "aria-hidden": "true", children: [
2020
2314
  /* @__PURE__ */ jsx("circle", { cx: "11", cy: "11", r: "7" }),
2021
2315
  /* @__PURE__ */ jsx("path", { d: "m20 20-3.5-3.5" })
2022
2316
  ] });
2023
2317
  }
2024
- function BackGlyph() {
2025
- return /* @__PURE__ */ jsxs("svg", { width: "17", height: "17", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
2318
+ function CloseGlyph() {
2319
+ return /* @__PURE__ */ jsxs("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", "aria-hidden": "true", children: [
2320
+ /* @__PURE__ */ jsx("path", { d: "M18 6 6 18" }),
2321
+ /* @__PURE__ */ jsx("path", { d: "m6 6 12 12" })
2322
+ ] });
2323
+ }
2324
+ function ArrowLeftGlyph() {
2325
+ return /* @__PURE__ */ jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
2026
2326
  /* @__PURE__ */ jsx("path", { d: "M19 12H5" }),
2027
2327
  /* @__PURE__ */ jsx("path", { d: "m12 19-7-7 7-7" })
2028
2328
  ] });
2029
2329
  }
2030
- var rowKey = (t) => `${Number(t.chainId)}:${String(t.address || "").toLowerCase()}`;
2031
2330
  function TokenSelect(props) {
2032
- const [chainFilter, setChainFilter] = useState(null);
2331
+ const side = props.side ?? "from";
2033
2332
  const [query, setQuery] = useState("");
2034
- const chains = useMemo(() => {
2035
- const live = new Set(props.tokens.filter((t) => !props.optionStates?.[rowKey(t)]?.disabled).map((t) => Number(t.chainId)));
2036
- return props.chains.filter((c) => live.has(Number(c.chainId)));
2037
- }, [props.chains, props.tokens, props.optionStates]);
2038
- const activeFilter = chainFilter != null && chains.some((c) => Number(c.chainId) === chainFilter) ? chainFilter : null;
2039
- const rows = useMemo(() => {
2040
- const q = query.trim().toLowerCase();
2041
- const filtered = props.tokens.filter((t) => activeFilter == null ? true : Number(t.chainId) === activeFilter).filter((t) => {
2042
- if (!q) return true;
2043
- return String(t.symbol || "").toLowerCase().includes(q) || // The chain's own ticker too, with `₮` read as `T`: "usdt0" finds USD₮0.
2044
- 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
2045
- // show a three-letter badge, so "Katana" or "Berachain" has to be findable by typing it.
2046
- String(CHAIN_LABELS[Number(t.chainId)] || "").toLowerCase().includes(q);
2047
- });
2048
- const off = (t) => props.optionStates?.[rowKey(t)]?.disabled ? 1 : 0;
2049
- const balNum = (t) => {
2050
- const n = Number(props.balances?.[rowKey(t)]?.formatted);
2051
- return Number.isFinite(n) ? n : 0;
2333
+ const [openKey, setOpenKey] = useState(null);
2334
+ const listRef = useRef(null);
2335
+ const savedScroll = useRef(0);
2336
+ const chainById = useMemo(() => new Map(props.chains.map((c) => [Number(c.chainId), c])), [props.chains]);
2337
+ const chainName3 = (chainId) => CHAIN_LABELS[chainId] || chainById.get(chainId)?.displayName || chainById.get(chainId)?.name || `Chain ${chainId}`;
2338
+ const showBalances = side === "from" && !!props.balances && Object.keys(props.balances).length > 0;
2339
+ const [prices, setPrices] = useState({});
2340
+ const symbolKey2 = useMemo(() => [...new Set(props.tokens.map((t) => String(t.symbol).toUpperCase()))].sort().join(","), [props.tokens]);
2341
+ const fetchPrices = props.fetchPrices;
2342
+ useEffect(() => {
2343
+ if (!showBalances || !fetchPrices || !symbolKey2) return;
2344
+ let alive = true;
2345
+ let timer2;
2346
+ const ask = (retriesLeft) => {
2347
+ fetchPrices(symbolKey2.split(",")).then((next) => {
2348
+ if (!alive) return;
2349
+ setPrices(next);
2350
+ if (!Object.keys(next).length && retriesLeft > 0) timer2 = setTimeout(() => ask(retriesLeft - 1), retriesLeft > 1 ? 5e3 : 2e4);
2351
+ }).catch(() => {
2352
+ });
2052
2353
  };
2053
- return [...filtered].sort((a, b) => off(a) - off(b) || balNum(b) - balNum(a));
2054
- }, [props.tokens, activeFilter, query, props.balances, props.optionStates]);
2055
- return /* @__PURE__ */ jsxs("div", { children: [
2056
- /* @__PURE__ */ jsxs("div", { className: "sg-sel-head", children: [
2057
- /* @__PURE__ */ jsx("button", { type: "button", className: "sg-back", onClick: props.onBack, "aria-label": "Back", children: /* @__PURE__ */ jsx(BackGlyph, {}) }),
2058
- /* @__PURE__ */ jsx("div", { className: "sg-sel-title", children: props.title })
2059
- ] }),
2060
- /* @__PURE__ */ jsxs("div", { className: "sg-chain-grid", "data-scroll": chains.length > 14 ? void 0 : "false", role: "group", "aria-label": "Filter by chain", children: [
2061
- /* @__PURE__ */ jsx(ChainChip, { label: "All", selected: activeFilter == null, onClick: () => setChainFilter(null) }),
2062
- chains.map((c) => /* @__PURE__ */ jsx(
2063
- ChainChip,
2064
- {
2065
- chain: c,
2066
- label: chainBadge(Number(c.chainId)),
2067
- name: CHAIN_LABELS[Number(c.chainId)] || c.displayName || c.name || `Chain ${c.chainId}`,
2068
- selected: activeFilter === Number(c.chainId),
2069
- onClick: () => setChainFilter(Number(c.chainId))
2070
- },
2071
- c.chainId
2072
- ))
2073
- ] }),
2074
- /* @__PURE__ */ jsxs("div", { className: "sg-search", children: [
2075
- /* @__PURE__ */ jsx(SearchGlyph, {}),
2076
- /* @__PURE__ */ 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" })
2077
- ] }),
2078
- /* @__PURE__ */ jsx("div", { className: "sg-toklist", role: "group", "aria-label": props.title, children: rows.length ? rows.map((t) => {
2079
- const chainId = Number(t.chainId);
2080
- const key = rowKey(t);
2081
- const bal = props.balances?.[key];
2354
+ ask(2);
2355
+ return () => {
2356
+ alive = false;
2357
+ if (timer2) clearTimeout(timer2);
2358
+ };
2359
+ }, [showBalances, fetchPrices, symbolKey2]);
2360
+ const groups = useMemo(() => {
2361
+ const deployments = [];
2362
+ for (const token of props.tokens) {
2363
+ const key = rowKey(token);
2364
+ const n = Number(props.balances?.[key]?.formatted);
2082
2365
  const st = props.optionStates?.[key];
2083
- const disabled = !!st?.disabled;
2084
- return /* @__PURE__ */ jsxs(
2085
- "button",
2086
- {
2087
- type: "button",
2088
- className: `sg-tokrow${disabled ? " sg-tokrow--off" : ""}`,
2089
- disabled,
2090
- "aria-disabled": disabled || void 0,
2091
- "data-disabled": disabled || void 0,
2092
- onClick: disabled ? void 0 : () => props.onPick({ chainId, symbol: t.symbol }),
2093
- children: [
2094
- /* @__PURE__ */ jsx(TokenGlyph, { symbol: t.symbol, logoUrl: t.logoUrl, chainId }),
2095
- /* @__PURE__ */ jsxs("span", { className: "sg-tokrow-main", children: [
2096
- /* @__PURE__ */ jsx("span", { className: "sg-tokrow-sym", children: tokenTicker(t) }),
2097
- /* @__PURE__ */ jsx("span", { className: "sg-tokrow-name", children: t.name || t.symbol })
2366
+ if (st?.disabled && !WALLET_STATE_REASONS.has(String(st.reason))) continue;
2367
+ deployments.push({
2368
+ token,
2369
+ key,
2370
+ balance: showBalances && props.balances?.[key] && Number.isFinite(n) ? n : null,
2371
+ disabled: !!st?.disabled,
2372
+ // The line under a greyed row says why. Callers send either a sentence in `reason` (the
2373
+ // exchange's "cannot be delivered on this chain") or a machine code there with the words in
2374
+ // `hint` (the deposit card's "no-balance" / "No balance on this chain").
2375
+ reason: st?.disabled ? st.reason && /\s/.test(st.reason) ? st.reason : st.hint || st.reason : void 0,
2376
+ hint: st?.disabled ? void 0 : st?.hint
2377
+ });
2378
+ }
2379
+ return groupDeployments(deployments, prices);
2380
+ }, [props.tokens, props.balances, props.optionStates, showBalances, prices]);
2381
+ const chainTerms = useMemo(() => buildChainSearchTerms(props.chains), [props.chains]);
2382
+ const visible = useMemo(() => searchGroups(groups, query, chainTerms, prices), [groups, query, chainTerms, prices]);
2383
+ const openGroup = openKey ? visible.find((g) => g.key === openKey) ?? null : null;
2384
+ useEffect(() => {
2385
+ if (openKey && !openGroup) setOpenKey(null);
2386
+ }, [openKey, openGroup]);
2387
+ useLayoutEffect(() => {
2388
+ if (!openKey && listRef.current) listRef.current.scrollTop = savedScroll.current;
2389
+ }, [openKey]);
2390
+ const selected = props.selected;
2391
+ const isSelected = (t) => isPick(selected, t);
2392
+ const pick = (t) => props.onPick({ chainId: Number(t.chainId), symbol: t.symbol });
2393
+ const selectedRow = useMemo(() => {
2394
+ if (!selected) return null;
2395
+ for (const g of groups) for (const d of g.deployments) if (!d.disabled && isPick(selected, d.token)) return d;
2396
+ return null;
2397
+ }, [groups, selected]);
2398
+ const head = /* @__PURE__ */ jsxs("div", { className: "sg-pk-head", children: [
2399
+ openGroup ? /* @__PURE__ */ jsxs("button", { type: "button", className: "sg-pk-backlink", onClick: () => setOpenKey(null), children: [
2400
+ /* @__PURE__ */ jsx(ArrowLeftGlyph, {}),
2401
+ "Tokens"
2402
+ ] }) : /* @__PURE__ */ jsx("div", { className: "sg-pk-title", children: props.title }),
2403
+ /* @__PURE__ */ jsx("button", { type: "button", className: "sg-pk-close", onClick: props.onBack, "aria-label": "Close", children: /* @__PURE__ */ jsx(CloseGlyph, {}) })
2404
+ ] });
2405
+ if (openGroup) {
2406
+ const sym = openGroup.symbol;
2407
+ return /* @__PURE__ */ jsxs("div", { className: "sg-pk", "data-step": "network", children: [
2408
+ head,
2409
+ /* @__PURE__ */ jsxs("div", { className: "sg-pk-intro", children: [
2410
+ /* @__PURE__ */ jsxs("div", { className: "sg-pk-title", children: [
2411
+ side === "from" ? "Pay with" : "Receive",
2412
+ " ",
2413
+ sym
2414
+ ] }),
2415
+ /* @__PURE__ */ jsx("p", { className: "sg-pk-lead", children: side === "from" ? "Choose the network to pay from" : `Choose the network to receive ${sym} on` })
2416
+ ] }),
2417
+ /* @__PURE__ */ jsx("div", { className: "sg-pk-list", role: "group", "aria-label": "Select network", children: openGroup.deployments.map((d) => {
2418
+ const id = Number(d.token.chainId);
2419
+ const name = chainName3(id);
2420
+ if (d.disabled) {
2421
+ return /* @__PURE__ */ jsx(UnavailableRow, { icon: /* @__PURE__ */ jsx(ChainMark, { chainId: id, chain: chainById.get(id), size: "row" }), label: name, reason: d.reason, testId: "network-row-unavailable" }, d.key);
2422
+ }
2423
+ const sel = isSelected(d.token);
2424
+ const ticker = tokenTicker(d.token);
2425
+ return /* @__PURE__ */ 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: [
2426
+ /* @__PURE__ */ jsxs("span", { className: "sg-pk-left", children: [
2427
+ /* @__PURE__ */ jsxs("span", { className: "sg-pk-chainwrap", children: [
2428
+ /* @__PURE__ */ jsx(ChainMark, { chainId: id, chain: chainById.get(id), size: "row" }),
2429
+ sel ? /* @__PURE__ */ jsx(TickBadge, {}) : null
2098
2430
  ] }),
2099
- /* @__PURE__ */ jsxs("span", { className: "sg-tokrow-end", children: [
2100
- bal ? /* @__PURE__ */ jsx("span", { className: "sg-tokrow-bal sg-mono", children: bal.formatted }) : null,
2101
- st?.hint ? /* @__PURE__ */ jsx("span", { className: "sg-tokrow-hint", "data-tone": disabled ? void 0 : "note", children: st.hint }) : null,
2102
- /* @__PURE__ */ jsx("span", { className: "sg-tokrow-chain", children: CHAIN_LABELS[chainId] || `Chain ${chainId}` })
2431
+ /* @__PURE__ */ jsxs("span", { className: "sg-pk-text", children: [
2432
+ /* @__PURE__ */ jsxs("span", { className: "sg-pk-label", children: [
2433
+ name,
2434
+ ticker !== sym ? /* @__PURE__ */ jsx("span", { className: "sg-pk-alt", children: ticker }) : null
2435
+ ] }),
2436
+ d.hint ? /* @__PURE__ */ jsx("span", { className: "sg-pk-note", "data-testid": "lane-limit", children: d.hint }) : null
2103
2437
  ] })
2104
- ]
2105
- },
2106
- `${chainId}:${t.address}`
2107
- );
2108
- }) : props.loading ? /* @__PURE__ */ jsx("div", { className: "sg-sel-empty", children: "Loading the token list\u2026" }) : /* @__PURE__ */ jsx("div", { className: "sg-sel-empty", children: "No tokens match \u2014 try another chain or search." }) })
2438
+ ] }),
2439
+ showBalances ? /* @__PURE__ */ jsx(BalanceColumn, { amount: d.balance, usd: usdOf(d.balance, prices, d.token.symbol), symbol: ticker }) : null
2440
+ ] }, d.key);
2441
+ }) })
2442
+ ] });
2443
+ }
2444
+ return /* @__PURE__ */ jsxs("div", { className: "sg-pk", "data-step": "token", children: [
2445
+ head,
2446
+ /* @__PURE__ */ jsxs("label", { className: "sg-pk-search", children: [
2447
+ /* @__PURE__ */ jsx(SearchGlyph, {}),
2448
+ /* @__PURE__ */ jsx("input", { autoFocus: true, placeholder: "Search by token or address", value: query, onChange: (e) => setQuery(e.target.value), spellCheck: false, "aria-label": "Search by token or address" }),
2449
+ query ? /* @__PURE__ */ jsx("button", { type: "button", className: "sg-pk-clear", onClick: () => setQuery(""), "aria-label": "Clear token search", children: /* @__PURE__ */ jsx(CloseGlyph, {}) }) : null
2450
+ ] }),
2451
+ /* @__PURE__ */ jsxs("div", { className: "sg-pk-body", children: [
2452
+ selectedRow ? /* @__PURE__ */ jsxs("div", { className: "sg-pk-selected", children: [
2453
+ /* @__PURE__ */ jsx("p", { className: "sg-pk-cap", children: "Selected" }),
2454
+ /* @__PURE__ */ jsxs("button", { type: "button", className: "sg-pk-row", "data-testid": "selected-row", "data-selected": "true", "aria-pressed": "true", onClick: () => pick(selectedRow.token), children: [
2455
+ /* @__PURE__ */ jsxs("span", { className: "sg-pk-left", children: [
2456
+ /* @__PURE__ */ jsx(TokenPlate, { symbol: selectedRow.token.symbol, logoUrl: selectedRow.token.logoUrl, checked: true }),
2457
+ /* @__PURE__ */ jsxs("span", { className: "sg-pk-text", children: [
2458
+ /* @__PURE__ */ jsx("span", { className: "sg-pk-label", children: tokenTicker(selectedRow.token) }),
2459
+ /* @__PURE__ */ jsxs("span", { className: "sg-pk-line", children: [
2460
+ /* @__PURE__ */ jsxs("span", { className: "sg-pk-sub", children: [
2461
+ "On ",
2462
+ chainName3(Number(selectedRow.token.chainId))
2463
+ ] }),
2464
+ /* @__PURE__ */ jsx(ChainMarks, { chainIds: [Number(selectedRow.token.chainId)], chainById, decorative: true })
2465
+ ] })
2466
+ ] })
2467
+ ] }),
2468
+ showBalances ? /* @__PURE__ */ jsx(
2469
+ BalanceColumn,
2470
+ {
2471
+ amount: selectedRow.balance,
2472
+ usd: usdOf(selectedRow.balance, prices, selectedRow.token.symbol),
2473
+ symbol: tokenTicker(selectedRow.token)
2474
+ }
2475
+ ) : null
2476
+ ] })
2477
+ ] }) : null,
2478
+ /* @__PURE__ */ jsx("p", { className: "sg-pk-cap", children: side === "from" ? "Your tokens \xB7 All networks" : "Popular tokens \xB7 All networks" }),
2479
+ /* @__PURE__ */ jsx("div", { className: "sg-pk-list", ref: listRef, role: "group", "aria-label": props.title, children: visible.length === 0 ? /* @__PURE__ */ jsx("p", { className: "sg-pk-empty", children: props.loading ? "Loading the token list\u2026" : "No tokens found." }) : visible.map((g) => {
2480
+ const members = g.deployments;
2481
+ const multi = members.length > 1;
2482
+ const single = members[0];
2483
+ const label = multi ? g.symbol : tokenTicker(single.token);
2484
+ const blocked = !!g.unavailable;
2485
+ const opensNetworks = multi || blocked;
2486
+ const zero = showBalances && g.amount === 0 || blocked;
2487
+ return /* @__PURE__ */ jsxs(
2488
+ "button",
2489
+ {
2490
+ type: "button",
2491
+ className: "sg-pk-row",
2492
+ "data-testid": "token-row",
2493
+ "data-symbol": g.symbol,
2494
+ "data-networks": members.length,
2495
+ "data-zero": zero || void 0,
2496
+ "data-unavailable": blocked || void 0,
2497
+ onClick: () => {
2498
+ if (opensNetworks) {
2499
+ savedScroll.current = listRef.current?.scrollTop ?? 0;
2500
+ setOpenKey(g.key);
2501
+ } else pick(single.token);
2502
+ },
2503
+ children: [
2504
+ /* @__PURE__ */ jsxs("span", { className: "sg-pk-left", children: [
2505
+ /* @__PURE__ */ jsx(TokenPlate, { symbol: g.symbol, logoUrl: g.logoUrl }),
2506
+ /* @__PURE__ */ jsxs("span", { className: "sg-pk-text", children: [
2507
+ /* @__PURE__ */ jsx("span", { className: "sg-pk-label", children: label }),
2508
+ /* @__PURE__ */ jsxs("span", { className: "sg-pk-line", children: [
2509
+ /* @__PURE__ */ jsx("span", { className: "sg-pk-sub", children: multi ? showBalances ? "Total across" : "Available on" : `On ${chainName3(Number(single.token.chainId))}` }),
2510
+ /* @__PURE__ */ jsx(ChainMarks, { chainIds: members.map((m) => Number(m.token.chainId)), chainById, decorative: !multi }),
2511
+ opensNetworks && showBalances ? /* @__PURE__ */ jsx("span", { className: "sg-pk-chev sg-pk-chev--sm", "aria-hidden": "true", children: /* @__PURE__ */ jsx(ChevronGlyph, {}) }) : null
2512
+ ] }),
2513
+ !multi && single.hint ? /* @__PURE__ */ jsx("span", { className: "sg-pk-note", "data-testid": "lane-limit", children: single.hint }) : null
2514
+ ] })
2515
+ ] }),
2516
+ showBalances ? /* @__PURE__ */ jsx(BalanceColumn, { amount: g.amount, usd: g.usd, symbol: label }) : opensNetworks ? /* @__PURE__ */ jsx("span", { className: "sg-pk-chev", "aria-hidden": "true", children: /* @__PURE__ */ jsx(ChevronGlyph, {}) }) : null
2517
+ ]
2518
+ },
2519
+ g.key
2520
+ );
2521
+ }) })
2522
+ ] })
2109
2523
  ] });
2110
2524
  }
2111
2525
  function ChevronRight({ size = 16 }) {
@@ -2123,7 +2537,7 @@ function ArrowDown({ size = 16 }) {
2123
2537
  /* @__PURE__ */ jsx("path", { d: "M12.667 8L8 12.667 3.333 8", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })
2124
2538
  ] });
2125
2539
  }
2126
- function CloseGlyph() {
2540
+ function CloseGlyph2() {
2127
2541
  return /* @__PURE__ */ jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M18 6L6 18M6 6l12 12", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) });
2128
2542
  }
2129
2543
  function ShieldTickGlyph({ size = 16 }) {
@@ -2163,7 +2577,7 @@ function AmountText({ value, suffix, exact }) {
2163
2577
  suffix ? ` ${suffix}` : null
2164
2578
  ] });
2165
2579
  }
2166
- function usdOf(amount, price) {
2580
+ function usdOf2(amount, price) {
2167
2581
  const n = typeof amount === "number" ? amount : Number(amount);
2168
2582
  if (!Number.isFinite(n) || n <= 0 || price === void 0 || !Number.isFinite(price) || price <= 0) return null;
2169
2583
  const usd = n * price;
@@ -2293,7 +2707,7 @@ function WidgetShell(props) {
2293
2707
  ] }),
2294
2708
  props.onClose ? (
2295
2709
  // type="button": a host page may wrap the widget in a <form>.
2296
- /* @__PURE__ */ jsx("button", { type: "button", className: "sg-close", onClick: props.onClose, "aria-label": "Close", children: /* @__PURE__ */ jsx(CloseGlyph, {}) })
2710
+ /* @__PURE__ */ jsx("button", { type: "button", className: "sg-close", onClick: props.onClose, "aria-label": "Close", children: /* @__PURE__ */ jsx(CloseGlyph2, {}) })
2297
2711
  ) : null
2298
2712
  ] })
2299
2713
  ] }),
@@ -2589,7 +3003,7 @@ function useTxHistory(account) {
2589
3003
  }, [account]);
2590
3004
  return entries;
2591
3005
  }
2592
- function BackGlyph2() {
3006
+ function BackGlyph() {
2593
3007
  return /* @__PURE__ */ jsxs("svg", { width: "17", height: "17", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
2594
3008
  /* @__PURE__ */ jsx("path", { d: "M19 12H5" }),
2595
3009
  /* @__PURE__ */ jsx("path", { d: "m12 19-7-7 7-7" })
@@ -2831,7 +3245,7 @@ function TxHistoryPanel(props) {
2831
3245
  };
2832
3246
  return /* @__PURE__ */ jsxs("div", { children: [
2833
3247
  /* @__PURE__ */ jsxs("div", { className: "sg-sel-head", children: [
2834
- /* @__PURE__ */ jsx("button", { type: "button", autoFocus: true, ref: backRef, className: "sg-back", onClick: selected ? () => setSelected(null) : props.onBack, "aria-label": "Back", children: /* @__PURE__ */ jsx(BackGlyph2, {}) }),
3248
+ /* @__PURE__ */ jsx("button", { type: "button", autoFocus: true, ref: backRef, className: "sg-back", onClick: selected ? () => setSelected(null) : props.onBack, "aria-label": "Back", children: /* @__PURE__ */ jsx(BackGlyph, {}) }),
2835
3249
  /* @__PURE__ */ jsxs("div", { className: "sg-sel-title", children: [
2836
3250
  selected ? "Transaction" : "Transaction history",
2837
3251
  account ? /* @__PURE__ */ jsx("span", { className: "sg-sel-sub sg-mono", children: shortAddress(account) }) : null
@@ -3587,6 +4001,9 @@ function PaymentIsland(props) {
3587
4001
  TokenSelect,
3588
4002
  {
3589
4003
  title: "Pay with",
4004
+ side: "from",
4005
+ selected: sel ? { chainId: sel.source.chainId, symbol: sel.source.asset } : null,
4006
+ fetchPrices: engine.fetchPrices,
3590
4007
  chains: fundingChains,
3591
4008
  tokens: fundingTokens,
3592
4009
  balances: holdings.balances,
@@ -3602,6 +4019,9 @@ function PaymentIsland(props) {
3602
4019
  TokenSelect,
3603
4020
  {
3604
4021
  title: isFrom ? "Exchange from" : "Exchange to",
4022
+ side: isFrom ? "from" : "to",
4023
+ selected: isFrom ? exFrom : exTo,
4024
+ fetchPrices: engine.fetchPrices,
3605
4025
  chains,
3606
4026
  tokens: isFrom ? exFromPicker : exToPicker,
3607
4027
  balances: exBalances,
@@ -3951,6 +4371,21 @@ function PayCard(props) {
3951
4371
  );
3952
4372
  const heldIds = useMemo(() => new Set(held.map((a) => a.route.id)), [held]);
3953
4373
  const scannedEmpty = !holdings.loading && Object.keys(holdings.balances).length > 0 && held.length === 0;
4374
+ const [failedOptions, setFailedOptions] = useState(/* @__PURE__ */ new Set());
4375
+ const [pricing, setPricing] = useState(null);
4376
+ const [pickError, setPickError] = useState(null);
4377
+ useEffect(() => {
4378
+ setFailedOptions(/* @__PURE__ */ new Set());
4379
+ setPricing(null);
4380
+ setPickError(null);
4381
+ }, [wallet.account, paramsKey]);
4382
+ const unquoted = useMemo(
4383
+ () => (paymentPlan?.unquotedOptions ?? []).filter(
4384
+ (o) => (!fundingSet || fundingSet.has(o.symbolKey)) && (STABLES2.has(o.symbolKey)) && !failedOptions.has(balanceKey(o.chainId, o.address))
4385
+ ),
4386
+ [paymentPlan, fundingSet, method, failedOptions]
4387
+ );
4388
+ const listBalances = useMemo(() => ({ ...prefetchedBalances ?? {}, ...holdings.balances }), [prefetchedBalances, holdings.balances]);
3954
4389
  const optionStates = useMemo(() => {
3955
4390
  const map = {};
3956
4391
  for (const a of annotated) {
@@ -3973,8 +4408,19 @@ function PayCard(props) {
3973
4408
  map[key] = { disabled: false };
3974
4409
  }
3975
4410
  }
4411
+ for (const o of unquoted) {
4412
+ const key = balanceKey(o.chainId, o.address);
4413
+ if (map[key]) continue;
4414
+ let zero = false;
4415
+ try {
4416
+ zero = BigInt(listBalances[key]?.raw ?? "x") === 0n;
4417
+ } catch {
4418
+ zero = false;
4419
+ }
4420
+ map[key] = zero ? { disabled: true, reason: "no-balance", hint: "No balance on this chain" } : { disabled: false };
4421
+ }
3976
4422
  return map;
3977
- }, [annotated, holdings.loading]);
4423
+ }, [annotated, holdings.loading, unquoted, listBalances]);
3978
4424
  const [catalogue, setCatalogue] = useState(null);
3979
4425
  const chains = useMemo(() => {
3980
4426
  const order = new Map(SUPPORTED_CHAINS.map((id, i) => [id, i]));
@@ -3994,24 +4440,27 @@ function PayCard(props) {
3994
4440
  const fundingTokens = useMemo(() => {
3995
4441
  const seen = /* @__PURE__ */ new Set();
3996
4442
  const list = [];
3997
- for (const r of visibleRoutes) {
3998
- const key = balanceKey(r.source.chainId, r.source.tokenAddress);
3999
- if (seen.has(key)) continue;
4443
+ const push = (chainId, address, fallback) => {
4444
+ const key = balanceKey(chainId, address);
4445
+ if (seen.has(key)) return;
4000
4446
  seen.add(key);
4001
- const reg = registryTokens.find((t) => Number(t.chainId) === r.source.chainId && addrEq2(t.address, r.source.tokenAddress));
4002
- list.push(
4003
- reg ?? {
4004
- symbol: r.source.asset,
4005
- displaySymbol: r.source.ticker,
4006
- name: r.source.asset,
4007
- chainId: r.source.chainId,
4008
- address: r.source.tokenAddress ?? "",
4009
- decimals: r.source.decimals ?? 18
4010
- }
4011
- );
4447
+ list.push(registryTokens.find((t) => Number(t.chainId) === chainId && addrEq2(t.address, address)) ?? fallback);
4448
+ };
4449
+ for (const r of visibleRoutes) {
4450
+ push(r.source.chainId, r.source.tokenAddress, {
4451
+ symbol: r.source.asset,
4452
+ displaySymbol: r.source.ticker,
4453
+ name: r.source.asset,
4454
+ chainId: r.source.chainId,
4455
+ address: r.source.tokenAddress ?? "",
4456
+ decimals: r.source.decimals ?? 18
4457
+ });
4458
+ }
4459
+ for (const o of unquoted) {
4460
+ 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 });
4012
4461
  }
4013
4462
  return list;
4014
- }, [visibleRoutes, registryTokens]);
4463
+ }, [visibleRoutes, unquoted, registryTokens]);
4015
4464
  const fundingChains = useMemo(() => {
4016
4465
  const ids = new Set(fundingTokens.map((t) => Number(t.chainId)));
4017
4466
  return chains.filter((c) => ids.has(Number(c.chainId)));
@@ -4055,9 +4504,23 @@ function PayCard(props) {
4055
4504
  useEffect(() => setHist(null), [wallet.account]);
4056
4505
  const lastTxOwned = Boolean(flow.lastTxEntry?.hash && wallet.account && flow.lastTxEntry.account === wallet.account.toLowerCase());
4057
4506
  const pickFunding = (pick) => {
4507
+ setPickError(null);
4058
4508
  const r = visibleRoutes.find((x) => x.source.chainId === pick.chainId && symbolKey(x.source.asset) === symbolKey(pick.symbol));
4059
- if (r) selectRoute(r.id);
4509
+ if (r) {
4510
+ selectRoute(r.id);
4511
+ closeSelector();
4512
+ return;
4513
+ }
4514
+ const option = unquoted.find((o) => o.chainId === pick.chainId && o.symbolKey === symbolKey(pick.symbol));
4060
4515
  closeSelector();
4516
+ if (!option || !wallet.account) return;
4517
+ const key = balanceKey(option.chainId, option.address);
4518
+ setPricing(key);
4519
+ userPicked.current = true;
4520
+ 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(() => {
4521
+ setFailedOptions((prev) => /* @__PURE__ */ new Set([...prev, key]));
4522
+ setPickError(`${option.ticker || option.symbol} on ${option.chainName} cannot settle this payment right now. Pick another way to pay.`);
4523
+ }).finally(() => setPricing((cur) => cur === key ? null : cur));
4061
4524
  };
4062
4525
  const parked = !isLiveMethod(method);
4063
4526
  const submitting = flow.status === "submitting";
@@ -4084,7 +4547,7 @@ function PayCard(props) {
4084
4547
  setSheet(false);
4085
4548
  requestAnimationFrame(() => complianceBtnRef.current?.focus());
4086
4549
  };
4087
- 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";
4550
+ 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";
4088
4551
  const walletSlot = wallet.account ? /* @__PURE__ */ jsxs("div", { className: "sg-head-tools", children: [
4089
4552
  /* @__PURE__ */ jsx(HistoryButton, { btnRef: histBtnRef, disabled: submitting, onClick: () => setHist({}) }),
4090
4553
  /* @__PURE__ */ jsxs("span", { className: "sg-wallet", "data-connected": "true", children: [
@@ -4098,14 +4561,17 @@ function PayCard(props) {
4098
4561
  { label: "Network fee", value: nativeWei > 0n ? `~${formatNative(nativeWei)} ${nativeSymbol(sel.source.chainId)}` : "Gas only" },
4099
4562
  ...durationLabel(sel.quote.estimatedDuration) ? [{ label: "Estimated time", value: durationLabel(sel.quote.estimatedDuration) }] : []
4100
4563
  ] : [];
4101
- const loadingPlan = flow.status === "loading" || holdings.loading && !sel;
4564
+ const loadingPlan = flow.status === "loading" || holdings.loading && !sel || pricing !== null;
4102
4565
  return /* @__PURE__ */ jsx(WidgetShell, { title: config.title || "Complete payment", theme: config.theme, heightPx: props.heightPx, walletSlot, onClose: props.onClose, children: hist && wallet.account ? /* @__PURE__ */ jsx(TxHistoryPanel, { account: wallet.account, tokens: registryTokens, vaultIcons: catalogue?.vaultIcons, initialEntry: hist.entry ?? null, onBack: closeHistory }) : view === "select" && wallet.account ? /* @__PURE__ */ jsx(
4103
4566
  TokenSelect,
4104
4567
  {
4105
4568
  title: "Pay with",
4569
+ side: "from",
4570
+ selected: sel ? { chainId: sel.source.chainId, symbol: sel.source.asset } : null,
4571
+ fetchPrices: engine.fetchPrices,
4106
4572
  chains: fundingChains,
4107
4573
  tokens: fundingTokens,
4108
- balances: holdings.balances,
4574
+ balances: listBalances,
4109
4575
  optionStates,
4110
4576
  onBack: closeSelector,
4111
4577
  onPick: pickFunding
@@ -4136,7 +4602,7 @@ function PayCard(props) {
4136
4602
  /* @__PURE__ */ jsxs("div", { className: "sg-pane", "data-kind": "pay", children: [
4137
4603
  /* @__PURE__ */ jsx("span", { className: "sg-pane-label", children: "You pay" }),
4138
4604
  /* @__PURE__ */ jsxs("div", { className: "sg-pane-mid", children: [
4139
- /* @__PURE__ */ jsx("span", { className: "sg-amt-out", "aria-live": "polite", children: loadingPlan ? /* @__PURE__ */ jsx("span", { className: "sg-amt-empty", children: "\u2026" }) : sel && selectedVisible ? /* @__PURE__ */ jsx(AmountText, { value: groupDecimal(atLeastCents(sel.source.payAmount)) }) : /* @__PURE__ */ jsx("span", { className: "sg-amt-empty", children: "\u2014" }) }),
4605
+ /* @__PURE__ */ jsx("span", { className: "sg-amt-out", "aria-live": "polite", children: loadingPlan ? /* @__PURE__ */ jsx("span", { className: "sg-skel sg-skel--amt", "data-testid": "pay-loading-amount", "aria-hidden": "true" }) : sel && selectedVisible ? /* @__PURE__ */ jsx(AmountText, { value: groupDecimal(atLeastCents(sel.source.payAmount)) }) : /* @__PURE__ */ jsx("span", { className: "sg-amt-empty", children: "\u2014" }) }),
4140
4606
  /* @__PURE__ */ jsx(
4141
4607
  TokenButton,
4142
4608
  {
@@ -4150,12 +4616,22 @@ function PayCard(props) {
4150
4616
  }
4151
4617
  )
4152
4618
  ] }),
4153
- /* @__PURE__ */ jsx(PaneFoot, { usd: sel && selectedVisible ? usdOf(sel.source.payAmount, prices[selSymbol]) : null, balance: selBal ? shortBalance(selBal.formatted) : null })
4619
+ /* @__PURE__ */ jsx(PaneFoot, { usd: sel && selectedVisible ? usdOf2(sel.source.payAmount, prices[selSymbol]) : null, balance: selBal ? shortBalance(selBal.formatted) : null })
4154
4620
  ] }),
4621
+ loadingPlan ? /* @__PURE__ */ jsxs("div", { className: "sg-pay-loading", "data-testid": "pay-loading", role: "status", children: [
4622
+ /* @__PURE__ */ jsx("div", { className: "sg-skel sg-skel--row" }),
4623
+ /* @__PURE__ */ jsx("div", { className: "sg-skel sg-skel--row" }),
4624
+ /* @__PURE__ */ jsxs("div", { className: "sg-muted sg-pay-loading-line", children: [
4625
+ /* @__PURE__ */ jsx("span", { className: "sg-spinner", "aria-hidden": "true" }),
4626
+ " ",
4627
+ pricing ? "Pricing this option\u2026" : "Checking your balances and finding the best way to pay\u2026"
4628
+ ] })
4629
+ ] }) : null,
4630
+ pickError ? /* @__PURE__ */ jsx(StatusPanel, { tone: "error", children: pickError }) : null,
4155
4631
  flow.status === "error" && flow.error ? /* @__PURE__ */ jsx(StatusPanel, { tone: "error", children: flow.error }) : null,
4156
4632
  scannedEmpty ? /* @__PURE__ */ jsx("div", { className: "sg-note", children: "None of your balances can cover this yet \u2014 pick a different asset to fund with." }) : null,
4157
4633
  flow.status === "ready" && !visibleRoutes.length ? /* @__PURE__ */ jsx(StatusPanel, { children: "No funding route matches the accepted assets for this payment." }) : null,
4158
- sel && flow.status !== "loading" ? /* @__PURE__ */ jsx(
4634
+ sel && !loadingPlan ? /* @__PURE__ */ jsx(
4159
4635
  DetailButton,
4160
4636
  {
4161
4637
  btnRef: complianceBtnRef,
@@ -4167,7 +4643,7 @@ function PayCard(props) {
4167
4643
  onClick: () => setSheet(true)
4168
4644
  }
4169
4645
  ) : null,
4170
- sel && selectedVisible && flow.status !== "loading" ? /* @__PURE__ */ jsx(RateBox, { rowsOnly: true, rate: null, fromSymbol: "", toTicker: "", rows: feeRows }) : null
4646
+ sel && selectedVisible && !loadingPlan ? /* @__PURE__ */ jsx(RateBox, { rowsOnly: true, rate: null, fromSymbol: "", toTicker: "", rows: feeRows }) : null
4171
4647
  ] }),
4172
4648
  submitting ? /* @__PURE__ */ jsx(StepList, { steps: flow.steps }) : null,
4173
4649
  /* @__PURE__ */ jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsx(
@@ -4175,7 +4651,7 @@ function PayCard(props) {
4175
4651
  {
4176
4652
  onClick: parked || !selectedVisible ? void 0 : flow.submit,
4177
4653
  busy: submitting,
4178
- disabled: parked || !selectedVisible || flow.insufficient || !!flow.nativeShortfall || flow.status === "loading",
4654
+ disabled: parked || !selectedVisible || flow.insufficient || !!flow.nativeShortfall || loadingPlan,
4179
4655
  children: payLabel
4180
4656
  }
4181
4657
  ) })
@@ -4513,6 +4989,10 @@ function ExchangeCard(props) {
4513
4989
  }
4514
4990
  return states;
4515
4991
  }, [catalogue, fromToken]);
4992
+ const toPickerVisible = useMemo(
4993
+ () => destinationStates ? toPickerTokens.filter((t) => !destinationStates[`${Number(t.chainId)}:${String(t.address || "").toLowerCase()}`]?.disabled) : toPickerTokens,
4994
+ [toPickerTokens, destinationStates]
4995
+ );
4516
4996
  const normalizedAmount = normalizeDecimalText(amount);
4517
4997
  const amountValid = /^\d+(\.\d+)?$/.test(normalizedAmount) && Number(normalizedAmount) > 0 && Number(normalizedAmount) <= 1e9;
4518
4998
  const rampMode = mode !== "exchange";
@@ -4648,8 +5128,8 @@ function ExchangeCard(props) {
4648
5128
  const routeShape = via === null ? "Direct" : via ? `Via ${via}` : "Two steps";
4649
5129
  const compliance = selected?.quote.compliance;
4650
5130
  const complianceHasQuote = Boolean(selected && flow.status !== "loading");
4651
- const fromUsd = usdOf(normalizedAmount, prices[from?.symbol ?? ""]);
4652
- const toUsd = usdOf(receive, prices[to?.symbol ?? ""]);
5131
+ const fromUsd = usdOf2(normalizedAmount, prices[from?.symbol ?? ""]);
5132
+ const toUsd = usdOf2(receive, prices[to?.symbol ?? ""]);
4653
5133
  const flippable = !rampMode && !submitting && Boolean(to && sourceTokens.some((t) => Number(t.chainId) === to.chainId && symbolKey(t.symbol) === to.symbol));
4654
5134
  const flip = () => {
4655
5135
  if (!flippable) return;
@@ -4732,8 +5212,11 @@ function ExchangeCard(props) {
4732
5212
  TokenSelect,
4733
5213
  {
4734
5214
  title: isFrom ? "Exchange from" : "Exchange to",
5215
+ side: isFrom ? "from" : "to",
5216
+ selected: isFrom ? from : to,
5217
+ fetchPrices: engine.fetchPrices,
4735
5218
  chains,
4736
- tokens: isFrom ? fromPickerTokens : toPickerTokens,
5219
+ tokens: isFrom ? fromPickerTokens : toPickerVisible,
4737
5220
  balances,
4738
5221
  optionStates: isFrom ? void 0 : destinationStates,
4739
5222
  loading: !catalogue?.ready,