Skip to content

Commit

Permalink
add lastCommaToDot for european decimal seperator
Browse files Browse the repository at this point in the history
  • Loading branch information
hanwong committed Apr 4, 2022
1 parent 2751117 commit a6f6cc2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/components/UseStationFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ const FormInput = ({ field }: { field: Field }): ReactElement => {
const onChangeText = (text: string): void => {
let value = text
if (field.attrs.type === 'number') {
if (text.charAt(text.length - 1) === ',') {
text = UTIL.lastCommaToDot(text)
}
const onlyNumber = UTIL.delComma(text)
const bn = new BigNumber(onlyNumber).dp(6, BigNumber.ROUND_DOWN)
if (bn.isNaN()) {
Expand Down
5 changes: 5 additions & 0 deletions src/consts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const delComma = (str: string | number): string => {
return _.toString(str).replace(/,/g, '')
}

const lastCommaToDot = (str: string | number): string => {
return _.toString(str).replace(/,\s*$/, '.')
}

const extractNumber = (str: string): string => str.replace(/\D+/g, '')

const isNativeTerra = (str: string): boolean =>
Expand Down Expand Up @@ -179,6 +183,7 @@ export default {
jsonTryStringify,
setComma,
delComma,
lastCommaToDot,
extractNumber,
isNativeTerra,
isNativeDenom,
Expand Down
11 changes: 9 additions & 2 deletions src/screens/TabSwap/SelectInputForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import _ from 'lodash'
import { useNavigation } from '@react-navigation/core'

import { COLOR, LAYOUT } from 'consts'
import { COLOR, LAYOUT, UTIL } from 'consts'

import { Field, Option, Options } from 'lib'

Expand Down Expand Up @@ -119,6 +119,13 @@ const SelectInputForm = ({
const error = inputError || selectError
const isCoinSelected = _.some(selectField.attrs.value)

const handleOnChange = (value: string) => {
if (value.charAt(value.length - 1) === ',') {
value = UTIL.lastCommaToDot(value)
}
inputField.setValue?.(value)
}

return (
<View
style={{
Expand Down Expand Up @@ -148,7 +155,7 @@ const SelectInputForm = ({
defaultValue={inputField.attrs.defaultValue}
editable={!disabled && !inputField.attrs.readOnly}
placeholder={inputField.attrs.placeholder}
onChangeText={inputField.setValue}
onChangeText={handleOnChange}
containerStyle={{
flex: 2,
borderWidth: 0,
Expand Down

0 comments on commit a6f6cc2

Please sign in to comment.