From b1d42b1335d3c9ecad1753f1a5c511fa84ebe435 Mon Sep 17 00:00:00 2001
From: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com>
Date: Fri, 10 Mar 2023 15:57:56 +0100
Subject: [PATCH] Borrow page adjustments (#114)
* Hide activeBorrowings when not present
* add extra info to borrowmodal
---
src/components/Borrow/AssetExpanded.tsx | 3 +-
src/components/Borrow/Borrowings.tsx | 39 ++++++++++++++++-----
src/components/BorrowModal.tsx | 45 +++++++++++++++++++++----
src/components/Modal.tsx | 2 +-
src/components/pages/borrow.tsx | 7 ++--
src/store/slices/common.ts | 7 ++--
6 files changed, 80 insertions(+), 23 deletions(-)
diff --git a/src/components/Borrow/AssetExpanded.tsx b/src/components/Borrow/AssetExpanded.tsx
index 213b281f..b5f09177 100644
--- a/src/components/Borrow/AssetExpanded.tsx
+++ b/src/components/Borrow/AssetExpanded.tsx
@@ -26,7 +26,8 @@ export default function AssetExpanded(props: AssetRowProps) {
if (!asset) return null
function borrowHandler() {
- useStore.setState({ borrowModal: true })
+ if (!asset) return null
+ useStore.setState({ borrowModal: { asset: asset, marketData: props.row.original } })
}
function repayHandler() {
diff --git a/src/components/Borrow/Borrowings.tsx b/src/components/Borrow/Borrowings.tsx
index 2e41ff57..7ab7ab94 100644
--- a/src/components/Borrow/Borrowings.tsx
+++ b/src/components/Borrow/Borrowings.tsx
@@ -6,6 +6,10 @@ import { getMarketAssets } from 'utils/assets'
import { BorrowTable } from './BorrowTable'
+interface Props extends PageProps {
+ type: 'active' | 'available'
+}
+
async function Content(props: Props) {
const debtData = await getAccountDebts(props.params?.account)
const borrowData = await getBorrowData()
@@ -35,7 +39,22 @@ async function Content(props: Props) {
const { available, active } = getBorrowAssets()
- return
+ const assets = props.type === 'active' ? active : available
+
+ if (!assets.length) return null
+
+ if (props.type === 'active') {
+ return (
+
+
+
+ )
+ }
+
+ return
}
function Fallback() {
@@ -50,20 +69,22 @@ function Fallback() {
return
}
-export default function BorrowPage(props: Props) {
+export function AvailableBorrowings(props: PageProps) {
return (
-
+
}>
{/* @ts-expect-error Server Component */}
-
+
)
}
-interface Props extends PageProps {
- type: 'active' | 'available'
+export function ActiveBorrowings(props: PageProps) {
+ return (
+
+ {/* @ts-expect-error Server Component */}
+
+
+ )
}
diff --git a/src/components/BorrowModal.tsx b/src/components/BorrowModal.tsx
index 9afd4e59..1b4fbdfa 100644
--- a/src/components/BorrowModal.tsx
+++ b/src/components/BorrowModal.tsx
@@ -1,22 +1,53 @@
-import useStore from 'store'
import { Modal } from 'components/Modal'
import TitleAndSubCell from 'components/TitleAndSubCell'
+import { usePathname } from 'next/navigation'
+import useStore from 'store'
+import Image from 'next/image'
+import { Text } from 'components/Text'
+import { formatPercent, formatValue } from 'utils/formatters'
export default function BorrowModal() {
- const open = useStore((s) => s.borrowModal)
+ const modal = useStore((s) => s.borrowModal)
function setOpen(isOpen: boolean) {
- useStore.setState({ borrowModal: isOpen })
+ useStore.setState({ borrowModal: null })
}
+ if (!modal) return null
+
+ const liquidityAmount: string = formatValue(modal.marketData.liquidity?.amount || '0', {
+ abbreviated: true,
+ decimals: 6,
+ })
+
+ const liquidityValue: string = formatValue(modal.marketData.liquidity?.value || '0', {
+ abbreviated: true,
+ decimals: 6,
+ })
+
return (
-
+
+
+ Borrow {modal.asset.symbol}
+
+ }
+ >
diff --git a/src/components/Modal.tsx b/src/components/Modal.tsx
index 1dcfe232..31063be2 100644
--- a/src/components/Modal.tsx
+++ b/src/components/Modal.tsx
@@ -6,7 +6,7 @@ import { Text } from 'components/Text'
import { Button } from 'components/Button'
interface Props {
- title: string
+ title: string | ReactNode
children?: ReactNode | string
content?: ReactNode | string
className?: string
diff --git a/src/components/pages/borrow.tsx b/src/components/pages/borrow.tsx
index 59baac4f..b4c5b531 100644
--- a/src/components/pages/borrow.tsx
+++ b/src/components/pages/borrow.tsx
@@ -1,4 +1,5 @@
-import Borrowings from 'components/Borrow/Borrowings'
+import { AvailableBorrowings } from 'components/Borrow/Borrowings'
+import { ActiveBorrowings } from 'components/Borrow/Borrowings'
interface Props {
params: PageParams
@@ -7,8 +8,8 @@ interface Props {
export default function BorrowPage(props: Props) {
return (
)
}
diff --git a/src/store/slices/common.ts b/src/store/slices/common.ts
index d416ccdf..2e625eaf 100644
--- a/src/store/slices/common.ts
+++ b/src/store/slices/common.ts
@@ -13,7 +13,10 @@ import { formatValue } from 'utils/formatters'
export interface CommonSlice {
address?: string
- borrowModal: boolean
+ borrowModal: {
+ asset: Asset
+ marketData: BorrowAsset | BorrowAssetActive
+ } | null
client?: WalletClient
clients: {
accountNft?: MarsAccountNftClient
@@ -38,7 +41,7 @@ export interface CommonSlice {
export function createCommonSlice(set: SetState, get: GetState) {
return {
- borrowModal: false,
+ borrowModal: null,
createAccountModal: false,
clients: {},
creditAccounts: null,