2022-11-24 18:39:14 -08:00
|
|
|
import { EXPLORERS } from '@components/settings/PreferredExplorerSettings'
|
2022-09-28 06:04:58 -07:00
|
|
|
import { IconButton, LinkButton } from '@components/shared/Button'
|
2023-01-19 17:45:08 -08:00
|
|
|
import ConnectEmptyState from '@components/shared/ConnectEmptyState'
|
2022-09-28 20:35:34 -07:00
|
|
|
import SheenLoader from '@components/shared/SheenLoader'
|
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'
|
2022-09-28 06:04:58 -07:00
|
|
|
import { Transition } from '@headlessui/react'
|
|
|
|
import {
|
|
|
|
ChevronDownIcon,
|
|
|
|
ChevronRightIcon,
|
2022-12-12 14:53:04 -08:00
|
|
|
NoSymbolIcon,
|
2022-09-28 06:04:58 -07:00
|
|
|
} from '@heroicons/react/20/solid'
|
2023-01-19 17:45:08 -08:00
|
|
|
import { useWallet } from '@solana/wallet-adapter-react'
|
2022-09-28 06:04:58 -07:00
|
|
|
import mangoStore, { LiquidationFeedItem } 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'
|
2022-09-28 06:04:58 -07:00
|
|
|
import { Fragment, useCallback, useState } from 'react'
|
2023-01-12 16:16:10 -08:00
|
|
|
import { PAGINATION_PAGE_LENGTH, PREFERRED_EXPLORER_KEY } from 'utils/constants'
|
2022-09-27 23:17:06 -07:00
|
|
|
import { formatDecimal, formatFixedDecimals } from 'utils/numbers'
|
2022-09-28 06:04:58 -07:00
|
|
|
import { breakpoints } from 'utils/theme'
|
2022-09-27 23:17:06 -07:00
|
|
|
|
2023-01-10 16:20:06 -08:00
|
|
|
const formatFee = (value: number) => {
|
|
|
|
return value.toLocaleString(undefined, {
|
|
|
|
minimumSignificantDigits: 1,
|
|
|
|
maximumSignificantDigits: 1,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-09-27 23:17:06 -07:00
|
|
|
const ActivityFeedTable = ({
|
|
|
|
activityFeed,
|
|
|
|
handleShowActivityDetails,
|
2022-09-28 20:35:34 -07:00
|
|
|
params,
|
2022-09-27 23:17:06 -07:00
|
|
|
}: {
|
|
|
|
activityFeed: any
|
|
|
|
handleShowActivityDetails: (x: LiquidationFeedItem) => void
|
2022-09-29 20:22:55 -07:00
|
|
|
params: string
|
2022-09-27 23:17:06 -07:00
|
|
|
}) => {
|
|
|
|
const { t } = useTranslation(['common', 'activity'])
|
2023-01-05 20:01:03 -08:00
|
|
|
const { mangoAccountAddress } = useMangoAccount()
|
2023-01-03 14:20:00 -08:00
|
|
|
const actions = mangoStore.getState().actions
|
2022-09-28 20:35:34 -07:00
|
|
|
const loadActivityFeed = mangoStore((s) => s.activityFeed.loading)
|
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,
|
|
|
|
EXPLORERS[0]
|
|
|
|
)
|
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
|
|
|
|
})
|
2023-01-05 20:01:03 -08:00
|
|
|
if (!mangoAccountAddress) return
|
2023-01-12 16:16:10 -08:00
|
|
|
setOffset(offset + PAGINATION_PAGE_LENGTH)
|
|
|
|
actions.fetchActivityFeed(
|
|
|
|
mangoAccountAddress,
|
|
|
|
offset + PAGINATION_PAGE_LENGTH,
|
|
|
|
params
|
|
|
|
)
|
2023-01-05 20:01:03 -08:00
|
|
|
}, [actions, offset, params, mangoAccountAddress])
|
2022-09-27 23:17:06 -07:00
|
|
|
|
|
|
|
const getCreditAndDebit = (activity: any) => {
|
|
|
|
const { activity_type } = activity
|
2022-09-28 06:04:58 -07:00
|
|
|
let credit = { value: '0', symbol: '' }
|
|
|
|
let debit = { value: '0', symbol: '' }
|
2022-09-27 23:17:06 -07:00
|
|
|
if (activity_type === 'liquidate_token_with_token') {
|
|
|
|
const { side, liab_amount, liab_symbol, asset_amount, asset_symbol } =
|
|
|
|
activity.activity_details
|
|
|
|
if (side === 'liqee') {
|
2022-09-28 06:04:58 -07:00
|
|
|
credit = { value: formatDecimal(liab_amount), symbol: liab_symbol }
|
|
|
|
debit = {
|
2022-12-29 16:04:23 -08:00
|
|
|
value: formatDecimal(asset_amount),
|
2022-09-28 06:04:58 -07:00
|
|
|
symbol: asset_symbol,
|
|
|
|
}
|
2022-09-27 23:17:06 -07:00
|
|
|
} else {
|
2022-09-28 06:04:58 -07:00
|
|
|
credit = { value: formatDecimal(asset_amount), symbol: asset_symbol }
|
2022-12-29 16:04:23 -08:00
|
|
|
debit = { value: formatDecimal(liab_amount), symbol: liab_symbol }
|
2022-09-27 23:17:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (activity_type === 'deposit') {
|
|
|
|
const { symbol, quantity } = activity.activity_details
|
2022-09-28 06:04:58 -07:00
|
|
|
credit = { value: formatDecimal(quantity), symbol }
|
|
|
|
debit = { value: '0', symbol: '' }
|
2022-09-27 23:17:06 -07:00
|
|
|
}
|
|
|
|
if (activity_type === 'withdraw') {
|
|
|
|
const { symbol, quantity } = activity.activity_details
|
2022-09-28 06:04:58 -07:00
|
|
|
credit = { value: '0', symbol: '' }
|
|
|
|
debit = { value: formatDecimal(quantity * -1), symbol }
|
2022-09-27 23:17:06 -07:00
|
|
|
}
|
2022-11-29 02:33:15 -08:00
|
|
|
if (activity_type === 'swap') {
|
|
|
|
const {
|
|
|
|
swap_in_amount,
|
|
|
|
swap_in_symbol,
|
|
|
|
swap_out_amount,
|
|
|
|
swap_out_symbol,
|
|
|
|
} = activity.activity_details
|
|
|
|
credit = {
|
|
|
|
value: formatDecimal(swap_out_amount),
|
|
|
|
symbol: swap_out_symbol,
|
|
|
|
}
|
|
|
|
debit = {
|
|
|
|
value: formatDecimal(swap_in_amount * -1),
|
|
|
|
symbol: swap_in_symbol,
|
|
|
|
}
|
|
|
|
}
|
2022-11-29 15:15:25 -08:00
|
|
|
if (activity_type === 'perp_trade') {
|
2023-01-23 01:59:43 -08:00
|
|
|
const { perp_market_name, price, quantity } = activity.activity_details
|
|
|
|
credit = { value: quantity, symbol: perp_market_name }
|
2022-11-29 15:15:25 -08:00
|
|
|
debit = { value: formatDecimal(quantity * price * -1), symbol: 'USDC' }
|
|
|
|
}
|
2023-01-03 20:29:16 -08:00
|
|
|
if (activity_type === 'openbook_trade') {
|
|
|
|
const { side, price, size, base_symbol, quote_symbol } =
|
|
|
|
activity.activity_details
|
|
|
|
credit =
|
|
|
|
side === 'buy'
|
|
|
|
? { value: formatDecimal(size), symbol: base_symbol }
|
|
|
|
: { value: formatDecimal(size * price), symbol: quote_symbol }
|
|
|
|
debit =
|
|
|
|
side === 'buy'
|
|
|
|
? { value: formatDecimal(size * price * -1), symbol: quote_symbol }
|
|
|
|
: { value: formatDecimal(size * -1), symbol: base_symbol }
|
|
|
|
}
|
2022-09-27 23:17:06 -07:00
|
|
|
return { credit, debit }
|
|
|
|
}
|
|
|
|
|
|
|
|
const getValue = (activity: any) => {
|
|
|
|
const { activity_type } = activity
|
|
|
|
let value = 0
|
|
|
|
if (activity_type === 'liquidate_token_with_token') {
|
|
|
|
const { side, liab_amount, liab_price, asset_amount, asset_price } =
|
|
|
|
activity.activity_details
|
|
|
|
if (side === 'liqee') {
|
2022-12-29 16:04:23 -08:00
|
|
|
value = asset_amount * asset_price
|
2022-09-27 23:17:06 -07:00
|
|
|
} else {
|
2022-12-29 16:04:23 -08:00
|
|
|
value = liab_amount * liab_price
|
2022-09-27 23:17:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (activity_type === 'deposit' || activity_type === 'withdraw') {
|
|
|
|
const { usd_equivalent } = activity.activity_details
|
2022-09-28 06:04:58 -07:00
|
|
|
value =
|
|
|
|
activity_type === 'withdraw' ? usd_equivalent * -1 : usd_equivalent
|
2022-09-27 23:17:06 -07:00
|
|
|
}
|
2022-11-29 02:33:15 -08:00
|
|
|
if (activity_type === 'swap') {
|
2022-12-20 02:01:49 -08:00
|
|
|
const { swap_out_amount, swap_out_price_usd } = activity.activity_details
|
|
|
|
value = swap_out_amount * swap_out_price_usd
|
2022-11-29 02:33:15 -08:00
|
|
|
}
|
2022-11-29 15:15:25 -08:00
|
|
|
if (activity_type === 'perp_trade') {
|
|
|
|
const { maker_fee, price, quantity, taker_fee } =
|
|
|
|
activity.activity_details
|
2022-12-27 01:57:23 -08:00
|
|
|
value = quantity * price + maker_fee + taker_fee
|
2022-11-29 15:15:25 -08:00
|
|
|
}
|
2023-01-03 20:29:16 -08:00
|
|
|
if (activity_type === 'openbook_trade') {
|
|
|
|
const { price, size } = activity.activity_details
|
|
|
|
value = price * size
|
|
|
|
}
|
2022-09-27 23:17:06 -07:00
|
|
|
return value
|
|
|
|
}
|
|
|
|
|
2023-01-09 18:02:51 -08:00
|
|
|
const getFee = (activity: any) => {
|
|
|
|
const { activity_type } = activity
|
2023-01-23 01:59:43 -08:00
|
|
|
let fee = { value: '0', symbol: '' }
|
2023-01-09 18:02:51 -08:00
|
|
|
if (activity_type === 'swap') {
|
|
|
|
const { loan_origination_fee, swap_in_symbol } = activity.activity_details
|
|
|
|
fee = loan_origination_fee
|
2023-01-23 01:59:43 -08:00
|
|
|
? { value: formatFee(loan_origination_fee), symbol: swap_in_symbol }
|
|
|
|
: { value: '0', symbol: '' }
|
2023-01-09 18:02:51 -08:00
|
|
|
}
|
|
|
|
if (activity_type === 'perp_trade') {
|
|
|
|
const { maker_fee, taker_fee } = activity.activity_details
|
2023-01-23 01:59:43 -08:00
|
|
|
fee = { value: formatFee(maker_fee + taker_fee), symbol: 'USDC' }
|
2023-01-09 18:02:51 -08:00
|
|
|
}
|
|
|
|
if (activity_type === 'openbook_trade') {
|
|
|
|
const { fee_cost, quote_symbol } = activity.activity_details
|
2023-01-23 01:59:43 -08:00
|
|
|
fee = { value: formatFee(fee_cost), symbol: quote_symbol }
|
2023-01-09 18:02:51 -08:00
|
|
|
}
|
|
|
|
return fee
|
|
|
|
}
|
|
|
|
|
2023-01-05 20:01:03 -08:00
|
|
|
return mangoAccountAddress && (activityFeed.length || loadActivityFeed) ? (
|
2023-01-03 18:11:29 -08:00
|
|
|
<>
|
|
|
|
{showTableView ? (
|
|
|
|
<Table className="min-w-full">
|
|
|
|
<thead className="sticky top-0 z-10">
|
|
|
|
<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">
|
|
|
|
<Tooltip content={t('activity:tooltip-fee')} delay={250}>
|
|
|
|
<span className="tooltip-underline">{t('fee')}</span>
|
|
|
|
</Tooltip>
|
|
|
|
</Th>
|
2023-01-03 18:11:29 -08:00
|
|
|
<Th className="bg-th-bkg-1 text-right">
|
|
|
|
{t('activity:activity-value')}
|
|
|
|
</Th>
|
|
|
|
<Th className="bg-th-bkg-1 text-right">{t('explorer')}</Th>
|
|
|
|
</TrHead>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2023-01-11 21:06:17 -08:00
|
|
|
{activityFeed.map((activity: any, index: number) => {
|
2023-01-03 18:11:29 -08:00
|
|
|
const { activity_type, block_datetime } = activity
|
|
|
|
const { signature } = activity.activity_details
|
|
|
|
const isLiquidation =
|
|
|
|
activity_type === 'liquidate_token_with_token'
|
2023-01-03 20:29:16 -08:00
|
|
|
const isOpenbook = activity_type === 'openbook_trade'
|
2023-01-03 18:11:29 -08:00
|
|
|
const amounts = getCreditAndDebit(activity)
|
|
|
|
const value = getValue(activity)
|
2023-01-09 18:02:51 -08:00
|
|
|
const fee = getFee(activity)
|
2023-01-03 18:11:29 -08:00
|
|
|
return (
|
|
|
|
<TrBody
|
2023-01-11 21:06:17 -08:00
|
|
|
key={signature + index}
|
2023-01-03 18:11:29 -08:00
|
|
|
className={`default-transition text-sm hover:bg-th-bkg-2 ${
|
|
|
|
isLiquidation ? 'cursor-pointer' : ''
|
|
|
|
}`}
|
|
|
|
onClick={
|
|
|
|
isLiquidation
|
|
|
|
? () => handleShowActivityDetails(activity)
|
|
|
|
: undefined
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Td>
|
2023-01-14 04:41:30 -08:00
|
|
|
<p className="font-body">
|
2023-01-03 18:11:29 -08:00
|
|
|
{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">
|
2023-01-04 04:10:36 -08:00
|
|
|
{t(`activity:${activity_type}`)}
|
2023-01-03 18:11:29 -08:00
|
|
|
</Td>
|
|
|
|
<Td className="text-right font-mono">
|
|
|
|
{amounts.credit.value}{' '}
|
2023-01-05 18:03:58 -08:00
|
|
|
<span className="font-body text-th-fgd-3">
|
2023-01-03 18:11:29 -08:00
|
|
|
{amounts.credit.symbol}
|
|
|
|
</span>
|
|
|
|
</Td>
|
|
|
|
<Td className="text-right font-mono">
|
|
|
|
{amounts.debit.value}{' '}
|
2023-01-05 18:03:58 -08:00
|
|
|
<span className="font-body text-th-fgd-3">
|
2023-01-03 18:11:29 -08:00
|
|
|
{amounts.debit.symbol}
|
|
|
|
</span>
|
|
|
|
</Td>
|
2023-01-23 01:59:43 -08:00
|
|
|
<Td className="text-right font-mono">
|
|
|
|
{fee.value}{' '}
|
|
|
|
<span className="font-body text-th-fgd-3">
|
|
|
|
{fee.symbol}
|
|
|
|
</span>
|
|
|
|
</Td>
|
2023-01-03 18:11:29 -08:00
|
|
|
<Td
|
|
|
|
className={`text-right font-mono ${
|
2023-01-04 04:10:36 -08:00
|
|
|
activity_type === 'swap' ||
|
|
|
|
activity_type === 'perp_trade' ||
|
2023-01-03 20:29:16 -08:00
|
|
|
isOpenbook
|
2023-01-03 18:11:29 -08:00
|
|
|
? 'text-th-fgd-2'
|
|
|
|
: value >= 0
|
|
|
|
? 'text-th-up'
|
|
|
|
: 'text-th-down'
|
2022-09-28 06:04:58 -07:00
|
|
|
}`}
|
|
|
|
>
|
2023-01-03 18:11:29 -08:00
|
|
|
{value > 0 &&
|
2023-01-04 04:10:36 -08:00
|
|
|
activity_type !== 'swap' &&
|
|
|
|
activity_type !== 'perp_trade' &&
|
2023-01-03 20:29:16 -08:00
|
|
|
!isOpenbook
|
2023-01-03 18:11:29 -08:00
|
|
|
? '+'
|
|
|
|
: ''}
|
|
|
|
{formatFixedDecimals(value, true)}
|
|
|
|
</Td>
|
|
|
|
<Td>
|
|
|
|
{activity_type !== 'liquidate_token_with_token' ? (
|
|
|
|
<div className="flex items-center justify-end">
|
|
|
|
<Tooltip
|
|
|
|
content={`View on ${t(
|
|
|
|
`settings:${preferredExplorer.name}`
|
|
|
|
)}`}
|
|
|
|
placement="top-end"
|
|
|
|
>
|
|
|
|
<a
|
|
|
|
href={`${preferredExplorer.url}${signature}`}
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
2022-09-27 23:17:06 -07:00
|
|
|
>
|
2023-01-03 18:11:29 -08:00
|
|
|
<div className="h-6 w-6">
|
|
|
|
<Image
|
|
|
|
alt=""
|
|
|
|
width="24"
|
|
|
|
height="24"
|
|
|
|
src={`/explorer-logos/${preferredExplorer.name}.png`}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</Tooltip>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="flex items-center justify-end">
|
|
|
|
<ChevronRightIcon className="h-6 w-6 text-th-fgd-3" />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Td>
|
|
|
|
</TrBody>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</tbody>
|
|
|
|
</Table>
|
|
|
|
) : (
|
|
|
|
<div>
|
2023-01-11 21:06:17 -08:00
|
|
|
{activityFeed.map((activity: any, index: number) => (
|
2023-01-03 18:11:29 -08:00
|
|
|
<MobileActivityFeedItem
|
|
|
|
activity={activity}
|
|
|
|
getValue={getValue}
|
2023-01-11 21:06:17 -08:00
|
|
|
key={activity?.activity_details?.signature + index}
|
2023-01-03 18:11:29 -08:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</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-01-03 18:11:29 -08:00
|
|
|
<LinkButton onClick={handleShowMore}>Show More</LinkButton>
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</>
|
2023-01-19 19:10:15 -08:00
|
|
|
) : mangoAccountAddress || connected ? (
|
2023-01-03 18:11:29 -08:00
|
|
|
<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
|
|
|
|
|
|
|
const MobileActivityFeedItem = ({
|
|
|
|
activity,
|
|
|
|
getValue,
|
|
|
|
}: {
|
|
|
|
activity: any
|
|
|
|
getValue: (x: any) => number
|
|
|
|
}) => {
|
|
|
|
const { t } = useTranslation(['common', 'activity'])
|
|
|
|
const [expandActivityDetails, setExpandActivityDetails] = useState(false)
|
|
|
|
const [preferredExplorer] = useLocalStorageState(
|
|
|
|
PREFERRED_EXPLORER_KEY,
|
|
|
|
EXPLORERS[0]
|
|
|
|
)
|
|
|
|
const { activity_type, block_datetime } = activity
|
|
|
|
const { signature } = activity.activity_details
|
|
|
|
const isLiquidation = activity_type === 'liquidate_token_with_token'
|
2022-11-29 02:33:15 -08:00
|
|
|
const isSwap = activity_type === 'swap'
|
2022-11-29 15:15:25 -08:00
|
|
|
const isPerp = activity_type === 'perp_trade'
|
2022-09-28 06:04:58 -07:00
|
|
|
const value = getValue(activity)
|
|
|
|
return (
|
2022-11-29 02:33:15 -08:00
|
|
|
<div key={signature} className="border-b border-th-bkg-3 p-4">
|
2022-09-28 06:04:58 -07:00
|
|
|
<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-4">
|
|
|
|
<div>
|
|
|
|
<p className="text-right text-xs">
|
2023-01-04 04:10:36 -08:00
|
|
|
{t(`activity:${activity_type}`)}
|
2022-09-28 06:04:58 -07:00
|
|
|
</p>
|
|
|
|
<p className="text-right font-mono text-sm text-th-fgd-1">
|
|
|
|
{isLiquidation ? (
|
|
|
|
formatFixedDecimals(value, true)
|
2022-11-29 02:33:15 -08:00
|
|
|
) : isSwap ? (
|
|
|
|
<>
|
|
|
|
<span className="mr-1">
|
|
|
|
{activity.activity_details.swap_in_amount.toLocaleString(
|
|
|
|
undefined,
|
|
|
|
{ maximumFractionDigits: 6 }
|
|
|
|
)}
|
|
|
|
</span>
|
2023-01-05 18:03:58 -08:00
|
|
|
<span className="font-body text-th-fgd-3">
|
2022-11-29 02:33:15 -08:00
|
|
|
{activity.activity_details.swap_in_symbol}
|
|
|
|
</span>
|
|
|
|
<span className="mx-1 font-body text-th-fgd-3">for</span>
|
|
|
|
<span className="mr-1">
|
|
|
|
{activity.activity_details.swap_out_amount.toLocaleString(
|
|
|
|
undefined,
|
|
|
|
{ maximumFractionDigits: 6 }
|
|
|
|
)}
|
|
|
|
</span>
|
2023-01-05 18:03:58 -08:00
|
|
|
<span className="font-body text-th-fgd-3">
|
2022-11-29 02:33:15 -08:00
|
|
|
{activity.activity_details.swap_out_symbol}
|
|
|
|
</span>
|
|
|
|
</>
|
2022-11-29 15:15:25 -08:00
|
|
|
) : isPerp ? (
|
|
|
|
<>
|
|
|
|
<span
|
|
|
|
className={`mr-1 font-body ${
|
|
|
|
activity.activity_details.taker_side === 'bid'
|
2022-11-30 19:32:32 -08:00
|
|
|
? 'text-th-up'
|
|
|
|
: 'text-th-down'
|
2022-11-29 15:15:25 -08:00
|
|
|
}`}
|
|
|
|
>
|
|
|
|
{activity.activity_details.taker_side === 'bid'
|
|
|
|
? 'BUY'
|
|
|
|
: 'SELL'}
|
|
|
|
</span>
|
|
|
|
<span className="mr-1">
|
|
|
|
{activity.activity_details.quantity}
|
|
|
|
</span>
|
|
|
|
<span className="font-body text-th-fgd-3">
|
|
|
|
{activity.activity_details.perp_market}
|
|
|
|
</span>
|
|
|
|
</>
|
2022-09-28 06:04:58 -07:00
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<span className="mr-1">
|
|
|
|
{activity.activity_details.quantity}
|
|
|
|
</span>
|
2023-01-05 18:03:58 -08:00
|
|
|
<span className="font-body text-th-fgd-3">
|
2022-09-28 06:04:58 -07:00
|
|
|
{activity.activity_details.symbol}
|
|
|
|
</span>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
{isLiquidation ? (
|
|
|
|
<IconButton
|
|
|
|
onClick={() => setExpandActivityDetails((prev) => !prev)}
|
|
|
|
>
|
|
|
|
<ChevronDownIcon
|
|
|
|
className={`${
|
|
|
|
expandActivityDetails ? 'rotate-180' : 'rotate-360'
|
|
|
|
} h-6 w-6 flex-shrink-0 text-th-fgd-1`}
|
|
|
|
/>
|
|
|
|
</IconButton>
|
|
|
|
) : (
|
|
|
|
<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>
|
|
|
|
<Transition
|
|
|
|
appear={true}
|
|
|
|
show={expandActivityDetails}
|
|
|
|
as={Fragment}
|
|
|
|
enter="transition ease-in duration-200"
|
|
|
|
enterFrom="opacity-0"
|
|
|
|
enterTo="opacity-100"
|
|
|
|
leave="transition ease-out"
|
|
|
|
leaveFrom="opacity-100"
|
|
|
|
leaveTo="opacity-0"
|
|
|
|
>
|
|
|
|
<div className="mt-4 grid grid-cols-2 gap-4 border-t border-th-bkg-3 pt-4">
|
|
|
|
<div className="col-span-1">
|
|
|
|
<p className="mb-0.5 text-sm">{t('activity:asset-liquidated')}</p>
|
|
|
|
<p className="font-mono text-sm text-th-fgd-1">
|
|
|
|
{formatDecimal(activity.activity_details.asset_amount)}{' '}
|
2023-01-14 04:41:30 -08:00
|
|
|
<span className="font-body">
|
2022-09-28 06:04:58 -07:00
|
|
|
{activity.activity_details.asset_symbol}
|
|
|
|
</span>
|
2023-01-05 18:03:58 -08:00
|
|
|
<span className="ml-2 font-body text-th-fgd-3">at</span>{' '}
|
2022-09-28 06:04:58 -07:00
|
|
|
{formatFixedDecimals(activity.activity_details.asset_price, true)}
|
|
|
|
</p>
|
|
|
|
<p className="font-mono text-xs text-th-fgd-3">
|
|
|
|
{formatFixedDecimals(
|
|
|
|
activity.activity_details.asset_price *
|
|
|
|
activity.activity_details.asset_amount,
|
|
|
|
true
|
|
|
|
)}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div className="col-span-1">
|
|
|
|
<p className="mb-0.5 text-sm">{t('activity:asset-returned')}</p>
|
|
|
|
<p className="font-mono text-sm text-th-fgd-1">
|
|
|
|
{formatDecimal(activity.activity_details.liab_amount)}{' '}
|
2023-01-14 04:41:30 -08:00
|
|
|
<span className="font-body">
|
2022-09-28 06:04:58 -07:00
|
|
|
{activity.activity_details.liab_symbol}
|
|
|
|
</span>
|
2023-01-05 18:03:58 -08:00
|
|
|
<span className="ml-2 font-body text-th-fgd-3">at</span>{' '}
|
2022-09-28 06:04:58 -07:00
|
|
|
{formatFixedDecimals(activity.activity_details.liab_price, true)}
|
|
|
|
</p>
|
|
|
|
<p className="font-mono text-xs text-th-fgd-3">
|
|
|
|
{formatFixedDecimals(
|
|
|
|
activity.activity_details.liab_price *
|
|
|
|
activity.activity_details.liab_amount,
|
|
|
|
true
|
|
|
|
)}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div className="col-span-2 flex justify-center pt-3">
|
|
|
|
<a
|
|
|
|
className="default-transition flex items-center text-sm text-th-fgd-1 hover:text-th-fgd-3"
|
|
|
|
href={`${preferredExplorer.url}${signature}`}
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
<Image
|
|
|
|
alt=""
|
|
|
|
width="20"
|
|
|
|
height="20"
|
|
|
|
src={`/explorer-logos/${preferredExplorer.name}.png`}
|
|
|
|
/>
|
2022-12-29 16:31:13 -08:00
|
|
|
<span className="ml-2 text-base">{t('view-transaction')}</span>
|
2022-09-28 06:04:58 -07:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Transition>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|