@gearbox-protocol/ui-kit 3.14.0-next.5 → 3.14.0-next.7

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 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),j=require("class-variance-authority"),re=require("react"),ae=require("react-dom"),oe=require("../checkbox/checkbox.cjs");require("../checkbox/checkbox-labeled.cjs");const ce=require("../currency-button/currency-button.cjs"),ie=require("@fortawesome/free-solid-svg-icons"),le=require("../icons/fa-icon.cjs"),I=require("../typed-intl/index.cjs"),N=require("../../hooks/use-media-query.cjs"),b=require("../../test-ids/smart-number-input.cjs"),ue=require("../../utils/bn-to-input-view.cjs");require("@gearbox-protocol/sdk");const de=require("../../utils/parse-input-to-bn.cjs"),y=require("../../utils/cn.cjs");require("sonner");require("@gearbox-protocol/sdk/common-utils");require("luxon");require("../../utils/z-index.cjs");const me=require("./balance-indicator.cjs");function fe(a){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const o in a)if(o!=="default"){const r=Object.getOwnPropertyDescriptor(a,o);Object.defineProperty(s,o,r.get?r:{enumerable:!0,get:()=>a[o]})}}return s.default=a,Object.freeze(s)}const c=fe(re),pe=j.cva("relative w-full text-foreground bg-gray-20 border border-gray-30 transition-[background-color] duration-100 ease-linear [&:hover]:bg-gray-30 [&:hover]:border-gray-40 data-[active=true]:bg-gray-30 data-[active=true]:outline data-[active=true]:outline-2 data-[active=true]:outline-primary data-[active=true]:outline-offset-[-2px] data-[disabled=true]:cursor-not-allowed",{variants:{size:{sm:"px-3 py-[7px] min-h-[60px] rounded-[8px]",md:"pl-4 pr-3 py-[10px] min-h-[82px] rounded-lg"}},defaultVariants:{size:"md"}}),he=j.cva("font-medium text-foreground",{variants:{size:{sm:"text-xs",md:"text-sm"}},defaultVariants:{size:"md"}}),xe=j.cva("w-full p-0 bg-transparent border-none outline-none text-foreground placeholder:text-secondary-foreground focus:outline-none",{variants:{size:{sm:"text-[18px]! leading-[21px]!",md:"text-[28px]! leading-[33px]!"}},defaultVariants:{size:"md"}});function ge(a,s){const o=parseFloat(a.replace(",",".")||"0");if(!Number.isFinite(o)||o===0)return"$0";const r=o*s,h=Math.abs(r)<100;try{return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:h?2:0,maximumFractionDigits:h?2:0}).format(r)}catch{return"$0"}}const M=c.forwardRef(({amount:a,token:s,label:o,maxAmount:r,maxAmountLimit:p,maxButtonLabel:h,chainId:S,network:L,maxButton:B=!0,disabled:u=!1,active:F=!1,size:V="md",symbolMaxLength:D,tokenOptions:v,multiSelectMode:R=!1,onSetAmount:m,onShowSelectDialog:k,onRemove:q,onFocus:E,onBlur:O,usdPrice:z},$)=>{const{formatMessage:P}=I.useIntlTyped(),U=c.useId(),C=s?.decimals??18,W=e=>{const n=e.target.value,[i,l]=de.parseInputToBN(n,C);i===null||l===null||m&&m(i,l)},Q=()=>{if(m){const e=r&&p&&r>p?p:r||0n,n=ue.bnToInputView(e,C);m(e,n)}},[X,T]=c.useState(!1),G=()=>{T(!0),E?.()},H=()=>{T(!1),O?.()},f=V??"md",J=N.useIsMobile(),K=N.useIsTablet(),Y=N.useIsDesktop(),Z=D??(J?20:K?30:Y?22:30),[d,w]=c.useState(!1),x=c.useRef(null),_=c.useRef(null),[A,ee]=c.useState({});c.useLayoutEffect(()=>{if(!d||!x.current)return;const e=()=>{const n=x.current?.getBoundingClientRect();n&&ee({position:"fixed",top:n.bottom+4,right:window.innerWidth-n.right,minWidth:n.width,zIndex:9999})};return e(),window.addEventListener("scroll",e,!0),window.addEventListener("resize",e),()=>{window.removeEventListener("scroll",e,!0),window.removeEventListener("resize",e)}},[d]),c.useEffect(()=>{if(!d)return;const e=n=>{const i=n.target,l=x.current?.contains(i),se=_.current?.contains(i);!l&&!se&&w(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]);const g=!!(v&&v.length>0),te=!u&&g?()=>w(e=>!e):k,ne=!!(s||k||g);return t.jsxs("div",{ref:$,className:pe({size:f}),"data-testid":b.smartNumberInputTestIds.root,"data-active":X,"data-disabled":u,children:[q&&t.jsx("div",{className:"absolute top-0 right-0 flex h-5 w-5 translate-x-1/2 -translate-y-1/2 items-center justify-center","data-testid":b.smartNumberInputTestIds.close,children:t.jsx("button",{type:"button",onClick:q,className:"flex h-5 w-5 items-center justify-center rounded-full bg-muted hover:bg-muted/80 text-muted-foreground",children:t.jsx(le.FaIcon,{icon:ie.faXmark,className:"size-3"})})}),t.jsxs("div",{className:"mb-2 flex justify-between text-sm leading-[120%]",children:[t.jsx("span",{className:y.cn(he({size:f}),"grow shrink-0 basis-0"),"data-testid":b.smartNumberInputTestIds.label,children:o??t.jsx(I.FormattedMessageTyped,{messageId:"components.smartNumberInput.amountLabel"})}),r!==void 0&&s&&t.jsx(me.BalanceIndicator,{title:h,token:s,maxAmount:r,size:f,disabled:u,maxButton:B,onMaxButtonClick:Q})]}),t.jsxs("div",{className:y.cn("flex w-full max-w-full shrink-0 basis-full items-center"),children:[t.jsx("div",{className:"mr-3 grow shrink-0 basis-0",children:t.jsx("input",{type:"text",inputMode:"decimal",autoComplete:"off",autoCorrect:"off",spellCheck:"false",pattern:"^[0-9]*[.,]?[0-9]*$",placeholder:"0",value:a,onChange:W,onFocus:G,onBlur:H,disabled:u||!m,className:y.cn(xe({size:f}),u&&"cursor-not-allowed"),"data-testid":b.smartNumberInputTestIds.input,minLength:1,maxLength:79,title:P({messageId:"components.smartNumberInput.inputTitle"})})}),ne?t.jsxs("div",{ref:x,className:"shrink-0",children:[t.jsx(ce.CurrencyButton,{active:g?d:F,size:f,disabled:u,token:s,showSelectDialog:te,chainId:S,network:L,maxLength:Z,children:s?.symbol??t.jsx(I.FormattedMessageTyped,{messageId:"components.smartNumberInput.selectToken"})}),g&&d&&ae.createPortal(t.jsx("div",{ref:_,style:A,className:"overflow-hidden rounded-lg border border-gray-30 bg-gray-20 shadow-lg",children:v?.map((e,n)=>{const i=`${U}-${n}`,l="flex w-full min-w-0 items-center gap-2 px-3 py-2 text-sm text-foreground hover:bg-gray-30";return R?t.jsxs("div",{className:l,children:[t.jsx(oe.Checkbox,{id:i,checked:!!e.checked,color:"secondary",size:"md",className:"shrink-0",onCheckedChange:()=>e.onSelect()}),t.jsxs("label",{htmlFor:i,className:"flex min-w-0 flex-1 cursor-pointer items-center gap-2 text-left",children:[e.icon?t.jsx("span",{className:"inline-flex shrink-0 items-center",children:e.icon}):null,t.jsx("span",{className:"truncate",children:e.label})]})]},n):t.jsxs("button",{type:"button",onClick:()=>{e.onSelect(),w(!1)},className:y.cn(l,"text-left"),children:[e.icon?t.jsx("span",{className:"inline-flex shrink-0 items-center",children:e.icon}):null,t.jsx("span",{className:"truncate",children:e.label})]},n)})}),document.body)]}):null]}),z!==void 0&&t.jsx("div",{className:"mt-1 text-xs leading-[130%] text-secondary-foreground",children:ge(a,z)})]})});M.displayName="SmartNumberInput";exports.SmartNumberInput=M;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),q=require("class-variance-authority"),de=require("react"),me=require("react-dom"),pe=require("../checkbox/checkbox.cjs");require("../checkbox/checkbox-labeled.cjs");const fe=require("../currency-button/currency-button.cjs"),he=require("../health-factor/health-factor.cjs"),xe=require("@fortawesome/free-solid-svg-icons"),ge=require("../icons/fa-icon.cjs"),be=require("../slider/slider.cjs");require("../slider/slider-context.cjs");const I=require("../typed-intl/index.cjs"),j=require("../../hooks/use-media-query.cjs"),v=require("../../test-ids/smart-number-input.cjs"),ve=require("../../utils/bn-to-input-view.cjs");require("@gearbox-protocol/sdk");const ye=require("../../utils/parse-input-to-bn.cjs"),y=require("../../utils/cn.cjs");require("sonner");require("@gearbox-protocol/sdk/common-utils");require("luxon");require("../../utils/z-index.cjs");const we=require("./balance-indicator.cjs");function Ne(n){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const o in n)if(o!=="default"){const a=Object.getOwnPropertyDescriptor(n,o);Object.defineProperty(r,o,a.get?a:{enumerable:!0,get:()=>n[o]})}}return r.default=n,Object.freeze(r)}const c=Ne(de),Ie=q.cva("relative w-full text-foreground bg-gray-20 border border-gray-30 transition-[background-color] duration-100 ease-linear [&:hover]:bg-gray-30 [&:hover]:border-gray-40 data-[active=true]:bg-gray-30 data-[active=true]:outline data-[active=true]:outline-2 data-[active=true]:outline-primary data-[active=true]:outline-offset-[-2px] data-[disabled=true]:cursor-not-allowed",{variants:{size:{sm:"px-3 py-[7px] min-h-[60px] rounded-[8px]",md:"pl-4 pr-3 py-[10px] min-h-[82px] rounded-lg"}},defaultVariants:{size:"md"}}),je=q.cva("font-medium text-foreground",{variants:{size:{sm:"text-xs",md:"text-sm"}},defaultVariants:{size:"md"}}),ke=q.cva("w-full p-0 bg-transparent border-none outline-none text-foreground placeholder:text-secondary-foreground focus:outline-none",{variants:{size:{sm:"text-[18px]! leading-[21px]!",md:"text-[28px]! leading-[33px]!"}},defaultVariants:{size:"md"}});function k(n){return Math.round(n*100)}function qe(n){return n/100}function Me(n,r){if(!r)return null;const o=parseFloat(n.replace(",",".")||"0");if(!Number.isFinite(o)||o===0)return null;const a=o*r,x=Math.abs(a)<100;try{return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:x?2:0,maximumFractionDigits:x?2:0}).format(a)}catch{return"$0"}}const S=c.forwardRef(({amount:n,token:r,label:o,maxAmount:a,maxAmountLimit:h,maxButtonLabel:x,chainId:L,network:B,maxButton:V=!0,disabled:d=!1,active:D=!1,size:R="md",symbolMaxLength:E,tokenOptions:w,multiSelectMode:O=!1,onSetAmount:p,onShowSelectDialog:M,onRemove:_,onFocus:P,onBlur:$,usdPrice:C,hfSlider:l},H)=>{const{formatMessage:U}=I.useIntlTyped(),W=c.useId(),T=r?.decimals??18,Q=e=>{const s=e.target.value,[i,u]=ye.parseInputToBN(s,T);i===null||u===null||p&&p(i,u)},X=()=>{if(p){const e=a&&h&&a>h?h:a||0n,s=ve.bnToInputView(e,T);p(e,s)}},[G,z]=c.useState(!1),J=()=>{z(!0),P?.()},K=()=>{z(!1),$?.()},Y=j.useIsMobile(),Z=l?.min??1,A=l?.max??3,ee=l?.step??.01,te=Math.max(1,Math.round(1/ee)),f=R??"md",ne=Y,se=j.useIsTablet(),re=j.useIsDesktop(),ae=E??(ne?20:se?30:re?22:30),[m,N]=c.useState(!1),g=c.useRef(null),F=c.useRef(null),[oe,ce]=c.useState({});c.useLayoutEffect(()=>{if(!m||!g.current)return;const e=()=>{const s=g.current?.getBoundingClientRect();s&&ce({position:"fixed",top:s.bottom+4,right:window.innerWidth-s.right,minWidth:s.width,zIndex:9999})};return e(),window.addEventListener("scroll",e,!0),window.addEventListener("resize",e),()=>{window.removeEventListener("scroll",e,!0),window.removeEventListener("resize",e)}},[m]),c.useEffect(()=>{if(!m)return;const e=s=>{const i=s.target,u=g.current?.contains(i),ue=F.current?.contains(i);!u&&!ue&&N(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[m]);const b=!!(w&&w.length>0),ie=!d&&b?()=>N(e=>!e):M,le=!!(r||M||b);return t.jsxs("div",{ref:H,className:Ie({size:f}),"data-testid":v.smartNumberInputTestIds.root,"data-active":G,"data-disabled":d,children:[_&&t.jsx("div",{className:"absolute top-0 right-0 flex h-5 w-5 translate-x-1/2 -translate-y-1/2 items-center justify-center","data-testid":v.smartNumberInputTestIds.close,children:t.jsx("button",{type:"button",onClick:_,className:"flex h-5 w-5 items-center justify-center rounded-full bg-muted hover:bg-muted/80 text-muted-foreground",children:t.jsx(ge.FaIcon,{icon:xe.faXmark,className:"size-3"})})}),t.jsxs("div",{className:"mb-2 flex justify-between text-sm leading-[120%]",children:[t.jsx("span",{className:y.cn(je({size:f}),"grow shrink-0 basis-0"),"data-testid":v.smartNumberInputTestIds.label,children:o??t.jsx(I.FormattedMessageTyped,{messageId:"components.smartNumberInput.amountLabel"})}),l!==void 0?t.jsxs("div",{className:"ml-auto flex w-1/2 min-w-0 items-center gap-1",children:[t.jsx("span",{className:"shrink-0 text-xs text-secondary-foreground",children:"HF"}),t.jsx("div",{className:"min-w-0 flex-1 [&>div]:px-0 [&>div]:pb-0",children:t.jsx(be.Slider,{from:k(Z),to:k(A),value:k(l.value),precision:te,markerStep:0,epsilon:0,onChangeValue:e=>l.onChange(qe(e))})}),t.jsx(he.HealthFactor,{value:Math.round(l.value*1e4),debt:1n,decimals:2,className:"shrink-0 text-xs tabular-nums"})]}):a!==void 0&&r&&t.jsx(we.BalanceIndicator,{title:x,token:r,maxAmount:a,size:f,disabled:d,maxButton:V,onMaxButtonClick:X})]}),t.jsxs("div",{className:y.cn("flex w-full max-w-full shrink-0 basis-full items-center"),children:[t.jsx("div",{className:"mr-3 grow shrink-0 basis-0",children:t.jsx("input",{type:"text",inputMode:"decimal",autoComplete:"off",autoCorrect:"off",spellCheck:"false",pattern:"^[0-9]*[.,]?[0-9]*$",placeholder:"0",value:n,onChange:Q,onFocus:J,onBlur:K,disabled:d||!p,className:y.cn(ke({size:f}),d&&"cursor-not-allowed"),"data-testid":v.smartNumberInputTestIds.input,minLength:1,maxLength:79,title:U({messageId:"components.smartNumberInput.inputTitle"})})}),le?t.jsxs("div",{ref:g,className:"shrink-0",children:[t.jsx(fe.CurrencyButton,{active:b?m:D,size:f,disabled:d,token:r,showSelectDialog:ie,chainId:L,network:B,maxLength:ae,children:r?.symbol??t.jsx(I.FormattedMessageTyped,{messageId:"components.smartNumberInput.selectToken"})}),b&&m&&me.createPortal(t.jsx("div",{ref:F,style:oe,className:"overflow-hidden rounded-lg border border-gray-30 bg-gray-20 shadow-lg",children:w?.map((e,s)=>{const i=`${W}-${s}`,u="flex w-full min-w-0 items-center gap-2 px-3 py-2 text-sm text-foreground hover:bg-gray-30";return O?t.jsxs("div",{className:u,children:[t.jsx(pe.Checkbox,{id:i,checked:!!e.checked,color:"secondary",size:"md",className:"shrink-0",onCheckedChange:()=>e.onSelect()}),t.jsxs("label",{htmlFor:i,className:"flex min-w-0 flex-1 cursor-pointer items-center gap-2 text-left",children:[e.icon?t.jsx("span",{className:"inline-flex shrink-0 items-center",children:e.icon}):null,t.jsx("span",{className:"truncate",children:e.label})]})]},s):t.jsxs("button",{type:"button",onClick:()=>{e.onSelect(),N(!1)},className:y.cn(u,"text-left"),children:[e.icon?t.jsx("span",{className:"inline-flex shrink-0 items-center",children:e.icon}):null,t.jsx("span",{className:"truncate",children:e.label})]},s)})}),document.body)]}):null]}),C!==void 0&&(()=>{const e=Me(n,C);return e?t.jsx("div",{className:"mt-1 text-xs leading-[130%] text-secondary-foreground",children:e}):null})()]})});S.displayName="SmartNumberInput";exports.SmartNumberInput=S;
@@ -1,5 +1,5 @@
1
1
  import { jsxs as f, jsx as c } from "react/jsx-runtime";
2
- import { PERCENTAGE_FACTOR as p, formatPercentage as v } from "@gearbox-protocol/sdk";
2
+ import { formatPercentage as p, PERCENTAGE_FACTOR as v } from "@gearbox-protocol/sdk";
3
3
  import { cva as x } from "class-variance-authority";
4
4
  import "react";
5
5
  import { cn as C } from "../../utils/cn.js";
@@ -10,7 +10,7 @@ import "../../utils/z-index.js";
10
10
  import { StatusBars as F } from "../status-elements/status-elements.js";
11
11
  const g = 15e3, A = 11e3, H = 10500, N = (t) => {
12
12
  if (t)
13
- return t >= g ? "good" : t > A ? "medium" : t > H ? "bad" : t > p ? "critical" : "liquidation";
13
+ return t >= g ? "good" : t > A ? "medium" : t > H ? "bad" : t > v ? "critical" : "liquidation";
14
14
  }, b = x(
15
15
  "inline-flex items-center font-medium [text-decoration:inherit]",
16
16
  {
@@ -38,7 +38,7 @@ function G({
38
38
  const n = e !== void 0 && e === 0n, r = !n && i === "color" ? o === void 0 ? N(t) : o : void 0, s = r === void 0 ? void 0 : r === null ? "unset" : r, d = () => {
39
39
  if (n) return "N/A";
40
40
  const l = Number(t);
41
- return v(l, a);
41
+ return p(l, a);
42
42
  };
43
43
  return /* @__PURE__ */ f(
44
44
  "span",
@@ -1,25 +1,28 @@
1
1
  import { jsxs as l, jsx as t } from "react/jsx-runtime";
2
- import { cva as I } from "class-variance-authority";
3
- import * as n from "react";
4
- import { createPortal as ne } from "react-dom";
5
- import { Checkbox as se } from "../checkbox/checkbox.js";
2
+ import { cva as k } from "class-variance-authority";
3
+ import * as s from "react";
4
+ import { createPortal as de } from "react-dom";
5
+ import { Checkbox as ue } from "../checkbox/checkbox.js";
6
6
  import "../checkbox/checkbox-labeled.js";
7
- import { CurrencyButton as ae } from "../currency-button/currency-button.js";
8
- import { faXmark as oe } from "@fortawesome/free-solid-svg-icons";
9
- import { FaIcon as ie } from "../icons/fa-icon.js";
10
- import { useIntlTyped as le, FormattedMessageTyped as B } from "../typed-intl/index.js";
11
- import { useIsMobile as ce, useIsTablet as de, useIsDesktop as ue } from "../../hooks/use-media-query.js";
7
+ import { CurrencyButton as me } from "../currency-button/currency-button.js";
8
+ import { HealthFactor as fe } from "../health-factor/health-factor.js";
9
+ import { faXmark as pe } from "@fortawesome/free-solid-svg-icons";
10
+ import { FaIcon as he } from "../icons/fa-icon.js";
11
+ import { Slider as ge } from "../slider/slider.js";
12
+ import "../slider/slider-context.js";
13
+ import { useIntlTyped as xe, FormattedMessageTyped as B } from "../typed-intl/index.js";
14
+ import { useIsMobile as be, useIsTablet as ve, useIsDesktop as we } from "../../hooks/use-media-query.js";
12
15
  import { smartNumberInputTestIds as w } from "../../test-ids/smart-number-input.js";
13
- import { bnToInputView as me } from "../../utils/bn-to-input-view.js";
16
+ import { bnToInputView as ye } from "../../utils/bn-to-input-view.js";
14
17
  import "@gearbox-protocol/sdk";
15
- import { parseInputToBN as fe } from "../../utils/parse-input-to-bn.js";
16
- import { cn as v } from "../../utils/cn.js";
18
+ import { parseInputToBN as Ne } from "../../utils/parse-input-to-bn.js";
19
+ import { cn as y } from "../../utils/cn.js";
17
20
  import "sonner";
18
21
  import "@gearbox-protocol/sdk/common-utils";
19
22
  import "luxon";
20
23
  import "../../utils/z-index.js";
21
- import { BalanceIndicator as pe } from "./balance-indicator.js";
22
- const he = I(
24
+ import { BalanceIndicator as Ie } from "./balance-indicator.js";
25
+ const Ce = k(
23
26
  "relative w-full text-foreground bg-gray-20 border border-gray-30 transition-[background-color] duration-100 ease-linear [&:hover]:bg-gray-30 [&:hover]:border-gray-40 data-[active=true]:bg-gray-30 data-[active=true]:outline data-[active=true]:outline-2 data-[active=true]:outline-primary data-[active=true]:outline-offset-[-2px] data-[disabled=true]:cursor-not-allowed",
24
27
  {
25
28
  variants: {
@@ -30,7 +33,7 @@ const he = I(
30
33
  },
31
34
  defaultVariants: { size: "md" }
32
35
  }
33
- ), ge = I("font-medium text-foreground", {
36
+ ), ke = k("font-medium text-foreground", {
34
37
  variants: {
35
38
  size: {
36
39
  sm: "text-xs",
@@ -38,7 +41,7 @@ const he = I(
38
41
  }
39
42
  },
40
43
  defaultVariants: { size: "md" }
41
- }), xe = I(
44
+ }), Me = k(
42
45
  "w-full p-0 bg-transparent border-none outline-none text-foreground placeholder:text-secondary-foreground focus:outline-none",
43
46
  {
44
47
  variants: {
@@ -50,90 +53,98 @@ const he = I(
50
53
  defaultVariants: { size: "md" }
51
54
  }
52
55
  );
53
- function be(p, s) {
54
- const u = parseFloat(p.replace(",", ".") || "0");
55
- if (!Number.isFinite(u) || u === 0) return "$0";
56
- const a = u * s, g = Math.abs(a) < 100;
56
+ function C(a) {
57
+ return Math.round(a * 100);
58
+ }
59
+ function ze(a) {
60
+ return a / 100;
61
+ }
62
+ function Fe(a, r) {
63
+ if (!r) return null;
64
+ const f = parseFloat(a.replace(",", ".") || "0");
65
+ if (!Number.isFinite(f) || f === 0) return null;
66
+ const o = f * r, x = Math.abs(o) < 100;
57
67
  try {
58
68
  return new Intl.NumberFormat("en-US", {
59
69
  style: "currency",
60
70
  currency: "USD",
61
- minimumFractionDigits: g ? 2 : 0,
62
- maximumFractionDigits: g ? 2 : 0
63
- }).format(a);
71
+ minimumFractionDigits: x ? 2 : 0,
72
+ maximumFractionDigits: x ? 2 : 0
73
+ }).format(o);
64
74
  } catch {
65
75
  return "$0";
66
76
  }
67
77
  }
68
- const we = n.forwardRef(
78
+ const Le = s.forwardRef(
69
79
  ({
70
- amount: p,
71
- token: s,
72
- label: u,
73
- maxAmount: a,
74
- maxAmountLimit: h,
75
- maxButtonLabel: g,
76
- chainId: T,
77
- network: V,
78
- maxButton: S = !0,
79
- disabled: c = !1,
80
- active: E = !1,
81
- size: R = "md",
82
- symbolMaxLength: D,
83
- tokenOptions: y,
84
- multiSelectMode: j = !1,
85
- onSetAmount: m,
86
- onShowSelectDialog: C,
80
+ amount: a,
81
+ token: r,
82
+ label: f,
83
+ maxAmount: o,
84
+ maxAmountLimit: g,
85
+ maxButtonLabel: x,
86
+ chainId: S,
87
+ network: E,
88
+ maxButton: R = !0,
89
+ disabled: u = !1,
90
+ active: D = !1,
91
+ size: j = "md",
92
+ symbolMaxLength: $,
93
+ tokenOptions: N,
94
+ multiSelectMode: H = !1,
95
+ onSetAmount: p,
96
+ onShowSelectDialog: M,
87
97
  onRemove: z,
88
- onFocus: $,
89
- onBlur: U,
90
- usdPrice: k
91
- }, W) => {
92
- const { formatMessage: O } = le(), P = n.useId(), L = s?.decimals ?? 18, X = (e) => {
93
- const r = e.target.value, [o, i] = fe(r, L);
94
- o === null || i === null || m && m(o, i);
95
- }, q = () => {
96
- if (m) {
97
- const e = a && h && a > h ? h : a || 0n, r = me(e, L);
98
- m(e, r);
98
+ onFocus: U,
99
+ onBlur: W,
100
+ usdPrice: F,
101
+ hfSlider: c
102
+ }, O) => {
103
+ const { formatMessage: P } = xe(), X = s.useId(), L = r?.decimals ?? 18, q = (e) => {
104
+ const n = e.target.value, [i, d] = Ne(n, L);
105
+ i === null || d === null || p && p(i, d);
106
+ }, G = () => {
107
+ if (p) {
108
+ const e = o && g && o > g ? g : o || 0n, n = ye(e, L);
109
+ p(e, n);
99
110
  }
100
- }, [G, M] = n.useState(!1), H = () => {
101
- M(!0), $?.();
102
- }, J = () => {
103
- M(!1), U?.();
104
- }, f = R ?? "md", K = ce(), Q = de(), Y = ue(), Z = D ?? (K ? 20 : Q ? 30 : Y ? 22 : 30), [d, N] = n.useState(!1), x = n.useRef(null), F = n.useRef(null), [_, A] = n.useState({});
105
- n.useLayoutEffect(() => {
106
- if (!d || !x.current) return;
111
+ }, [J, T] = s.useState(!1), K = () => {
112
+ T(!0), U?.();
113
+ }, Q = () => {
114
+ T(!1), W?.();
115
+ }, Y = be(), Z = c?.min ?? 1, _ = c?.max ?? 3, A = c?.step ?? 0.01, ee = Math.max(1, Math.round(1 / A)), h = j ?? "md", te = Y, ne = ve(), re = we(), se = $ ?? (te ? 20 : ne ? 30 : re ? 22 : 30), [m, I] = s.useState(!1), b = s.useRef(null), V = s.useRef(null), [ae, oe] = s.useState({});
116
+ s.useLayoutEffect(() => {
117
+ if (!m || !b.current) return;
107
118
  const e = () => {
108
- const r = x.current?.getBoundingClientRect();
109
- r && A({
119
+ const n = b.current?.getBoundingClientRect();
120
+ n && oe({
110
121
  position: "fixed",
111
- top: r.bottom + 4,
112
- right: window.innerWidth - r.right,
113
- minWidth: r.width,
122
+ top: n.bottom + 4,
123
+ right: window.innerWidth - n.right,
124
+ minWidth: n.width,
114
125
  zIndex: 9999
115
126
  });
116
127
  };
117
128
  return e(), window.addEventListener("scroll", e, !0), window.addEventListener("resize", e), () => {
118
129
  window.removeEventListener("scroll", e, !0), window.removeEventListener("resize", e);
119
130
  };
120
- }, [d]), n.useEffect(() => {
121
- if (!d) return;
122
- const e = (r) => {
123
- const o = r.target, i = x.current?.contains(o), re = F.current?.contains(o);
124
- !i && !re && N(!1);
131
+ }, [m]), s.useEffect(() => {
132
+ if (!m) return;
133
+ const e = (n) => {
134
+ const i = n.target, d = b.current?.contains(i), ce = V.current?.contains(i);
135
+ !d && !ce && I(!1);
125
136
  };
126
137
  return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
127
- }, [d]);
128
- const b = !!(y && y.length > 0), ee = !c && b ? () => N((e) => !e) : C, te = !!(s || C || b);
138
+ }, [m]);
139
+ const v = !!(N && N.length > 0), ie = !u && v ? () => I((e) => !e) : M, le = !!(r || M || v);
129
140
  return /* @__PURE__ */ l(
130
141
  "div",
131
142
  {
132
- ref: W,
133
- className: he({ size: f }),
143
+ ref: O,
144
+ className: Ce({ size: h }),
134
145
  "data-testid": w.root,
135
- "data-active": G,
136
- "data-disabled": c,
146
+ "data-active": J,
147
+ "data-disabled": u,
137
148
  children: [
138
149
  z && /* @__PURE__ */ t(
139
150
  "div",
@@ -146,7 +157,7 @@ const we = n.forwardRef(
146
157
  type: "button",
147
158
  onClick: z,
148
159
  className: "flex h-5 w-5 items-center justify-center rounded-full bg-muted hover:bg-muted/80 text-muted-foreground",
149
- children: /* @__PURE__ */ t(ie, { icon: oe, className: "size-3" })
160
+ children: /* @__PURE__ */ t(he, { icon: pe, className: "size-3" })
150
161
  }
151
162
  )
152
163
  }
@@ -155,31 +166,54 @@ const we = n.forwardRef(
155
166
  /* @__PURE__ */ t(
156
167
  "span",
157
168
  {
158
- className: v(
159
- ge({ size: f }),
169
+ className: y(
170
+ ke({ size: h }),
160
171
  "grow shrink-0 basis-0"
161
172
  ),
162
173
  "data-testid": w.label,
163
- children: u ?? /* @__PURE__ */ t(B, { messageId: "components.smartNumberInput.amountLabel" })
174
+ children: f ?? /* @__PURE__ */ t(B, { messageId: "components.smartNumberInput.amountLabel" })
164
175
  }
165
176
  ),
166
- a !== void 0 && s && /* @__PURE__ */ t(
167
- pe,
177
+ c !== void 0 ? /* @__PURE__ */ l("div", { className: "ml-auto flex w-1/2 min-w-0 items-center gap-1", children: [
178
+ /* @__PURE__ */ t("span", { className: "shrink-0 text-xs text-secondary-foreground", children: "HF" }),
179
+ /* @__PURE__ */ t("div", { className: "min-w-0 flex-1 [&>div]:px-0 [&>div]:pb-0", children: /* @__PURE__ */ t(
180
+ ge,
181
+ {
182
+ from: C(Z),
183
+ to: C(_),
184
+ value: C(c.value),
185
+ precision: ee,
186
+ markerStep: 0,
187
+ epsilon: 0,
188
+ onChangeValue: (e) => c.onChange(ze(e))
189
+ }
190
+ ) }),
191
+ /* @__PURE__ */ t(
192
+ fe,
193
+ {
194
+ value: Math.round(c.value * 1e4),
195
+ debt: 1n,
196
+ decimals: 2,
197
+ className: "shrink-0 text-xs tabular-nums"
198
+ }
199
+ )
200
+ ] }) : o !== void 0 && r && /* @__PURE__ */ t(
201
+ Ie,
168
202
  {
169
- title: g,
170
- token: s,
171
- maxAmount: a,
172
- size: f,
173
- disabled: c,
174
- maxButton: S,
175
- onMaxButtonClick: q
203
+ title: x,
204
+ token: r,
205
+ maxAmount: o,
206
+ size: h,
207
+ disabled: u,
208
+ maxButton: R,
209
+ onMaxButtonClick: G
176
210
  }
177
211
  )
178
212
  ] }),
179
213
  /* @__PURE__ */ l(
180
214
  "div",
181
215
  {
182
- className: v(
216
+ className: y(
183
217
  "flex w-full max-w-full shrink-0 basis-full items-center"
184
218
  ),
185
219
  children: [
@@ -193,56 +227,56 @@ const we = n.forwardRef(
193
227
  spellCheck: "false",
194
228
  pattern: "^[0-9]*[.,]?[0-9]*$",
195
229
  placeholder: "0",
196
- value: p,
197
- onChange: X,
198
- onFocus: H,
199
- onBlur: J,
200
- disabled: c || !m,
201
- className: v(
202
- xe({ size: f }),
203
- c && "cursor-not-allowed"
230
+ value: a,
231
+ onChange: q,
232
+ onFocus: K,
233
+ onBlur: Q,
234
+ disabled: u || !p,
235
+ className: y(
236
+ Me({ size: h }),
237
+ u && "cursor-not-allowed"
204
238
  ),
205
239
  "data-testid": w.input,
206
240
  minLength: 1,
207
241
  maxLength: 79,
208
- title: O({
242
+ title: P({
209
243
  messageId: "components.smartNumberInput.inputTitle"
210
244
  })
211
245
  }
212
246
  ) }),
213
- te ? /* @__PURE__ */ l("div", { ref: x, className: "shrink-0", children: [
247
+ le ? /* @__PURE__ */ l("div", { ref: b, className: "shrink-0", children: [
214
248
  /* @__PURE__ */ t(
215
- ae,
249
+ me,
216
250
  {
217
- active: b ? d : E,
218
- size: f,
219
- disabled: c,
220
- token: s,
221
- showSelectDialog: ee,
222
- chainId: T,
223
- network: V,
224
- maxLength: Z,
225
- children: s?.symbol ?? /* @__PURE__ */ t(B, { messageId: "components.smartNumberInput.selectToken" })
251
+ active: v ? m : D,
252
+ size: h,
253
+ disabled: u,
254
+ token: r,
255
+ showSelectDialog: ie,
256
+ chainId: S,
257
+ network: E,
258
+ maxLength: se,
259
+ children: r?.symbol ?? /* @__PURE__ */ t(B, { messageId: "components.smartNumberInput.selectToken" })
226
260
  }
227
261
  ),
228
- b && d && ne(
262
+ v && m && de(
229
263
  /* @__PURE__ */ t(
230
264
  "div",
231
265
  {
232
- ref: F,
233
- style: _,
266
+ ref: V,
267
+ style: ae,
234
268
  className: "overflow-hidden rounded-lg border border-gray-30 bg-gray-20 shadow-lg",
235
- children: y?.map((e, r) => {
236
- const o = `${P}-${r}`, i = "flex w-full min-w-0 items-center gap-2 px-3 py-2 text-sm text-foreground hover:bg-gray-30";
237
- return j ? /* @__PURE__ */ l(
269
+ children: N?.map((e, n) => {
270
+ const i = `${X}-${n}`, d = "flex w-full min-w-0 items-center gap-2 px-3 py-2 text-sm text-foreground hover:bg-gray-30";
271
+ return H ? /* @__PURE__ */ l(
238
272
  "div",
239
273
  {
240
- className: i,
274
+ className: d,
241
275
  children: [
242
276
  /* @__PURE__ */ t(
243
- se,
277
+ ue,
244
278
  {
245
- id: o,
279
+ id: i,
246
280
  checked: !!e.checked,
247
281
  color: "secondary",
248
282
  size: "md",
@@ -253,7 +287,7 @@ const we = n.forwardRef(
253
287
  /* @__PURE__ */ l(
254
288
  "label",
255
289
  {
256
- htmlFor: o,
290
+ htmlFor: i,
257
291
  className: "flex min-w-0 flex-1 cursor-pointer items-center gap-2 text-left",
258
292
  children: [
259
293
  e.icon ? /* @__PURE__ */ t("span", { className: "inline-flex shrink-0 items-center", children: e.icon }) : null,
@@ -263,21 +297,21 @@ const we = n.forwardRef(
263
297
  )
264
298
  ]
265
299
  },
266
- r
300
+ n
267
301
  ) : /* @__PURE__ */ l(
268
302
  "button",
269
303
  {
270
304
  type: "button",
271
305
  onClick: () => {
272
- e.onSelect(), N(!1);
306
+ e.onSelect(), I(!1);
273
307
  },
274
- className: v(i, "text-left"),
308
+ className: y(d, "text-left"),
275
309
  children: [
276
310
  e.icon ? /* @__PURE__ */ t("span", { className: "inline-flex shrink-0 items-center", children: e.icon }) : null,
277
311
  /* @__PURE__ */ t("span", { className: "truncate", children: e.label })
278
312
  ]
279
313
  },
280
- r
314
+ n
281
315
  );
282
316
  })
283
317
  }
@@ -288,13 +322,16 @@ const we = n.forwardRef(
288
322
  ]
289
323
  }
290
324
  ),
291
- k !== void 0 && /* @__PURE__ */ t("div", { className: "mt-1 text-xs leading-[130%] text-secondary-foreground", children: be(p, k) })
325
+ F !== void 0 && (() => {
326
+ const e = Fe(a, F);
327
+ return e ? /* @__PURE__ */ t("div", { className: "mt-1 text-xs leading-[130%] text-secondary-foreground", children: e }) : null;
328
+ })()
292
329
  ]
293
330
  }
294
331
  );
295
332
  }
296
333
  );
297
- we.displayName = "SmartNumberInput";
334
+ Le.displayName = "SmartNumberInput";
298
335
  export {
299
- we as SmartNumberInput
336
+ Le as SmartNumberInput
300
337
  };