Skip to content

Commit

Permalink
Centrifuge App: Fix investor transaction report (#1675)
Browse files Browse the repository at this point in the history
  • Loading branch information
onnovisser authored Nov 1, 2023
1 parent 3ae0643 commit 70c8e32
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 44 deletions.
35 changes: 21 additions & 14 deletions centrifuge-app/src/components/Report/PoolBalance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,27 @@ export function PoolBalance({ pool }: { pool: Pool }) {
cell: (row: TableDataRow) => <Text variant={row.heading ? 'heading4' : 'body2'}>{row.name}</Text>,
width: '200px',
},
].concat(
poolStates.map((state, index) => ({
align: 'right',
header: `${new Date(state.timestamp).toLocaleDateString('en-US', {
month: 'short',
})} ${
groupBy === 'day'
? new Date(state.timestamp).toLocaleDateString('en-US', { day: 'numeric' })
: new Date(state.timestamp).toLocaleDateString('en-US', { year: 'numeric' })
}`,
cell: (row: TableDataRow) => <Text variant="body2">{(row.value as any)[index]}</Text>,
width: '120px',
}))
)
]
.concat(
poolStates.map((state, index) => ({
align: 'right',
header: `${new Date(state.timestamp).toLocaleDateString('en-US', {
month: 'short',
})} ${
groupBy === 'day'
? new Date(state.timestamp).toLocaleDateString('en-US', { day: 'numeric' })
: new Date(state.timestamp).toLocaleDateString('en-US', { year: 'numeric' })
}`,
cell: (row: TableDataRow) => <Text variant="body2">{(row.value as any)[index]}</Text>,
width: '120px',
}))
)
.concat({
align: 'left',
header: '',
cell: () => <span />,
width: '1fr',
})
}, [poolStates, groupBy])

const overviewRecords: TableDataRow[] = React.useMemo(() => {
Expand Down
2 changes: 1 addition & 1 deletion centrifuge-app/src/components/Report/ReportContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const defaultContext = {
report: 'pool-balance' as Report,
setReport() {},

groupBy: 'day' as GroupBy,
groupBy: 'month' as GroupBy,
setGroupBy() {},

activeTranche: 'all',
Expand Down
49 changes: 20 additions & 29 deletions centrifuge-js/src/modules/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2084,7 +2084,6 @@ export function getPoolsModule(inst: Centrifuge) {

function getInvestorTransactions(args: [poolId: string, trancheId?: string, from?: Date, to?: Date]) {
const [poolId, trancheId, from, to] = args
const $api = inst.getApi()

const $query = inst.getSubqueryObservable<{
investorTransactions: { nodes: SubqueryInvestorTransaction[] }
Expand Down Expand Up @@ -2121,35 +2120,27 @@ export function getPoolsModule(inst: Centrifuge) {
}
)

return $api.pipe(
switchMap((api) =>
combineLatest([$query, api.query.poolSystem.pool(poolId).pipe(take(1)), getCurrencies()]).pipe(
switchMap(([queryData, poolValue, currencies]) => {
const pool = poolValue.toHuman() as unknown as PoolDetailsData
const currency = findCurrency(currencies, pool.currency)!
const currencyDecimals = currency.decimals
return combineLatest([$query, getPoolCurrency([poolId])]).pipe(
switchMap(([queryData, currency]) => {
const currencyDecimals = currency.decimals

return [
queryData?.investorTransactions.nodes.map((tx) => {
return {
id: tx.id,
timestamp: new Date(tx.timestamp),
accountId: tx.accountId,
trancheId: tx.trancheId,
epochNumber: tx.epochNumber,
type: tx.type as InvestorTransactionType,
currencyAmount: tx.currencyAmount
? new CurrencyBalance(tx.currencyAmount, currencyDecimals)
: undefined,
tokenAmount: tx.tokenAmount ? new CurrencyBalance(tx.tokenAmount, currencyDecimals) : undefined,
tokenPrice: tx.tokenPrice ? new Price(tx.tokenPrice) : undefined,
transactionFee: tx.transactionFee ? new CurrencyBalance(tx.transactionFee, 18) : undefined, // native tokenks are always denominated in 18
}
}) as unknown as InvestorTransaction[],
]
})
)
)
return [
queryData?.investorTransactions.nodes.map((tx) => {
return {
id: tx.id,
timestamp: new Date(tx.timestamp),
accountId: tx.accountId,
trancheId: tx.trancheId,
epochNumber: tx.epochNumber,
type: tx.type as InvestorTransactionType,
currencyAmount: tx.currencyAmount ? new CurrencyBalance(tx.currencyAmount, currencyDecimals) : undefined,
tokenAmount: tx.tokenAmount ? new CurrencyBalance(tx.tokenAmount, currencyDecimals) : undefined,
tokenPrice: tx.tokenPrice ? new Price(tx.tokenPrice) : undefined,
transactionFee: tx.transactionFee ? new CurrencyBalance(tx.transactionFee, 18) : undefined, // native tokenks are always denominated in 18
}
}) as unknown as InvestorTransaction[],
]
})
)
}

Expand Down

0 comments on commit 70c8e32

Please sign in to comment.