1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-28 03:08:30 +00:00

Convert 'CoinSelection' to a class component

This commit is contained in:
Vasek Mlejnsky 2018-08-16 12:26:40 +02:00
parent 0410735c2a
commit f8c11f918e

View File

@ -3,7 +3,8 @@ import coins from 'constants/coins';
import colors from 'config/colors'; import colors from 'config/colors';
import ICONS from 'config/icons'; import ICONS from 'config/icons';
import { NavLink } from 'react-router-dom'; import { NavLink } from 'react-router-dom';
import React from 'react'; import PropTypes from 'prop-types';
import React, { Component } from 'react';
import AsideDivider from './AsideDivider'; import AsideDivider from './AsideDivider';
import AsideRowCoin from './row/coin/AsideRowCoin'; import AsideRowCoin from './row/coin/AsideRowCoin';
@ -12,11 +13,10 @@ import AsideRowCoin from './row/coin/AsideRowCoin';
import type { Props } from './index'; import type { Props } from './index';
const CoinSelection = (props: Props) => { class CoinSelection extends Component {
const { config } = props.localStorage; getBaseUrl() {
const { selectedDevice } = props.wallet; const { selectedDevice } = this.props.wallet;
let baseUrl = '';
let baseUrl: string = '';
if (selectedDevice && selectedDevice.features) { if (selectedDevice && selectedDevice.features) {
baseUrl = `/device/${selectedDevice.features.device_id}`; baseUrl = `/device/${selectedDevice.features.device_id}`;
if (selectedDevice.instance) { if (selectedDevice.instance) {
@ -24,9 +24,14 @@ const CoinSelection = (props: Props) => {
} }
} }
const walletCoins = config.coins.map((item) => { return baseUrl;
const url = `${baseUrl}/network/${item.network}/account/0`; }
render() {
const { config } = this.props.localStorage;
return (
<React.Fragment>
{config.coins.map((item) => {
let imgName = item.network; let imgName = item.network;
if (item.network === 'ethereum') { if (item.network === 'ethereum') {
imgName = 'eth'; imgName = 'eth';
@ -36,7 +41,10 @@ const CoinSelection = (props: Props) => {
const imgUrl = `../images/${imgName}-logo.png`; const imgUrl = `../images/${imgName}-logo.png`;
return ( return (
<NavLink to={url}> <NavLink
key={item.network}
to={`${this.getBaseUrl()}/network/${item.network}/account/0`}
>
<AsideRowCoin <AsideRowCoin
coin={{ coin={{
img: imgUrl, img: imgUrl,
@ -45,9 +53,12 @@ const CoinSelection = (props: Props) => {
/> />
</NavLink> </NavLink>
); );
}); })}
<AsideDivider
const externalCoins = coins.map(coin => ( textLeft="Other coins"
textRight="(You will be redirected)"
/>
{coins.map(coin => (
<a href={coin.url}> <a href={coin.url}>
<AsideRowCoin <AsideRowCoin
coin={{ coin={{
@ -60,19 +71,17 @@ const CoinSelection = (props: Props) => {
}} }}
/> />
</a> </a>
)); ))}
</React.Fragment>
return (
<AsideSection>
{ walletCoins }
<AsideDivider
textLeft="Other coins"
textRight="(You will be redirected)"
/>
{ externalCoins }
</AsideSection>
); );
}
}
CoinSelection.propTypes = {
config: PropTypes.object,
wallet: PropTypes.object,
selectedDevice: PropTypes.object,
localStorage: PropTypes.object,
}; };
export default CoinSelection; export default CoinSelection;