From e512812eb407fb475815eae40e35d4a495e74e29 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Tue, 18 Sep 2018 11:27:41 +0200 Subject: [PATCH] unifying DiscoveryResult type with EthereumAccount from 'trezor-connect' --- src/actions/BlockchainActions.js | 20 ++++++++------------ src/actions/Web3Actions.js | 4 ++-- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/actions/BlockchainActions.js b/src/actions/BlockchainActions.js index 3c13a0cf..353cd345 100644 --- a/src/actions/BlockchainActions.js +++ b/src/actions/BlockchainActions.js @@ -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 => async (dispatch: Dispatch, getState: GetState): Promise => { +export const discoverAccount = (device: TrezorDevice, address: string, network: string): PromiseAction => async (dispatch: Dispatch, getState: GetState): Promise => { // 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, diff --git a/src/actions/Web3Actions.js b/src/actions/Web3Actions.js index ce894771..b4611bd3 100644 --- a/src/actions/Web3Actions.js +++ b/src/actions/Web3Actions.js @@ -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 => async (dispatch: Dispatch, getState: GetState): Promise => { +export const discoverAccount = (address: string, network: string): PromiseAction => async (dispatch: Dispatch, getState: GetState): Promise => { 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'),