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.
73 lines
2.3 KiB
73 lines
2.3 KiB
4 years ago
|
import React, { Component } from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import classnames from 'classnames';
|
||
|
import { checkExistingAddresses } from '../../../helpers/utils/util';
|
||
|
import TokenListPlaceholder from './token-list-placeholder';
|
||
7 years ago
|
|
||
4 years ago
|
export default class TokenList extends Component {
|
||
7 years ago
|
static contextTypes = {
|
||
|
t: PropTypes.func,
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
|
static propTypes = {
|
||
|
tokens: PropTypes.array,
|
||
|
results: PropTypes.array,
|
||
|
selectedTokens: PropTypes.object,
|
||
|
onToggleToken: PropTypes.func,
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
4 years ago
|
render() {
|
||
|
const {
|
||
|
results = [],
|
||
|
selectedTokens = {},
|
||
|
onToggleToken,
|
||
|
tokens = [],
|
||
4 years ago
|
} = this.props;
|
||
7 years ago
|
|
||
4 years ago
|
return results.length === 0 ? (
|
||
|
<TokenListPlaceholder />
|
||
|
) : (
|
||
|
<div className="token-list">
|
||
|
<div className="token-list__title">
|
||
|
{this.context.t('searchResults')}
|
||
|
</div>
|
||
|
<div className="token-list__tokens-container">
|
||
|
{Array(6)
|
||
|
.fill(undefined)
|
||
|
.map((_, i) => {
|
||
4 years ago
|
const { logo, symbol, name, address } = results[i] || {};
|
||
|
const tokenAlreadyAdded = checkExistingAddresses(address, tokens);
|
||
4 years ago
|
const onClick = () =>
|
||
4 years ago
|
!tokenAlreadyAdded && onToggleToken(results[i]);
|
||
7 years ago
|
|
||
4 years ago
|
return (
|
||
|
Boolean(logo || symbol || name) && (
|
||
|
<div
|
||
|
className={classnames('token-list__token', {
|
||
|
'token-list__token--selected': selectedTokens[address],
|
||
|
'token-list__token--disabled': tokenAlreadyAdded,
|
||
|
})}
|
||
4 years ago
|
onClick={onClick}
|
||
|
onKeyPress={(event) => event.key === 'Enter' && onClick()}
|
||
4 years ago
|
key={i}
|
||
4 years ago
|
tabIndex="0"
|
||
4 years ago
|
>
|
||
7 years ago
|
<div
|
||
4 years ago
|
className="token-list__token-icon"
|
||
|
style={{
|
||
|
backgroundImage: logo && `url(images/contract/${logo})`,
|
||
|
}}
|
||
|
/>
|
||
|
<div className="token-list__token-data">
|
||
|
<span className="token-list__token-name">{`${name} (${symbol})`}</span>
|
||
7 years ago
|
</div>
|
||
4 years ago
|
</div>
|
||
|
)
|
||
4 years ago
|
);
|
||
4 years ago
|
})}
|
||
7 years ago
|
</div>
|
||
4 years ago
|
</div>
|
||
4 years ago
|
);
|
||
7 years ago
|
}
|
||
|
}
|