@avail-project/widgets 0.0.1

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.
Files changed (143) hide show
  1. package/README.md +34 -0
  2. package/dist/common/components/ErrorBoundary.d.ts +44 -0
  3. package/dist/common/components/ErrorBoundary.d.ts.map +1 -0
  4. package/dist/common/components/ErrorBoundary.js +65 -0
  5. package/dist/common/hooks/useDebouncedCallback.d.ts +13 -0
  6. package/dist/common/hooks/useDebouncedCallback.d.ts.map +1 -0
  7. package/dist/common/hooks/useDebouncedCallback.js +42 -0
  8. package/dist/common/hooks/useDebouncedValue.d.ts +5 -0
  9. package/dist/common/hooks/useDebouncedValue.d.ts.map +1 -0
  10. package/dist/common/hooks/useDebouncedValue.js +15 -0
  11. package/dist/common/hooks/useInterval.d.ts +11 -0
  12. package/dist/common/hooks/useInterval.d.ts.map +1 -0
  13. package/dist/common/hooks/useInterval.js +25 -0
  14. package/dist/common/hooks/useLatest.d.ts +12 -0
  15. package/dist/common/hooks/useLatest.d.ts.map +1 -0
  16. package/dist/common/hooks/useLatest.js +19 -0
  17. package/dist/common/hooks/useNexusError.d.ts +20 -0
  18. package/dist/common/hooks/useNexusError.d.ts.map +1 -0
  19. package/dist/common/hooks/useNexusError.js +120 -0
  20. package/dist/common/hooks/usePolling.d.ts +7 -0
  21. package/dist/common/hooks/usePolling.d.ts.map +1 -0
  22. package/dist/common/hooks/usePolling.js +29 -0
  23. package/dist/common/hooks/useStableCallback.d.ts +6 -0
  24. package/dist/common/hooks/useStableCallback.d.ts.map +1 -0
  25. package/dist/common/hooks/useStableCallback.js +13 -0
  26. package/dist/common/hooks/useStopwatch.d.ts +17 -0
  27. package/dist/common/hooks/useStopwatch.d.ts.map +1 -0
  28. package/dist/common/hooks/useStopwatch.js +44 -0
  29. package/dist/common/hooks/useTransactionExecution.d.ts +62 -0
  30. package/dist/common/hooks/useTransactionExecution.d.ts.map +1 -0
  31. package/dist/common/hooks/useTransactionExecution.js +273 -0
  32. package/dist/common/hooks/useTransactionFlow.d.ts +71 -0
  33. package/dist/common/hooks/useTransactionFlow.d.ts.map +1 -0
  34. package/dist/common/hooks/useTransactionFlow.js +435 -0
  35. package/dist/common/index.d.ts +17 -0
  36. package/dist/common/index.d.ts.map +1 -0
  37. package/dist/common/index.js +16 -0
  38. package/dist/common/tx/steps.d.ts +19 -0
  39. package/dist/common/tx/steps.d.ts.map +1 -0
  40. package/dist/common/tx/steps.js +89 -0
  41. package/dist/common/tx/types.d.ts +11 -0
  42. package/dist/common/tx/types.d.ts.map +1 -0
  43. package/dist/common/tx/types.js +19 -0
  44. package/dist/common/tx/useTransactionSteps.d.ts +21 -0
  45. package/dist/common/tx/useTransactionSteps.d.ts.map +1 -0
  46. package/dist/common/tx/useTransactionSteps.js +40 -0
  47. package/dist/common/types/transaction-flow.d.ts +48 -0
  48. package/dist/common/types/transaction-flow.d.ts.map +1 -0
  49. package/dist/common/types/transaction-flow.js +2 -0
  50. package/dist/common/utils/constant.d.ts +99 -0
  51. package/dist/common/utils/constant.d.ts.map +1 -0
  52. package/dist/common/utils/constant.js +370 -0
  53. package/dist/common/utils/token-pricing.d.ts +33 -0
  54. package/dist/common/utils/token-pricing.d.ts.map +1 -0
  55. package/dist/common/utils/token-pricing.js +255 -0
  56. package/dist/common/utils/transaction-flow.d.ts +35 -0
  57. package/dist/common/utils/transaction-flow.d.ts.map +1 -0
  58. package/dist/common/utils/transaction-flow.js +65 -0
  59. package/dist/index.d.ts +5 -0
  60. package/dist/index.d.ts.map +1 -0
  61. package/dist/index.js +2 -0
  62. package/dist/lib/utils.d.ts +4 -0
  63. package/dist/lib/utils.d.ts.map +1 -0
  64. package/dist/lib/utils.js +8 -0
  65. package/dist/nexus/NexusProvider.d.ts +50 -0
  66. package/dist/nexus/NexusProvider.d.ts.map +1 -0
  67. package/dist/nexus/NexusProvider.js +572 -0
  68. package/dist/nexus-widget/components/address-identicon.d.ts +5 -0
  69. package/dist/nexus-widget/components/address-identicon.d.ts.map +1 -0
  70. package/dist/nexus-widget/components/address-identicon.js +39 -0
  71. package/dist/nexus-widget/components/amount-input-unified.d.ts +18 -0
  72. package/dist/nexus-widget/components/amount-input-unified.d.ts.map +1 -0
  73. package/dist/nexus-widget/components/amount-input-unified.js +88 -0
  74. package/dist/nexus-widget/components/deposit-idle-form.d.ts +29 -0
  75. package/dist/nexus-widget/components/deposit-idle-form.d.ts.map +1 -0
  76. package/dist/nexus-widget/components/deposit-idle-form.js +506 -0
  77. package/dist/nexus-widget/components/nexus-widget-progress-screen.d.ts +36 -0
  78. package/dist/nexus-widget/components/nexus-widget-progress-screen.d.ts.map +1 -0
  79. package/dist/nexus-widget/components/nexus-widget-progress-screen.js +737 -0
  80. package/dist/nexus-widget/components/pay-using-selector.d.ts +9 -0
  81. package/dist/nexus-widget/components/pay-using-selector.d.ts.map +1 -0
  82. package/dist/nexus-widget/components/pay-using-selector.js +37 -0
  83. package/dist/nexus-widget/components/pay-with-sources.d.ts +11 -0
  84. package/dist/nexus-widget/components/pay-with-sources.d.ts.map +1 -0
  85. package/dist/nexus-widget/components/pay-with-sources.js +266 -0
  86. package/dist/nexus-widget/components/receive-asset-selector.d.ts +28 -0
  87. package/dist/nexus-widget/components/receive-asset-selector.d.ts.map +1 -0
  88. package/dist/nexus-widget/components/receive-asset-selector.js +1178 -0
  89. package/dist/nexus-widget/components/recipient-input.d.ts +10 -0
  90. package/dist/nexus-widget/components/recipient-input.d.ts.map +1 -0
  91. package/dist/nexus-widget/components/recipient-input.js +44 -0
  92. package/dist/nexus-widget/components/send-idle-form.d.ts +29 -0
  93. package/dist/nexus-widget/components/send-idle-form.d.ts.map +1 -0
  94. package/dist/nexus-widget/components/send-idle-form.js +548 -0
  95. package/dist/nexus-widget/components/status-alerts.d.ts +7 -0
  96. package/dist/nexus-widget/components/status-alerts.d.ts.map +1 -0
  97. package/dist/nexus-widget/components/status-alerts.js +17 -0
  98. package/dist/nexus-widget/components/swap-asset-selector.d.ts +74 -0
  99. package/dist/nexus-widget/components/swap-asset-selector.d.ts.map +1 -0
  100. package/dist/nexus-widget/components/swap-asset-selector.js +1910 -0
  101. package/dist/nexus-widget/components/swap-idle-form.d.ts +29 -0
  102. package/dist/nexus-widget/components/swap-idle-form.d.ts.map +1 -0
  103. package/dist/nexus-widget/components/swap-idle-form.js +1289 -0
  104. package/dist/nexus-widget/components/swap-intent-preview.d.ts +95 -0
  105. package/dist/nexus-widget/components/swap-intent-preview.d.ts.map +1 -0
  106. package/dist/nexus-widget/components/swap-intent-preview.js +1050 -0
  107. package/dist/nexus-widget/nexus-widget.d.ts +4 -0
  108. package/dist/nexus-widget/nexus-widget.d.ts.map +1 -0
  109. package/dist/nexus-widget/nexus-widget.js +7819 -0
  110. package/dist/nexus-widget/sdk-types.d.ts +13 -0
  111. package/dist/nexus-widget/sdk-types.d.ts.map +1 -0
  112. package/dist/nexus-widget/sdk-types.js +1 -0
  113. package/dist/nexus-widget/theme.d.ts +156 -0
  114. package/dist/nexus-widget/theme.d.ts.map +1 -0
  115. package/dist/nexus-widget/theme.js +159 -0
  116. package/dist/nexus-widget/types.d.ts +141 -0
  117. package/dist/nexus-widget/types.d.ts.map +1 -0
  118. package/dist/nexus-widget/types.js +1 -0
  119. package/dist/nexus-widget/utils/citrea-tokens.d.ts +82 -0
  120. package/dist/nexus-widget/utils/citrea-tokens.d.ts.map +1 -0
  121. package/dist/nexus-widget/utils/citrea-tokens.js +136 -0
  122. package/dist/nexus-widget/utils/deposit-source-selection.d.ts +55 -0
  123. package/dist/nexus-widget/utils/deposit-source-selection.d.ts.map +1 -0
  124. package/dist/nexus-widget/utils/deposit-source-selection.js +219 -0
  125. package/dist/swaps/components/stacked-token-icons.d.ts +15 -0
  126. package/dist/swaps/components/stacked-token-icons.d.ts.map +1 -0
  127. package/dist/swaps/components/stacked-token-icons.js +38 -0
  128. package/dist/swaps/components/step-flow.d.ts +32 -0
  129. package/dist/swaps/components/step-flow.d.ts.map +1 -0
  130. package/dist/swaps/components/step-flow.js +54 -0
  131. package/dist/swaps/components/token-icon.d.ts +11 -0
  132. package/dist/swaps/components/token-icon.d.ts.map +1 -0
  133. package/dist/swaps/components/token-icon.js +16 -0
  134. package/dist/swaps/components/transaction-progress.d.ts +43 -0
  135. package/dist/swaps/components/transaction-progress.d.ts.map +1 -0
  136. package/dist/swaps/components/transaction-progress.js +94 -0
  137. package/dist/ui/button.d.ts +11 -0
  138. package/dist/ui/button.d.ts.map +1 -0
  139. package/dist/ui/button.js +34 -0
  140. package/dist/ui/dialog.d.ts +17 -0
  141. package/dist/ui/dialog.d.ts.map +1 -0
  142. package/dist/ui/dialog.js +47 -0
  143. package/package.json +60 -0
@@ -0,0 +1,88 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // biome-ignore-all lint: NexusWidget registry component from shadcn registry.
3
+ import Decimal from "decimal.js";
4
+ import React, { useMemo } from "react";
5
+ import { formatTokenAmountDisplay, formatUsdBalanceLabel, } from "./swap-asset-selector";
6
+ export function AmountInputUnified({ amount, onChange, onCommit, disabled, maxAvailableAmount, unifiedBalances, tokenIcon, usdValue, tokenSymbol, header, }) {
7
+ const handleMax = () => {
8
+ if (!totalBalanceValue)
9
+ return;
10
+ onChange(totalBalanceValue);
11
+ onCommit?.(totalBalanceValue);
12
+ };
13
+ const isUsdMode = !tokenSymbol;
14
+ const totalBalanceValue = useMemo(() => {
15
+ if (!unifiedBalances || !unifiedBalances.length)
16
+ return "";
17
+ if (isUsdMode) {
18
+ return unifiedBalances
19
+ .reduce((acc, curr) => acc.add(curr.balanceInFiat ?? 0), new Decimal(0))
20
+ .toDecimalPlaces(8, Decimal.ROUND_DOWN)
21
+ .toFixed();
22
+ }
23
+ return unifiedBalances
24
+ .reduce((acc, curr) => acc.add(curr.balance ?? 0), new Decimal(0))
25
+ .toDecimalPlaces(8, Decimal.ROUND_DOWN)
26
+ .toFixed();
27
+ }, [isUsdMode, unifiedBalances]);
28
+ const totalBalanceLabel = useMemo(() => {
29
+ if (!unifiedBalances || !unifiedBalances.length)
30
+ return "0";
31
+ if (isUsdMode) {
32
+ const fiatAmount = unifiedBalances.reduce((acc, curr) => acc.add(curr.balanceInFiat ?? 0), new Decimal(0));
33
+ return formatUsdBalanceLabel(fiatAmount);
34
+ }
35
+ const amount = unifiedBalances.reduce((acc, curr) => acc.add(curr.balance ?? 0), new Decimal(0));
36
+ return formatTokenAmountDisplay(amount);
37
+ }, [isUsdMode, unifiedBalances]);
38
+ return (_jsxs("div", { className: "w-full flex flex-col bg-white min-h-[136px] nexus-focus-container", style: {
39
+ borderRadius: "10px",
40
+ border: "1px solid var(--border-default, #E8E8E7)",
41
+ boxShadow: "0px 1px 12px 0px #5B5B5B0D",
42
+ background: "#FFFFFF",
43
+ }, children: [header && (_jsx("div", { className: "w-full border-b border-[#E8E8E7] px-3.5 py-2.5", children: header })), _jsxs("div", { className: "flex-1 w-full flex flex-col items-center justify-center p-3.5 relative", children: [_jsxs("div", { className: "flex items-center justify-center w-full gap-x-1.5 mb-1", children: [_jsxs("div", { className: "flex items-center justify-center text-center", style: {
44
+ fontSize: "28px",
45
+ fontWeight: 500,
46
+ gap: "2px",
47
+ }, children: [tokenIcon ? (_jsx("div", { className: "flex items-center justify-center mr-2", children: tokenIcon })) : (_jsx("span", { className: "leading-none text-gray-800 mr-1", children: "$" })), _jsx("input", { className: "min-w-0 text-start bg-transparent border-none outline-none p-0 focus:ring-0 placeholder:text-gray-300 truncate tabular-nums", disabled: disabled, inputMode: "decimal", onBlur: () => onCommit?.(amount), onChange: (e) => {
48
+ let next = e.target.value.replaceAll(/[^0-9.]/g, "");
49
+ const parts = next.split(".");
50
+ if (parts.length > 2)
51
+ next = parts[0] + "." + parts.slice(1).join("");
52
+ if (next === ".")
53
+ next = "0.";
54
+ onChange(next);
55
+ }, onKeyDown: (e) => {
56
+ if (e.key === "Enter")
57
+ onCommit?.(amount);
58
+ }, placeholder: "0", style: {
59
+ fontFamily: "'Delight', sans-serif",
60
+ fontWeight: 500,
61
+ fontSize: "28px",
62
+ lineHeight: "100%",
63
+ height: "28px",
64
+ letterSpacing: "2%",
65
+ color: "var(--foreground-primary, #161615)",
66
+ fieldSizing: "content",
67
+ minWidth: "1ch",
68
+ maxWidth: "6ch",
69
+ }, type: "text", value: amount })] }), _jsx("button", { className: "shrink-0 focus:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed transition-opacity", disabled: disabled || !maxAvailableAmount, onClick: handleMax, style: {
70
+ background: "var(--background-tertiary, #F0F0EF)",
71
+ width: "36px",
72
+ height: "20px",
73
+ borderRadius: "5px",
74
+ padding: "2px 6px",
75
+ color: "var(--foreground-muted, #848483)",
76
+ fontFamily: "var(--font-geist-mono), ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",
77
+ fontWeight: 400,
78
+ fontSize: "9px",
79
+ lineHeight: "100%",
80
+ }, children: "MAX" })] }), (totalBalanceValue || maxAvailableAmount) && (_jsx("div", { className: "absolute bottom-3 left-0 w-full flex justify-center", children: _jsxs("p", { style: {
81
+ color: "var(--widget-card-foreground-muted, #848483)",
82
+ fontFamily: "var(--font-geist-sans), ui-sans-serif, system-ui, sans-serif",
83
+ fontWeight: 400,
84
+ fontSize: "10.5px",
85
+ lineHeight: "100%",
86
+ textAlign: "center",
87
+ }, children: ["Balance: ", totalBalanceLabel || "0", tokenSymbol ? ` ${tokenSymbol}` : ""] }) }))] })] }));
88
+ }
@@ -0,0 +1,29 @@
1
+ import { type SwapTokenOption } from "./swap-asset-selector";
2
+ interface DepositIdleFormProps {
3
+ amount: string;
4
+ amountMode: "token" | "usd";
5
+ calculatingPercent?: number | null;
6
+ fromTokens: SwapTokenOption[];
7
+ isAmountReadOnly?: boolean;
8
+ isCalculatingMax?: boolean;
9
+ isQuoteRefreshing?: boolean;
10
+ isSourcePickerDisabled?: boolean;
11
+ isTokenPickerDisabled?: boolean;
12
+ hideDestinationTokenDropdownIcon?: boolean;
13
+ onAmountChange: (val: string) => void;
14
+ onAmountModeToggle: () => void;
15
+ onOpenSourcePicker: () => void;
16
+ onOpenTokenPicker?: () => void;
17
+ onSetPercent: (pct: number) => void;
18
+ reserveSourceRows?: boolean;
19
+ routeMessage?: string;
20
+ routeStatus?: "loading" | "insufficient";
21
+ showAutoBadge?: boolean;
22
+ tokenValue: string;
23
+ toToken?: SwapTokenOption;
24
+ totalBalance: string;
25
+ usdValue: string;
26
+ }
27
+ export declare function DepositIdleForm({ amount, amountMode, onAmountChange, onAmountModeToggle, toToken, totalBalance, usdValue, tokenValue, fromTokens, onOpenSourcePicker, onSetPercent, routeStatus, routeMessage, isAmountReadOnly, isCalculatingMax, calculatingPercent, isQuoteRefreshing, hideDestinationTokenDropdownIcon, showAutoBadge, isSourcePickerDisabled, isTokenPickerDisabled, onOpenTokenPicker, reserveSourceRows, }: DepositIdleFormProps): import("react/jsx-runtime").JSX.Element;
28
+ export {};
29
+ //# sourceMappingURL=deposit-idle-form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deposit-idle-form.d.ts","sourceRoot":"","sources":["../../../.build-src/nexus-widget/components/deposit-idle-form.tsx"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,uBAAuB,CAAC;AAE/B,UAAU,oBAAoB;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,GAAG,KAAK,CAAC;IAC5B,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,gCAAgC,CAAC,EAAE,OAAO,CAAC;IAC3C,cAAc,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,kBAAkB,EAAE,MAAM,IAAI,CAAC;IAC/B,kBAAkB,EAAE,MAAM,IAAI,CAAC;IAC/B,iBAAiB,CAAC,EAAE,MAAM,IAAI,CAAC;IAC/B,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,SAAS,GAAG,cAAc,CAAC;IACzC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAmgBD,wBAAgB,eAAe,CAAC,EAC9B,MAAM,EACN,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,gBAAwB,EACxB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,gCAAwC,EACxC,aAAoB,EACpB,sBAA8B,EAC9B,qBAA6B,EAC7B,iBAAiB,EACjB,iBAAyB,GAC1B,EAAE,oBAAoB,2CA2XtB"}
@@ -0,0 +1,506 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ // biome-ignore-all lint: NexusWidget registry component from shadcn registry.
3
+ import Decimal from "decimal.js";
4
+ import { AlertCircle, ChevronDown, Loader2 } from "lucide-react";
5
+ import React, { useRef, useState } from "react";
6
+ import { PayWithSources as SharedPayWithSources } from "./pay-with-sources";
7
+ import { formatSelectedTokenBalanceLabel, formatUsdBalanceLabel, } from "./swap-asset-selector";
8
+ const uiFont = '"Geist", system-ui, sans-serif';
9
+ const primary = "#161615";
10
+ const muted = "#848483";
11
+ const border = "#E8E8E7";
12
+ const brand = "var(--foreground-brand)";
13
+ const parseDecimal = (value) => {
14
+ if (value === null || value === undefined || value === "")
15
+ return undefined;
16
+ if (Decimal.isDecimal(value))
17
+ return value;
18
+ const cleaned = String(value).replace(/[^0-9.-]/g, "");
19
+ if (!cleaned || cleaned === "-" || cleaned === "." || cleaned === "-.") {
20
+ return undefined;
21
+ }
22
+ try {
23
+ const parsed = new Decimal(cleaned);
24
+ return parsed.isFinite() ? parsed : undefined;
25
+ }
26
+ catch {
27
+ return undefined;
28
+ }
29
+ };
30
+ const formatToken = (value) => {
31
+ const amount = parseDecimal(value) ?? new Decimal(0);
32
+ return amount.toDecimalPlaces(8).toFixed();
33
+ };
34
+ const formatUsd = (value) => {
35
+ const amount = parseDecimal(value) ?? new Decimal(0);
36
+ if (amount.gt(0) && amount.lt(0.01))
37
+ return "<$0.01";
38
+ return `$${amount.toDecimalPlaces(2).toFixed()}`;
39
+ };
40
+ const MAX_AMOUNT_DISPLAY_DECIMALS = 8;
41
+ const getTokenInputDecimals = (token) => {
42
+ const decimals = Number(token?.decimals);
43
+ return Number.isFinite(decimals) && decimals >= 0 ? Math.floor(decimals) : 18;
44
+ };
45
+ const formatAmountInputDisplay = (value) => {
46
+ if (!value)
47
+ return "";
48
+ try {
49
+ return new Decimal(value)
50
+ .toDecimalPlaces(MAX_AMOUNT_DISPLAY_DECIMALS, Decimal.ROUND_DOWN)
51
+ .toFixed();
52
+ }
53
+ catch {
54
+ return value;
55
+ }
56
+ };
57
+ const sanitizeAmountInput = (raw, maxDecimals) => {
58
+ let next = raw.replaceAll(/[^0-9.]/g, "");
59
+ const parts = next.split(".");
60
+ if (parts.length > 2)
61
+ next = parts[0] + "." + parts.slice(1).join("");
62
+ const [integerPart, decimalPart] = next.split(".");
63
+ if (decimalPart !== undefined) {
64
+ next = `${integerPart}.${decimalPart.slice(0, Math.max(0, maxDecimals))}`;
65
+ }
66
+ if (next === ".")
67
+ next = "0.";
68
+ return next;
69
+ };
70
+ function TokenLogo({ src, label, size = 30, fontSize = 12, style, }) {
71
+ const [failed, setFailed] = useState(!src);
72
+ React.useEffect(() => {
73
+ setFailed(!src);
74
+ }, [src]);
75
+ if (!failed && src) {
76
+ return (_jsx("img", { alt: label || "", onError: () => setFailed(true), src: src, style: {
77
+ backgroundColor: "#FFFFFE",
78
+ borderRadius: "999px",
79
+ height: size,
80
+ objectFit: "cover",
81
+ width: size,
82
+ ...style,
83
+ } }));
84
+ }
85
+ return (_jsx("div", { style: {
86
+ alignItems: "center",
87
+ backgroundColor: "#E8F0FF",
88
+ borderRadius: "999px",
89
+ color: brand,
90
+ display: "flex",
91
+ fontFamily: uiFont,
92
+ fontSize,
93
+ fontWeight: 700,
94
+ height: size,
95
+ justifyContent: "center",
96
+ width: size,
97
+ ...style,
98
+ }, children: (label || "?").slice(0, 1).toUpperCase() }));
99
+ }
100
+ function SourceLogoPair({ token }) {
101
+ return (_jsxs("div", { style: { flexShrink: 0, height: 32, position: "relative", width: 32 }, children: [_jsx(TokenLogo, { label: token.symbol, size: 32, src: token.logo }), token.chainLogo && (_jsx(TokenLogo, { label: token.chainName, size: 14, src: token.chainLogo, style: {
102
+ bottom: -2,
103
+ outline: "1px solid #FFFFFE",
104
+ position: "absolute",
105
+ right: -2,
106
+ } }))] }));
107
+ }
108
+ function ExactOutPercentButtons({ visible, onSelect, }) {
109
+ return (_jsx("div", { style: {
110
+ alignItems: "center",
111
+ boxSizing: "border-box",
112
+ display: "flex",
113
+ gap: "6px",
114
+ opacity: visible ? 1 : 0,
115
+ pointerEvents: visible ? "auto" : "none",
116
+ transition: "opacity 0.18s ease-out",
117
+ width: "100%",
118
+ }, children: [25, 50, 75, 100].map((pct) => {
119
+ const isMax = pct === 100;
120
+ return (_jsx("button", { onClick: (e) => {
121
+ e.stopPropagation();
122
+ onSelect(pct);
123
+ }, onMouseDown: (e) => {
124
+ e.preventDefault();
125
+ }, style: {
126
+ alignItems: "center",
127
+ backgroundColor: isMax ? "#E8F0FF" : "#F4F4F3",
128
+ border: "none",
129
+ borderRadius: "8px",
130
+ boxSizing: "border-box",
131
+ color: isMax ? brand : "#363635",
132
+ cursor: "pointer",
133
+ display: "flex",
134
+ flex: "1 1 0%",
135
+ fontFamily: '"Geist", system-ui, sans-serif',
136
+ fontSize: "12px",
137
+ fontWeight: 500,
138
+ justifyContent: "center",
139
+ lineHeight: "20px",
140
+ minWidth: 0,
141
+ paddingBlock: "5px",
142
+ paddingInline: "10px",
143
+ }, tabIndex: -1, type: "button", children: isMax ? "MAX" : `${pct}%` }, pct));
144
+ }) }));
145
+ }
146
+ function SkeletonRow() {
147
+ return (_jsxs("div", { style: {
148
+ alignItems: "center",
149
+ display: "flex",
150
+ justifyContent: "space-between",
151
+ }, children: [_jsx("div", { className: "animate-pulse", style: {
152
+ background: "linear-gradient(90deg, #F0F0EF 0%, #F7F7F6 48%, #F0F0EF 100%)",
153
+ backgroundSize: "200% 100%",
154
+ borderRadius: "6px",
155
+ height: "32px",
156
+ width: "128px",
157
+ } }), _jsx("div", { className: "animate-pulse", style: {
158
+ background: "linear-gradient(90deg, #F0F0EF 0%, #F7F7F6 48%, #F0F0EF 100%)",
159
+ backgroundSize: "200% 100%",
160
+ borderRadius: "999px",
161
+ height: "32px",
162
+ width: "108px",
163
+ } })] }));
164
+ }
165
+ function PayWithSources({ fromTokens, onOpenSourcePicker, routeStatus, routeMessage, }) {
166
+ const scrollRef = useRef(null);
167
+ const isRouteLoading = routeStatus === "loading";
168
+ const shouldShowSourceSummary = !isRouteLoading && fromTokens.length > 0;
169
+ const shouldScroll = shouldShowSourceSummary && fromTokens.length > 3;
170
+ const autoBadge = (_jsx("span", { style: {
171
+ border: `1px solid ${brand}`,
172
+ borderRadius: "999px",
173
+ color: brand,
174
+ fontFamily: uiFont,
175
+ fontSize: "9px",
176
+ fontWeight: 600,
177
+ letterSpacing: "0.04em",
178
+ lineHeight: "14px",
179
+ padding: "1px 5px",
180
+ }, children: "AUTO" }));
181
+ return (_jsxs("div", { style: {
182
+ backgroundColor: "#FFFFFE",
183
+ border: `1px solid ${border}`,
184
+ borderRadius: "12px",
185
+ boxShadow: "#1616150A 0px 1px 2px",
186
+ boxSizing: "border-box",
187
+ display: "flex",
188
+ flexDirection: "column",
189
+ gap: "10px",
190
+ padding: "14px",
191
+ }, children: [_jsxs("div", { style: {
192
+ alignItems: "center",
193
+ display: "flex",
194
+ justifyContent: "space-between",
195
+ }, children: [_jsxs("div", { style: {
196
+ alignItems: "center",
197
+ color: muted,
198
+ display: "flex",
199
+ fontFamily: uiFont,
200
+ fontSize: "14px",
201
+ fontWeight: 500,
202
+ gap: "6px",
203
+ letterSpacing: "0.08em",
204
+ lineHeight: "20px",
205
+ textTransform: "uppercase",
206
+ }, children: [_jsxs("span", { children: ["Pay With", shouldShowSourceSummary ? ` · ${fromTokens.length} assets` : ""] }), autoBadge] }), shouldShowSourceSummary && (_jsx("button", { onClick: onOpenSourcePicker, style: {
207
+ backgroundColor: "#F4F7FE",
208
+ border: "none",
209
+ borderRadius: "6px",
210
+ color: brand,
211
+ cursor: "pointer",
212
+ fontFamily: uiFont,
213
+ fontSize: "14px",
214
+ fontWeight: 500,
215
+ lineHeight: "16px",
216
+ padding: "7px 10px",
217
+ }, children: "Edit tokens" }))] }), isRouteLoading ? (_jsxs(_Fragment, { children: [_jsx(SkeletonRow, {}), _jsxs("div", { style: {
218
+ alignItems: "center",
219
+ color: brand,
220
+ display: "flex",
221
+ fontFamily: uiFont,
222
+ fontSize: "15px",
223
+ gap: "6px",
224
+ }, children: [_jsx(Loader2, { className: "animate-spin", style: { height: 13, width: 13 } }), "Calculating best route..."] })] })) : shouldShowSourceSummary ? (_jsxs("div", { style: { position: "relative" }, children: [_jsx("div", { ref: scrollRef, style: {
225
+ display: "flex",
226
+ flexDirection: "column",
227
+ maxHeight: shouldScroll ? "184px" : undefined,
228
+ overflowY: shouldScroll ? "auto" : undefined,
229
+ paddingRight: shouldScroll ? "6px" : 0,
230
+ }, children: fromTokens.map((token, index) => (_jsxs("div", { style: {
231
+ alignItems: "center",
232
+ borderTop: index === 0 ? "none" : "1px solid #F0F0EF",
233
+ display: "flex",
234
+ justifyContent: "space-between",
235
+ minHeight: "52px",
236
+ padding: "6px 0",
237
+ }, children: [_jsxs("div", { style: {
238
+ alignItems: "center",
239
+ display: "flex",
240
+ gap: "10px",
241
+ minWidth: 0,
242
+ }, children: [_jsx(SourceLogoPair, { token: token }), _jsxs("div", { style: {
243
+ display: "flex",
244
+ flexDirection: "column",
245
+ gap: "3px",
246
+ minWidth: 0,
247
+ }, children: [_jsx("span", { style: {
248
+ color: primary,
249
+ fontFamily: uiFont,
250
+ fontSize: "16px",
251
+ fontWeight: 600,
252
+ }, children: token.symbol }), _jsx("span", { style: {
253
+ color: muted,
254
+ fontFamily: uiFont,
255
+ fontSize: "14px",
256
+ overflow: "hidden",
257
+ textOverflow: "ellipsis",
258
+ whiteSpace: "nowrap",
259
+ }, children: token.isUnified
260
+ ? "Unified balance"
261
+ : `on ${token.chainName || "Unknown chain"}` })] })] }), _jsxs("div", { style: {
262
+ display: "flex",
263
+ flexDirection: "column",
264
+ gap: "3px",
265
+ textAlign: "right",
266
+ }, children: [_jsxs("span", { style: {
267
+ color: primary,
268
+ fontFamily: uiFont,
269
+ fontSize: "15px",
270
+ }, children: [formatToken(token.userAmount || token.balance), " ", token.symbol] }), _jsx("span", { style: {
271
+ color: muted,
272
+ fontFamily: uiFont,
273
+ fontSize: "14px",
274
+ }, children: formatUsd(token.userAmountUsd || token.balanceInFiat) })] })] }, `${token.contractAddress}-${token.chainId ?? "unified"}-${index}`))) }), shouldScroll && (_jsx("button", { "aria-label": "Scroll payment sources", onClick: () => scrollRef.current?.scrollBy({ behavior: "smooth", top: 64 }), style: {
275
+ alignItems: "center",
276
+ background: "#FFFFFE",
277
+ border: `1px solid ${border}`,
278
+ borderRadius: "999px",
279
+ bottom: "4px",
280
+ boxShadow: "0 2px 8px rgba(22,22,21,0.08)",
281
+ cursor: "pointer",
282
+ display: "flex",
283
+ height: "22px",
284
+ justifyContent: "center",
285
+ left: "50%",
286
+ padding: 0,
287
+ position: "absolute",
288
+ transform: "translateX(-50%)",
289
+ width: "22px",
290
+ }, type: "button", children: _jsx(ChevronDown, { style: { color: muted, height: 14, width: 14 } }) }))] })) : (_jsx("div", { style: {
291
+ color: primary,
292
+ fontFamily: uiFont,
293
+ fontSize: "15px",
294
+ lineHeight: "20px",
295
+ }, children: "Sources will be auto selected" })), routeStatus === "insufficient" && routeMessage && (_jsxs("div", { style: {
296
+ alignItems: "center",
297
+ color: "#D32F2F",
298
+ display: "flex",
299
+ fontFamily: uiFont,
300
+ fontSize: "15px",
301
+ gap: "8px",
302
+ lineHeight: "20px",
303
+ }, children: [_jsx(AlertCircle, { style: { flexShrink: 0, height: 15, width: 15 } }), routeMessage] }))] }));
304
+ }
305
+ export function DepositIdleForm({ amount, amountMode, onAmountChange, onAmountModeToggle, toToken, totalBalance, usdValue, tokenValue, fromTokens, onOpenSourcePicker, onSetPercent, routeStatus, routeMessage, isAmountReadOnly = false, isCalculatingMax, calculatingPercent, isQuoteRefreshing, hideDestinationTokenDropdownIcon = false, showAutoBadge = true, isSourcePickerDisabled = false, isTokenPickerDisabled = false, onOpenTokenPicker, reserveSourceRows = false, }) {
306
+ const [pendingPercent, setPendingPercent] = useState(null);
307
+ const [isAmountFocused, setIsAmountFocused] = useState(false);
308
+ React.useEffect(() => {
309
+ if (!isCalculatingMax)
310
+ setPendingPercent(null);
311
+ }, [isCalculatingMax]);
312
+ const handlePercentSelect = (pct) => {
313
+ setPendingPercent(pct);
314
+ onSetPercent(pct);
315
+ };
316
+ const handleInput = (e) => {
317
+ if (isAmountReadOnly)
318
+ return;
319
+ onAmountChange(sanitizeAmountInput(e.target.value, isUsdMode
320
+ ? MAX_AMOUNT_DISPLAY_DECIMALS
321
+ : getTokenInputDecimals(toToken)));
322
+ };
323
+ const isUsdMode = amountMode === "usd";
324
+ const amountDisplayValue = isAmountFocused
325
+ ? amount
326
+ : formatAmountInputDisplay(amount);
327
+ const showTokenPickerDropdownIcon = Boolean(onOpenTokenPicker) &&
328
+ !isTokenPickerDisabled &&
329
+ !hideDestinationTokenDropdownIcon;
330
+ const activePendingPercent = calculatingPercent ?? (isCalculatingMax ? pendingPercent : null);
331
+ const isMaxCalculating = Boolean(isCalculatingMax && activePendingPercent === 100);
332
+ const destinationBalanceLabel = isUsdMode
333
+ ? formatUsdBalanceLabel(toToken?.balanceInFiat)
334
+ : formatSelectedTokenBalanceLabel(toToken) ||
335
+ `0 ${toToken?.symbol || ""}`.trim();
336
+ return (_jsxs("div", { style: {
337
+ display: "flex",
338
+ flexDirection: "column",
339
+ gap: "10px",
340
+ width: "100%",
341
+ }, children: [_jsxs("div", { className: "nexus-focus-container", style: {
342
+ backgroundColor: "#FFFFFE",
343
+ borderColor: border,
344
+ borderRadius: "14px",
345
+ borderStyle: "solid",
346
+ borderWidth: "1px",
347
+ boxShadow: "#1616150A 0px 1px 2px",
348
+ boxSizing: "border-box",
349
+ display: "flex",
350
+ flexDirection: "column",
351
+ gap: "14px",
352
+ padding: "16px",
353
+ }, children: [_jsxs("div", { style: {
354
+ alignItems: "center",
355
+ display: "flex",
356
+ justifyContent: "space-between",
357
+ }, children: [_jsx("div", { style: {
358
+ color: muted,
359
+ fontFamily: uiFont,
360
+ fontSize: "12px",
361
+ fontWeight: 600,
362
+ letterSpacing: "0.08em",
363
+ lineHeight: "20px",
364
+ textTransform: "uppercase",
365
+ }, children: "Deposit" }), _jsxs("div", { style: { alignItems: "center", display: "flex", gap: "4px" }, children: [_jsx("span", { style: {
366
+ color: muted,
367
+ fontFamily: uiFont,
368
+ fontSize: "14px",
369
+ lineHeight: "20px",
370
+ }, children: "Total Balance:" }), _jsxs("span", { style: {
371
+ color: primary,
372
+ fontFamily: uiFont,
373
+ fontSize: "14px",
374
+ fontWeight: 600,
375
+ lineHeight: "20px",
376
+ }, children: ["$", totalBalance] })] })] }), _jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "10px" }, children: [_jsxs("div", { style: {
377
+ alignItems: "center",
378
+ display: "flex",
379
+ gap: "12px",
380
+ justifyContent: "space-between",
381
+ width: "100%",
382
+ }, children: [_jsxs("div", { style: {
383
+ alignItems: "baseline",
384
+ display: "flex",
385
+ flex: "1 1 0%",
386
+ minWidth: 0,
387
+ }, children: [isMaxCalculating ? (_jsx("div", { "aria-label": "Calculating max amount", className: "animate-pulse", style: {
388
+ alignSelf: "center",
389
+ backgroundColor: "#F0F0EF",
390
+ borderRadius: "8px",
391
+ height: "44px",
392
+ maxWidth: "220px",
393
+ minWidth: "132px",
394
+ width: "62%",
395
+ } })) : (_jsxs(_Fragment, { children: [isUsdMode && amount && (_jsx("span", { style: {
396
+ color: primary,
397
+ fontFamily: '"Delight-Medium", "Delight", system-ui, sans-serif',
398
+ fontSize: "36px",
399
+ fontWeight: 500,
400
+ lineHeight: "44px",
401
+ }, children: "$" })), _jsx("input", { "aria-readonly": isAmountReadOnly, onBlur: () => setIsAmountFocused(false), onChange: handleInput, onFocus: () => setIsAmountFocused(true), placeholder: "0", style: {
402
+ background: "transparent",
403
+ border: "none",
404
+ boxSizing: "border-box",
405
+ color: amount ? primary : "#C8C8C6",
406
+ cursor: isAmountReadOnly ? "default" : "text",
407
+ fontFamily: '"Delight-Medium", "Delight", system-ui, sans-serif',
408
+ fontSize: "36px",
409
+ fontWeight: 500,
410
+ lineHeight: "44px",
411
+ minWidth: 0,
412
+ outline: "none",
413
+ padding: 0,
414
+ width: "100%",
415
+ }, readOnly: isAmountReadOnly, type: "text", value: amountDisplayValue })] })), isCalculatingMax && !isMaxCalculating && (_jsx(Loader2, { className: "animate-spin", style: {
416
+ alignSelf: "center",
417
+ color: brand,
418
+ flexShrink: 0,
419
+ height: 18,
420
+ marginLeft: 6,
421
+ width: 18,
422
+ } }))] }), _jsxs("div", { onClick: onOpenTokenPicker && !isTokenPickerDisabled
423
+ ? onOpenTokenPicker
424
+ : undefined, role: onOpenTokenPicker && !isTokenPickerDisabled
425
+ ? "button"
426
+ : undefined, tabIndex: onOpenTokenPicker && !isTokenPickerDisabled ? 0 : undefined, style: {
427
+ alignItems: "center",
428
+ backgroundColor: "#FFFFFE",
429
+ borderColor: border,
430
+ borderRadius: "999px",
431
+ borderStyle: "solid",
432
+ borderWidth: "1px",
433
+ boxShadow: "#1616150A 0px 1px 2px",
434
+ boxSizing: "border-box",
435
+ cursor: onOpenTokenPicker && !isTokenPickerDisabled
436
+ ? "pointer"
437
+ : "default",
438
+ display: "inline-flex",
439
+ flexShrink: 0,
440
+ gap: "8px",
441
+ paddingBottom: "5px",
442
+ paddingLeft: toToken ? "5px" : "10px",
443
+ paddingRight: "10px",
444
+ paddingTop: "5px",
445
+ }, children: [_jsxs("div", { style: {
446
+ flexShrink: 0,
447
+ height: "26px",
448
+ position: "relative",
449
+ width: "26px",
450
+ }, children: [_jsx(TokenLogo, { label: toToken?.symbol, size: 26, src: toToken?.logo }), toToken?.chainLogo && (_jsx(TokenLogo, { label: toToken.chainName, size: 12, src: toToken.chainLogo, style: {
451
+ bottom: -2,
452
+ outline: "1px solid #FFFFFE",
453
+ position: "absolute",
454
+ right: -2,
455
+ width: 12,
456
+ height: 12,
457
+ } }))] }), _jsx("div", { style: {
458
+ color: primary,
459
+ fontFamily: uiFont,
460
+ fontSize: "16px",
461
+ fontWeight: 500,
462
+ lineHeight: "24px",
463
+ }, children: toToken?.symbol || "Token" }), showTokenPickerDropdownIcon && (_jsx(ChevronDown, { style: { color: "#5B5B5A", height: 16, width: 16 } }))] })] }), _jsxs("div", { style: {
464
+ alignItems: "center",
465
+ display: "flex",
466
+ justifyContent: "space-between",
467
+ width: "100%",
468
+ minHeight: "20px",
469
+ }, children: [_jsx("div", { style: {
470
+ display: "flex",
471
+ justifyContent: "flex-start",
472
+ alignItems: "center",
473
+ flex: 1,
474
+ }, children: _jsx("button", { disabled: isAmountReadOnly, onClick: onAmountModeToggle, style: {
475
+ background: "transparent",
476
+ border: "none",
477
+ color: isAmountReadOnly ? "#A8A8A6" : muted,
478
+ cursor: isAmountReadOnly ? "default" : "pointer",
479
+ fontFamily: uiFont,
480
+ fontSize: "14px",
481
+ lineHeight: "20px",
482
+ padding: 0,
483
+ }, type: "button", children: isUsdMode
484
+ ? `≈ ${tokenValue || "0"} ${toToken?.symbol || ""} ↕`
485
+ : `≈ $${usdValue || "0"} ↕` }) }), _jsxs("div", { style: {
486
+ alignItems: "center",
487
+ display: "flex",
488
+ justifyContent: "flex-end",
489
+ gap: "5px",
490
+ flex: 1,
491
+ minWidth: 0,
492
+ }, children: [_jsx("span", { style: {
493
+ color: "#7C7C7A",
494
+ fontFamily: uiFont,
495
+ fontSize: "14px",
496
+ lineHeight: "20px",
497
+ whiteSpace: "nowrap",
498
+ }, children: "Balance:" }), _jsx("span", { style: {
499
+ color: primary,
500
+ fontFamily: uiFont,
501
+ fontSize: "14px",
502
+ fontWeight: 500,
503
+ lineHeight: "20px",
504
+ whiteSpace: "nowrap",
505
+ }, children: destinationBalanceLabel })] })] }), _jsx(ExactOutPercentButtons, { onSelect: handlePercentSelect, visible: Boolean(toToken) && !isAmountReadOnly })] })] }), _jsx(SharedPayWithSources, { fromTokens: fromTokens, isSourcePickerDisabled: isSourcePickerDisabled, onOpenSourcePicker: onOpenSourcePicker, reserveSourceRows: reserveSourceRows, routeMessage: routeMessage, routeStatus: routeStatus, showAutoBadge: showAutoBadge })] }));
506
+ }