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

Fix closed asset handling #1693

Merged
merged 1 commit into from
Nov 17, 2023
Merged
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
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
Loading