From 0ee782e69eebc3f1fa2f001aacb177103545afcb Mon Sep 17 00:00:00 2001 From: saml33 Date: Wed, 20 Jul 2022 15:49:09 +1000 Subject: [PATCH] responsive token list --- components/TokenList.tsx | 292 +++++++++++++++++++++++++---------- components/shared/Layout.tsx | 4 +- 2 files changed, 215 insertions(+), 81 deletions(-) diff --git a/components/TokenList.tsx b/components/TokenList.tsx index bdf416c7..89e01029 100644 --- a/components/TokenList.tsx +++ b/components/TokenList.tsx @@ -1,115 +1,247 @@ +import { Transition } from '@headlessui/react' +import { ChevronDownIcon } from '@heroicons/react/solid' +import { useTranslation } from 'next-i18next' import Image from 'next/image' +import { Fragment, useState } from 'react' +import { useViewport } from '../hooks/useViewport' import mangoStore from '../store/state' import { formatDecimal, numberFormat } from '../utils/numbers' -import Button from './shared/Button' +import { breakpoints } from '../utils/theme' +import Button, { IconButton } from './shared/Button' import ContentBox from './shared/ContentBox' const TokenList = () => { + const { t } = useTranslation('common') + const [showTokenDetails, setShowTokenDetails] = useState('') const mangoAccount = mangoStore((s) => s.mangoAccount) const group = mangoStore((s) => s.group) + const { width } = useViewport() + const showTableView = width ? width > breakpoints.md : false const banks = group?.banksMap ? Array.from(group?.banksMap, ([key, value]) => ({ key, value })) : [] + const handleShowTokenDetails = (name: string) => { + showTokenDetails ? setShowTokenDetails('') : setShowTokenDetails(name) + } + return (

Tokens

- - - - - - - - - - - - - + {showTableView ? ( +
TokenPrice24hr Change24hr VolumeRates (APR)LiquidityAvailable Balance
+ + + + + + + + + + + + + {banks.map((bank) => { + const oraclePrice = bank.value.price + return ( + + + + + + + + + + + ) + })} + +
TokenPrice{t('rolling-change')}{t('daily-volume')}Rates (APR){t('liquidity')}Available Balance
+
+
+ +
+

{bank.value.name}

+
+
+
+

${formatDecimal(oraclePrice.toNumber(), 2)}

+
+
+
+

0%

+
+
+
+

1000

+
+
+
+

+ {formatDecimal( + bank.value.getDepositRate().toNumber(), + 2 + )} + % +

+ | +

+ {formatDecimal( + bank.value.getBorrowRate().toNumber(), + 2 + )} + % +

+
+
+
+

+ {formatDecimal( + bank.value.uiDeposits() - bank.value.uiBorrows(), + bank.value.mintDecimals + )} +

+
+
+

+ {mangoAccount + ? formatDecimal(mangoAccount.getUi(bank.value)) + : 0} +

+

+ {mangoAccount + ? `$${formatDecimal( + mangoAccount.getUi(bank.value) * + oraclePrice.toNumber(), + 2 + )}` + : '$0'} +

+
+
+ + +
+
+ ) : ( +
{banks.map((bank) => { const oraclePrice = bank.value.price return ( - - +
+
-

{bank.value.name}

+
+

{bank.value.name}

+

+ Available: + {mangoAccount + ? formatDecimal(mangoAccount.getUi(bank.value)) + : 0} +

+
- - -
-

${formatDecimal(oraclePrice.toNumber(), 2)}

+
+
+ + +
+ handleShowTokenDetails(bank.value.name)} + > + +
- - -
-

0%

+
+ +
+
+

{t('price')}

+

+ ${formatDecimal(oraclePrice.toNumber(), 2)} +

+
+
+

+ {t('rolling-change')} +

+

0%

+
+
+

+ {t('daily-volume')} +

+

$1000

+
+
+

Rates (APR)

+

+ + {formatDecimal( + bank.value.getDepositRate().toNumber(), + 2 + )} + % + + | + + {formatDecimal( + bank.value.getBorrowRate().toNumber(), + 2 + )} + % + +

+
+
+

{t('liquidity')}

+

+ {formatDecimal( + bank.value.uiDeposits() - bank.value.uiBorrows(), + bank.value.mintDecimals + )} +

+
- - -
-

1000

-
- - -
-

- {formatDecimal(bank.value.getDepositRate().toNumber(), 2)} - % -

- | -

- {formatDecimal(bank.value.getBorrowRate().toNumber(), 2)}% -

-
- - -
-

- {formatDecimal( - bank.value.uiDeposits() - bank.value.uiBorrows(), - bank.value.mintDecimals - )} -

-
- - -

- {mangoAccount - ? formatDecimal(mangoAccount.getUi(bank.value)) - : '-'} -

-

- {mangoAccount - ? `$${formatDecimal( - mangoAccount.getUi(bank.value) * - oraclePrice.toNumber(), - 2 - )}` - : '-'} -

- - -
- - -
- - +
+
) })} - - +
+ )} ) } diff --git a/components/shared/Layout.tsx b/components/shared/Layout.tsx index b4ea5f5b..705c4e09 100644 --- a/components/shared/Layout.tsx +++ b/components/shared/Layout.tsx @@ -93,7 +93,9 @@ const Layout = ({ children }: { children: ReactNode }) => { {connected ? : }
-
{children}
+
+ {children} +