1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-24 09:18:09 +00:00

added pending to SelectedAccountReducer

This commit is contained in:
Szymon Lesisz 2018-05-25 11:49:15 +02:00
parent c40432d2f2
commit 7b639fb223
3 changed files with 15 additions and 3 deletions

View File

@ -56,7 +56,8 @@ export const updateSelectedValues = (prevState: State, action: Action): AsyncAct
const account = stateUtils.getSelectedAccount(state); const account = stateUtils.getSelectedAccount(state);
const network = stateUtils.getSelectedNetwork(state); const network = stateUtils.getSelectedNetwork(state);
const discovery = stateUtils.getDiscoveryProcess(state); const discovery = stateUtils.getDiscoveryProcess(state);
const tokens = stateUtils.getTokens(state, account); const tokens = stateUtils.getAccountTokens(state, account);
const pending = stateUtils.getAccountPendingTx(state, account);
const web3 = stateUtils.getWeb3(state); const web3 = stateUtils.getWeb3(state);
const payload: $ElementType<State, 'selectedAccount'> = { const payload: $ElementType<State, 'selectedAccount'> = {
@ -65,6 +66,7 @@ export const updateSelectedValues = (prevState: State, action: Action): AsyncAct
network, network,
discovery, discovery,
tokens, tokens,
pending,
web3 web3
} }

View File

@ -8,6 +8,7 @@ import type {
Account, Account,
Coin, Coin,
Token, Token,
PendingTx,
Discovery, Discovery,
Web3Instance Web3Instance
} from '~/flowtype'; } from '~/flowtype';
@ -18,6 +19,7 @@ export type State = {
account: ?Account; account: ?Account;
network: ?Coin; network: ?Coin;
tokens: Array<Token>, tokens: Array<Token>,
pending: Array<PendingTx>,
web3: ?Web3Instance, web3: ?Web3Instance,
discovery: ?Discovery discovery: ?Discovery
}; };
@ -27,6 +29,7 @@ export const initialState: State = {
account: null, account: null,
network: null, network: null,
tokens: [], tokens: [],
pending: [],
web3: null, web3: null,
discovery: null discovery: null
}; };

View File

@ -19,6 +19,7 @@ import type {
Coin, Coin,
Discovery, Discovery,
Token, Token,
PendingTx,
Web3Instance Web3Instance
} from '~/flowtype'; } from '~/flowtype';
@ -83,9 +84,15 @@ 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 getTokens = (state: State, account: ?Account): Array<Token> => { export const getAccountPendingTx = (state: State, account: ?Account): Array<PendingTx> => {
const a = account; const a = account;
if (!a) return state.selectedAccount.tokens; if (!a) return state.selectedAccount.pending.length > 0 ? [] : state.selectedAccount.pending;
return state.pending.filter(p => p.network === a.network && p.address === a.address);
}
export const getAccountTokens = (state: State, account: ?Account): Array<Token> => {
const a = account;
if (!a) return state.selectedAccount.tokens.length > 0 ? [] : state.selectedAccount.tokens;
return state.tokens.filter(t => t.ethAddress === a.address && t.network === a.network && t.deviceState === a.deviceState); return state.tokens.filter(t => t.ethAddress === a.address && t.network === a.network && t.deviceState === a.deviceState);
} }