import { IconButton, LinkButton } from '@components/shared/Button' import Tooltip from '@components/shared/Tooltip' import { Transition } from '@headlessui/react' import { BoltIcon, ChevronDownIcon, ChevronRightIcon, LinkIcon, } from '@heroicons/react/20/solid' import { useWallet } from '@solana/wallet-adapter-react' import mangoStore, { LiquidationFeedItem } from '@store/mangoStore' import dayjs from 'dayjs' import useLocalStorageState from 'hooks/useLocalStorageState' import { useViewport } from 'hooks/useViewport' import { useTranslation } from 'next-i18next' import Image from 'next/image' import { EXPLORERS } from 'pages/settings' import { Fragment, useCallback, useState } from 'react' import { PREFERRED_EXPLORER_KEY } from 'utils/constants' import { formatDecimal, formatFixedDecimals } from 'utils/numbers' import { breakpoints } from 'utils/theme' const ActivityFeedTable = ({ activityFeed, handleShowActivityDetails, }: { activityFeed: any handleShowActivityDetails: (x: LiquidationFeedItem) => void }) => { const { t } = useTranslation(['common', 'activity']) const { connected } = useWallet() const actions = mangoStore((s) => s.actions) const [offset, setOffset] = useState(0) const [preferredExplorer] = useLocalStorageState( PREFERRED_EXPLORER_KEY, EXPLORERS[0] ) const { width } = useViewport() const showTableView = width ? width > breakpoints.md : false const handleShowMore = useCallback(() => { const mangoAccount = mangoStore.getState().mangoAccount.current if (!mangoAccount) return setOffset(offset + 25) actions.fetchActivityFeed(mangoAccount.publicKey.toString(), offset + 25) }, [actions, offset]) const getCreditAndDebit = (activity: any) => { 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: formatDecimal(liab_amount), symbol: liab_symbol } debit = { value: formatDecimal(asset_amount * -1), symbol: asset_symbol, } } else { credit = { value: formatDecimal(asset_amount), symbol: asset_symbol } debit = { value: formatDecimal(liab_amount * -1), symbol: liab_symbol } } } if (activity_type === 'deposit') { const { symbol, quantity } = activity.activity_details credit = { value: formatDecimal(quantity), symbol } debit = { value: '0', symbol: '' } } if (activity_type === 'withdraw') { const { symbol, quantity } = activity.activity_details credit = { value: '0', symbol: '' } debit = { value: formatDecimal(quantity * -1), symbol } } 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') { value = asset_amount * asset_price - liab_amount * liab_price } else { value = liab_amount * liab_price - asset_amount * asset_price } } if (activity_type === 'deposit' || activity_type === 'withdraw') { const { usd_equivalent } = activity.activity_details value = activity_type === 'withdraw' ? usd_equivalent * -1 : usd_equivalent } return value } return connected ? ( activityFeed.length ? ( <> {showTableView ? (
{t('date')} | {t('activity:activity')} | {t('activity:credit')} | {t('activity:debit')} | {t('activity:activity-value')} | {t('explorer')} |
---|---|---|---|---|---|
{dayjs(block_datetime).format('ddd D MMM')} {dayjs(block_datetime).format('h:mma')} |
{t(`activity:${activityName}`)} | {amounts.credit.value}{' '} {amounts.credit.symbol} | {amounts.debit.value}{' '} {amounts.debit.symbol} | {formatFixedDecimals(value, true)} |
{activity_type !== 'liquidate_token_with_token' ? (
) : (
|
No account activity found...
Connect to view your account activity
{dayjs(block_datetime).format('ddd D MMM')}
{dayjs(block_datetime).format('h:mma')}
{t('activity:asset-liquidated')}
{formatDecimal(activity.activity_details.asset_amount)}{' '} {activity.activity_details.asset_symbol} at {' '} {formatFixedDecimals(activity.activity_details.asset_price, true)}
{formatFixedDecimals( activity.activity_details.asset_price * activity.activity_details.asset_amount, true )}
{t('activity:asset-returned')}
{formatDecimal(activity.activity_details.liab_amount)}{' '} {activity.activity_details.liab_symbol} at {' '} {formatFixedDecimals(activity.activity_details.liab_price, true)}
{formatFixedDecimals( activity.activity_details.liab_price * activity.activity_details.liab_amount, true )}