Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cosmos): Add events to cosmos #142

Merged
merged 6 commits into from
Aug 17, 2022
Merged

feat(cosmos): Add events to cosmos #142

merged 6 commits into from
Aug 17, 2022

Conversation

JFrankfurt
Copy link
Contributor

image

@JFrankfurt JFrankfurt self-assigned this Aug 12, 2022
@vercel
Copy link

vercel bot commented Aug 12, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
widgets ✅ Ready (Inspect) Visit Preview Aug 17, 2022 at 4:55PM (UTC)

@vercel vercel bot temporarily deployed to Preview August 12, 2022 20:23 Inactive
Copy link
Contributor

@zzmp zzmp left a comment

Choose a reason for hiding this comment

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

Style updates for page symmetry


import { DAI, USDC_MAINNET } from '../constants/tokens'
import useOption from './useOption'
import useProvider, { INFURA_NETWORK_URLS } from './useProvider'

const EventFeedWrapper = styled.div`
Copy link
Contributor

Choose a reason for hiding this comment

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

Add box-sizing: border-box

onTxSuccess={(txHash: string, data: any) => console.log('tx success:', txHash, data)}
onTxFail={(error: Error, data: any) => console.log('tx fail:', error, data)}
/>
<Row align="baseline" justify="space-around">
Copy link
Contributor

Choose a reason for hiding this comment

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

Change align to start

onTxFail={(error: Error, data: any) => addEvent({ message: `onTxFail`, data: { ...data, error } })}
/>
<EventFeedWrapper>
<H2>Event Feed</H2>
Copy link
Contributor

Choose a reason for hiding this comment

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

h2, not H2 - only React elements are capitalized, native elements are not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are components import { H2, H3 } from 'theme/type' I'll do a default import to make this less confusing.

{events?.map(({ message, data }, i) => (
<EventRow key={i}>
<div>
<H3 padding={0}>
Copy link
Contributor

Choose a reason for hiding this comment

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

h3, not H3

tokenList={tokenList}
width={width}
routerUrl={routerUrl}
onConnectWalletClick={() =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Simplify the Promise-returning event handlers as

onConnectWalletClick={() => {
  addEvent({ message: 'onConnectWalletClick', data: {} })
  return Promise.resolve(true)
}}

<H3 padding={0}>
<Message>{message}</Message>
</H3>
<pre>{JSON.stringify(data, null, 2)}</pre>
Copy link
Contributor

Choose a reason for hiding this comment

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

Make a new Event wrapper for the JSON:

const Event = styled.pre`
  margin-top: 1em;
`

/>
<EventFeedWrapper>
<H2>Event Feed</H2>
{events.length > 0 && <button onClick={() => setEvents([])}>clear</button>}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: You can leave the clear button visible to reduce layout thrashing

routerUrl={routerUrl}
onConnectWalletClick={() =>
new Promise((resolve) => {
addEvent({ message: 'onConnectWalletClick', data: {} })
Copy link
Contributor

Choose a reason for hiding this comment

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

If no data is passed, then data should be undefined, not {} - otherwise it suggests that you can use property access on it.

I think that you should always just pass through the event, so that the handlers look like:

(data: unknown) => addEvent({ message: 'onTxSubmit', data })

or

(data: unknown) => {
  addEvent({ message: 'onTxSubmit', data })
  return Promise.resolve(true)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

You could also make these into two callback helpers:

const addNopEvent = useCallback((message: string) => (data: unknown) => addEvent({ message, data }), [addEvent])
const addResolvingEvent = useCallback((message: string) => (data: unknown) => {
  addEvent({ message, data })
  return Promise.resolve(true)
}, [addEvent])

margin: 0;
`

type HandlerEventMessage = { message: string; data: Record<string, any> }
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

interface HandlerEvent {
  name: string
  data: Record<string, any>
}

@vercel vercel bot temporarily deployed to Preview August 17, 2022 16:14 Inactive
@@ -42,7 +46,10 @@ const Message = styled.pre`
margin: 0;
`

type HandlerEventMessage = { message: string; data: Record<string, any> }
type HandlerEventMessage = {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be an interface, not a type (it's handled better by the checker).

<H2>Event Feed</H2>
{events.length > 0 && <button onClick={() => setEvents([])}>clear</button>}
<Type.H2>Event Feed</Type.H2>
<button onClick={() => setEvents([])} disabled={events.length === 0}>
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't need to be disabled - it just adds complexity.

@@ -15,7 +15,7 @@ import { useCallback, useEffect, useState } from 'react'
import { useValue } from 'react-cosmos/fixture'
import { Field } from 'state/swap'
import styled from 'styled-components/macro'
import { H2, H3 } from 'theme/type'
import * as Type from 'theme/type'
Copy link
Contributor

Choose a reason for hiding this comment

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

I hadn't realized H2/H3 came from here - it's fine to import them directly if you want to revert that.

@vercel vercel bot temporarily deployed to Preview August 17, 2022 16:55 Inactive
@JFrankfurt JFrankfurt merged commit 60ae77e into main Aug 17, 2022
@github-actions
Copy link

🎉 This PR is included in version 2.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants