A Metamask fork with Infura removed and default networks editable
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.
 
 
 
 
 
ciphermask/ui/pages/import-token/token-list/token-list.component.js

78 lines
2.5 KiB

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';
export default class TokenList extends Component {
static contextTypes = {
t: PropTypes.func,
};
static propTypes = {
tokens: PropTypes.array,
results: PropTypes.array,
selectedTokens: PropTypes.object,
onToggleToken: PropTypes.func,
useTokenDetection: PropTypes.bool,
};
render() {
const {
results = [],
selectedTokens = {},
onToggleToken,
tokens = [],
useTokenDetection,
} = this.props;
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) => {
const { iconUrl, symbol, name, address } = results[i] || {};
// token from dynamic api list is fetched when useTokenDetection is true
const iconPath = useTokenDetection
? iconUrl
: `images/contract/${iconUrl}`;
const tokenAlreadyAdded = checkExistingAddresses(address, tokens);
const onClick = () =>
!tokenAlreadyAdded && onToggleToken(results[i]);
return (
Boolean(iconUrl || symbol || name) && (
<div
className={classnames('token-list__token', {
'token-list__token--selected': selectedTokens[address],
'token-list__token--disabled': tokenAlreadyAdded,
})}
onClick={onClick}
onKeyPress={(event) => event.key === 'Enter' && onClick()}
key={i}
tabIndex="0"
>
<div
className="token-list__token-icon"
style={{
backgroundImage: iconUrl && `url(${iconPath})`,
}}
/>
<div className="token-list__token-data">
<span className="token-list__token-name">{`${name} (${symbol})`}</span>
</div>
</div>
)
);
})}
</div>
</div>
);
}
}