@glacislabs/stablegenie-zerodelta 4.7.0 → 4.9.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
@@ -895,6 +895,20 @@ function withVaultArtwork(tokens, icons) {
895
895
  }
896
896
 
897
897
  // src/core/compliance.ts
898
+ function formatJurisdiction(jurisdiction, country) {
899
+ const region = jurisdiction?.trim() ?? "";
900
+ const explicitCountry = country?.trim() ?? "";
901
+ const countryCode = (explicitCountry || (/^[a-z]{2}$/i.test(region) && region.toUpperCase() !== "EU" ? region : "")).toUpperCase();
902
+ if (!countryCode) return region;
903
+ let countryLabel = countryCode;
904
+ try {
905
+ countryLabel = new Intl.DisplayNames(["en"], { type: "region" }).of(countryCode) ?? countryCode;
906
+ } catch {
907
+ }
908
+ const namedCountry = countryLabel === countryCode ? countryCode : `${countryLabel} (${countryCode})`;
909
+ if (!region || region.toUpperCase() === countryCode) return namedCountry;
910
+ return `${region} \xB7 ${namedCountry}`;
911
+ }
898
912
  var COMPLIANCE_DENY_LABEL = "Compliance check failed";
899
913
  function complianceView(compliance, hasQuote = true) {
900
914
  if (!hasQuote) {
@@ -1699,7 +1713,7 @@ var CHANNEL_HEADER = "x-zd-channel";
1699
1713
  var CHANNEL_VERSION_HEADER = "x-zd-channel-version";
1700
1714
  var CHANNEL_ORIGIN_HEADER = "x-zd-channel-origin";
1701
1715
  var WIDGET_CHANNEL = "widget";
1702
- var WIDGET_VERSION = "4.7.0" ;
1716
+ var WIDGET_VERSION = "4.9.0" ;
1703
1717
  var MAX_CHANNEL_VERSION_LEN = 32;
1704
1718
  function sanitizeVersion(raw) {
1705
1719
  const v = String(raw).trim();
@@ -3294,6 +3308,83 @@ function useHoldings(engine, account, routes, initialBalances) {
3294
3308
  return { balances, loading };
3295
3309
  }
3296
3310
 
3311
+ // src/react/ui/amount.ts
3312
+ var MAX_FRACTION_DIGITS = 8;
3313
+ function trimFraction(fixed) {
3314
+ return fixed.includes(".") ? fixed.replace(/\.?0+$/, "") : fixed;
3315
+ }
3316
+ function groupDecimal(value) {
3317
+ const match = value.match(/^([+-]?)(\d+)(\.\d+)?$/);
3318
+ if (!match) return value;
3319
+ const integer = match[2].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
3320
+ return `${match[1]}${integer}${match[3] ?? ""}`;
3321
+ }
3322
+ var SIGNIFICANT_DIGITS = 7;
3323
+ var MIN_FRACTION_DIGITS = 4;
3324
+ function formatCalculatedAmount(value, decimals) {
3325
+ let raw = typeof value === "number" ? String(value) : value.trim();
3326
+ if (typeof value === "number") {
3327
+ if (!Number.isFinite(value)) return raw;
3328
+ if (/e/i.test(raw)) {
3329
+ raw = value.toLocaleString("en-US", {
3330
+ useGrouping: false,
3331
+ maximumFractionDigits: 20
3332
+ });
3333
+ }
3334
+ }
3335
+ const match = raw.match(/^([+-]?)(\d*)(?:\.(\d*))?$/);
3336
+ if (!match) return raw;
3337
+ const negative = match[1] === "-";
3338
+ const integer = (match[2] || "0").replace(/^0+(?=\d)/, "");
3339
+ const fraction = match[3] ?? "";
3340
+ const firstNonZero = fraction.search(/[1-9]/);
3341
+ const isZero = integer === "0" && firstNonZero === -1;
3342
+ if (isZero) return "0";
3343
+ if (integer === "0" && firstNonZero >= 6) return `${negative ? "-" : ""}<0.000001`;
3344
+ const cap = decimals === void 0 || !Number.isFinite(decimals) ? MAX_FRACTION_DIGITS : Math.min(MAX_FRACTION_DIGITS, Math.max(0, Math.trunc(decimals)));
3345
+ const places = integer !== "0" ? Math.min(cap, Math.max(MIN_FRACTION_DIGITS, SIGNIFICANT_DIGITS - integer.length)) : (
3346
+ // Below one the leading zeros are not significant, so the count starts
3347
+ // at the first digit that is.
3348
+ Math.min(cap, firstNonZero + SIGNIFICANT_DIGITS)
3349
+ );
3350
+ const scale = 10n ** BigInt(places);
3351
+ const padded = fraction.padEnd(places + 1, "0");
3352
+ const kept = padded.slice(0, places);
3353
+ let rounded = BigInt(integer) * scale + BigInt(kept || "0");
3354
+ if ((padded[places] ?? "0") >= "5") rounded += 1n;
3355
+ const whole = rounded / scale;
3356
+ const remainder = rounded % scale;
3357
+ const fixed = places === 0 ? whole.toString() : `${whole}.${remainder.toString().padStart(places, "0")}`;
3358
+ const out = groupDecimal(trimFraction(fixed));
3359
+ return negative && out !== "0" ? `-${out}` : out;
3360
+ }
3361
+ function exactAmountTitle(raw, shown) {
3362
+ const full = typeof raw === "number" ? String(raw) : raw.trim();
3363
+ if (!full || /e/i.test(full)) return void 0;
3364
+ const normalized = full.includes(".") ? trimFraction(full) : full;
3365
+ const grouped = groupDecimal(normalized);
3366
+ return grouped === shown ? void 0 : grouped;
3367
+ }
3368
+ function sanitizeAmount(raw) {
3369
+ const cleaned = raw.replace(/[^0-9.]/g, "");
3370
+ const first = cleaned.indexOf(".");
3371
+ if (first === -1) return cleaned;
3372
+ return cleaned.slice(0, first + 1) + cleaned.slice(first + 1).replace(/\./g, "");
3373
+ }
3374
+ function groupAmountInput(value) {
3375
+ const point = value.indexOf(".");
3376
+ const whole = point === -1 ? value : value.slice(0, point);
3377
+ return whole.replace(/\B(?=(\d{3})+(?!\d))/g, ",") + (point === -1 ? "" : value.slice(point));
3378
+ }
3379
+ function groupedAmountCaret(grouped, kept) {
3380
+ if (kept <= 0) return 0;
3381
+ let seen = 0;
3382
+ for (let i = 0; i < grouped.length; i++) {
3383
+ if (grouped[i] !== "," && ++seen === kept) return i + 1;
3384
+ }
3385
+ return grouped.length;
3386
+ }
3387
+
3297
3388
  // src/react/styles.ts
3298
3389
  var WIDGET_CSS = `
3299
3390
  /* The card as the ZeroDelta widget design draws it (Figma "Widget Playground", 2026-09-30): no
@@ -4115,6 +4206,53 @@ function BrandMark({ size = 18, mono = false, className, style, title }) {
4115
4206
  }
4116
4207
  );
4117
4208
  }
4209
+ var MIN_FONT_PX = 10;
4210
+ function useFitText(ref, text) {
4211
+ react.useLayoutEffect(() => {
4212
+ const el = ref.current;
4213
+ if (!el) return;
4214
+ const fit = () => {
4215
+ el.style.fontSize = "";
4216
+ const room = el.clientWidth;
4217
+ const needed = el.scrollWidth;
4218
+ if (!room || needed <= room) return;
4219
+ const base = Number.parseFloat(getComputedStyle(el).fontSize);
4220
+ if (!Number.isFinite(base) || base <= 0) return;
4221
+ el.style.fontSize = `${Math.max(MIN_FONT_PX, Math.floor(base * room / needed))}px`;
4222
+ };
4223
+ fit();
4224
+ if (typeof ResizeObserver === "undefined") return;
4225
+ const observer = new ResizeObserver(fit);
4226
+ if (el.parentElement) observer.observe(el.parentElement);
4227
+ return () => observer.disconnect();
4228
+ }, [ref, text]);
4229
+ }
4230
+ function useGroupedAmountInput(amount, onAmount) {
4231
+ const caret = react.useRef(null);
4232
+ const [, rerender] = react.useReducer((n) => n + 1, 0);
4233
+ react.useLayoutEffect(() => {
4234
+ const pending = caret.current;
4235
+ caret.current = null;
4236
+ if (pending === null || pending.input !== document.activeElement) return;
4237
+ const at = groupedAmountCaret(pending.input.value, pending.kept);
4238
+ pending.input.setSelectionRange(at, at);
4239
+ });
4240
+ const onChange = (e) => {
4241
+ const input = e.target;
4242
+ const raw = input.value;
4243
+ caret.current = { input, kept: sanitizeAmount(raw.slice(0, input.selectionEnd ?? raw.length)).length };
4244
+ onAmount(sanitizeAmount(raw));
4245
+ rerender();
4246
+ };
4247
+ const onKeyDown = (e) => {
4248
+ const input = e.currentTarget;
4249
+ const at = input.selectionStart;
4250
+ if (at === null || at !== input.selectionEnd) return;
4251
+ if (e.key === "Backspace" && input.value[at - 1] === ",") input.setSelectionRange(at - 1, at - 1);
4252
+ else if (e.key === "Delete" && input.value[at] === ",") input.setSelectionRange(at + 1, at + 1);
4253
+ };
4254
+ return { value: groupAmountInput(amount), onChange, onKeyDown };
4255
+ }
4118
4256
  var SOURCE_CHAIN_LABELS = {
4119
4257
  1: "Ethereum",
4120
4258
  10: "Optimism",
@@ -4168,17 +4306,22 @@ function Select(props) {
4168
4306
  ] }) });
4169
4307
  }
4170
4308
  function AmountInput(props) {
4309
+ const grouped = useGroupedAmountInput(props.value, props.onChange);
4310
+ const field = react.useRef(null);
4311
+ useFitText(field, grouped.value);
4171
4312
  return /* @__PURE__ */ jsxRuntime.jsx(
4172
4313
  "input",
4173
4314
  {
4315
+ ref: field,
4174
4316
  className: "sg-input sg-amount sg-mono",
4175
4317
  inputMode: "decimal",
4176
4318
  placeholder: props.placeholder ?? "0.0",
4177
- value: props.value,
4319
+ value: grouped.value,
4178
4320
  disabled: props.disabled,
4179
4321
  "aria-invalid": props.invalid || void 0,
4180
4322
  "aria-describedby": props.describedBy,
4181
- onChange: (e) => props.onChange(e.target.value.replace(/[^0-9.,]/g, ""))
4323
+ onChange: grouped.onChange,
4324
+ onKeyDown: grouped.onKeyDown
4182
4325
  }
4183
4326
  );
4184
4327
  }
@@ -4604,11 +4747,11 @@ function QuoteGlyph({ size = 16 }) {
4604
4747
  )
4605
4748
  ] });
4606
4749
  }
4607
- function AmountText({ value, suffix }) {
4608
- const dot = value.indexOf(".");
4750
+ function AmountText({ value, suffix, exact }) {
4751
+ const dot = value.startsWith("<") ? -1 : value.indexOf(".");
4609
4752
  const whole = dot < 0 ? value : value.slice(0, dot + 1);
4610
4753
  const decimals = dot < 0 ? "" : value.slice(dot + 1);
4611
- return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-amt", children: [
4754
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-amt", title: exact === void 0 ? void 0 : exactAmountTitle(exact, value), children: [
4612
4755
  whole,
4613
4756
  decimals ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-dec", children: decimals }) : null,
4614
4757
  suffix ? ` ${suffix}` : null
@@ -4863,7 +5006,7 @@ function QuoteChecks({
4863
5006
  const summary = allPassed ? "All checks passed" : cv.label;
4864
5007
  const orphans = unattributedComplianceReasons(compliance, cv);
4865
5008
  const wallets = distinctScreenedWallets(compliance);
4866
- const jurisdiction = compliance?.sourceJurisdiction?.trim();
5009
+ const jurisdiction = formatJurisdiction(compliance?.sourceJurisdiction, compliance?.sourceCountry);
4867
5010
  const hasDetails = Boolean(jurisdiction || wallets.length || compliance?.checkId);
4868
5011
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-cp-tabpanel", role: "tabpanel", "aria-label": "Quote checks", children: [
4869
5012
  /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "sg-cp-card", children: [
@@ -6534,7 +6677,7 @@ function PayCard(props) {
6534
6677
  setSheet(false);
6535
6678
  requestAnimationFrame(() => complianceBtnRef.current?.focus());
6536
6679
  };
6537
- const payLabel = parked ? "Coming soon" : submitting ? "Paying\u2026" : flow.insufficient ? "Insufficient balance" : flow.nativeShortfall ? flow.nativeShortfall : sel && selectedVisible ? `Pay ${atLeastCents(sel.source.payAmount)} ${sel.source.ticker || sel.source.asset}` : "Pay";
6680
+ const payLabel = parked ? "Coming soon" : submitting ? "Paying\u2026" : flow.insufficient ? "Insufficient balance" : flow.nativeShortfall ? flow.nativeShortfall : sel && selectedVisible ? `Pay ${groupDecimal(atLeastCents(sel.source.payAmount))} ${sel.source.ticker || sel.source.asset}` : "Pay";
6538
6681
  const walletSlot = wallet.account ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-head-tools", children: [
6539
6682
  /* @__PURE__ */ jsxRuntime.jsx(HistoryButton, { btnRef: histBtnRef, disabled: submitting, onClick: () => setHist({}) }),
6540
6683
  /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-wallet", "data-connected": "true", children: [
@@ -6586,7 +6729,7 @@ function PayCard(props) {
6586
6729
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-pane", "data-kind": "pay", children: [
6587
6730
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pane-label", children: "You pay" }),
6588
6731
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-pane-mid", children: [
6589
- /* @__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: atLeastCents(sel.source.payAmount) }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "\u2014" }) }),
6732
+ /* @__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" }) }),
6590
6733
  /* @__PURE__ */ jsxRuntime.jsx(
6591
6734
  TokenButton,
6592
6735
  {
@@ -6911,6 +7054,15 @@ function ExchangeCard(props) {
6911
7054
  () => props.defaultToChainId && props.defaultToAsset ? { chainId: props.defaultToChainId, symbol: symbolKey(props.defaultToAsset) } : null
6912
7055
  );
6913
7056
  const [amount, setAmount] = react.useState(props.defaultAmount ?? "");
7057
+ const onInputChange = react.useRef(props.onInputChange);
7058
+ onInputChange.current = props.onInputChange;
7059
+ const fromChainId = from?.chainId ?? null;
7060
+ const fromSymbol = from?.symbol ?? null;
7061
+ const toChainId = to?.chainId ?? null;
7062
+ const toSymbolKey = to?.symbol ?? null;
7063
+ react.useEffect(() => {
7064
+ onInputChange.current?.({ fromChainId, fromAsset: fromSymbol, toChainId, toAsset: toSymbolKey, amount });
7065
+ }, [fromChainId, fromSymbol, toChainId, toSymbolKey, amount]);
6914
7066
  const [fiatCurrency, setFiatCurrency] = react.useState(props.fiatCurrency ?? "EUR");
6915
7067
  const fromToken = react.useMemo(() => from ? findToken(tokens, from.chainId, from.symbol) : null, [tokens, from]);
6916
7068
  const toToken = react.useMemo(() => to ? findToken(tokens, to.chainId, to.symbol) : null, [tokens, to]);
@@ -7048,6 +7200,18 @@ function ExchangeCard(props) {
7048
7200
  const amountError = overLimit && laneLimit ? laneLimitError(laneLimit, limitSymbol) : gatewayAmountError;
7049
7201
  const amountNote = mode === "exchange" ? amountError || (laneLimit ? laneLimitHint(laneLimit, limitSymbol) : null) : null;
7050
7202
  const receive = connected ? flow.selected?.receive.amount : preview.data?.receive;
7203
+ const receiveOutRef = react.useRef(null);
7204
+ const receiveSideRef = react.useRef(null);
7205
+ const receiveShown = `${receive ?? ""}|${quoting}|${toTicker}`;
7206
+ useFitText(receiveOutRef, receiveShown);
7207
+ useFitText(receiveSideRef, receiveShown);
7208
+ const toDecimals = react.useMemo(() => {
7209
+ try {
7210
+ return toToken ? assetDecimals(toToken) : void 0;
7211
+ } catch {
7212
+ return void 0;
7213
+ }
7214
+ }, [toToken]);
7051
7215
  const meta = connected ? flow.selected ? { bridge: flow.selected.quote.bridge || "ZeroDelta", feeBps: Number(flow.selected.quote.feeBps || 0), duration: Number(flow.selected.quote.estimatedDuration || 0) } : null : preview.data ? { bridge: preview.data.bridge || "ZeroDelta", feeBps: preview.data.feeBps, duration: preview.data.estimatedDuration } : null;
7052
7216
  const pct = (p) => {
7053
7217
  if (!fromBal || !fromToken) return;
@@ -7241,7 +7405,7 @@ function ExchangeCard(props) {
7241
7405
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-pane", "data-kind": "receive", children: [
7242
7406
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pane-label", children: product === "rwa" ? "You receive (estimated)" : "You receive" }),
7243
7407
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-pane-mid", children: [
7244
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-out", "aria-live": "polite", children: rampMode ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "\u2014" }) : quoting ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "\u2026" }) : receive && quotable && !quoteError ? /* @__PURE__ */ jsxRuntime.jsx(AmountText, { value: receive }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "0" }) }),
7408
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-out", "aria-live": "polite", ref: receiveOutRef, children: rampMode ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "\u2014" }) : quoting ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "\u2026" }) : receive && quotable && !quoteError ? /* @__PURE__ */ jsxRuntime.jsx(AmountText, { value: formatCalculatedAmount(receive, toDecimals), exact: receive }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "0" }) }),
7245
7409
  receiveToken
7246
7410
  ] }),
7247
7411
  /* @__PURE__ */ jsxRuntime.jsx(PaneFoot, { usd: hasQuote ? toUsd : null })
@@ -7302,7 +7466,7 @@ function ExchangeCard(props) {
7302
7466
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-recv", children: [
7303
7467
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-recv-line", children: [
7304
7468
  /* @__PURE__ */ jsxRuntime.jsx(TokenGlyph, { symbol: to?.symbol ?? "", logoUrl: toToken?.logoUrl, chainId: to?.chainId, size: "xs" }),
7305
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-recv-amt", children: /* @__PURE__ */ jsxRuntime.jsx(AmountText, { value: receive, suffix: toTicker }) })
7469
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-recv-amt", ref: receiveSideRef, children: /* @__PURE__ */ jsxRuntime.jsx(AmountText, { value: formatCalculatedAmount(receive, toDecimals), exact: receive, suffix: toTicker }) })
7306
7470
  ] }),
7307
7471
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-recv-sub", children: [
7308
7472
  "On ",
package/dist/mount.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- export { M as MountConfig, s as mount } from './mount-D4mbJwdc.cjs';
1
+ export { M as MountConfig, t as mount } from './mount-CQ2kUcrx.cjs';
2
2
  import 'react';
3
- import './verify-BEQ8DMvJ.cjs';
3
+ import './verify-CbsVzIkp.cjs';
package/dist/mount.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { M as MountConfig, s as mount } from './mount-D5TIOkMe.js';
1
+ export { M as MountConfig, t as mount } from './mount-BdpykBEW.js';
2
2
  import 'react';
3
- import './verify-BEQ8DMvJ.js';
3
+ import './verify-CbsVzIkp.js';
package/dist/mount.js CHANGED
@@ -1,2 +1,2 @@
1
- export { mount } from './chunk-L7ZEFAZ4.js';
2
- import './chunk-MZCS5TL2.js';
1
+ export { mount } from './chunk-YGBSCSBP.js';
2
+ import './chunk-ZRGTK4B2.js';