Skip to content

Commit

Permalink
fix(wallet-mobile): send funnel accepts local decimal separator (#3760)
Browse files Browse the repository at this point in the history
  • Loading branch information
banklesss authored Dec 11, 2024
1 parent c5a0b72 commit 4f33434
Showing 1 changed file with 9 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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})
}
Expand All @@ -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(() => {
Expand Down Expand Up @@ -187,25 +179,14 @@ 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 (
<TextInput
keyboardType="numeric"
mode="flat"
autoComplete="off"
value={value}
placeholder="0"
onChangeText={onChangeText}
onChangeText={onChange}
selectTextOnAutoFocus
allowFontScaling
right={<Ticker ticker={ticker} />}
Expand Down

0 comments on commit 4f33434

Please sign in to comment.