Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix assets table quantity and pagination #2560

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions centrifuge-app/src/components/LoanList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ export function LoanList({ loans, snapshots, isLoading }: Props) {
]),
].filter(Boolean) as Column[]

const pagination = usePagination({ data: rows, pageSize: 20 })

const csvData = React.useMemo(() => {
if (!rows.length) return undefined

Expand All @@ -266,6 +264,8 @@ export function LoanList({ loans, snapshots, isLoading }: Props) {
}, [rows, pool])

const csvUrl = React.useMemo(() => csvData && getCSVDownloadUrl(csvData as any), [csvData])
const filteredData = isLoading ? [] : showRepaid ? rows : rows.filter((row) => !row.marketValue?.isZero())
const pagination = usePagination({ data: filteredData, pageSize: 20 })

if (isLoading) return <Spinner />

Expand Down Expand Up @@ -293,7 +293,7 @@ export function LoanList({ loans, snapshots, isLoading }: Props) {
View asset transactions
</Button>
<AnchorButton
href={csvUrl}
href={csvUrl ?? undefined}
download={`pool-assets-${poolId}.csv`}
variant="inverted"
icon={IconDownload}
Expand All @@ -309,7 +309,7 @@ export function LoanList({ loans, snapshots, isLoading }: Props) {
<Stack gap={2}>
<Box overflow="auto">
<DataTable
data={showRepaid ? rows : rows.filter((row) => !row?.marketValue?.isZero())}
data={filteredData}
columns={columns}
onRowClicked={(row) => `${basePath}/${poolId}/assets/${row.id}`}
pageSize={20}
Expand Down Expand Up @@ -383,13 +383,18 @@ export function AssetName({ loan }: { loan: Pick<Row, 'id' | 'poolId' | 'asset'
</Shelf>
)
}
export function getAmount(l: Row, pool: Pool | TinlakePool, format?: boolean) {

export function getAmount(l: Row, pool: Pool | TinlakePool, format?: boolean, isPresentValue?: boolean) {
switch (l.status) {
case 'Closed':
return format ? formatBalance(l.totalRepaid) : l.totalRepaid

case 'Active':
if ('presentValue' in l) {
if ('outstandingQuantity' in l.pricing && !isPresentValue) {
return format ? formatBalance(l.pricing.outstandingQuantity) : l.pricing.outstandingQuantity
}

if ('presentValue' in l && isPresentValue) {
return format ? formatBalance(l.presentValue) : l.presentValue
}

Expand Down
2 changes: 1 addition & 1 deletion centrifuge-app/src/pages/Pool/Assets/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function PoolDetailAssets() {
const totalAssets = loans.reduce((sum, loan) => {
const amount =
hasValuationMethod(loan.pricing) && loan.pricing.valuationMethod !== 'cash'
? new CurrencyBalance(getAmount(loan as any, pool), pool.currency.decimals).toDecimal()
? new CurrencyBalance(getAmount(loan as any, pool, false, true), pool.currency.decimals).toDecimal()
: 0

return sum.add(amount)
Expand Down
Loading