mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-12 03:54:13 +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
137 lines
4.1 KiB
TypeScript
137 lines
4.1 KiB
TypeScript
import React from 'react';
|
|
import translate from 'translations';
|
|
import { Token } from 'config';
|
|
import { TokenBalance } from 'selectors/wallet';
|
|
import AddCustomTokenForm from './AddCustomTokenForm';
|
|
import TokenRow from './TokenRow';
|
|
|
|
interface Props {
|
|
allTokens: Token[];
|
|
tokenBalances: TokenBalance[];
|
|
hasSavedWalletTokens: boolean;
|
|
scanWalletForTokens(): any;
|
|
setWalletTokens(tokens: string[]): any;
|
|
onAddCustomToken(token: Token): any;
|
|
onRemoveCustomToken(symbol: string): any;
|
|
}
|
|
|
|
interface State {
|
|
trackedTokens: { [symbol: string]: boolean };
|
|
showCustomTokenForm: boolean;
|
|
}
|
|
export default class TokenBalances extends React.Component<Props, State> {
|
|
public state = {
|
|
trackedTokens: {},
|
|
showCustomTokenForm: false
|
|
};
|
|
|
|
public componentWillReceiveProps(nextProps: Props) {
|
|
if (nextProps.tokenBalances !== this.props.tokenBalances) {
|
|
const trackedTokens = nextProps.tokenBalances.reduce((prev, t) => {
|
|
prev[t.symbol] = !t.balance.isZero();
|
|
return prev;
|
|
}, {});
|
|
this.setState({ trackedTokens });
|
|
}
|
|
}
|
|
|
|
public render() {
|
|
const { allTokens, tokenBalances, hasSavedWalletTokens } = this.props;
|
|
const { showCustomTokenForm, trackedTokens } = this.state;
|
|
|
|
let bottom;
|
|
let help;
|
|
if (tokenBalances.length && !hasSavedWalletTokens) {
|
|
help = 'Select which tokens you would like to keep track of';
|
|
bottom = (
|
|
<div className="TokenBalances-buttons">
|
|
<button className="btn btn-primary btn-block" onClick={this.handleSetWalletTokens}>
|
|
<span>{translate('x_Save')}</span>
|
|
</button>
|
|
<p className="TokenBalances-buttons-help">
|
|
{translate('Missing tokens? You can add custom tokens next.')}
|
|
</p>
|
|
</div>
|
|
);
|
|
} else if (showCustomTokenForm) {
|
|
bottom = (
|
|
<div className="TokenBalances-form">
|
|
<AddCustomTokenForm
|
|
allTokens={allTokens}
|
|
onSave={this.addCustomToken}
|
|
toggleForm={this.toggleShowCustomTokenForm}
|
|
/>
|
|
</div>
|
|
);
|
|
} else {
|
|
bottom = (
|
|
<div className="TokenBalances-buttons">
|
|
<button className="btn btn-default btn-xs" onClick={this.toggleShowCustomTokenForm}>
|
|
<span>{translate('SEND_custom')}</span>
|
|
</button>{' '}
|
|
<button className="btn btn-default btn-xs" onClick={this.props.scanWalletForTokens}>
|
|
<span>Scan for New Tokens</span>
|
|
</button>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div>
|
|
{help && <p className="TokenBalances-help">{help}</p>}
|
|
|
|
{tokenBalances.length ? (
|
|
<table className="TokenBalances-rows">
|
|
<tbody>
|
|
{tokenBalances.map(
|
|
token =>
|
|
token ? (
|
|
<TokenRow
|
|
key={token.symbol}
|
|
balance={token.balance}
|
|
symbol={token.symbol}
|
|
custom={token.custom}
|
|
decimal={token.decimal}
|
|
tracked={trackedTokens[token.symbol]}
|
|
toggleTracked={!hasSavedWalletTokens && this.toggleTrack}
|
|
onRemove={this.props.onRemoveCustomToken}
|
|
/>
|
|
) : null
|
|
)}
|
|
</tbody>
|
|
</table>
|
|
) : (
|
|
<div className="well well-sm text-center">No tokens found</div>
|
|
)}
|
|
{bottom}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
private toggleTrack = (symbol: string) => {
|
|
this.setState({
|
|
trackedTokens: {
|
|
...this.state.trackedTokens,
|
|
[symbol]: !this.state.trackedTokens[symbol]
|
|
}
|
|
});
|
|
};
|
|
|
|
private toggleShowCustomTokenForm = () => {
|
|
this.setState({
|
|
showCustomTokenForm: !this.state.showCustomTokenForm
|
|
});
|
|
};
|
|
|
|
private addCustomToken = (token: Token) => {
|
|
this.props.onAddCustomToken(token);
|
|
this.setState({ showCustomTokenForm: false });
|
|
};
|
|
|
|
private handleSetWalletTokens = () => {
|
|
const { trackedTokens } = this.state;
|
|
const desiredTokens = Object.keys(trackedTokens).filter(t => trackedTokens[t]);
|
|
this.props.setWalletTokens(desiredTokens);
|
|
};
|
|
}
|