From 6aec6fd144a4a7b815f90d5067060fdb18b6f318 Mon Sep 17 00:00:00 2001 From: saml33 Date: Wed, 5 Apr 2023 14:21:01 +1000 Subject: [PATCH 1/2] expand perp trade activity feed details --- components/account/ActivityFeed.tsx | 31 +++-- components/account/ActivityFeedTable.tsx | 78 ++++++++--- components/account/PerpTradeDetails.tsx | 158 +++++++++++++++++++++++ components/shared/SideBadge.tsx | 6 +- components/trade/PerpSideBadge.tsx | 4 +- public/locales/en/activity.json | 3 + public/locales/es/activity.json | 3 + public/locales/ru/activity.json | 3 + public/locales/zh/activity.json | 3 + public/locales/zh_tw/activity.json | 3 + types/index.ts | 38 +++++- 11 files changed, 297 insertions(+), 33 deletions(-) create mode 100644 components/account/PerpTradeDetails.tsx diff --git a/components/account/ActivityFeed.tsx b/components/account/ActivityFeed.tsx index 522c7d1f..148d9cca 100644 --- a/components/account/ActivityFeed.tsx +++ b/components/account/ActivityFeed.tsx @@ -1,16 +1,24 @@ import mangoStore from '@store/mangoStore' import { useEffect, useState } from 'react' import ActivityFeedTable from './ActivityFeedTable' -import { LiquidationActivity } from 'types' +import { + LiquidationActivity, + PerpTradeActivity, + isLiquidationFeedItem, +} from 'types' import LiquidationDetails from './LiquidationDetails' +import PerpTradeDetails from './PerpTradeDetails' const ActivityFeed = () => { const activityFeed = mangoStore((s) => s.activityFeed.feed) - const [showActivityDetail, setShowActivityDetail] = - useState() + const [showActivityDetail, setShowActivityDetail] = useState< + LiquidationActivity | PerpTradeActivity + >() const [scrollPosition, setScrollPosition] = useState(0) - const handleShowActivityDetails = (activity: LiquidationActivity) => { + const handleShowActivityDetails = ( + activity: LiquidationActivity | PerpTradeActivity + ) => { setShowActivityDetail(activity) setScrollPosition(window.scrollY) } @@ -28,10 +36,17 @@ const ActivityFeed = () => { /> ) : (
- + {isLiquidationFeedItem(showActivityDetail) ? ( + + ) : ( + + )}
) } diff --git a/components/account/ActivityFeedTable.tsx b/components/account/ActivityFeedTable.tsx index 42ec42b6..5a43a5a3 100644 --- a/components/account/ActivityFeedTable.tsx +++ b/components/account/ActivityFeedTable.tsx @@ -23,16 +23,23 @@ import { useViewport } from 'hooks/useViewport' import { useTranslation } from 'next-i18next' import Image from 'next/legacy/image' import { useCallback, useState } from 'react' -import { ActivityFeed, isLiquidationFeedItem, LiquidationActivity } from 'types' +import { + ActivityFeed, + isLiquidationFeedItem, + LiquidationActivity, + isPerpTradeFeedItem, + PerpTradeActivity, +} from 'types' import { PAGINATION_PAGE_LENGTH, PREFERRED_EXPLORER_KEY } from 'utils/constants' import { formatNumericValue } from 'utils/numbers' import { breakpoints } from 'utils/theme' import LiquidationDetails from './LiquidationDetails' +import PerpTradeDetails from './PerpTradeDetails' -const formatFee = (value: number) => { +export const formatFee = (value: number) => { return value.toLocaleString(undefined, { minimumSignificantDigits: 1, - maximumSignificantDigits: 2, + maximumSignificantDigits: 3, }) } @@ -264,7 +271,9 @@ const ActivityFeedTable = ({ handleShowActivityDetails, }: { activityFeed: ActivityFeed[] - handleShowActivityDetails: (x: LiquidationActivity) => void + handleShowActivityDetails: ( + x: LiquidationActivity | PerpTradeActivity + ) => void }) => { const { t } = useTranslation(['common', 'activity']) const { mangoAccountAddress } = useMangoAccount() @@ -323,14 +332,16 @@ const ActivityFeedTable = ({ const amounts = getCreditAndDebit(activity, mangoAccountAddress) const value = getValue(activity, mangoAccountAddress) const fee = getFee(activity, mangoAccountAddress) + const isExpandable = + isLiquidationFeedItem(activity) || isPerpTradeFeedItem(activity) return ( handleShowActivityDetails(activity) : undefined } @@ -366,10 +377,7 @@ const ActivityFeedTable = ({ = 0 ? 'text-th-up' @@ -378,15 +386,14 @@ const ActivityFeedTable = ({ > {value > 0 && activity_type !== 'swap' && - activity_type !== 'perp_trade' && !isOpenbook && - !isLiquidationFeedItem(activity) + !isExpandable ? '+' : ''} - {!isLiquidationFeedItem(activity) ? ( + {!isExpandable ? (
- {isLiquidationFeedItem(activity) ? ( + {isExpandable ? ( {({ open }) => ( <> @@ -503,9 +522,26 @@ const MobileActivityFeedItem = ({

{t(`activity:${activity_type}`)}

-

- -

+ {isLiquidationFeedItem(activity) ? ( +

+ +

+ ) : ( +

+ + {activity.activity_details.quantity} + + + {activity.activity_details.perp_market_name} + + + {' '} + + +

+ )}
- + {isLiquidationFeedItem(activity) ? ( + + ) : ( + + )}
diff --git a/components/account/PerpTradeDetails.tsx b/components/account/PerpTradeDetails.tsx new file mode 100644 index 00000000..2c11cc04 --- /dev/null +++ b/components/account/PerpTradeDetails.tsx @@ -0,0 +1,158 @@ +import { EXPLORERS } from '@components/settings/PreferredExplorerSettings' +import { IconButton } from '@components/shared/Button' +import FormatNumericValue from '@components/shared/FormatNumericValue' +import PerpSideBadge from '@components/trade/PerpSideBadge' +import { ArrowLeftIcon } from '@heroicons/react/20/solid' +import dayjs from 'dayjs' +import useLocalStorageState from 'hooks/useLocalStorageState' +import useMangoAccount from 'hooks/useMangoAccount' +import { useTranslation } from 'next-i18next' +import Image from 'next/image' +import { PerpTradeActivity } from 'types' +import { PREFERRED_EXPLORER_KEY } from 'utils/constants' +import { getDecimalCount } from 'utils/numbers' +import { formatFee } from './ActivityFeedTable' + +const PerpTradeDetails = ({ + activity, + setShowActivityDetail, +}: { + activity: PerpTradeActivity + setShowActivityDetail?: (x: PerpTradeActivity | undefined) => void +}) => { + const { t } = useTranslation(['common', 'activity', 'settings', 'trade']) + const { mangoAccountAddress } = useMangoAccount() + const [preferredExplorer] = useLocalStorageState( + PREFERRED_EXPLORER_KEY, + EXPLORERS[0] + ) + const { block_datetime } = activity + const { + maker, + maker_fee, + perp_market_name, + price, + quantity, + signature, + taker, + taker_fee, + taker_side, + } = activity.activity_details + + const isTaker = taker === mangoAccountAddress + + const side = isTaker ? taker_side : taker_side === 'bid' ? 'ask' : 'bid' + + const notional = quantity * price + + const fee = isTaker ? taker_fee * notional : maker_fee * notional + + const totalPrice = (notional + fee) / quantity + + return ( +
+ {setShowActivityDetail ? ( +
+ setShowActivityDetail(undefined)} + size="small" + > + + +

{t('activity:perp-details')}

+
+ ) : null} +
+
+

{t('date')}

+

+ {dayjs(block_datetime).format('ddd D MMM')} +

+

+ {dayjs(block_datetime).format('h:mma')} +

+
+
+

{t('trade:side')}

+ +
+
+

{t('trade:size')}

+

+ {quantity}{' '} + {perp_market_name} +

+
+
+

{t('activity:execution-price')}

+

+ {' '} + USDC +

+
+
+

{t('value')}

+

+ +

+
+
+

{t('fee')}

+

+ {formatFee(fee)}{' '} + USDC +

+

+ {isTaker ? t('trade:taker') : t('trade:maker')} +

+
+
+

{t('activity:total-price')}

+

+ {' '} + USDC +

+
+
+

{t('activity:counterparty')}

+ + {t('activity:view-account')} + +
+ +
+
+ ) +} + +export default PerpTradeDetails diff --git a/components/shared/SideBadge.tsx b/components/shared/SideBadge.tsx index 128b352e..0adc8c5c 100644 --- a/components/shared/SideBadge.tsx +++ b/components/shared/SideBadge.tsx @@ -6,13 +6,13 @@ type SideBadgeProps = { const SideBadge: FunctionComponent = ({ side }) => { if (side !== 'buy' && side !== 'sell') { - return
Unknown
+ return Unknown } const isBid = side === 'buy' return ( -
= ({ side }) => { uppercase md:-my-0.5 md:px-1.5 md:py-0.5 md:text-xs`} > {isBid ? 'Buy' : 'Sell'} -
+ ) } diff --git a/components/trade/PerpSideBadge.tsx b/components/trade/PerpSideBadge.tsx index 4d04a5ea..a1501d22 100644 --- a/components/trade/PerpSideBadge.tsx +++ b/components/trade/PerpSideBadge.tsx @@ -2,7 +2,7 @@ const PerpSideBadge = ({ basePosition }: { basePosition: number }) => { return ( <> {basePosition !== 0 ? ( -
0 ? 'text-th-up md:border md:border-th-up' @@ -11,7 +11,7 @@ const PerpSideBadge = ({ basePosition }: { basePosition: number }) => { uppercase md:-my-0.5 md:px-1.5 md:py-0.5 md:text-xs`} > {basePosition > 0 ? 'Long' : 'Short'} -
+ ) : ( '--' )} diff --git a/public/locales/en/activity.json b/public/locales/en/activity.json index a5f6692d..cfb5fee2 100644 --- a/public/locales/en/activity.json +++ b/public/locales/en/activity.json @@ -11,6 +11,7 @@ "debit": "Debit", "deposit": "Deposit", "deposits": "Deposits", + "execution-price": "Execution Price", "filter-results": "Filter", "liquidate_perp_base_position_or_positive_pnl": "Perp Liquidation", "liquidate_token_with_token": "Spot Liquidation", @@ -24,6 +25,7 @@ "liquidator": "Liquidator", "no-activity": "No account activity", "openbook_trade": "Spot Trade", + "perp-details": "Perp Trade Details", "perps": "Perps", "perp_trade": "Perp Trade", "reset-filters": "Reset Filters", @@ -32,6 +34,7 @@ "swap": "Swap", "swaps": "Swaps", "tooltip-fee": "Swap fees paid to other DEXs are not displayed", + "total-price": "Total Price", "trades": "Trades", "update": "Update", "value-from": "Value From", diff --git a/public/locales/es/activity.json b/public/locales/es/activity.json index a5f6692d..cfb5fee2 100644 --- a/public/locales/es/activity.json +++ b/public/locales/es/activity.json @@ -11,6 +11,7 @@ "debit": "Debit", "deposit": "Deposit", "deposits": "Deposits", + "execution-price": "Execution Price", "filter-results": "Filter", "liquidate_perp_base_position_or_positive_pnl": "Perp Liquidation", "liquidate_token_with_token": "Spot Liquidation", @@ -24,6 +25,7 @@ "liquidator": "Liquidator", "no-activity": "No account activity", "openbook_trade": "Spot Trade", + "perp-details": "Perp Trade Details", "perps": "Perps", "perp_trade": "Perp Trade", "reset-filters": "Reset Filters", @@ -32,6 +34,7 @@ "swap": "Swap", "swaps": "Swaps", "tooltip-fee": "Swap fees paid to other DEXs are not displayed", + "total-price": "Total Price", "trades": "Trades", "update": "Update", "value-from": "Value From", diff --git a/public/locales/ru/activity.json b/public/locales/ru/activity.json index a5f6692d..cfb5fee2 100644 --- a/public/locales/ru/activity.json +++ b/public/locales/ru/activity.json @@ -11,6 +11,7 @@ "debit": "Debit", "deposit": "Deposit", "deposits": "Deposits", + "execution-price": "Execution Price", "filter-results": "Filter", "liquidate_perp_base_position_or_positive_pnl": "Perp Liquidation", "liquidate_token_with_token": "Spot Liquidation", @@ -24,6 +25,7 @@ "liquidator": "Liquidator", "no-activity": "No account activity", "openbook_trade": "Spot Trade", + "perp-details": "Perp Trade Details", "perps": "Perps", "perp_trade": "Perp Trade", "reset-filters": "Reset Filters", @@ -32,6 +34,7 @@ "swap": "Swap", "swaps": "Swaps", "tooltip-fee": "Swap fees paid to other DEXs are not displayed", + "total-price": "Total Price", "trades": "Trades", "update": "Update", "value-from": "Value From", diff --git a/public/locales/zh/activity.json b/public/locales/zh/activity.json index a5f6692d..cfb5fee2 100644 --- a/public/locales/zh/activity.json +++ b/public/locales/zh/activity.json @@ -11,6 +11,7 @@ "debit": "Debit", "deposit": "Deposit", "deposits": "Deposits", + "execution-price": "Execution Price", "filter-results": "Filter", "liquidate_perp_base_position_or_positive_pnl": "Perp Liquidation", "liquidate_token_with_token": "Spot Liquidation", @@ -24,6 +25,7 @@ "liquidator": "Liquidator", "no-activity": "No account activity", "openbook_trade": "Spot Trade", + "perp-details": "Perp Trade Details", "perps": "Perps", "perp_trade": "Perp Trade", "reset-filters": "Reset Filters", @@ -32,6 +34,7 @@ "swap": "Swap", "swaps": "Swaps", "tooltip-fee": "Swap fees paid to other DEXs are not displayed", + "total-price": "Total Price", "trades": "Trades", "update": "Update", "value-from": "Value From", diff --git a/public/locales/zh_tw/activity.json b/public/locales/zh_tw/activity.json index a5f6692d..cfb5fee2 100644 --- a/public/locales/zh_tw/activity.json +++ b/public/locales/zh_tw/activity.json @@ -11,6 +11,7 @@ "debit": "Debit", "deposit": "Deposit", "deposits": "Deposits", + "execution-price": "Execution Price", "filter-results": "Filter", "liquidate_perp_base_position_or_positive_pnl": "Perp Liquidation", "liquidate_token_with_token": "Spot Liquidation", @@ -24,6 +25,7 @@ "liquidator": "Liquidator", "no-activity": "No account activity", "openbook_trade": "Spot Trade", + "perp-details": "Perp Trade Details", "perps": "Perps", "perp_trade": "Perp Trade", "reset-filters": "Reset Filters", @@ -32,6 +34,7 @@ "swap": "Swap", "swaps": "Swaps", "tooltip-fee": "Swap fees paid to other DEXs are not displayed", + "total-price": "Total Price", "trades": "Trades", "update": "Update", "value-from": "Value From", diff --git a/types/index.ts b/types/index.ts index 9e408e15..4e204de9 100644 --- a/types/index.ts +++ b/types/index.ts @@ -132,6 +132,26 @@ export interface DepositWithdrawFeedItem { wallet_pk: string } +export interface PerpTradeFeedItem { + block_datetime: string + maker: string + maker_fee: number + maker_order_id: string | null + market_index: number + perp_market: string + perp_market_name: string + price: number + quantity: number + seq_num: number + signature: number + slot: number + taker: string + taker_client_order_id: string | null + taker_fee: number + taker_order_id: string | null + taker_side: string +} + export interface SpotLiquidationFeedItem { asset_amount: number asset_price: number @@ -173,6 +193,13 @@ export interface LiquidationActivity { symbol: string } +export interface PerpTradeActivity { + activity_details: PerpTradeFeedItem + block_datetime: string + activity_type: string + symbol: string +} + export function isLiquidationFeedItem( item: ActivityFeed ): item is LiquidationActivity { @@ -182,6 +209,15 @@ export function isLiquidationFeedItem( return false } +export function isPerpTradeFeedItem( + item: ActivityFeed +): item is PerpTradeActivity { + if (item.activity_type === 'perp_trade') { + return true + } + return false +} + export function isPerpLiquidation( activityDetails: SpotOrPerpLiquidationItem ): activityDetails is PerpLiquidationFeedItem { @@ -234,7 +270,7 @@ export type ActivityFeed = { | SpotLiquidationFeedItem | PerpLiquidationFeedItem | SwapHistoryItem - | PerpTradeHistory + | PerpTradeFeedItem | SpotTradeHistory } From d849e34c9697a7e11fd68ca4f0aba34283515ae0 Mon Sep 17 00:00:00 2001 From: saml33 Date: Wed, 5 Apr 2023 23:14:23 +1000 Subject: [PATCH 2/2] make table rows expand for more details --- components/account/ActivityFeed.tsx | 54 ---- components/account/ActivityFeedTable.tsx | 217 ++++++++-------- components/account/HistoryTabs.tsx | 6 +- components/account/LiquidationDetails.tsx | 294 +++++++++++----------- components/account/PerpTradeDetails.tsx | 198 +++++++-------- public/locales/en/activity.json | 3 +- public/locales/es/activity.json | 3 +- public/locales/ru/activity.json | 3 +- public/locales/zh/activity.json | 3 +- public/locales/zh_tw/activity.json | 3 +- 10 files changed, 353 insertions(+), 431 deletions(-) delete mode 100644 components/account/ActivityFeed.tsx diff --git a/components/account/ActivityFeed.tsx b/components/account/ActivityFeed.tsx deleted file mode 100644 index 148d9cca..00000000 --- a/components/account/ActivityFeed.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import mangoStore from '@store/mangoStore' -import { useEffect, useState } from 'react' -import ActivityFeedTable from './ActivityFeedTable' -import { - LiquidationActivity, - PerpTradeActivity, - isLiquidationFeedItem, -} from 'types' -import LiquidationDetails from './LiquidationDetails' -import PerpTradeDetails from './PerpTradeDetails' - -const ActivityFeed = () => { - const activityFeed = mangoStore((s) => s.activityFeed.feed) - const [showActivityDetail, setShowActivityDetail] = useState< - LiquidationActivity | PerpTradeActivity - >() - const [scrollPosition, setScrollPosition] = useState(0) - - const handleShowActivityDetails = ( - activity: LiquidationActivity | PerpTradeActivity - ) => { - setShowActivityDetail(activity) - setScrollPosition(window.scrollY) - } - - useEffect(() => { - if (scrollPosition && !showActivityDetail) { - window.scroll(0, scrollPosition) - } - }, [scrollPosition, showActivityDetail]) - - return !showActivityDetail ? ( - - ) : ( -
- {isLiquidationFeedItem(showActivityDetail) ? ( - - ) : ( - - )} -
- ) -} - -export default ActivityFeed diff --git a/components/account/ActivityFeedTable.tsx b/components/account/ActivityFeedTable.tsx index 5a43a5a3..6a408e2d 100644 --- a/components/account/ActivityFeedTable.tsx +++ b/components/account/ActivityFeedTable.tsx @@ -9,11 +9,7 @@ import { Table, Td, Th, TrBody, TrHead } from '@components/shared/TableElements' import Tooltip from '@components/shared/Tooltip' import { Disclosure, Transition } from '@headlessui/react' import PerpSideBadge from '@components/trade/PerpSideBadge' -import { - ChevronDownIcon, - ChevronRightIcon, - NoSymbolIcon, -} from '@heroicons/react/20/solid' +import { ChevronDownIcon, NoSymbolIcon } from '@heroicons/react/20/solid' import { useWallet } from '@solana/wallet-adapter-react' import mangoStore from '@store/mangoStore' import dayjs from 'dayjs' @@ -23,13 +19,7 @@ import { useViewport } from 'hooks/useViewport' import { useTranslation } from 'next-i18next' import Image from 'next/legacy/image' import { useCallback, useState } from 'react' -import { - ActivityFeed, - isLiquidationFeedItem, - LiquidationActivity, - isPerpTradeFeedItem, - PerpTradeActivity, -} from 'types' +import { isLiquidationFeedItem, isPerpTradeFeedItem } from 'types' import { PAGINATION_PAGE_LENGTH, PREFERRED_EXPLORER_KEY } from 'utils/constants' import { formatNumericValue } from 'utils/numbers' import { breakpoints } from 'utils/theme' @@ -266,16 +256,9 @@ const getValue = (activity: any, mangoAccountAddress: string) => { return value } -const ActivityFeedTable = ({ - activityFeed, - handleShowActivityDetails, -}: { - activityFeed: ActivityFeed[] - handleShowActivityDetails: ( - x: LiquidationActivity | PerpTradeActivity - ) => void -}) => { +const ActivityFeedTable = () => { const { t } = useTranslation(['common', 'activity']) + const activityFeed = mangoStore((s) => s.activityFeed.feed) const { mangoAccountAddress } = useMangoAccount() const actions = mangoStore((s) => s.actions) const loadActivityFeed = mangoStore((s) => s.activityFeed.loading) @@ -335,95 +318,115 @@ const ActivityFeedTable = ({ const isExpandable = isLiquidationFeedItem(activity) || isPerpTradeFeedItem(activity) return ( - handleShowActivityDetails(activity) - : undefined - } - > - -

- {dayjs(block_datetime).format('ddd D MMM')} -

-

- {dayjs(block_datetime).format('h:mma')} -

- - - {t(`activity:${activity_type}`)} - - - {amounts.credit.value}{' '} - - {amounts.credit.symbol} - - - - {amounts.debit.value}{' '} - - {amounts.debit.symbol} - - - - {fee.value}{' '} - - {fee.symbol} - - - = 0 - ? 'text-th-up' - : 'text-th-down' - }`} - > - {value > 0 && - activity_type !== 'swap' && - !isOpenbook && - !isExpandable - ? '+' - : ''} - - - - {!isExpandable ? ( -
- + {({ open }) => ( + <> + + +

+ {dayjs(block_datetime).format('ddd D MMM')} +

+

+ {dayjs(block_datetime).format('h:mma')} +

+ + + {t(`activity:${activity_type}`)} + + + {amounts.credit.value}{' '} + + {amounts.credit.symbol} + + + + {amounts.debit.value}{' '} + + {amounts.debit.symbol} + + + + {fee.value}{' '} + + {fee.symbol} + + + = 0 + ? 'text-th-up' + : 'text-th-down' + }`} > - - - ) : ( -
- -
- )} - - + )} + +
+ + {isLiquidationFeedItem(activity) ? ( + + + + ) : isPerpTradeFeedItem(activity) ? ( + + + + ) : null} + + + )} + ) })} diff --git a/components/account/HistoryTabs.tsx b/components/account/HistoryTabs.tsx index b9e424d2..9b541a5c 100644 --- a/components/account/HistoryTabs.tsx +++ b/components/account/HistoryTabs.tsx @@ -1,11 +1,11 @@ import { useEffect, useState } from 'react' import SwapHistoryTable from '../swap/SwapHistoryTable' -import ActivityFeed from './ActivityFeed' import TradeHistory from '@components/trade/TradeHistory' import { useTranslation } from 'next-i18next' import ActivityFilters from './ActivityFilters' import mangoStore from '@store/mangoStore' import useMangoAccount from 'hooks/useMangoAccount' +import ActivityFeedTable from './ActivityFeedTable' const TABS = ['activity:activity-feed', 'activity:swaps', 'activity:trades'] @@ -49,13 +49,13 @@ const HistoryTabs = () => { const TabContent = ({ activeTab }: { activeTab: string }) => { switch (activeTab) { case 'activity:activity-feed': - return + return case 'activity:swaps': return case 'activity:trades': return default: - return + return } } diff --git a/components/account/LiquidationDetails.tsx b/components/account/LiquidationDetails.tsx index 9c6f39d3..15e5ffc4 100644 --- a/components/account/LiquidationDetails.tsx +++ b/components/account/LiquidationDetails.tsx @@ -1,8 +1,5 @@ import { EXPLORERS } from '@components/settings/PreferredExplorerSettings' -import { IconButton } from '@components/shared/Button' import FormatNumericValue from '@components/shared/FormatNumericValue' -import { ArrowLeftIcon } from '@heroicons/react/20/solid' -import dayjs from 'dayjs' import useLocalStorageState from 'hooks/useLocalStorageState' import { useTranslation } from 'next-i18next' import Image from 'next/image' @@ -16,17 +13,14 @@ import { PREFERRED_EXPLORER_KEY } from 'utils/constants' const LiquidationDetails = ({ activity, - setShowActivityDetail, }: { activity: LiquidationActivity - setShowActivityDetail?: (x: LiquidationActivity | undefined) => void }) => { const { t } = useTranslation(['common', 'activity', 'settings']) const [preferredExplorer] = useLocalStorageState( PREFERRED_EXPLORER_KEY, EXPLORERS[0] ) - const { block_datetime } = activity const getAssetLiquidatedReturned = (details: SpotOrPerpLiquidationItem) => { const assets = { @@ -91,152 +85,148 @@ const LiquidationDetails = ({ }, [activity]) return ( -
- {setShowActivityDetail ? ( -
- setShowActivityDetail(undefined)} - size="small" - > - - -

{t('activity:liquidation-details')}

-
- ) : null} -
- {isPerpLiquidation(activity.activity_details) ? ( - <> -
-

{t('date')}

-

- {dayjs(block_datetime).format('ddd D MMM')} -

-

- {dayjs(block_datetime).format('h:mma')} -

-
-
-

{t('activity:liquidation-type')}

-

{t('perp')}

-
-
-

{t('activity:asset-liquidated')}

-

- {' '} - {assetLiquidatedSymbol} - at{' '} - -

-

- -

-
-
-

{t('activity:asset-returned')}

-

- {' '} - {assetReturnedSymbol} -

-

- -

-
- - ) : ( - <> -
-

{t('date')}

-

- {dayjs(block_datetime).format('ddd D MMM')} -

-

- {dayjs(block_datetime).format('h:mma')} -

-
-
-

{t('activity:liquidation-type')}

-

{t('spot')}

-
-
-

{t('activity:asset-liquidated')}

-

- {' '} - {assetLiquidatedSymbol} - at{' '} - -

-

- -

-
-
-

{t('activity:asset-returned')}

-

- {' '} - {assetReturnedSymbol} - at{' '} - -

-

- -

-
- - )} -
-

{t('activity:liquidation-fee')}

-

- -

-
-
-

{t('activity:liquidation-side')}

-

- {activity.activity_details.side === 'liqor' - ? t('activity:liquidator') - : t('activity:liquidated')} -

-
-
-

{t('activity:counterparty')}

- - {t('activity:view-account')} - -
- +
+ {isPerpLiquidation(activity.activity_details) ? ( + <> +
+

+ {t('activity:liquidation-type')} +

+

{t('perp')}

+
+
+

+ {t('activity:asset-liquidated')} +

+

+ {' '} + + {assetLiquidatedSymbol} + + at{' '} + +

+

+ +

+
+
+

+ {t('activity:asset-returned')} +

+

+ {' '} + + {assetReturnedSymbol} + +

+

+ +

+
+ + ) : ( + <> +
+

+ {t('activity:liquidation-type')} +

+

{t('spot')}

+
+
+

+ {t('activity:asset-liquidated')} +

+

+ {' '} + + {assetLiquidatedSymbol} + + at{' '} + +

+

+ +

+
+
+

+ {t('activity:asset-returned')} +

+

+ {' '} + + {assetReturnedSymbol} + + at{' '} + +

+

+ +

+
+ + )} +
+

+ {t('activity:liquidation-fee')} +

+

+ +

+
+
+

+ {t('activity:liquidation-side')} +

+

+ {activity.activity_details.side === 'liqor' + ? t('activity:liquidator') + : t('activity:liquidated')} +

+
+
+

+ {t('activity:counterparty')} +

+ + {t('activity:view-account')} + +
+
) diff --git a/components/account/PerpTradeDetails.tsx b/components/account/PerpTradeDetails.tsx index 2c11cc04..87bba026 100644 --- a/components/account/PerpTradeDetails.tsx +++ b/components/account/PerpTradeDetails.tsx @@ -1,9 +1,7 @@ import { EXPLORERS } from '@components/settings/PreferredExplorerSettings' -import { IconButton } from '@components/shared/Button' import FormatNumericValue from '@components/shared/FormatNumericValue' +import Tooltip from '@components/shared/Tooltip' import PerpSideBadge from '@components/trade/PerpSideBadge' -import { ArrowLeftIcon } from '@heroicons/react/20/solid' -import dayjs from 'dayjs' import useLocalStorageState from 'hooks/useLocalStorageState' import useMangoAccount from 'hooks/useMangoAccount' import { useTranslation } from 'next-i18next' @@ -13,20 +11,13 @@ import { PREFERRED_EXPLORER_KEY } from 'utils/constants' import { getDecimalCount } from 'utils/numbers' import { formatFee } from './ActivityFeedTable' -const PerpTradeDetails = ({ - activity, - setShowActivityDetail, -}: { - activity: PerpTradeActivity - setShowActivityDetail?: (x: PerpTradeActivity | undefined) => void -}) => { +const PerpTradeDetails = ({ activity }: { activity: PerpTradeActivity }) => { const { t } = useTranslation(['common', 'activity', 'settings', 'trade']) const { mangoAccountAddress } = useMangoAccount() const [preferredExplorer] = useLocalStorageState( PREFERRED_EXPLORER_KEY, EXPLORERS[0] ) - const { block_datetime } = activity const { maker, maker_fee, @@ -50,106 +41,93 @@ const PerpTradeDetails = ({ const totalPrice = (notional + fee) / quantity return ( -
- {setShowActivityDetail ? ( -
- setShowActivityDetail(undefined)} - size="small" - > - - -

{t('activity:perp-details')}

-
- ) : null} -
-
-

{t('date')}

-

- {dayjs(block_datetime).format('ddd D MMM')} +

+
+

+ {t('trade:side')} +

+ +
+
+

+ {t('trade:size')} +

+

+ {quantity}{' '} + {perp_market_name} +

+
+
+

+ {t('activity:execution-price')} +

+

+ {' '} + USDC +

+
+
+

{t('value')}

+

+ +

+
+
+

{t('fee')}

+

+ {formatFee(fee)} USDC +

+

+ {isTaker ? t('trade:taker') : t('trade:maker')} +

+
+
+ +

+ {t('activity:net-price')}

-

- {dayjs(block_datetime).format('h:mma')} -

-
-
-

{t('trade:side')}

- -
-
-

{t('trade:size')}

-

- {quantity}{' '} - {perp_market_name} -

-
-
-

{t('activity:execution-price')}

-

- {' '} - USDC -

-
-
-

{t('value')}

-

- -

-
-
-

{t('fee')}

-

- {formatFee(fee)}{' '} - USDC -

-

- {isTaker ? t('trade:taker') : t('trade:maker')} -

-
-
-

{t('activity:total-price')}

-

- {' '} - USDC -

-
-
-

{t('activity:counterparty')}

- - {t('activity:view-account')} - -
- + +

+ {' '} + USDC +

+
+
+

+ {t('activity:counterparty')} +

+ + {t('activity:view-account')} + +
+
) diff --git a/public/locales/en/activity.json b/public/locales/en/activity.json index cfb5fee2..316679f5 100644 --- a/public/locales/en/activity.json +++ b/public/locales/en/activity.json @@ -23,6 +23,8 @@ "liquidations": "Liquidations", "liquidation-details": "Liquidation Details", "liquidator": "Liquidator", + "net-price": "Net Price", + "net-price-desc": "The trade price inclusive of fees", "no-activity": "No account activity", "openbook_trade": "Spot Trade", "perp-details": "Perp Trade Details", @@ -34,7 +36,6 @@ "swap": "Swap", "swaps": "Swaps", "tooltip-fee": "Swap fees paid to other DEXs are not displayed", - "total-price": "Total Price", "trades": "Trades", "update": "Update", "value-from": "Value From", diff --git a/public/locales/es/activity.json b/public/locales/es/activity.json index cfb5fee2..316679f5 100644 --- a/public/locales/es/activity.json +++ b/public/locales/es/activity.json @@ -23,6 +23,8 @@ "liquidations": "Liquidations", "liquidation-details": "Liquidation Details", "liquidator": "Liquidator", + "net-price": "Net Price", + "net-price-desc": "The trade price inclusive of fees", "no-activity": "No account activity", "openbook_trade": "Spot Trade", "perp-details": "Perp Trade Details", @@ -34,7 +36,6 @@ "swap": "Swap", "swaps": "Swaps", "tooltip-fee": "Swap fees paid to other DEXs are not displayed", - "total-price": "Total Price", "trades": "Trades", "update": "Update", "value-from": "Value From", diff --git a/public/locales/ru/activity.json b/public/locales/ru/activity.json index cfb5fee2..316679f5 100644 --- a/public/locales/ru/activity.json +++ b/public/locales/ru/activity.json @@ -23,6 +23,8 @@ "liquidations": "Liquidations", "liquidation-details": "Liquidation Details", "liquidator": "Liquidator", + "net-price": "Net Price", + "net-price-desc": "The trade price inclusive of fees", "no-activity": "No account activity", "openbook_trade": "Spot Trade", "perp-details": "Perp Trade Details", @@ -34,7 +36,6 @@ "swap": "Swap", "swaps": "Swaps", "tooltip-fee": "Swap fees paid to other DEXs are not displayed", - "total-price": "Total Price", "trades": "Trades", "update": "Update", "value-from": "Value From", diff --git a/public/locales/zh/activity.json b/public/locales/zh/activity.json index cfb5fee2..316679f5 100644 --- a/public/locales/zh/activity.json +++ b/public/locales/zh/activity.json @@ -23,6 +23,8 @@ "liquidations": "Liquidations", "liquidation-details": "Liquidation Details", "liquidator": "Liquidator", + "net-price": "Net Price", + "net-price-desc": "The trade price inclusive of fees", "no-activity": "No account activity", "openbook_trade": "Spot Trade", "perp-details": "Perp Trade Details", @@ -34,7 +36,6 @@ "swap": "Swap", "swaps": "Swaps", "tooltip-fee": "Swap fees paid to other DEXs are not displayed", - "total-price": "Total Price", "trades": "Trades", "update": "Update", "value-from": "Value From", diff --git a/public/locales/zh_tw/activity.json b/public/locales/zh_tw/activity.json index cfb5fee2..316679f5 100644 --- a/public/locales/zh_tw/activity.json +++ b/public/locales/zh_tw/activity.json @@ -23,6 +23,8 @@ "liquidations": "Liquidations", "liquidation-details": "Liquidation Details", "liquidator": "Liquidator", + "net-price": "Net Price", + "net-price-desc": "The trade price inclusive of fees", "no-activity": "No account activity", "openbook_trade": "Spot Trade", "perp-details": "Perp Trade Details", @@ -34,7 +36,6 @@ "swap": "Swap", "swaps": "Swaps", "tooltip-fee": "Swap fees paid to other DEXs are not displayed", - "total-price": "Total Price", "trades": "Trades", "update": "Update", "value-from": "Value From",