@@ -4,15 +4,13 @@ import { IDropdownOption } from 'office-ui-fabric-react'
44import { AppActions , StateDispatch } from 'states/stateProvider/reducer'
55import { calculateCycles } from 'services/remote/wallets'
66
7- import { Message } from 'utils/const'
7+ import { Message , MAX_DECIMAL_DIGITS } from 'utils/const'
88import { verifyAddress , verifyAmountRange } from 'utils/validators'
99import { outputsToTotalCapacity } from 'utils/formatters'
1010import { TransactionOutput } from '.'
1111
1212let cyclesTimer : ReturnType < typeof setTimeout >
1313
14- const MAX_DECIMAL_DIGITS = 8
15-
1614const validateTransactionParams = ( { items, dispatch } : { items : TransactionOutput [ ] ; dispatch ?: StateDispatch } ) => {
1715 const errorAction = {
1816 type : AppActions . AddNotification ,
@@ -39,22 +37,27 @@ const validateTransactionParams = ({ items, dispatch }: { items: TransactionOutp
3937 }
4038 if ( Number . isNaN ( + item . amount ) || + item . amount < 0 ) {
4139 errorAction . payload . content = Message . InvalidAmount
42- return true
43- }
44- if ( ! verifyAmountRange ( item . amount ) ) {
45- errorAction . payload . content = Message . AmountTooSmall
40+ errorAction . payload . meta = { amount : item . amount }
4641 return true
4742 }
4843 const [ , decimal = '' ] = item . amount . split ( '.' )
4944 if ( decimal . length > MAX_DECIMAL_DIGITS ) {
50- errorAction . payload . content = Message . InvalidAmount
45+ errorAction . payload . content = Message . DecimalExceed
46+ errorAction . payload . meta = { amount : item . amount }
47+ return true
48+ }
49+ if ( ! verifyAmountRange ( item . amount ) ) {
50+ errorAction . payload . content = Message . AmountTooSmall
51+ errorAction . payload . meta = { amount : item . amount }
5152 return true
5253 }
5354 return false
5455 }
5556 )
56- if ( invalid && dispatch ) {
57- dispatch ( errorAction )
57+ if ( invalid ) {
58+ if ( dispatch ) {
59+ dispatch ( errorAction )
60+ }
5861 return false
5962 }
6063 return true
@@ -156,17 +159,10 @@ const useOnItemChange = (updateTransactionOutput: Function) =>
156159 ) => {
157160 if ( undefined !== value ) {
158161 if ( field === 'amount' ) {
159- const amount = value . replace ( / [ ^ \d . ] / g, '' )
160- if ( Number . isNaN ( + amount ) ) {
162+ if ( Number . isNaN ( + value ) || / [ ^ \d . ] / . test ( value ) ) {
161163 return
162164 }
163-
164- const [ , decimal ] = amount . split ( '.' )
165- if ( typeof decimal === 'string' && decimal . length > MAX_DECIMAL_DIGITS ) {
166- return
167- }
168-
169- updateTransactionOutput ( field ) ( idx ) ( amount )
165+ updateTransactionOutput ( field ) ( idx ) ( value )
170166 } else {
171167 updateTransactionOutput ( field ) ( idx ) ( value )
172168 }
0 commit comments