Skip to content

Commit

Permalink
test: add filter to event feed (#554)
Browse files Browse the repository at this point in the history
* test: add filter to event feed

* fix: pr feedback
  • Loading branch information
zzmp authored Mar 16, 2023
1 parent c3e49cd commit f7b7602
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/cosmos/EventFeed.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defaultTheme, SwapEventHandlers, TransactionEventHandlers, WidgetEventHandlers } from '@uniswap/widgets'
import Row from 'components/Row'
import { useState } from 'react'
import styled from 'styled-components/macro'
import * as Type from 'theme/type'

Expand Down Expand Up @@ -53,6 +54,8 @@ export const HANDLERS: (keyof SwapEventHandlers | keyof TransactionEventHandlers
'onWrapSend',
]

const SHOW_ALL_EVENTS = '(show all events)'

export interface Event {
name: string
data: unknown
Expand All @@ -64,6 +67,7 @@ export interface EventFeedProps {
}

export default function EventFeed({ events, onClear }: EventFeedProps) {
const [selectedEventType, setSelectedEventType] = useState<string>(SHOW_ALL_EVENTS)
return (
<EventFeedWrapper>
<Row>
Expand All @@ -72,15 +76,27 @@ export default function EventFeed({ events, onClear }: EventFeedProps) {
<Type.Subhead1>clear</Type.Subhead1>
</button>
</Row>
<Row>
<Type.Subhead2>Filter: </Type.Subhead2>
<select onChange={(e) => setSelectedEventType(e.target.value)} value={selectedEventType}>
<option>{SHOW_ALL_EVENTS}</option>
{HANDLERS.map((name) => (
// Handlers should never have the same name - using key={name} will enforce that at runtime.
<option key={name}>{name}</option>
))}
</select>
</Row>
<EventColumn>
{events?.map(({ name, data }, i) => (
<EventRow key={i}>
<Type.Subhead2 margin={0} padding={0}>
{name}
</Type.Subhead2>
<EventData>{JSON.stringify(data, null, 2)}</EventData>
</EventRow>
))}
{events
?.filter(({ name }) => (selectedEventType === SHOW_ALL_EVENTS ? true : name === selectedEventType))
.map(({ name, data }, i) => (
<EventRow key={i}>
<Type.Subhead2 margin={0} padding={0}>
{name}
</Type.Subhead2>
<EventData>{JSON.stringify(data, null, 2)}</EventData>
</EventRow>
))}
</EventColumn>
</EventFeedWrapper>
)
Expand Down

1 comment on commit f7b7602

@vercel
Copy link

@vercel vercel bot commented on f7b7602 Mar 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

widgets – ./

widgets-git-main-uniswap.vercel.app
widgets-uniswap.vercel.app
widgets-seven-tau.vercel.app

Please sign in to comment.