From 354d5bd5f02db2e96c625899dbb3d27ca3a07ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Mon, 10 Sep 2018 17:29:49 +0200 Subject: [PATCH] Fix checking the tagId validity --- src/components/AdvancedOptions/RippleKind.js | 58 ++++++++++++-------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/src/components/AdvancedOptions/RippleKind.js b/src/components/AdvancedOptions/RippleKind.js index b87cff5f..74b0b5a4 100644 --- a/src/components/AdvancedOptions/RippleKind.js +++ b/src/components/AdvancedOptions/RippleKind.js @@ -1,5 +1,6 @@ // @flow -import React from 'react' +import React, { Component } from 'react' +import { BigNumber } from 'bignumber.js' import { translate } from 'react-i18next' import Box from 'components/base/Box' @@ -13,24 +14,37 @@ type Props = { t: *, } -export default translate()(({ tag, onChangeTag, t }: Props) => ( - - - - - - - { - const tag = parseInt(str, 10) - if (!isNaN(tag) && isFinite(tag)) onChangeTag(tag) - else onChangeTag(undefined) - }} - /> - - - -)) +const uint32maxPlus1 = BigNumber(2).pow(32) + +class RippleKind extends Component { + onChange = str => { + const { onChangeTag } = this.props + const tag = BigNumber(str.replace(/[^0-9]/g, '')) + if (!tag.isNaN() && tag.isFinite()) { + if (tag.isInteger() && tag.isPositive() && tag.lt(uint32maxPlus1)) { + onChangeTag(tag.toNumber()) + } + } else { + onChangeTag(undefined) + } + } + render() { + const { tag, t } = this.props + return ( + + + + + + + + + + + ) + } +} + +export default translate()(RippleKind)