changed walletcard to have an internal state and not props.

This commit is contained in:
Giulio De Pasquale 2020-12-19 21:53:47 +00:00
parent 9a1a63533b
commit 7208ed7d47

View File

@ -1,5 +1,5 @@
import React, {Component} from 'react'; import React, {Component} from 'react';
import * as Icon from 'react-cryptocoins'; import {Currency} from "../types";
type CardProps = { type CardProps = {
title: string, title: string,
@ -73,20 +73,28 @@ export class SidebarCard extends Component<CardProps> {
} }
} }
export type WalletCardProps = { export type WalletCardState = {
balances: Array<CoinBalanceProps>, balances: Array<CoinBalanceProps>,
total_balance: number, total_balance: number,
quote_symbol: string quote: Currency,
}
export class WalletCard extends Component<{}, WalletCardState> {
state = {
balances: [],
total_balance: 0,
quote: {name: "USD", short_name: "$"}
} }
export class WalletCard extends Component<WalletCardProps> {
constructor(props) { constructor(props) {
super(props); super(props);
} }
renderCoinBalances() { renderCoinBalances() {
return ( return (
this.props.balances.map((balance) => { this.state.balances.map((balance) => {
return ( return (
<CoinBalance icon={balance.icon} name={balance.name} amount={balance.amount} short={balance.short} <CoinBalance icon={balance.icon} name={balance.name} amount={balance.amount} short={balance.short}
quote_equivalent={balance.quote_equivalent} percentage={balance.percentage} quote_equivalent={balance.quote_equivalent} percentage={balance.percentage}
@ -121,7 +129,7 @@ export class WalletCard extends Component<WalletCardProps> {
<div className="px-6 py-4"> <div className="px-6 py-4">
<div className="text-center text-gray-400"> <div className="text-center text-gray-400">
Total Balance &asymp; {this.props.quote_symbol}{this.props.total_balance.toFixed(2)} Total Balance &asymp; {this.state.quote_symbol}{this.props.total_balance.toFixed(2)}
</div> </div>
</div> </div>
</div> </div>