@0xsquid/ui 0.24.1 → 0.25.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
|
@@ -18578,7 +18578,7 @@ function SwapConfiguration({ amount, tokenPrice = 0, isFetching: isFetchingProp
|
|
|
18578
18578
|
? walletButton === null || walletButton === void 0 ? void 0 : walletButton.address
|
|
18579
18579
|
: (_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)
|
|
18580
18580
|
? 'tw-text-grey-600'
|
|
18581
|
-
: '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: {
|
|
18581
|
+
: '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: {
|
|
18582
18582
|
decimals: (_b = token === null || token === void 0 ? void 0 : token.decimals) !== null && _b !== void 0 ? _b : 18,
|
|
18583
18583
|
symbol: (_c = token === null || token === void 0 ? void 0 : token.symbol) !== null && _c !== void 0 ? _c : '',
|
|
18584
18584
|
price: tokenPrice,
|
|
@@ -25968,18 +25968,19 @@ const RegExpNonZeroValue = /[^0.]/;
|
|
|
25968
25968
|
const interactiveChipClassName = 'hover:tw-bg-material-light-thin';
|
|
25969
25969
|
const notInteractiveChipClassName = 'tw-cursor-not-allowed';
|
|
25970
25970
|
const loadingClassName = 'tw-opacity-50';
|
|
25971
|
-
var
|
|
25972
|
-
(function (
|
|
25973
|
-
|
|
25974
|
-
|
|
25975
|
-
})(
|
|
25976
|
-
function NumericInput(
|
|
25977
|
-
|
|
25978
|
-
|
|
25979
|
-
|
|
25980
|
-
|
|
25971
|
+
var UserInputType;
|
|
25972
|
+
(function (UserInputType) {
|
|
25973
|
+
UserInputType[UserInputType["TOKEN"] = 0] = "TOKEN";
|
|
25974
|
+
UserInputType[UserInputType["USD"] = 1] = "USD";
|
|
25975
|
+
})(UserInputType || (UserInputType = {}));
|
|
25976
|
+
function NumericInput(_a) {
|
|
25977
|
+
var _b;
|
|
25978
|
+
var { priceImpactPercentage, balance = '0', error, criticalPriceImpactPercentage = 5, token, onAmountChange, forcedAmount, maxUsdDecimals = 4, formatIfVerySmall = {
|
|
25979
|
+
token: '0.001',
|
|
25980
|
+
usd: '0.01',
|
|
25981
|
+
}, 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"]);
|
|
25981
25982
|
const [inputValue, setInputValue] = React$1.useState('');
|
|
25982
|
-
const [
|
|
25983
|
+
const [userInputType, setUserInputType] = React$1.useState(UserInputType.TOKEN);
|
|
25983
25984
|
const balanceChipClickable = isInteractive && parseFloat(balance) > 0;
|
|
25984
25985
|
React$1.useEffect(() => {
|
|
25985
25986
|
if (forcedAmount !== undefined) {
|
|
@@ -25988,11 +25989,11 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
25988
25989
|
}, [forcedAmount]);
|
|
25989
25990
|
const updateInputValue = React$1.useCallback((newValue) => {
|
|
25990
25991
|
const safeNewValue = trimExtraDecimals(newValue, token.decimals);
|
|
25991
|
-
const formattedAmount =
|
|
25992
|
+
const formattedAmount = userInputType === UserInputType.TOKEN
|
|
25992
25993
|
? safeNewValue
|
|
25993
25994
|
: convertTokenAmountToUSD(safeNewValue, token.price, maxUsdDecimals);
|
|
25994
25995
|
setInputValue(formattedAmount);
|
|
25995
|
-
}, [
|
|
25996
|
+
}, [userInputType, token.price, direction, token.decimals]);
|
|
25996
25997
|
const onBalanceButtonClick = React$1.useCallback(() => {
|
|
25997
25998
|
if (balanceChipClickable) {
|
|
25998
25999
|
updateInputValue(balance);
|
|
@@ -26004,7 +26005,7 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
26004
26005
|
]);
|
|
26005
26006
|
const handleInputChange = (e) => {
|
|
26006
26007
|
let value = e.target.value.replace(/,/g, '.'); // Replace commas with dots
|
|
26007
|
-
const maxDecimalsForInputType =
|
|
26008
|
+
const maxDecimalsForInputType = userInputType === UserInputType.TOKEN ? token.decimals : maxUsdDecimals;
|
|
26008
26009
|
const isValidAmount = new RegExp(`^\\d*\\.?\\d{0,${maxDecimalsForInputType}}$`).test(value);
|
|
26009
26010
|
if (isValidAmount) {
|
|
26010
26011
|
setInputValue(value);
|
|
@@ -26023,12 +26024,14 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
26023
26024
|
const handleSwitchInputMode = () => {
|
|
26024
26025
|
var _a;
|
|
26025
26026
|
if (inputValue !== '') {
|
|
26026
|
-
const convertedAmount =
|
|
26027
|
+
const convertedAmount = userInputType === UserInputType.TOKEN
|
|
26027
26028
|
? convertTokenAmountToUSD(inputValue, token.price, maxUsdDecimals)
|
|
26028
26029
|
: convertUSDToTokenAmount(inputValue, token.price, token.decimals);
|
|
26029
26030
|
setInputValue(convertedAmount);
|
|
26030
26031
|
}
|
|
26031
|
-
|
|
26032
|
+
setUserInputType((prevMode) => prevMode === UserInputType.TOKEN
|
|
26033
|
+
? UserInputType.USD
|
|
26034
|
+
: UserInputType.TOKEN);
|
|
26032
26035
|
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
26033
26036
|
};
|
|
26034
26037
|
const getRawAmounts = (amount) => {
|
|
@@ -26039,7 +26042,7 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
26039
26042
|
isTokenAmountVerySmall: false,
|
|
26040
26043
|
isUsdAmountVerySmall: false,
|
|
26041
26044
|
};
|
|
26042
|
-
if (
|
|
26045
|
+
if (userInputType === UserInputType.TOKEN) {
|
|
26043
26046
|
const usdRawAmount = convertTokenAmountToUSD(amount, token.price, maxUsdDecimals);
|
|
26044
26047
|
const tokenRawAmount = amount;
|
|
26045
26048
|
const isTokenAmountVerySmall = !!tokenRawAmount &&
|
|
@@ -26079,7 +26082,7 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
26079
26082
|
var _a;
|
|
26080
26083
|
if (isNaN(Number(inputValue)) || inputValue === '')
|
|
26081
26084
|
return '0';
|
|
26082
|
-
if (
|
|
26085
|
+
if (userInputType === UserInputType.TOKEN) {
|
|
26083
26086
|
if (direction === 'from') {
|
|
26084
26087
|
return formatAmount(convertTokenAmountToUSD(inputValue, token.price, maxUsdDecimals));
|
|
26085
26088
|
}
|
|
@@ -26092,13 +26095,13 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
26092
26095
|
}
|
|
26093
26096
|
}, [
|
|
26094
26097
|
inputValue,
|
|
26095
|
-
|
|
26098
|
+
userInputType,
|
|
26096
26099
|
token.price,
|
|
26097
26100
|
direction,
|
|
26098
26101
|
inputModeButton === null || inputModeButton === void 0 ? void 0 : inputModeButton.amountUsd,
|
|
26099
26102
|
]);
|
|
26100
26103
|
const AmountChip = isInteractive ? 'button' : 'div';
|
|
26101
|
-
const priceImpactClass = ((
|
|
26104
|
+
const priceImpactClass = ((_b = Number(priceImpactPercentage)) !== null && _b !== void 0 ? _b : 0) > Number(criticalPriceImpactPercentage)
|
|
26102
26105
|
? 'tw-text-status-negative'
|
|
26103
26106
|
: 'tw-text-grey-300';
|
|
26104
26107
|
const BalanceChipTag = balanceChipClickable ? 'button' : 'div';
|
|
@@ -26109,13 +26112,13 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
26109
26112
|
const inputRef = React$1.useRef(null);
|
|
26110
26113
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [isInteractive && !isLoading ? (jsxRuntime.jsxs("form", { className: containerClassname, onSubmit: (e) => {
|
|
26111
26114
|
e.preventDefault();
|
|
26112
|
-
}, children: [
|
|
26115
|
+
}, 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
|
|
26113
26116
|
? undefined
|
|
26114
|
-
:
|
|
26117
|
+
: userInputType === UserInputType.TOKEN
|
|
26115
26118
|
? inputModeButton === null || inputModeButton === void 0 ? void 0 : inputModeButton.tokenModeTooltip
|
|
26116
26119
|
: 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
|
|
26117
26120
|
? interactiveChipClassName
|
|
26118
|
-
: notInteractiveChipClassName), children: [jsxRuntime.jsx(SwapInputsIcon, {}),
|
|
26121
|
+
: 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
|
|
26119
26122
|
? formatIfVerySmall.token
|
|
26120
26123
|
: amountFormatted })] }) })) : (jsxRuntime.jsxs("span", { className: "tw-text-grey-500", children: [isTokenAmountVerySmall ? '<' : '', jsxRuntime.jsx(CaptionText, { children: isTokenAmountVerySmall
|
|
26121
26124
|
? 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
|
@@ -18558,7 +18558,7 @@ function SwapConfiguration({ amount, tokenPrice = 0, isFetching: isFetchingProp
|
|
|
18558
18558
|
? walletButton === null || walletButton === void 0 ? void 0 : walletButton.address
|
|
18559
18559
|
: (_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)
|
|
18560
18560
|
? 'tw-text-grey-600'
|
|
18561
|
-
: '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: {
|
|
18561
|
+
: '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: {
|
|
18562
18562
|
decimals: (_b = token === null || token === void 0 ? void 0 : token.decimals) !== null && _b !== void 0 ? _b : 18,
|
|
18563
18563
|
symbol: (_c = token === null || token === void 0 ? void 0 : token.symbol) !== null && _c !== void 0 ? _c : '',
|
|
18564
18564
|
price: tokenPrice,
|
|
@@ -25948,18 +25948,19 @@ const RegExpNonZeroValue = /[^0.]/;
|
|
|
25948
25948
|
const interactiveChipClassName = 'hover:tw-bg-material-light-thin';
|
|
25949
25949
|
const notInteractiveChipClassName = 'tw-cursor-not-allowed';
|
|
25950
25950
|
const loadingClassName = 'tw-opacity-50';
|
|
25951
|
-
var
|
|
25952
|
-
(function (
|
|
25953
|
-
|
|
25954
|
-
|
|
25955
|
-
})(
|
|
25956
|
-
function NumericInput(
|
|
25957
|
-
|
|
25958
|
-
|
|
25959
|
-
|
|
25960
|
-
|
|
25951
|
+
var UserInputType;
|
|
25952
|
+
(function (UserInputType) {
|
|
25953
|
+
UserInputType[UserInputType["TOKEN"] = 0] = "TOKEN";
|
|
25954
|
+
UserInputType[UserInputType["USD"] = 1] = "USD";
|
|
25955
|
+
})(UserInputType || (UserInputType = {}));
|
|
25956
|
+
function NumericInput(_a) {
|
|
25957
|
+
var _b;
|
|
25958
|
+
var { priceImpactPercentage, balance = '0', error, criticalPriceImpactPercentage = 5, token, onAmountChange, forcedAmount, maxUsdDecimals = 4, formatIfVerySmall = {
|
|
25959
|
+
token: '0.001',
|
|
25960
|
+
usd: '0.01',
|
|
25961
|
+
}, 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"]);
|
|
25961
25962
|
const [inputValue, setInputValue] = useState('');
|
|
25962
|
-
const [
|
|
25963
|
+
const [userInputType, setUserInputType] = useState(UserInputType.TOKEN);
|
|
25963
25964
|
const balanceChipClickable = isInteractive && parseFloat(balance) > 0;
|
|
25964
25965
|
useEffect(() => {
|
|
25965
25966
|
if (forcedAmount !== undefined) {
|
|
@@ -25968,11 +25969,11 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
25968
25969
|
}, [forcedAmount]);
|
|
25969
25970
|
const updateInputValue = useCallback((newValue) => {
|
|
25970
25971
|
const safeNewValue = trimExtraDecimals(newValue, token.decimals);
|
|
25971
|
-
const formattedAmount =
|
|
25972
|
+
const formattedAmount = userInputType === UserInputType.TOKEN
|
|
25972
25973
|
? safeNewValue
|
|
25973
25974
|
: convertTokenAmountToUSD(safeNewValue, token.price, maxUsdDecimals);
|
|
25974
25975
|
setInputValue(formattedAmount);
|
|
25975
|
-
}, [
|
|
25976
|
+
}, [userInputType, token.price, direction, token.decimals]);
|
|
25976
25977
|
const onBalanceButtonClick = useCallback(() => {
|
|
25977
25978
|
if (balanceChipClickable) {
|
|
25978
25979
|
updateInputValue(balance);
|
|
@@ -25984,7 +25985,7 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
25984
25985
|
]);
|
|
25985
25986
|
const handleInputChange = (e) => {
|
|
25986
25987
|
let value = e.target.value.replace(/,/g, '.'); // Replace commas with dots
|
|
25987
|
-
const maxDecimalsForInputType =
|
|
25988
|
+
const maxDecimalsForInputType = userInputType === UserInputType.TOKEN ? token.decimals : maxUsdDecimals;
|
|
25988
25989
|
const isValidAmount = new RegExp(`^\\d*\\.?\\d{0,${maxDecimalsForInputType}}$`).test(value);
|
|
25989
25990
|
if (isValidAmount) {
|
|
25990
25991
|
setInputValue(value);
|
|
@@ -26003,12 +26004,14 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
26003
26004
|
const handleSwitchInputMode = () => {
|
|
26004
26005
|
var _a;
|
|
26005
26006
|
if (inputValue !== '') {
|
|
26006
|
-
const convertedAmount =
|
|
26007
|
+
const convertedAmount = userInputType === UserInputType.TOKEN
|
|
26007
26008
|
? convertTokenAmountToUSD(inputValue, token.price, maxUsdDecimals)
|
|
26008
26009
|
: convertUSDToTokenAmount(inputValue, token.price, token.decimals);
|
|
26009
26010
|
setInputValue(convertedAmount);
|
|
26010
26011
|
}
|
|
26011
|
-
|
|
26012
|
+
setUserInputType((prevMode) => prevMode === UserInputType.TOKEN
|
|
26013
|
+
? UserInputType.USD
|
|
26014
|
+
: UserInputType.TOKEN);
|
|
26012
26015
|
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
26013
26016
|
};
|
|
26014
26017
|
const getRawAmounts = (amount) => {
|
|
@@ -26019,7 +26022,7 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
26019
26022
|
isTokenAmountVerySmall: false,
|
|
26020
26023
|
isUsdAmountVerySmall: false,
|
|
26021
26024
|
};
|
|
26022
|
-
if (
|
|
26025
|
+
if (userInputType === UserInputType.TOKEN) {
|
|
26023
26026
|
const usdRawAmount = convertTokenAmountToUSD(amount, token.price, maxUsdDecimals);
|
|
26024
26027
|
const tokenRawAmount = amount;
|
|
26025
26028
|
const isTokenAmountVerySmall = !!tokenRawAmount &&
|
|
@@ -26059,7 +26062,7 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
26059
26062
|
var _a;
|
|
26060
26063
|
if (isNaN(Number(inputValue)) || inputValue === '')
|
|
26061
26064
|
return '0';
|
|
26062
|
-
if (
|
|
26065
|
+
if (userInputType === UserInputType.TOKEN) {
|
|
26063
26066
|
if (direction === 'from') {
|
|
26064
26067
|
return formatAmount(convertTokenAmountToUSD(inputValue, token.price, maxUsdDecimals));
|
|
26065
26068
|
}
|
|
@@ -26072,13 +26075,13 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
26072
26075
|
}
|
|
26073
26076
|
}, [
|
|
26074
26077
|
inputValue,
|
|
26075
|
-
|
|
26078
|
+
userInputType,
|
|
26076
26079
|
token.price,
|
|
26077
26080
|
direction,
|
|
26078
26081
|
inputModeButton === null || inputModeButton === void 0 ? void 0 : inputModeButton.amountUsd,
|
|
26079
26082
|
]);
|
|
26080
26083
|
const AmountChip = isInteractive ? 'button' : 'div';
|
|
26081
|
-
const priceImpactClass = ((
|
|
26084
|
+
const priceImpactClass = ((_b = Number(priceImpactPercentage)) !== null && _b !== void 0 ? _b : 0) > Number(criticalPriceImpactPercentage)
|
|
26082
26085
|
? 'tw-text-status-negative'
|
|
26083
26086
|
: 'tw-text-grey-300';
|
|
26084
26087
|
const BalanceChipTag = balanceChipClickable ? 'button' : 'div';
|
|
@@ -26089,13 +26092,13 @@ function NumericInput({ priceImpactPercentage, balance = '0', error, criticalPri
|
|
|
26089
26092
|
const inputRef = useRef(null);
|
|
26090
26093
|
return (jsxs(Fragment, { children: [isInteractive && !isLoading ? (jsxs("form", { className: containerClassname, onSubmit: (e) => {
|
|
26091
26094
|
e.preventDefault();
|
|
26092
|
-
}, children: [
|
|
26095
|
+
}, 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
|
|
26093
26096
|
? undefined
|
|
26094
|
-
:
|
|
26097
|
+
: userInputType === UserInputType.TOKEN
|
|
26095
26098
|
? inputModeButton === null || inputModeButton === void 0 ? void 0 : inputModeButton.tokenModeTooltip
|
|
26096
26099
|
: 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
|
|
26097
26100
|
? interactiveChipClassName
|
|
26098
|
-
: notInteractiveChipClassName), children: [jsx(SwapInputsIcon, {}),
|
|
26101
|
+
: 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
|
|
26099
26102
|
? formatIfVerySmall.token
|
|
26100
26103
|
: amountFormatted })] }) })) : (jsxs("span", { className: "tw-text-grey-500", children: [isTokenAmountVerySmall ? '<' : '', jsx(CaptionText, { children: isTokenAmountVerySmall
|
|
26101
26104
|
? 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
|
@@ -171,7 +171,7 @@ interface Token$1 {
|
|
|
171
171
|
symbol: string;
|
|
172
172
|
decimals: number;
|
|
173
173
|
}
|
|
174
|
-
interface NumericInputProps {
|
|
174
|
+
interface NumericInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
175
175
|
token: Token$1;
|
|
176
176
|
onAmountChange: (tokenAmount: string) => void;
|
|
177
177
|
forcedAmount?: string;
|
|
@@ -199,7 +199,7 @@ interface NumericInputProps {
|
|
|
199
199
|
tooltip?: Omit<TooltipProps, 'children'>;
|
|
200
200
|
};
|
|
201
201
|
}
|
|
202
|
-
declare function NumericInput({ priceImpactPercentage, balance, error, criticalPriceImpactPercentage, token, onAmountChange, forcedAmount, maxUsdDecimals, formatIfVerySmall, showDetails, isLoading, direction, inputModeButton, isInteractive, balanceButton, }: NumericInputProps): react_jsx_runtime.JSX.Element;
|
|
202
|
+
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;
|
|
203
203
|
|
|
204
204
|
interface SettingsSliderProps {
|
|
205
205
|
value: number | undefined;
|