@0xsquid/ui 0.23.2 → 0.23.3-beta.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/cjs/index.js
CHANGED
|
@@ -18192,7 +18192,7 @@ function SwapConfiguration({ amount, tokenPrice = 0, isFetching: isFetchingProp
|
|
|
18192
18192
|
? walletButton === null || walletButton === void 0 ? void 0 : walletButton.address
|
|
18193
18193
|
: (_a = walletButton === null || walletButton === void 0 ? void 0 : walletButton.emptyAddressLabel) !== null && _a !== void 0 ? _a : 'Connect wallet' }), jsxRuntime.jsx(ChevronArrowIcon, { className: (walletButton === null || walletButton === void 0 ? void 0 : walletButton.address)
|
|
18194
18194
|
? 'tw-text-grey-600'
|
|
18195
|
-
: 'tw-text-royal-400' })] })] }))] }) })) }), jsxRuntime.jsx("div", { className: "tw-px-squid-m mobile-lg:tw-px-squid-l", children: jsxRuntime.jsx(AssetsButton, Object.assign({}, assetsButton, { chain: chain, token: token, isLoading: isLoading })) }), isFetching && (jsxRuntime.jsx("div", { className: "tw-absolute tw-bottom-2 tw-left-squid-m tw-z-10 tw-overflow-hidden mobile-lg:tw-left-squid-l", children: jsxRuntime.jsx("div", { className: "tw-h-[94px] tw-w-[1260px] tw-animate-move-loading-cover-to-right tw-bg-dark-cover" }) })), jsxRuntime.jsx(NumericInput, { token: {
|
|
18195
|
+
: 'tw-text-royal-400' })] })] }))] }) })) }), jsxRuntime.jsx("div", { className: "tw-px-squid-m mobile-lg:tw-px-squid-l", children: jsxRuntime.jsx(AssetsButton, Object.assign({}, assetsButton, { chain: chain, token: token, isLoading: isLoading })) }), isFetching && (jsxRuntime.jsx("div", { className: "tw-absolute tw-bottom-2 tw-left-squid-m tw-z-10 tw-overflow-hidden mobile-lg:tw-left-squid-l", children: jsxRuntime.jsx("div", { className: "tw-h-[94px] tw-w-[1260px] tw-animate-move-loading-cover-to-right tw-bg-dark-cover" }) })), jsxRuntime.jsx(NumericInput, { inputMode: "decimal", pattern: "[0-9.,]*", token: {
|
|
18196
18196
|
decimals: (_b = token === null || token === void 0 ? void 0 : token.decimals) !== null && _b !== void 0 ? _b : 18,
|
|
18197
18197
|
symbol: (_c = token === null || token === void 0 ? void 0 : token.symbol) !== null && _c !== void 0 ? _c : '',
|
|
18198
18198
|
price: tokenPrice,
|
|
@@ -25576,18 +25576,19 @@ const RegExpNonZeroValue = /[^0.]/;
|
|
|
25576
25576
|
const interactiveChipClassName = 'hover:tw-bg-material-light-thin';
|
|
25577
25577
|
const notInteractiveChipClassName = 'tw-cursor-not-allowed';
|
|
25578
25578
|
const loadingClassName = 'tw-opacity-50';
|
|
25579
|
-
var
|
|
25580
|
-
(function (
|
|
25581
|
-
|
|
25582
|
-
|
|
25583
|
-
})(
|
|
25584
|
-
function NumericInput(
|
|
25585
|
-
|
|
25586
|
-
|
|
25587
|
-
|
|
25588
|
-
|
|
25579
|
+
var UserInputType;
|
|
25580
|
+
(function (UserInputType) {
|
|
25581
|
+
UserInputType[UserInputType["TOKEN"] = 0] = "TOKEN";
|
|
25582
|
+
UserInputType[UserInputType["USD"] = 1] = "USD";
|
|
25583
|
+
})(UserInputType || (UserInputType = {}));
|
|
25584
|
+
function NumericInput(_a) {
|
|
25585
|
+
var _b;
|
|
25586
|
+
var { priceImpactPercentage, balance = '0', error, criticalPriceImpactPercentage = 5, token, onAmountChange, forcedAmount, maxUsdDecimals = 4, formatIfVerySmall = {
|
|
25587
|
+
token: '0.001',
|
|
25588
|
+
usd: '0.01',
|
|
25589
|
+
}, showDetails = true, isLoading = false, direction, inputModeButton, isInteractive = false, balanceButton } = _a, props = __rest$1(_a, ["priceImpactPercentage", "balance", "error", "criticalPriceImpactPercentage", "token", "onAmountChange", "forcedAmount", "maxUsdDecimals", "formatIfVerySmall", "showDetails", "isLoading", "direction", "inputModeButton", "isInteractive", "balanceButton"]);
|
|
25589
25590
|
const [inputValue, setInputValue] = React$1.useState('');
|
|
25590
|
-
const [
|
|
25591
|
+
const [userInputType, setUserInputType] = React$1.useState(UserInputType.TOKEN);
|
|
25591
25592
|
const balanceChipClickable = isInteractive && parseFloat(balance) > 0;
|
|
25592
25593
|
React$1.useEffect(() => {
|
|
25593
25594
|
if (forcedAmount !== undefined) {
|
|
@@ -25596,11 +25597,11 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
25596
25597
|
}, [forcedAmount]);
|
|
25597
25598
|
const updateInputValue = React$1.useCallback((newValue) => {
|
|
25598
25599
|
const safeNewValue = trimExtraDecimals(newValue, token.decimals);
|
|
25599
|
-
const formattedAmount =
|
|
25600
|
+
const formattedAmount = userInputType === UserInputType.TOKEN
|
|
25600
25601
|
? safeNewValue
|
|
25601
25602
|
: convertTokenAmountToUSD(safeNewValue, token.price, maxUsdDecimals);
|
|
25602
25603
|
setInputValue(formattedAmount);
|
|
25603
|
-
}, [
|
|
25604
|
+
}, [userInputType, token.price, direction, token.decimals]);
|
|
25604
25605
|
const onBalanceButtonClick = React$1.useCallback(() => {
|
|
25605
25606
|
if (balanceChipClickable) {
|
|
25606
25607
|
updateInputValue(balance);
|
|
@@ -25612,7 +25613,7 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
25612
25613
|
]);
|
|
25613
25614
|
const handleInputChange = (e) => {
|
|
25614
25615
|
let value = e.target.value.replace(/,/g, '.'); // Replace commas with dots
|
|
25615
|
-
const maxDecimalsForInputType =
|
|
25616
|
+
const maxDecimalsForInputType = userInputType === UserInputType.TOKEN ? token.decimals : maxUsdDecimals;
|
|
25616
25617
|
const isValidAmount = new RegExp(`^\\d*\\.?\\d{0,${maxDecimalsForInputType}}$`).test(value);
|
|
25617
25618
|
if (isValidAmount) {
|
|
25618
25619
|
setInputValue(value);
|
|
@@ -25631,12 +25632,14 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
25631
25632
|
const handleSwitchInputMode = () => {
|
|
25632
25633
|
var _a;
|
|
25633
25634
|
if (inputValue !== '') {
|
|
25634
|
-
const convertedAmount =
|
|
25635
|
+
const convertedAmount = userInputType === UserInputType.TOKEN
|
|
25635
25636
|
? convertTokenAmountToUSD(inputValue, token.price, maxUsdDecimals)
|
|
25636
25637
|
: convertUSDToTokenAmount(inputValue, token.price, token.decimals);
|
|
25637
25638
|
setInputValue(convertedAmount);
|
|
25638
25639
|
}
|
|
25639
|
-
|
|
25640
|
+
setUserInputType((prevMode) => prevMode === UserInputType.TOKEN
|
|
25641
|
+
? UserInputType.USD
|
|
25642
|
+
: UserInputType.TOKEN);
|
|
25640
25643
|
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
25641
25644
|
};
|
|
25642
25645
|
const getRawAmounts = (amount) => {
|
|
@@ -25647,7 +25650,7 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
25647
25650
|
isTokenAmountVerySmall: false,
|
|
25648
25651
|
isUsdAmountVerySmall: false,
|
|
25649
25652
|
};
|
|
25650
|
-
if (
|
|
25653
|
+
if (userInputType === UserInputType.TOKEN) {
|
|
25651
25654
|
const usdRawAmount = convertTokenAmountToUSD(amount, token.price, maxUsdDecimals);
|
|
25652
25655
|
const tokenRawAmount = amount;
|
|
25653
25656
|
const isTokenAmountVerySmall = !!tokenRawAmount &&
|
|
@@ -25687,7 +25690,7 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
25687
25690
|
var _a;
|
|
25688
25691
|
if (isNaN(Number(inputValue)) || inputValue === '')
|
|
25689
25692
|
return '0';
|
|
25690
|
-
if (
|
|
25693
|
+
if (userInputType === UserInputType.TOKEN) {
|
|
25691
25694
|
if (direction === 'from') {
|
|
25692
25695
|
return formatAmount(convertTokenAmountToUSD(inputValue, token.price, maxUsdDecimals));
|
|
25693
25696
|
}
|
|
@@ -25700,13 +25703,13 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
25700
25703
|
}
|
|
25701
25704
|
}, [
|
|
25702
25705
|
inputValue,
|
|
25703
|
-
|
|
25706
|
+
userInputType,
|
|
25704
25707
|
token.price,
|
|
25705
25708
|
direction,
|
|
25706
25709
|
inputModeButton === null || inputModeButton === void 0 ? void 0 : inputModeButton.amountUsd,
|
|
25707
25710
|
]);
|
|
25708
25711
|
const AmountChip = isInteractive ? 'button' : 'div';
|
|
25709
|
-
const priceImpactClass = ((
|
|
25712
|
+
const priceImpactClass = ((_b = Number(priceImpactPercentage)) !== null && _b !== void 0 ? _b : 0) > Number(criticalPriceImpactPercentage)
|
|
25710
25713
|
? 'tw-text-status-negative'
|
|
25711
25714
|
: 'tw-text-grey-300';
|
|
25712
25715
|
const BalanceChipTag = balanceChipClickable ? 'button' : 'div';
|
|
@@ -25717,13 +25720,13 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
25717
25720
|
const inputRef = React$1.useRef(null);
|
|
25718
25721
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [isInteractive && !isLoading ? (jsxRuntime.jsxs("form", { className: containerClassname, onSubmit: (e) => {
|
|
25719
25722
|
e.preventDefault();
|
|
25720
|
-
}, children: [
|
|
25723
|
+
}, children: [userInputType === UserInputType.USD && (jsxRuntime.jsx("span", { className: "tw-absolute tw-left-5 tw-top-[11px] tw-leading-[43px] tw-text-grey-600 mobile-lg:tw-left-[30px]", children: "$" })), jsxRuntime.jsx("input", Object.assign({ ref: inputRef, type: "text", value: inputValue, onChange: handleInputChange, placeholder: "0", className: cn('tw-h-[55px] tw-w-full tw-rounded-squid-s tw-bg-transparent tw-px-squid-xs tw-py-squid-s tw-text-grey-300 placeholder:tw-text-grey-600 hover:tw-bg-material-light-thin focus:tw-bg-material-light-thin focus:tw-text-royal-400 focus:tw-outline-none', userInputType === UserInputType.USD && 'tw-pl-[33px]') }, props))] })) : (jsxRuntime.jsx("div", { className: cn(containerClassname, (isLoading || Number(inputValue || 0) === 0) && loadingClassName), children: jsxRuntime.jsx("div", { className: "tw-flex tw-h-[55px] tw-w-full tw-items-center tw-rounded-squid-s tw-bg-transparent tw-px-squid-xs tw-py-squid-s tw-text-heading-small tw-font-heading-regular tw-text-grey-300 mobile-sm-height:tw-h-[65px]", children: jsxRuntime.jsx("span", { children: inputValue || 0 }) }) })), !showDetails ? null : (jsxRuntime.jsxs("footer", { className: cn('tw-flex tw-h-squid-m tw-max-h-squid-m tw-items-center tw-justify-between tw-gap-2 tw-px-squid-xs tw-text-grey-500 mobile-lg:tw-px-squid-m', isLoading && loadingClassName), children: [error ? (jsxRuntime.jsx("div", { className: "tw-px-squid-xs", children: jsxRuntime.jsx(ErrorMessage, { message: error.message }) })) : (jsxRuntime.jsx(Tooltip, Object.assign({}, (isLoading
|
|
25721
25724
|
? undefined
|
|
25722
|
-
:
|
|
25725
|
+
: userInputType === UserInputType.TOKEN
|
|
25723
25726
|
? inputModeButton === null || inputModeButton === void 0 ? void 0 : inputModeButton.tokenModeTooltip
|
|
25724
25727
|
: inputModeButton === null || inputModeButton === void 0 ? void 0 : inputModeButton.usdModeTooltip), { tooltipWidth: "max", childrenClassName: "tw-rounded-squid-s", containerClassName: "tw-rounded-squid-s", children: jsxRuntime.jsxs(AmountChip, { onClick: isInteractive ? handleSwitchInputMode : undefined, className: cn(buttonClassName, isInteractive
|
|
25725
25728
|
? interactiveChipClassName
|
|
25726
|
-
: notInteractiveChipClassName), children: [jsxRuntime.jsx(SwapInputsIcon, {}),
|
|
25729
|
+
: notInteractiveChipClassName), children: [jsxRuntime.jsx(SwapInputsIcon, {}), userInputType === UserInputType.TOKEN ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs("span", { className: "tw-flex tw-items-center tw-text-grey-500", children: [jsxRuntime.jsxs(CaptionText, { className: "tw-opacity-66", children: [isUsdAmountVerySmall ? '<' : '', "$"] }), jsxRuntime.jsx(CaptionText, { children: isUsdAmountVerySmall
|
|
25727
25730
|
? formatIfVerySmall.token
|
|
25728
25731
|
: amountFormatted })] }) })) : (jsxRuntime.jsxs("span", { className: "tw-text-grey-500", children: [isTokenAmountVerySmall ? '<' : '', jsxRuntime.jsx(CaptionText, { children: isTokenAmountVerySmall
|
|
25729
25732
|
? formatIfVerySmall.token
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { SwapDirection } from '../../types/components';
|
|
2
3
|
import { TooltipProps } from './Tooltip';
|
|
3
4
|
interface Token {
|
|
@@ -5,7 +6,7 @@ interface Token {
|
|
|
5
6
|
symbol: string;
|
|
6
7
|
decimals: number;
|
|
7
8
|
}
|
|
8
|
-
interface NumericInputProps {
|
|
9
|
+
interface NumericInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
9
10
|
token: Token;
|
|
10
11
|
onAmountChange: (tokenAmount: string) => void;
|
|
11
12
|
forcedAmount?: string;
|
|
@@ -33,5 +34,5 @@ interface NumericInputProps {
|
|
|
33
34
|
tooltip?: Omit<TooltipProps, 'children'>;
|
|
34
35
|
};
|
|
35
36
|
}
|
|
36
|
-
export declare function NumericInput({ priceImpactPercentage, balance, error, criticalPriceImpactPercentage, token, onAmountChange, forcedAmount, maxUsdDecimals, formatIfVerySmall, showDetails, isLoading, direction, inputModeButton, isInteractive, balanceButton, }: NumericInputProps): import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
export declare function NumericInput({ priceImpactPercentage, balance, error, criticalPriceImpactPercentage, token, onAmountChange, forcedAmount, maxUsdDecimals, formatIfVerySmall, showDetails, isLoading, direction, inputModeButton, isInteractive, balanceButton, ...props }: NumericInputProps): import("react/jsx-runtime").JSX.Element;
|
|
37
38
|
export {};
|
package/dist/esm/index.js
CHANGED
|
@@ -18172,7 +18172,7 @@ function SwapConfiguration({ amount, tokenPrice = 0, isFetching: isFetchingProp
|
|
|
18172
18172
|
? walletButton === null || walletButton === void 0 ? void 0 : walletButton.address
|
|
18173
18173
|
: (_a = walletButton === null || walletButton === void 0 ? void 0 : walletButton.emptyAddressLabel) !== null && _a !== void 0 ? _a : 'Connect wallet' }), jsx(ChevronArrowIcon, { className: (walletButton === null || walletButton === void 0 ? void 0 : walletButton.address)
|
|
18174
18174
|
? 'tw-text-grey-600'
|
|
18175
|
-
: 'tw-text-royal-400' })] })] }))] }) })) }), jsx("div", { className: "tw-px-squid-m mobile-lg:tw-px-squid-l", children: jsx(AssetsButton, Object.assign({}, assetsButton, { chain: chain, token: token, isLoading: isLoading })) }), isFetching && (jsx("div", { className: "tw-absolute tw-bottom-2 tw-left-squid-m tw-z-10 tw-overflow-hidden mobile-lg:tw-left-squid-l", children: jsx("div", { className: "tw-h-[94px] tw-w-[1260px] tw-animate-move-loading-cover-to-right tw-bg-dark-cover" }) })), jsx(NumericInput, { token: {
|
|
18175
|
+
: 'tw-text-royal-400' })] })] }))] }) })) }), jsx("div", { className: "tw-px-squid-m mobile-lg:tw-px-squid-l", children: jsx(AssetsButton, Object.assign({}, assetsButton, { chain: chain, token: token, isLoading: isLoading })) }), isFetching && (jsx("div", { className: "tw-absolute tw-bottom-2 tw-left-squid-m tw-z-10 tw-overflow-hidden mobile-lg:tw-left-squid-l", children: jsx("div", { className: "tw-h-[94px] tw-w-[1260px] tw-animate-move-loading-cover-to-right tw-bg-dark-cover" }) })), jsx(NumericInput, { inputMode: "decimal", pattern: "[0-9.,]*", token: {
|
|
18176
18176
|
decimals: (_b = token === null || token === void 0 ? void 0 : token.decimals) !== null && _b !== void 0 ? _b : 18,
|
|
18177
18177
|
symbol: (_c = token === null || token === void 0 ? void 0 : token.symbol) !== null && _c !== void 0 ? _c : '',
|
|
18178
18178
|
price: tokenPrice,
|
|
@@ -25556,18 +25556,19 @@ const RegExpNonZeroValue = /[^0.]/;
|
|
|
25556
25556
|
const interactiveChipClassName = 'hover:tw-bg-material-light-thin';
|
|
25557
25557
|
const notInteractiveChipClassName = 'tw-cursor-not-allowed';
|
|
25558
25558
|
const loadingClassName = 'tw-opacity-50';
|
|
25559
|
-
var
|
|
25560
|
-
(function (
|
|
25561
|
-
|
|
25562
|
-
|
|
25563
|
-
})(
|
|
25564
|
-
function NumericInput(
|
|
25565
|
-
|
|
25566
|
-
|
|
25567
|
-
|
|
25568
|
-
|
|
25559
|
+
var UserInputType;
|
|
25560
|
+
(function (UserInputType) {
|
|
25561
|
+
UserInputType[UserInputType["TOKEN"] = 0] = "TOKEN";
|
|
25562
|
+
UserInputType[UserInputType["USD"] = 1] = "USD";
|
|
25563
|
+
})(UserInputType || (UserInputType = {}));
|
|
25564
|
+
function NumericInput(_a) {
|
|
25565
|
+
var _b;
|
|
25566
|
+
var { priceImpactPercentage, balance = '0', error, criticalPriceImpactPercentage = 5, token, onAmountChange, forcedAmount, maxUsdDecimals = 4, formatIfVerySmall = {
|
|
25567
|
+
token: '0.001',
|
|
25568
|
+
usd: '0.01',
|
|
25569
|
+
}, showDetails = true, isLoading = false, direction, inputModeButton, isInteractive = false, balanceButton } = _a, props = __rest$1(_a, ["priceImpactPercentage", "balance", "error", "criticalPriceImpactPercentage", "token", "onAmountChange", "forcedAmount", "maxUsdDecimals", "formatIfVerySmall", "showDetails", "isLoading", "direction", "inputModeButton", "isInteractive", "balanceButton"]);
|
|
25569
25570
|
const [inputValue, setInputValue] = useState('');
|
|
25570
|
-
const [
|
|
25571
|
+
const [userInputType, setUserInputType] = useState(UserInputType.TOKEN);
|
|
25571
25572
|
const balanceChipClickable = isInteractive && parseFloat(balance) > 0;
|
|
25572
25573
|
useEffect(() => {
|
|
25573
25574
|
if (forcedAmount !== undefined) {
|
|
@@ -25576,11 +25577,11 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
25576
25577
|
}, [forcedAmount]);
|
|
25577
25578
|
const updateInputValue = useCallback((newValue) => {
|
|
25578
25579
|
const safeNewValue = trimExtraDecimals(newValue, token.decimals);
|
|
25579
|
-
const formattedAmount =
|
|
25580
|
+
const formattedAmount = userInputType === UserInputType.TOKEN
|
|
25580
25581
|
? safeNewValue
|
|
25581
25582
|
: convertTokenAmountToUSD(safeNewValue, token.price, maxUsdDecimals);
|
|
25582
25583
|
setInputValue(formattedAmount);
|
|
25583
|
-
}, [
|
|
25584
|
+
}, [userInputType, token.price, direction, token.decimals]);
|
|
25584
25585
|
const onBalanceButtonClick = useCallback(() => {
|
|
25585
25586
|
if (balanceChipClickable) {
|
|
25586
25587
|
updateInputValue(balance);
|
|
@@ -25592,7 +25593,7 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
25592
25593
|
]);
|
|
25593
25594
|
const handleInputChange = (e) => {
|
|
25594
25595
|
let value = e.target.value.replace(/,/g, '.'); // Replace commas with dots
|
|
25595
|
-
const maxDecimalsForInputType =
|
|
25596
|
+
const maxDecimalsForInputType = userInputType === UserInputType.TOKEN ? token.decimals : maxUsdDecimals;
|
|
25596
25597
|
const isValidAmount = new RegExp(`^\\d*\\.?\\d{0,${maxDecimalsForInputType}}$`).test(value);
|
|
25597
25598
|
if (isValidAmount) {
|
|
25598
25599
|
setInputValue(value);
|
|
@@ -25611,12 +25612,14 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
25611
25612
|
const handleSwitchInputMode = () => {
|
|
25612
25613
|
var _a;
|
|
25613
25614
|
if (inputValue !== '') {
|
|
25614
|
-
const convertedAmount =
|
|
25615
|
+
const convertedAmount = userInputType === UserInputType.TOKEN
|
|
25615
25616
|
? convertTokenAmountToUSD(inputValue, token.price, maxUsdDecimals)
|
|
25616
25617
|
: convertUSDToTokenAmount(inputValue, token.price, token.decimals);
|
|
25617
25618
|
setInputValue(convertedAmount);
|
|
25618
25619
|
}
|
|
25619
|
-
|
|
25620
|
+
setUserInputType((prevMode) => prevMode === UserInputType.TOKEN
|
|
25621
|
+
? UserInputType.USD
|
|
25622
|
+
: UserInputType.TOKEN);
|
|
25620
25623
|
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
25621
25624
|
};
|
|
25622
25625
|
const getRawAmounts = (amount) => {
|
|
@@ -25627,7 +25630,7 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
25627
25630
|
isTokenAmountVerySmall: false,
|
|
25628
25631
|
isUsdAmountVerySmall: false,
|
|
25629
25632
|
};
|
|
25630
|
-
if (
|
|
25633
|
+
if (userInputType === UserInputType.TOKEN) {
|
|
25631
25634
|
const usdRawAmount = convertTokenAmountToUSD(amount, token.price, maxUsdDecimals);
|
|
25632
25635
|
const tokenRawAmount = amount;
|
|
25633
25636
|
const isTokenAmountVerySmall = !!tokenRawAmount &&
|
|
@@ -25667,7 +25670,7 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
25667
25670
|
var _a;
|
|
25668
25671
|
if (isNaN(Number(inputValue)) || inputValue === '')
|
|
25669
25672
|
return '0';
|
|
25670
|
-
if (
|
|
25673
|
+
if (userInputType === UserInputType.TOKEN) {
|
|
25671
25674
|
if (direction === 'from') {
|
|
25672
25675
|
return formatAmount(convertTokenAmountToUSD(inputValue, token.price, maxUsdDecimals));
|
|
25673
25676
|
}
|
|
@@ -25680,13 +25683,13 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
25680
25683
|
}
|
|
25681
25684
|
}, [
|
|
25682
25685
|
inputValue,
|
|
25683
|
-
|
|
25686
|
+
userInputType,
|
|
25684
25687
|
token.price,
|
|
25685
25688
|
direction,
|
|
25686
25689
|
inputModeButton === null || inputModeButton === void 0 ? void 0 : inputModeButton.amountUsd,
|
|
25687
25690
|
]);
|
|
25688
25691
|
const AmountChip = isInteractive ? 'button' : 'div';
|
|
25689
|
-
const priceImpactClass = ((
|
|
25692
|
+
const priceImpactClass = ((_b = Number(priceImpactPercentage)) !== null && _b !== void 0 ? _b : 0) > Number(criticalPriceImpactPercentage)
|
|
25690
25693
|
? 'tw-text-status-negative'
|
|
25691
25694
|
: 'tw-text-grey-300';
|
|
25692
25695
|
const BalanceChipTag = balanceChipClickable ? 'button' : 'div';
|
|
@@ -25697,13 +25700,13 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
25697
25700
|
const inputRef = useRef(null);
|
|
25698
25701
|
return (jsxs(Fragment, { children: [isInteractive && !isLoading ? (jsxs("form", { className: containerClassname, onSubmit: (e) => {
|
|
25699
25702
|
e.preventDefault();
|
|
25700
|
-
}, children: [
|
|
25703
|
+
}, children: [userInputType === UserInputType.USD && (jsx("span", { className: "tw-absolute tw-left-5 tw-top-[11px] tw-leading-[43px] tw-text-grey-600 mobile-lg:tw-left-[30px]", children: "$" })), jsx("input", Object.assign({ ref: inputRef, type: "text", value: inputValue, onChange: handleInputChange, placeholder: "0", className: cn('tw-h-[55px] tw-w-full tw-rounded-squid-s tw-bg-transparent tw-px-squid-xs tw-py-squid-s tw-text-grey-300 placeholder:tw-text-grey-600 hover:tw-bg-material-light-thin focus:tw-bg-material-light-thin focus:tw-text-royal-400 focus:tw-outline-none', userInputType === UserInputType.USD && 'tw-pl-[33px]') }, props))] })) : (jsx("div", { className: cn(containerClassname, (isLoading || Number(inputValue || 0) === 0) && loadingClassName), children: jsx("div", { className: "tw-flex tw-h-[55px] tw-w-full tw-items-center tw-rounded-squid-s tw-bg-transparent tw-px-squid-xs tw-py-squid-s tw-text-heading-small tw-font-heading-regular tw-text-grey-300 mobile-sm-height:tw-h-[65px]", children: jsx("span", { children: inputValue || 0 }) }) })), !showDetails ? null : (jsxs("footer", { className: cn('tw-flex tw-h-squid-m tw-max-h-squid-m tw-items-center tw-justify-between tw-gap-2 tw-px-squid-xs tw-text-grey-500 mobile-lg:tw-px-squid-m', isLoading && loadingClassName), children: [error ? (jsx("div", { className: "tw-px-squid-xs", children: jsx(ErrorMessage, { message: error.message }) })) : (jsx(Tooltip, Object.assign({}, (isLoading
|
|
25701
25704
|
? undefined
|
|
25702
|
-
:
|
|
25705
|
+
: userInputType === UserInputType.TOKEN
|
|
25703
25706
|
? inputModeButton === null || inputModeButton === void 0 ? void 0 : inputModeButton.tokenModeTooltip
|
|
25704
25707
|
: inputModeButton === null || inputModeButton === void 0 ? void 0 : inputModeButton.usdModeTooltip), { tooltipWidth: "max", childrenClassName: "tw-rounded-squid-s", containerClassName: "tw-rounded-squid-s", children: jsxs(AmountChip, { onClick: isInteractive ? handleSwitchInputMode : undefined, className: cn(buttonClassName, isInteractive
|
|
25705
25708
|
? interactiveChipClassName
|
|
25706
|
-
: notInteractiveChipClassName), children: [jsx(SwapInputsIcon, {}),
|
|
25709
|
+
: notInteractiveChipClassName), children: [jsx(SwapInputsIcon, {}), userInputType === UserInputType.TOKEN ? (jsx(Fragment, { children: jsxs("span", { className: "tw-flex tw-items-center tw-text-grey-500", children: [jsxs(CaptionText, { className: "tw-opacity-66", children: [isUsdAmountVerySmall ? '<' : '', "$"] }), jsx(CaptionText, { children: isUsdAmountVerySmall
|
|
25707
25710
|
? formatIfVerySmall.token
|
|
25708
25711
|
: amountFormatted })] }) })) : (jsxs("span", { className: "tw-text-grey-500", children: [isTokenAmountVerySmall ? '<' : '', jsx(CaptionText, { children: isTokenAmountVerySmall
|
|
25709
25712
|
? formatIfVerySmall.token
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { SwapDirection } from '../../types/components';
|
|
2
3
|
import { TooltipProps } from './Tooltip';
|
|
3
4
|
interface Token {
|
|
@@ -5,7 +6,7 @@ interface Token {
|
|
|
5
6
|
symbol: string;
|
|
6
7
|
decimals: number;
|
|
7
8
|
}
|
|
8
|
-
interface NumericInputProps {
|
|
9
|
+
interface NumericInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
9
10
|
token: Token;
|
|
10
11
|
onAmountChange: (tokenAmount: string) => void;
|
|
11
12
|
forcedAmount?: string;
|
|
@@ -33,5 +34,5 @@ interface NumericInputProps {
|
|
|
33
34
|
tooltip?: Omit<TooltipProps, 'children'>;
|
|
34
35
|
};
|
|
35
36
|
}
|
|
36
|
-
export declare function NumericInput({ priceImpactPercentage, balance, error, criticalPriceImpactPercentage, token, onAmountChange, forcedAmount, maxUsdDecimals, formatIfVerySmall, showDetails, isLoading, direction, inputModeButton, isInteractive, balanceButton, }: NumericInputProps): import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
export declare function NumericInput({ priceImpactPercentage, balance, error, criticalPriceImpactPercentage, token, onAmountChange, forcedAmount, maxUsdDecimals, formatIfVerySmall, showDetails, isLoading, direction, inputModeButton, isInteractive, balanceButton, ...props }: NumericInputProps): import("react/jsx-runtime").JSX.Element;
|
|
37
38
|
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -174,7 +174,7 @@ interface Token$1 {
|
|
|
174
174
|
symbol: string;
|
|
175
175
|
decimals: number;
|
|
176
176
|
}
|
|
177
|
-
interface NumericInputProps {
|
|
177
|
+
interface NumericInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
178
178
|
token: Token$1;
|
|
179
179
|
onAmountChange: (tokenAmount: string) => void;
|
|
180
180
|
forcedAmount?: string;
|
|
@@ -202,7 +202,7 @@ interface NumericInputProps {
|
|
|
202
202
|
tooltip?: Omit<TooltipProps, 'children'>;
|
|
203
203
|
};
|
|
204
204
|
}
|
|
205
|
-
declare function NumericInput({ priceImpactPercentage, balance, error, criticalPriceImpactPercentage, token, onAmountChange, forcedAmount, maxUsdDecimals, formatIfVerySmall, showDetails, isLoading, direction, inputModeButton, isInteractive, balanceButton, }: NumericInputProps): react_jsx_runtime.JSX.Element;
|
|
205
|
+
declare function NumericInput({ priceImpactPercentage, balance, error, criticalPriceImpactPercentage, token, onAmountChange, forcedAmount, maxUsdDecimals, formatIfVerySmall, showDetails, isLoading, direction, inputModeButton, isInteractive, balanceButton, ...props }: NumericInputProps): react_jsx_runtime.JSX.Element;
|
|
206
206
|
|
|
207
207
|
interface SettingsSliderProps {
|
|
208
208
|
value: number | undefined;
|