From 53572e8824f0ad16197bab65e41ce9ee67808e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Brzezin=CC=81ski?= Date: Wed, 11 Jan 2023 18:38:51 +0100 Subject: [PATCH 01/36] wip --- components/modals/CloseAccountModal.tsx | 48 ++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/components/modals/CloseAccountModal.tsx b/components/modals/CloseAccountModal.tsx index 1d9341f5..b1ed66d1 100644 --- a/components/modals/CloseAccountModal.tsx +++ b/components/modals/CloseAccountModal.tsx @@ -4,21 +4,35 @@ import mangoStore from '@store/mangoStore' import { notify } from '../../utils/notifications' import Button from '../shared/Button' import { useTranslation } from 'next-i18next' -import { useState } from 'react' +import { useEffect, useState } from 'react' import BounceLoader from '../shared/BounceLoader' import { MangoAccount } from '@blockworks-foundation/mango-v4' import { TrashIcon } from '@heroicons/react/20/solid' +import useUnsettledPerpPositions from 'hooks/useUnsettledPerpPositions' const CloseAccountModal = ({ isOpen, onClose }: ModalProps) => { const { t } = useTranslation('common') const [loading, setLoading] = useState(false) const set = mangoStore((s) => s.set) + const openOrders = Object.values(mangoStore((s) => s.mangoAccount.openOrders)) + const mangoAccount = mangoStore((s) => s.mangoAccount) + const perpPositions = mangoStore((s) => s.mangoAccount.perpPositions) + const openPerpPositions = Object.values(perpPositions).filter((p) => + p.basePositionLots.toNumber() + ) + const unsettledBalances = Object.values(mangoAccount.spotBalances).filter( + (x) => x.unsettled && x.unsettled > 0 + ) + const unsettledPerpPositions = useUnsettledPerpPositions() + const [hasBorrows] = useState(false) + const [hasOpenPositions, setHasOpenPositions] = useState(false) const handleCloseMangoAccount = async () => { const client = mangoStore.getState().client const mangoAccount = mangoStore.getState().mangoAccount.current const mangoAccounts = mangoStore.getState().mangoAccounts const group = mangoStore.getState().group + if (!mangoAccount || !group) return setLoading(true) try { @@ -50,16 +64,42 @@ const CloseAccountModal = ({ isOpen, onClose }: ModalProps) => { } } + useEffect(() => { + if (mangoAccount) { + // if (mangoAccount.borrows.some((b) => b.gt(ZERO_I80F48))) { + // setHasBorrows(true) + // } + if (openPerpPositions.length || unsettledPerpPositions.length) { + setHasOpenPositions(true) + } + } + }, [mangoAccount]) + + const isDisabled = + (openOrders && openOrders.length > 0) || + hasBorrows || + hasOpenPositions || + !!unsettledBalances.length + console.log(isDisabled) return ( -
+
{loading ? ( ) : (
-
+

{t('close-account')}

-

{t('close-account-desc')}

+

+ You can close your Mango account and recover the small amount + amount of SOL used to cover rent exemption.{' '} +

+

To close account you must:

+
    +
  • Close all borrows
  • +
  • Close and settle all Perp positions
  • +
  • Close all open orders
  • +
+
- {!loadPerformanceData ? ( - mangoAccount && performanceData.length ? ( + {performanceInitialLoad ? ( + oneDayPerformanceData.length ? (
@@ -290,7 +299,7 @@ const AccountPage = () => { ? COLORS.UP[theme] : COLORS.DOWN[theme] } - data={performanceData.concat(latestAccountData)} + data={oneDayPerformanceData.concat(latestAccountData)} name="accountValue" xKey="time" yKey="account_equity" @@ -316,11 +325,11 @@ const AccountPage = () => {
) : null - ) : ( + ) : mangoAccountAddress ? (
- )} + ) : null}
@@ -442,7 +451,7 @@ const AccountPage = () => {
@@ -453,7 +462,7 @@ const AccountPage = () => { {mangoAccountAddress ? (
{performanceData.length > 4 ? ( - + { ) : null} - + {
- +
{/* {!tourSettings?.account_tour_seen && isOnBoarded && connected ? ( @@ -524,7 +538,7 @@ const AccountPage = () => { setShowPnlHistory(false)} + onClose={handleCloseDailyPnlModal} /> ) : null} diff --git a/components/modals/PnlHistoryModal.tsx b/components/modals/PnlHistoryModal.tsx index 3016052e..b5cae654 100644 --- a/components/modals/PnlHistoryModal.tsx +++ b/components/modals/PnlHistoryModal.tsx @@ -3,10 +3,11 @@ import Modal from '../shared/Modal' import mangoStore, { PerformanceDataItem } from '@store/mangoStore' // import { useTranslation } from 'next-i18next' import { useEffect, useMemo } from 'react' -import BounceLoader from '../shared/BounceLoader' import useMangoAccount from 'hooks/useMangoAccount' import dayjs from 'dayjs' import Change from '@components/shared/Change' +import SheenLoader from '@components/shared/SheenLoader' +import { NoSymbolIcon } from '@heroicons/react/20/solid' interface PnlHistoryModalProps { pnlChangeToday: number @@ -61,30 +62,37 @@ const PnlHistoryModal = ({ return (
- {loading ? ( - - ) : ( -
-

Daily PnL

- {dailyValues?.length ? ( -
-
- {dailyValues.map((v: any) => ( -
-

{dayjs(v.time).format('YYYY-MM-DD')}

- -
- ))} -
+
+

Daily PnL

+ {loading ? ( +
+ {[...Array(4)].map((x, i) => ( + +
+ + ))} +
+ ) : dailyValues?.length ? ( +
+
+ {dailyValues.map((v: any) => ( +
+

{dayjs(v.time).format('YYYY-MM-DD')}

+ +
+ ))}
- ) : ( -

No daily history

- )} -
- )} +
+ ) : ( +
+ +

No PnL History

+
+ )} +
) From 9716c5f7755acf9c8a956b9515c5d3b1cfa77927 Mon Sep 17 00:00:00 2001 From: saml33 Date: Tue, 17 Jan 2023 12:26:31 +1100 Subject: [PATCH 22/36] add pnl for current week --- components/account/AccountPage.tsx | 2 +- components/modals/PnlHistoryModal.tsx | 73 ++++++++++++++++++++------- 2 files changed, 55 insertions(+), 20 deletions(-) diff --git a/components/account/AccountPage.tsx b/components/account/AccountPage.tsx index d92b75d8..8a9a7752 100644 --- a/components/account/AccountPage.tsx +++ b/components/account/AccountPage.tsx @@ -472,7 +472,7 @@ const AccountPage = () => { ) : null} - + { + const dailyValues: PnlChange[] = useMemo(() => { if (!performanceData.length) return [] const dailyPnl = performanceData.filter((d: PerformanceDataItem) => { @@ -48,22 +53,43 @@ const PnlHistoryModal = ({ time: d.time, pnlChange: dailyPnl[index + 1].pnl - d.pnl, } + } else { + return { + time: performanceData[performanceData.length - 1].time, + pnlChange: pnlChangeToday, + } } }) - .slice(0, -1) - .concat({ - time: performanceData[performanceData.length - 1].time, - pnlChange: pnlChangeToday, - }) .reverse() : [] }, [performanceData]) + const pnlThisWeek = useMemo(() => { + if (dailyValues.length) { + const saturdayIndex = dailyValues.findIndex((d) => { + const day = new Date(d.time).getDay() + return day === 6 + }) + if (saturdayIndex !== -1) { + return dailyValues + .slice(0, saturdayIndex) + .reduce((a, c) => a + c.pnlChange, 0) + } else { + return dailyValues.reduce((a, c) => a + c.pnlChange, 0) + } + } + return 0 + }, [dailyValues]) + + const getLastSunday = (d: Date) => { + return d.setDate(d.getDate() - d.getDay()) + } + return (
-

Daily PnL

+

PnL History

{loading ? (
{[...Array(4)].map((x, i) => ( @@ -73,19 +99,28 @@ const PnlHistoryModal = ({ ))}
) : dailyValues?.length ? ( -
-
- {dailyValues.map((v: any) => ( -
-

{dayjs(v.time).format('YYYY-MM-DD')}

- -
- ))} + <> +
+
+ {dailyValues.map((v: any) => ( +
+

{dayjs(v.time).format('YYYY-MM-DD')}

+ +
+ ))} +
-
+ +
+

{`Week starting ${dayjs(getLastSunday(new Date())).format( + 'MM-DD' + )}`}

+ +
+ ) : (
From 46d9c54ef3dec3492719b72bf9440f5c1df4e862 Mon Sep 17 00:00:00 2001 From: saml33 Date: Tue, 17 Jan 2023 15:59:51 +1100 Subject: [PATCH 23/36] add translation vars --- components/account/AccountPage.tsx | 31 ++++++++------------------- components/modals/PnlHistoryModal.tsx | 16 ++++++++------ pages/index.tsx | 1 + public/locales/en/account.json | 11 ++++++++++ public/locales/en/common.json | 1 + public/locales/es/account.json | 11 ++++++++++ public/locales/es/common.json | 1 + public/locales/ru/account.json | 11 ++++++++++ public/locales/ru/common.json | 1 + public/locales/zh/account.json | 11 ++++++++++ public/locales/zh/common.json | 1 + public/locales/zh_tw/account.json | 11 ++++++++++ public/locales/zh_tw/common.json | 1 + 13 files changed, 79 insertions(+), 29 deletions(-) create mode 100644 public/locales/en/account.json create mode 100644 public/locales/es/account.json create mode 100644 public/locales/ru/account.json create mode 100644 public/locales/zh/account.json create mode 100644 public/locales/zh_tw/account.json diff --git a/components/account/AccountPage.tsx b/components/account/AccountPage.tsx index 8a9a7752..2d749f66 100644 --- a/components/account/AccountPage.tsx +++ b/components/account/AccountPage.tsx @@ -3,7 +3,6 @@ import { toUiDecimalsForQuote, } from '@blockworks-foundation/mango-v4' import { useTranslation } from 'next-i18next' -import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import { useEffect, useMemo, useState } from 'react' import AccountActions from './AccountActions' import mangoStore, { PerformanceDataItem } from '@store/mangoStore' @@ -43,20 +42,8 @@ import { breakpoints } from 'utils/theme' import useMangoGroup from 'hooks/useMangoGroup' import PnlHistoryModal from '@components/modals/PnlHistoryModal' -export async function getStaticProps({ locale }: { locale: string }) { - return { - props: { - ...(await serverSideTranslations(locale, [ - 'common', - 'close-account', - 'trade', - ])), - }, - } -} - const AccountPage = () => { - const { t } = useTranslation('common') + const { t } = useTranslation(['common', 'account']) // const { connected } = useWallet() const { group } = useMangoGroup() const { mangoAccount, mangoAccountAddress } = useMangoAccount() @@ -385,7 +372,7 @@ const AccountPage = () => {
{

- Total: + {t('total')}: {group && mangoAccount ? formatFixedDecimals( @@ -433,7 +420,7 @@ const AccountPage = () => {
{
@@ -462,7 +449,7 @@ const AccountPage = () => { {mangoAccountAddress ? (
{performanceData.length > 4 ? ( - + { ) : null} - + {
{ - // const { t } = useTranslation('common') + const { t } = useTranslation('account') const { mangoAccountAddress } = useMangoAccount() const actions = mangoStore.getState().actions const loading = mangoStore((s) => s.mangoAccount.performance.loading) @@ -89,7 +89,7 @@ const PnlHistoryModal = ({
-

PnL History

+

{t('pnl-history')}

{loading ? (
{[...Array(4)].map((x, i) => ( @@ -115,16 +115,18 @@ const PnlHistoryModal = ({
-

{`Week starting ${dayjs(getLastSunday(new Date())).format( - 'MM-DD' - )}`}

+

+ {t('week-starting', { + week: dayjs(getLastSunday(new Date())).format('MM-DD'), + })} +

) : (
-

No PnL History

+

{t('no-pnl-history')}

)}
diff --git a/pages/index.tsx b/pages/index.tsx index b216e035..ead15c41 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -6,6 +6,7 @@ export async function getStaticProps({ locale }: { locale: string }) { return { props: { ...(await serverSideTranslations(locale, [ + 'account', 'activity', 'common', 'onboarding', diff --git a/public/locales/en/account.json b/public/locales/en/account.json new file mode 100644 index 00000000..28d4646c --- /dev/null +++ b/public/locales/en/account.json @@ -0,0 +1,11 @@ +{ + "no-pnl-history": "No PnL History", + "pnl-chart": "PnL Chart", + "pnl-history": "PnL History", + "tooltip-free-collateral": "The amount of capital you have to use for trades and loans. When your free collateral reaches $0 you won't be able to trade, borrow or withdraw", + "tooltip-leverage": "Total assets value divided by account equity value", + "tooltip-pnl": "The amount your account has profited or lost", + "tooltip-total-collateral": "Total value of collateral for trading and borrowing (including unsettled PnL)", + "tooltip-total-interest": "The value of interest earned (deposits) minus interest paid (borrows)", + "week-starting": "Week starting {{week}}" +} \ No newline at end of file diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 3f6b6386..ddd3cedd 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -121,6 +121,7 @@ "token-collateral-multiplier": "{{token}} Collateral Multiplier", "tooltip-borrow-rate": "The variable interest rate you'll pay on your borrowed balance", "tooltip-collateral-value": "The USD amount you can trade or borrow against", + "total": "Total", "total-borrows": "Total Borrows", "total-borrow-value": "Total Borrow Value", "total-collateral": "Total Collateral", diff --git a/public/locales/es/account.json b/public/locales/es/account.json new file mode 100644 index 00000000..28d4646c --- /dev/null +++ b/public/locales/es/account.json @@ -0,0 +1,11 @@ +{ + "no-pnl-history": "No PnL History", + "pnl-chart": "PnL Chart", + "pnl-history": "PnL History", + "tooltip-free-collateral": "The amount of capital you have to use for trades and loans. When your free collateral reaches $0 you won't be able to trade, borrow or withdraw", + "tooltip-leverage": "Total assets value divided by account equity value", + "tooltip-pnl": "The amount your account has profited or lost", + "tooltip-total-collateral": "Total value of collateral for trading and borrowing (including unsettled PnL)", + "tooltip-total-interest": "The value of interest earned (deposits) minus interest paid (borrows)", + "week-starting": "Week starting {{week}}" +} \ No newline at end of file diff --git a/public/locales/es/common.json b/public/locales/es/common.json index 3f6b6386..ddd3cedd 100644 --- a/public/locales/es/common.json +++ b/public/locales/es/common.json @@ -121,6 +121,7 @@ "token-collateral-multiplier": "{{token}} Collateral Multiplier", "tooltip-borrow-rate": "The variable interest rate you'll pay on your borrowed balance", "tooltip-collateral-value": "The USD amount you can trade or borrow against", + "total": "Total", "total-borrows": "Total Borrows", "total-borrow-value": "Total Borrow Value", "total-collateral": "Total Collateral", diff --git a/public/locales/ru/account.json b/public/locales/ru/account.json new file mode 100644 index 00000000..28d4646c --- /dev/null +++ b/public/locales/ru/account.json @@ -0,0 +1,11 @@ +{ + "no-pnl-history": "No PnL History", + "pnl-chart": "PnL Chart", + "pnl-history": "PnL History", + "tooltip-free-collateral": "The amount of capital you have to use for trades and loans. When your free collateral reaches $0 you won't be able to trade, borrow or withdraw", + "tooltip-leverage": "Total assets value divided by account equity value", + "tooltip-pnl": "The amount your account has profited or lost", + "tooltip-total-collateral": "Total value of collateral for trading and borrowing (including unsettled PnL)", + "tooltip-total-interest": "The value of interest earned (deposits) minus interest paid (borrows)", + "week-starting": "Week starting {{week}}" +} \ No newline at end of file diff --git a/public/locales/ru/common.json b/public/locales/ru/common.json index 3f6b6386..ddd3cedd 100644 --- a/public/locales/ru/common.json +++ b/public/locales/ru/common.json @@ -121,6 +121,7 @@ "token-collateral-multiplier": "{{token}} Collateral Multiplier", "tooltip-borrow-rate": "The variable interest rate you'll pay on your borrowed balance", "tooltip-collateral-value": "The USD amount you can trade or borrow against", + "total": "Total", "total-borrows": "Total Borrows", "total-borrow-value": "Total Borrow Value", "total-collateral": "Total Collateral", diff --git a/public/locales/zh/account.json b/public/locales/zh/account.json new file mode 100644 index 00000000..28d4646c --- /dev/null +++ b/public/locales/zh/account.json @@ -0,0 +1,11 @@ +{ + "no-pnl-history": "No PnL History", + "pnl-chart": "PnL Chart", + "pnl-history": "PnL History", + "tooltip-free-collateral": "The amount of capital you have to use for trades and loans. When your free collateral reaches $0 you won't be able to trade, borrow or withdraw", + "tooltip-leverage": "Total assets value divided by account equity value", + "tooltip-pnl": "The amount your account has profited or lost", + "tooltip-total-collateral": "Total value of collateral for trading and borrowing (including unsettled PnL)", + "tooltip-total-interest": "The value of interest earned (deposits) minus interest paid (borrows)", + "week-starting": "Week starting {{week}}" +} \ No newline at end of file diff --git a/public/locales/zh/common.json b/public/locales/zh/common.json index 3f6b6386..ddd3cedd 100644 --- a/public/locales/zh/common.json +++ b/public/locales/zh/common.json @@ -121,6 +121,7 @@ "token-collateral-multiplier": "{{token}} Collateral Multiplier", "tooltip-borrow-rate": "The variable interest rate you'll pay on your borrowed balance", "tooltip-collateral-value": "The USD amount you can trade or borrow against", + "total": "Total", "total-borrows": "Total Borrows", "total-borrow-value": "Total Borrow Value", "total-collateral": "Total Collateral", diff --git a/public/locales/zh_tw/account.json b/public/locales/zh_tw/account.json new file mode 100644 index 00000000..28d4646c --- /dev/null +++ b/public/locales/zh_tw/account.json @@ -0,0 +1,11 @@ +{ + "no-pnl-history": "No PnL History", + "pnl-chart": "PnL Chart", + "pnl-history": "PnL History", + "tooltip-free-collateral": "The amount of capital you have to use for trades and loans. When your free collateral reaches $0 you won't be able to trade, borrow or withdraw", + "tooltip-leverage": "Total assets value divided by account equity value", + "tooltip-pnl": "The amount your account has profited or lost", + "tooltip-total-collateral": "Total value of collateral for trading and borrowing (including unsettled PnL)", + "tooltip-total-interest": "The value of interest earned (deposits) minus interest paid (borrows)", + "week-starting": "Week starting {{week}}" +} \ No newline at end of file diff --git a/public/locales/zh_tw/common.json b/public/locales/zh_tw/common.json index 3f6b6386..ddd3cedd 100644 --- a/public/locales/zh_tw/common.json +++ b/public/locales/zh_tw/common.json @@ -121,6 +121,7 @@ "token-collateral-multiplier": "{{token}} Collateral Multiplier", "tooltip-borrow-rate": "The variable interest rate you'll pay on your borrowed balance", "tooltip-collateral-value": "The USD amount you can trade or borrow against", + "total": "Total", "total-borrows": "Total Borrows", "total-borrow-value": "Total Borrow Value", "total-collateral": "Total Collateral", From ad473e9807068e77a979502db74d112c692b2ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Brzezin=CC=81ski?= Date: Wed, 18 Jan 2023 02:04:50 +0100 Subject: [PATCH 24/36] upgrade mango v4 --- yarn.lock | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/yarn.lock b/yarn.lock index f27ae11c..624ae37c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -52,7 +52,7 @@ "@blockworks-foundation/mango-v4@https://github.com/blockworks-foundation/mango-v4.git#ts-client": version "0.0.1-beta.6" - resolved "https://github.com/blockworks-foundation/mango-v4.git#59ef05ebe95ed5ca947ab5cfecf97c4c9fc99740" + resolved "https://github.com/blockworks-foundation/mango-v4.git#adc9140ad2a3c2e9c3b425b8804d9415f2a05067" dependencies: "@project-serum/anchor" "^0.25.0" "@project-serum/serum" "^0.13.65" @@ -4844,7 +4844,14 @@ node-addon-api@^2.0.0: resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-2.0.2.tgz#432cfa82962ce494b132e9d72a15b29f71ff5d32" integrity sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA== -node-fetch@2, node-fetch@2.6.7, node-fetch@^2.6.1: +node-fetch@2, node-fetch@^2.6.1: + version "2.6.8" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.8.tgz#a68d30b162bc1d8fd71a367e81b997e1f4d4937e" + integrity sha512-RZ6dBYuj8dRSfxpUSu+NsdF1dpPpluJxwOp+6IoDp/sH2QNDSvurYsAa+F1WxY2RjA1iP93xhcsUoYbF2XBqVg== + dependencies: + whatwg-url "^5.0.0" + +node-fetch@2.6.7: version "2.6.7" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ== From 9d8f804b75a2b8d3f099bdca7331d993698ff2dc Mon Sep 17 00:00:00 2001 From: saml33 Date: Wed, 18 Jan 2023 22:18:57 +1100 Subject: [PATCH 25/36] fix token logo symbol matching --- components/swap/SwapHistoryTable.tsx | 8 ++++---- components/trade/MarketLogos.tsx | 8 ++++++-- hooks/useSelectedMarket.ts | 8 +++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/components/swap/SwapHistoryTable.tsx b/components/swap/SwapHistoryTable.tsx index 18f17534..04fe735e 100644 --- a/components/swap/SwapHistoryTable.tsx +++ b/components/swap/SwapHistoryTable.tsx @@ -105,10 +105,10 @@ const SwapHistoryTable = () => { if (mangoTokens.length) { baseLogoURI = mangoTokens.find( - (t) => t.symbol === inSymbol + (t) => t.symbol.toUpperCase() === inSymbol.toUpperCase() )?.logoURI quoteLogoURI = mangoTokens.find( - (t) => t.symbol === outSymbol + (t) => t.symbol.toUpperCase() === outSymbol.toUpperCase() )?.logoURI } @@ -268,10 +268,10 @@ const SwapHistoryTable = () => { if (mangoTokens.length) { baseLogoURI = mangoTokens.find( - (t) => t.symbol === inSymbol + (t) => t.symbol.toUpperCase() === inSymbol.toUpperCase() )?.logoURI quoteLogoURI = mangoTokens.find( - (t) => t.symbol === outSymbol + (t) => t.symbol.toUpperCase() === outSymbol.toUpperCase() )?.logoURI } diff --git a/components/trade/MarketLogos.tsx b/components/trade/MarketLogos.tsx index bf394db2..02d6fb8f 100644 --- a/components/trade/MarketLogos.tsx +++ b/components/trade/MarketLogos.tsx @@ -33,8 +33,12 @@ const MarketLogos = ({ ) } else { jupiterBaseToken = - mangoTokens.find((t) => t.symbol === market.name.split('-')[0]) || - mangoTokens.find((t) => t.symbol.includes(market.name.split('-')[0])) + mangoTokens.find( + (t) => t.symbol.toUpperCase() === market.name.split('-')[0] + ) || + mangoTokens.find((t) => + t.symbol.toUpperCase()?.includes(market.name.split('-')[0]) + ) } const baseLogoURI = jupiterBaseToken ? jupiterBaseToken.logoURI : '' const quoteLogoURI = jupiterQuoteToken ? jupiterQuoteToken.logoURI : '' diff --git a/hooks/useSelectedMarket.ts b/hooks/useSelectedMarket.ts index 775c9755..8cd268f8 100644 --- a/hooks/useSelectedMarket.ts +++ b/hooks/useSelectedMarket.ts @@ -40,8 +40,8 @@ export default function useSelectedMarket() { const baseLogoURI = useMemo(() => { if (!baseSymbol || !mangoTokens.length) return '' const token = - mangoTokens.find((t) => t.symbol === baseSymbol) || - mangoTokens.find((t) => t.symbol?.includes(baseSymbol)) + mangoTokens.find((t) => t.symbol.toUpperCase() === baseSymbol) || + mangoTokens.find((t) => t.symbol.toUpperCase()?.includes(baseSymbol)) if (token) { return token.logoURI } @@ -64,7 +64,9 @@ export default function useSelectedMarket() { const quoteLogoURI = useMemo(() => { if (!quoteSymbol || !mangoTokens.length) return '' - const token = mangoTokens.find((t) => t.symbol === quoteSymbol) + const token = mangoTokens.find( + (t) => t.symbol.toUpperCase() === quoteSymbol + ) if (token) { return token.logoURI } From 7107b91ad17637e276d1a0592130efadf1578c9d Mon Sep 17 00:00:00 2001 From: saml33 Date: Wed, 18 Jan 2023 22:34:25 +1100 Subject: [PATCH 26/36] fix swap history amounts and improve columns --- components/swap/SwapHistoryTable.tsx | 110 ++++++++++++++------------- public/locales/en/swap.json | 2 + public/locales/es/swap.json | 6 +- public/locales/ru/swap.json | 6 +- public/locales/zh/swap.json | 6 +- public/locales/zh_tw/swap.json | 6 +- 6 files changed, 76 insertions(+), 60 deletions(-) diff --git a/components/swap/SwapHistoryTable.tsx b/components/swap/SwapHistoryTable.tsx index 04fe735e..29038dbf 100644 --- a/components/swap/SwapHistoryTable.tsx +++ b/components/swap/SwapHistoryTable.tsx @@ -63,7 +63,8 @@ const SwapHistoryTable = () => { {t('date')} - {t('swap')} + {t('swap:paid')} + {t('swap:received')} {t('value')} {t('borrow')} {t('borrow-fee')} @@ -112,7 +113,7 @@ const SwapHistoryTable = () => { )?.logoURI } - const inDecimals = countLeadingZeros(swap_in_amount) + const inDecimals = countLeadingZeros(swap_in_amount) + 2 const outDecimals = countLeadingZeros(swap_out_amount) + 2 return ( @@ -124,54 +125,53 @@ const SwapHistoryTable = () => { {dayjs(block_datetime).format('h:mma')}

- -
-
-
- -
-
-

- {`${formatDecimal(swap_in_amount, inDecimals)}`} - - {inSymbol} - -

-

- - {t('price')}: - {' '} - {formatFixedDecimals(swap_in_price_usd, true)} -

-
+ +
+
+
- -
-
- -
-
-

- {`${formatDecimal(swap_out_amount, outDecimals)}`} - - {outSymbol} - -

-

- {t('price')}:{' '} - {formatFixedDecimals(swap_out_price_usd, true)} -

-
+
+

+ {`${formatDecimal(swap_in_amount, inDecimals)}`} + + {inSymbol} + +

+

+ + {t('price')}: + {' '} + {formatFixedDecimals(swap_in_price_usd, true)} +

+
+
+ + +
+
+ +
+
+

+ {`${formatDecimal(swap_out_amount, outDecimals)}`} + + {outSymbol} + +

+

+ {t('price')}:{' '} + {formatFixedDecimals(swap_out_price_usd, true)} +

@@ -275,6 +275,9 @@ const SwapHistoryTable = () => { )?.logoURI } + const inDecimals = countLeadingZeros(swap_in_amount) + 2 + const outDecimals = countLeadingZeros(swap_out_amount) + 2 + return (
@@ -290,7 +293,7 @@ const SwapHistoryTable = () => {

- {swap_in_amount.toFixed(2)}{' '} + {formatDecimal(swap_in_amount, inDecimals)}{' '} {inSymbol} @@ -315,7 +318,7 @@ const SwapHistoryTable = () => {

- {swap_out_amount.toFixed(2)}{' '} + {formatDecimal(swap_out_amount, outDecimals)}{' '} {outSymbol} @@ -329,7 +332,10 @@ const SwapHistoryTable = () => {

- handleShowSwapDetails(signature)}> + handleShowSwapDetails(signature)} + size="medium" + > Date: Wed, 18 Jan 2023 13:13:29 +0000 Subject: [PATCH 27/36] Replace references to mango-transaction-log --- components/profile/EditNftProfilePic.tsx | 5 +++-- components/profile/EditProfileForm.tsx | 5 +++-- components/tours/CustomTooltip.tsx | 3 ++- components/trade/PerpFundingRate.tsx | 3 ++- store/mangoStore.ts | 21 +++++++++++---------- utils/constants.ts | 2 ++ 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/components/profile/EditNftProfilePic.tsx b/components/profile/EditNftProfilePic.tsx index b711d950..0a11b390 100644 --- a/components/profile/EditNftProfilePic.tsx +++ b/components/profile/EditNftProfilePic.tsx @@ -6,6 +6,7 @@ import { useTranslation } from 'next-i18next' import Button, { LinkButton } from '../shared/Button' import { bs58 } from '@project-serum/anchor/dist/cjs/utils/bytes' import { notify } from 'utils/notifications' +import { MANGO_DATA_API_URL } from 'utils/constants' const ImgWithLoader = (props: any) => { const [isLoading, setIsLoading] = useState(true) @@ -67,7 +68,7 @@ const EditNftProfilePic = ({ onClose }: { onClose: () => void }) => { }), } const response = await fetch( - 'https://mango-transaction-log.herokuapp.com/v4/user-data/profile-details', + `${MANGO_DATA_API_URL}/user-data/profile-details`, requestOptions ) if (response.status === 200) { @@ -113,7 +114,7 @@ const EditNftProfilePic = ({ onClose }: { onClose: () => void }) => { }), } const response = await fetch( - 'https://mango-transaction-log.herokuapp.com/v4/user-data/profile-details', + `${MANGO_DATA_API_URL}/user-data/profile-details`, requestOptions ) if (response.status === 200) { diff --git a/components/profile/EditProfileForm.tsx b/components/profile/EditProfileForm.tsx index 6d238d91..5d268824 100644 --- a/components/profile/EditProfileForm.tsx +++ b/components/profile/EditProfileForm.tsx @@ -14,6 +14,7 @@ import mangoStore from '@store/mangoStore' import startCase from 'lodash/startCase' import { useTranslation } from 'next-i18next' import { ChangeEvent, useState } from 'react' +import { MANGO_DATA_API_URL } from 'utils/constants' import { notify } from 'utils/notifications' import ProfileImage from './ProfileImage' @@ -42,7 +43,7 @@ const EditProfileForm = ({ try { setLoadUniquenessCheck(true) const response = await fetch( - `https://mango-transaction-log.herokuapp.com/v4/user-data/check-profile-name-unique?profile-name=${name}` + `${MANGO_DATA_API_URL}/user-data/check-profile-name-unique?profile-name=${name}` ) const uniquenessCheck = await response.json() @@ -103,7 +104,7 @@ const EditProfileForm = ({ }), } const response = await fetch( - 'https://mango-transaction-log.herokuapp.com/v4/user-data/profile-details', + `${MANGO_DATA_API_URL}/user-data/profile-details`, requestOptions ) if (response.status === 200) { diff --git a/components/tours/CustomTooltip.tsx b/components/tours/CustomTooltip.tsx index cf5313f0..d35b433a 100644 --- a/components/tours/CustomTooltip.tsx +++ b/components/tours/CustomTooltip.tsx @@ -3,6 +3,7 @@ import { XMarkIcon } from '@heroicons/react/20/solid' import { useWallet } from '@solana/wallet-adapter-react' import mangoStore from '@store/mangoStore' import { useState } from 'react' +import { MANGO_DATA_API_URL } from 'utils/constants' import { WalktourLogic } from 'walktour' const CustomTooltip = ({ @@ -37,7 +38,7 @@ const CustomTooltip = ({ body: message, } const response = await fetch( - 'https://mango-transaction-log.herokuapp.com/v4/user-data/settings-unsigned', + `${MANGO_DATA_API_URL}/user-data/settings-unsigned`, requestOptions ) if (response.status === 200) { diff --git a/components/trade/PerpFundingRate.tsx b/components/trade/PerpFundingRate.tsx index 13a8fb5e..4cf18363 100644 --- a/components/trade/PerpFundingRate.tsx +++ b/components/trade/PerpFundingRate.tsx @@ -5,10 +5,11 @@ import { useQuery } from '@tanstack/react-query' import useMangoGroup from 'hooks/useMangoGroup' import useSelectedMarket from 'hooks/useSelectedMarket' import { useMemo } from 'react' +import { MANGO_DATA_API_URL } from 'utils/constants' const fetchFundingRate = async (groupPk: string | undefined) => { const res = await fetch( - `https://mango-transaction-log.herokuapp.com/v4/one-hour-funding-rate?mango-group=${groupPk}` + `${MANGO_DATA_API_URL}/one-hour-funding-rate?mango-group=${groupPk}` ) return await res.json() } diff --git a/store/mangoStore.ts b/store/mangoStore.ts index f8c13c4a..22bfc3d8 100644 --- a/store/mangoStore.ts +++ b/store/mangoStore.ts @@ -33,6 +33,7 @@ import { DEFAULT_MARKET_NAME, INPUT_TOKEN_DEFAULT, LAST_ACCOUNT_KEY, + MANGO_DATA_API_URL, OUTPUT_TOKEN_DEFAULT, RPC_PROVIDER_KEY, } from '../utils/constants' @@ -461,7 +462,7 @@ const mangoStore = create()( }) try { const response = await fetch( - `https://mango-transaction-log.herokuapp.com/v4/stats/interest-account-total?mango-account=${mangoAccountPk}` + `${MANGO_DATA_API_URL}/stats/interest-account-total?mango-account=${mangoAccountPk}` ) const parsedResponse = await response.json() const entries: any = Object.entries(parsedResponse).sort((a, b) => @@ -498,7 +499,7 @@ const mangoStore = create()( }) try { const response = await fetch( - `https://mango-transaction-log.herokuapp.com/v4/stats/performance_account?mango-account=${mangoAccountPk}&start-date=${dayjs() + `${MANGO_DATA_API_URL}/stats/performance_account?mango-account=${mangoAccountPk}&start-date=${dayjs() .subtract(range, 'day') .format('YYYY-MM-DD')}` ) @@ -541,7 +542,7 @@ const mangoStore = create()( try { const response = await fetch( - `https://mango-transaction-log.herokuapp.com/v4/stats/activity-feed?mango-account=${mangoAccountPk}&offset=${offset}&limit=25${ + `${MANGO_DATA_API_URL}/stats/activity-feed?mango-account=${mangoAccountPk}&offset=${offset}&limit=25${ params ? params : '' }` ) @@ -817,7 +818,7 @@ const mangoStore = create()( }) try { const response = await fetch( - `https://mango-transaction-log.herokuapp.com/v4/perp-historical-stats?mango-group=${group?.publicKey.toString()}` + `${MANGO_DATA_API_URL}/perp-historical-stats?mango-group=${group?.publicKey.toString()}` ) const data = await response.json() @@ -840,7 +841,7 @@ const mangoStore = create()( setTimeout(async () => { try { const history = await fetch( - `https://mango-transaction-log.herokuapp.com/v4/stats/swap-history?mango-account=${mangoAccountPk}` + `${MANGO_DATA_API_URL}/stats/swap-history?mango-account=${mangoAccountPk}` ) const parsedHistory = await history.json() const sortedHistory = @@ -876,7 +877,7 @@ const mangoStore = create()( }) try { const response = await fetch( - `https://mango-transaction-log.herokuapp.com/v4/token-historical-stats?mango-group=${group?.publicKey.toString()}` + `${MANGO_DATA_API_URL}/token-historical-stats?mango-group=${group?.publicKey.toString()}` ) const data = await response.json() @@ -945,7 +946,7 @@ const mangoStore = create()( }) try { const response = await fetch( - `https://mango-transaction-log.herokuapp.com/v4/user-data/profile-details?wallet-pk=${walletPk}` + `${MANGO_DATA_API_URL}/user-data/profile-details?wallet-pk=${walletPk}` ) const data = await response.json() set((state) => { @@ -967,7 +968,7 @@ const mangoStore = create()( }) try { const response = await fetch( - `https://mango-transaction-log.herokuapp.com/v4/user-data/settings-unsigned?wallet-pk=${walletPk}` + `${MANGO_DATA_API_URL}/user-data/settings-unsigned?wallet-pk=${walletPk}` ) const data = await response.json() set((state) => { @@ -1021,10 +1022,10 @@ const mangoStore = create()( try { const [spotRes, perpRes] = await Promise.all([ fetch( - `https://mango-transaction-log.herokuapp.com/v4/stats/openbook-trades?address=${mangoAccount?.publicKey.toString()}&address-type=mango-account` + `${MANGO_DATA_API_URL}/stats/openbook-trades?address=${mangoAccount?.publicKey.toString()}&address-type=mango-account` ), fetch( - `https://mango-transaction-log.herokuapp.com/v4/stats/perp-trade-history?mango-account=${mangoAccount?.publicKey.toString()}&limit=1000` + `${MANGO_DATA_API_URL}/stats/perp-trade-history?mango-account=${mangoAccount?.publicKey.toString()}&limit=1000` ), ]) const spotHistory = await spotRes.json() diff --git a/utils/constants.ts b/utils/constants.ts index 1a19ddab..13421363 100644 --- a/utils/constants.ts +++ b/utils/constants.ts @@ -60,6 +60,8 @@ export const CHART_DATA_FEED = `https://dry-ravine-67635.herokuapp.com/tv` export const MANGO_ROUTER_API_URL = 'https://api.mngo.cloud/router/v1' +export const MANGO_DATA_API_URL = 'https://api.mngo.cloud/data/v4' + export const DEFAULT_MARKET_NAME = 'SOL/USDC' export const MIN_SOL_BALANCE = 0.001 From b470d03adf2ba30802991f883d9bf38384210ba9 Mon Sep 17 00:00:00 2001 From: Riordan Panayides Date: Wed, 18 Jan 2023 18:00:27 +0000 Subject: [PATCH 28/36] Fix mango-v4 dependency --- yarn.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index 624ae37c..95df898e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -52,7 +52,7 @@ "@blockworks-foundation/mango-v4@https://github.com/blockworks-foundation/mango-v4.git#ts-client": version "0.0.1-beta.6" - resolved "https://github.com/blockworks-foundation/mango-v4.git#adc9140ad2a3c2e9c3b425b8804d9415f2a05067" + resolved "https://github.com/blockworks-foundation/mango-v4.git#1ca560c007081127ac31486a96a3729da22f99fb" dependencies: "@project-serum/anchor" "^0.25.0" "@project-serum/serum" "^0.13.65" From 79821f52165b33884793a4d579c0e0d8ce2776e7 Mon Sep 17 00:00:00 2001 From: Riordan Panayides Date: Wed, 18 Jan 2023 18:41:42 +0000 Subject: [PATCH 29/36] Fix side badge for combinedTradeHistory trades --- components/trade/TradeHistory.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/components/trade/TradeHistory.tsx b/components/trade/TradeHistory.tsx index aeccc5b4..91f207bf 100644 --- a/components/trade/TradeHistory.tsx +++ b/components/trade/TradeHistory.tsx @@ -189,6 +189,17 @@ const TradeHistory = () => { makerTaker = 'Taker' } } + let side = trade.side + if ('perp_market' in trade) { + const sideObj: any = {} + if (makerTaker == 'Taker') { + sideObj[trade.taker_side] = 1 + } else { + sideObj[trade.taker_side == 'bid' ? 'ask' : 'bid'] = 1 + } + side = sideObj + } + const size = trade.size || trade.quantity let fee if (trade.fee_cost || trade.feeCost) { @@ -209,14 +220,14 @@ const TradeHistory = () => { - + {size} {formatDecimal(trade.price)} - {formatFixedDecimals(trade.price * size)} + ${formatFixedDecimals(trade.price * size)} {formatDecimal(fee)} From 193d2a16fe5ab894525be10dfc4d4e5cc7f25000 Mon Sep 17 00:00:00 2001 From: saml33 Date: Thu, 19 Jan 2023 10:50:55 +1100 Subject: [PATCH 30/36] fix connect wallet button for long wallet names --- components/wallet/ConnectWalletButton.tsx | 38 +++++++++++++---------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/components/wallet/ConnectWalletButton.tsx b/components/wallet/ConnectWalletButton.tsx index 0c49a624..bbc15b80 100644 --- a/components/wallet/ConnectWalletButton.tsx +++ b/components/wallet/ConnectWalletButton.tsx @@ -29,24 +29,28 @@ export const ConnectWalletButton: React.FC = () => { >
-
- {`${wallet?.adapter.name} -
+ {connecting ? ( + + ) : ( +
+ {`${wallet?.adapter.name} +
+ )}
-
- {connecting ? : t('connect')} +
+ {t('connect')}
From b8ca0a40c73aa2fbc6f0d3e7278629dd3fd16abc Mon Sep 17 00:00:00 2001 From: tjs Date: Wed, 18 Jan 2023 19:19:46 -0500 Subject: [PATCH 31/36] fix type error from merge --- store/mangoStore.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/store/mangoStore.ts b/store/mangoStore.ts index d38444bb..a781ffb0 100644 --- a/store/mangoStore.ts +++ b/store/mangoStore.ts @@ -384,11 +384,9 @@ const mangoStore = create()( openOrders: {}, perpPositions: [], spotBalances: {}, - stats: { - interestTotals: { data: [], loading: false }, - performance: { data: [], loading: false }, - swapHistory: { data: [], initialLoad: false }, - }, + interestTotals: { data: [], loading: false }, + performance: { data: [], loading: false, initialLoad: false }, + swapHistory: { data: [], initialLoad: false }, tradeHistory: { data: [], loading: true }, }, mangoAccounts: [], From 8ffe2eb19540e949e52de8eedd1ad6e386b71a8c Mon Sep 17 00:00:00 2001 From: tjs Date: Wed, 18 Jan 2023 19:21:02 -0500 Subject: [PATCH 32/36] add quiet flag to husky check --- .husky/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index f3a559de..c8cc17a7 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -yarn typecheck && yarn lint +yarn typecheck && yarn lint --quiet From 270c74b9db35c1556f71908f18686c6cae1b8d26 Mon Sep 17 00:00:00 2001 From: saml33 Date: Thu, 19 Jan 2023 13:42:29 +1100 Subject: [PATCH 33/36] toggle tradingview on mobile --- components/trade/AdvancedMarketHeader.tsx | 71 +++++++++++++------- components/trade/MobileTradeAdvancedPage.tsx | 15 +++-- components/trade/TradingChartContainer.tsx | 4 +- components/trade/TradingViewChartKline.tsx | 4 +- 4 files changed, 62 insertions(+), 32 deletions(-) diff --git a/components/trade/AdvancedMarketHeader.tsx b/components/trade/AdvancedMarketHeader.tsx index 81220542..825c7c74 100644 --- a/components/trade/AdvancedMarketHeader.tsx +++ b/components/trade/AdvancedMarketHeader.tsx @@ -1,5 +1,7 @@ import { PerpMarket } from '@blockworks-foundation/mango-v4' +import { IconButton } from '@components/shared/Button' import Change from '@components/shared/Change' +import { ChartBarIcon } from '@heroicons/react/20/solid' import { useCoingecko } from 'hooks/useCoingecko' import useSelectedMarket from 'hooks/useSelectedMarket' import { useTranslation } from 'next-i18next' @@ -8,7 +10,13 @@ import { getDecimalCount } from 'utils/numbers' import MarketSelectDropdown from './MarketSelectDropdown' import PerpFundingRate from './PerpFundingRate' -const AdvancedMarketHeader = () => { +const AdvancedMarketHeader = ({ + showChart, + setShowChart, +}: { + showChart?: boolean + setShowChart?: (x: boolean) => void +}) => { const { t } = useTranslation(['common', 'trade']) const { serumOrPerpMarket, baseSymbol, price } = useSelectedMarket() const { data: tokenPrices } = useCoingecko() @@ -35,31 +43,46 @@ const AdvancedMarketHeader = () => {
-
-
-
{t('trade:oracle-price')}
-
- {price ? ( - `$${price.toFixed( - getDecimalCount(serumOrPerpMarket?.tickSize || 0.01) - )}` - ) : ( - – - )} -
-
-
-
{t('rolling-change')}
- -
- {serumOrPerpMarket instanceof PerpMarket ? ( -
-
- {t('trade:funding-rate')} +
+
+
+
+
+ {t('trade:oracle-price')} +
+
+ {price ? ( + `$${price.toFixed( + getDecimalCount(serumOrPerpMarket?.tickSize || 0.01) + )}` + ) : ( + – + )} +
- +
+
{t('rolling-change')}
+ +
+ {serumOrPerpMarket instanceof PerpMarket ? ( +
+
+ {t('trade:funding-rate')} +
+ +
+ ) : null}
- ) : null} + {setShowChart ? ( + setShowChart(!showChart)} + hideBg + > + + + ) : null} +
) diff --git a/components/trade/MobileTradeAdvancedPage.tsx b/components/trade/MobileTradeAdvancedPage.tsx index d22bce4d..2eb744e5 100644 --- a/components/trade/MobileTradeAdvancedPage.tsx +++ b/components/trade/MobileTradeAdvancedPage.tsx @@ -6,17 +6,24 @@ import TradeInfoTabs from './TradeInfoTabs' import TabButtons from '@components/shared/TabButtons' import { TABS } from './OrderbookAndTrades' import RecentTrades from './RecentTrades' +import TradingChartContainer from './TradingChartContainer' const MobileTradeAdvancedPage = () => { const [activeTab, setActiveTab] = useState('trade:book') + const [showChart, setShowChart] = useState(false) return (
- +
- {/*
- -
*/} + {showChart ? ( +
+ +
+ ) : null}
diff --git a/components/trade/TradingChartContainer.tsx b/components/trade/TradingChartContainer.tsx index 2776e877..7392fd8a 100644 --- a/components/trade/TradingChartContainer.tsx +++ b/components/trade/TradingChartContainer.tsx @@ -17,9 +17,9 @@ const TradingChartContainer = () => { const [tradingChart] = useLocalStorageState(TRADE_CHART_UI_KEY) const isTradingChart = tradingChart === 'custom' return !isTradingChart ? ( - + ) : ( - + ) } diff --git a/components/trade/TradingViewChartKline.tsx b/components/trade/TradingViewChartKline.tsx index 8c90ec64..0241e279 100644 --- a/components/trade/TradingViewChartKline.tsx +++ b/components/trade/TradingViewChartKline.tsx @@ -405,9 +405,9 @@ const TradingViewChartKline = ({ setIsFullView, isFullView }: Props) => { return (
From 4ce190161d4098165b53562905bdf46d52218cbe Mon Sep 17 00:00:00 2001 From: saml33 Date: Thu, 19 Jan 2023 14:38:06 +1100 Subject: [PATCH 34/36] round pnl history --- components/modals/PnlHistoryModal.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/components/modals/PnlHistoryModal.tsx b/components/modals/PnlHistoryModal.tsx index 272b201d..4638603a 100644 --- a/components/modals/PnlHistoryModal.tsx +++ b/components/modals/PnlHistoryModal.tsx @@ -8,6 +8,7 @@ import dayjs from 'dayjs' import Change from '@components/shared/Change' import SheenLoader from '@components/shared/SheenLoader' import { NoSymbolIcon } from '@heroicons/react/20/solid' +import { formatDecimal } from 'utils/numbers' interface PnlChange { time: string @@ -49,9 +50,10 @@ const PnlHistoryModal = ({ ? dailyPnl .map((d: PerformanceDataItem, index: number) => { if (index < dailyPnl.length - 1) { + const change = dailyPnl[index + 1].pnl - d.pnl return { time: d.time, - pnlChange: dailyPnl[index + 1].pnl - d.pnl, + pnlChange: change, } } else { return { @@ -108,7 +110,10 @@ const PnlHistoryModal = ({ key={v.time + v.pnlChange} >

{dayjs(v.time).format('YYYY-MM-DD')}

- +
))}
From 235f3cde9d06fbc3b73f68a53b67da984f8350bb Mon Sep 17 00:00:00 2001 From: saml33 Date: Thu, 19 Jan 2023 15:16:43 +1100 Subject: [PATCH 35/36] fix account performance data when changing accounts --- components/account/AccountPage.tsx | 41 ++++++++++++++++-------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/components/account/AccountPage.tsx b/components/account/AccountPage.tsx index 2d749f66..dc7c74dc 100644 --- a/components/account/AccountPage.tsx +++ b/components/account/AccountPage.tsx @@ -75,16 +75,25 @@ const AccountPage = () => { useEffect(() => { if (mangoAccountAddress) { + const set = mangoStore.getState().set + set((s) => { + s.mangoAccount.performance.initialLoad = false + }) + setOneDayPerformanceData([]) actions.fetchAccountPerformance(mangoAccountAddress, 1) actions.fetchAccountInterestTotals(mangoAccountAddress) } }, [actions, mangoAccountAddress]) useEffect(() => { - if (performanceInitialLoad && !oneDayPerformanceData.length) { + if ( + performanceData.length && + performanceInitialLoad && + !oneDayPerformanceData.length + ) { setOneDayPerformanceData(performanceData) } - }, [performanceInitialLoad, oneDayPerformanceData]) + }, [performanceInitialLoad, oneDayPerformanceData, performanceData]) const onHoverMenu = (open: boolean, action: string) => { if ( @@ -134,30 +143,24 @@ const AccountPage = () => { } }, [mangoAccount, group, accountValue]) - const { accountPnl, accountValueChange } = useMemo(() => { + const [accountPnl, accountValueChange, oneDayPnlChange] = useMemo(() => { if ( accountValue && oneDayPerformanceData.length && performanceData.length ) { - return { - accountPnl: performanceData[performanceData.length - 1].pnl, - accountValueChange: - accountValue - oneDayPerformanceData[0].account_equity, - } - } - return { accountPnl: 0, accountValueChange: 0 } - }, [accountValue, oneDayPerformanceData, performanceData]) - - const oneDayPnlChange = useMemo(() => { - if (accountPnl && oneDayPerformanceData.length) { + const accountPnl = performanceData[performanceData.length - 1].pnl + const accountValueChange = + accountValue - oneDayPerformanceData[0].account_equity const startDayPnl = oneDayPerformanceData[0].pnl const endDayPnl = oneDayPerformanceData[oneDayPerformanceData.length - 1].pnl - return endDayPnl - startDayPnl + const oneDayPnlChange = endDayPnl - startDayPnl + + return [accountPnl, accountValueChange, oneDayPnlChange] } - return 0.0 - }, [accountPnl, oneDayPerformanceData]) + return [0, 0, 0] + }, [accountValue, oneDayPerformanceData, performanceData]) const interestTotalValue = useMemo(() => { if (totalInterestData.length) { @@ -170,7 +173,7 @@ const AccountPage = () => { }, [totalInterestData]) const oneDayInterestChange = useMemo(() => { - if (oneDayPerformanceData.length && mangoAccount) { + if (oneDayPerformanceData.length) { const startDayInterest = oneDayPerformanceData[0].borrow_interest_cumulative_usd + oneDayPerformanceData[0].deposit_interest_cumulative_usd @@ -184,7 +187,7 @@ const AccountPage = () => { return endDayInterest - startDayInterest } return 0.0 - }, [oneDayPerformanceData, mangoAccount]) + }, [oneDayPerformanceData]) const maintHealth = useMemo(() => { return group && mangoAccount From cf7cf1c037eba01a84b1dedf5e4e00722292781f Mon Sep 17 00:00:00 2001 From: saml33 Date: Thu, 19 Jan 2023 15:22:16 +1100 Subject: [PATCH 36/36] round account page change components --- components/account/AccountPage.tsx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/components/account/AccountPage.tsx b/components/account/AccountPage.tsx index dc7c74dc..99a06c4e 100644 --- a/components/account/AccountPage.tsx +++ b/components/account/AccountPage.tsx @@ -6,7 +6,7 @@ import { useTranslation } from 'next-i18next' import { useEffect, useMemo, useState } from 'react' import AccountActions from './AccountActions' import mangoStore, { PerformanceDataItem } from '@store/mangoStore' -import { formatFixedDecimals } from '../../utils/numbers' +import { formatDecimal, formatFixedDecimals } from '../../utils/numbers' import FlipNumbers from 'react-flip-numbers' import dynamic from 'next/dynamic' const SimpleAreaChart = dynamic( @@ -268,7 +268,10 @@ const AccountPage = () => { )}
- +

{t('today')}

@@ -478,7 +481,11 @@ const AccountPage = () => { {formatFixedDecimals(accountPnl, true, true)}

- +

{t('today')}

@@ -514,7 +521,11 @@ const AccountPage = () => { {formatFixedDecimals(interestTotalValue, true, true)}

- +

{t('today')}