* feat: added simulateTrade * MP-3330: added vault positions to the useUpdated Account * tidy: format * tidy: refactor * Health indicator change preview (#410) * fix: adjusted the AccountDetail width * feat: added health indicator updates * Update src/components/Account/AccountDetails.tsx Co-authored-by: Yusuf Seyrek <yusufseyrek@users.noreply.github.com> * fix: created a function for the back- and foregroundColors * fix: updated tailwind conf * fix: fixed the useHealthColorAndLabel function --------- Co-authored-by: Yusuf Seyrek <yusufseyrek@users.noreply.github.com> Co-authored-by: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com> * fix: added updatedAccount to AccountSummary (#414) Co-authored-by: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com> * fix: added a new way of calulating values to vaults * fix: refactored the displayCurrency * fix: fixed the subtitles, to not nest <p> tags * MP-3330: added comparison to the vault mechanics * fix: fixed tests * fix: updated the borrow slider percentage on vaults * fix: addressed change request * update displayValue stuff * fixed wrong display conversions * fix: fixed the display price and renamed getDepositsAndLendsAfterCoinSpent * fix test and update DisplayCurrency * tidy: refactor * tidy: rename method --------- Co-authored-by: Yusuf Seyrek <yusufseyrek@users.noreply.github.com> Co-authored-by: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com>
142 lines
4.4 KiB
TypeScript
142 lines
4.4 KiB
TypeScript
import { ColumnDef, Row, Table } from '@tanstack/react-table'
|
|
import { useCallback, useMemo } from 'react'
|
|
|
|
import AssetImage from 'components/AssetImage'
|
|
import LendingActionButtons from 'components/Earn/Lend/LendingActionButtons'
|
|
import { FormattedNumber } from 'components/FormattedNumber'
|
|
import { ChevronDown, ChevronUp } from 'components/Icons'
|
|
import AssetListTable from 'components/MarketAssetTable'
|
|
import MarketAssetTableRow from 'components/MarketAssetTable/MarketAssetTableRow'
|
|
import MarketDetails from 'components/MarketAssetTable/MarketDetails'
|
|
import TitleAndSubCell from 'components/TitleAndSubCell'
|
|
import { convertLiquidityRateToAPR, demagnify } from 'utils/formatters'
|
|
import { BN } from 'utils/helpers'
|
|
|
|
import { BN_ZERO } from '../../../constants/math'
|
|
import AmountAndValue from '../../AmountAndValue'
|
|
|
|
interface Props {
|
|
title: string
|
|
data: LendingMarketTableData[]
|
|
}
|
|
|
|
export default function LendingMarketsTable(props: Props) {
|
|
const { title, data } = props
|
|
const shouldShowAccountDeposit = !!data[0]?.accountLentValue
|
|
|
|
const rowRenderer = useCallback(
|
|
(row: Row<LendingMarketTableData>, table: Table<LendingMarketTableData>) => {
|
|
return (
|
|
<MarketAssetTableRow
|
|
key={`lend-asset-${row.id}`}
|
|
isExpanded={row.getIsExpanded()}
|
|
resetExpanded={table.resetExpanded}
|
|
rowData={row}
|
|
expandedActionButtons={<LendingActionButtons data={row.original} />}
|
|
expandedDetails={<MarketDetails data={row.original} type='lend' />}
|
|
/>
|
|
)
|
|
},
|
|
[],
|
|
)
|
|
|
|
const columns = useMemo<ColumnDef<LendingMarketTableData>[]>(
|
|
() => [
|
|
{
|
|
accessorKey: 'asset.name',
|
|
header: 'Asset',
|
|
id: 'symbol',
|
|
cell: ({ row }) => {
|
|
const asset = row.original.asset
|
|
|
|
return (
|
|
<div className='flex items-center flex-1 gap-3'>
|
|
<AssetImage asset={asset} size={32} />
|
|
<TitleAndSubCell
|
|
title={asset.symbol}
|
|
sub={asset.name}
|
|
className='text-left min-w-15'
|
|
/>
|
|
</div>
|
|
)
|
|
},
|
|
},
|
|
...(shouldShowAccountDeposit
|
|
? [
|
|
{
|
|
accessorKey: 'accountDepositValue',
|
|
header: 'Deposited',
|
|
cell: ({ row }) => {
|
|
const amount = row.original.accountLentAmount
|
|
|
|
return (
|
|
<AmountAndValue
|
|
asset={row.original.asset}
|
|
amount={amount ? BN(amount) : BN_ZERO}
|
|
/>
|
|
)
|
|
},
|
|
} as ColumnDef<LendingMarketTableData>,
|
|
]
|
|
: []),
|
|
{
|
|
accessorKey: 'marketLiquidityRate',
|
|
header: 'APR',
|
|
cell: ({ row }) => {
|
|
return (
|
|
<FormattedNumber
|
|
amount={convertLiquidityRateToAPR(row.original.marketLiquidityRate)}
|
|
options={{ minDecimals: 2, maxDecimals: 2, suffix: '%' }}
|
|
className='text-xs'
|
|
animate
|
|
/>
|
|
)
|
|
},
|
|
},
|
|
{
|
|
accessorKey: 'marketDepositCap',
|
|
header: 'Depo. Cap',
|
|
cell: ({ row }) => {
|
|
const { marketDepositCap, marketDepositAmount, asset } = row.original
|
|
const remainingCap = row.original.marketDepositCap.minus(
|
|
demagnify(marketDepositAmount, asset),
|
|
)
|
|
|
|
return (
|
|
<TitleAndSubCell
|
|
className='text-xs'
|
|
title={
|
|
<FormattedNumber
|
|
amount={marketDepositCap.toNumber()}
|
|
options={{ abbreviated: true, decimals: asset.decimals }}
|
|
animate
|
|
/>
|
|
}
|
|
sub={
|
|
<FormattedNumber
|
|
amount={remainingCap.toNumber()}
|
|
options={{ abbreviated: true, decimals: asset.decimals, suffix: ` left` }}
|
|
animate
|
|
/>
|
|
}
|
|
/>
|
|
)
|
|
},
|
|
},
|
|
{
|
|
accessorKey: 'manage',
|
|
enableSorting: false,
|
|
header: 'Manage',
|
|
cell: ({ row }) => (
|
|
<div className='flex items-center justify-end'>
|
|
<div className='w-4'>{row.getIsExpanded() ? <ChevronUp /> : <ChevronDown />}</div>
|
|
</div>
|
|
),
|
|
},
|
|
],
|
|
[shouldShowAccountDeposit],
|
|
)
|
|
|
|
return <AssetListTable title={title} rowRenderer={rowRenderer} columns={columns} data={data} />
|
|
}
|