mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-27 10:48:22 +00:00
debounce validation in send forms
This commit is contained in:
parent
bcd618aa0a
commit
2fd208ddb9
@ -11,6 +11,7 @@ import { initialState } from 'reducers/SendFormEthereumReducer';
|
|||||||
import * as reducerUtils from 'reducers/utils';
|
import * as reducerUtils from 'reducers/utils';
|
||||||
import * as ethUtils from 'utils/ethUtils';
|
import * as ethUtils from 'utils/ethUtils';
|
||||||
import { toFiatCurrency, fromFiatCurrency } from 'utils/fiatConverter';
|
import { toFiatCurrency, fromFiatCurrency } from 'utils/fiatConverter';
|
||||||
|
import { debounce } from 'utils/common';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
Dispatch,
|
Dispatch,
|
||||||
@ -36,6 +37,15 @@ const actions = [
|
|||||||
...Object.values(SEND).filter(v => typeof v === 'string'),
|
...Object.values(SEND).filter(v => typeof v === 'string'),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const debouncedValidation = debounce((dispatch: Dispatch) => {
|
||||||
|
const validated = dispatch(ValidationActions.validation());
|
||||||
|
dispatch({
|
||||||
|
type: SEND.VALIDATION,
|
||||||
|
networkType: 'ethereum',
|
||||||
|
state: validated,
|
||||||
|
});
|
||||||
|
}, 300);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called from WalletService
|
* Called from WalletService
|
||||||
*/
|
*/
|
||||||
@ -108,12 +118,7 @@ export const observe = (prevState: ReducersState, action: Action): ThunkAction =
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (shouldUpdate) {
|
if (shouldUpdate) {
|
||||||
const validated = dispatch(ValidationActions.validation());
|
debouncedValidation(dispatch);
|
||||||
dispatch({
|
|
||||||
type: SEND.VALIDATION,
|
|
||||||
networkType: 'ethereum',
|
|
||||||
state: validated,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import { initialState } from 'reducers/SendFormRippleReducer';
|
|||||||
import * as reducerUtils from 'reducers/utils';
|
import * as reducerUtils from 'reducers/utils';
|
||||||
import { fromDecimalAmount } from 'utils/formatUtils';
|
import { fromDecimalAmount } from 'utils/formatUtils';
|
||||||
import { toFiatCurrency, fromFiatCurrency } from 'utils/fiatConverter';
|
import { toFiatCurrency, fromFiatCurrency } from 'utils/fiatConverter';
|
||||||
|
import { debounce } from 'utils/common';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
Dispatch,
|
Dispatch,
|
||||||
@ -23,6 +24,15 @@ import * as SessionStorageActions from '../SessionStorageActions';
|
|||||||
import * as BlockchainActions from './BlockchainActions';
|
import * as BlockchainActions from './BlockchainActions';
|
||||||
import * as ValidationActions from './SendFormValidationActions';
|
import * as ValidationActions from './SendFormValidationActions';
|
||||||
|
|
||||||
|
const debouncedValidation = debounce((dispatch: Dispatch, prevState: ReducersState) => {
|
||||||
|
const validated = dispatch(ValidationActions.validation(prevState.sendFormRipple));
|
||||||
|
dispatch({
|
||||||
|
type: SEND.VALIDATION,
|
||||||
|
networkType: 'ripple',
|
||||||
|
state: validated,
|
||||||
|
});
|
||||||
|
}, 300);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called from WalletService
|
* Called from WalletService
|
||||||
*/
|
*/
|
||||||
@ -71,12 +81,7 @@ export const observe = (prevState: ReducersState, action: Action): ThunkAction =
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (shouldUpdate) {
|
if (shouldUpdate) {
|
||||||
const validated = dispatch(ValidationActions.validation(prevState.sendFormRipple));
|
debouncedValidation(dispatch, prevState);
|
||||||
dispatch({
|
|
||||||
type: SEND.VALIDATION,
|
|
||||||
networkType: 'ripple',
|
|
||||||
state: validated,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
9
src/utils/common.js
Normal file
9
src/utils/common.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export const debounce = (func, wait) => {
|
||||||
|
let timeout;
|
||||||
|
return (...args) => {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = setTimeout(() => {
|
||||||
|
func(...args);
|
||||||
|
}, wait);
|
||||||
|
};
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user