-
-
-
{row.symbol}
-
{row.name}
+ cell: ({ row }) => {
+ const asset = marketAssets.find((asset) => asset.denom === row.original.denom)
+
+ if (!asset) return null
+
+ return (
+
+
+
+
{asset.symbol}
+
{asset.name}
+
-
- ),
- cell: (info) => info.getValue(),
+ )
+ },
},
{
accessorKey: 'borrowRate',
header: 'Borrow Rate',
- accessorFn: (row) => (
-
- {row.borrowRate ? `${(row.borrowRate * 100).toFixed(2)}%` : '-'}
-
- ),
- cell: (info) => info.getValue(),
+ cell: ({ row }) =>
{(Number(row.original.borrowRate) * 100).toFixed(2)}%
,
},
{
- accessorKey: 'age',
- header: 'Borrowed',
- accessorFn: (row) => (
-
- {row.borrowed ? (
-
-
{row.borrowed.amount}
-
{formatCurrency(row.borrowed.value)}
-
- ) : (
- '-'
- )}
-
- ),
- cell: (info) => info.getValue(),
- },
- {
- accessorKey: 'marketLiquidity',
+ accessorKey: 'liquidity',
header: 'Liquidity Available',
+ cell: ({ row }) => (
+
+
{row.original.liquidity.amount}
+
${row.original.liquidity.value}
+
+ ),
},
{
accessorKey: 'status',
@@ -98,7 +77,7 @@ export const BorrowTable = ({ data, onBorrowClick, onRepayClick }: Props) => {
)
const table = useReactTable({
- data,
+ data: props.data,
columns,
state: {
sorting,
@@ -110,47 +89,67 @@ export const BorrowTable = ({ data, onBorrowClick, onRepayClick }: Props) => {
})
return (
-
- {table.getHeaderGroups().map((headerGroup) => (
-
- {headerGroup.headers.map((header) => {
- return (
-
- {header.isPlaceholder ? null : (
+
+
+ {table.getHeaderGroups().map((headerGroup) => (
+
+ {headerGroup.headers.map((header, index) => {
+ return (
+
- {flexRender(header.column.columnDef.header, header.getContext())}
- {{
- asc: ' 🔼',
- desc: ' 🔽',
- }[header.column.getIsSorted() as string] ?? null}
+ {header.column.getCanSort()
+ ? {
+ asc: (
+
+ ),
+ desc: (
+
+ ),
+ false: (
+
+ ),
+ }[header.column.getIsSorted() as string] ?? null
+ : null}
+ {flexRender(header.column.columnDef.header, header.getContext())}
- )}
-
- )
- })}
-
- ))}
-
- {table.getRowModel().rows.length === 0 ? (
- No Data
- ) : (
- table.getRowModel().rows.map((row) => {
+ |
+ )
+ })}
+
+ ))}
+
+
+ {table.getRowModel().rows.map((row) => {
+ if (row.getIsExpanded()) {
return (
- onBorrowClick(row.original.denom)}
- onRepayClick={() => onRepayClick(row.original.denom)}
- />
+
+
+ {}}
+ onRepayClick={() => {}}
+ resetExpanded={table.resetExpanded}
+ />
+
)
- })
- )}
-
-
+ }
+ return
+ })}
+
+
)
}
diff --git a/src/components/BorrowTable.tsx b/src/components/BorrowTable.tsx
deleted file mode 100644
index e15d5291..00000000
--- a/src/components/BorrowTable.tsx
+++ /dev/null
@@ -1,13 +0,0 @@
-import { getBorrowData } from 'utils/api'
-
-export async function BorrowTable() {
- const borrowData = await getBorrowData()
-
- return borrowData.map((borrow) => {
- return (
-
- {borrow.denom} {borrow.borrowRate} {borrow.marketLiquidity}
-
- )
- })
-}
diff --git a/src/components/Card.tsx b/src/components/Card.tsx
index 8e8be983..fa011111 100644
--- a/src/components/Card.tsx
+++ b/src/components/Card.tsx
@@ -2,19 +2,21 @@ import classNames from 'classnames'
import { ReactNode } from 'react'
interface Props {
+ title: string
children: ReactNode
className?: string
}
-export const Card = ({ children, className }: Props) => {
+export const Card = (props: Props) => {
return (
-
- {children}
-
+
{props.title}
+
{props.children}
+
)
}
diff --git a/src/components/Loading.tsx b/src/components/Loading.tsx
index 6322b116..04fd64dd 100644
--- a/src/components/Loading.tsx
+++ b/src/components/Loading.tsx
@@ -14,10 +14,10 @@ export default function Loading(props: Props) {
diff --git a/src/components/Modal.tsx b/src/components/Modal.tsx
index a3f9660f..9855f2b0 100644
--- a/src/components/Modal.tsx
+++ b/src/components/Modal.tsx
@@ -20,7 +20,10 @@ export const Modal = ({ children, content, className, open, setOpen }: Props) =>
return open ? (
-
+
{setOpen && (
{
- const marketAssets = getMarketAssets()
-
- const [modalState, setModalState] = useState({
- show: false,
- data: { tokenDenom: '' },
- })
-
- const selectedAccount = useStore((s) => s.selectedAccount)
-
- const { data: allowedCoinsData } = useAllowedCoins()
- const { data: positionsData } = useCreditAccountPositions(selectedAccount ?? '')
- const { data: marketsData } = useMarkets()
- const { data: tokenPrices } = useTokenPrices()
- const { data: redbankBalances } = useRedbankBalances()
-
- // recreate modals and reset state whenever ref changes
- const modalId = useRef(0)
-
- const borrowedAssetsMap = useMemo(() => {
- let borrowedAssetsMap: Map = new Map()
-
- positionsData?.debts.forEach((coin) => {
- borrowedAssetsMap.set(coin.denom, coin.amount)
- })
-
- return borrowedAssetsMap
- }, [positionsData])
-
- const { borrowedAssets, notBorrowedAssets } = useMemo(() => {
- return {
- borrowedAssets:
- allowedCoinsData
- ?.filter((denom) => borrowedAssetsMap.has(denom))
- .map((denom) => {
- const { symbol, name, logo } = getTokenInfo(denom, marketAssets)
- const borrowRate = Number(marketsData?.[denom].borrow_rate) || 0
- const marketLiquidity = BigNumber(
- redbankBalances?.find((asset) => asset.denom.toLowerCase() === denom.toLowerCase())
- ?.amount || 0,
- )
- .div(10 ** getTokenDecimals(denom, marketAssets))
- .toNumber()
-
- const borrowAmount = BigNumber(borrowedAssetsMap.get(denom) as string)
- .div(10 ** getTokenDecimals(denom, marketAssets))
- .toNumber()
- const borrowValue = borrowAmount * (tokenPrices?.[denom] ?? 0)
-
- const rowData = {
- denom,
- symbol,
- logo,
- name,
- borrowed: {
- amount: borrowAmount,
- value: borrowValue,
- },
- borrowRate,
- marketLiquidity,
- }
-
- return rowData
- }) ?? [],
- notBorrowedAssets:
- allowedCoinsData
- ?.filter((denom) => !borrowedAssetsMap.has(denom))
- .map((denom) => {
- const { symbol, name, logo } = getTokenInfo(denom, marketAssets)
- const borrowRate = Number(marketsData?.[denom].borrow_rate) || 0
- const marketLiquidity = BigNumber(
- redbankBalances?.find((asset) => asset.denom.toLowerCase() === denom.toLowerCase())
- ?.amount || 0,
- )
- .div(10 ** getTokenDecimals(denom, marketAssets))
- .toNumber()
-
- const rowData = {
- denom,
- symbol,
- logo,
- name,
- borrowed: null,
- borrowRate,
- marketLiquidity,
- }
-
- return rowData
- }) ?? [],
- }
- }, [allowedCoinsData, borrowedAssetsMap, marketsData, redbankBalances, tokenPrices, marketAssets])
-
- const handleBorrowClick = (denom: string) => {
- setModalState({ show: 'borrow', data: { tokenDenom: denom } })
- modalId.current += 1
- }
-
- const handleRepayClick = (denom: string) => {
- setModalState({ show: 'repay', data: { tokenDenom: denom } })
- modalId.current += 1
- }
-
- return (
-
-
-
-
-
- Borrowings
-
-
-
-
-
-
-
- Available to Borrow
-
-
-
-
-
-
setModalState({ ...modalState, show: false })}
- />
- setModalState({ ...modalState, show: false })}
- />
-
- )
-}
-
-export default Borrow
diff --git a/src/pages/api/markets/borrow.ts b/src/pages/api/markets/borrow.ts
index 1b358828..71ad8562 100644
--- a/src/pages/api/markets/borrow.ts
+++ b/src/pages/api/markets/borrow.ts
@@ -3,6 +3,7 @@ import { NextApiRequest, NextApiResponse } from 'next'
import { ENV_MISSING_MESSAGE, URL_API } from 'constants/env'
import { getMarketAssets } from 'utils/assets'
import { Coin } from '@cosmjs/stargate'
+import BigNumber from 'bignumber.js'
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (!URL_API) {
@@ -12,18 +13,25 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const marketAssets = getMarketAssets()
const $liquidity = fetch(`${URL_API}/markets/liquidity`)
const $markets = fetch(`${URL_API}/markets`)
+ const $prices = fetch(`${URL_API}/prices`)
- const borrow: BorrowData[] = await Promise.all([$liquidity, $markets]).then(
- async ([$liquidity, $markets]) => {
+ const borrow: BorrowAsset[] = await Promise.all([$liquidity, $markets, $prices]).then(
+ async ([$liquidity, $markets, $prices]) => {
const liquidity: Coin[] = await $liquidity.json()
const markets: Market[] = await $markets.json()
+ const prices: Coin[] = await $prices.json()
return marketAssets.map((asset) => {
const currentMarket = markets.find((market) => market.denom === asset.denom)
+ const price = prices.find((coin) => coin.denom === asset.denom)?.amount ?? '1'
+ const amount = liquidity.find((coin) => coin.denom === asset.denom)?.amount ?? '0'
return {
denom: asset.denom,
borrowRate: currentMarket?.borrow_rate ?? '0',
- marketLiquidity: liquidity.find((coin) => coin.denom === asset.denom)?.amount ?? '0',
+ liquidity: {
+ amount: amount,
+ value: new BigNumber(amount).times(price).toString(),
+ },
}
})
},
@@ -35,9 +43,3 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
return res.status(404)
}
-
-export interface BorrowData {
- denom: string
- borrowRate: string
- marketLiquidity: string
-}
diff --git a/src/pages/api/prices/index.ts b/src/pages/api/prices/index.ts
index ff4f20c5..1b1b710e 100644
--- a/src/pages/api/prices/index.ts
+++ b/src/pages/api/prices/index.ts
@@ -3,6 +3,7 @@ import { NextApiRequest, NextApiResponse } from 'next'
import { ADDRESS_ORACLE, ENV_MISSING_MESSAGE, URL_GQL } from 'constants/env'
import { getMarketAssets } from 'utils/assets'
+import { Coin } from '@cosmjs/stargate'
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (!URL_GQL || !ADDRESS_ORACLE) {
@@ -31,13 +32,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
`,
)
- const data = Object.values(result?.prices).reduce(
- (acc, entry) => ({
- ...acc,
- [entry.denom]: Number(entry.price),
- }),
- {},
- ) as { [key in string]: number }
+ const data: Coin[] = Object.values(result?.prices).reduce((acc: Coin[], curr) => {
+ return [...acc, { denom: curr.denom, amount: curr.price }] as Coin[]
+ }, [])
return res.status(200).json(data)
}
diff --git a/src/types/interfaces/asset.d.ts b/src/types/interfaces/asset.d.ts
index ac44e635..a298af47 100644
--- a/src/types/interfaces/asset.d.ts
+++ b/src/types/interfaces/asset.d.ts
@@ -15,3 +15,19 @@ interface Asset {
interface OtherAsset extends Omit {
symbol: 'MARS'
}
+
+interface BorrowAsset {
+ denom: string
+ borrowRate: string
+ liquidity: {
+ amount: string
+ value: string
+ }
+}
+
+interface BorrowAssetActive extends BorrowAsset {
+ debt: {
+ amount: string
+ value: string
+ }
+}
diff --git a/src/utils/api.ts b/src/utils/api.ts
index 232ee776..848bf845 100644
--- a/src/utils/api.ts
+++ b/src/utils/api.ts
@@ -1,6 +1,5 @@
import { Coin } from '@cosmjs/stargate'
import { URL_API } from 'constants/env'
-import { BorrowData } from 'pages/api/markets/borrow'
export async function callAPI(endpoint: string): Promise {
const response = await fetch(`${URL_API}${endpoint}`, {
@@ -11,7 +10,7 @@ export async function callAPI(endpoint: string): Promise {
}
export async function getBorrowData() {
- return callAPI('/markets/borrow')
+ return callAPI('/markets/borrow')
}
export async function getCreditAccounts(address: string) {
diff --git a/tailwind.config.js b/tailwind.config.js
index 791a9c4c..a0ee8f7c 100644
--- a/tailwind.config.js
+++ b/tailwind.config.js
@@ -36,7 +36,6 @@ module.exports = {
fadein: 'fadein 1s ease-in-out forwards',
},
backgroundImage: {
- mars: 'url(/images/bg.svg)',
'fund-modal': 'url(/images/fund-bg.webp), url(/images/fund-bg.png)',
'delete-modal': 'url(/images/delete-account-bg.webp), url(/images/delete-account-bg.png)',
'create-modal': 'url(/images/create-account-bg.webp), url(/images/create-account-bg.png)',