From 1406e5bc6c485271adfd975845c8de027d5958c7 Mon Sep 17 00:00:00 2001 From: Onno Visser Date: Wed, 15 Nov 2023 09:52:31 +0100 Subject: [PATCH 1/2] Centrifuge App: Fix getting loan NFT data (#1685) --- centrifuge-app/src/components/LoanList.tsx | 6 ++++++ centrifuge-app/src/pages/Pools.tsx | 5 +++++ centrifuge-js/src/modules/nfts.ts | 6 +++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/centrifuge-app/src/components/LoanList.tsx b/centrifuge-app/src/components/LoanList.tsx index 07b2dce5d2..10131020d7 100644 --- a/centrifuge-app/src/components/LoanList.tsx +++ b/centrifuge-app/src/components/LoanList.tsx @@ -11,6 +11,7 @@ import { Thumbnail, usePagination, } from '@centrifuge/fabric' +import * as React from 'react' import { useParams, useRouteMatch } from 'react-router' import { formatNftAttribute } from '../pages/Loan/utils' import { nftMetadataSchema } from '../schemas' @@ -24,6 +25,7 @@ import { usePool, usePoolMetadata } from '../utils/usePools' import { Column, DataTable, SortableTableHeader } from './DataTable' import { LoadBoundary } from './LoadBoundary' import LoanLabel from './LoanLabel' +import { prefetchRoute } from './Root' type Row = (Loan | TinlakeLoan) & { idSortKey: number @@ -45,6 +47,10 @@ export function LoanList({ loans }: Props) { const templateId = templateIds.at(-1) const { data: templateMetadata } = useMetadata(templateId) + React.useEffect(() => { + prefetchRoute('/pools/1/assets/1') + }, []) + const additionalColumns: Column[] = templateMetadata?.keyAttributes?.map((key) => { const attr = templateMetadata.attributes![key] diff --git a/centrifuge-app/src/pages/Pools.tsx b/centrifuge-app/src/pages/Pools.tsx index d49669df50..130c961469 100644 --- a/centrifuge-app/src/pages/Pools.tsx +++ b/centrifuge-app/src/pages/Pools.tsx @@ -2,8 +2,13 @@ import * as React from 'react' import { LayoutBase } from '../components/LayoutBase' import { PoolList } from '../components/PoolList' import { PoolsTokensShared } from '../components/PoolsTokensShared' +import { prefetchRoute } from '../components/Root' export default function PoolsPage() { + React.useEffect(() => { + prefetchRoute('/pools/1') + prefetchRoute('/pools/tokens') + }, []) return ( diff --git a/centrifuge-js/src/modules/nfts.ts b/centrifuge-js/src/modules/nfts.ts index 5750b0d879..e3dcb80093 100644 --- a/centrifuge-js/src/modules/nfts.ts +++ b/centrifuge-js/src/modules/nfts.ts @@ -1,6 +1,6 @@ import { StorageKey, u32 } from '@polkadot/types' import BN from 'bn.js' -import { combineLatest, EMPTY, firstValueFrom } from 'rxjs' +import { combineLatest, EMPTY, firstValueFrom, of } from 'rxjs' import { expand, filter, map, repeatWhen, switchMap, take } from 'rxjs/operators' import { Centrifuge } from '../Centrifuge' import { TransactionOptions } from '../types' @@ -177,12 +177,12 @@ export function getNftsModule(inst: Centrifuge) { combineLatest([ api.query.uniques.instanceMetadataOf(collectionId, nftId), api.query.uniques.asset(collectionId, nftId), - api.query.nftSales.sales(collectionId, nftId), + api.query.nftSales?.sales(collectionId, nftId) ?? of(null), ]) ), map(([meta, nftData, sale]) => { const nftValue = nftData.toJSON() as Item - const saleValue = sale.toJSON() as any + const saleValue = sale?.toJSON() as any if (!nftValue) throw new Error(`NFT not found: collectionId: ${collectionId}, nftId: ${nftId}`) const nft: NFT = { id: nftId, From d15638f849c74d4f78844d46c13883276caac8b8 Mon Sep 17 00:00:00 2001 From: Onno Visser Date: Wed, 15 Nov 2023 12:55:39 +0100 Subject: [PATCH 2/2] Centrifuge App: Fix formatting for investor transactions (#1686) --- .../src/components/Report/InvestorTransactions.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/centrifuge-app/src/components/Report/InvestorTransactions.tsx b/centrifuge-app/src/components/Report/InvestorTransactions.tsx index 97bb66b944..69ac401d70 100644 --- a/centrifuge-app/src/components/Report/InvestorTransactions.tsx +++ b/centrifuge-app/src/components/Report/InvestorTransactions.tsx @@ -19,6 +19,9 @@ function truncate(string: string) { return `${first}...${last}` } +const noop = (v: any) => v +const cellFormatters = [noop, truncate, noop, noop, noop, noop, noop, noop] + export function InvestorTransactions({ pool }: { pool: Pool }) { const { activeTranche, setCsvData, startDate, endDate } = React.useContext(ReportContext) @@ -43,7 +46,7 @@ export function InvestorTransactions({ pool }: { pool: Pool }) { const columns = headers.map((col, index) => ({ align: 'left', header: col, - cell: (row: TableDataRow) => {(row.value as any)[index]}, + cell: (row: TableDataRow) => {cellFormatters[index]((row.value as any)[index])}, })) const data: TableDataRow[] = React.useMemo(() => { @@ -59,7 +62,7 @@ export function InvestorTransactions({ pool }: { pool: Pool }) { name: '', value: [ token.currency.name, - truncate(tx.accountId), + tx.accountId, tx.epochNumber.toString(), formatDate(tx.timestamp.toString()), formatInvestorTransactionsType({