import { PortfolioMetrics } from 'common/user' import { formatMoney } from 'common/util/format' import { last } from 'lodash' import { memo, useState } from 'react' import { Period } from 'web/lib/firebase/users' import { Col } from '../layout/col' import { Row } from '../layout/row' import { PortfolioValueGraph } from './portfolio-value-graph' export const PortfolioValueSection = memo( function PortfolioValueSection(props: { portfolioHistory: PortfolioMetrics[] }) { const { portfolioHistory } = props const lastPortfolioMetrics = last(portfolioHistory) const [portfolioPeriod, setPortfolioPeriod] = useState('allTime') if (portfolioHistory.length === 0 || !lastPortfolioMetrics) { return <> } // PATCH: If portfolio history started on June 1st, then we label it as "Since June" // instead of "All time" const allTimeLabel = lastPortfolioMetrics.timestamp < Date.parse('2022-06-20T00:00:00.000Z') ? 'Since June' : 'All time' return (
Portfolio value
{formatMoney( lastPortfolioMetrics.balance + lastPortfolioMetrics.investmentValue )}
) } )