From 945cf94e5641a10edd389e8dde63fece1121efe4 Mon Sep 17 00:00:00 2001 From: saml33 Date: Tue, 4 Oct 2022 13:26:50 +1100 Subject: [PATCH] mobile trade balances --- components/trade/TradeBalances.tsx | 61 +++++++++++++++++++++++++++- components/trade/UnsettledTrades.tsx | 3 +- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/components/trade/TradeBalances.tsx b/components/trade/TradeBalances.tsx index d279ffa0..d0a7fcd9 100644 --- a/components/trade/TradeBalances.tsx +++ b/components/trade/TradeBalances.tsx @@ -1,9 +1,11 @@ import { QuestionMarkCircleIcon } from '@heroicons/react/20/solid' import mangoStore from '@store/mangoStore' +import { useViewport } from 'hooks/useViewport' import { useTranslation } from 'next-i18next' import Image from 'next/image' import { useMemo } from 'react' import { formatDecimal } from 'utils/numbers' +import { breakpoints } from 'utils/theme' const Balances = () => { const { t } = useTranslation(['common', 'trade']) @@ -11,6 +13,8 @@ const Balances = () => { const spotBalances = mangoStore((s) => s.mangoAccount.spotBalances) const group = mangoStore((s) => s.group) const jupiterTokens = mangoStore((s) => s.jupiterTokens) + const { width } = useViewport() + const showTableView = width ? width > breakpoints.md : false const banks = useMemo(() => { if (group) { @@ -41,7 +45,7 @@ const Balances = () => { return [] }, [group, mangoAccount]) - return ( + return showTableView ? ( @@ -97,6 +101,61 @@ const Balances = () => { })}
+ ) : ( + <> + {banks.map(({ key, value }) => { + const bank = value[0] + + let logoURI + if (jupiterTokens.length) { + logoURI = jupiterTokens.find( + (t) => t.address === bank.mint.toString() + )!.logoURI + } + + return ( +
+
+
+ {logoURI ? ( + + ) : ( + + )} +
+ {bank.name} +
+
+

+ {mangoAccount + ? formatDecimal( + mangoAccount.getTokenBalanceUi(bank), + bank.mintDecimals + ) + : 0} +

+
+

+ {t('trade:in-orders')}:{' '} + + {spotBalances[bank.mint.toString()]?.inOrders || 0.0} + +

+

+ {t('trade:unsettled')}:{' '} + + {spotBalances[bank.mint.toString()]?.unsettled || 0.0} + +

+
+
+
+ ) + })} + ) } diff --git a/components/trade/UnsettledTrades.tsx b/components/trade/UnsettledTrades.tsx index b08211be..9c0c5d89 100644 --- a/components/trade/UnsettledTrades.tsx +++ b/components/trade/UnsettledTrades.tsx @@ -1,6 +1,6 @@ import mangoStore from '@store/mangoStore' import { useTranslation } from 'next-i18next' -import { useCallback, useMemo, useState } from 'react' +import { useCallback, useState } from 'react' import { PublicKey } from '@solana/web3.js' import { IconButton } from '@components/shared/Button' import { notify } from 'utils/notifications' @@ -73,7 +73,6 @@ const UnsettledTrades = ({ const market = group.getSerum3MarketByPk( new PublicKey(mktAddress) ) - console.log('market', mktAddress) const base = market?.name.split('/')[0] const quote = market?.name.split('/')[1]