1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-12-30 19:00:53 +00:00

fix pending tx for ethereum networkType

This commit is contained in:
Szymon Lesisz 2018-12-03 20:22:49 +01:00
parent 2e89624b27
commit 90cc406773
5 changed files with 37 additions and 38 deletions

View File

@ -6,6 +6,7 @@ import BigNumber from 'bignumber.js';
import * as ACCOUNT from 'actions/constants/account';
import * as NOTIFICATION from 'actions/constants/notification';
import * as SEND from 'actions/constants/send';
import * as PENDING from 'actions/constants/pendingTx';
import * as WEB3 from 'actions/constants/web3';
import { initialState } from 'reducers/SendFormEthereumReducer';
import { findToken } from 'reducers/TokensReducer';
@ -480,7 +481,7 @@ export const onSend = (): AsyncAction => async (dispatch: Dispatch, getState: Ge
const currentState: State = getState().sendFormEthereum;
const isToken: boolean = currentState.currency !== currentState.networkSymbol;
const pendingNonce: number = reducerUtils.getPendingNonce(pending);
const pendingNonce: number = reducerUtils.getPendingSequence(pending);
const nonce = pendingNonce > 0 && pendingNonce >= account.nonce ? pendingNonce : account.nonce;
const txData = await dispatch(prepareEthereumTx({
@ -553,6 +554,22 @@ export const onSend = (): AsyncAction => async (dispatch: Dispatch, getState: Ge
txData,
});
dispatch({
type: PENDING.ADD,
payload: {
type: 'send',
deviceState: account.deviceState,
sequence: nonce,
hash: txid,
network: account.network,
address: account.address,
currency: currentState.currency,
amount: currentState.amount,
total: currentState.total,
fee: '0', // TODO: calculate fee
},
});
// clear session storage
dispatch(SessionStorageActions.clear());

View File

@ -44,6 +44,8 @@ export const onNotification = (payload: $ElementType<BlockchainNotification, 'pa
type: PENDING.ADD,
payload: {
type: notification.type,
deviceState: account.deviceState,
sequence: account.sequence,
hash: notification.hash,
network: account.network,
address: account.address,

View File

@ -71,6 +71,8 @@ const start = (state: State, action: DiscoveryStartAction): State => {
instance.hdKey = hdKey;
instance.publicKey = action.publicKey;
instance.chainCode = action.chainCode;
instance.basePath = action.basePath;
}
const newState: State = [...state];

View File

@ -1,12 +1,13 @@
/* @flow */
import * as CONNECT from 'actions/constants/TrezorConnect';
import * as PENDING from 'actions/constants/pendingTx';
import * as SEND from 'actions/constants/send';
import type { TrezorDevice, Action } from 'flowtype';
import type { Action } from 'flowtype';
export type PendingTx = {
+type: 'send' | 'recv',
+deviceState: string,
+sequence: number,
+hash: string,
+network: string,
+address: string,
@ -21,35 +22,15 @@ export type State = Array<PendingTx>;
const initialState: State = [];
// const add = (state: State, action: SendTxAction): State => {
// const newState = [...state];
// newState.push({
// type: 'send',
// id: action.txid,
// network: action.account.network,
// address: action.account.address,
// deviceState: action.account.deviceState,
// currency: action.selectedCurrency,
// amount: action.amount,
// total: action.total,
// tx: action.tx,
// nonce: action.nonce,
// rejected: false,
// });
// return newState;
// };
const addFromNotification = (state: State, payload: PendingTx): State => {
const add = (state: State, payload: PendingTx): State => {
const newState = [...state];
newState.push(payload);
return newState;
};
//const clear = (state: State, device: TrezorDevice): State => state.filter(tx => tx.deviceState !== device.state);
const removeByDeviceState = (state: State, deviceState: ?string): State => state.filter(tx => tx.deviceState !== deviceState);
const remove = (state: State, hash: string): State => state.filter(tx => tx.hash !== hash);
const removeByHash = (state: State, hash: string): State => state.filter(tx => tx.hash !== hash);
const reject = (state: State, hash: string): State => state.map((tx) => {
if (tx.hash === hash && !tx.rejected) {
@ -60,19 +41,16 @@ const reject = (state: State, hash: string): State => state.map((tx) => {
export default function pending(state: State = initialState, action: Action): State {
switch (action.type) {
// case SEND.TX_COMPLETE:
// return add(state, action);
// case CONNECT.FORGET:
// case CONNECT.FORGET_SINGLE:
// case CONNECT.FORGET_SILENT:
// case CONNECT.RECEIVE_WALLET_TYPE:
// return clear(state, action.device);
case CONNECT.FORGET:
case CONNECT.FORGET_SINGLE:
case CONNECT.FORGET_SILENT:
case CONNECT.RECEIVE_WALLET_TYPE:
return removeByDeviceState(state, action.device.state);
case PENDING.ADD:
return addFromNotification(state, action.payload);
return add(state, action.payload);
case PENDING.TX_RESOLVED:
return remove(state, action.hash);
return removeByHash(state, action.hash);
case PENDING.TX_REJECTED:
return reject(state, action.hash);

View File

@ -89,9 +89,9 @@ export const getAccountPendingTx = (pending: Array<PendingTx>, account: ?Account
return pending.filter(p => p.network === a.network && p.address === a.address);
};
export const getPendingNonce = (pending: Array<PendingTx>): number => pending.reduce((value: number, tx: PendingTx) => {
export const getPendingSequence = (pending: Array<PendingTx>): number => pending.reduce((value: number, tx: PendingTx) => {
if (tx.rejected) return value;
return Math.max(value, tx.nonce + 1);
return Math.max(value, tx.sequence + 1);
}, 0);
export const getPendingAmount = (pending: Array<PendingTx>, currency: string, token: boolean = false): BigNumber => pending.reduce((value: BigNumber, tx: PendingTx) => {