Skip to content

Commit

Permalink
fix loans not showing when subquery is down
Browse files Browse the repository at this point in the history
  • Loading branch information
onnovisser committed Dec 18, 2024
1 parent e6d6f4b commit fa31d58
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
14 changes: 5 additions & 9 deletions centrifuge-app/src/components/LoanList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useBasePath } from '@centrifuge/centrifuge-app/src/utils/useBasePath'
import { AssetSnapshot, CurrencyBalance, Loan, Pool, TinlakeLoan } from '@centrifuge/centrifuge-js'
import { CurrencyBalance, Loan, Pool, TinlakeLoan } from '@centrifuge/centrifuge-js'
import {
AnchorButton,
Box,
Expand Down Expand Up @@ -27,10 +27,9 @@ import { formatBalance, formatPercentage } from '../utils/formatting'
import { useFilters } from '../utils/useFilters'
import { useMetadata } from '../utils/useMetadata'
import { useCentNFT } from '../utils/useNFTs'
import { usePool, usePoolMetadata } from '../utils/usePools'
import { useAllPoolAssetSnapshots, usePool, usePoolMetadata } from '../utils/usePools'
import { Column, DataTable, SortableTableHeader } from './DataTable'
import { prefetchRoute } from './Root'
import { Spinner } from './Spinner'

type Row = (Loan | TinlakeLoan) & {
idSortKey: number
Expand All @@ -46,15 +45,14 @@ type Row = (Loan | TinlakeLoan) & {

type Props = {
loans: Loan[] | TinlakeLoan[]
snapshots: AssetSnapshot[]
isLoading: boolean
}

export function LoanList({ loans, snapshots, isLoading }: Props) {
export function LoanList({ loans }: Props) {
const { pid: poolId } = useParams<{ pid: string }>()
if (!poolId) throw new Error('Pool not found')

const navigate = useNavigate()
const { data: snapshots } = useAllPoolAssetSnapshots(poolId, new Date().toISOString().slice(0, 10))
const pool = usePool(poolId)
const isTinlakePool = poolId?.startsWith('0x')
const basePath = useBasePath()
Expand Down Expand Up @@ -267,8 +265,6 @@ export function LoanList({ loans, snapshots, isLoading }: Props) {

const csvUrl = React.useMemo(() => csvData && getCSVDownloadUrl(csvData as any), [csvData])

if (isLoading) return <Spinner />

return (
<>
<Box pt={1} pb={2} paddingX={1} display="flex" justifyContent="space-between" alignItems="center">
Expand All @@ -293,7 +289,7 @@ export function LoanList({ loans, snapshots, isLoading }: Props) {
View asset transactions
</Button>
<AnchorButton
href={csvUrl}
href={csvUrl ?? ''}
download={`pool-assets-${poolId}.csv`}
variant="inverted"
icon={IconDownload}
Expand Down
14 changes: 5 additions & 9 deletions centrifuge-app/src/pages/Pool/Assets/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Dec } from '../../../utils/Decimal'
import { formatBalance } from '../../../utils/formatting'
import { useLoans } from '../../../utils/useLoans'
import { useSuitableAccounts } from '../../../utils/usePermissions'
import { useAllPoolAssetSnapshots, usePool } from '../../../utils/usePools'
import { usePool } from '../../../utils/usePools'
import { PoolDetailHeader } from '../Header'
import { OffchainMenu } from './OffchainMenu'

Expand Down Expand Up @@ -44,11 +44,7 @@ export function PoolDetailAssets() {
if (!poolId) throw new Error('Pool not found')

const pool = usePool(poolId)
const { data: loans, isLoading } = useLoans(poolId)
const { data: snapshots, isLoading: isLoadingSnapshots } = useAllPoolAssetSnapshots(
poolId,
new Date().toISOString().slice(0, 10)
)
const { data: loans } = useLoans(poolId)
const isTinlakePool = poolId.startsWith('0x')
const basePath = useBasePath()
const cashLoans = (loans ?? []).filter(
Expand Down Expand Up @@ -90,7 +86,7 @@ export function PoolDetailAssets() {
)

const total = isTinlakePool ? pool.nav.total : pool.reserve.total.toDecimal().add(offchainReserve).add(totalAssets)
const totalNAV = isTinlakePool ? pool.nav.total : Dec(total).sub(pool.fees.totalPaid.toDecimal())
const totalNAV = isTinlakePool ? pool.nav.total : Dec(total as any).sub(pool.fees.totalPaid.toDecimal())

const pageSummaryData: { label: React.ReactNode; value: React.ReactNode; heading?: boolean }[] = [
{
Expand All @@ -112,7 +108,7 @@ export function PoolDetailAssets() {
? [
{
label: <Tooltips label="Offchain cash (USD)" type="offchainCash" />,
value: <OffchainMenu value={formatBalance(offchainReserve)} loans={cashLoans} />,
value: <OffchainMenu value={formatBalance(offchainReserve)} loans={cashLoans as Loan[]} />,
heading: false,
},
{
Expand All @@ -135,7 +131,7 @@ export function PoolDetailAssets() {
<CreateAssetButton poolId={poolId} />
</PageSummary>
<Box paddingX={3}>
<LoanList loans={loans} snapshots={snapshots} isLoading={isLoadingSnapshots || isLoading} />
<LoanList loans={loans} />
</Box>
</>
)
Expand Down

0 comments on commit fa31d58

Please sign in to comment.