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

fix(widget): polish configurator #3380

Merged
merged 5 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/widget-configurator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>CoW Swap: Widget configurator</title>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, width=device-width" />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<link rel="icon" type="image/x-icon" href="/favicon.png" />
</head>
<body>
<div id="root"></div>
Expand Down
Binary file removed apps/widget-configurator/public/favicon.ico
Binary file not shown.
Binary file added apps/widget-configurator/public/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext } from 'react'
import { useContext, useState } from 'react'

import FormControl from '@mui/material/FormControl'
import InputLabel from '@mui/material/InputLabel'
Expand All @@ -7,21 +7,26 @@ import Select, { SelectChangeEvent } from '@mui/material/Select'

import { ColorModeContext } from '../../../theme/ColorModeContext'

const AUTO = 'auto'

const ThemeOptions = [
{ label: 'Auto', value: 'auto' },
{ label: 'Auto', value: AUTO },
{ label: 'Light', value: 'light' },
{ label: 'Dark', value: 'dark' },
]

export function ThemeControl() {
const { mode, toggleColorMode, setAutoMode } = useContext(ColorModeContext)
const [isAutoMode, setIsAutoMode] = useState(false)

const handleThemeChange = (event: SelectChangeEvent) => {
const selectedTheme = event.target.value
if (selectedTheme === 'auto') {
if (selectedTheme === AUTO) {
setAutoMode()
setIsAutoMode(true)
} else {
toggleColorMode()
setIsAutoMode(false)
}
}

Expand All @@ -31,7 +36,7 @@ export function ThemeControl() {
<Select
labelId="select-theme-label"
id="select-theme"
value={mode}
value={isAutoMode ? AUTO : mode}
onChange={handleThemeChange}
autoWidth
label="Theme"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import MenuItem from '@mui/material/MenuItem'
import OutlinedInput from '@mui/material/OutlinedInput'
import Select, { SelectChangeEvent } from '@mui/material/Select'

const LABEL = 'Trade Modes'
const LABEL = 'Trade types'
export function TradeModesControl({ state }: { state: [TradeType[], Dispatch<SetStateAction<TradeType[]>>] }) {
const [tradeModes, setTradeModes] = state
const handleTradeModeChange = (event: SelectChangeEvent<TradeType[]>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { COMMENTS_BEFORE_PARAMS } from '../const'

export function reactExample(params: CowSwapWidgetParams): string {
return `
import { CowSwapWidget } from '@cowprotocol/widget-react'
import { CowSwapWidget, CowSwapWidgetParams } from '@cowprotocol/widget-react'

// ${COMMENTS_BEFORE_PARAMS}
const params: CowSwapWidgetParams = ${formatParameters(params)}
Expand Down
13 changes: 3 additions & 10 deletions libs/widget-lib/src/urlUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { COWSWAP_URLS } from './consts'
import { CowSwapWidgetParams, TradeType } from './types'

const EMPTY_TOKEN = '_'

export function buildWidgetUrl(params: CowSwapWidgetParams): string {
const host = COWSWAP_URLS[params.env || 'prod']
const path = buildWidgetPath(params)
Expand All @@ -12,16 +14,7 @@ export function buildWidgetUrl(params: CowSwapWidgetParams): string {
export function buildWidgetPath(params: CowSwapWidgetParams): string {
const { chainId = 1, sell, buy, tradeType = TradeType.SWAP } = params

const assets = []
if (sell?.asset) {
assets.push(sell.asset)
}

if (buy?.asset) {
assets.push(buy.asset)
}

const assetsPath = assets.map(encodeURIComponent).join('/')
const assetsPath = [sell?.asset || EMPTY_TOKEN, buy?.asset || EMPTY_TOKEN].map(encodeURIComponent).join('/')

return `/${chainId}/widget/${tradeType}/${assetsPath}`
}
Expand Down
Loading