1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-12-25 00:18:07 +00:00

unifying DiscoveryResult type with EthereumAccount from 'trezor-connect'

This commit is contained in:
Szymon Lesisz 2018-09-18 11:27:41 +02:00
parent 38669a5dfb
commit e512812eb4
2 changed files with 10 additions and 14 deletions

View File

@ -28,7 +28,7 @@ import type {
PromiseAction,
ThunkAction,
} from 'flowtype';
import type { EthereumAccount } from 'trezor-connect';
import type { Token } from 'reducers/TokensReducer';
import type { NetworkToken } from 'reducers/LocalStorageReducer';
@ -36,21 +36,16 @@ export type BlockchainAction = {
type: typeof BLOCKCHAIN.READY,
}
export type DiscoveryResult = {
transactions: number;
block: number;
balance: string;
nonce: number;
}
export const discoverAccount = (device: TrezorDevice, xpub: string, network: string): PromiseAction<DiscoveryResult> => async (dispatch: Dispatch, getState: GetState): Promise<DiscoveryResult> => {
export const discoverAccount = (device: TrezorDevice, address: string, network: string): PromiseAction<EthereumAccount> => async (dispatch: Dispatch, getState: GetState): Promise<EthereumAccount> => {
// get data from connect
// Temporary disabled, enable after trezor-connect@5.0.32 release
const txs = await TrezorConnect.ethereumGetAccountInfo({
account: {
address: xpub,
address,
block: 0,
transactions: 0
transactions: 0,
balance: "0",
nonce: 0
},
coin: network,
});
@ -60,9 +55,10 @@ export const discoverAccount = (device: TrezorDevice, xpub: string, network: str
}
// blockbook web3 fallback
const web3account = await dispatch( Web3Actions.discoverAccount(xpub, network) );
const web3account = await dispatch( Web3Actions.discoverAccount(address, network) );
// return { transactions: txs.payload, ...web3account };
return {
address,
transactions: txs.payload.transactions,
block: txs.payload.block,
balance: web3account.balance,

View File

@ -27,7 +27,6 @@ import type { PendingTx } from 'reducers/PendingTxReducer';
import type { Web3Instance } from 'reducers/Web3Reducer';
import type { Token } from 'reducers/TokensReducer';
import type { NetworkToken } from 'reducers/LocalStorageReducer';
import type { DiscoveryResult } from './BlockchainActions';
import * as TokenActions from './TokenActions';
import * as AccountsActions from './AccountsActions';
@ -131,11 +130,12 @@ export const initWeb3 = (network: string, urlIndex: number = 0): PromiseAction<W
});
}
export const discoverAccount = (address: string, network: string): PromiseAction<DiscoveryResult> => async (dispatch: Dispatch, getState: GetState): Promise<DiscoveryResult> => {
export const discoverAccount = (address: string, network: string): PromiseAction<EthereumAccount> => async (dispatch: Dispatch, getState: GetState): Promise<EthereumAccount> => {
const instance: Web3Instance = await dispatch( initWeb3(network) );
const balance = await instance.web3.eth.getBalance(address);
const nonce = await instance.web3.eth.getTransactionCount(address);
return {
address,
transactions: 0,
block: 0,
balance: EthereumjsUnits.convert(balance, 'wei', 'ether'),