/ common / features / wallet / types.ts
types.ts
  1  import { Wei, TokenValue } from 'libs/units';
  2  import { IWallet, WalletConfig, Balance } from 'libs/wallet';
  3  import { Token } from 'types/network';
  4  
  5  export interface WalletState {
  6    inst?: IWallet | null;
  7    config?: WalletConfig | null;
  8    // in ETH
  9    balance: Balance;
 10    tokens: {
 11      [key: string]: {
 12        balance: TokenValue;
 13        error: string | null;
 14      };
 15    };
 16    isWalletPending: boolean;
 17    isTokensLoading: boolean;
 18    isPasswordPending: boolean;
 19    tokensError: string | null;
 20    hasSavedWalletTokens: boolean;
 21    recentAddresses: string[];
 22  }
 23  
 24  export enum WalletActions {
 25    UNLOCK_PRIVATE_KEY = 'WALLET_UNLOCK_PRIVATE_KEY',
 26    UNLOCK_KEYSTORE = 'WALLET_UNLOCK_KEYSTORE',
 27    UNLOCK_MNEMONIC = 'WALLET_UNLOCK_MNEMONIC',
 28    UNLOCK_WEB3 = 'WALLET_UNLOCK_WEB3',
 29    SET = 'WALLET_SET',
 30    SET_BALANCE_PENDING = 'WALLET_SET_BALANCE_PENDING',
 31    SET_BALANCE_FULFILLED = 'WALLET_SET_BALANCE_FULFILLED',
 32    SET_BALANCE_REJECTED = 'WALLET_SET_BALANCE_REJECTED',
 33    SET_TOKEN_BALANCES_PENDING = 'WALLET_SET_TOKEN_BALANCES_PENDING',
 34    SET_TOKEN_BALANCES_FULFILLED = 'WALLET_SET_TOKEN_BALANCES_FULFILLED',
 35    SET_TOKEN_BALANCES_REJECTED = 'WALLET_SET_TOKEN_BALANCES_REJECTED',
 36    SET_PENDING = 'WALLET_SET_PENDING',
 37    SET_NOT_PENDING = 'WALLET_SET_NOT_PENDING',
 38    SET_TOKEN_BALANCE_PENDING = 'WALLET_SET_TOKEN_BALANCE_PENDING',
 39    SET_TOKEN_BALANCE_FULFILLED = 'WALLET_SET_TOKEN_BALANCE_FULFILLED',
 40    SET_TOKEN_BALANCE_REJECTED = 'WALLET_SET_TOKEN_BALANCE_REJECTED',
 41    SCAN_WALLET_FOR_TOKENS = 'WALLET_SCAN_WALLET_FOR_TOKENS',
 42    SET_WALLET_TOKENS = 'WALLET_SET_WALLET_TOKENS',
 43    SET_CONFIG = 'WALLET_SET_CONFIG',
 44    RESET = 'WALLET_RESET',
 45    SET_PASSWORD_PENDING = 'WALLET_SET_PASSWORD_PENDING',
 46    REFRESH_ACCOUNT_BALANCE = 'WALLET_REFRESH_ACCOUNT_BALANCE',
 47    REFRESH_TOKEN_BALANCES = 'WALLET_REFRESH_TOKEN_BALANCES'
 48  }
 49  
 50  export interface PrivateKeyUnlockParams {
 51    key: string;
 52    password: string;
 53  }
 54  
 55  export interface UnlockPrivateKeyAction {
 56    type: WalletActions.UNLOCK_PRIVATE_KEY;
 57    payload: PrivateKeyUnlockParams;
 58  }
 59  export interface UnlockMnemonicAction {
 60    type: WalletActions.UNLOCK_MNEMONIC;
 61    payload: MnemonicUnlockParams;
 62  }
 63  
 64  export interface UnlockWeb3Action {
 65    type: WalletActions.UNLOCK_WEB3;
 66  }
 67  
 68  export interface SetWalletAction {
 69    type: WalletActions.SET;
 70    payload: IWallet;
 71  }
 72  
 73  export interface ResetWalletAction {
 74    type: WalletActions.RESET;
 75  }
 76  
 77  export interface SetWalletPendingAction {
 78    type: WalletActions.SET_PENDING;
 79    payload: boolean;
 80  }
 81  
 82  export interface SetBalancePendingAction {
 83    type: WalletActions.SET_BALANCE_PENDING;
 84  }
 85  
 86  export interface SetBalanceFullfilledAction {
 87    type: WalletActions.SET_BALANCE_FULFILLED;
 88    payload: Wei;
 89  }
 90  
 91  export interface SetBalanceRejectedAction {
 92    type: WalletActions.SET_BALANCE_REJECTED;
 93  }
 94  
 95  export interface SetTokenBalancesPendingAction {
 96    type: WalletActions.SET_TOKEN_BALANCES_PENDING;
 97  }
 98  
 99  export interface SetTokenBalancesFulfilledAction {
100    type: WalletActions.SET_TOKEN_BALANCES_FULFILLED;
101    payload: {
102      [key: string]: {
103        balance: TokenValue;
104        error: string | null;
105      };
106    };
107  }
108  
109  export interface SetTokenBalancesRejectedAction {
110    type: WalletActions.SET_TOKEN_BALANCES_REJECTED;
111  }
112  
113  export interface SetTokenBalancePendingAction {
114    type: WalletActions.SET_TOKEN_BALANCE_PENDING;
115    payload: { tokenSymbol: string };
116  }
117  
118  export interface SetTokenBalanceFulfilledAction {
119    type: WalletActions.SET_TOKEN_BALANCE_FULFILLED;
120    payload: {
121      [key: string]: {
122        balance: TokenValue;
123        error: string | null;
124      };
125    };
126  }
127  
128  export interface SetTokenBalanceRejectedAction {
129    type: WalletActions.SET_TOKEN_BALANCE_REJECTED;
130  }
131  
132  export interface ScanWalletForTokensAction {
133    type: WalletActions.SCAN_WALLET_FOR_TOKENS;
134    payload: IWallet;
135  }
136  
137  export interface SetWalletTokensAction {
138    type: WalletActions.SET_WALLET_TOKENS;
139    payload: string[];
140  }
141  
142  export interface MnemonicUnlockParams {
143    phrase: string;
144    pass: string;
145    path: string;
146    address: string;
147  }
148  
149  export interface KeystoreUnlockParams {
150    file: string;
151    password: string;
152  }
153  
154  export interface UnlockKeystoreAction {
155    type: WalletActions.UNLOCK_KEYSTORE;
156    payload: KeystoreUnlockParams;
157  }
158  
159  export interface SetWalletConfigAction {
160    type: WalletActions.SET_CONFIG;
161    payload: WalletConfig;
162  }
163  
164  export interface SetPasswordPendingAction {
165    type: WalletActions.SET_PASSWORD_PENDING;
166  }
167  
168  export interface RefreshAccountBalanceAction {
169    type: WalletActions.REFRESH_ACCOUNT_BALANCE;
170  }
171  
172  export interface RefreshTokenBalancesAction {
173    type: WalletActions.REFRESH_TOKEN_BALANCES;
174  }
175  
176  export interface TokenBalance {
177    symbol: string;
178    balance: TokenValue;
179    custom: boolean;
180    decimal: number;
181    error: string | null;
182  }
183  
184  export type MergedToken = Token & {
185    custom: boolean;
186  };
187  
188  export interface TokenBalanceLookup {
189    [symbol: string]: TokenBalance;
190  }
191  
192  export type WalletAction =
193    | UnlockPrivateKeyAction
194    | SetWalletAction
195    | SetWalletPendingAction
196    | ResetWalletAction
197    | SetBalancePendingAction
198    | SetBalanceFullfilledAction
199    | SetBalanceRejectedAction
200    | SetTokenBalancesPendingAction
201    | SetTokenBalancesFulfilledAction
202    | SetTokenBalancesRejectedAction
203    | SetTokenBalancePendingAction
204    | SetTokenBalanceFulfilledAction
205    | SetTokenBalanceRejectedAction
206    | ScanWalletForTokensAction
207    | SetWalletTokensAction
208    | SetWalletConfigAction
209    | SetPasswordPendingAction
210    | RefreshAccountBalanceAction
211    | RefreshTokenBalancesAction;