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

refactor(widget): make only one flat set of params #3318

Merged
merged 13 commits into from
Nov 3, 2023

Conversation

shoom3301
Copy link
Collaborator

Summary

To simplify the widget lib interface I merged all parameters into one set and made all of the optional.
Now it's actually one line:

import { cowSwapWidget } from '@cowprotocol/widget-lib'

const updateWidget = cowSwapWidget(document.getElementById('<YOUR_CONTAINER>'))

@shoom3301 shoom3301 requested a review from a team November 2, 2023 12:19
@shoom3301 shoom3301 self-assigned this Nov 2, 2023
Copy link

vercel bot commented Nov 2, 2023

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

Name Status Preview Comments Updated (UTC)
cosmos ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 3, 2023 8:34am
swap-dev ✅ Ready (Inspect) Visit Preview Nov 3, 2023 8:34am
widget-configurator ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 3, 2023 8:34am

Copy link
Contributor

@anxolin anxolin left a comment

Choose a reason for hiding this comment

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

Just some nit comments. Looks great!

libs/widget-lib/docs/README.md Outdated Show resolved Hide resolved
libs/widget-lib/docs/README.md Outdated Show resolved Hide resolved
libs/widget-lib/docs/README.md Outdated Show resolved Hide resolved
libs/widget-lib/docs/README.md Outdated Show resolved Hide resolved
libs/widget-lib/docs/README.md Outdated Show resolved Hide resolved
| `theme` | `CowSwapTheme` | The theme of the widget (`'dark'` for dark theme or `'light'` for light theme). |
| `logoUrl` | `boolean` | The width of the widget in pixels. |
| `hideLogo` | `boolean` | The height of the widget in pixels. |
| `hideNetworkSelector` | `boolean` | Disables an opportunity to change the network from the widget UI. |
Copy link
Contributor

Choose a reason for hiding this comment

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

Allow users to change network from the Widget. Missing defaults

I assume is mandatory if we run it in standalone and there's more than one network?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since an integrator can preselect a network (by passing chainId parameter) they might want to disable the opportunity. For example, some of integrators supports only Gnosis chain, they wouldn't like their users to switch to Mainnet.
And yes, this option works only in standalone mode.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

image

@fairlighteth looks like we never show the network selector in the widget mode. Could you please help with that?

libs/widget-lib/docs/README.md Outdated Show resolved Hide resolved
| `hideNetworkSelector` | `boolean` | Disables an opportunity to change the network from the widget UI. |
| `dynamicHeightEnabled` | `boolean` | Dynamically changes the height of the iframe depending on the content. |
| `enabledTradeTypes` | `Array<TradeType>` | CowSwap provides three trading widgets: swap, limit and twap orders. Using this option you can narrow down the list of available trading widgets. |
| `palette` | `CowSwapWidgetPalette` | Using the palette you can customize the appearance of the widget. For example, you can change the main color of the background and text. |
Copy link
Contributor

Choose a reason for hiding this comment

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

We have theme, and palette. Should we make the names closer:

theme: 'dark' | 'light' themePalette: 'dark' | CowSwapWidgetPalette

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm afraid we need both.
them sets a general subset of colors.
palette only overrides some of them

Copy link
Contributor

Choose a reason for hiding this comment

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

yep, but i could see that in the future palette has more and more options.

BEcause both are part of theming, as a dev i find it easier to find if they show close to each other so their names are similar.

So i was suggesting leaving both: theme & themePallete

However, there's another alternative, since apps will likely setup this once.

What about defining it like this?

type ThemeBase = 'light' | 'dark' | 'auto'

export interface CowSwapTheme {
  baseTheme: ThemeBase
  primaryColor: string
  screenBackground: string
  widgetBackground: string
  textColor: string
}

Then, the theme type would be

{
    theme: ThemeBase | CowSwapTheme
    ...
}

// so users can do:
theme = 'light'
theme = 'dark'
theme = {
   baseTheme: 'light,
   primaryColor: '#fff'
   ...
}

Alternatively:

type ThemeBase = 'light' | 'dark' | 'auto'

export interface CowSwapTheme {
  baseTheme?: ThemeBase
  primaryColor?: string
  screenBackground?: string
  widgetBackground?: string
  textColor?: string
}

{
    theme?: CowSwapTheme // defaults to "{ baseTheme: 'auto' }" which uses the OS
    ...
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Got your point.
Don't you mind if I will implement this in the next PR?
Anyway, currently the palette just randomly bound to colors. It needs and input from Michel

@anxolin
Copy link
Contributor

anxolin commented Nov 2, 2023

image

@shoom3301
Copy link
Collaborator Author

Merging the PR, the rest of comments will be addressed in the next iteration

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

Successfully merging this pull request may close these issues.

2 participants