Skip to content

Commit

Permalink
Merge branch 'main' into fix-env-var
Browse files Browse the repository at this point in the history
  • Loading branch information
onnovisser authored Nov 20, 2023
2 parents a9db85f + 974ce3b commit 0221e82
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions centrifuge-js/src/modules/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,11 @@ type ClosedLoanData = {
info: LoanInfoData
closedAt: number
totalBorrowed: string
totalRepaid: string
totalRepaid: {
interest: string
principal: string
unscheduled: string
}
}

export type PricingInfo = InternalPricingInfo | ExternalPricingInfo
Expand Down Expand Up @@ -492,6 +496,11 @@ export type ClosedLoan = {
}
totalBorrowed: CurrencyBalance
totalRepaid: CurrencyBalance
repaid: {
interest: CurrencyBalance
principal: CurrencyBalance
unscheduled: CurrencyBalance
}
}

export type Loan = CreatedLoan | ClosedLoan | ActiveLoan
Expand Down Expand Up @@ -2618,13 +2627,26 @@ export function getPoolsModule(inst: Centrifuge) {

const closedLoans: ClosedLoan[] = (closedLoanValues as any[]).map(([key, value]) => {
const loan = value.toPrimitive() as unknown as ClosedLoanData

const repaidPrincipal = new CurrencyBalance(loan.totalRepaid.principal, currency.decimals)
const repaidInterest = new CurrencyBalance(loan.totalRepaid.interest, currency.decimals)
const repaidUnscheduled = new CurrencyBalance(loan.totalRepaid.unscheduled, currency.decimals)

return {
...getSharedLoanInfo(loan),
id: formatLoanKey(key as StorageKey<[u32, u32]>),
poolId,
status: 'Closed',
totalBorrowed: new CurrencyBalance(loan.totalBorrowed, currency.decimals),
totalRepaid: new CurrencyBalance(loan.totalRepaid, currency.decimals),
totalRepaid: new CurrencyBalance(
repaidPrincipal.add(repaidInterest).add(repaidUnscheduled),
currency.decimals
),
repaid: {
principal: repaidPrincipal,
interest: repaidInterest,
unscheduled: repaidUnscheduled,
},
}
})

Expand Down

0 comments on commit 0221e82

Please sign in to comment.