|
|
|
@ -1,20 +1,17 @@
|
|
|
|
|
/* @flow */
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
import * as SEND from './constants/send';
|
|
|
|
|
import * as NOTIFICATION from './constants/notification';
|
|
|
|
|
|
|
|
|
|
import * as SessionStorageActions from './SessionStorageActions';
|
|
|
|
|
|
|
|
|
|
import { estimateGas, getGasPrice, pushTx } from './Web3Actions';
|
|
|
|
|
|
|
|
|
|
import EthereumjsUtil from 'ethereumjs-util';
|
|
|
|
|
import EthereumjsUnits from 'ethereumjs-units';
|
|
|
|
|
import EthereumjsTx from 'ethereumjs-tx';
|
|
|
|
|
import TrezorConnect from 'trezor-connect';
|
|
|
|
|
import { strip } from '../utils/ethUtils';
|
|
|
|
|
import { push } from 'react-router-redux';
|
|
|
|
|
import BigNumber from 'bignumber.js';
|
|
|
|
|
import { strip } from '../utils/ethUtils';
|
|
|
|
|
import { estimateGas, getGasPrice, pushTx } from './Web3Actions';
|
|
|
|
|
import * as SessionStorageActions from './SessionStorageActions';
|
|
|
|
|
import * as NOTIFICATION from './constants/notification';
|
|
|
|
|
import * as SEND from './constants/send';
|
|
|
|
|
|
|
|
|
|
import { initialState } from '../reducers/SendFormReducer';
|
|
|
|
|
import { findAccount } from '../reducers/AccountsReducer';
|
|
|
|
@ -30,7 +27,7 @@ import type {
|
|
|
|
|
ThunkAction,
|
|
|
|
|
AsyncAction,
|
|
|
|
|
RouterLocationState,
|
|
|
|
|
TrezorDevice
|
|
|
|
|
TrezorDevice,
|
|
|
|
|
} from '~/flowtype';
|
|
|
|
|
import type { State as AccountState } from '../reducers/SelectedAccountReducer';
|
|
|
|
|
import type { Web3Instance } from '../reducers/Web3Reducer';
|
|
|
|
@ -128,7 +125,7 @@ export const calculateFee = (gasPrice: string, gasLimit: string): string => {
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return '0';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const calculateTotal = (amount: string, gasPrice: string, gasLimit: string): string => {
|
|
|
|
|
try {
|
|
|
|
@ -136,7 +133,7 @@ export const calculateTotal = (amount: string, gasPrice: string, gasLimit: strin
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return '0';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const calculateMaxAmount = (balance: BigNumber, gasPrice: string, gasLimit: string): string => {
|
|
|
|
|
try {
|
|
|
|
@ -148,8 +145,7 @@ export const calculateMaxAmount = (balance: BigNumber, gasPrice: string, gasLimi
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return '0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const calculate = (prevProps: Props, props: Props) => {
|
|
|
|
|
const {
|
|
|
|
@ -173,7 +169,6 @@ export const calculate = (prevProps: Props, props: Props) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (state.setMax) {
|
|
|
|
|
|
|
|
|
|
const pendingAmount: BigNumber = stateUtils.getPendingAmount(pending, state.currency, isToken);
|
|
|
|
|
|
|
|
|
|
if (isToken) {
|
|
|
|
@ -195,11 +190,11 @@ export const calculate = (prevProps: Props, props: Props) => {
|
|
|
|
|
state.selectedFeeLevel.label = `${calculateFee(state.gasPrice, state.gasLimit)} ${state.networkSymbol}`;
|
|
|
|
|
state.selectedFeeLevel.gasPrice = state.gasPrice;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getFeeLevels = (symbol: string, gasPrice: BigNumber | string, gasLimit: string, selected?: FeeLevel): Array<FeeLevel> => {
|
|
|
|
|
const price: BigNumber = typeof gasPrice === 'string' ? new BigNumber(gasPrice) : gasPrice
|
|
|
|
|
const price: BigNumber = typeof gasPrice === 'string' ? new BigNumber(gasPrice) : gasPrice;
|
|
|
|
|
const quarter: BigNumber = price.dividedBy(4);
|
|
|
|
|
const high: string = price.plus(quarter.times(2)).toString(10);
|
|
|
|
|
const low: string = price.minus(quarter.times(2)).toString(10);
|
|
|
|
@ -208,42 +203,40 @@ export const getFeeLevels = (symbol: string, gasPrice: BigNumber | string, gasLi
|
|
|
|
|
value: 'Custom',
|
|
|
|
|
gasPrice: selected.gasPrice,
|
|
|
|
|
// label: `${ calculateFee(gasPrice, gasLimit) } ${ symbol }`
|
|
|
|
|
label: `${ calculateFee(selected.gasPrice, gasLimit) } ${ symbol }`
|
|
|
|
|
label: `${calculateFee(selected.gasPrice, gasLimit)} ${symbol}`,
|
|
|
|
|
} : {
|
|
|
|
|
value: 'Custom',
|
|
|
|
|
gasPrice: low,
|
|
|
|
|
label: ''
|
|
|
|
|
}
|
|
|
|
|
label: '',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
value: 'High',
|
|
|
|
|
gasPrice: high,
|
|
|
|
|
label: `${ calculateFee(high, gasLimit) } ${ symbol }`
|
|
|
|
|
label: `${calculateFee(high, gasLimit)} ${symbol}`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'Normal',
|
|
|
|
|
gasPrice: gasPrice.toString(),
|
|
|
|
|
label: `${ calculateFee(price.toString(10), gasLimit) } ${ symbol }`
|
|
|
|
|
label: `${calculateFee(price.toString(10), gasLimit)} ${symbol}`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'Low',
|
|
|
|
|
gasPrice: low,
|
|
|
|
|
label: `${ calculateFee(low, gasLimit) } ${ symbol }`
|
|
|
|
|
label: `${calculateFee(low, gasLimit)} ${symbol}`,
|
|
|
|
|
},
|
|
|
|
|
customLevel
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
customLevel,
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// initialize component
|
|
|
|
|
export const init = (): ThunkAction => {
|
|
|
|
|
return (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
|
|
|
|
|
export const init = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
const {
|
|
|
|
|
account,
|
|
|
|
|
network,
|
|
|
|
|
web3
|
|
|
|
|
web3,
|
|
|
|
|
} = getState().selectedAccount;
|
|
|
|
|
|
|
|
|
|
if (!account || !network || !web3) return;
|
|
|
|
@ -252,7 +245,7 @@ export const init = (): ThunkAction => {
|
|
|
|
|
if (stateFromStorage) {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SEND.INIT,
|
|
|
|
|
state: stateFromStorage
|
|
|
|
|
state: stateFromStorage,
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -280,20 +273,16 @@ export const init = (): ThunkAction => {
|
|
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SEND.INIT,
|
|
|
|
|
state
|
|
|
|
|
state,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const toggleAdvanced = (address: string): Action => {
|
|
|
|
|
return {
|
|
|
|
|
type: SEND.TOGGLE_ADVANCED
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
export const toggleAdvanced = (address: string): Action => ({
|
|
|
|
|
type: SEND.TOGGLE_ADVANCED,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const addressValidation = (): ThunkAction => {
|
|
|
|
|
return (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
const addressValidation = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
const {
|
|
|
|
|
account,
|
|
|
|
|
network,
|
|
|
|
@ -322,7 +311,7 @@ const addressValidation = (): ThunkAction => {
|
|
|
|
|
const otherNetworkAccount = savedAccounts[0];
|
|
|
|
|
const device: ?TrezorDevice = findDevice(getState().devices, otherNetworkAccount.deviceID, otherNetworkAccount.deviceState);
|
|
|
|
|
const coins = getState().localStorage.config.coins;
|
|
|
|
|
const otherNetwork: ?Coin = coins.find(c => c.network === otherNetworkAccount.network)
|
|
|
|
|
const otherNetwork: ?Coin = coins.find(c => c.network === otherNetworkAccount.network);
|
|
|
|
|
if (device && otherNetwork) {
|
|
|
|
|
warnings.address = `Looks like it's ${device.instanceLabel} Account #${(otherNetworkAccount.index + 1)} address of ${otherNetwork.name} network`;
|
|
|
|
|
}
|
|
|
|
@ -337,15 +326,13 @@ const addressValidation = (): ThunkAction => {
|
|
|
|
|
state: {
|
|
|
|
|
...state,
|
|
|
|
|
infos,
|
|
|
|
|
warnings
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
warnings,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const validation = (props: Props): void => {
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
account,
|
|
|
|
|
network,
|
|
|
|
@ -388,7 +375,6 @@ export const validation = (props: Props): void => {
|
|
|
|
|
} else if (state.amount.length > 0 && !state.amount.match(numberRegExp)) {
|
|
|
|
|
errors.amount = 'Amount is not a number';
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
let decimalRegExp: RegExp;
|
|
|
|
|
const pendingAmount: BigNumber = stateUtils.getPendingAmount(pending, state.currency, state.currency !== state.networkSymbol);
|
|
|
|
|
|
|
|
|
@ -397,7 +383,7 @@ export const validation = (props: Props): void => {
|
|
|
|
|
if (token) {
|
|
|
|
|
if (parseInt(token.decimals) > 0) {
|
|
|
|
|
//decimalRegExp = new RegExp('^(0|0\\.([0-9]{0,' + token.decimals + '})?|[1-9]+\\.?([0-9]{0,' + token.decimals + '})?|\\.[0-9]{1,' + token.decimals + '})$');
|
|
|
|
|
decimalRegExp = new RegExp('^(0|0\\.([0-9]{0,' + token.decimals + '})?|[1-9][0-9]*\\.?([0-9]{0,' + token.decimals + '})?|\\.[0-9]{1,' + token.decimals + '})$');
|
|
|
|
|
decimalRegExp = new RegExp(`^(0|0\\.([0-9]{0,${token.decimals}})?|[1-9][0-9]*\\.?([0-9]{0,${token.decimals}})?|\\.[0-9]{1,${token.decimals}})$`);
|
|
|
|
|
} else {
|
|
|
|
|
// decimalRegExp = new RegExp('^(0|0\\.?|[1-9]+\\.?)$');
|
|
|
|
|
decimalRegExp = new RegExp('^[0-9]+$');
|
|
|
|
@ -413,11 +399,10 @@ export const validation = (props: Props): void => {
|
|
|
|
|
errors.amount = 'Amount is too low';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
decimalRegExp = new RegExp('^(0|0\\.([0-9]{0,18})?|[1-9][0-9]*\\.?([0-9]{0,18})?|\\.[0-9]{0,18})$');
|
|
|
|
|
if (!state.amount.match(decimalRegExp)) {
|
|
|
|
|
errors.amount = `Maximum 18 decimals allowed`;
|
|
|
|
|
errors.amount = 'Maximum 18 decimals allowed';
|
|
|
|
|
} else if (new BigNumber(state.total).greaterThan(new BigNumber(account.balance).minus(pendingAmount))) {
|
|
|
|
|
errors.amount = 'Not enough funds';
|
|
|
|
|
}
|
|
|
|
@ -487,14 +472,10 @@ export const validation = (props: Props): void => {
|
|
|
|
|
state.errors = errors;
|
|
|
|
|
state.warnings = warnings;
|
|
|
|
|
state.infos = infos;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const onAddressChange = (address: string): ThunkAction => {
|
|
|
|
|
return (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
export const onAddressChange = (address: string): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
const state: State = getState().sendForm;
|
|
|
|
|
const touched = { ...state.touched };
|
|
|
|
|
touched.address = true;
|
|
|
|
@ -505,16 +486,14 @@ export const onAddressChange = (address: string): ThunkAction => {
|
|
|
|
|
...state,
|
|
|
|
|
untouched: false,
|
|
|
|
|
touched,
|
|
|
|
|
address
|
|
|
|
|
}
|
|
|
|
|
address,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
dispatch(addressValidation());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const onAmountChange = (amount: string): ThunkAction => {
|
|
|
|
|
return (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
export const onAmountChange = (amount: string): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
const state = getState().sendForm;
|
|
|
|
|
const touched = { ...state.touched };
|
|
|
|
|
touched.amount = true;
|
|
|
|
@ -527,16 +506,14 @@ export const onAmountChange = (amount: string): ThunkAction => {
|
|
|
|
|
touched,
|
|
|
|
|
setMax: false,
|
|
|
|
|
amount,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const onCurrencyChange = (currency: { value: string, label: string }): ThunkAction => {
|
|
|
|
|
return (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
export const onCurrencyChange = (currency: { value: string, label: string }): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
const {
|
|
|
|
|
account,
|
|
|
|
|
network
|
|
|
|
|
network,
|
|
|
|
|
} = getState().selectedAccount;
|
|
|
|
|
if (!account || !network) return;
|
|
|
|
|
|
|
|
|
@ -560,13 +537,11 @@ export const onCurrencyChange = (currency: { value: string, label: string }): Th
|
|
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SEND.CURRENCY_CHANGE,
|
|
|
|
|
state
|
|
|
|
|
state,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const onSetMax = (): ThunkAction => {
|
|
|
|
|
return (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
export const onSetMax = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
const state = getState().sendForm;
|
|
|
|
|
const touched = { ...state.touched };
|
|
|
|
|
touched.amount = true;
|
|
|
|
@ -578,15 +553,13 @@ export const onSetMax = (): ThunkAction => {
|
|
|
|
|
untouched: false,
|
|
|
|
|
touched,
|
|
|
|
|
setMax: !state.setMax,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const onFeeLevelChange = (feeLevel: FeeLevel): ThunkAction => {
|
|
|
|
|
return (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
export const onFeeLevelChange = (feeLevel: FeeLevel): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
const {
|
|
|
|
|
network
|
|
|
|
|
network,
|
|
|
|
|
} = getState().selectedAccount;
|
|
|
|
|
if (!network) return;
|
|
|
|
|
|
|
|
|
@ -605,11 +578,10 @@ export const onFeeLevelChange = (feeLevel: FeeLevel): ThunkAction => {
|
|
|
|
|
feeLevel.label = `${calculateFee(state.gasPrice, state.gasLimit)} ${state.networkSymbol}`;
|
|
|
|
|
} else {
|
|
|
|
|
const customLevel: ?FeeLevel = state.feeLevels.find(f => f.value === 'Custom');
|
|
|
|
|
if (customLevel)
|
|
|
|
|
customLevel.label = '';
|
|
|
|
|
if (customLevel) customLevel.label = '';
|
|
|
|
|
state.gasPrice = feeLevel.gasPrice;
|
|
|
|
|
if (isToken) {
|
|
|
|
|
state.gasLimit = network.defaultGasLimitTokens.toString()
|
|
|
|
|
state.gasLimit = network.defaultGasLimitTokens.toString();
|
|
|
|
|
} else {
|
|
|
|
|
state.gasLimit = state.data.length > 0 ? state.gasLimit : network.defaultGasLimit.toString();
|
|
|
|
|
}
|
|
|
|
@ -617,19 +589,17 @@ export const onFeeLevelChange = (feeLevel: FeeLevel): ThunkAction => {
|
|
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SEND.FEE_LEVEL_CHANGE,
|
|
|
|
|
state
|
|
|
|
|
state,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Manually triggered from user
|
|
|
|
|
// Update gasPrice to recommended value
|
|
|
|
|
|
|
|
|
|
export const updateFeeLevels = (): ThunkAction => {
|
|
|
|
|
return (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
export const updateFeeLevels = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
const {
|
|
|
|
|
account,
|
|
|
|
|
network
|
|
|
|
|
network,
|
|
|
|
|
} = getState().selectedAccount;
|
|
|
|
|
if (!account || !network) return;
|
|
|
|
|
|
|
|
|
@ -659,14 +629,11 @@ export const updateFeeLevels = (): ThunkAction => {
|
|
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SEND.UPDATE_FEE_LEVELS,
|
|
|
|
|
state
|
|
|
|
|
state,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const onGasPriceChange = (gasPrice: string): ThunkAction => {
|
|
|
|
|
return (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const onGasPriceChange = (gasPrice: string): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
const currentState: State = getState().sendForm;
|
|
|
|
|
const isToken: boolean = currentState.currency !== currentState.networkSymbol;
|
|
|
|
|
|
|
|
|
@ -677,7 +644,7 @@ export const onGasPriceChange = (gasPrice: string): ThunkAction => {
|
|
|
|
|
...currentState,
|
|
|
|
|
untouched: false,
|
|
|
|
|
touched,
|
|
|
|
|
gasPrice: gasPrice,
|
|
|
|
|
gasPrice,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (currentState.selectedFeeLevel.value !== 'Custom') {
|
|
|
|
@ -688,14 +655,11 @@ export const onGasPriceChange = (gasPrice: string): ThunkAction => {
|
|
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SEND.GAS_PRICE_CHANGE,
|
|
|
|
|
state
|
|
|
|
|
state,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const onGasLimitChange = (gasLimit: string, updateFeeLevels: boolean = false): ThunkAction => {
|
|
|
|
|
return (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const onGasLimitChange = (gasLimit: string, updateFeeLevels: boolean = false): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
const currentState: State = getState().sendForm;
|
|
|
|
|
const isToken: boolean = currentState.currency !== currentState.networkSymbol;
|
|
|
|
|
|
|
|
|
@ -718,13 +682,11 @@ export const onGasLimitChange = (gasLimit: string, updateFeeLevels: boolean = fa
|
|
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SEND.GAS_LIMIT_CHANGE,
|
|
|
|
|
state
|
|
|
|
|
state,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const onNonceChange = (nonce: string): AsyncAction => {
|
|
|
|
|
return async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
|
|
|
|
export const onNonceChange = (nonce: string): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
|
|
|
|
const currentState: State = getState().sendForm;
|
|
|
|
|
const touched = { ...currentState.touched };
|
|
|
|
|
touched.nonce = true;
|
|
|
|
@ -738,13 +700,11 @@ export const onNonceChange = (nonce: string): AsyncAction => {
|
|
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SEND.NONCE_CHANGE,
|
|
|
|
|
state
|
|
|
|
|
state,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const onDataChange = (data: string): AsyncAction => {
|
|
|
|
|
return async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
|
|
|
|
export const onDataChange = (data: string): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
|
|
|
|
const currentState: State = getState().sendForm;
|
|
|
|
|
const touched = { ...currentState.touched };
|
|
|
|
|
touched.data = true;
|
|
|
|
@ -765,20 +725,17 @@ export const onDataChange = (data: string): AsyncAction => {
|
|
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SEND.DATA_CHANGE,
|
|
|
|
|
state
|
|
|
|
|
state,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
dispatch(estimateGasPrice());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const estimateGasPrice = (): AsyncAction => {
|
|
|
|
|
return async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
|
|
|
|
|
|
|
|
|
const estimateGasPrice = (): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
|
|
|
|
const {
|
|
|
|
|
web3,
|
|
|
|
|
network
|
|
|
|
|
network,
|
|
|
|
|
} = getState().selectedAccount;
|
|
|
|
|
if (!web3 || !network) return;
|
|
|
|
|
|
|
|
|
@ -801,7 +758,7 @@ const estimateGasPrice = (): AsyncAction => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: allow data starting with 0x ...
|
|
|
|
|
const data: string = '0x' + (state.data.length % 2 === 0 ? state.data : '0' + state.data);
|
|
|
|
|
const data: string = `0x${state.data.length % 2 === 0 ? state.data : `0${state.data}`}`;
|
|
|
|
|
const gasLimit = await estimateGas(w3, {
|
|
|
|
|
to: '0x0000000000000000000000000000000000000000',
|
|
|
|
|
data,
|
|
|
|
@ -812,18 +769,14 @@ const estimateGasPrice = (): AsyncAction => {
|
|
|
|
|
if (getState().sendForm.data === requestedData) {
|
|
|
|
|
dispatch(onGasLimitChange(gasLimit.toString()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const onSend = (): AsyncAction => {
|
|
|
|
|
return async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const onSend = (): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
|
|
|
|
const {
|
|
|
|
|
account,
|
|
|
|
|
network,
|
|
|
|
|
web3,
|
|
|
|
|
pending
|
|
|
|
|
pending,
|
|
|
|
|
} = getState().selectedAccount;
|
|
|
|
|
if (!account || !web3 || !network) return;
|
|
|
|
|
|
|
|
|
@ -834,7 +787,7 @@ export const onSend = (): AsyncAction => {
|
|
|
|
|
|
|
|
|
|
const address_n = account.addressPath;
|
|
|
|
|
|
|
|
|
|
let data: string = '0x' + currentState.data;
|
|
|
|
|
let data: string = `0x${currentState.data}`;
|
|
|
|
|
let txAmount: string = w3.toHex(w3.toWei(currentState.amount, 'ether'));
|
|
|
|
|
let txAddress: string = currentState.address;
|
|
|
|
|
if (isToken) {
|
|
|
|
@ -847,7 +800,7 @@ export const onSend = (): AsyncAction => {
|
|
|
|
|
data = contract.transfer.getData(currentState.address, amountValue, {
|
|
|
|
|
from: account.address,
|
|
|
|
|
gasLimit: currentState.gasLimit,
|
|
|
|
|
gasPrice: currentState.gasPrice
|
|
|
|
|
gasPrice: currentState.gasPrice,
|
|
|
|
|
});
|
|
|
|
|
txAmount = '0x00';
|
|
|
|
|
txAddress = token.address;
|
|
|
|
@ -856,7 +809,7 @@ export const onSend = (): AsyncAction => {
|
|
|
|
|
const pendingNonce: number = stateUtils.getPendingNonce(pending);
|
|
|
|
|
const nonce = pendingNonce > 0 && pendingNonce >= account.nonce ? pendingNonce : account.nonce;
|
|
|
|
|
|
|
|
|
|
console.warn("NONCE", nonce, account.nonce, pendingNonce)
|
|
|
|
|
console.warn('NONCE', nonce, account.nonce, pendingNonce);
|
|
|
|
|
|
|
|
|
|
const txData = {
|
|
|
|
|
address_n,
|
|
|
|
@ -870,17 +823,17 @@ export const onSend = (): AsyncAction => {
|
|
|
|
|
gasPrice: w3.toHex(EthereumjsUnits.convert(currentState.gasPrice, 'gwei', 'wei')),
|
|
|
|
|
r: '',
|
|
|
|
|
s: '',
|
|
|
|
|
v: ''
|
|
|
|
|
}
|
|
|
|
|
v: '',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const selected: ?TrezorDevice = getState().wallet.selectedDevice;
|
|
|
|
|
if (!selected) return;
|
|
|
|
|
|
|
|
|
|
let signedTransaction = await TrezorConnect.ethereumSignTransaction({
|
|
|
|
|
const signedTransaction = await TrezorConnect.ethereumSignTransaction({
|
|
|
|
|
device: {
|
|
|
|
|
path: selected.path,
|
|
|
|
|
instance: selected.instance,
|
|
|
|
|
state: selected.state
|
|
|
|
|
state: selected.state,
|
|
|
|
|
},
|
|
|
|
|
useEmptyPassphrase: !selected.instance,
|
|
|
|
|
path: txData.address_n,
|
|
|
|
@ -890,11 +843,10 @@ export const onSend = (): AsyncAction => {
|
|
|
|
|
to: strip(txData.to),
|
|
|
|
|
value: strip(txData.value),
|
|
|
|
|
data: strip(txData.data),
|
|
|
|
|
chainId: txData.chainId
|
|
|
|
|
chainId: txData.chainId,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!signedTransaction || !signedTransaction.success) {
|
|
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
type: NOTIFICATION.ADD,
|
|
|
|
|
payload: {
|
|
|
|
@ -902,26 +854,25 @@ export const onSend = (): AsyncAction => {
|
|
|
|
|
title: 'Transaction error',
|
|
|
|
|
message: signedTransaction.payload.error,
|
|
|
|
|
cancelable: true,
|
|
|
|
|
actions: [ ]
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
actions: [],
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
txData.r = '0x' + signedTransaction.payload.r;
|
|
|
|
|
txData.s = '0x' + signedTransaction.payload.s;
|
|
|
|
|
txData.r = `0x${signedTransaction.payload.r}`;
|
|
|
|
|
txData.s = `0x${signedTransaction.payload.s}`;
|
|
|
|
|
txData.v = w3.toHex(signedTransaction.payload.v);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const tx = new EthereumjsTx(txData);
|
|
|
|
|
const serializedTx = '0x' + tx.serialize().toString('hex');
|
|
|
|
|
const serializedTx = `0x${tx.serialize().toString('hex')}`;
|
|
|
|
|
const txid: string = await pushTx(w3, serializedTx);
|
|
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SEND.TX_COMPLETE,
|
|
|
|
|
account: account,
|
|
|
|
|
account,
|
|
|
|
|
selectedCurrency: currentState.currency,
|
|
|
|
|
amount: currentState.amount,
|
|
|
|
|
total: currentState.total,
|
|
|
|
@ -945,12 +896,10 @@ export const onSend = (): AsyncAction => {
|
|
|
|
|
title: 'Transaction success',
|
|
|
|
|
message: `<a href="${network.explorer.tx}${txid}" class="green" target="_blank" rel="noreferrer noopener">See transaction detail</a>`,
|
|
|
|
|
cancelable: true,
|
|
|
|
|
actions: []
|
|
|
|
|
}
|
|
|
|
|
actions: [],
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
type: NOTIFICATION.ADD,
|
|
|
|
|
payload: {
|
|
|
|
@ -958,12 +907,11 @@ export const onSend = (): AsyncAction => {
|
|
|
|
|
title: 'Transaction error',
|
|
|
|
|
message: error.message || error,
|
|
|
|
|
cancelable: true,
|
|
|
|
|
actions: [ ]
|
|
|
|
|
}
|
|
|
|
|
actions: [],
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
toggleAdvanced,
|
|
|
|
@ -978,4 +926,4 @@ export default {
|
|
|
|
|
onNonceChange,
|
|
|
|
|
onDataChange,
|
|
|
|
|
onSend,
|
|
|
|
|
}
|
|
|
|
|
};
|