/ common / features / wallet / selectors.ts
selectors.ts
 1  import { Wei } from 'libs/units';
 2  import { WalletConfig } from 'libs/wallet/config';
 3  import { IWallet } from 'libs/wallet/IWallet';
 4  import { LedgerWallet } from 'libs/wallet/deterministic/ledger';
 5  import { TrezorWallet } from 'libs/wallet/deterministic/trezor';
 6  import { SafeTWallet } from 'libs/wallet/deterministic/safe-t';
 7  import Web3Wallet from 'libs/wallet/non-deterministic/web3';
 8  import ParitySignerWallet from 'libs/wallet/non-deterministic/parity';
 9  import { AppState } from 'features/reducers';
10  
11  export function getWalletInst(state: AppState): IWallet | null | undefined {
12    return state.wallet.inst;
13  }
14  
15  export function getWalletConfig(state: AppState): WalletConfig | null | undefined {
16    return state.wallet.config;
17  }
18  
19  export function isWalletFullyUnlocked(state: AppState): boolean | null | undefined {
20    return state.wallet.inst && !state.wallet.inst.isReadOnly;
21  }
22  
23  export interface IWalletType {
24    isWeb3Wallet: boolean;
25    isHardwareWallet: boolean;
26    isParitySignerWallet: boolean;
27  }
28  
29  export const getWallet = (state: AppState) => state.wallet;
30  
31  export const getWalletType = (state: AppState): IWalletType => {
32    const wallet = getWalletInst(state);
33    const isWeb3Wallet = wallet instanceof Web3Wallet;
34    const isLedgerWallet = wallet instanceof LedgerWallet;
35    const isTrezorWallet = wallet instanceof TrezorWallet;
36    const isSafeTWallet = wallet instanceof SafeTWallet;
37    const isParitySignerWallet = wallet instanceof ParitySignerWallet;
38    const isHardwareWallet = isLedgerWallet || isTrezorWallet || isSafeTWallet;
39    return { isWeb3Wallet, isHardwareWallet, isParitySignerWallet };
40  };
41  
42  export const isUnlocked = (state: AppState) => !!getWalletInst(state);
43  
44  export const isEtherBalancePending = (state: AppState): boolean =>
45    getWallet(state).balance.isPending;
46  
47  export const getEtherBalance = (state: AppState): Wei | null => getWallet(state).balance.wei;
48  
49  export function getRecentAddresses(state: AppState) {
50    return state.wallet.recentAddresses;
51  }