1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-24 09:18:09 +00:00

added (commented) NONCE in Sendform

This commit is contained in:
Szymon Lesisz 2018-05-11 15:20:11 +02:00
parent b8b8ed6a34
commit 9125fbcd61
5 changed files with 180 additions and 120 deletions

View File

@ -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,
}

View File

@ -11,6 +11,7 @@ export const CURRENCY_CHANGE: 'send__currency_change' = 'send__currency_change';
export const FEE_LEVEL_CHANGE: 'send__fee_level_change' = 'send__fee_level_change';
export const GAS_PRICE_CHANGE: 'send__gas_price_change' = 'send__gas_price_change';
export const GAS_LIMIT_CHANGE: 'send__gas_limit_change' = 'send__gas_limit_change';
export const NONCE_CHANGE: 'send__nonce_change' = 'send__nonce_change';
export const UPDATE_FEE_LEVELS: 'send__update_fee_levels' = 'send__update_fee_levels';
export const DATA_CHANGE: 'send__data_change' = 'send__data_change';
export const SEND: 'send__submit' = 'send__submit';

View File

@ -17,6 +17,7 @@ const AdvancedForm = (props: Props) => {
selectedCurrency,
gasPrice,
gasLimit,
nonce,
data,
errors,
warnings,
@ -28,6 +29,7 @@ const AdvancedForm = (props: Props) => {
toggleAdvanced,
onGasPriceChange,
onGasLimitChange,
onNonceChange,
onDataChange
} = props.sendFormActions;
@ -68,6 +70,27 @@ 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">
<label>
Nonce
<Tooltip
arrowContent={<div className="rc-tooltip-arrow-inner"></div>}
overlay={ gasLimitTooltip }
placement="top">
<span className="what-is-it"></span>
</Tooltip>
</label>
<input
type="text"
autoComplete="off"
autoCorrect="off"
autoCapitalize="off"
spellCheck="false"
value={ nonce }
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 className="column">
<label>
Gas limit

View File

@ -157,6 +157,7 @@ export default (state: State = initialState, action: Action): State => {
case SEND.UPDATE_FEE_LEVELS :
case SEND.GAS_PRICE_CHANGE :
case SEND.GAS_LIMIT_CHANGE :
case SEND.NONCE_CHANGE :
case SEND.DATA_CHANGE :
return action.state;

View File

@ -68,6 +68,7 @@
bottom: 6px;
font-size: 12px;
color: @color_error_primary;
white-space: nowrap;
}
.error {
@ -255,6 +256,11 @@
flex: 1;
padding-right: 20px;
&.nonce {
width: 100px;
flex: none;
}
&:last-child {
padding-right: 0px;
}
@ -264,6 +270,7 @@
.info {
left: 0;
bottom: -17px;
white-space: nowrap;
}
}
}