mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-10 11:05:47 +00:00
ab5fa1a799
* Make UnlockHeader a PureComponent * MVP * actually disable wallet format if not determined to be valid format for wallet * default to correct derivation in mnemonic modal * cleanup * fix tslint * use enums for HD wallet getPath * Add stricter typing * Fix labels not updating on selector * Ban hardware wallet support for custom network unsupported chainIds * Fix type error * Fix custom node dPath not being saved * Fix mnemonic modal * default path bugfixes * add react-select * misc fixes; rabbit holing hard. * fix tslint * revert identicon changes * reload on network change :/ * actually reload on network change * really really reload on network change * tslint fixes * Update styles * set table width * fix package versioning * push broken sagas * Fix saga test * fix tslint * address round of review * move non-selectors out to utilty; adjust reload timer * cleanup network util comments * manage wallet disable at WalletDecrypt instead of in both WalletDecrypt and WalletButton * Separate WalletDecrypt props into ownProps / StateProps * disable payment requests on non-eth networks * specialize connect; separate props * remove unused state prop * remove bad import * create tests for networks * Clarify Lite-Send error on non-ethereum networkS * remove string option for network config name * Create concept of always-on 'EXTRA_PATHS'; include SINGULAR_DTV legacy dPath in 'EXTRA_PATHS' * fix multiple imports * address PR comments
41 lines
1.6 KiB
TypeScript
41 lines
1.6 KiB
TypeScript
import { apply, select, call } from 'redux-saga/effects';
|
|
import { AppState } from 'reducers';
|
|
import { Token } from 'config';
|
|
import { INode } from 'libs/nodes/INode';
|
|
import { IWallet, WalletConfig } from 'libs/wallet';
|
|
import { TokenBalance } from 'selectors/wallet';
|
|
import { getCustomTokens } from 'selectors/customTokens';
|
|
import { getNodeLib } from 'selectors/config';
|
|
import { loadWalletConfig } from 'utils/localStorage';
|
|
import { TokenBalanceLookup } from './wallet';
|
|
|
|
export function* getTokenBalances(wallet: IWallet, tokens: Token[]) {
|
|
const node: INode = yield select(getNodeLib);
|
|
const address: string = yield apply(wallet, wallet.getAddressString);
|
|
const tokenBalances: TokenBalance[] = yield apply(node, node.getTokenBalances, [address, tokens]);
|
|
return tokens.reduce((acc, t, i) => {
|
|
acc[t.symbol] = tokenBalances[i];
|
|
return acc;
|
|
}, {});
|
|
}
|
|
|
|
// Return an array of the tokens that meet any of the following conditions:
|
|
// 1. Non-zero balance
|
|
// 2. It was in the previous wallet's config
|
|
// 3. It's a custom token that the user added
|
|
export function* filterScannedTokenBalances(wallet: IWallet, balances: TokenBalanceLookup) {
|
|
const customTokens: AppState['customTokens'] = yield select(getCustomTokens);
|
|
const oldConfig: WalletConfig = yield call(loadWalletConfig, wallet);
|
|
return Object.keys(balances).filter(symbol => {
|
|
if (balances[symbol] && !balances[symbol].balance.isZero()) {
|
|
return true;
|
|
}
|
|
if (oldConfig.tokens && oldConfig.tokens.includes(symbol)) {
|
|
return true;
|
|
}
|
|
if (customTokens.find(token => token.symbol === symbol)) {
|
|
return true;
|
|
}
|
|
});
|
|
}
|