Skip to content

Commit

Permalink
fix tinlake assets
Browse files Browse the repository at this point in the history
  • Loading branch information
onnovisser committed Oct 10, 2023
1 parent e80d1e6 commit 63eed23
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions centrifuge-app/src/pages/Loan/FinanceForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActiveLoan, CurrencyBalance, findBalance, Loan as LoanType } from '@centrifuge/centrifuge-js'
import { ActiveLoan, CurrencyBalance, ExternalLoan, findBalance, Loan as LoanType } from '@centrifuge/centrifuge-js'
import { useBalances, useCentrifugeTransaction } from '@centrifuge/centrifuge-react'
import { Button, Card, CurrencyInput, IconInfo, InlineFeedback, Shelf, Stack, Text } from '@centrifuge/fabric'
import BN from 'bn.js'
Expand All @@ -24,7 +24,7 @@ type RepayValues = {

export const FinanceForm = ({ loan }: { loan: LoanType }) => {
const isExternalAsset = 'valuationMethod' in loan.pricing && loan.pricing.valuationMethod === 'oracle'
return isExternalAsset ? <ExternalFinanceForm loan={loan} /> : <InternalFinanceForm loan={loan} />
return isExternalAsset ? <ExternalFinanceForm loan={loan as ExternalLoan} /> : <InternalFinanceForm loan={loan} />
}

function InternalFinanceForm({ loan }: { loan: LoanType }) {
Expand Down
1 change: 1 addition & 0 deletions centrifuge-app/src/utils/tinlake/useTinlakePools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export function useTinlakeLoans(poolId: string) {
id: loan.index.toString(),
originationDate: loan.financingDate ? new Date(Number(loan.financingDate) * 1000).toISOString() : null,
outstandingDebt: new CurrencyBalance(loan.debt, 18),
presentValue: new CurrencyBalance(loan.debt, 18),
poolId: loan.pool.id,
pricing: {
maturityDate: Number(loan.maturityDate) ? new Date(Number(loan.maturityDate) * 1000).toISOString() : null,
Expand Down
6 changes: 3 additions & 3 deletions centrifuge-app/src/utils/usePools.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Centrifuge, { ActiveLoan, BorrowerTransaction, Pool, PoolMetadata } from '@centrifuge/centrifuge-js'
import Centrifuge, { BorrowerTransaction, Loan, Pool, PoolMetadata } from '@centrifuge/centrifuge-js'
import { useCentrifuge, useCentrifugeQuery, useWallet } from '@centrifuge/centrifuge-react'
import BN from 'bn.js'
import { useEffect } from 'react'
Expand Down Expand Up @@ -95,10 +95,10 @@ export function useAverageAmount(poolId: string) {

if (!loans?.length || !pool) return new BN(0)

return loans
return (loans as Loan[])
.reduce((sum, loan) => {
if (loan.status !== 'Active') return sum
return sum.add((loan as ActiveLoan).presentValue.toDecimal())
return sum.add(loan.presentValue.toDecimal())
}, Dec(0))
.div(loans.filter((loan) => loan.status === 'Active').length)
}
Expand Down

0 comments on commit 63eed23

Please sign in to comment.