diff --git a/src/components/LoanInfoLine/index.tsx b/src/components/LoanInfoLine/index.tsx new file mode 100644 index 0000000..2fdd832 --- /dev/null +++ b/src/components/LoanInfoLine/index.tsx @@ -0,0 +1,88 @@ +import { Card, Statistic } from "antd"; +import { + formatNumber, + formatPct, + fromLamports, + wadToLamports, +} from "../../utils/utils"; +import React, { useMemo } from "react"; +import { + EnrichedLendingObligation, + useLendingReserve, + useTokenName, +} from "../../hooks"; +import { useMint } from "../../contexts/accounts"; +import { calculateBorrowAPY, collateralToLiquidity } from "../../models"; + +export const LoanInfoLine = (props: { + className?: string; + obligation: EnrichedLendingObligation; +}) => { + const obligation = props.obligation; + + const repayReserve = useLendingReserve(obligation?.info.borrowReserve); + const withdrawReserve = useLendingReserve(obligation?.info.collateralReserve); + + const liquidityMint = useMint(repayReserve?.info.liquidityMint); + const collateralMint = useMint(withdrawReserve?.info.liquidityMint); + const repayName = useTokenName(repayReserve?.info.liquidityMint); + const withdrawName = useTokenName(withdrawReserve?.info.liquidityMint); + + const borrowAPY = useMemo( + () => (repayReserve ? calculateBorrowAPY(repayReserve?.info) : 0), + [repayReserve] + ); + if (!obligation || !repayReserve) { + return null; + } + const borrowAmount = fromLamports( + wadToLamports(obligation?.info.borrowAmountWad), + liquidityMint + ); + const collateralLamports = collateralToLiquidity( + obligation?.info.depositedCollateral, + repayReserve.info + ); + const collateral = fromLamports(collateralLamports, collateralMint); + + return ( + + ( +
+
+ {formatNumber.format(borrowAmount)} {repayName} +
+
+ ${formatNumber.format(parseFloat(val.toString()))} +
+
+ )} + /> + ( +
+
+ {formatNumber.format(collateral)} {withdrawName} +
+
+ ${formatNumber.format(parseFloat(val.toString()))} +
+
+ )} + /> + + +
+ ); +}; diff --git a/src/views/liquidate/index.tsx b/src/views/liquidate/index.tsx index 677eff6..78f546c 100644 --- a/src/views/liquidate/index.tsx +++ b/src/views/liquidate/index.tsx @@ -107,7 +107,7 @@ export const LiquidateView = () => { + /> ))} diff --git a/src/views/liquidateReserve/index.tsx b/src/views/liquidateReserve/index.tsx index e050d0a..652dc79 100644 --- a/src/views/liquidateReserve/index.tsx +++ b/src/views/liquidateReserve/index.tsx @@ -6,6 +6,8 @@ import { SideReserveOverviewMode, } from "../../components/SideReserveOverview"; +import { LoanInfoLine } from "../../components/LoanInfoLine"; + import { LiquidateInput } from "../../components/LiquidateInput"; import "./style.less"; @@ -14,6 +16,7 @@ export const LiquidateReserveView = () => { const { id } = useParams<{ id: string }>(); const obligation = useEnrichedLendingObligation(id); + const repayReserve = useLendingReserve(obligation?.info.borrowReserve); const withdrawReserve = useLendingReserve(obligation?.info.collateralReserve); @@ -23,6 +26,10 @@ export const LiquidateReserveView = () => { return (
+