Skip to content

Commit

Permalink
fixed amount input field to properly interpret BTC
Browse files Browse the repository at this point in the history
  • Loading branch information
amitx13 committed Jul 19, 2024
1 parent 4a5bf20 commit 0915ac5
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/components/BitcoinAmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ const BitcoinAmountInput = forwardRef(
field.onBlur(e)
}}
onChange={(e) => {
const valueOrNan = parseFloat(e.target.value ?? '')

if (!isValidNumber(valueOrNan)) {
const valueOrNan = e.target.value ?? ''
const floatValueOrNan = parseFloat(valueOrNan)
if (!isValidNumber(floatValueOrNan)) {
form.setFieldValue(
field.name,
{
Expand All @@ -129,10 +129,12 @@ const BitcoinAmountInput = forwardRef(
)
return
} else {
const value: number = valueOrNan

const value: number = floatValueOrNan
let numberValues: string | undefined
const unit = unitFromValue(String(value))
const unit =
valueOrNan.includes('.') && parseFloat(valueOrNan)
? unitFromValue(String(valueOrNan))
: unitFromValue(String(value))
if (unit === 'BTC') {
const splitted = String(value).split('.')
const [integerPart, fractionalPart = ''] = splitted
Expand Down

0 comments on commit 0915ac5

Please sign in to comment.