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: allow integrators to disable uniswap branding #158

Merged
merged 9 commits into from
Aug 25, 2022

Conversation

JFrankfurt
Copy link
Contributor

image

@JFrankfurt JFrankfurt requested a review from zzmp August 22, 2022 21:35
@vercel
Copy link

vercel bot commented Aug 22, 2022

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

Name Status Preview Updated
widgets ✅ Ready (Inspect) Visit Preview Aug 25, 2022 at 2:26PM (UTC)

@vercel vercel bot temporarily deployed to Preview August 22, 2022 21:35 Inactive
@@ -27,6 +29,10 @@ const UniswapA = styled(ExternalLink)`
`

export default memo(function BrandedFooter() {
const disableBranding = useAtomValue(disableBrandingAtom)
if (disableBranding) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: As a guard I'd prefer this as a one-liner (no brackets).

src/hooks/useSyncBrandingSetting.ts Outdated Show resolved Hide resolved
@@ -62,6 +63,7 @@ export default function Swap(props: SwapProps) {
useSyncSwapEventHandlers(props as SwapEventHandlers)
useSyncTokenDefaults(props as TokenDefaults)
useSyncWidgetEventHandlers(props as WidgetEventHandlers)
useSyncBrandingSetting(props as BrandingSetting)
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 sync'ed as part of the Widget component, not as part of the Swap component, as it is widget-scoped state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had the same thought, but the AtomProvider is at the Widget component level, so only its children can share atoms

Copy link
Contributor

Choose a reason for hiding this comment

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

This will need to be moved eventually (with useSyncWidgetEventHandlers) but I think it's fine for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

On L53, SwapProps must extend BrandingSettings so that the type system will enforce that these props are available.

@vercel vercel bot temporarily deployed to Preview August 23, 2022 15:07 Inactive
@vercel vercel bot temporarily deployed to Preview August 23, 2022 15:10 Inactive
src/components/Swap/Output.tsx Outdated Show resolved Hide resolved
src/hooks/useSyncBrandingSetting.ts Outdated Show resolved Hide resolved
import { useUpdateAtom } from 'jotai/utils'
import { useEffect } from 'react'

export const disableBrandingAtom = atom<boolean>(false)
Copy link
Contributor

Choose a reason for hiding this comment

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

If you expect more branding settings, you should shape the atom for them:

const initialBrandingSettings: BrandingSettings = {}
const brandingSettingsAtom = atom(initialBrandingSettings)

This will also let you simplify your sync hook, so that any future additions to the BrandingSettings type can be effected by just updating the type, and not touching the rest of the implementation.

export default function useSyncBrandingSettings(settings: BrandingSettings): void {
  const updateSettings = useUpdateAtom(brandingSettingsAtom)
  useEffect(() => updateSettings(settings), [settings, updateSettings])
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't expect more. Do you?

src/components/Widget.tsx Outdated Show resolved Hide resolved
@@ -62,6 +63,7 @@ export default function Swap(props: SwapProps) {
useSyncSwapEventHandlers(props as SwapEventHandlers)
useSyncTokenDefaults(props as TokenDefaults)
useSyncWidgetEventHandlers(props as WidgetEventHandlers)
useSyncBrandingSetting(props as BrandingSetting)
Copy link
Contributor

Choose a reason for hiding this comment

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

This will need to be moved eventually (with useSyncWidgetEventHandlers) but I think it's fine for now.

@@ -62,6 +63,7 @@ export default function Swap(props: SwapProps) {
useSyncSwapEventHandlers(props as SwapEventHandlers)
useSyncTokenDefaults(props as TokenDefaults)
useSyncWidgetEventHandlers(props as WidgetEventHandlers)
useSyncBrandingSetting(props as BrandingSetting)
Copy link
Contributor

Choose a reason for hiding this comment

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

On L53, SwapProps must extend BrandingSettings so that the type system will enforce that these props are available.

@JFrankfurt JFrankfurt requested a review from zzmp August 24, 2022 16:41
@vercel vercel bot temporarily deployed to Preview August 24, 2022 16:42 Inactive
@vercel vercel bot temporarily deployed to Preview August 24, 2022 17:16 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.

lgtm, but remove the explicit prop from WidgetProps

@@ -97,6 +98,7 @@ export interface WidgetProps extends TransactionEventHandlers {
tokenList?: string | TokenInfo[]
width?: string | number
dialog?: HTMLDivElement | null
disableBranding?: boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the explicit disableBranding prop, as it's already included in WidgetProps through extends BrandingSettings.

@vercel vercel bot temporarily deployed to Preview August 24, 2022 23:37 Inactive
@vercel vercel bot temporarily deployed to Preview August 25, 2022 14:24 Inactive
@vercel vercel bot temporarily deployed to Preview August 25, 2022 14:26 Inactive
@JFrankfurt JFrankfurt merged commit cd6265c into main Aug 25, 2022
@JFrankfurt JFrankfurt deleted the disable-branding branch August 25, 2022 15:09
@github-actions
Copy link

🎉 This PR is included in version 2.3.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