Browse Source

Merge pull request #1503 from gre/xrp-limit-tagid

Fix checking the tagId validity
master
Gaëtan Renaudeau 6 years ago
committed by GitHub
parent
commit
7159aa7c16
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 58
      src/components/AdvancedOptions/RippleKind.js

58
src/components/AdvancedOptions/RippleKind.js

@ -1,5 +1,6 @@
// @flow // @flow
import React from 'react' import React, { Component } from 'react'
import { BigNumber } from 'bignumber.js'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
import Box from 'components/base/Box' import Box from 'components/base/Box'
@ -13,24 +14,37 @@ type Props = {
t: *, t: *,
} }
export default translate()(({ tag, onChangeTag, t }: Props) => ( const uint32maxPlus1 = BigNumber(2).pow(32)
<Spoiler title={t('app:send.steps.amount.advancedOptions')}>
<Box horizontal align="center" flow={5}> class RippleKind extends Component<Props> {
<Box style={{ width: 200 }}> onChange = str => {
<Label> const { onChangeTag } = this.props
<span>{t('app:send.steps.amount.rippleTag')}</span> const tag = BigNumber(str.replace(/[^0-9]/g, ''))
</Label> if (!tag.isNaN() && tag.isFinite()) {
</Box> if (tag.isInteger() && tag.isPositive() && tag.lt(uint32maxPlus1)) {
<Box grow> onChangeTag(tag.toNumber())
<Input }
value={String(tag || '')} } else {
onChange={str => { onChangeTag(undefined)
const tag = parseInt(str, 10) }
if (!isNaN(tag) && isFinite(tag)) onChangeTag(tag) }
else onChangeTag(undefined) render() {
}} const { tag, t } = this.props
/> return (
</Box> <Spoiler title={t('app:send.steps.amount.advancedOptions')}>
</Box> <Box horizontal align="center" flow={5}>
</Spoiler> <Box style={{ width: 200 }}>
)) <Label>
<span>{t('app:send.steps.amount.rippleTag')}</span>
</Label>
</Box>
<Box grow>
<Input value={String(tag || '')} onChange={this.onChange} />
</Box>
</Box>
</Spoiler>
)
}
}
export default translate()(RippleKind)

Loading…
Cancel
Save