Commit 0284623e authored by yann300's avatar yann300

validate input using BigNumber

parent 9c42776f
import { BN } from 'ethereumjs-util'
const $ = require('jquery') const $ = require('jquery')
const yo = require('yo-yo') const yo = require('yo-yo')
const remixLib = require('@remix-project/remix-lib') const remixLib = require('@remix-project/remix-lib')
...@@ -65,14 +66,19 @@ class SettingsUI { ...@@ -65,14 +66,19 @@ class SettingsUI {
validateValue () { validateValue () {
const valueEl = this.el.querySelector('#value') const valueEl = this.el.querySelector('#value')
valueEl.value = parseInt(valueEl.value) let v
// assign 0 if given value is try {
// - empty v = new BN(valueEl.value, 10)
// - not valid (for ex 4345-54) } catch (e) {
// - contains only '0's (for ex 0000) copy past or edit // assign 0 if given value is
if (!valueEl.value) valueEl.value = 0 // - empty
// - not valid (for ex 4345-54)
// - contains only '0's (for ex 0000) copy past or edit
valueEl.value = 0
}
// if giveen value is negative(possible with copy-pasting) set to 0 // if giveen value is negative(possible with copy-pasting) set to 0
if (valueEl.value < 0) valueEl.value = 0 if (v.lt(0)) valueEl.value = 0
} }
render () { render () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment