|
|
|
@ -83,6 +83,9 @@ export type SendFormAction = SendTxAction | {
|
|
|
|
|
} | {
|
|
|
|
|
type: typeof SEND.GAS_LIMIT_CHANGE,
|
|
|
|
|
state: State
|
|
|
|
|
} | {
|
|
|
|
|
type: typeof SEND.NONCE_CHANGE,
|
|
|
|
|
state: State
|
|
|
|
|
} | {
|
|
|
|
|
type: typeof SEND.DATA_CHANGE,
|
|
|
|
|
state: State
|
|
|
|
@ -182,6 +185,7 @@ export const init = (): ThunkAction => {
|
|
|
|
|
return (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
|
|
|
|
|
const accountState: ?AccountState = getState().abstractAccount;
|
|
|
|
|
if (!accountState) return;
|
|
|
|
|
|
|
|
|
|
const { location } = getState().router;
|
|
|
|
|
const urlParams: RouterLocationState = location.state;
|
|
|
|
@ -196,11 +200,8 @@ export const init = (): ThunkAction => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: check if there are some unfinished tx in localStorage
|
|
|
|
|
const { config } = getState().localStorage;
|
|
|
|
|
if (!config) return;
|
|
|
|
|
|
|
|
|
|
const coin: ?Coin = config.coins.find(c => c.network === urlParams.network);
|
|
|
|
|
if (!coin) return;
|
|
|
|
|
const coin: Coin = accountState.coin;
|
|
|
|
|
|
|
|
|
|
const gasPrice: BigNumber = new BigNumber( EthereumjsUnits.convert(web3instance.gasPrice, 'wei', 'gwei') ) || new BigNumber(coin.defaultGasPrice);
|
|
|
|
|
const gasLimit: string = coin.defaultGasLimit.toString();
|
|
|
|
@ -252,7 +253,7 @@ export const validation = (): ThunkAction => {
|
|
|
|
|
const warnings: {[k: string]: string} = {};
|
|
|
|
|
const infos: {[k: string]: string} = {};
|
|
|
|
|
|
|
|
|
|
if (!state.untouched) {
|
|
|
|
|
if (state.untouched) return;
|
|
|
|
|
// valid address
|
|
|
|
|
if (state.touched.address) {
|
|
|
|
|
|
|
|
|
@ -334,7 +335,7 @@ export const validation = (): ThunkAction => {
|
|
|
|
|
const gl: BigNumber = new BigNumber(state.gasLimit);
|
|
|
|
|
if (gl.lessThan(1)) {
|
|
|
|
|
errors.gasLimit = 'Gas limit is too low';
|
|
|
|
|
} else if (gl.lessThan(1000)) {
|
|
|
|
|
} else if (gl.lessThan( state.selectedCurrency !== state.coinSymbol ? accountState.coin.defaultGasLimitTokens : accountState.coin.defaultGasLimit )) {
|
|
|
|
|
warnings.gasLimit = 'Gas limit is below recommended';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -348,14 +349,21 @@ export const validation = (): ThunkAction => {
|
|
|
|
|
errors.gasPrice = 'Gas price is not a number';
|
|
|
|
|
} else {
|
|
|
|
|
const gp: BigNumber = new BigNumber(state.gasPrice);
|
|
|
|
|
if (gp.greaterThan(100)) {
|
|
|
|
|
errors.gasPrice = 'Gas price is too high';
|
|
|
|
|
if (gp.greaterThan(1000)) {
|
|
|
|
|
warnings.gasPrice = 'Gas price is too high';
|
|
|
|
|
} else if (gp.lessThanOrEqualTo('0')) {
|
|
|
|
|
errors.gasPrice = 'Gas price is too low';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// valid nonce
|
|
|
|
|
if (state.touched.nonce) {
|
|
|
|
|
if (state.nonce.length < 1) {
|
|
|
|
|
errors.nonce = 'Nonce is not set';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// valid data
|
|
|
|
|
if (state.touched.data && state.data.length > 0) {
|
|
|
|
|
const re = /^[0-9A-Fa-f]+$/g;
|
|
|
|
@ -373,8 +381,6 @@ export const validation = (): ThunkAction => {
|
|
|
|
|
warnings,
|
|
|
|
|
infos
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -727,6 +733,27 @@ export const onGasLimitChange = (gasLimit: string): ThunkAction => {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const onNonceChange = (nonce: string): AsyncAction => {
|
|
|
|
|
return async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
|
|
|
|
const currentState: State = getState().sendForm;
|
|
|
|
|
const touched = { ...currentState.touched };
|
|
|
|
|
touched.nonce = true;
|
|
|
|
|
|
|
|
|
|
const state: State = {
|
|
|
|
|
...currentState,
|
|
|
|
|
untouched: false,
|
|
|
|
|
touched,
|
|
|
|
|
nonce,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SEND.NONCE_CHANGE,
|
|
|
|
|
state
|
|
|
|
|
});
|
|
|
|
|
dispatch( validation() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const onDataChange = (data: string): AsyncAction => {
|
|
|
|
|
return async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
|
|
|
|
const currentState: State = getState().sendForm;
|
|
|
|
@ -948,6 +975,7 @@ export default {
|
|
|
|
|
updateFeeLevels,
|
|
|
|
|
onGasPriceChange,
|
|
|
|
|
onGasLimitChange,
|
|
|
|
|
onNonceChange,
|
|
|
|
|
onDataChange,
|
|
|
|
|
onSend,
|
|
|
|
|
}
|
|
|
|
|