You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
139 lines
4.7 KiB
139 lines
4.7 KiB
4 years ago
|
import React, { Component } from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import { ASSET_ROUTE, ADD_TOKEN_ROUTE } from '../../helpers/constants/routes';
|
||
|
import Button from '../../components/ui/button';
|
||
|
import Identicon from '../../components/ui/identicon';
|
||
|
import TokenBalance from '../../components/ui/token-balance';
|
||
7 years ago
|
|
||
|
export default class ConfirmAddToken extends Component {
|
||
|
static contextTypes = {
|
||
|
t: PropTypes.func,
|
||
4 years ago
|
trackEvent: PropTypes.func,
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
|
static propTypes = {
|
||
|
history: PropTypes.object,
|
||
|
clearPendingTokens: PropTypes.func,
|
||
|
addTokens: PropTypes.func,
|
||
5 years ago
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
||
7 years ago
|
pendingTokens: PropTypes.object,
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
4 years ago
|
componentDidMount() {
|
||
4 years ago
|
const { mostRecentOverviewPage, pendingTokens = {}, history } = this.props;
|
||
7 years ago
|
|
||
|
if (Object.keys(pendingTokens).length === 0) {
|
||
4 years ago
|
history.push(mostRecentOverviewPage);
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
getTokenName(name, symbol) {
|
||
4 years ago
|
return typeof name === 'undefined' ? symbol : `${name} (${symbol})`;
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
render() {
|
||
|
const {
|
||
|
history,
|
||
|
addTokens,
|
||
|
clearPendingTokens,
|
||
|
mostRecentOverviewPage,
|
||
|
pendingTokens,
|
||
4 years ago
|
} = this.props;
|
||
7 years ago
|
|
||
|
return (
|
||
|
<div className="page-container">
|
||
|
<div className="page-container__header">
|
||
|
<div className="page-container__title">
|
||
4 years ago
|
{this.context.t('addTokens')}
|
||
7 years ago
|
</div>
|
||
|
<div className="page-container__subtitle">
|
||
4 years ago
|
{this.context.t('likeToAddTokens')}
|
||
7 years ago
|
</div>
|
||
|
</div>
|
||
|
<div className="page-container__content">
|
||
|
<div className="confirm-add-token">
|
||
|
<div className="confirm-add-token__header">
|
||
|
<div className="confirm-add-token__token">
|
||
4 years ago
|
{this.context.t('token')}
|
||
7 years ago
|
</div>
|
||
|
<div className="confirm-add-token__balance">
|
||
4 years ago
|
{this.context.t('balance')}
|
||
7 years ago
|
</div>
|
||
|
</div>
|
||
|
<div className="confirm-add-token__token-list">
|
||
4 years ago
|
{Object.entries(pendingTokens).map(([address, token]) => {
|
||
4 years ago
|
const { name, symbol } = token;
|
||
7 years ago
|
|
||
4 years ago
|
return (
|
||
|
<div
|
||
|
className="confirm-add-token__token-list-item"
|
||
|
key={address}
|
||
|
>
|
||
|
<div className="confirm-add-token__token confirm-add-token__data">
|
||
|
<Identicon
|
||
|
className="confirm-add-token__token-icon"
|
||
|
diameter={48}
|
||
|
address={address}
|
||
|
/>
|
||
|
<div className="confirm-add-token__name">
|
||
|
{this.getTokenName(name, symbol)}
|
||
7 years ago
|
</div>
|
||
4 years ago
|
</div>
|
||
|
<div className="confirm-add-token__balance">
|
||
|
<TokenBalance token={token} />
|
||
|
</div>
|
||
|
</div>
|
||
4 years ago
|
);
|
||
4 years ago
|
})}
|
||
7 years ago
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div className="page-container__footer">
|
||
5 years ago
|
<footer>
|
||
6 years ago
|
<Button
|
||
|
type="default"
|
||
|
large
|
||
|
className="page-container__footer-button"
|
||
|
onClick={() => history.push(ADD_TOKEN_ROUTE)}
|
||
|
>
|
||
4 years ago
|
{this.context.t('back')}
|
||
6 years ago
|
</Button>
|
||
|
<Button
|
||
6 years ago
|
type="secondary"
|
||
6 years ago
|
large
|
||
|
className="page-container__footer-button"
|
||
|
onClick={() => {
|
||
4 years ago
|
addTokens(pendingTokens).then(() => {
|
||
4 years ago
|
const pendingTokenValues = Object.values(pendingTokens);
|
||
4 years ago
|
pendingTokenValues.forEach((pendingToken) => {
|
||
|
this.context.trackEvent({
|
||
|
event: 'Token Added',
|
||
|
category: 'Wallet',
|
||
|
sensitiveProperties: {
|
||
|
token_symbol: pendingToken.symbol,
|
||
|
token_contract_address: pendingToken.address,
|
||
|
token_decimal_precision: pendingToken.decimals,
|
||
|
unlisted: pendingToken.unlisted,
|
||
|
source: pendingToken.isCustom ? 'custom' : 'list',
|
||
|
},
|
||
4 years ago
|
});
|
||
|
});
|
||
|
clearPendingTokens();
|
||
|
const firstTokenAddress = pendingTokenValues?.[0].address?.toLowerCase();
|
||
4 years ago
|
if (firstTokenAddress) {
|
||
4 years ago
|
history.push(`${ASSET_ROUTE}/${firstTokenAddress}`);
|
||
4 years ago
|
} else {
|
||
4 years ago
|
history.push(mostRecentOverviewPage);
|
||
4 years ago
|
}
|
||
4 years ago
|
});
|
||
6 years ago
|
}}
|
||
|
>
|
||
4 years ago
|
{this.context.t('addTokens')}
|
||
6 years ago
|
</Button>
|
||
5 years ago
|
</footer>
|
||
7 years ago
|
</div>
|
||
|
</div>
|
||
4 years ago
|
);
|
||
7 years ago
|
}
|
||
|
}
|