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

183 lines
5.8 KiB

/* @flow */
6 years ago
import styled from 'styled-components';
import coins from 'constants/coins';
import PropTypes from 'prop-types';
import React, { PureComponent } from 'react';
import { Link, colors, icons as ICONS } from 'trezor-ui-components';
import { NavLink } from 'react-router-dom';
import { FormattedMessage } from 'react-intl';
import l10nCommonMessages from 'views/common.messages';
import Divider from '../Divider';
import RowCoin from '../RowCoin';
import l10nMessages from './index.messages';
import type { Props } from '../common';
6 years ago
const Wrapper = styled.div``;
const ExternalWallet = styled.div`
cursor: pointer;
`;
const StyledLink = styled(Link)`
&:hover {
text-decoration: none;
}
`;
const Empty = styled.span`
display: flex;
justify-content: center;
align-items: center;
min-height: 50px;
`;
const StyledLinkEmpty = styled(Link)`
5 years ago
padding: 0;
`;
const Gray = styled.span`
color: ${colors.TEXT_SECONDARY};
`;
class CoinMenu extends PureComponent<Props> {
getBaseUrl() {
const { selectedDevice } = this.props.wallet;
let baseUrl = '';
if (selectedDevice && selectedDevice.id) {
baseUrl = `/device/${selectedDevice.id}`;
if (selectedDevice.instance) {
baseUrl += `:${selectedDevice.instance}`;
}
}
return baseUrl;
}
getOtherCoins() {
5 years ago
const { hiddenCoinsExternal } = this.props.wallet;
return coins
.sort((a, b) => a.order - b.order)
.filter(item => !item.isHidden) // hide coins globally in config
5 years ago
.filter(item => !hiddenCoinsExternal.includes(item.id))
.map(coin => {
const row = (
<RowCoin
network={{
name: coin.coinName,
shortcut: coin.id,
}}
iconRight={{
type: ICONS.SKIP,
color: colors.TEXT_SECONDARY,
5 years ago
size: 13,
}}
/>
);
if (coin.external)
return (
<ExternalWallet
key={coin.id}
onClick={() => this.props.gotoExternalWallet(coin.id, coin.url)}
>
{row}
</ExternalWallet>
);
5 years ago
return (
<StyledLink isGray key={coin.id} href={coin.url} target="_top">
5 years ago
{row}
</StyledLink>
5 years ago
);
});
}
getEmptyContent() {
return (
<Empty>
<Gray>
<FormattedMessage
{...l10nMessages.TR_SELECT_COINS}
values={{
TR_SELECT_COINS_LINK: (
<StyledLinkEmpty to="/settings">
<FormattedMessage
{...l10nCommonMessages.TR_SELECT_COINS_LINK}
/>
</StyledLinkEmpty>
),
}}
/>{' '}
</Gray>
</Empty>
);
}
isTopMenuEmpty() {
const numberOfVisibleNetworks = this.props.localStorage.config.networks
.filter(item => !item.isHidden) // hide coins globally in config
5 years ago
.filter(item => !this.props.wallet.hiddenCoins.includes(item.shortcut));
return numberOfVisibleNetworks.length <= 0;
}
isBottomMenuEmpty() {
5 years ago
const { hiddenCoinsExternal } = this.props.wallet;
const numberOfVisibleNetworks = coins
.filter(item => !item.isHidden)
5 years ago
.filter(item => !hiddenCoinsExternal.includes(item.id));
return numberOfVisibleNetworks.length <= 0;
}
isMenuEmpty() {
return this.isTopMenuEmpty() && this.isBottomMenuEmpty();
}
render() {
const { hiddenCoins } = this.props.wallet;
const { config } = this.props.localStorage;
6 years ago
return (
Integration tests (#311) * Add base test env * Add eslint rules for cypress * Add configs and scripts in package json * Added docker file for bridge and emualator * Bridge install progress * Bridge install next step * Add task for integration tests * Fixed deps * Added baseUrl * Added baseUrl fix * Added npx * Added caching for cypress bin * Added path to binary * Install cypress * Finalized dockerfile * Fixed bridge lib path * Fixed path for binary * Adjust script again * Run all the things properly * Try to run the tests * First POC test * First POC test in gitlab * Fixed flow * Fixed gitlab test url, try docker service * export artifacts * Test only integration tests in CI * Test only integration tests in CI 2 * Test only integration tests in CI 3 * Added tests for initialize device * Try to add docker in only one step * Turn on other integration steps * Correct node version * Ignore cache in flow * Run bridge and emulator in debug link mode * Fix param * Try to run new config in CI * init device in docker * Remove docker image after run * Remove amp * Fix path * Artifacts on fail * Artifacts on fail with volume * Artifacts on fail with volume 2 * Install mkdir * Install mkdir again * test * test 2 * test 3 * test 4 * test 5 * test 6 * test 7 * test 8 * test 9 * test 10 * test 11 * test 12 * test 13 * test 14 * test 15 * test 16 * test 17 * Revert "test 17" This reverts commit f3f6c0d6906cdc470aa11ae728b4b61a6b71a732. * test 18 * test 19 * test 20 * test 21 try chrome * test 22 * test 23 * test 24 * test 25 * test 25 try to install chrome again * test 25 try to install chrome again * Added missing deps * Added debug * Install chromium * Install chromium 2 * turn on chromium * turn off debug * turn on debug * fix folder * turn off debug * Fix init device * Add header dashboard test * Bring things back * clean * clean fix * Build image in CI * Added stage step * Added docker image * Added service * Added tests to docker image * Refactor a bit * Correct registry image * Build wallet again * Add test for dashbaord content * new node version, more tests * Remove unused code * typo * Correct snapshots, moved deps to dev, beta disclaimer prop
5 years ago
<Wrapper data-test="Main__page__coin__menu">
{this.isMenuEmpty() || (this.isTopMenuEmpty() && this.getEmptyContent())}
5 years ago
{config.networks
.filter(item => !item.isHidden) // hide coins globally in config
.filter(item => !hiddenCoins.includes(item.shortcut)) // hide coins by user settings
5 years ago
.sort((a, b) => a.order - b.order)
.map(item => (
<NavLink
key={item.shortcut}
to={`${this.getBaseUrl()}/network/${item.shortcut}/account/0`}
>
<RowCoin
network={{
name: item.name,
shortcut: item.shortcut,
}}
/>
</NavLink>
))}
{!this.isMenuEmpty() && (
<Divider
testId="Main__page__coin__menu__divider"
textLeft={<FormattedMessage {...l10nMessages.TR_OTHER_COINS} />}
hasBorder
/>
)}
{this.isBottomMenuEmpty() && this.getEmptyContent()}
{!this.isBottomMenuEmpty() && 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;