diff --git a/centrifuge-app/src/components/Charts/PoolPerformanceChart.tsx b/centrifuge-app/src/components/Charts/PoolPerformanceChart.tsx index d1702e70e..2abb06ae4 100644 --- a/centrifuge-app/src/components/Charts/PoolPerformanceChart.tsx +++ b/centrifuge-app/src/components/Charts/PoolPerformanceChart.tsx @@ -204,7 +204,6 @@ function PoolPerformanceChart() { return result } - return ( @@ -479,8 +478,9 @@ function CustomLegend({ ) } -const CustomTick = ({ x, y, payload }: any) => { +export const CustomTick = ({ x, y, payload }: any) => { const theme = useTheme() + return ( { + const theme = useTheme() + + const getOneDayPerMonth = () => { + const seenMonths = new Set() + const result: string[] = [] + + data.forEach((item) => { + const date = new Date(item.name) + const month = date.getMonth() + 1 + const year = date.getFullYear() + const monthYear = `${year}-${month}` + + if (!seenMonths.has(monthYear)) { + seenMonths.add(monthYear) + result.push(item.name) + } + }) + + return result + } + + if (!data.length) return + return ( + + + + + } + /> + formatBalanceAbbreviated(tick, '', 0)} + tick={{ fontSize: 10, color: theme.colors.textPrimary }} + tickLine={false} + /> + { + if (payload && payload?.length > 0) { + return ( + + {formatDate(payload[0].payload.name)} + {payload.map((item) => ( + {formatBalance(item.value as number, currency)} + ))} + + ) + } + }} + /> + + + + + ) +} diff --git a/centrifuge-app/src/components/Report/BalanceSheet.tsx b/centrifuge-app/src/components/Report/BalanceSheet.tsx index fee1b7f3b..e7bf62c4a 100644 --- a/centrifuge-app/src/components/Report/BalanceSheet.tsx +++ b/centrifuge-app/src/components/Report/BalanceSheet.tsx @@ -20,7 +20,7 @@ type Row = TableDataRow & { } export function BalanceSheet({ pool }: { pool: Pool }) { - const { startDate, endDate, groupBy, setCsvData } = React.useContext(ReportContext) + const { startDate, endDate, groupBy, setCsvData, setReportData, reportData } = React.useContext(ReportContext) const [adjustedStartDate, adjustedEndDate] = React.useMemo(() => { const today = new Date() @@ -239,6 +239,10 @@ export function BalanceSheet({ pool }: { pool: Pool }) { // eslint-disable-next-line react-hooks/exhaustive-deps }, [assetValuationRecords, trancheRecords]) + React.useEffect(() => { + setReportData(poolStates) + }, [assetValuationRecords, trancheRecords]) + if (!poolStates) { return } diff --git a/centrifuge-app/src/components/Report/ReportContext.tsx b/centrifuge-app/src/components/Report/ReportContext.tsx index e9a9876c1..ead107ef0 100644 --- a/centrifuge-app/src/components/Report/ReportContext.tsx +++ b/centrifuge-app/src/components/Report/ReportContext.tsx @@ -49,6 +49,9 @@ export type ReportContextType = { loan: string setLoan: (type: string) => void + + reportData: any + setReportData: (type: any) => void } export type CsvDataProps = { @@ -78,6 +81,7 @@ export function ReportContextProvider({ children }: { children: React.ReactNode const [address, setAddress] = React.useState(searchParams.get('address') || '') const [network, setNetwork] = React.useState(searchParams.get('network') || 'all') const [loan, setLoan] = React.useState(searchParams.get('loan') || '') + const [reportData, setReportData] = React.useState([]) React.useEffect(() => { const startDate = searchParams.get('from') @@ -170,6 +174,8 @@ export function ReportContextProvider({ children }: { children: React.ReactNode setNetwork: (value: any) => updateParamValues('network', value), loan, setLoan: (value: string) => updateParamValues('asset', value), + reportData, + setReportData, }} > {children} diff --git a/centrifuge-app/src/components/Report/ReportFilter.tsx b/centrifuge-app/src/components/Report/ReportFilter.tsx index 65c5151b0..2eb215f8f 100644 --- a/centrifuge-app/src/components/Report/ReportFilter.tsx +++ b/centrifuge-app/src/components/Report/ReportFilter.tsx @@ -1,4 +1,4 @@ -import { Pool } from '@centrifuge/centrifuge-js' +import { CurrencyBalance, Pool } from '@centrifuge/centrifuge-js' import { AnchorButton, Box, @@ -15,6 +15,7 @@ import * as React from 'react' import { useNavigate } from 'react-router' import styled from 'styled-components' import { useBasePath } from '../../utils/useBasePath' +import { SimpleBarChart } from '../Charts/SimpleBarChart' import { GroupBy, ReportContext } from './ReportContext' interface StyledButtonProps { @@ -37,102 +38,118 @@ type ReportFilterProps = { } export function ReportFilter({ pool }: ReportFilterProps) { - const { csvData, setStartDate, startDate, endDate, setEndDate, groupBy, setGroupBy, report } = + const { csvData, setStartDate, startDate, endDate, setEndDate, groupBy, setGroupBy, report, reportData } = React.useContext(ReportContext) const navigate = useNavigate() const basePath = useBasePath() + const transformDataChart = React.useMemo(() => { + if (report === 'balance-sheet') { + return reportData.map((data: { timestamp: string; netAssetValue: CurrencyBalance }) => ({ + name: data.timestamp, + yAxis: new CurrencyBalance(data.netAssetValue, pool.currency.decimals).toDecimal().toNumber(), + })) + } + }, [report, reportData]) + return ( - - } - onClick={() => navigate(`${basePath}/${pool.id}/reporting/balance-sheet`)} - > - Balance sheet - - } - onClick={() => navigate(`${basePath}/${pool.id}/reporting/profit-and-loss`)} - > - Profit & loss - - } - onClick={() => navigate(`${basePath}/${pool.id}/reporting/cash-flow-statement`)} - > - Cash flow - - - - - - { + setGroupBy(event.target.value as GroupBy) + }} + value={groupBy} + options={[ + { label: 'Day', value: 'day' }, + { label: 'Daily', value: 'daily' }, + { label: 'Monthly', value: 'month' }, + { label: 'Quarterly', value: 'quarter' }, + { label: 'Yearly', value: 'year' }, + ]} + hideBorder + /> + + + {groupBy === 'day' && ( + setStartDate(e.target.value)} /> + )} + + {groupBy === 'month' || groupBy === 'daily' ? ( + <> + + setStartDate(e.target.value)} + /> + + + setEndDate(e.target.value)} + /> + + + ) : null} + } + small + variant="inverted" + > + CSV + + + + + )