token list table columns

This commit is contained in:
saml33 2022-07-19 15:27:11 +10:00
parent db1f52f452
commit 82a54714a4
6 changed files with 161 additions and 44 deletions

View File

@ -2,6 +2,7 @@ import Image from 'next/image'
import mangoStore from '../store/state'
import { formatDecimal, numberFormat } from '../utils/numbers'
import Button from './shared/Button'
import ContentBox from './shared/ContentBox'
const TokenList = () => {
@ -18,12 +19,13 @@ const TokenList = () => {
<table className="min-w-full">
<thead>
<tr>
<th className="text-left">Asset</th>
<th className="text-right">Deposits</th>
<th className="text-right">APR</th>
<th className="text-right">Borrows</th>
<th className="text-right">APR</th>
<th className="text-right">Your Balance</th>
<th className="w-[12.5%] text-left">Token</th>
<th className="w-[12.5%] text-right">Price</th>
<th className="w-[12.5%] text-right">24hr Change</th>
<th className="w-[12.5%] text-right">24hr Volume</th>
<th className="w-[12.5%] text-right">Rates (APR)</th>
<th className="w-[12.5%] text-right">Liquidity</th>
<th className="w-[12.5%] text-right">Available Balance</th>
</tr>
</thead>
<tbody>
@ -31,7 +33,7 @@ const TokenList = () => {
const oraclePrice = bank.value.price
return (
<tr key={bank.key}>
<td>
<td className="w-[12.5%]">
<div className="flex items-center">
<div className="mr-2.5 flex flex-shrink-0 items-center">
<Image
@ -41,50 +43,47 @@ const TokenList = () => {
src={`/icons/${bank.value.name.toLowerCase()}.svg`}
/>
</div>
<div className="flex flex-col">
<p className="font-bold">{bank.value.name}</p>
<p className="text-xs text-th-fgd-4">
${formatDecimal(oraclePrice.toNumber(), 2)}
</p>
</div>
<p className="font-bold">{bank.value.name}</p>
</div>
</td>
<td>
<td className="w-[12.5%]">
<div className="flex flex-col text-right">
<p>
{formatDecimal(
bank.value.uiDeposits(),
bank.value.mintDecimals
)}
</p>
<p>${formatDecimal(oraclePrice.toNumber(), 2)}</p>
</div>
</td>
<td>
<td className="w-[12.5%]">
<div className="flex flex-col text-right">
<p className="text-th-green">0%</p>
</div>
</td>
<td className="w-[12.5%]">
<div className="flex flex-col text-right">
<p>1000</p>
</div>
</td>
<td className="w-[12.5%]">
<div className="flex justify-end space-x-2 text-right">
<p className="text-th-green">
{formatDecimal(bank.value.getDepositRate().toNumber(), 2)}
%
</p>
</div>
</td>
<td>
<div className="flex flex-col text-right">
<p>
{formatDecimal(
bank.value.uiBorrows(),
bank.value.mintDecimals
)}
</p>
</div>
</td>
<td>
<div className="flex flex-col text-right">
<span className="text-th-fgd-4">|</span>
<p className="text-th-red">
{formatDecimal(bank.value.getBorrowRate().toNumber(), 2)}%
</p>
</div>
</td>
<td className="pt-4 text-right">
<td className="w-[12.5%]">
<div className="flex flex-col text-right">
<p>
{formatDecimal(
bank.value.uiDeposits() - bank.value.uiBorrows(),
bank.value.mintDecimals
)}
</p>
</div>
</td>
<td className="w-[12.5%] pt-4 text-right">
<p className="px-2">
{mangoAccount
? formatDecimal(mangoAccount.getUi(bank.value))
@ -100,12 +99,17 @@ const TokenList = () => {
: '-'}
</p>
</td>
<td className="w-[12.5%]">
<div className="flex justify-end space-x-2">
<Button>Buy</Button>
<Button secondary>Sell</Button>
</div>
</td>
</tr>
)
})}
</tbody>
</table>
<div className="mt-2 space-y-2 p-2"></div>
</ContentBox>
)
}

View File

@ -0,0 +1,113 @@
import Image from 'next/image'
import mangoStore from '../store/state'
import { formatDecimal, numberFormat } from '../utils/numbers'
import ContentBox from './shared/ContentBox'
const TokenList = () => {
const mangoAccount = mangoStore((s) => s.mangoAccount)
const group = mangoStore((s) => s.group)
const banks = group?.banksMap
? Array.from(group?.banksMap, ([key, value]) => ({ key, value }))
: []
return (
<ContentBox hideBorder hidePadding>
<h2>Tokens</h2>
<table className="min-w-full">
<thead>
<tr>
<th className="text-left">Asset</th>
<th className="text-right">Deposits</th>
<th className="text-right">APR</th>
<th className="text-right">Borrows</th>
<th className="text-right">APR</th>
<th className="text-right">Your Balance</th>
</tr>
</thead>
<tbody>
{banks.map((bank) => {
const oraclePrice = bank.value.price
return (
<tr key={bank.key}>
<td>
<div className="flex items-center">
<div className="mr-2.5 flex flex-shrink-0 items-center">
<Image
alt=""
width="24"
height="24"
src={`/icons/${bank.value.name.toLowerCase()}.svg`}
/>
</div>
<div className="flex flex-col">
<p className="font-bold">{bank.value.name}</p>
<p className="text-xs text-th-fgd-4">
${formatDecimal(oraclePrice.toNumber(), 2)}
</p>
</div>
</div>
</td>
<td>
<div className="flex flex-col text-right">
<p>
{formatDecimal(
bank.value.uiDeposits(),
bank.value.mintDecimals
)}
</p>
</div>
</td>
<td>
<div className="flex flex-col text-right">
<p className="text-th-green">
{formatDecimal(bank.value.getDepositRate().toNumber(), 2)}
%
</p>
</div>
</td>
<td>
<div className="flex flex-col text-right">
<p>
{formatDecimal(
bank.value.uiBorrows(),
bank.value.mintDecimals
)}
</p>
</div>
</td>
<td>
<div className="flex flex-col text-right">
<p className="text-th-red">
{formatDecimal(bank.value.getBorrowRate().toNumber(), 2)}%
</p>
</div>
</td>
<td className="pt-4 text-right">
<p className="px-2">
{mangoAccount
? formatDecimal(mangoAccount.getUi(bank.value))
: '-'}
</p>
<p className="px-2 text-xs text-th-fgd-4">
{mangoAccount
? `$${formatDecimal(
mangoAccount.getUi(bank.value) *
oraclePrice.toNumber(),
2
)}`
: '-'}
</p>
</td>
</tr>
)
})}
</tbody>
</table>
<div className="mt-2 space-y-2 p-2"></div>
</ContentBox>
)
}
export default TokenList

View File

@ -10,17 +10,19 @@ const TradeSimplePage = () => {
return (
<div className="grid grid-cols-12 gap-6">
<div className="order-2 col-span-12 space-y-12 md:order-1 md:col-span-6 lg:col-span-8">
<div className="col-span-12 space-y-12 md:col-span-6 lg:col-span-8">
<SwapTokenChart
inputTokenId={inputTokenInfo?.extensions?.coingeckoId}
outputTokenId={outputTokenInfo?.extensions?.coingeckoId}
/>
<TokenList />
</div>
<div className="order-1 col-span-12 space-y-6 md:order-2 md:col-span-6 lg:col-span-4">
<div className="col-span-12 space-y-6 md:col-span-6 lg:col-span-4">
<Swap />
{/* <MangoAccount /> */}
</div>
<div className="col-span-12">
<TokenList />
</div>
</div>
)
}

View File

@ -41,8 +41,6 @@ const Layout = ({ children }: { children: ReactNode }) => {
}, 100)
}
console.log(width)
return (
<div className={`flex-grow bg-th-bkg-1 text-th-fgd-1 transition-all`}>
<div className="flex">

View File

@ -221,7 +221,7 @@ const SwapTokenChart: FunctionComponent<SwapTokenChartProps> = ({
</div>
</div>
{!hideChart ? (
<div className="-mx-5 -mb-6 h-56">
<div className="-mx-5 -mb-6 h-64">
<ResponsiveContainer width="100%" height="100%">
<AreaChart
data={chartData}

View File

@ -230,7 +230,7 @@ input[type='range']::-ms-thumb {
/* Table */
table {
@apply m-0 w-full table-fixed p-0;
@apply m-0 w-full p-0;
}
table caption {