Browse Source

Merge pull request #1218 from gre/usebignumber

Fix missing case where bignumber.js was not used
master
Gaëtan Renaudeau 7 years ago
committed by GitHub
parent
commit
f2539945a3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      src/components/RequestAmount/index.js

23
src/components/RequestAmount/index.js

@ -1,5 +1,6 @@
// @flow // @flow
import { BigNumber } from 'bignumber.js'
import React, { PureComponent } from 'react' import React, { PureComponent } from 'react'
import { compose } from 'redux' import { compose } from 'redux'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
@ -45,15 +46,15 @@ type OwnProps = {
t: T, t: T,
// left value (always the one which is returned) // left value (always the one which is returned)
value: number, value: BigNumber,
canBeSpentError: ?Error, canBeSpentError: ?Error,
// max left value // max left value
max: number, max: BigNumber,
// change handler // change handler
onChange: number => void, onChange: BigNumber => void,
// used to determine the left input unit // used to determine the left input unit
account: Account, account: Account,
@ -68,8 +69,8 @@ type Props = OwnProps & {
rightCurrency: Currency, rightCurrency: Currency,
// used to calculate the opposite field value (right & left) // used to calculate the opposite field value (right & left)
getCounterValue: number => ?number, getCounterValue: BigNumber => ?BigNumber,
getReverseCounterValue: number => ?number, getReverseCounterValue: BigNumber => ?BigNumber,
} }
const mapStateToProps = (state: State, props: OwnProps) => { const mapStateToProps = (state: State, props: OwnProps) => {
@ -111,7 +112,7 @@ const mapStateToProps = (state: State, props: OwnProps) => {
export class RequestAmount extends PureComponent<Props> { export class RequestAmount extends PureComponent<Props> {
static defaultProps = { static defaultProps = {
max: Infinity, max: BigNumber(Infinity),
canBeSpent: true, canBeSpent: true,
withMax: true, withMax: true,
} }
@ -123,13 +124,13 @@ export class RequestAmount extends PureComponent<Props> {
} }
} }
handleChangeAmount = (changedField: string) => (val: number) => { handleChangeAmount = (changedField: string) => (val: BigNumber) => {
const { getReverseCounterValue, max, onChange } = this.props const { getReverseCounterValue, max, onChange } = this.props
if (changedField === 'left') { if (changedField === 'left') {
onChange(val > max ? max : val) onChange(val.gt(max) ? max : val)
} else if (changedField === 'right') { } else if (changedField === 'right') {
const leftVal = getReverseCounterValue(val) || 0 const leftVal = getReverseCounterValue(val) || BigNumber(0)
onChange(leftVal > max ? max : leftVal) onChange(leftVal.gt(max) ? max : leftVal)
} }
} }
@ -139,7 +140,7 @@ export class RequestAmount extends PureComponent<Props> {
renderInputs(containerProps: Object) { renderInputs(containerProps: Object) {
// TODO move this inlined into render() for less spaghetti // TODO move this inlined into render() for less spaghetti
const { value, account, rightCurrency, getCounterValue, canBeSpentError } = this.props const { value, account, rightCurrency, getCounterValue, canBeSpentError } = this.props
const right = getCounterValue(value) || 0 const right = getCounterValue(value) || BigNumber(0)
const rightUnit = rightCurrency.units[0] const rightUnit = rightCurrency.units[0]
// FIXME: no way InputCurrency pure can work here. inlined InputRight (should be static func?), inline containerProps object.. // FIXME: no way InputCurrency pure can work here. inlined InputRight (should be static func?), inline containerProps object..
return ( return (

Loading…
Cancel
Save