mirror of
https://github.com/trezor/trezor-wallet
synced 2024-12-30 19:00:53 +00:00
replace PendingTx flow declaration by BlockchainLinkTransation from 'trezor-connect'
This commit is contained in:
parent
39786377b6
commit
7ad19dd1c0
@ -15,7 +15,6 @@ import * as storageUtils from 'utils/storage';
|
|||||||
import { findAccountTokens } from 'reducers/TokensReducer';
|
import { findAccountTokens } from 'reducers/TokensReducer';
|
||||||
import type { Account } from 'reducers/AccountsReducer';
|
import type { Account } from 'reducers/AccountsReducer';
|
||||||
import type { Token } from 'reducers/TokensReducer';
|
import type { Token } from 'reducers/TokensReducer';
|
||||||
import type { PendingTx } from 'reducers/PendingTxReducer';
|
|
||||||
import type { Discovery } from 'reducers/DiscoveryReducer';
|
import type { Discovery } from 'reducers/DiscoveryReducer';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
@ -24,6 +23,7 @@ import type {
|
|||||||
AsyncAction,
|
AsyncAction,
|
||||||
GetState,
|
GetState,
|
||||||
Dispatch,
|
Dispatch,
|
||||||
|
Transaction,
|
||||||
} from 'flowtype';
|
} from 'flowtype';
|
||||||
import type { Config, Network, TokensCollection } from 'reducers/LocalStorageReducer';
|
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 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 => {
|
export const save = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
||||||
const devices: Array<TrezorDevice> = getState().devices.filter(d => d.features && d.remember === true);
|
const devices: Array<TrezorDevice> = getState().devices.filter(d => d.features && d.remember === true);
|
||||||
const accounts: Array<Account> = findAccounts(devices, getState().accounts);
|
const accounts: Array<Account> = findAccounts(devices, getState().accounts);
|
||||||
const tokens: Array<Token> = findTokens(accounts, getState().tokens);
|
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);
|
const discovery: Array<Discovery> = findDiscovery(devices, getState().discovery);
|
||||||
|
|
||||||
// save devices
|
// save devices
|
||||||
|
@ -3,14 +3,15 @@
|
|||||||
|
|
||||||
import * as PENDING from 'actions/constants/pendingTx';
|
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 = {
|
export type PendingTxAction = {
|
||||||
type: typeof PENDING.FROM_STORAGE,
|
type: typeof PENDING.FROM_STORAGE,
|
||||||
payload: State
|
payload: State
|
||||||
} | {
|
} | {
|
||||||
type: typeof PENDING.ADD,
|
type: typeof PENDING.ADD,
|
||||||
payload: PendingTx
|
payload: Transaction
|
||||||
} | {
|
} | {
|
||||||
type: typeof PENDING.TX_RESOLVED,
|
type: typeof PENDING.TX_RESOLVED,
|
||||||
hash: string,
|
hash: string,
|
||||||
|
@ -44,6 +44,7 @@ import type {
|
|||||||
TransportMessageType,
|
TransportMessageType,
|
||||||
UiMessageType,
|
UiMessageType,
|
||||||
BlockchainEvent,
|
BlockchainEvent,
|
||||||
|
BlockchainLinkTransaction,
|
||||||
} from 'trezor-connect';
|
} from 'trezor-connect';
|
||||||
|
|
||||||
import type { RouterAction, LocationState } from 'react-router-redux';
|
import type { RouterAction, LocationState } from 'react-router-redux';
|
||||||
@ -84,11 +85,17 @@ export type UnknownDevice = $Exact<{
|
|||||||
instanceLabel: string;
|
instanceLabel: string;
|
||||||
instanceName: ?string;
|
instanceName: ?string;
|
||||||
ts: number;
|
ts: number;
|
||||||
}>
|
}>;
|
||||||
|
|
||||||
export type { Device } from 'trezor-connect';
|
export type { Device } from 'trezor-connect';
|
||||||
export type TrezorDevice = AcquiredDevice | UnknownDevice;
|
export type TrezorDevice = AcquiredDevice | UnknownDevice;
|
||||||
|
|
||||||
|
export type Transaction = BlockchainLinkTransaction & {
|
||||||
|
deviceState: string,
|
||||||
|
network: string,
|
||||||
|
rejected?: boolean,
|
||||||
|
};
|
||||||
|
|
||||||
export type RouterLocationState = LocationState;
|
export type RouterLocationState = LocationState;
|
||||||
|
|
||||||
// Cast event from TrezorConnect event listener to react Action
|
// 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 { Discovery } from 'reducers/DiscoveryReducer';
|
||||||
export type { Token } from 'reducers/TokensReducer';
|
export type { Token } from 'reducers/TokensReducer';
|
||||||
export type { Web3Instance } from 'reducers/Web3Reducer';
|
export type { Web3Instance } from 'reducers/Web3Reducer';
|
||||||
export type { PendingTx } from 'reducers/PendingTxReducer';
|
|
||||||
|
|
||||||
export type Accounts = $ElementType<State, 'accounts'>;
|
export type Accounts = $ElementType<State, 'accounts'>;
|
||||||
export type LocalStorage = $ElementType<State, 'localStorage'>;
|
export type LocalStorage = $ElementType<State, 'localStorage'>;
|
||||||
|
@ -2,43 +2,13 @@
|
|||||||
import * as CONNECT from 'actions/constants/TrezorConnect';
|
import * as CONNECT from 'actions/constants/TrezorConnect';
|
||||||
import * as PENDING from 'actions/constants/pendingTx';
|
import * as PENDING from 'actions/constants/pendingTx';
|
||||||
|
|
||||||
import type { Action } from 'flowtype';
|
import type { Action, Transaction } from 'flowtype';
|
||||||
|
|
||||||
|
export type State = Array<Transaction>;
|
||||||
// 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>;
|
|
||||||
|
|
||||||
const initialState: State = [];
|
const initialState: State = [];
|
||||||
|
|
||||||
const add = (state: State, payload: PendingTx): State => {
|
const add = (state: State, payload: Transaction): State => {
|
||||||
const newState = [...state];
|
const newState = [...state];
|
||||||
newState.push(payload);
|
newState.push(payload);
|
||||||
return newState;
|
return newState;
|
||||||
|
@ -6,7 +6,7 @@ import type {
|
|||||||
Account,
|
Account,
|
||||||
Network,
|
Network,
|
||||||
Token,
|
Token,
|
||||||
PendingTx,
|
Transaction,
|
||||||
Discovery,
|
Discovery,
|
||||||
} from 'flowtype';
|
} from 'flowtype';
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ export type State = {
|
|||||||
account: ?Account,
|
account: ?Account,
|
||||||
network: ?Network,
|
network: ?Network,
|
||||||
tokens: Array<Token>,
|
tokens: Array<Token>,
|
||||||
pending: Array<PendingTx>,
|
pending: Array<Transaction>,
|
||||||
discovery: ?Discovery,
|
discovery: ?Discovery,
|
||||||
loader: ?Loader,
|
loader: ?Loader,
|
||||||
notification: ?Notification,
|
notification: ?Notification,
|
||||||
|
@ -9,7 +9,7 @@ import type {
|
|||||||
Network,
|
Network,
|
||||||
Discovery,
|
Discovery,
|
||||||
Token,
|
Token,
|
||||||
PendingTx,
|
Transaction,
|
||||||
Web3Instance,
|
Web3Instance,
|
||||||
} from 'flowtype';
|
} 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);
|
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;
|
const a = account;
|
||||||
if (!a) return [];
|
if (!a) return [];
|
||||||
return pending.filter(p => p.network === a.network && p.address === a.address);
|
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;
|
if (tx.rejected) return value;
|
||||||
return Math.max(value, tx.sequence + 1);
|
return Math.max(value, tx.sequence + 1);
|
||||||
}, 0);
|
}, 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) {
|
if (tx.currency === currency && !tx.rejected) {
|
||||||
return new BigNumber(value).plus(token ? tx.amount : tx.total);
|
return new BigNumber(value).plus(token ? tx.amount : tx.total);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user