Skip to content

Commit

Permalink
Fix reporting page not loading due to holder report (#1837)
Browse files Browse the repository at this point in the history
* WIP fix holders page data

* Fix investor transactions across networks

* Clean up chains

* Incorporate currency balances

* Fix copyable, remove debug flag

* Undo subquery change for now

* Fix todo

* Revert

* Use constant

* Help!

* Oops!

* Fix query

* Remove constnat

* Renames

* Remove duplicate type

* Add debug flag
  • Loading branch information
hieronx authored Jan 19, 2024
1 parent 88f96aa commit 3f78b88
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 30 deletions.
5 changes: 5 additions & 0 deletions centrifuge-app/src/components/DebugFlags/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type Key =
| 'showPrime'
| 'poolCreationType'
| 'podAdminSeed'
| 'holdersReport'

export const flagsConfig: Record<Key, DebugFlagConfig> = {
address: {
Expand Down Expand Up @@ -91,6 +92,10 @@ export const flagsConfig: Record<Key, DebugFlagConfig> = {
default: '',
type: 'text',
},
holdersReport: {
type: 'checkbox',
default: false,
},
persistDebugFlags: {
alwaysShow: true,
default: !!localStorage.getItem('debugFlags'),
Expand Down
6 changes: 3 additions & 3 deletions centrifuge-app/src/components/Report/Holders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ export function Holders({ pool }: { pool: Pool }) {
holder.evmAddress || holder.accountId,
(evmChains as any)[holder.chainId]?.name || 'Centrifuge',
formatBalance(
holder.balance.toDecimal().add(holder.sumInvestUncollectedAmount.toDecimal()),
holder.balance.toDecimal().add(holder.claimableTrancheTokens.toDecimal()), // TODO: if chain id != centrifuge (LP investor), add collected amount - redeemed amount
pool.tranches[0].currency // TODO: not hardcode to tranche index 0
),
formatBalance(holder.sumInvestOrderedAmount.toDecimal(), pool.currency),
formatBalance(holder.sumRedeemOrderedAmount.toDecimal(), pool.tranches[0].currency), // TODO: not hardcode to tranche index 0
formatBalance(holder.pendingInvestCurrency.toDecimal(), pool.currency),
formatBalance(holder.pendingRedeemTrancheTokens.toDecimal(), pool.tranches[0].currency), // TODO: not hardcode to tranche index 0
],
heading: false,
}))
Expand Down
5 changes: 4 additions & 1 deletion centrifuge-app/src/components/Report/ReportFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { Pool } from '@centrifuge/centrifuge-js'
import { AnchorButton, Box, DateRange, Select, Shelf } from '@centrifuge/fabric'
import * as React from 'react'
import { useDebugFlags } from '../DebugFlags'
import { GroupBy, Report, ReportContext } from './ReportContext'

type ReportFilterProps = {
pool: Pool
}

export function ReportFilter({ pool }: ReportFilterProps) {
const { holdersReport } = useDebugFlags()

const {
csvData,
setStartDate,
Expand All @@ -24,11 +27,11 @@ export function ReportFilter({ pool }: ReportFilterProps) {
} = React.useContext(ReportContext)

const reportOptions: { label: string; value: Report }[] = [
{ label: 'Holders', value: 'holders' },
{ label: 'Investor transactions', value: 'investor-tx' },
{ label: 'Borrower transactions', value: 'borrower-tx' },
{ label: 'Pool balance', value: 'pool-balance' },
{ label: 'Asset list', value: 'asset-list' },
...(holdersReport == true ? [{ label: 'Holders', value: 'holders' as Report }] : []),
]

return (
Expand Down
40 changes: 20 additions & 20 deletions centrifuge-js/src/modules/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,12 +730,12 @@ type Holder = {
chainId: number
evmAddress?: string
balance: CurrencyBalance
sumInvestOrderedAmount: CurrencyBalance
sumInvestUncollectedAmount: CurrencyBalance
sumInvestCollectedAmount: CurrencyBalance
sumRedeemOrderedAmount: CurrencyBalance
sumRedeemUncollectedAmount: CurrencyBalance
sumRedeemCollectedAmount: CurrencyBalance
pendingInvestCurrency: CurrencyBalance
claimableTrancheTokens: CurrencyBalance
sumClaimedTrancheTokens: CurrencyBalance
pendingRedeemTrancheTokens: CurrencyBalance
claimableCurrency: CurrencyBalance
sumClaimedCurrency: CurrencyBalance
}

export type ExternalLoan = Loan & {
Expand Down Expand Up @@ -2515,12 +2515,12 @@ export function getPoolsModule(inst: Centrifuge) {
chainId
evmAddress
}
sumInvestOrderedAmount
sumInvestUncollectedAmount
sumInvestCollectedAmount
sumRedeemOrderedAmount
sumRedeemUncollectedAmount
sumRedeemCollectedAmount
pendingInvestCurrency
claimableTrancheTokens
sumClaimedTrancheTokens
pendingRedeemTrancheTokens
claimableCurrency
sumClaimedCurrency
}
}
Expand Down Expand Up @@ -2556,15 +2556,15 @@ export function getPoolsModule(inst: Centrifuge) {

return data!.trancheBalances.nodes.map((balance) => ({
accountId: balance.accountId,
chainId: Number(balance.account.chainId),
evmAddress: balance.account.evmAddress,
chainId: Number(balance.account?.chainId || 2031),
evmAddress: balance.account?.evmAddress,
balance: new CurrencyBalance(currencyBalancesByAccountId[balance.accountId].amount, currency.decimals),
sumInvestOrderedAmount: new CurrencyBalance(balance.sumInvestOrderedAmount, currency.decimals),
sumInvestUncollectedAmount: new CurrencyBalance(balance.sumInvestUncollectedAmount, currency.decimals),
sumInvestCollectedAmount: new CurrencyBalance(balance.sumInvestCollectedAmount, currency.decimals),
sumRedeemOrderedAmount: new CurrencyBalance(balance.sumRedeemOrderedAmount, currency.decimals),
sumRedeemUncollectedAmount: new CurrencyBalance(balance.sumRedeemUncollectedAmount, currency.decimals),
sumRedeemCollectedAmount: new CurrencyBalance(balance.sumRedeemCollectedAmount, currency.decimals),
pendingInvestCurrency: new CurrencyBalance(balance.pendingInvestCurrency, currency.decimals),
claimableTrancheTokens: new CurrencyBalance(balance.claimableTrancheTokens, currency.decimals),
sumClaimedTrancheTokens: new CurrencyBalance(balance.sumClaimedTrancheTokens, currency.decimals),
pendingRedeemTrancheTokens: new CurrencyBalance(balance.pendingRedeemTrancheTokens, currency.decimals),
claimableCurrency: new CurrencyBalance(balance.claimableCurrency, currency.decimals),
sumClaimedCurrency: new CurrencyBalance(balance.sumClaimedCurrency, currency.decimals),
})) as unknown as Holder[]
})
)
Expand Down
12 changes: 6 additions & 6 deletions centrifuge-js/src/types/subquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ export type SubqueryTrancheBalances = {
}
poolId: string
trancheId: string
sumInvestOrderedAmount: string
sumInvestUncollectedAmount: string
sumInvestCollectedAmount: string
sumRedeemOrderedAmount: string
sumRedeemUncollectedAmount: string
sumRedeemCollectedAmount: string
pendingInvestCurrency: string
claimableTrancheTokens: string
sumClaimedTrancheTokens: string
pendingRedeemTrancheTokens: string
claimableCurrency: string
sumClaimedCurrency: string
}

export type SubqueryCurrencyBalances = {
Expand Down

0 comments on commit 3f78b88

Please sign in to comment.