|
|
@ -6,49 +6,43 @@ import {CustomTooltip, isNumeric} from '@remix-ui/helper' |
|
|
|
import {ValueProps} from '../types' |
|
|
|
import {ValueProps} from '../types' |
|
|
|
|
|
|
|
|
|
|
|
export function ValueUI(props: ValueProps) { |
|
|
|
export function ValueUI(props: ValueProps) { |
|
|
|
const [sendValue, setSendValue] = useState<string>(props.sendValue) |
|
|
|
const inputValue = useRef<HTMLInputElement>({} as HTMLInputElement)
|
|
|
|
const inputValue = useRef<HTMLInputElement>({} as HTMLInputElement) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
sendValue !== props.sendValue && props.setSendValue(sendValue) |
|
|
|
if (props.sendValue !== inputValue.current.value) { |
|
|
|
}, [sendValue]) |
|
|
|
inputValue.current.value = props.sendValue |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
if(props.sendValue !== sendValue) { |
|
|
|
|
|
|
|
setSendValue(props.sendValue) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
},[props.sendValue]) |
|
|
|
},[props.sendValue]) |
|
|
|
|
|
|
|
|
|
|
|
const validateInputKey = (e) => { |
|
|
|
|
|
|
|
// preventing not numeric keys
|
|
|
|
|
|
|
|
// preventing 000 case
|
|
|
|
|
|
|
|
if (!isNumeric(e.key) || (e.key === '0' && !parseInt(inputValue.current.value) && inputValue.current.value.length > 0)) { |
|
|
|
|
|
|
|
e.preventDefault() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const validateValue = (e) => { |
|
|
|
const validateValue = (e) => { |
|
|
|
|
|
|
|
console.log('validateValue', e.target.value) |
|
|
|
const value = e.target.value |
|
|
|
const value = e.target.value |
|
|
|
|
|
|
|
|
|
|
|
if (!value) { |
|
|
|
if (!value) { |
|
|
|
// assign 0 if given value is
|
|
|
|
// assign 0 if given value is
|
|
|
|
// - empty
|
|
|
|
// - empty
|
|
|
|
return setSendValue('0') |
|
|
|
inputValue.current.value = '0' |
|
|
|
|
|
|
|
props.setSendValue('0') |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let v |
|
|
|
let v |
|
|
|
try { |
|
|
|
try { |
|
|
|
v = new BN(value, 10) |
|
|
|
v = new BN(value, 10) |
|
|
|
setSendValue(v.toString(10)) |
|
|
|
props.setSendValue(v.toString(10)) |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
// assign 0 if given value is
|
|
|
|
// assign 0 if given value is
|
|
|
|
// - not valid (for ex 4345-54)
|
|
|
|
// - not valid (for ex 4345-54)
|
|
|
|
// - contains only '0's (for ex 0000) copy past or edit
|
|
|
|
// - contains only '0's (for ex 0000) copy past or edit
|
|
|
|
setSendValue('0') |
|
|
|
inputValue.current.value = '0' |
|
|
|
|
|
|
|
props.setSendValue('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 (v.lt(0)) setSendValue('0') |
|
|
|
if (v.lt(0)) { |
|
|
|
|
|
|
|
inputValue.current.value = '0' |
|
|
|
|
|
|
|
props.setSendValue('0') |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
@ -67,9 +61,8 @@ export function ValueUI(props: ValueProps) { |
|
|
|
className="form-control udapp_gasNval udapp_col2" |
|
|
|
className="form-control udapp_gasNval udapp_col2" |
|
|
|
id="value" |
|
|
|
id="value" |
|
|
|
data-id="dandrValue" |
|
|
|
data-id="dandrValue" |
|
|
|
onKeyPress={validateInputKey} |
|
|
|
|
|
|
|
onChange={validateValue} |
|
|
|
onChange={validateValue} |
|
|
|
value={sendValue} |
|
|
|
value={props.sendValue} |
|
|
|
/> |
|
|
|
/> |
|
|
|
</CustomTooltip> |
|
|
|
</CustomTooltip> |
|
|
|
|
|
|
|
|
|
|
|