From 383a4a245d93ae09a0e223f2fab38859452d59f7 Mon Sep 17 00:00:00 2001 From: bartosz-lipinski <264380+bartosz-lipinski@users.noreply.github.com> Date: Tue, 5 Jan 2021 13:02:09 -0600 Subject: [PATCH] feat: repay overview --- src/hooks/useBorrowingPower.ts | 4 +- src/views/borrowReserve/index.tsx | 4 +- src/views/repayReserve/index.tsx | 91 ++++++++++++++++++++++++------- 3 files changed, 75 insertions(+), 24 deletions(-) diff --git a/src/hooks/useBorrowingPower.ts b/src/hooks/useBorrowingPower.ts index 2574dcd..6923948 100644 --- a/src/hooks/useBorrowingPower.ts +++ b/src/hooks/useBorrowingPower.ts @@ -8,8 +8,8 @@ import { useUserObligations } from "./useUserObligations"; // TODO: add option to decrease buying power by overcollateralization factor // TODO: add support for balance in the wallet -export function useBorrowingPower(reserveAddress: string | PublicKey, includeWallet = false, overcollateralize = true) { - const key = useMemo(() => typeof reserveAddress === 'string' ? reserveAddress : reserveAddress.toBase58(), [reserveAddress]); +export function useBorrowingPower(reserveAddress: string | PublicKey | undefined, includeWallet = false, overcollateralize = true) { + const key = useMemo(() => typeof reserveAddress === 'string' ? reserveAddress : reserveAddress?.toBase58() || '', [reserveAddress]); const reserve = useLendingReserve(key); diff --git a/src/views/borrowReserve/index.tsx b/src/views/borrowReserve/index.tsx index 1f1f2cb..0a6a809 100644 --- a/src/views/borrowReserve/index.tsx +++ b/src/views/borrowReserve/index.tsx @@ -67,14 +67,14 @@ export const BorrowReserveView = () => { - + - + { const { reserve: reserveId, obligation: obligationId } = useParams<{ @@ -17,35 +20,83 @@ export const RepayReserveView = () => { }>(); const lendingObligation = useEnrichedLendingObligation(obligationId); - const lendingReserve = useLendingReserve( - obligationId ? lendingObligation?.info.borrowReserve : reserveId - ); + const id = obligationId ? lendingObligation?.info.borrowReserve : reserveId; + const lendingReserve = useLendingReserve(id); const repayReserve = useLendingReserve( obligationId ? lendingObligation?.info.collateralReserve : reserveId ); + const { userObligations, totalInQuote: loansValue } = useUserObligations(); + const { totalInQuote: borrowingPower, utilization } = useBorrowingPower(id); + const reserve = lendingReserve?.info; if (!reserve || !lendingReserve || !lendingObligation) { return null; } + return (
-
- - -
-
- ); -}; + + + + + + + + + + + + + + + + + + + item.obligation.info.borrowedInQuote / loansValue} + name={(item) => item.obligation.info.repayName} /> + + + + + + + + + + + + ); +}