From c90802d729102c34d2fabd8be8ce52ec595124fe Mon Sep 17 00:00:00 2001 From: saml33 Date: Thu, 8 Sep 2022 12:36:39 +1000 Subject: [PATCH] fix token list on mobile --- components/TokenList.tsx | 63 ++++++++++++++++++++------ components/account/AccountPage.tsx | 2 +- components/shared/PercentageChange.tsx | 2 +- store/mangoStore.ts | 2 +- 4 files changed, 52 insertions(+), 17 deletions(-) diff --git a/components/TokenList.tsx b/components/TokenList.tsx index eb368547..166713d9 100644 --- a/components/TokenList.tsx +++ b/components/TokenList.tsx @@ -11,12 +11,12 @@ import { useTheme } from 'next-themes' import Image from 'next/image' import { useRouter } from 'next/router' import { Fragment, useCallback, useEffect, useMemo, useState } from 'react' -import useLocalStorageState from '../hooks/useLocalStorageState' +// import useLocalStorageState from '../hooks/useLocalStorageState' import { useViewport } from '../hooks/useViewport' import mangoStore from '../store/mangoStore' import { COLORS } from '../styles/colors' -import { SHOW_ZERO_BALANCES_KEY } from '../utils/constants' +// import { SHOW_ZERO_BALANCES_KEY } from '../utils/constants' import { formatDecimal, formatFixedDecimals } from '../utils/numbers' import { breakpoints } from '../utils/theme' import Switch from './forms/Switch' @@ -87,8 +87,6 @@ const TokenList = () => { } }, [connected]) - console.log(coingeckoPrices) - return (
@@ -266,12 +264,28 @@ const TokenList = () => { export default TokenList -const MobileTokenListItem = ({ bank, key }: { bank: Bank; key: string }) => { +const MobileTokenListItem = ({ bank }: { bank: Bank }) => { const { t } = useTranslation('common') const [showTokenDetails, setShowTokenDetails] = useState(false) const jupiterTokens = mangoStore((s) => s.jupiterTokens) const mangoAccount = mangoStore((s) => s.mangoAccount.current) - const group = mangoStore((s) => s.group) + const coingeckoPrices = mangoStore((s) => s.coingeckoPrices.data) + const totalInterestData = mangoStore( + (s) => s.mangoAccount.stats.interestTotals.data + ) + const symbol = bank.name + const oraclePrice = bank.uiPrice + + const coingeckoData = coingeckoPrices.find((asset) => + symbol === 'soETH' ? asset.symbol === 'ETH' : asset.symbol === symbol + ) + + const change = coingeckoData + ? ((coingeckoData.prices[coingeckoData.prices.length - 1][1] - + coingeckoData.prices[0][1]) / + coingeckoData.prices[0][1]) * + 100 + : 0 let logoURI if (jupiterTokens.length) { @@ -279,8 +293,22 @@ const MobileTokenListItem = ({ bank, key }: { bank: Bank; key: string }) => { (t) => t.address === bank.mint.toString() )!.logoURI } + + const hasInterestEarned = totalInterestData.find( + (d) => d.symbol === bank.name + ) + + const interestAmount = hasInterestEarned + ? hasInterestEarned.borrow_interest + hasInterestEarned.deposit_interest + : 0 + + const interestValue = hasInterestEarned + ? hasInterestEarned.borrow_interest_usd + + hasInterestEarned.deposit_interest_usd + : 0.0 + return ( -
+
@@ -324,12 +352,17 @@ const MobileTokenListItem = ({ bank, key }: { bank: Bank; key: string }) => { >
-

{t('price')}

-

${formatDecimal(bank.uiPrice!, 2)}

+

{t('interest-earned-paid')}

+
+

{formatDecimal(interestAmount)}

+

+ ({formatFixedDecimals(interestValue, true)}) +

+

{t('rates')}

-

+

{formatDecimal(bank.getDepositRate().toNumber(), 2)}% @@ -340,10 +373,12 @@ const MobileTokenListItem = ({ bank, key }: { bank: Bank; key: string }) => {

-

Vault {t('liquidity')}

-

- {group ? group.getTokenVaultBalanceByMintUi(bank.mint) : '-'} -

+

{t('price')}

+

{formatFixedDecimals(oraclePrice!, true)}

+
+
+

{t('rolling-change')}

+
diff --git a/components/account/AccountPage.tsx b/components/account/AccountPage.tsx index 3cd3a77e..22c6899f 100644 --- a/components/account/AccountPage.tsx +++ b/components/account/AccountPage.tsx @@ -139,7 +139,7 @@ const AccountPage = () => {

{t('account-value')}

-
+
$ {mangoAccount ? ( { return ( -
+
{change > 0 ? : change < 0 ? : ''}