diff --git a/src/js/actions/SendFormActions.js b/src/js/actions/SendFormActions.js index f52a116b..0d255d6d 100644 --- a/src/js/actions/SendFormActions.js +++ b/src/js/actions/SendFormActions.js @@ -209,6 +209,9 @@ export const init = (): ThunkAction => { const web3instance: ?Web3Instance = getState().web3.find(w3 => w3.network === urlParams.network); if (!web3instance) return; + const account = getState().accounts.find(a => a.deviceState === accountState.deviceState && a.index === accountState.index && a.network === accountState.network); + if (!account) return; + // TODO: check if there are some unfinished tx in localStorage const coin: Coin = accountState.coin; @@ -229,7 +232,7 @@ export const init = (): ThunkAction => { recommendedGasPrice: gasPrice.toString(), gasLimit, gasPrice: gasPrice.toString(), - nonce: '', // TODO!!! + nonce: account.nonce.toString(), // TODO!!! }; dispatch({ @@ -301,7 +304,7 @@ export const validation = (): ThunkAction => { } else { const account: ?Account = findAccount(getState().accounts, accountState.index, accountState.deviceState, accountState.network); - if (!account) return; // this should not happen + if (!account) return; let decimalRegExp: RegExp; @@ -372,15 +375,27 @@ export const validation = (): ThunkAction => { // valid nonce if (state.touched.nonce) { + const re = new RegExp('^[0-9]+$'); if (state.nonce.length < 1) { errors.nonce = 'Nonce is not set'; + } else if (!state.nonce.match(re)) { + errors.nonce = 'Nonce is not a valid number'; + } else { + const account: ?Account = findAccount(getState().accounts, accountState.index, accountState.deviceState, accountState.network); + if (!account) return; + + const n: BigNumber = new BigNumber(state.nonce); + if (n.lessThan(account.nonce)) { + warnings.nonce = 'Nonce is lower than recommended'; + } else if (n.greaterThan(account.nonce)) { + warnings.nonce = 'Nonce is greater than recommended'; + } } } // valid data if (state.touched.data && state.data.length > 0) { const re = /^[0-9A-Fa-f]+$/g; - //const re = /^[0-9A-Fa-f]{6}$/g; if (!re.test(state.data)) { errors.data = 'Data is not valid hexadecimal'; } @@ -649,7 +664,7 @@ export const onGasPriceChange = (gasPrice: string): ThunkAction => { const accountState: ?AccountState = getState().abstractAccount; if (!accountState) return; const currentState: State = getState().sendForm; - const isToken: boolean = currentState.selectedCurrency !== accountState.network; + const isToken: boolean = currentState.selectedCurrency !== currentState.coinSymbol; const touched = { ...currentState.touched }; touched.gasPrice = true; diff --git a/src/js/components/wallet/send/AdvancedForm.js b/src/js/components/wallet/send/AdvancedForm.js index cc620983..9d092a20 100644 --- a/src/js/components/wallet/send/AdvancedForm.js +++ b/src/js/components/wallet/send/AdvancedForm.js @@ -3,7 +3,6 @@ import React from 'react'; import Tooltip from 'rc-tooltip'; - import type { Props } from './index'; const AdvancedForm = (props: Props) => { @@ -40,6 +39,12 @@ const AdvancedForm = (props: Props) => { ); + const nonceTooltip = ( +
+ Nonce is.....
+
+ ); + const gasLimitTooltip = (
Gas limit is the amount of gas to send with your transaction.
@@ -70,12 +75,12 @@ const AdvancedForm = (props: Props) => {
Advanced settings
- {/*
+
} - overlay={ gasLimitTooltip } + overlay={ nonceTooltip } placement="top"> @@ -90,7 +95,7 @@ const AdvancedForm = (props: Props) => { onChange={ event => onNonceChange(event.target.value) } /> { errors.nonce ? ({ errors.nonce }) : null } { warnings.nonce ? ({ warnings.nonce }) : null } -
*/} +