'use client' import { ColumnDef, flexRender, getCoreRowModel, getSortedRowModel, SortingState, useReactTable, } from '@tanstack/react-table' import Image from 'next/image' import React from 'react' import { AssetRow } from 'components/Borrow/AssetRow' import { ChevronDown, ChevronUp } from 'components/Icons' import { getMarketAssets } from 'utils/assets' import classNames from 'classnames' import AssetExpanded from './AssetExpanded' type Props = { data: BorrowAsset[] | BorrowAssetActive[] } export const BorrowTable = (props: Props) => { const [sorting, setSorting] = React.useState([]) const marketAssets = getMarketAssets() const columns = React.useMemo[]>( () => [ { header: 'Asset', id: 'symbol', cell: ({ row }) => { const asset = marketAssets.find((asset) => asset.denom === row.original.denom) if (!asset) return null return (
token
{asset.symbol}
{asset.name}
) }, }, { accessorKey: 'borrowRate', header: 'Borrow Rate', cell: ({ row }) =>
{(Number(row.original.borrowRate) * 100).toFixed(2)}%
, }, { accessorKey: 'liquidity', header: 'Liquidity Available', cell: ({ row }) => (
{row.original.liquidity.amount}
${row.original.liquidity.value}
), }, { accessorKey: 'status', enableSorting: false, header: 'Manage', width: 150, cell: ({ row }) => (
{row.getIsExpanded() ? : }
), }, ], [], ) const table = useReactTable({ data: props.data, columns, state: { sorting, }, onSortingChange: setSorting, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), debugTable: true, }) return ( {table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header, index) => { return ( ) })} ))} {table.getRowModel().rows.map((row) => { if (row.getIsExpanded()) { return ( {}} onRepayClick={() => {}} resetExpanded={table.resetExpanded} /> ) } return })}
{header.column.getCanSort() ? { asc: ( mars ), desc: ( mars ), false: ( mars ), }[header.column.getIsSorted() as string] ?? null : null} {flexRender(header.column.columnDef.header, header.getContext())}
) }