2022-09-28 20:35:34 -07:00
|
|
|
import Checkbox from '@components/forms/Checkbox'
|
2022-09-29 20:22:55 -07:00
|
|
|
import MangoDateRangePicker from '@components/forms/DateRangePicker'
|
|
|
|
import Input from '@components/forms/Input'
|
|
|
|
import Label from '@components/forms/Label'
|
|
|
|
import MultiSelectDropdown from '@components/forms/MultiSelectDropdown'
|
2022-09-28 20:35:34 -07:00
|
|
|
import Button, { IconButton, LinkButton } from '@components/shared/Button'
|
2022-09-29 20:22:55 -07:00
|
|
|
import Modal from '@components/shared/Modal'
|
|
|
|
import Tooltip from '@components/shared/Tooltip'
|
2022-10-01 05:36:39 -07:00
|
|
|
import { Disclosure, Transition } from '@headlessui/react'
|
|
|
|
import {
|
|
|
|
ArrowLeftIcon,
|
|
|
|
ArrowPathIcon,
|
|
|
|
ChevronDownIcon,
|
|
|
|
} from '@heroicons/react/20/solid'
|
2022-09-29 20:22:55 -07:00
|
|
|
import { useWallet } from '@solana/wallet-adapter-react'
|
2022-09-28 06:04:58 -07:00
|
|
|
import mangoStore, { LiquidationFeedItem } from '@store/mangoStore'
|
2022-09-26 23:22:51 -07:00
|
|
|
import dayjs from 'dayjs'
|
2022-09-27 23:17:06 -07:00
|
|
|
import useLocalStorageState from 'hooks/useLocalStorageState'
|
2022-10-01 05:36:39 -07:00
|
|
|
import { useViewport } from 'hooks/useViewport'
|
2022-09-26 23:22:51 -07:00
|
|
|
import { useTranslation } from 'next-i18next'
|
2022-10-28 14:46:38 -07:00
|
|
|
import Image from 'next/legacy/image'
|
2022-09-27 23:17:06 -07:00
|
|
|
import { EXPLORERS } from 'pages/settings'
|
2022-09-29 20:22:55 -07:00
|
|
|
import { ChangeEvent, useCallback, useEffect, useMemo, useState } from 'react'
|
2022-09-27 23:17:06 -07:00
|
|
|
import { PREFERRED_EXPLORER_KEY } from 'utils/constants'
|
|
|
|
import { formatDecimal, formatFixedDecimals } from 'utils/numbers'
|
2022-10-01 05:36:39 -07:00
|
|
|
import { breakpoints } from 'utils/theme'
|
2022-09-27 23:17:06 -07:00
|
|
|
import ActivityFeedTable from './ActivityFeedTable'
|
2022-09-26 23:22:51 -07:00
|
|
|
|
2022-10-01 05:36:39 -07:00
|
|
|
interface Filters {
|
|
|
|
deposit: boolean
|
|
|
|
liquidate_token_with_token: boolean
|
|
|
|
withdraw: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
interface AdvancedFilters {
|
|
|
|
symbol: string[]
|
|
|
|
'start-date': string
|
|
|
|
'end-date': string
|
|
|
|
'usd-lower': string
|
|
|
|
'usd-upper': string
|
|
|
|
}
|
|
|
|
|
2022-09-28 20:35:34 -07:00
|
|
|
const DEFAULT_FILTERS = {
|
|
|
|
deposit: true,
|
|
|
|
liquidate_token_with_token: true,
|
|
|
|
withdraw: true,
|
|
|
|
}
|
|
|
|
|
2022-09-29 20:22:55 -07:00
|
|
|
const DEFAULT_ADVANCED_FILTERS = {
|
|
|
|
symbol: [],
|
|
|
|
'start-date': '',
|
|
|
|
'end-date': '',
|
|
|
|
'usd-lower': '',
|
|
|
|
'usd-upper': '',
|
|
|
|
}
|
|
|
|
|
2022-09-28 20:35:34 -07:00
|
|
|
const DEFAULT_PARAMS = ['deposit', 'liquidate_token_with_token', 'withdraw']
|
|
|
|
|
2022-09-26 23:22:51 -07:00
|
|
|
const ActivityFeed = () => {
|
|
|
|
const activityFeed = mangoStore((s) => s.activityFeed.feed)
|
2022-10-28 05:23:28 -07:00
|
|
|
const initialLoad = mangoStore((s) => s.activityFeed.initialLoad)
|
|
|
|
const actions = mangoStore((s) => s.actions)
|
|
|
|
const mangoAccount = mangoStore((s) => s.mangoAccount.current)
|
2022-09-27 23:17:06 -07:00
|
|
|
const [showActivityDetail, setShowActivityDetail] = useState(null)
|
2022-10-01 05:36:39 -07:00
|
|
|
const [filters, setFilters] = useState<Filters>(DEFAULT_FILTERS)
|
|
|
|
const [advancedFilters, setAdvancedFilters] = useState<AdvancedFilters>(
|
2022-09-29 20:22:55 -07:00
|
|
|
DEFAULT_ADVANCED_FILTERS
|
|
|
|
)
|
2022-09-28 20:35:34 -07:00
|
|
|
const [params, setParams] = useState<string[]>(DEFAULT_PARAMS)
|
2022-09-26 23:22:51 -07:00
|
|
|
|
2022-10-28 05:23:28 -07:00
|
|
|
useEffect(() => {
|
|
|
|
if (mangoAccount && !initialLoad) {
|
|
|
|
const pubKey = mangoAccount.publicKey.toString()
|
|
|
|
actions.fetchActivityFeed(pubKey)
|
|
|
|
}
|
|
|
|
}, [actions, initialLoad, mangoAccount])
|
|
|
|
|
2022-09-27 23:17:06 -07:00
|
|
|
const handleShowActivityDetails = (activity: any) => {
|
|
|
|
setShowActivityDetail(activity)
|
|
|
|
}
|
2022-09-26 23:22:51 -07:00
|
|
|
|
2022-09-28 20:35:34 -07:00
|
|
|
const updateFilters = (e: ChangeEvent<HTMLInputElement>, filter: string) => {
|
|
|
|
setFilters({ ...filters, [filter]: e.target.checked })
|
|
|
|
|
|
|
|
let newParams: string[] = DEFAULT_PARAMS
|
|
|
|
|
|
|
|
if (params.includes(filter)) {
|
|
|
|
newParams = params.filter((p) => p !== filter)
|
|
|
|
} else {
|
|
|
|
newParams = [...params, filter]
|
|
|
|
}
|
|
|
|
setParams(newParams)
|
|
|
|
}
|
|
|
|
|
2022-09-29 20:22:55 -07:00
|
|
|
const advancedParamsString = useMemo(() => {
|
2022-10-02 04:21:09 -07:00
|
|
|
let advancedParams: string = ''
|
2022-09-29 20:22:55 -07:00
|
|
|
Object.entries(advancedFilters).map((entry) => {
|
|
|
|
if (entry[1].length) {
|
2022-10-02 04:21:09 -07:00
|
|
|
advancedParams = advancedParams + `&${entry[0]}=${entry[1]}`
|
2022-09-29 20:22:55 -07:00
|
|
|
}
|
|
|
|
})
|
2022-10-02 04:21:09 -07:00
|
|
|
return advancedParams
|
2022-09-29 20:22:55 -07:00
|
|
|
}, [advancedFilters])
|
|
|
|
|
|
|
|
const queryParams = useMemo(() => {
|
|
|
|
return params.length === 3
|
|
|
|
? advancedParamsString
|
2022-10-02 04:21:09 -07:00
|
|
|
: `&activity-type=${params.toString()}${advancedParamsString}`
|
2022-09-29 20:22:55 -07:00
|
|
|
}, [advancedParamsString, params])
|
|
|
|
|
2022-09-27 23:17:06 -07:00
|
|
|
return !showActivityDetail ? (
|
2022-09-28 20:35:34 -07:00
|
|
|
<>
|
|
|
|
<ActivityFilters
|
|
|
|
filters={filters}
|
2022-10-02 04:21:09 -07:00
|
|
|
setFilters={setFilters}
|
2022-09-28 20:35:34 -07:00
|
|
|
updateFilters={updateFilters}
|
2022-09-29 20:22:55 -07:00
|
|
|
params={queryParams}
|
|
|
|
advancedFilters={advancedFilters}
|
|
|
|
setAdvancedFilters={setAdvancedFilters}
|
2022-09-28 20:35:34 -07:00
|
|
|
/>
|
|
|
|
<ActivityFeedTable
|
|
|
|
activityFeed={activityFeed}
|
|
|
|
handleShowActivityDetails={handleShowActivityDetails}
|
2022-09-29 20:22:55 -07:00
|
|
|
params={queryParams}
|
2022-09-28 20:35:34 -07:00
|
|
|
/>
|
|
|
|
</>
|
2022-09-27 23:17:06 -07:00
|
|
|
) : (
|
|
|
|
<ActivityDetails
|
|
|
|
activity={showActivityDetail}
|
|
|
|
setShowActivityDetail={setShowActivityDetail}
|
|
|
|
/>
|
2022-09-26 23:22:51 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ActivityFeed
|
2022-09-27 23:17:06 -07:00
|
|
|
|
2022-09-28 20:35:34 -07:00
|
|
|
const ActivityFilters = ({
|
|
|
|
filters,
|
2022-10-02 04:21:09 -07:00
|
|
|
setFilters,
|
2022-09-28 20:35:34 -07:00
|
|
|
updateFilters,
|
|
|
|
params,
|
2022-09-29 20:22:55 -07:00
|
|
|
advancedFilters,
|
|
|
|
setAdvancedFilters,
|
2022-09-28 20:35:34 -07:00
|
|
|
}: {
|
2022-10-01 05:36:39 -07:00
|
|
|
filters: Filters
|
2022-10-02 04:21:09 -07:00
|
|
|
setFilters: (x: Filters) => void
|
2022-10-01 05:36:39 -07:00
|
|
|
updateFilters: (e: ChangeEvent<HTMLInputElement>, filter: string) => void
|
2022-09-29 20:22:55 -07:00
|
|
|
params: string
|
2022-10-01 05:36:39 -07:00
|
|
|
advancedFilters: AdvancedFilters
|
|
|
|
setAdvancedFilters: (x: AdvancedFilters) => void
|
2022-09-28 20:35:34 -07:00
|
|
|
}) => {
|
2022-09-29 20:22:55 -07:00
|
|
|
const { t } = useTranslation(['common', 'activity'])
|
2022-09-28 20:35:34 -07:00
|
|
|
const actions = mangoStore((s) => s.actions)
|
2022-09-29 20:22:55 -07:00
|
|
|
const loadActivityFeed = mangoStore((s) => s.activityFeed.loading)
|
2022-10-27 13:58:54 -07:00
|
|
|
const mangoAccount = mangoStore((s) => s.mangoAccount.current)
|
2022-09-29 20:22:55 -07:00
|
|
|
const [showAdvancedFiltersModal, setShowAdvancedFiltersModal] =
|
|
|
|
useState(false)
|
2022-10-01 05:36:39 -07:00
|
|
|
const { width } = useViewport()
|
|
|
|
const isMobile = width ? width < breakpoints.lg : false
|
2022-10-02 04:21:09 -07:00
|
|
|
const [showMobileFilters, setShowMobileFilters] = useState(false)
|
|
|
|
const [hasFilters, setHasFilters] = useState(false)
|
2022-09-28 20:35:34 -07:00
|
|
|
|
|
|
|
const handleUpdateResults = useCallback(() => {
|
|
|
|
const mangoAccount = mangoStore.getState().mangoAccount.current
|
|
|
|
const set = mangoStore.getState().set
|
2022-10-02 16:47:21 -07:00
|
|
|
if (params) {
|
|
|
|
setHasFilters(true)
|
|
|
|
} else {
|
|
|
|
setHasFilters(false)
|
|
|
|
}
|
2022-09-28 20:35:34 -07:00
|
|
|
set((s) => {
|
|
|
|
s.activityFeed.feed = []
|
|
|
|
s.activityFeed.loading = true
|
|
|
|
})
|
|
|
|
if (mangoAccount) {
|
2022-09-29 20:22:55 -07:00
|
|
|
actions.fetchActivityFeed(mangoAccount.publicKey.toString(), 0, params)
|
2022-09-28 20:35:34 -07:00
|
|
|
}
|
2022-09-29 20:22:55 -07:00
|
|
|
}, [actions, params])
|
2022-09-28 20:35:34 -07:00
|
|
|
|
2022-10-02 04:21:09 -07:00
|
|
|
const handleResetFilters = useCallback(async () => {
|
2022-09-29 20:22:55 -07:00
|
|
|
const mangoAccount = mangoStore.getState().mangoAccount.current
|
|
|
|
const set = mangoStore.getState().set
|
2022-10-02 04:21:09 -07:00
|
|
|
setHasFilters(false)
|
2022-09-29 20:22:55 -07:00
|
|
|
set((s) => {
|
|
|
|
s.activityFeed.feed = []
|
|
|
|
s.activityFeed.loading = true
|
|
|
|
})
|
|
|
|
if (mangoAccount) {
|
|
|
|
await actions.fetchActivityFeed(mangoAccount.publicKey.toString())
|
|
|
|
setAdvancedFilters(DEFAULT_ADVANCED_FILTERS)
|
2022-10-02 04:21:09 -07:00
|
|
|
setFilters(DEFAULT_FILTERS)
|
2022-09-29 20:22:55 -07:00
|
|
|
}
|
|
|
|
}, [actions])
|
|
|
|
|
2022-10-02 04:21:09 -07:00
|
|
|
const handleUpdateModalResults = () => {
|
2022-10-01 05:36:39 -07:00
|
|
|
handleUpdateResults()
|
|
|
|
setShowAdvancedFiltersModal(false)
|
2022-10-02 04:21:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const handleUpdateMobileResults = () => {
|
|
|
|
handleUpdateResults()
|
|
|
|
setShowMobileFilters(false)
|
2022-10-01 05:36:39 -07:00
|
|
|
}
|
|
|
|
|
2022-10-27 13:58:54 -07:00
|
|
|
return mangoAccount ? (
|
2022-10-01 05:36:39 -07:00
|
|
|
!isMobile ? (
|
|
|
|
<>
|
|
|
|
<div className="flex items-center justify-between border-b border-th-bkg-3 bg-th-bkg-2 pl-6">
|
|
|
|
<h3 className="flex items-center whitespace-nowrap pr-6 text-sm">
|
2022-10-02 04:21:09 -07:00
|
|
|
{t('activity:filter-results')}
|
2022-10-01 05:36:39 -07:00
|
|
|
</h3>
|
|
|
|
<ActivityTypeFiltersForm
|
|
|
|
filters={filters}
|
|
|
|
updateFilters={updateFilters}
|
|
|
|
/>
|
|
|
|
<div className="flex h-12 items-center justify-between border-l border-th-bkg-4 p-6">
|
2022-09-29 20:22:55 -07:00
|
|
|
<LinkButton
|
2022-10-01 05:36:39 -07:00
|
|
|
className="whitespace-nowrap text-sm"
|
2022-09-29 20:22:55 -07:00
|
|
|
onClick={() => setShowAdvancedFiltersModal(true)}
|
|
|
|
>
|
2022-10-02 04:21:09 -07:00
|
|
|
{t('activity:advanced-filters')}
|
2022-09-29 20:22:55 -07:00
|
|
|
</LinkButton>
|
2022-10-02 04:21:09 -07:00
|
|
|
{hasFilters ? (
|
|
|
|
<Tooltip content={t('activity:reset-filters')}>
|
2022-09-29 20:22:55 -07:00
|
|
|
<IconButton
|
2022-10-01 05:36:39 -07:00
|
|
|
className={`ml-4 ${loadActivityFeed ? 'animate-spin' : ''}`}
|
2022-10-02 04:21:09 -07:00
|
|
|
onClick={() => handleResetFilters()}
|
2022-09-29 20:22:55 -07:00
|
|
|
size="small"
|
|
|
|
>
|
|
|
|
<ArrowPathIcon className="h-5 w-5" />
|
|
|
|
</IconButton>
|
|
|
|
</Tooltip>
|
|
|
|
) : null}
|
|
|
|
</div>
|
2022-10-22 05:14:25 -07:00
|
|
|
<Button
|
|
|
|
className="rounded-none"
|
|
|
|
size="large"
|
|
|
|
onClick={handleUpdateResults}
|
|
|
|
>
|
2022-10-02 04:21:09 -07:00
|
|
|
{t('activity:update')}
|
2022-10-01 05:36:39 -07:00
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
{showAdvancedFiltersModal ? (
|
|
|
|
<Modal
|
|
|
|
isOpen={showAdvancedFiltersModal}
|
|
|
|
onClose={() => setShowAdvancedFiltersModal(false)}
|
|
|
|
>
|
|
|
|
<h2 className="mb-2 text-center">
|
|
|
|
{t('activity:advanced-filters')}
|
|
|
|
</h2>
|
|
|
|
<AdvancedFiltersForm
|
|
|
|
advancedFilters={advancedFilters}
|
|
|
|
setAdvancedFilters={setAdvancedFilters}
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
className="w-full"
|
|
|
|
size="large"
|
2022-10-02 04:21:09 -07:00
|
|
|
onClick={handleUpdateModalResults}
|
2022-10-01 05:36:39 -07:00
|
|
|
>
|
2022-10-02 04:21:09 -07:00
|
|
|
{t('activity:update')}
|
2022-10-01 05:36:39 -07:00
|
|
|
</Button>
|
|
|
|
</Modal>
|
|
|
|
) : null}
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<Disclosure>
|
|
|
|
<div className="relative">
|
2022-10-02 04:21:09 -07:00
|
|
|
{hasFilters ? (
|
2022-10-01 05:36:39 -07:00
|
|
|
<div className="absolute right-14 top-3">
|
2022-10-02 04:21:09 -07:00
|
|
|
<Tooltip content={t('activity:reset-filters')}>
|
2022-10-01 05:36:39 -07:00
|
|
|
<IconButton
|
|
|
|
className={`${loadActivityFeed ? 'animate-spin' : ''}`}
|
2022-10-02 04:21:09 -07:00
|
|
|
onClick={() => handleResetFilters()}
|
2022-10-01 05:36:39 -07:00
|
|
|
size="small"
|
|
|
|
>
|
|
|
|
<ArrowPathIcon className="h-5 w-5" />
|
|
|
|
</IconButton>
|
|
|
|
</Tooltip>
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
<div
|
2022-10-02 04:21:09 -07:00
|
|
|
onClick={() => setShowMobileFilters(!showMobileFilters)}
|
2022-10-01 05:36:39 -07:00
|
|
|
role="button"
|
2022-10-02 16:47:21 -07:00
|
|
|
className={`default-transition w-full border-b border-th-bkg-3 bg-th-bkg-2 px-6 py-4 hover:bg-th-bkg-3`}
|
2022-10-01 05:36:39 -07:00
|
|
|
>
|
|
|
|
<Disclosure.Button
|
|
|
|
className={`flex h-full w-full items-center justify-between rounded-none`}
|
|
|
|
>
|
2022-10-02 16:47:21 -07:00
|
|
|
<span className="font-bold text-th-fgd-1">
|
2022-10-02 04:21:09 -07:00
|
|
|
{t('activity:filter-results')}
|
|
|
|
</span>
|
2022-10-01 05:36:39 -07:00
|
|
|
|
|
|
|
<ChevronDownIcon
|
|
|
|
className={`${
|
2022-10-02 04:21:09 -07:00
|
|
|
showMobileFilters ? 'rotate-180' : 'rotate-360'
|
2022-10-01 05:36:39 -07:00
|
|
|
} h-6 w-6 flex-shrink-0`}
|
|
|
|
/>
|
|
|
|
</Disclosure.Button>
|
|
|
|
</div>
|
2022-09-28 20:35:34 -07:00
|
|
|
</div>
|
2022-10-01 05:36:39 -07:00
|
|
|
<Transition
|
|
|
|
appear={true}
|
2022-10-02 04:21:09 -07:00
|
|
|
show={showMobileFilters}
|
2022-10-01 05:36:39 -07:00
|
|
|
enter="transition-all ease-in duration-300"
|
|
|
|
enterFrom="opacity-100 max-h-0"
|
|
|
|
enterTo="opacity-100 max-h-full"
|
|
|
|
leave="transition-all ease-out duration-300"
|
|
|
|
leaveFrom="opacity-100 max-h-full"
|
|
|
|
leaveTo="opacity-0 max-h-0"
|
2022-09-30 05:31:22 -07:00
|
|
|
>
|
2022-10-01 05:36:39 -07:00
|
|
|
<Disclosure.Panel className="bg-th-bkg-2 px-6 pb-6">
|
|
|
|
<div className="py-4">
|
|
|
|
<Label text={t('activity:activity-type')} />
|
|
|
|
<ActivityTypeFiltersForm
|
|
|
|
filters={filters}
|
|
|
|
updateFilters={updateFilters}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<AdvancedFiltersForm
|
|
|
|
advancedFilters={advancedFilters}
|
|
|
|
setAdvancedFilters={setAdvancedFilters}
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
className="w-full"
|
|
|
|
size="large"
|
2022-10-02 04:21:09 -07:00
|
|
|
onClick={handleUpdateMobileResults}
|
2022-10-01 05:36:39 -07:00
|
|
|
>
|
2022-10-02 04:21:09 -07:00
|
|
|
{t('activity:update')}
|
2022-10-01 05:36:39 -07:00
|
|
|
</Button>
|
|
|
|
</Disclosure.Panel>
|
|
|
|
</Transition>
|
|
|
|
</Disclosure>
|
|
|
|
)
|
2022-09-29 20:22:55 -07:00
|
|
|
) : null
|
|
|
|
}
|
|
|
|
|
2022-10-01 05:36:39 -07:00
|
|
|
const ActivityTypeFiltersForm = ({
|
|
|
|
filters,
|
|
|
|
updateFilters,
|
|
|
|
}: {
|
|
|
|
filters: Filters
|
|
|
|
updateFilters: (e: ChangeEvent<HTMLInputElement>, filter: string) => void
|
|
|
|
}) => {
|
2022-10-02 04:21:09 -07:00
|
|
|
const { t } = useTranslation('activity')
|
2022-10-01 05:36:39 -07:00
|
|
|
return (
|
|
|
|
<div className="flex w-full flex-col space-y-2 md:flex-row md:space-y-0">
|
|
|
|
<div className="flex h-8 flex-1 items-center lg:h-12 lg:border-l lg:border-th-bkg-4 lg:p-4">
|
|
|
|
<Checkbox
|
|
|
|
checked={filters.deposit}
|
|
|
|
onChange={(e) => updateFilters(e, 'deposit')}
|
|
|
|
>
|
2022-10-02 04:21:09 -07:00
|
|
|
<span className="text-sm">{t('deposits')}</span>
|
2022-10-01 05:36:39 -07:00
|
|
|
</Checkbox>
|
|
|
|
</div>
|
|
|
|
<div className="flex h-8 flex-1 items-center lg:h-12 lg:border-l lg:border-th-bkg-4 lg:p-4">
|
|
|
|
<Checkbox
|
|
|
|
checked={filters.withdraw}
|
|
|
|
onChange={(e) => updateFilters(e, 'withdraw')}
|
|
|
|
>
|
2022-10-02 04:21:09 -07:00
|
|
|
<span className="text-sm">{t('withdrawals')}</span>
|
2022-10-01 05:36:39 -07:00
|
|
|
</Checkbox>
|
|
|
|
</div>
|
|
|
|
<div className="flex h-8 flex-1 items-center lg:h-12 lg:border-l lg:border-th-bkg-4 lg:p-4">
|
|
|
|
<Checkbox
|
|
|
|
checked={filters.liquidate_token_with_token}
|
|
|
|
onChange={(e) => updateFilters(e, 'liquidate_token_with_token')}
|
|
|
|
>
|
2022-10-02 04:21:09 -07:00
|
|
|
<span className="text-sm">{t('liquidations')}</span>
|
2022-10-01 05:36:39 -07:00
|
|
|
</Checkbox>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
interface AdvancedFiltersFormProps {
|
2022-09-29 20:22:55 -07:00
|
|
|
advancedFilters: any
|
|
|
|
setAdvancedFilters: (x: any) => void
|
|
|
|
}
|
|
|
|
|
2022-10-01 05:36:39 -07:00
|
|
|
const AdvancedFiltersForm = ({
|
2022-09-29 20:22:55 -07:00
|
|
|
advancedFilters,
|
|
|
|
setAdvancedFilters,
|
2022-10-01 05:36:39 -07:00
|
|
|
}: AdvancedFiltersFormProps) => {
|
2022-09-29 20:22:55 -07:00
|
|
|
const { t } = useTranslation(['common', 'activity'])
|
|
|
|
const group = mangoStore((s) => s.group)
|
|
|
|
const [dateFrom, setDateFrom] = useState<Date | null>(null)
|
|
|
|
const [dateTo, setDateTo] = useState<Date | null>(null)
|
|
|
|
const [valueFrom, setValueFrom] = useState(advancedFilters['usd-lower'] || '')
|
|
|
|
const [valueTo, setValueTo] = useState(advancedFilters['usd-upper'] || '')
|
|
|
|
|
|
|
|
const symbols = useMemo(() => {
|
|
|
|
if (!group) return []
|
|
|
|
return Array.from(group.banksMapByName, ([key, value]) => key)
|
|
|
|
}, [group])
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (advancedFilters['start-date']) {
|
|
|
|
setDateFrom(new Date(advancedFilters['start-date']))
|
|
|
|
}
|
|
|
|
if (advancedFilters['end-date']) {
|
|
|
|
setDateTo(new Date(advancedFilters['end-date']))
|
|
|
|
}
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
const toggleOption = (option: string) => {
|
|
|
|
setAdvancedFilters((prevSelected: any) => {
|
|
|
|
const newSelections = prevSelected.symbol ? [...prevSelected.symbol] : []
|
|
|
|
if (newSelections.includes(option)) {
|
|
|
|
return {
|
|
|
|
...prevSelected,
|
|
|
|
symbol: newSelections.filter((item) => item != option),
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
newSelections.push(option)
|
|
|
|
return { ...prevSelected, symbol: newSelections }
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (dateFrom && dateTo) {
|
|
|
|
setAdvancedFilters({
|
|
|
|
...advancedFilters,
|
2022-11-15 02:47:11 -08:00
|
|
|
'start-date': dayjs(dateFrom).set('hour', 0).toISOString(),
|
|
|
|
'end-date': dayjs(dateTo)
|
|
|
|
.set('hour', 23)
|
|
|
|
.set('minute', 59)
|
|
|
|
.toISOString(),
|
2022-09-29 20:22:55 -07:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
setAdvancedFilters({
|
|
|
|
...advancedFilters,
|
|
|
|
'start-date': '',
|
|
|
|
'end-date': '',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}, [dateFrom, dateTo])
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (valueFrom && valueTo) {
|
|
|
|
setAdvancedFilters({
|
|
|
|
...advancedFilters,
|
|
|
|
'usd-lower': valueFrom,
|
|
|
|
'usd-upper': valueTo,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
setAdvancedFilters({
|
|
|
|
...advancedFilters,
|
|
|
|
'usd-lower': '',
|
|
|
|
'usd-upper': '',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}, [valueFrom, valueTo])
|
|
|
|
|
|
|
|
return (
|
2022-10-01 05:36:39 -07:00
|
|
|
<>
|
2022-09-29 20:22:55 -07:00
|
|
|
<Label text={t('tokens')} />
|
|
|
|
<MultiSelectDropdown
|
|
|
|
options={symbols}
|
|
|
|
selected={advancedFilters.symbol || []}
|
|
|
|
toggleOption={toggleOption}
|
|
|
|
/>
|
|
|
|
<div className="my-4 w-full">
|
|
|
|
<MangoDateRangePicker
|
|
|
|
startDate={dateFrom}
|
|
|
|
setStartDate={setDateFrom}
|
|
|
|
endDate={dateTo}
|
|
|
|
setEndDate={setDateTo}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="flex items-center space-x-2 pb-6">
|
|
|
|
<div className="w-1/2">
|
|
|
|
<Label text={t('activity:value-from')} />
|
|
|
|
<Input
|
|
|
|
type="text"
|
|
|
|
placeholder="0.00"
|
|
|
|
value={valueFrom}
|
|
|
|
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
|
|
|
setValueFrom(e.target.value)
|
|
|
|
}
|
|
|
|
/>
|
2022-09-28 20:35:34 -07:00
|
|
|
</div>
|
2022-09-29 20:22:55 -07:00
|
|
|
<div className="w-1/2">
|
|
|
|
<Label text={t('activity:value-to')} />
|
|
|
|
<Input
|
|
|
|
type="text"
|
|
|
|
placeholder="0.00"
|
|
|
|
value={valueTo || ''}
|
|
|
|
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
|
|
|
setValueTo(e.target.value)
|
|
|
|
}
|
|
|
|
/>
|
2022-09-28 20:35:34 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-10-01 05:36:39 -07:00
|
|
|
</>
|
2022-09-28 20:35:34 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-09-27 23:17:06 -07:00
|
|
|
const ActivityDetails = ({
|
|
|
|
activity,
|
|
|
|
setShowActivityDetail,
|
|
|
|
}: {
|
|
|
|
activity: LiquidationFeedItem
|
|
|
|
setShowActivityDetail: (x: any) => void
|
|
|
|
}) => {
|
2022-09-28 06:04:58 -07:00
|
|
|
const { t } = useTranslation(['common', 'activity', 'settings'])
|
2022-09-27 23:17:06 -07:00
|
|
|
const [preferredExplorer] = useLocalStorageState(
|
|
|
|
PREFERRED_EXPLORER_KEY,
|
|
|
|
EXPLORERS[0]
|
|
|
|
)
|
|
|
|
const { block_datetime } = activity
|
|
|
|
const {
|
|
|
|
asset_amount,
|
|
|
|
asset_price,
|
|
|
|
asset_symbol,
|
|
|
|
liab_amount,
|
|
|
|
liab_price,
|
|
|
|
liab_symbol,
|
|
|
|
signature,
|
|
|
|
} = activity.activity_details
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div className="flex items-center p-6">
|
|
|
|
<IconButton
|
|
|
|
className="mr-4"
|
|
|
|
onClick={() => setShowActivityDetail(null)}
|
|
|
|
>
|
|
|
|
<ArrowLeftIcon className="h-5 w-5" />
|
|
|
|
</IconButton>
|
2022-09-28 06:04:58 -07:00
|
|
|
<h2 className="text-lg">{t('activity:liquidation-details')}</h2>
|
2022-09-27 23:17:06 -07:00
|
|
|
</div>
|
2022-09-28 06:04:58 -07:00
|
|
|
<div className="grid grid-cols-1 gap-4 px-6 lg:grid-cols-3">
|
2022-09-27 23:17:06 -07:00
|
|
|
<div className="col-span-1">
|
|
|
|
<p className="mb-0.5 text-sm">{t('date')}</p>
|
|
|
|
<p className="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="col-span-1">
|
|
|
|
<p className="mb-0.5 text-sm">{t('activity:asset-liquidated')}</p>
|
2022-09-28 06:04:58 -07:00
|
|
|
<p className="font-mono text-th-fgd-1">
|
|
|
|
{formatDecimal(asset_amount)}{' '}
|
|
|
|
<span className="font-body tracking-wide">{asset_symbol}</span>
|
|
|
|
<span className="ml-2 font-body tracking-wide text-th-fgd-3">
|
|
|
|
at
|
|
|
|
</span>{' '}
|
|
|
|
{formatFixedDecimals(asset_price, true)}
|
2022-09-27 23:17:06 -07:00
|
|
|
</p>
|
2022-09-28 06:04:58 -07:00
|
|
|
<p className="font-mono text-xs text-th-fgd-3">
|
2022-09-27 23:17:06 -07:00
|
|
|
{formatFixedDecimals(asset_price * asset_amount, true)}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div className="col-span-1">
|
|
|
|
<p className="mb-0.5 text-sm">{t('activity:asset-returned')}</p>
|
2022-09-28 06:04:58 -07:00
|
|
|
<p className="font-mono text-th-fgd-1">
|
|
|
|
{formatDecimal(liab_amount)}{' '}
|
|
|
|
<span className="font-body tracking-wide">{liab_symbol}</span>
|
|
|
|
<span className="ml-2 font-body tracking-wide text-th-fgd-3">
|
|
|
|
at
|
|
|
|
</span>{' '}
|
|
|
|
{formatFixedDecimals(liab_price, true)}
|
2022-09-27 23:17:06 -07:00
|
|
|
</p>
|
2022-09-28 06:04:58 -07:00
|
|
|
<p className="font-mono text-xs text-th-fgd-3">
|
2022-09-27 23:17:06 -07:00
|
|
|
{formatFixedDecimals(liab_price * liab_amount, true)}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="col-span-3 mt-8 flex justify-center border-y border-th-bkg-3 py-3">
|
|
|
|
<a
|
|
|
|
className="default-transition flex items-center 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`}
|
|
|
|
/>
|
|
|
|
<span className="ml-2 text-base">{`View on ${t(
|
|
|
|
`settings:${preferredExplorer.name}`
|
|
|
|
)}`}</span>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|