diff --git a/src/actions/LocalStorageActions.js b/src/actions/LocalStorageActions.js index b95e4ba4..03bca7bd 100644 --- a/src/actions/LocalStorageActions.js +++ b/src/actions/LocalStorageActions.js @@ -15,7 +15,6 @@ import * as storageUtils from 'utils/storage'; import { findAccountTokens } from 'reducers/TokensReducer'; import type { Account } from 'reducers/AccountsReducer'; import type { Token } from 'reducers/TokensReducer'; -import type { PendingTx } from 'reducers/PendingTxReducer'; import type { Discovery } from 'reducers/DiscoveryReducer'; import type { @@ -24,6 +23,7 @@ import type { AsyncAction, GetState, Dispatch, + Transaction, } from 'flowtype'; import type { Config, Network, TokensCollection } from 'reducers/LocalStorageReducer'; @@ -63,13 +63,13 @@ const findTokens = (accounts: Array, tokens: Array): Array, discovery: Array): Array => devices.reduce((arr, dev) => arr.concat(discovery.filter(a => a.deviceState === dev.state && a.publicKey.length > 0)), []); -const findPendingTxs = (accounts: Array, pending: Array): Array => accounts.reduce((result, account) => result.concat(pending.filter(p => p.address === account.address && p.network === account.network)), []); +const findPendingTxs = (accounts: Array, pending: Array): Array => accounts.reduce((result, account) => result.concat(pending.filter(p => p.address === account.address && p.network === account.network)), []); export const save = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => { const devices: Array = getState().devices.filter(d => d.features && d.remember === true); const accounts: Array = findAccounts(devices, getState().accounts); const tokens: Array = findTokens(accounts, getState().tokens); - const pending: Array = findPendingTxs(accounts, getState().pending); + const pending: Array = findPendingTxs(accounts, getState().pending); const discovery: Array = findDiscovery(devices, getState().discovery); // save devices diff --git a/src/actions/PendingTxActions.js b/src/actions/PendingTxActions.js index a300937c..e6000374 100644 --- a/src/actions/PendingTxActions.js +++ b/src/actions/PendingTxActions.js @@ -3,14 +3,15 @@ import * as PENDING from 'actions/constants/pendingTx'; -import type { State, PendingTx } from 'reducers/PendingTxReducer'; +import type { Transaction } from 'flowtype'; +import type { State } from 'reducers/PendingTxReducer'; export type PendingTxAction = { type: typeof PENDING.FROM_STORAGE, payload: State } | { type: typeof PENDING.ADD, - payload: PendingTx + payload: Transaction } | { type: typeof PENDING.TX_RESOLVED, hash: string, diff --git a/src/flowtype/index.js b/src/flowtype/index.js index f486b32c..68a8cfee 100644 --- a/src/flowtype/index.js +++ b/src/flowtype/index.js @@ -44,6 +44,7 @@ import type { TransportMessageType, UiMessageType, BlockchainEvent, + BlockchainLinkTransaction, } from 'trezor-connect'; import type { RouterAction, LocationState } from 'react-router-redux'; @@ -84,11 +85,17 @@ export type UnknownDevice = $Exact<{ instanceLabel: string; instanceName: ?string; ts: number; -}> +}>; export type { Device } from 'trezor-connect'; export type TrezorDevice = AcquiredDevice | UnknownDevice; +export type Transaction = BlockchainLinkTransaction & { + deviceState: string, + network: string, + rejected?: boolean, +}; + export type RouterLocationState = LocationState; // Cast event from TrezorConnect event listener to react Action @@ -152,7 +159,6 @@ export type { Account } from 'reducers/AccountsReducer'; export type { Discovery } from 'reducers/DiscoveryReducer'; export type { Token } from 'reducers/TokensReducer'; export type { Web3Instance } from 'reducers/Web3Reducer'; -export type { PendingTx } from 'reducers/PendingTxReducer'; export type Accounts = $ElementType; export type LocalStorage = $ElementType; diff --git a/src/reducers/PendingTxReducer.js b/src/reducers/PendingTxReducer.js index 1f4fb8f4..3b00b80e 100644 --- a/src/reducers/PendingTxReducer.js +++ b/src/reducers/PendingTxReducer.js @@ -2,43 +2,13 @@ import * as CONNECT from 'actions/constants/TrezorConnect'; import * as PENDING from 'actions/constants/pendingTx'; -import type { Action } from 'flowtype'; +import type { Action, Transaction } from 'flowtype'; - -// TODO: import them from trezor-connect -type Input = { - addresses: Array, - amount: string, - fee: string, - total: string, -}; - -type Output = { - addresses: Array, - amount: string, -} - -export type PendingTx = { - +type: 'send' | 'recv' | 'self', - +address: string, - +deviceState: string, - +inputs: Array, - +outputs: Array, - +sequence: number, - +hash: string, - +network: string, - +currency: string, - +amount: string, - +total: string, - +fee: string, - rejected?: boolean, -}; - -export type State = Array; +export type State = Array; const initialState: State = []; -const add = (state: State, payload: PendingTx): State => { +const add = (state: State, payload: Transaction): State => { const newState = [...state]; newState.push(payload); return newState; diff --git a/src/reducers/SelectedAccountReducer.js b/src/reducers/SelectedAccountReducer.js index fba64661..a6b83e0d 100644 --- a/src/reducers/SelectedAccountReducer.js +++ b/src/reducers/SelectedAccountReducer.js @@ -6,7 +6,7 @@ import type { Account, Network, Token, - PendingTx, + Transaction, Discovery, } from 'flowtype'; @@ -34,7 +34,7 @@ export type State = { account: ?Account, network: ?Network, tokens: Array, - pending: Array, + pending: Array, discovery: ?Discovery, loader: ?Loader, notification: ?Notification, diff --git a/src/reducers/utils/index.js b/src/reducers/utils/index.js index 078535aa..f3734dad 100644 --- a/src/reducers/utils/index.js +++ b/src/reducers/utils/index.js @@ -9,7 +9,7 @@ import type { Network, Discovery, Token, - PendingTx, + Transaction, Web3Instance, } from 'flowtype'; @@ -83,18 +83,18 @@ export const getDiscoveryProcess = (state: State): ?Discovery => { return state.discovery.find(d => d.deviceState === device.state && d.network === locationState.network); }; -export const getAccountPendingTx = (pending: Array, account: ?Account): Array => { +export const getAccountPendingTx = (pending: Array, account: ?Account): Array => { const a = account; if (!a) return []; return pending.filter(p => p.network === a.network && p.address === a.address); }; -export const getPendingSequence = (pending: Array): number => pending.reduce((value: number, tx: PendingTx) => { +export const getPendingSequence = (pending: Array): number => pending.reduce((value: number, tx: Transaction) => { if (tx.rejected) return value; return Math.max(value, tx.sequence + 1); }, 0); -export const getPendingAmount = (pending: Array, currency: string, token: boolean = false): BigNumber => pending.reduce((value: BigNumber, tx: PendingTx) => { +export const getPendingAmount = (pending: Array, currency: string, token: boolean = false): BigNumber => pending.reduce((value: BigNumber, tx: Transaction) => { if (tx.currency === currency && !tx.rejected) { return new BigNumber(value).plus(token ? tx.amount : tx.total); }