Skip to content

Commit

Permalink
use present value for current value
Browse files Browse the repository at this point in the history
  • Loading branch information
JP Angelle committed Sep 12, 2023
1 parent 7f2105a commit 146c276
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
22 changes: 3 additions & 19 deletions centrifuge-app/src/pages/Loan/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CurrencyBalance, Loan as LoanType, Pool, TinlakeLoan } from '@centrifuge/centrifuge-js'
import { Loan as LoanType, Pool, TinlakeLoan } from '@centrifuge/centrifuge-js'
import {
AnchorButton,
Box,
Expand Down Expand Up @@ -126,17 +126,6 @@ const Loan: React.FC<{ setShowOraclePricing?: () => void }> = ({ setShowOraclePr
return 0
}, [originationDate, loan?.pricing.maturityDate])

const currentFace =
borrowerAssetTransactions?.reduce((sum, trx) => {
if (trx.type === 'BORROWED') {
sum = new CurrencyBalance(sum.add(trx.amount || new CurrencyBalance(0, 27)), 27)
}
if (trx.type === 'REPAID') {
sum = new CurrencyBalance(sum.sub(trx.amount || new CurrencyBalance(0, 27)), 27)
}
return sum
}, new CurrencyBalance(0, 27)) || new CurrencyBalance(0, 27)

return (
<Stack>
<Box mt={2} ml={2}>
Expand Down Expand Up @@ -189,16 +178,11 @@ const Loan: React.FC<{ setShowOraclePricing?: () => void }> = ({ setShowOraclePr
label: 'Maturity date',
value: formatDate(loan.pricing.maturityDate),
},
...('valuationMethod' in loan.pricing && loan.pricing.valuationMethod === 'oracle'
...('presentValue' in loan
? [
{
label: 'Current value',
value: `${formatBalance(
new CurrencyBalance(currentFace.mul(loan.pricing.oracle.value), 44),
pool.currency.symbol,
6,
2
)}`,
value: `${formatBalance(loan.presentValue, pool.currency.symbol, 6, 2)}`,
},
]
: []),
Expand Down
1 change: 1 addition & 0 deletions centrifuge-js/src/modules/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ export type ActiveLoan = {
outstandingDebt: CurrencyBalance
outstandingPrincipal: CurrencyBalance
outstandingInterest: CurrencyBalance
presentValue: CurrencyBalance
}

// transformed type for UI
Expand Down

0 comments on commit 146c276

Please sign in to comment.