import { Suspense } from 'react'
import { Card } from 'components/Card'
import { getAccountDebts, getBorrowData } from 'utils/api'
import { getMarketAssets } from 'utils/assets'
import { BorrowTable } from 'components/Borrow/BorrowTable'
interface Props extends PageProps {
type: 'active' | 'available'
}
async function Content(props: Props) {
const debtData = await getAccountDebts(props.params?.account)
const borrowData = await getBorrowData()
const marketAssets = getMarketAssets()
function getBorrowAssets() {
return marketAssets.reduce(
(prev: { available: BorrowAsset[]; active: BorrowAssetActive[] }, curr) => {
const borrow = borrowData.find((borrow) => borrow.denom === curr.denom)
if (borrow) {
const debt = debtData.find((debt) => debt.denom === curr.denom)
if (debt) {
prev.active.push({
...borrow,
debt: debt.amount,
})
} else {
prev.available.push(borrow)
}
}
return prev
},
{ available: [], active: [] },
)
}
const { available, active } = getBorrowAssets()
const assets = props.type === 'active' ? active : available
if (!assets.length) return null
if (props.type === 'active') {
return (
)
}
return
}
function Fallback() {
const marketAssets = getMarketAssets()
const available: BorrowAsset[] = marketAssets.reduce((prev: BorrowAsset[], curr) => {
prev.push({ ...curr, borrowRate: null, liquidity: null })
return prev
}, [])
return
}
export function AvailableBorrowings(props: PageProps) {
return (
}>
{/* @ts-expect-error Server Component */}
)
}
export function ActiveBorrowings(props: PageProps) {
return (
{/* @ts-expect-error Server Component */}
)
}