mango-v4-ui/components/account/ActivityFeedTable.tsx

710 lines
25 KiB
TypeScript
Raw Normal View History

2023-02-27 23:20:11 -08:00
/* eslint-disable @typescript-eslint/no-explicit-any */
2022-11-24 18:39:14 -08:00
import { EXPLORERS } from '@components/settings/PreferredExplorerSettings'
2023-03-23 17:51:03 -07:00
import { LinkButton } from '@components/shared/Button'
2023-01-19 17:45:08 -08:00
import ConnectEmptyState from '@components/shared/ConnectEmptyState'
2023-01-23 20:14:37 -08:00
import FormatNumericValue from '@components/shared/FormatNumericValue'
2022-09-28 20:35:34 -07:00
import SheenLoader from '@components/shared/SheenLoader'
2023-03-23 17:11:34 -07:00
import SideBadge from '@components/shared/SideBadge'
2022-11-20 02:44:14 -08:00
import { Table, Td, Th, TrBody, TrHead } from '@components/shared/TableElements'
2022-09-27 23:17:06 -07:00
import Tooltip from '@components/shared/Tooltip'
2023-03-23 17:51:03 -07:00
import { Disclosure, Transition } from '@headlessui/react'
2023-03-23 17:11:34 -07:00
import PerpSideBadge from '@components/trade/PerpSideBadge'
import { ChevronDownIcon, NoSymbolIcon } from '@heroicons/react/20/solid'
2023-01-19 17:45:08 -08:00
import { useWallet } from '@solana/wallet-adapter-react'
2023-02-23 16:28:49 -08:00
import mangoStore from '@store/mangoStore'
2022-09-27 23:17:06 -07:00
import dayjs from 'dayjs'
import useLocalStorageState from 'hooks/useLocalStorageState'
2022-11-18 09:09:39 -08:00
import useMangoAccount from 'hooks/useMangoAccount'
2022-09-28 06:04:58 -07:00
import { useViewport } from 'hooks/useViewport'
2022-09-27 23:17:06 -07:00
import { useTranslation } from 'next-i18next'
2022-10-28 14:46:38 -07:00
import Image from 'next/legacy/image'
2023-03-23 17:51:03 -07:00
import { useCallback, useState } from 'react'
import { isLiquidationFeedItem, isPerpTradeFeedItem } from 'types'
2023-01-12 16:16:10 -08:00
import { PAGINATION_PAGE_LENGTH, PREFERRED_EXPLORER_KEY } from 'utils/constants'
2023-01-23 20:14:37 -08:00
import { formatNumericValue } from 'utils/numbers'
2022-09-28 06:04:58 -07:00
import { breakpoints } from 'utils/theme'
2023-03-23 17:51:03 -07:00
import LiquidationDetails from './LiquidationDetails'
import PerpTradeDetails from './PerpTradeDetails'
2022-09-27 23:17:06 -07:00
export const formatFee = (value: number) => {
2023-01-10 16:20:06 -08:00
return value.toLocaleString(undefined, {
minimumSignificantDigits: 1,
maximumSignificantDigits: 3,
2023-01-10 16:20:06 -08:00
})
}
2023-04-20 03:55:52 -07:00
export const getFee = (activity: any, mangoAccountAddress: string) => {
2023-02-20 12:07:16 -08:00
const { activity_type } = activity
let fee = { value: '0', symbol: '' }
if (activity_type === 'swap') {
const { loan_origination_fee, swap_in_symbol } = activity.activity_details
fee = loan_origination_fee
? { value: formatFee(loan_origination_fee), symbol: swap_in_symbol }
: { value: '0', symbol: '' }
}
if (activity_type === 'perp_trade') {
2023-04-04 04:55:24 -07:00
const { maker_fee, taker_fee, maker, price, quantity } =
activity.activity_details
const value = price * quantity
2023-02-20 12:07:16 -08:00
fee = {
2023-04-04 04:55:24 -07:00
value: formatFee(
2023-07-21 11:47:53 -07:00
mangoAccountAddress === maker ? maker_fee * value : taker_fee * value,
2023-04-04 04:55:24 -07:00
),
2023-02-20 12:07:16 -08:00
symbol: 'USDC',
}
}
if (activity_type === 'openbook_trade') {
const { fee_cost, quote_symbol } = activity.activity_details
2023-03-02 12:42:59 -08:00
fee = { value: fee_cost, symbol: quote_symbol }
2023-02-20 12:07:16 -08:00
}
2023-03-26 17:25:34 -07:00
if (activity_type === 'liquidate_token_with_token') {
2023-03-27 16:56:23 -07:00
const { side, liab_amount, liab_symbol, asset_amount, asset_price } =
activity.activity_details
2023-03-26 17:25:34 -07:00
if (side === 'liqee') {
fee = {
value: formatNumericValue(
2023-07-21 11:47:53 -07:00
Math.abs(liab_amount) - Math.abs(asset_amount * asset_price),
2023-03-26 17:25:34 -07:00
),
symbol: liab_symbol,
}
} else {
fee = {
value: formatNumericValue(
2023-07-21 11:47:53 -07:00
Math.abs(asset_amount * asset_price) - Math.abs(liab_amount),
2023-03-26 17:25:34 -07:00
),
2023-03-27 16:56:23 -07:00
symbol: liab_symbol,
2023-03-26 17:25:34 -07:00
}
}
}
if (activity_type === 'liquidate_perp_base_position_or_positive_pnl') {
const { base_transfer, price, quote_transfer } = activity.activity_details
if (base_transfer > 0) {
fee = {
value: formatNumericValue(
2023-07-21 11:47:53 -07:00
Math.abs(base_transfer * price) - Math.abs(quote_transfer),
2023-03-26 17:25:34 -07:00
),
symbol: 'USDC',
}
} else {
fee = {
value: formatNumericValue(
2023-07-21 11:47:53 -07:00
Math.abs(quote_transfer) - Math.abs(base_transfer * price),
2023-03-26 17:25:34 -07:00
),
symbol: 'USDC',
}
}
}
2023-02-20 12:07:16 -08:00
return fee
}
2023-04-20 03:55:52 -07:00
export const getCreditAndDebit = (
activity: any,
2023-07-21 11:47:53 -07:00
mangoAccountAddress: string,
2023-04-20 03:55:52 -07:00
) => {
2023-02-20 12:07:16 -08:00
const { activity_type } = activity
let credit = { value: '0', symbol: '' }
let debit = { value: '0', symbol: '' }
if (activity_type === 'liquidate_token_with_token') {
const { side, liab_amount, liab_symbol, asset_amount, asset_symbol } =
activity.activity_details
if (side === 'liqee') {
credit = { value: formatNumericValue(liab_amount), symbol: liab_symbol }
debit = {
value: formatNumericValue(asset_amount),
symbol: asset_symbol,
}
} else {
credit = {
value: formatNumericValue(asset_amount),
symbol: asset_symbol,
}
debit = { value: formatNumericValue(liab_amount), symbol: liab_symbol }
}
}
2023-03-22 18:26:02 -07:00
if (activity_type === 'liquidate_perp_base_position_or_positive_pnl') {
2023-03-26 17:25:34 -07:00
const { base_transfer, perp_market_name, quote_transfer } =
activity.activity_details
2023-03-23 05:08:59 -07:00
if (base_transfer > 0) {
credit = {
2023-03-26 17:25:34 -07:00
value: formatNumericValue(base_transfer),
symbol: perp_market_name,
2023-03-22 18:26:02 -07:00
}
2023-03-23 05:08:59 -07:00
debit = { value: formatNumericValue(quote_transfer), symbol: 'USDC' }
2023-03-22 18:26:02 -07:00
} else {
2023-03-23 05:08:59 -07:00
credit = { value: formatNumericValue(quote_transfer), symbol: 'USDC' }
debit = {
2023-03-26 17:25:34 -07:00
value: formatNumericValue(base_transfer),
symbol: perp_market_name,
2023-03-22 18:26:02 -07:00
}
}
}
2023-02-20 12:07:16 -08:00
if (activity_type === 'deposit') {
const { symbol, quantity } = activity.activity_details
credit = { value: formatNumericValue(quantity), symbol }
debit = { value: '0', symbol: '' }
}
if (activity_type === 'withdraw') {
const { symbol, quantity } = activity.activity_details
credit = { value: '0', symbol: '' }
debit = { value: formatNumericValue(quantity * -1), symbol }
}
if (activity_type === 'swap') {
const { swap_in_amount, swap_in_symbol, swap_out_amount, swap_out_symbol } =
activity.activity_details
credit = {
value: formatNumericValue(swap_out_amount),
symbol: swap_out_symbol,
}
debit = {
value: formatNumericValue(swap_in_amount * -1),
symbol: swap_in_symbol,
}
}
if (activity_type === 'perp_trade') {
const {
maker_fee,
perp_market_name,
price,
quantity,
taker,
taker_fee,
taker_side,
} = activity.activity_details
const side =
taker === mangoAccountAddress
? taker_side
: taker_side === 'bid'
? 'ask'
: 'bid'
2023-04-04 05:26:59 -07:00
const feeRatio = taker === mangoAccountAddress ? taker_fee : maker_fee
2023-04-04 04:55:24 -07:00
const notional = quantity * price
2023-04-04 05:26:59 -07:00
const fee = feeRatio * notional
if (side === 'bid') {
credit = { value: quantity, symbol: perp_market_name }
debit = {
2023-04-04 05:26:59 -07:00
value: formatNumericValue((notional + fee) * -1),
symbol: 'USDC',
}
} else {
credit = {
2023-04-04 05:26:59 -07:00
value: formatNumericValue(notional - fee),
symbol: 'USDC',
}
debit = { value: `-${quantity}`, symbol: perp_market_name }
2023-02-20 12:07:16 -08:00
}
}
if (activity_type === 'openbook_trade') {
const { side, price, size, base_symbol, quote_symbol } =
activity.activity_details
credit =
side === 'buy'
? { value: formatNumericValue(size), symbol: base_symbol }
: { value: formatNumericValue(size * price), symbol: quote_symbol }
debit =
side === 'buy'
? {
value: formatNumericValue(size * price * -1),
symbol: quote_symbol,
}
: { value: formatNumericValue(size * -1), symbol: base_symbol }
}
return { credit, debit }
}
2023-04-20 03:55:52 -07:00
export const getValue = (activity: any, mangoAccountAddress: string) => {
2023-02-20 12:07:16 -08:00
const { activity_type } = activity
let value = 0
if (activity_type === 'liquidate_token_with_token') {
2023-03-26 17:25:34 -07:00
const { asset_amount, asset_price } = activity.activity_details
2023-03-27 16:56:23 -07:00
value = Math.abs(asset_amount * asset_price)
2023-03-22 18:26:02 -07:00
}
if (activity_type === 'liquidate_perp_base_position_or_positive_pnl') {
2023-03-26 17:25:34 -07:00
const { base_transfer, price, quote_transfer, side } =
activity.activity_details
2023-03-23 05:08:59 -07:00
if (base_transfer > 0) {
if (side === 'liqee') {
2023-03-27 16:56:23 -07:00
value = Math.abs(quote_transfer)
2023-03-23 05:08:59 -07:00
} else {
2023-03-27 16:56:23 -07:00
value = Math.abs(base_transfer * price)
2023-03-23 05:08:59 -07:00
}
2023-02-20 12:07:16 -08:00
} else {
2023-03-23 05:08:59 -07:00
if (side === 'liqee') {
2023-03-27 16:56:23 -07:00
value = Math.abs(base_transfer * price)
2023-03-23 05:08:59 -07:00
} else {
2023-03-27 16:56:23 -07:00
value = Math.abs(quote_transfer)
2023-03-23 05:08:59 -07:00
}
2023-02-20 12:07:16 -08:00
}
}
if (activity_type === 'deposit' || activity_type === 'withdraw') {
const { usd_equivalent } = activity.activity_details
value = activity_type === 'withdraw' ? usd_equivalent * -1 : usd_equivalent
}
if (activity_type === 'swap') {
const { swap_out_amount, swap_out_price_usd } = activity.activity_details
value = swap_out_amount * swap_out_price_usd
}
if (activity_type === 'perp_trade') {
2023-04-04 04:55:24 -07:00
const { price, quantity, taker, taker_fee, maker_fee } =
activity.activity_details
const isTaker = taker === mangoAccountAddress
const feeRatio = isTaker ? taker_fee : maker_fee
const notional = quantity * price
const fee = feeRatio * notional
value = isTaker ? notional + fee : notional - fee
2023-02-20 12:07:16 -08:00
}
if (activity_type === 'openbook_trade') {
const { price, size } = activity.activity_details
value = price * size
}
return value
}
const ActivityFeedTable = () => {
2022-09-27 23:17:06 -07:00
const { t } = useTranslation(['common', 'activity'])
const activityFeed = mangoStore((s) => s.activityFeed.feed)
const { mangoAccountAddress } = useMangoAccount()
2023-02-03 00:27:54 -08:00
const actions = mangoStore((s) => s.actions)
2022-09-28 20:35:34 -07:00
const loadActivityFeed = mangoStore((s) => s.activityFeed.loading)
2023-02-03 00:27:54 -08:00
const queryParams = mangoStore((s) => s.activityFeed.queryParams)
2022-09-27 23:17:06 -07:00
const [offset, setOffset] = useState(0)
2023-01-19 17:45:08 -08:00
const { connected } = useWallet()
2022-09-27 23:17:06 -07:00
const [preferredExplorer] = useLocalStorageState(
PREFERRED_EXPLORER_KEY,
2023-07-21 11:47:53 -07:00
EXPLORERS[0],
2022-09-27 23:17:06 -07:00
)
2022-09-28 06:04:58 -07:00
const { width } = useViewport()
const showTableView = width ? width > breakpoints.md : false
2022-09-27 23:17:06 -07:00
const handleShowMore = useCallback(() => {
2022-09-28 20:35:34 -07:00
const set = mangoStore.getState().set
set((s) => {
s.activityFeed.loading = true
})
if (!mangoAccountAddress) return
2023-01-12 16:16:10 -08:00
setOffset(offset + PAGINATION_PAGE_LENGTH)
actions.fetchActivityFeed(
mangoAccountAddress,
offset + PAGINATION_PAGE_LENGTH,
2023-07-21 11:47:53 -07:00
queryParams,
2023-01-12 16:16:10 -08:00
)
2023-02-03 00:27:54 -08:00
}, [actions, offset, queryParams, mangoAccountAddress])
2022-09-27 23:17:06 -07:00
return mangoAccountAddress && (activityFeed.length || loadActivityFeed) ? (
<>
{showTableView ? (
<Table className="min-w-full">
2023-02-03 00:27:54 -08:00
<thead>
<TrHead>
<Th className="bg-th-bkg-1 text-left">{t('date')}</Th>
<Th className="bg-th-bkg-1 text-right">
{t('activity:activity')}
</Th>
<Th className="bg-th-bkg-1 text-right">{t('activity:credit')}</Th>
<Th className="bg-th-bkg-1 text-right">{t('activity:debit')}</Th>
2023-01-22 20:25:43 -08:00
<Th className="flex justify-end bg-th-bkg-1">
2023-03-10 10:01:47 -08:00
<Tooltip content={t('activity:tooltip-fee')} delay={100}>
2023-01-22 20:25:43 -08:00
<span className="tooltip-underline">{t('fee')}</span>
</Tooltip>
</Th>
2023-02-08 02:47:31 -08:00
<Th className="bg-th-bkg-1 text-right">{t('value')}</Th>
<Th className="bg-th-bkg-1 text-right">{t('explorer')}</Th>
</TrHead>
</thead>
<tbody>
2023-02-23 16:28:49 -08:00
{activityFeed.map((activity, index: number) => {
const { activity_type, block_datetime } = activity
const { signature } = activity.activity_details
const isOpenbook = activity_type === 'openbook_trade'
const amounts = getCreditAndDebit(activity, mangoAccountAddress)
2023-04-04 04:55:24 -07:00
const value = getValue(activity, mangoAccountAddress)
2023-02-20 12:07:16 -08:00
const fee = getFee(activity, mangoAccountAddress)
const isExpandable =
isLiquidationFeedItem(activity) || isPerpTradeFeedItem(activity)
2023-04-16 20:18:51 -07:00
return isExpandable ? (
<Disclosure key={`${signature}${index}`}>
{({ open }) => (
<>
<Disclosure.Button
as={TrBody}
2023-04-16 20:18:51 -07:00
className="default-transition cursor-pointer text-sm md:hover:bg-th-bkg-2"
>
2023-04-16 20:18:51 -07:00
<SharedTableBody
activity_type={activity_type}
amounts={amounts}
block_datetime={block_datetime}
isExpandable={true}
isOpenbook={isOpenbook}
fee={fee}
value={value}
/>
<Td>
2023-04-16 20:18:51 -07:00
<div className="flex items-center justify-end">
<ChevronDownIcon
className={`h-6 w-6 text-th-fgd-3 ${
open ? 'rotate-180' : 'rotate-360'
}`}
/>
</div>
</Td>
</Disclosure.Button>
<Disclosure.Panel as={TrBody}>
{isLiquidationFeedItem(activity) ? (
<td className="p-6" colSpan={7}>
<LiquidationDetails activity={activity} />
</td>
) : isPerpTradeFeedItem(activity) ? (
<td className="p-6" colSpan={7}>
<PerpTradeDetails activity={activity} />
</td>
) : null}
</Disclosure.Panel>
</>
)}
</Disclosure>
2023-04-16 20:18:51 -07:00
) : (
2023-05-21 20:15:58 -07:00
<TrBody key={`${signature}${index}`}>
2023-04-16 20:18:51 -07:00
<SharedTableBody
activity_type={activity_type}
amounts={amounts}
block_datetime={block_datetime}
isExpandable={false}
isOpenbook={isOpenbook}
fee={fee}
value={value}
/>
<Td>
<div className="flex items-center justify-end">
<Tooltip
content={`View on ${t(
2023-07-21 11:47:53 -07:00
`settings:${preferredExplorer.name}`,
2023-04-16 20:18:51 -07:00
)}`}
placement="top-end"
>
<a
href={`${preferredExplorer.url}${signature}`}
target="_blank"
rel="noopener noreferrer"
>
<div className="h-6 w-6">
<Image
alt=""
width="24"
height="24"
src={`/explorer-logos/${preferredExplorer.name}.png`}
/>
</div>
</a>
</Tooltip>
</div>
</Td>
</TrBody>
)
})}
</tbody>
</Table>
) : (
<div>
2023-01-11 21:06:17 -08:00
{activityFeed.map((activity: any, index: number) => (
<MobileActivityFeedItem
activity={activity}
getValue={getValue}
2023-01-11 21:06:17 -08:00
key={activity?.activity_details?.signature + index}
/>
))}
</div>
)}
{loadActivityFeed ? (
<div className="mt-4 space-y-1.5">
{[...Array(4)].map((x, i) => (
<SheenLoader className="mx-4 flex flex-1 md:mx-6" key={i}>
<div className="h-16 w-full bg-th-bkg-2" />
</SheenLoader>
))}
</div>
) : null}
2023-01-12 16:16:10 -08:00
{activityFeed.length &&
activityFeed.length % PAGINATION_PAGE_LENGTH === 0 ? (
2023-01-11 21:06:17 -08:00
<div className="flex justify-center py-6">
2023-03-19 20:19:53 -07:00
<LinkButton onClick={handleShowMore}>{t('show-more')}</LinkButton>
</div>
) : null}
</>
2023-01-19 19:10:15 -08:00
) : mangoAccountAddress || connected ? (
<div className="flex flex-col items-center p-8">
<NoSymbolIcon className="mb-2 h-6 w-6 text-th-fgd-4" />
<p>{t('activity:no-activity')}</p>
2022-09-27 23:17:06 -07:00
</div>
2023-01-19 17:45:08 -08:00
) : (
<div className="p-8">
<ConnectEmptyState text={t('activity:connect-activity')} />
</div>
2022-09-27 23:17:06 -07:00
)
}
export default ActivityFeedTable
2022-09-28 06:04:58 -07:00
2023-04-16 20:18:51 -07:00
interface SharedTableBodyProps {
block_datetime: string
activity_type: string
amounts: {
credit: { value: string; symbol: string }
debit: { value: string; symbol: string }
}
isExpandable: boolean
fee: { value: string; symbol: string }
isOpenbook: boolean
value: number
}
const SharedTableBody = ({
block_datetime,
activity_type,
amounts,
isExpandable,
fee,
isOpenbook,
value,
}: SharedTableBodyProps) => {
const { t } = useTranslation('activity')
return (
<>
<Td>
<p className="font-body">{dayjs(block_datetime).format('ddd D MMM')}</p>
<p className="text-xs text-th-fgd-3">
{dayjs(block_datetime).format('h:mma')}
</p>
</Td>
<Td className="text-right">{t(`activity:${activity_type}`)}</Td>
<Td className="text-right font-mono">
{amounts.credit.value}{' '}
<span className="font-body text-th-fgd-3">{amounts.credit.symbol}</span>
</Td>
<Td className="text-right font-mono">
{amounts.debit.value}{' '}
<span className="font-body text-th-fgd-3">{amounts.debit.symbol}</span>
</Td>
<Td className="text-right font-mono">
{fee.value}{' '}
<span className="font-body text-th-fgd-3">{fee.symbol}</span>
</Td>
<Td
className={`text-right font-mono ${
activity_type === 'swap' || isOpenbook || isExpandable
? 'text-th-fgd-2'
: value >= 0
? 'text-th-up'
: 'text-th-down'
}`}
>
{value > 0 && activity_type !== 'swap' && !isOpenbook && !isExpandable
? '+'
: ''}
<FormatNumericValue value={value} isUsd />
</Td>
</>
)
}
2022-09-28 06:04:58 -07:00
const MobileActivityFeedItem = ({
activity,
getValue,
}: {
activity: any
2023-04-04 04:55:24 -07:00
getValue: (a: any, m: string) => number
2022-09-28 06:04:58 -07:00
}) => {
const { t } = useTranslation(['common', 'activity'])
const [preferredExplorer] = useLocalStorageState(
PREFERRED_EXPLORER_KEY,
2023-07-21 11:47:53 -07:00
EXPLORERS[0],
2022-09-28 06:04:58 -07:00
)
2023-04-04 04:55:24 -07:00
const { mangoAccountAddress } = useMangoAccount()
2022-09-28 06:04:58 -07:00
const { activity_type, block_datetime } = activity
const { signature } = activity.activity_details
2022-11-29 02:33:15 -08:00
const isSwap = activity_type === 'swap'
2023-01-25 16:45:48 -08:00
const isOpenbook = activity_type === 'openbook_trade'
2022-11-29 15:15:25 -08:00
const isPerp = activity_type === 'perp_trade'
2023-04-04 04:55:24 -07:00
const value = getValue(activity, mangoAccountAddress)
const isExpandable =
isLiquidationFeedItem(activity) || isPerpTradeFeedItem(activity)
const isPerpTaker =
isPerpTradeFeedItem(activity) &&
activity.activity_details.taker === mangoAccountAddress
const perpTradeSide = isPerpTaker
? activity.activity_details.taker_side
: activity.activity_details.taker_side === 'bid'
? 'ask'
: 'bid'
2023-01-25 16:45:48 -08:00
2022-09-28 06:04:58 -07:00
return (
2023-03-23 17:51:03 -07:00
<div key={signature} className="border-b border-th-bkg-3">
{isExpandable ? (
2023-03-23 17:51:03 -07:00
<Disclosure>
{({ open }) => (
<>
<Disclosure.Button className="w-full p-4 text-left focus:outline-none">
<div className="flex items-center justify-between">
<div>
<p className="text-sm text-th-fgd-1">
{dayjs(block_datetime).format('ddd D MMM')}
</p>
<p className="text-xs text-th-fgd-3">
{dayjs(block_datetime).format('h:mma')}
</p>
</div>
<div className="flex items-center space-x-6 pr-2">
<div>
<p className="text-right text-xs">
{t(`activity:${activity_type}`)}
</p>
{isLiquidationFeedItem(activity) ? (
<p className="text-right font-mono text-sm text-th-fgd-1">
<FormatNumericValue value={value} isUsd />
</p>
) : (
<p className="font-mono text-th-fgd-1">
<span className="mr-1">
{activity.activity_details.quantity}
</span>
<span className="font-body text-th-fgd-3">
{activity.activity_details.perp_market_name}
</span>
<span className="font-body">
{' '}
<PerpSideBadge
basePosition={perpTradeSide === 'bid' ? 1 : -1}
/>
</span>
</p>
)}
2023-03-23 17:51:03 -07:00
</div>
<ChevronDownIcon
className={`${
open ? 'rotate-180' : 'rotate-360'
} h-6 w-6 flex-shrink-0 text-th-fgd-3`}
/>
</div>
</div>
</Disclosure.Button>
<Transition
enter="transition ease-in duration-200"
enterFrom="opacity-0"
enterTo="opacity-100"
>
<Disclosure.Panel>
<div className="border-t border-th-bkg-3 px-4 py-4">
{isLiquidationFeedItem(activity) ? (
<LiquidationDetails activity={activity} />
) : (
<PerpTradeDetails activity={activity} />
)}
2023-03-23 17:51:03 -07:00
</div>
</Disclosure.Panel>
</Transition>
</>
)}
</Disclosure>
) : (
<div className="flex items-center justify-between p-4">
2022-09-28 06:04:58 -07:00
<div>
2023-03-23 17:51:03 -07:00
<p className="text-sm text-th-fgd-1">
{dayjs(block_datetime).format('ddd D MMM')}
2022-09-28 06:04:58 -07:00
</p>
2023-03-23 17:51:03 -07:00
<p className="text-xs text-th-fgd-3">
{dayjs(block_datetime).format('h:mma')}
2022-09-28 06:04:58 -07:00
</p>
</div>
2023-03-23 17:51:03 -07:00
<div className="flex items-center space-x-4">
<div>
<p className="text-right text-xs">
{t(`activity:${activity_type}`)}
</p>
<p className="text-right font-mono text-sm text-th-fgd-1">
{isSwap ? (
<>
<span className="mr-1">
<FormatNumericValue
value={activity.activity_details.swap_in_amount}
decimals={6}
/>
</span>
<span className="font-body text-th-fgd-3">
{activity.activity_details.swap_in_symbol}
</span>
<span className="mx-1 font-body text-th-fgd-3">for</span>
<span className="mr-1">
<FormatNumericValue
value={activity.activity_details.swap_out_amount}
decimals={6}
/>
</span>
<span className="font-body text-th-fgd-3">
{activity.activity_details.swap_out_symbol}
</span>
</>
) : isPerp ? (
<>
<span className="mr-1">
{activity.activity_details.quantity}
</span>
<span className="font-body text-th-fgd-3">
{activity.activity_details.perp_market_name}
</span>
2023-03-26 17:34:25 -07:00
<span className="font-body">
{' '}
<PerpSideBadge
basePosition={
activity.activity_details.taker_side === 'bid'
? 1
: -1
}
/>
</span>
2023-03-23 17:51:03 -07:00
</>
) : isOpenbook ? (
<>
<span className="mr-1">
{activity.activity_details.size}
</span>
<span className="font-body text-th-fgd-3">
{activity.activity_details.base_symbol}
</span>
2023-03-26 17:34:25 -07:00
<span className="font-body">
{' '}
<SideBadge side={activity.activity_details.side} />
</span>
2023-03-23 17:51:03 -07:00
</>
) : (
<>
<span className="mr-1">
{activity.activity_details.quantity}
</span>
<span className="font-body text-th-fgd-3">
{activity.activity_details.symbol}
</span>
</>
)}
</p>
</div>
2022-09-28 06:04:58 -07:00
<a
href={`${preferredExplorer.url}${signature}`}
target="_blank"
rel="noopener noreferrer"
>
<div className="flex h-10 w-10 items-center justify-center">
<Image
alt=""
width="24"
height="24"
src={`/explorer-logos/${preferredExplorer.name}.png`}
/>
</div>
</a>
</div>
</div>
2023-03-23 17:51:03 -07:00
)}
2022-09-28 06:04:58 -07:00
</div>
)
}