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.
trezor-wallet/src/views/Wallet/components/LeftNavigation/components/CoinMenu/index.js

92 lines
2.7 KiB

/* @flow */
6 years ago
import styled from 'styled-components';
import coins from 'constants/coins';
import colors from 'config/colors';
import ICONS from 'config/icons';
import PropTypes from 'prop-types';
import React, { PureComponent } from 'react';
import { NavLink } from 'react-router-dom';
import Link from 'components/Link';
import Divider from '../Divider';
import RowCoin from '../RowCoin';
import type { Props } from '../common';
6 years ago
const Wrapper = styled.div``;
const ExternalWallet = styled.div`
cursor: pointer;
`;
class CoinMenu extends PureComponent<Props> {
getBaseUrl() {
const { selectedDevice } = this.props.wallet;
let baseUrl = '';
if (selectedDevice && selectedDevice.features) {
baseUrl = `/device/${selectedDevice.features.device_id}`;
if (selectedDevice.instance) {
baseUrl += `:${selectedDevice.instance}`;
}
}
return baseUrl;
}
getOtherCoins() {
return coins.map((coin) => {
const row = (
<RowCoin
coin={{
name: coin.coinName,
id: coin.id,
}}
iconRight={{
type: ICONS.SKIP,
color: colors.TEXT_SECONDARY,
size: 27,
}}
/>
);
if (coin.external) return <ExternalWallet key={coin.id} onClick={() => this.props.gotoExternalWallet(coin.id, coin.url)}>{row}</ExternalWallet>;
return <Link key={coin.id} href={coin.url} target="_top">{row}</Link>;
});
}
render() {
const { config } = this.props.localStorage;
6 years ago
return (
6 years ago
<Wrapper>
{config.coins.map(item => (
<NavLink
key={item.network}
to={`${this.getBaseUrl()}/network/${item.network}/account/0`}
>
<RowCoin
coin={{
name: item.name,
network: item.network,
}}
/>
</NavLink>
))}
<Divider
textLeft="Other coins"
textRight="(You will be redirected)"
6 years ago
hasBorder
/>
{this.getOtherCoins()}
6 years ago
</Wrapper>
);
}
}
CoinMenu.propTypes = {
localStorage: PropTypes.object.isRequired,
wallet: PropTypes.object.isRequired,
gotoExternalWallet: PropTypes.func.isRequired,
};
6 years ago
export default CoinMenu;