diff --git a/src/actions/BlockchainActions.js b/src/actions/BlockchainActions.js index 9f68065c..5221c96e 100644 --- a/src/actions/BlockchainActions.js +++ b/src/actions/BlockchainActions.js @@ -27,8 +27,6 @@ import type { AsyncAction, PromiseAction, ThunkAction, - AccountDiscovery, - EthereumTxRequest } from 'flowtype'; import type { Token } from 'reducers/TokensReducer'; @@ -38,7 +36,14 @@ export type BlockchainAction = { type: typeof BLOCKCHAIN.READY, } -export const discoverAccount = (device: TrezorDevice, xpub: string, network: string): PromiseAction => async (dispatch: Dispatch, getState: GetState): Promise => { +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 => { // get data from connect // Temporary disabled, enable after trezor-connect@5.0.32 release const txs = await TrezorConnect.ethereumGetAccountInfo({ diff --git a/src/actions/TxActions.js b/src/actions/TxActions.js index ac8535a8..8bdaed0e 100644 --- a/src/actions/TxActions.js +++ b/src/actions/TxActions.js @@ -10,12 +10,28 @@ import type { Dispatch, GetState, PromiseAction, - EthereumTxRequest, - EthereumPreparedTx } from 'flowtype'; +import type { + EthereumTransaction +} from 'trezor-connect'; -export const prepareEthereumTx = (tx: EthereumTxRequest): PromiseAction => async (dispatch: Dispatch, getState: GetState): Promise => { +import type { Token } from 'reducers/TokensReducer'; + +type EthereumTxRequest = { + network: string; + token: ?Token; + from: string; + to: string; + amount: string; + data: string; + gasLimit: string; + gasPrice: string; + nonce: number; +} + + +export const prepareEthereumTx = (tx: EthereumTxRequest): PromiseAction => async (dispatch: Dispatch, getState: GetState): Promise => { const instance = await dispatch( initWeb3(tx.network) ); const token = tx.token; let data: string = `0x${tx.data}`; // TODO: check if already prefixed @@ -46,10 +62,8 @@ export const prepareEthereumTx = (tx: EthereumTxRequest): PromiseAction => async (dispatch: Dispatch, getState: GetState): Promise => { +export const serializeEthereumTx = (tx: EthereumTransaction): PromiseAction => async (dispatch: Dispatch, getState: GetState): Promise => { const ethTx = new EthereumjsTx(tx); - console.warn("SERIALIZE 1", `0x${ ethTx.serialize().toString('hex') }`) - console.warn("SERIALIZE 2", toHex( ethTx.serialize() )) return `0x${ ethTx.serialize().toString('hex') }`; // return toHex( ethTx.serialize() ); } \ No newline at end of file diff --git a/src/actions/Web3Actions.js b/src/actions/Web3Actions.js index a6821ef8..6738953d 100644 --- a/src/actions/Web3Actions.js +++ b/src/actions/Web3Actions.js @@ -19,9 +19,6 @@ import type { ThunkAction, AsyncAction, PromiseAction, - AccountDiscovery, - EthereumTxRequest, - EthereumPreparedTx } from 'flowtype'; import type { EthereumAccount } from 'trezor-connect'; @@ -30,6 +27,7 @@ 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'; @@ -137,7 +135,7 @@ 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); diff --git a/src/flowtype/index.js b/src/flowtype/index.js index 3fd602a0..ece6a996 100644 --- a/src/flowtype/index.js +++ b/src/flowtype/index.js @@ -169,41 +169,3 @@ export type PromiseAction = ReduxPromiseAction; export type Store = ReduxStore; export type GetState = () => State; - - -// temporary types -export type AccountDiscovery = { - transactions: number; - block: number; - balance: string; - nonce: number; -} - -import type { Token } from 'reducers/TokensReducer'; - -export type EthereumTxRequest = { - network: string; - token: ?Token; - from: string; - to: string; - amount: string; - data: string; - gasLimit: string; - gasPrice: string; - nonce: number; -} -// copypaste from trezor-connect -export type EthereumPreparedTx = { - to: string, - value: string, - gasPrice: string, - gasLimit: string, - nonce: string, - data?: string, - chainId?: number, - txType?: number, - v: string, - r: string, - s: string, -} -