Skip to content

Commit

Permalink
Remove event filtering
Browse files Browse the repository at this point in the history
As discussed on the task refinement meeting
  • Loading branch information
csillag committed Jan 23, 2024
1 parent 92b1259 commit 25b1b4b
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 129 deletions.
1 change: 1 addition & 0 deletions .changelog/1174.trivial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Simplify UI: remove event filtering switch
71 changes: 0 additions & 71 deletions src/app/components/RuntimeEvents/EventListFilterSwitch.tsx

This file was deleted.

17 changes: 2 additions & 15 deletions src/app/pages/AccountDetailsPage/AccountEventsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,19 @@ import { useTranslation } from 'react-i18next'
import { RuntimeEventsDetailedList } from '../../components/RuntimeEvents/RuntimeEventsDetailedList'
import { SearchScope } from '../../../types/searchScope'
import { AddressSwitchOption } from '../../components/AddressSwitch'
import { EventFilterMode, EventFilterSwitch } from '../../components/RuntimeEvents/EventListFilterSwitch'

type AccountEventProps = {
scope: SearchScope
isLoading: boolean
filterMode: EventFilterMode
setFilterMode: (mode: EventFilterMode) => void
isError: boolean
events: RuntimeEvent[] | undefined
}

export const AccountEventsCard: FC<AccountEventProps> = ({
scope,
isLoading,
filterMode,
setFilterMode,
isError,
events,
}) => {
export const AccountEventsCard: FC<AccountEventProps> = ({ scope, isLoading, isError, events }) => {
const { t } = useTranslation()

return (
<SubPageCard
title={t('common.events')}
action={<EventFilterSwitch selected={filterMode} onSelectionChange={setFilterMode} />}
>
<SubPageCard title={t('common.events')}>
<RuntimeEventsDetailedList
scope={scope}
events={events}
Expand Down
8 changes: 2 additions & 6 deletions src/app/pages/AccountDetailsPage/hook.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Layer,
RuntimeEventType,
useGetRuntimeAccountsAddress,
useGetRuntimeEvents,
useGetRuntimeTransactions,
Expand All @@ -9,7 +8,6 @@ import { AppErrors } from '../../../types/errors'
import { useSearchParamsPagination } from '../../components/Table/useSearchParamsPagination'
import { NUMBER_OF_ITEMS_ON_SEPARATE_PAGE } from '../../config'
import { SearchScope } from '../../../types/searchScope'
import { EventFilterMode } from '../../components/RuntimeEvents/EventListFilterSwitch'
import { useTransformToOasisAddress } from '../../hooks/useTransformToOasisAddress'

export const useAccount = (scope: SearchScope, address: string) => {
Expand Down Expand Up @@ -71,7 +69,7 @@ export const useAccountTransactions = (scope: SearchScope, address: string) => {
}
}

export const useAccountEvents = (scope: SearchScope, address: string, filterMode: EventFilterMode) => {
export const useAccountEvents = (scope: SearchScope, address: string) => {
const { network, layer } = scope
if (layer === Layer.consensus) {
throw AppErrors.UnsupportedLayer
Expand All @@ -94,8 +92,6 @@ export const useAccountEvents = (scope: SearchScope, address: string, filterMode
},
)
const { isFetched, isLoading, isError, data } = query
const events = data?.data.events.filter(
event => filterMode === EventFilterMode.All || event.type !== RuntimeEventType.accountstransfer,
)
const events = data?.data.events
return { isFetched, isLoading, isError, events }
}
19 changes: 3 additions & 16 deletions src/app/pages/AccountDetailsPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useState } from 'react'
import { FC } from 'react'
import { useTranslation } from 'react-i18next'
import { useHref, useLoaderData, useOutletContext } from 'react-router-dom'
import { PageLayout } from '../../components/PageLayout'
Expand All @@ -17,7 +17,6 @@ import { getTokenTypePluralName } from '../../../types/tokens'
import { SearchScope } from '../../../types/searchScope'
import { AccountDetailsCard } from './AccountDetailsCard'
import { AccountEventsCard } from './AccountEventsCard'
import { EventFilterMode } from '../../components/RuntimeEvents/EventListFilterSwitch'
import { DappBanner } from '../../components/DappBanner'

export type AccountDetailsContext = {
Expand All @@ -38,13 +37,8 @@ export const AccountDetailsPage: FC = () => {
const { token, isLoading: isTokenLoading } = useTokenInfo(scope, address, isContract)

const tokenPriceInfo = useTokenPrice(account?.ticker || Ticker.ROSE)
const [eventFilterMode, setEventFilterMode] = useState<EventFilterMode>(EventFilterMode.All)

const {
isLoading: areEventsLoading,
isError: isEventsError,
events,
} = useAccountEvents(scope, address, eventFilterMode)
const { isLoading: areEventsLoading, isError: isEventsError, events } = useAccountEvents(scope, address)

const tokenTransfersLink = useHref(`token-transfers#${accountTokenTransfersContainerId}`)
const erc20Link = useHref(`tokens/erc-20#${accountTokenContainerId}`)
Expand Down Expand Up @@ -85,14 +79,7 @@ export const AccountDetailsPage: FC = () => {
]}
context={context}
/>
<AccountEventsCard
scope={scope}
filterMode={eventFilterMode}
setFilterMode={setEventFilterMode}
isLoading={areEventsLoading}
isError={isEventsError}
events={events}
/>
<AccountEventsCard scope={scope} isLoading={areEventsLoading} isError={isEventsError} events={events} />
</PageLayout>
)
}
27 changes: 6 additions & 21 deletions src/app/pages/BlockDetailPage/EventsCard.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
import { FC, useState } from 'react'
import { FC } from 'react'
import { useTranslation } from 'react-i18next'
import { ScrollingCard } from '../../components/PageLayout/ScrollingCard'
import CardHeader from '@mui/material/CardHeader'
import CardContent from '@mui/material/CardContent'

import { Layer, RuntimeEventType, useGetRuntimeEvents } from '../../../oasis-nexus/api'
import { Layer, useGetRuntimeEvents } from '../../../oasis-nexus/api'
import { ErrorBoundary } from '../../components/ErrorBoundary'
import { AppErrors } from '../../../types/errors'
import { SearchScope } from '../../../types/searchScope'
import { RuntimeEventsDetailedList } from '../../components/RuntimeEvents/RuntimeEventsDetailedList'
import { AddressSwitchOption } from '../../components/AddressSwitch'
import { EventFilterMode, EventFilterSwitch } from '../../components/RuntimeEvents/EventListFilterSwitch'
import { EmptyState } from '../../components/EmptyState'

export const eventsContainerId = 'events'

const EventsList: FC<{ scope: SearchScope; blockHeight: number; filterMode: EventFilterMode }> = ({
scope,
blockHeight,
filterMode,
}) => {
const EventsList: FC<{ scope: SearchScope; blockHeight: number }> = ({ scope, blockHeight }) => {
const { t } = useTranslation()
if (scope.layer === Layer.consensus) {
// Loading events for consensus blocks is not yet supported.
Expand All @@ -34,11 +29,7 @@ const EventsList: FC<{ scope: SearchScope; blockHeight: number; filterMode: Even

const { isLoading, isError, data } = eventsQuery

const events = data?.data.events.filter(
event =>
!event.tx_hash && // TODO: remove filtering here if it's implemented using the query parameters
(filterMode === EventFilterMode.All || event.type !== RuntimeEventType.accountstransfer),
)
const events = data?.data.events.filter(event => !event.tx_hash)

if (!events?.length && !isLoading) {
return (
Expand All @@ -62,19 +53,13 @@ const EventsList: FC<{ scope: SearchScope; blockHeight: number; filterMode: Even
}

export const EventsCard: FC<{ scope: SearchScope; blockHeight: number }> = ({ scope, blockHeight }) => {
const [filterMode, setFilterMode] = useState<EventFilterMode>(EventFilterMode.All)
const { t } = useTranslation()
return (
<ScrollingCard id={eventsContainerId}>
<CardHeader
disableTypography
component="h3"
title={t('common.events')}
action={<EventFilterSwitch selected={filterMode} onSelectionChange={setFilterMode} />}
/>
<CardHeader disableTypography component="h3" title={t('common.events')} />
<CardContent>
<ErrorBoundary light={true}>
<EventsList scope={scope} blockHeight={blockHeight} filterMode={filterMode} />
<EventsList scope={scope} blockHeight={blockHeight} />
</ErrorBoundary>
</CardContent>
</ScrollingCard>
Expand Down

0 comments on commit 25b1b4b

Please sign in to comment.