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

Centrifuge App: Fix Tinlake assets #1631

Merged
merged 1 commit into from
Oct 10, 2023
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
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