Skip to content

Commit 46ae8c1

Browse files
committed
feat(neuron-ui): add verification on updating amounts
disable the amount to be updated if the value is not a number or has more than 8 digits decimal
1 parent a03bc44 commit 46ae8c1

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

  • packages/neuron-ui/src/components/Send

packages/neuron-ui/src/components/Send/hooks.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { TransactionOutput } from '.'
1111

1212
let cyclesTimer: ReturnType<typeof setTimeout>
1313

14+
const MAX_DECIMAL_DIGITS = 8
15+
1416
const validateTransactionParams = ({ items, dispatch }: { items: TransactionOutput[]; dispatch?: StateDispatch }) => {
1517
const errorAction = {
1618
type: AppActions.AddNotification,
@@ -44,7 +46,7 @@ const validateTransactionParams = ({ items, dispatch }: { items: TransactionOutp
4446
return true
4547
}
4648
const [, decimal = ''] = item.amount.split('.')
47-
if (decimal.length > 8) {
49+
if (decimal.length > MAX_DECIMAL_DIGITS) {
4850
errorAction.payload.content = Message.InvalidAmount
4951
return true
5052
}
@@ -155,6 +157,15 @@ const useOnItemChange = (updateTransactionOutput: Function) =>
155157
if (undefined !== value) {
156158
if (field === 'amount') {
157159
const amount = value.replace(/[^\d.]/g, '')
160+
if (Number.isNaN(+amount)) {
161+
return
162+
}
163+
164+
const [, decimal] = amount.split('.')
165+
if (typeof decimal === 'string' && decimal.length > MAX_DECIMAL_DIGITS) {
166+
return
167+
}
168+
158169
updateTransactionOutput(field)(idx)(amount)
159170
} else {
160171
updateTransactionOutput(field)(idx)(value)

0 commit comments

Comments
 (0)