import React, {Component} from 'react'; import {Balance, EventName, FirstConnectMessage, NewTickMessage} from "../types"; import {socket} from "../index"; import {SymbolAccessories} from "../utils"; export type CoinBalanceProps = { name: string, amount: number, percentage?: number, quote_equivalent: number, quote_symbol: string, } class CoinBalance extends Component { constructor(props) { super(props); } render() { // do not print equivalent if this element is the quote itself const quoteBlock = this.props.name != this.props.quote_symbol ? this.props.quote_symbol.concat(" ").concat(this.props.quote_equivalent.toLocaleString()) : null // const accessory = SymbolAccessories.filter((accessory) => { // return accessory.name == this.props.name // }) // // const icon = accessory.length > 0 ? accessory.pop().icon : null return (
{/*{icon}*/}
{this.props.name}
{Math.trunc(this.props.percentage)}%
{this.props.amount.toFixed(5)} {this.props.name}
{quoteBlock}
) } } export type WalletCardProps = { quote: string, } export class WalletCard extends Component <{}, { balances: Array }> { constructor(props) { super(props); } state = { balances: [] } totalQuoteBalance() { let total = 0 this.state.balances.forEach((balance: Balance) => { if (balance.currency == balance.quote) { total += balance.amount } else { total += balance.quote_equivalent } }) return total } renderCoinBalances() { return ( this.state.balances.map((balance: Balance) => { const percentage_amount = balance.quote == balance.currency ? balance.amount : balance.quote_equivalent; return ( ) }) ) } componentDidMount() { socket.on(EventName.NewTick, (data: NewTickMessage) => { this.setState({ balances: data.balances }) }) socket.on(EventName.FirstConnect, (data: FirstConnectMessage) => { this.setState({ balances: data.balances }) }) } render() { return (

Your Wallets

{this.renderCoinBalances()}
Total Balance ≈ USD {this.totalQuoteBalance().toLocaleString()}
) } }