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);
|
const web3instance: ?Web3Instance = getState().web3.find(w3 => w3.network === urlParams.network);
|
||||||
if (!web3instance) return;
|
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
|
// TODO: check if there are some unfinished tx in localStorage
|
||||||
|
|
||||||
const coin: Coin = accountState.coin;
|
const coin: Coin = accountState.coin;
|
||||||
@ -229,7 +232,7 @@ export const init = (): ThunkAction => {
|
|||||||
recommendedGasPrice: gasPrice.toString(),
|
recommendedGasPrice: gasPrice.toString(),
|
||||||
gasLimit,
|
gasLimit,
|
||||||
gasPrice: gasPrice.toString(),
|
gasPrice: gasPrice.toString(),
|
||||||
nonce: '', // TODO!!!
|
nonce: account.nonce.toString(), // TODO!!!
|
||||||
};
|
};
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
@ -301,7 +304,7 @@ export const validation = (): ThunkAction => {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
const account: ?Account = findAccount(getState().accounts, accountState.index, accountState.deviceState, accountState.network);
|
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;
|
let decimalRegExp: RegExp;
|
||||||
|
|
||||||
@ -372,15 +375,27 @@ export const validation = (): ThunkAction => {
|
|||||||
|
|
||||||
// valid nonce
|
// valid nonce
|
||||||
if (state.touched.nonce) {
|
if (state.touched.nonce) {
|
||||||
|
const re = new RegExp('^[0-9]+$');
|
||||||
if (state.nonce.length < 1) {
|
if (state.nonce.length < 1) {
|
||||||
errors.nonce = 'Nonce is not set';
|
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
|
// valid data
|
||||||
if (state.touched.data && state.data.length > 0) {
|
if (state.touched.data && state.data.length > 0) {
|
||||||
const re = /^[0-9A-Fa-f]+$/g;
|
const re = /^[0-9A-Fa-f]+$/g;
|
||||||
//const re = /^[0-9A-Fa-f]{6}$/g;
|
|
||||||
if (!re.test(state.data)) {
|
if (!re.test(state.data)) {
|
||||||
errors.data = 'Data is not valid hexadecimal';
|
errors.data = 'Data is not valid hexadecimal';
|
||||||
}
|
}
|
||||||
@ -649,7 +664,7 @@ export const onGasPriceChange = (gasPrice: string): ThunkAction => {
|
|||||||
const accountState: ?AccountState = getState().abstractAccount;
|
const accountState: ?AccountState = getState().abstractAccount;
|
||||||
if (!accountState) return;
|
if (!accountState) return;
|
||||||
const currentState: State = getState().sendForm;
|
const currentState: State = getState().sendForm;
|
||||||
const isToken: boolean = currentState.selectedCurrency !== accountState.network;
|
const isToken: boolean = currentState.selectedCurrency !== currentState.coinSymbol;
|
||||||
|
|
||||||
const touched = { ...currentState.touched };
|
const touched = { ...currentState.touched };
|
||||||
touched.gasPrice = true;
|
touched.gasPrice = true;
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Tooltip from 'rc-tooltip';
|
import Tooltip from 'rc-tooltip';
|
||||||
|
|
||||||
import type { Props } from './index';
|
import type { Props } from './index';
|
||||||
|
|
||||||
const AdvancedForm = (props: Props) => {
|
const AdvancedForm = (props: Props) => {
|
||||||
@ -40,6 +39,12 @@ const AdvancedForm = (props: Props) => {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const nonceTooltip = (
|
||||||
|
<div className="tooltip-wrapper">
|
||||||
|
Nonce is.....<br/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
const gasLimitTooltip = (
|
const gasLimitTooltip = (
|
||||||
<div className="tooltip-wrapper">
|
<div className="tooltip-wrapper">
|
||||||
Gas limit is the amount of gas to send with your transaction.<br/>
|
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">
|
<div className="advanced-container opened">
|
||||||
<a className="advanced" onClick={ toggleAdvanced }>Advanced settings</a>
|
<a className="advanced" onClick={ toggleAdvanced }>Advanced settings</a>
|
||||||
<div className="row gas-row">
|
<div className="row gas-row">
|
||||||
{/* <div className="column nonce">
|
<div className="column nonce">
|
||||||
<label>
|
<label>
|
||||||
Nonce
|
Nonce
|
||||||
<Tooltip
|
<Tooltip
|
||||||
arrowContent={<div className="rc-tooltip-arrow-inner"></div>}
|
arrowContent={<div className="rc-tooltip-arrow-inner"></div>}
|
||||||
overlay={ gasLimitTooltip }
|
overlay={ nonceTooltip }
|
||||||
placement="top">
|
placement="top">
|
||||||
<span className="what-is-it"></span>
|
<span className="what-is-it"></span>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
@ -90,7 +95,7 @@ const AdvancedForm = (props: Props) => {
|
|||||||
onChange={ event => onNonceChange(event.target.value) } />
|
onChange={ event => onNonceChange(event.target.value) } />
|
||||||
{ errors.nonce ? (<span className="error">{ errors.nonce }</span>) : null }
|
{ errors.nonce ? (<span className="error">{ errors.nonce }</span>) : null }
|
||||||
{ warnings.nonce ? (<span className="warning">{ warnings.nonce }</span>) : null }
|
{ warnings.nonce ? (<span className="warning">{ warnings.nonce }</span>) : null }
|
||||||
</div> */}
|
</div>
|
||||||
<div className="column">
|
<div className="column">
|
||||||
<label>
|
<label>
|
||||||
Gas limit
|
Gas limit
|
||||||
|
@ -172,6 +172,7 @@ export default (state: State = initialState, action: Action): State => {
|
|||||||
...state,
|
...state,
|
||||||
|
|
||||||
sending: false,
|
sending: false,
|
||||||
|
untouched: true,
|
||||||
touched: {},
|
touched: {},
|
||||||
address: '',
|
address: '',
|
||||||
amount: '',
|
amount: '',
|
||||||
@ -180,12 +181,11 @@ export default (state: State = initialState, action: Action): State => {
|
|||||||
gasLimit: state.gasLimit,
|
gasLimit: state.gasLimit,
|
||||||
gasPrice: state.recommendedGasPrice,
|
gasPrice: state.recommendedGasPrice,
|
||||||
data: '',
|
data: '',
|
||||||
nonce: '0',
|
nonce: new BigNumber(state.nonce).plus(1).toString(),
|
||||||
total: '0',
|
total: '0',
|
||||||
errors: {},
|
errors: {},
|
||||||
warnings: {},
|
warnings: {},
|
||||||
infos: {},
|
infos: {},
|
||||||
|
|
||||||
}
|
}
|
||||||
case SEND.TX_ERROR :
|
case SEND.TX_ERROR :
|
||||||
return {
|
return {
|
||||||
@ -218,7 +218,6 @@ export default (state: State = initialState, action: Action): State => {
|
|||||||
nonce: action.nonce,
|
nonce: action.nonce,
|
||||||
untouched: false,
|
untouched: false,
|
||||||
touched: action.touched,
|
touched: action.touched,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -62,8 +62,6 @@ const save = (dispatch: Dispatch, getState: GetState): void => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const load = (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) {
|
if (json.setMax) {
|
||||||
dispatch(SendFormActions.onSetMax());
|
dispatch(SendFormActions.onSetMax());
|
||||||
} else {
|
} 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 => {
|
const LocalStorageService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispatch) => (action: Action): Action => {
|
||||||
|
|
||||||
if (action.type === ACCOUNT.DISPOSE) {
|
if (action.type === ACCOUNT.DISPOSE) {
|
||||||
@ -137,6 +146,10 @@ const LocalStorageService: Middleware = (api: MiddlewareAPI) => (next: Middlewar
|
|||||||
case SEND.INIT :
|
case SEND.INIT :
|
||||||
load(api.dispatch, api.getState);
|
load(api.dispatch, api.getState);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SEND.TX_COMPLETE :
|
||||||
|
clear(api.getState);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return action;
|
return action;
|
||||||
|
Loading…
Reference in New Issue
Block a user