replace PendingTx flow declaration by BlockchainLinkTransation from 'trezor-connect'

pull/282/head
Szymon Lesisz 5 years ago
parent 39786377b6
commit 7ad19dd1c0

@ -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<Account>, tokens: Array<Token>): Array<Token
const findDiscovery = (devices: Array<TrezorDevice>, discovery: Array<Discovery>): Array<Discovery> => devices.reduce((arr, dev) => arr.concat(discovery.filter(a => a.deviceState === dev.state && a.publicKey.length > 0)), []);
const findPendingTxs = (accounts: Array<Account>, pending: Array<PendingTx>): Array<PendingTx> => accounts.reduce((result, account) => result.concat(pending.filter(p => p.address === account.address && p.network === account.network)), []);
const findPendingTxs = (accounts: Array<Account>, pending: Array<Transaction>): Array<Transaction> => 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<TrezorDevice> = getState().devices.filter(d => d.features && d.remember === true);
const accounts: Array<Account> = findAccounts(devices, getState().accounts);
const tokens: Array<Token> = findTokens(accounts, getState().tokens);
const pending: Array<PendingTx> = findPendingTxs(accounts, getState().pending);
const pending: Array<Transaction> = findPendingTxs(accounts, getState().pending);
const discovery: Array<Discovery> = findDiscovery(devices, getState().discovery);
// save devices

@ -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,

@ -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<State, 'accounts'>;
export type LocalStorage = $ElementType<State, 'localStorage'>;

@ -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<string>,
amount: string,
fee: string,
total: string,
};
type Output = {
addresses: Array<string>,
amount: string,
}
export type PendingTx = {
+type: 'send' | 'recv' | 'self',
+address: string,
+deviceState: string,
+inputs: Array<Input>,
+outputs: Array<Output>,
+sequence: number,
+hash: string,
+network: string,
+currency: string,
+amount: string,
+total: string,
+fee: string,
rejected?: boolean,
};
export type State = Array<PendingTx>;
export type State = Array<Transaction>;
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;

@ -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<Token>,
pending: Array<PendingTx>,
pending: Array<Transaction>,
discovery: ?Discovery,
loader: ?Loader,
notification: ?Notification,

@ -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<PendingTx>, account: ?Account): Array<PendingTx> => {
export const getAccountPendingTx = (pending: Array<Transaction>, account: ?Account): Array<Transaction> => {
const a = account;
if (!a) return [];
return pending.filter(p => p.network === a.network && p.address === a.address);
};
export const getPendingSequence = (pending: Array<PendingTx>): number => pending.reduce((value: number, tx: PendingTx) => {
export const getPendingSequence = (pending: Array<Transaction>): 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<PendingTx>, currency: string, token: boolean = false): BigNumber => pending.reduce((value: BigNumber, tx: PendingTx) => {
export const getPendingAmount = (pending: Array<Transaction>, 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);
}

Loading…
Cancel
Save