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: simplify theme config #3363

Merged
merged 2 commits into from
Nov 9, 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ import { useInjectedWidgetParams } from './useInjectedWidgetParams'
export function useInjectedWidgetPalette(): CowSwapWidgetPalette | undefined {
const state = useInjectedWidgetParams()

return state.palette
return isCowSwapWidgetPallet(state.theme) ? state.theme : undefined
}

function isCowSwapWidgetPallet(palette: any): palette is CowSwapWidgetPalette {
return palette && typeof palette === 'object'
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ export function useWidgetParamsAndSettings(
width: '450px',
height: '640px',
provider,
theme,
chainId,
env: getEnv(),
tradeType: currentTradeType,
sell: { asset: sellToken, amount: sellTokenAmount ? sellTokenAmount.toString() : undefined },
buy: { asset: buyToken, amount: buyTokenAmount?.toString() },
enabledTradeTypes,
// palette: {
theme,
// theme: {
// baseTheme: theme,
// primaryColor: '#d9258e',
// screenBackground: '#ee00cd',
// widgetBackground: '#b900ff',
Expand Down
2 changes: 1 addition & 1 deletion apps/widget-configurator/src/app/embedDialog/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const COMMENTS_BY_PARAM_NAME: Record<string, string> = {
provider:
'Ethereum EIP-1193 provider. For a quick test, you can pass `window.ethereum`, but consider using something like https://web3modal.com',
chainId: '1 (Mainnet), 5 (Goerli), 100 (Gnosis)',
theme: 'light or dark',
theme: 'light/dark or provide your own color palette',
tradeType: 'swap, limit or advanced',
sell: 'Sell token. Optionally add amount for sell orders',
buy: 'Buy token. Optionally add amount for buy orders',
Expand Down
8 changes: 2 additions & 6 deletions libs/widget-lib/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export enum TradeType {
}

export interface CowSwapWidgetPalette {
baseTheme: CowSwapTheme
primaryColor: string
screenBackground: string
widgetBackground: string
Expand Down Expand Up @@ -111,7 +112,7 @@ interface CowSwapWidgetConfig {
/**
* The theme of the widget UI.
*/
theme: CowSwapTheme
theme: CowSwapTheme | CowSwapWidgetPalette

/**
* Allows to set a custom logo for the widget.
Expand All @@ -133,11 +134,6 @@ interface CowSwapWidgetConfig {
*/
enabledTradeTypes: TradeType[]

/**
* Colors palette to customize the widget UI.
*/
palette: CowSwapWidgetPalette

/**
* The interface fee in basis points.
* For example: 1.5% = 150 bips
Expand Down
2 changes: 1 addition & 1 deletion libs/widget-lib/src/urlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function buildTradeAmountsQuery(params: CowSwapWidgetParams): URLSearchPa
}

if (theme) {
query.append('theme', theme)
query.append('theme', typeof theme === 'string' ? theme : theme.baseTheme)
}

return query
Expand Down
Loading