mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 09:18:09 +00:00
nonce in SendForm
This commit is contained in:
parent
e677a7580d
commit
aca4a26372
@ -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;
|
||||
|
@ -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) => {
|
||||
</div>
|
||||
);
|
||||
|
||||
const nonceTooltip = (
|
||||
<div className="tooltip-wrapper">
|
||||
Nonce is.....<br/>
|
||||
</div>
|
||||
);
|
||||
|
||||
const gasLimitTooltip = (
|
||||
<div className="tooltip-wrapper">
|
||||
Gas limit is the amount of gas to send with your transaction.<br/>
|
||||
@ -70,12 +75,12 @@ const AdvancedForm = (props: Props) => {
|
||||
<div className="advanced-container opened">
|
||||
<a className="advanced" onClick={ toggleAdvanced }>Advanced settings</a>
|
||||
<div className="row gas-row">
|
||||
{/* <div className="column nonce">
|
||||
<div className="column nonce">
|
||||
<label>
|
||||
Nonce
|
||||
<Tooltip
|
||||
arrowContent={<div className="rc-tooltip-arrow-inner"></div>}
|
||||
overlay={ gasLimitTooltip }
|
||||
overlay={ nonceTooltip }
|
||||
placement="top">
|
||||
<span className="what-is-it"></span>
|
||||
</Tooltip>
|
||||
@ -90,7 +95,7 @@ const AdvancedForm = (props: Props) => {
|
||||
onChange={ event => onNonceChange(event.target.value) } />
|
||||
{ errors.nonce ? (<span className="error">{ errors.nonce }</span>) : null }
|
||||
{ warnings.nonce ? (<span className="warning">{ warnings.nonce }</span>) : null }
|
||||
</div> */}
|
||||
</div>
|
||||
<div className="column">
|
||||
<label>
|
||||
Gas limit
|
||||
|
@ -106,7 +106,7 @@ const _render = (props: Props, state: AccountState): React$Element<string> => {
|
||||
buttonLabel = 'Loading accounts';
|
||||
buttonDisabled = true;
|
||||
}
|
||||
|
||||
|
||||
let notification = null;
|
||||
|
||||
return (
|
||||
|
@ -172,6 +172,7 @@ export default (state: State = initialState, action: Action): State => {
|
||||
...state,
|
||||
|
||||
sending: false,
|
||||
untouched: true,
|
||||
touched: {},
|
||||
address: '',
|
||||
amount: '',
|
||||
@ -180,12 +181,11 @@ export default (state: State = initialState, action: Action): State => {
|
||||
gasLimit: state.gasLimit,
|
||||
gasPrice: state.recommendedGasPrice,
|
||||
data: '',
|
||||
nonce: '0',
|
||||
nonce: new BigNumber(state.nonce).plus(1).toString(),
|
||||
total: '0',
|
||||
errors: {},
|
||||
warnings: {},
|
||||
infos: {},
|
||||
|
||||
}
|
||||
case SEND.TX_ERROR :
|
||||
return {
|
||||
@ -218,7 +218,6 @@ export default (state: State = initialState, action: Action): State => {
|
||||
nonce: action.nonce,
|
||||
untouched: false,
|
||||
touched: action.touched,
|
||||
|
||||
}
|
||||
|
||||
default:
|
||||
|
@ -62,8 +62,6 @@ const save = (dispatch: Dispatch, getState: GetState): void => {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
const load = (dispatch: Dispatch, getState: GetState): void => {
|
||||
@ -108,7 +106,8 @@ const load = (dispatch: Dispatch, getState: GetState): void => {
|
||||
if (json.setMax) {
|
||||
dispatch(SendFormActions.onSetMax());
|
||||
} else {
|
||||
dispatch(SendFormActions.validation());
|
||||
// dispatch(SendFormActions.validation());
|
||||
dispatch(SendFormActions.onAmountChange(json.amount));
|
||||
}
|
||||
|
||||
|
||||
@ -120,6 +119,16 @@ const load = (dispatch: Dispatch, getState: GetState): void => {
|
||||
}
|
||||
|
||||
|
||||
const clear = (getState: GetState) => {
|
||||
if (typeof window.localStorage === 'undefined') return;
|
||||
|
||||
const accountState = getState().abstractAccount;
|
||||
if (accountState) {
|
||||
const key: string = `SEND:${accountState.location}`;
|
||||
window.sessionStorage.removeItem(key);
|
||||
}
|
||||
}
|
||||
|
||||
const LocalStorageService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispatch) => (action: Action): Action => {
|
||||
|
||||
if (action.type === ACCOUNT.DISPOSE) {
|
||||
@ -137,6 +146,10 @@ const LocalStorageService: Middleware = (api: MiddlewareAPI) => (next: Middlewar
|
||||
case SEND.INIT :
|
||||
load(api.dispatch, api.getState);
|
||||
break;
|
||||
|
||||
case SEND.TX_COMPLETE :
|
||||
clear(api.getState);
|
||||
break;
|
||||
}
|
||||
|
||||
return action;
|
||||
|
Loading…
Reference in New Issue
Block a user