Skip to content

Commit

Permalink
chore: update facility card labels
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhart1o1 committed Feb 14, 2025
1 parent 8d88a04 commit f68fe25
Showing 1 changed file with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
"use client"
import { DetailsCard } from "@lana/web/components/details"

import React from "react"

import { GetCreditFacilityLayoutDetailsQuery } from "@/lib/graphql/generated"
import Balance from "@/components/balance/balance"
import BigNumber from "bignumber.js"
import { SignedUsdCents } from "@/types"

/**
* Calculates the total cost (interest + fees) assuming
* the one-time fee is applied to the entire facility amount.
*/
function calculateTotalCost(
creditFacility: NonNullable<GetCreditFacilityLayoutDetailsQuery["creditFacility"]>
): number {
const feeRateBN = new BigNumber(creditFacility.creditFacilityTerms.oneTimeFeeRate ?? 0)

const facilityAmountBN = new BigNumber(creditFacility.facilityAmount ?? 0)
const oneTimeFeeUsdBN = facilityAmountBN.multipliedBy(feeRateBN)

const totalInterestUsdBN = new BigNumber(
creditFacility.balance.interest.total.usdBalance ?? 0
)

// 5. total cost = interest + fee
const totalCostUsdBN = totalInterestUsdBN.plus(oneTimeFeeUsdBN)
return totalCostUsdBN.toNumber()
}

function FacilityCard({
creditFacility,
}: {
creditFacility: NonNullable<GetCreditFacilityLayoutDetailsQuery["creditFacility"]>
}) {
const totalCostUsd = calculateTotalCost(creditFacility)
const facilityData = [
{
label: "Facility Amount",
Expand All @@ -25,6 +48,15 @@ function FacilityCard({
/>
),
},
{
label: "Disbursed and Outstanding",
value: (
<Balance
amount={creditFacility.balance.disbursed.outstanding.usdBalance}
currency="usd"
/>
),
},
{
label: "Outstanding Interest",
value: (
Expand All @@ -50,24 +82,11 @@ function FacilityCard({
),
},
{
label: "Outstanding Disbursed",
value: (
<Balance
amount={creditFacility.balance.disbursed.outstanding.usdBalance}
currency="usd"
/>
),
},
{
label: "Total Interest",
value: (
<Balance
amount={creditFacility.balance.interest.total.usdBalance}
currency="usd"
/>
),
label: "Total Cost (Interest + Fees)",
value: <Balance amount={totalCostUsd as SignedUsdCents} currency="usd" />,
},
]

return (
<DetailsCard className="w-full" title="Facility" details={facilityData} columns={2} />
)
Expand Down

0 comments on commit f68fe25

Please sign in to comment.