Last active
April 30, 2018 17:48
-
-
Save kolomeetz/87c7fb24cfeaf5de71f3cf50151a5975 to your computer and use it in GitHub Desktop.
CoinList
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import * as types from '../constants' | |
import Coin from './Coin' | |
class CoinList extends Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
total_valuation: 0, | |
} | |
} | |
componentDidMount() { | |
} | |
calculateTotalValuation() { | |
this.state.total_valuation = 0 | |
this.props.coin_data.data.map((coin_datum) => { | |
for (var i = 0; i < this.props.user_coins.length; i++) { | |
if (this.props.user_coins[i][types.USER_COINS_TICKER] == coin_datum.symbol) { | |
this.state.total_valuation += coin_datum.price_usd * this.props.user_coins[i][types.USER_COINS_QUANTITY] | |
} | |
} | |
}, this) | |
} | |
render() { | |
const coins = this.props.coin_data.data.map((coin_datum) => { | |
for (var i = 0; i < this.props.user_coins.length; i++) { | |
if (this.props.user_coins[i][types.USER_COINS_TICKER] == coin_datum.symbol) { | |
return ( | |
<Coin key={coin_datum.symbol} id={coin_datum.symbol} name={coin_datum.name} price={coin_datum.price_usd} | |
quantity={this.props.user_coins[i].quantity} editUserCoinQuantity={this.props.editUserCoinQuantity} | |
removeUserCoin={this.props.removeUserCoin}/>) | |
} | |
} | |
}, this) | |
this.calculateTotalValuation() | |
return ( | |
<div> | |
<table className="table table-hover"> | |
<thead> | |
<tr> | |
<th></th> | |
<th>Name</th> | |
<th>Symbol</th> | |
<th>Price</th> | |
<th>Quantity</th> | |
<th>Value</th> | |
</tr> | |
</thead> | |
<tbody> | |
{coins} | |
</tbody> | |
</table> | |
<h2>TOTAL: ${this.state.total_valuation}</h2> | |
</div> | |
) | |
} | |
} | |
export default CoinList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment