Skip to content

Commit

Permalink
Fix assets table quantity and pagination (#2560)
Browse files Browse the repository at this point in the history
* Fix quantity

* Fix pagination

* Fix bug
  • Loading branch information
kattylucy authored Dec 18, 2024
1 parent df6cf97 commit 7cba4b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
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

0 comments on commit 7cba4b7

Please sign in to comment.