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

added PENDING.TX_NOT_FOUND

This commit is contained in:
Szymon Lesisz 2018-05-23 19:13:24 +02:00
parent c1bb93bf5c
commit 8a0f945c97
6 changed files with 67 additions and 13 deletions

View File

@ -47,11 +47,43 @@ declare module 'web3' {
id: string; id: string;
} }
declare export type TransactionStatus = {
blockHash: string,
blockNumber: ?number,
from: string,
gas: number,
gasPrice: BigNumber,
hash: string,
input: string,
nonce: number,
r: string,
s: string,
v: string,
to: string,
transactionIndex: number,
value: BigNumber
}
declare export type TransactionReceipt = {
blockHash: string,
blockNumber: number,
contractAddress: ?string,
cumulativeGasUsed: number,
from: string,
gasUsed: number,
logs: Array<any>,
status: string,
to: string,
transactionHash: string,
transactionIndex: number
}
declare class Eth { declare class Eth {
getGasPrice: (callback: (error: Error, gasPrice: string) => void) => void, getGasPrice: (callback: (error: Error, gasPrice: string) => void) => void,
getBalance: (address: string, callback: (error: Error, balance: BigNumber) => void) => void, getBalance: (address: string, callback: (error: Error, balance: BigNumber) => void) => void,
getTransactionCount: (address: string, callback: (error: Error, result: number) => void) => void, getTransactionCount: (address: string, callback: (error: Error, result: number) => void) => void,
getTransaction: (txid: string, callback: (error: Error, result: any) => void) => void, getTransaction: (txid: string, callback: (error: Error, result: TransactionStatus) => void) => void,
getTransactionReceipt: (txid: string, callback: (error: Error, result: TransactionReceipt) => void) => void,
getBlockNumber: (callback: (error: Error, blockNumber: number) => void) => void, getBlockNumber: (callback: (error: Error, blockNumber: number) => void) => void,
getBlock: (hash: string, callback: (error: Error, result: any) => void) => void, getBlock: (hash: string, callback: (error: Error, result: any) => void) => void,
// getAccounts: (callback: (error: Error, accounts: Array<EthereumAddressT>) => void) => void, // getAccounts: (callback: (error: Error, accounts: Array<EthereumAddressT>) => void) => void,

View File

@ -11,5 +11,10 @@ export type PendingTxAction = {
type: typeof PENDING.TX_RESOLVED, type: typeof PENDING.TX_RESOLVED,
tx: PendingTx, tx: PendingTx,
receipt: Object, receipt: Object,
block: string } | {
type: typeof PENDING.TX_NOT_FOUND,
tx: PendingTx,
} | {
type: typeof PENDING.TX_TOKEN_ERROR,
tx: PendingTx,
} }

View File

@ -27,6 +27,7 @@ import type { PendingTx } from '../reducers/PendingTxReducer';
import type { Web3Instance } from '../reducers/Web3Reducer'; import type { Web3Instance } from '../reducers/Web3Reducer';
import type { Token } from '../reducers/TokensReducer'; import type { Token } from '../reducers/TokensReducer';
import type { NetworkToken } from '../reducers/LocalStorageReducer'; import type { NetworkToken } from '../reducers/LocalStorageReducer';
import type { TransactionStatus, TransactionReceipt } from 'web3';
export type Web3Action = { export type Web3Action = {
type: typeof WEB3.READY, type: typeof WEB3.READY,
@ -309,16 +310,28 @@ export const getTransactionReceipt = (tx: PendingTx): AsyncAction => {
const web3instance = getState().web3.filter(w3 => w3.network === tx.network)[0]; const web3instance = getState().web3.filter(w3 => w3.network === tx.network)[0];
const web3 = web3instance.web3; const web3 = web3instance.web3;
//web3.eth.getTransactionReceipt(txid, (error, tx) => { web3.eth.getTransaction(tx.id, (error: Error, status: TransactionStatus) => {
web3.eth.getTransaction(tx.id, (error: Error, receipt: any) => { if (!error && !status) {
if (receipt && receipt.blockNumber) { dispatch({
web3.eth.getBlock(receipt.blockHash, (error, block) => { type: PENDING.TX_NOT_FOUND,
dispatch({ tx,
type: PENDING.TX_RESOLVED, })
tx, } else if (status && status.blockNumber) {
receipt, web3.eth.getTransactionReceipt(tx.id, (error: Error, receipt: TransactionReceipt) => {
block if (receipt) {
}) if (status.gas !== receipt.gasUsed) {
dispatch({
type: PENDING.TX_TOKEN_ERROR,
tx
})
}
dispatch({
type: PENDING.TX_RESOLVED,
tx,
receipt
})
}
}); });
} }
}); });

View File

@ -2,4 +2,6 @@
'use strict'; 'use strict';
export const FROM_STORAGE: 'pending__from_storage' = 'pending__from_storage'; export const FROM_STORAGE: 'pending__from_storage' = 'pending__from_storage';
export const TX_RESOLVED: 'pending__tx_resolved' = 'pending__tx_resolved'; export const TX_RESOLVED: 'pending__tx_resolved' = 'pending__tx_resolved';
export const TX_NOT_FOUND: 'pending__tx_not_found' = 'pending__tx_not_found';
export const TX_TOKEN_ERROR: 'pending__tx_token_error' = 'pending__tx_token_error';

View File

@ -44,6 +44,7 @@ export default function pending(state: State = initialState, action: Action): St
return add(state, action); return add(state, action);
case PENDING.TX_RESOLVED : case PENDING.TX_RESOLVED :
case PENDING.TX_NOT_FOUND :
return remove(state, action.tx.id); return remove(state, action.tx.id);
case PENDING.FROM_STORAGE : case PENDING.FROM_STORAGE :

View File

@ -135,6 +135,7 @@ const LocalStorageService: Middleware = (api: MiddlewareAPI) => (next: Middlewar
case SEND.TX_COMPLETE : case SEND.TX_COMPLETE :
case PENDING.TX_RESOLVED : case PENDING.TX_RESOLVED :
case PENDING.TX_NOT_FOUND :
save(api.dispatch, api.getState); save(api.dispatch, api.getState);
break; break;