diff --git a/src/components/LoanInfoLine/index.tsx b/src/components/LoanInfoLine/index.tsx new file mode 100644 index 0000000..f896743 --- /dev/null +++ b/src/components/LoanInfoLine/index.tsx @@ -0,0 +1,102 @@ +import { Card, Col, Row, 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"; +import { GUTTER } from "../../constants"; + +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 ed275d3..e9da931 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..b722035 100644 --- a/src/views/liquidateReserve/index.tsx +++ b/src/views/liquidateReserve/index.tsx @@ -6,14 +6,20 @@ import { SideReserveOverviewMode, } from "../../components/SideReserveOverview"; +import { LoanInfoLine } from "../../components/LoanInfoLine"; + import { LiquidateInput } from "../../components/LiquidateInput"; import "./style.less"; +import { Col, Row } from "antd"; +import { GUTTER } from "../../constants"; +import { BorrowInput } from "../../components/BorrowInput"; export const LiquidateReserveView = () => { const { id } = useParams<{ id: string }>(); const obligation = useEnrichedLendingObligation(id); + const repayReserve = useLendingReserve(obligation?.info.borrowReserve); const withdrawReserve = useLendingReserve(obligation?.info.collateralReserve); @@ -22,20 +28,25 @@ export const LiquidateReserveView = () => { } return ( -
-
- - -
+
+ + + + + + + + +
); };