Rewrite coin logo component to use import

pull/85/head
Vladimir Volek 6 years ago
parent c3e984301e
commit c7c346e6fc

@ -2,6 +2,5 @@ public
build build
build-devel build-devel
coverage coverage
images
node_modules node_modules
src/flowtype/npm src/flowtype/npm

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

@ -1,40 +1,58 @@
import React from 'react'; import React, { Component } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { ICON_SIZE } from 'config/variables';
const Wrapper = styled.div`
const Logo = styled.div` padding-right: 20px;
height: ${ICON_SIZE.BASE}; width: 40px;
width: ${ICON_SIZE.BASE}; `;
margin-right: 5px;
background-repeat: no-repeat; const Logo = styled.img`
background-position: center; width: ${props => (props.hasLongIcon ? '15px' : '23px')};
background-size: auto ${ICON_SIZE.BASE}; margin-left: ${props => (props.hasLongIcon ? '3px' : '0px')};
background-image: url('${props => props.coinImg}'); display: block;
`; `;
const CoinLogo = ({ class CoinLogo extends Component {
className, coinNetwork, coinImg, constructor() {
}) => { super();
let coinImgName = coinNetwork; this.longIcons = ['etc', 'eth', 'trop'];
if (coinImgName === 'ethereum') {
coinImgName = 'eth';
} else if (coinImgName === 'ethereum-classic') {
coinImgName = 'etc';
} }
const coinImgUrl = `../images/${coinImgName}-logo.png`;
getIcon() {
return ( const { coinNetwork, coinId } = this.props;
<Logo let coinImgName = coinNetwork;
className={className} if (coinImgName === 'ethereum') {
coinImg={coinImgName ? coinImgUrl : coinImg} coinImgName = 'eth';
/> } else if (coinImgName === 'ethereum-classic') {
); coinImgName = 'etc';
}; }
return coinImgName || coinId;
}
hasLongIcon(coinImgName) {
let hasLongIcon = false;
if (this.longIcons.includes(coinImgName)) {
hasLongIcon = true;
}
return hasLongIcon;
}
render() {
const iconName = this.getIcon();
return (
<Wrapper>
<Logo
hasLongIcon={this.hasLongIcon(iconName)}
src={require(`./images/${iconName}.png`)} // eslint-disable-line
/>
</Wrapper>
);
}
}
CoinLogo.propTypes = { CoinLogo.propTypes = {
className: PropTypes.string, coinId: PropTypes.string,
coinImg: PropTypes.string,
coinNetwork: PropTypes.string, coinNetwork: PropTypes.string,
}; };

@ -1,32 +1,26 @@
export default [ export default [
{ {
id: 'btc',
coinName: 'Bitcoin', coinName: 'Bitcoin',
url: 'https://wallet.trezor.io/#/coin/btc',
image: '../images/btc-logo.png',
}, },
{ {
id: 'ltc',
coinName: 'Litecoin', coinName: 'Litecoin',
url: 'https://wallet.trezor.io/#/coin/ltc',
image: '../images/ltc-logo.png',
}, },
{ {
id: 'bch',
coinName: 'Bitcoin Cash', coinName: 'Bitcoin Cash',
url: 'https://wallet.trezor.io/#/coin/bch',
image: '../images/bch-logo.png',
}, },
{ {
id: 'btg',
coinName: 'Bitcoin Gold', coinName: 'Bitcoin Gold',
url: 'https://wallet.trezor.io/#/coin/btg',
image: '../images/btg-logo.png',
}, },
{ {
id: 'dash',
coinName: 'Dash', coinName: 'Dash',
url: 'https://wallet.trezor.io/#/coin/dash',
image: '../images/dash-logo.png',
}, },
{ {
id: 'zec',
coinName: 'Zcash', coinName: 'Zcash',
url: 'https://wallet.trezor.io/#/coin/zec',
image: '../images/zec-logo.png',
}, },
]; ];

@ -24,6 +24,10 @@ class CoinMenu extends Component {
return baseUrl; return baseUrl;
} }
getCoinUrl(coinId) {
return `https://wallet.trezor.io/#/coin/${coinId}`;
}
render() { render() {
const { config } = this.props.localStorage; const { config } = this.props.localStorage;
return ( return (
@ -47,11 +51,11 @@ class CoinMenu extends Component {
hasBorder hasBorder
/> />
{coins.map(coin => ( {coins.map(coin => (
<a key={coin.url} href={coin.url}> <a key={this.getCoinUrl(coin.id)} href={this.getCoinUrl(coin.id)}>
<RowCoin <RowCoin
coin={{ coin={{
name: coin.coinName, name: coin.coinName,
img: coin.image, id: coin.id,
}} }}
iconRight={{ iconRight={{
type: ICONS.SKIP, type: ICONS.SKIP,

@ -37,10 +37,6 @@ const IconWrapper = styled.div`
margin-right: 10px; margin-right: 10px;
`; `;
const LogoWrapper = styled.div`
margin-right: 3px;
`;
const RowCoin = ({ const RowCoin = ({
coin, iconLeft, iconRight, coin, iconLeft, iconRight,
}) => ( }) => (
@ -57,12 +53,10 @@ const RowCoin = ({
</IconWrapper> </IconWrapper>
)} )}
<CoinNameWrapper> <CoinNameWrapper>
<LogoWrapper> <CoinLogo
<CoinLogo coinNetwork={coin.network}
coinNetwork={coin.network} coinId={coin.id}
coinImg={coin.img} />
/>
</LogoWrapper>
<p>{coin.name}</p> <p>{coin.name}</p>
</CoinNameWrapper> </CoinNameWrapper>
</Left> </Left>
@ -86,7 +80,7 @@ RowCoin.propTypes = {
coin: PropTypes.shape({ coin: PropTypes.shape({
name: PropTypes.string.isRequired, name: PropTypes.string.isRequired,
network: PropTypes.string, network: PropTypes.string,
img: PropTypes.string, id: PropTypes.string,
}).isRequired, }).isRequired,
iconLeft: PropTypes.shape(iconShape), iconLeft: PropTypes.shape(iconShape),
iconRight: PropTypes.shape(iconShape), iconRight: PropTypes.shape(iconShape),

Loading…
Cancel
Save