CoinList.jsx
import React from 'react';
import Coin from '../Coin/Coin';
import styled from 'styled-components';
const TableCoin = styled.table`
margin: 50px auto 50px auto;
display: inline-block;
font-size: 1.4rem;
`;
export default function CoinList(props) {
let tableBalance = null;
if (props.showBalance) {
tableBalance = <td>Balance</td>;
}
return (
<TableCoin>
<thead>
<tr>
<td>Name</td>
<td>Ticker</td>
{tableBalance}
<td>Price($)</td>
</tr>
</thead>
<tbody>
{
props.coinData.map(
({key, name, ticker, balance, price}) =>
<Coin key={key} id={key} name={name} ticker={ticker} balance={balance} price={price} handleRefresh={props.handleRefresh} showBalance={props.showBalance} />
)
}
</tbody>
</TableCoin>
)
}
AccountBalance.jsx
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
const Section = styled.section`
color: rgb(121, 209, 121);
text-align: right;
padding: 1rem 3rem 1rem 0rem;
`;
export default function AccountBalance(props) {
const balanceButtonText = props.showBalance ? 'Hide Balance' : 'Show Balance';
let accountBalance = null;
if (props.showBalance) {
accountBalance = <>Your Balance: {props.amount}</>;
}
return (<Section>
{accountBalance}
<button onClick={props.handleDisplayBalance}>{balanceButtonText}</button>
</Section>
);
}
AccountBalance.propTypes = {
amount: PropTypes.number.isRequired
}