diff --git a/apps/wallet-mobile/src/features/Send/useCases/ListAmountsToSend/EditAmount/EditAmountScreen.tsx b/apps/wallet-mobile/src/features/Send/useCases/ListAmountsToSend/EditAmount/EditAmountScreen.tsx index 77ad0b3276..80049082c6 100644 --- a/apps/wallet-mobile/src/features/Send/useCases/ListAmountsToSend/EditAmount/EditAmountScreen.tsx +++ b/apps/wallet-mobile/src/features/Send/useCases/ListAmountsToSend/EditAmount/EditAmountScreen.tsx @@ -1,5 +1,5 @@ import {useIsFocused} from '@react-navigation/native' -import {atomicBreakdown, parseDecimal} from '@yoroi/common' +import {atomicBreakdown} from '@yoroi/common' import {isPrimaryToken} from '@yoroi/portfolio' import {useTheme} from '@yoroi/theme' import {useTransfer} from '@yoroi/transfer' @@ -15,7 +15,7 @@ import {Spacer} from '../../../../../components/Spacer/Spacer' import {TextInput} from '../../../../../components/TextInput/TextInput' import {useLanguage} from '../../../../../kernel/i18n' import {logger} from '../../../../../kernel/logger/logger' -import {editedFormatter, pastedFormatter} from '../../../../../yoroi-wallets/utils/amountUtils' +import {Quantities} from '../../../../../yoroi-wallets/utils/utils' import {usePortfolioBalances} from '../../../../Portfolio/common/hooks/usePortfolioBalances' import {usePortfolioPrimaryBreakdown} from '../../../../Portfolio/common/hooks/usePortfolioPrimaryBreakdown' import {TokenAmountItem} from '../../../../Portfolio/common/TokenAmountItem/TokenAmountItem' @@ -74,13 +74,9 @@ export const EditAmountScreen = () => { const handleOnChangeQuantity = React.useCallback( (text: string) => { try { - const {text: newInputValue, bi: newQuantity} = parseDecimal({ - value: text, - decimalPlaces: amount.info.decimals, - format: numberLocale, - }) - setInputValue(newInputValue) - setQuantity(newQuantity) + const [input, quantity] = Quantities.parseFromText(text, amount.info.decimals ?? 0, numberLocale) + setInputValue(input) + setQuantity(BigInt(quantity)) } catch (error) { logger.error('EditAmountScreen: handleOnChangeQuantity error parsing input', {error}) } @@ -89,13 +85,9 @@ export const EditAmountScreen = () => { ) const handleOnMaxBalance = React.useCallback(() => { - const {text: newInputValue, bi: newQuantity} = parseDecimal({ - value: spendable.toString(), - decimalPlaces: amount.info.decimals, - format: numberLocale, - }) - setInputValue(newInputValue) - setQuantity(newQuantity) + const [input, quantity] = Quantities.parseFromText(spendable.toString(), amount.info.decimals ?? 0, numberLocale) + setInputValue(input) + setQuantity(BigInt(quantity)) }, [amount.info.decimals, numberLocale, spendable]) const handleOnApply = React.useCallback(() => { @@ -187,17 +179,6 @@ type AmountInputProps = { const AmountInput = ({onChange, value, ticker}: AmountInputProps) => { const {styles, colors} = useStyles() - const onChangeText = (text: string) => { - const shorterStringLength = Math.min(text.length, value.length) - const wasPasted = - Math.abs(value.length - text.length) > 1 || - value.substring(0, shorterStringLength) !== text.substring(0, shorterStringLength) - - const formatter = wasPasted ? pastedFormatter : editedFormatter - - onChange(formatter(text)) - } - return ( { autoComplete="off" value={value} placeholder="0" - onChangeText={onChangeText} + onChangeText={onChange} selectTextOnAutoFocus allowFontScaling right={}