Skip to content

Commit d7b0543

Browse files
authored
[WT-1731] remove custom theme (#883)
1 parent 0f24472 commit d7b0543

File tree

5 files changed

+74
-14
lines changed

5 files changed

+74
-14
lines changed

packages/checkout/widgets-lib/src/lib/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
export enum WidgetTheme {
55
LIGHT = 'light',
66
DARK = 'dark',
7-
CUSTOM = 'custom',
87
}

packages/checkout/widgets-lib/src/lib/withDefaultWidgetConfig.test.ts

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,88 @@ describe('withDefaultWidgetConfig', () => {
4141
});
4242
expect(
4343
withDefaultWidgetConfigs({
44-
theme: WidgetTheme.CUSTOM,
44+
isOnRampEnabled: false,
4545
}),
4646
).toEqual({
47-
theme: WidgetTheme.CUSTOM,
47+
theme: DEFAULT_THEME,
4848
environment: DEFAULT_ENV,
49+
isOnRampEnabled: false,
50+
isSwapEnabled: DEFAULT_SWAP_ENABLED,
51+
isBridgeEnabled: DEFAULT_BRIDGE_ENABLED,
52+
});
53+
});
54+
55+
it('should use the correct environment', () => {
56+
expect(
57+
withDefaultWidgetConfigs({
58+
environment: Environment.PRODUCTION,
59+
}),
60+
).toEqual({
61+
theme: DEFAULT_THEME,
62+
environment: Environment.PRODUCTION,
4963
isOnRampEnabled: DEFAULT_ON_RAMP_ENABLED,
5064
isSwapEnabled: DEFAULT_SWAP_ENABLED,
5165
isBridgeEnabled: DEFAULT_BRIDGE_ENABLED,
5266
});
67+
5368
expect(
5469
withDefaultWidgetConfigs({
55-
isOnRampEnabled: false,
70+
environment: Environment.SANDBOX,
71+
}),
72+
).toEqual({
73+
theme: DEFAULT_THEME,
74+
environment: Environment.SANDBOX,
75+
isOnRampEnabled: DEFAULT_ON_RAMP_ENABLED,
76+
isSwapEnabled: DEFAULT_SWAP_ENABLED,
77+
isBridgeEnabled: DEFAULT_BRIDGE_ENABLED,
78+
});
79+
80+
expect(
81+
withDefaultWidgetConfigs({
82+
environment: 'unknown' as Environment,
5683
}),
5784
).toEqual({
5885
theme: DEFAULT_THEME,
5986
environment: DEFAULT_ENV,
60-
isOnRampEnabled: false,
87+
isOnRampEnabled: DEFAULT_ON_RAMP_ENABLED,
88+
isSwapEnabled: DEFAULT_SWAP_ENABLED,
89+
isBridgeEnabled: DEFAULT_BRIDGE_ENABLED,
90+
});
91+
});
92+
93+
it('should use the correct theme', () => {
94+
expect(
95+
withDefaultWidgetConfigs({
96+
theme: WidgetTheme.DARK,
97+
}),
98+
).toEqual({
99+
theme: WidgetTheme.DARK,
100+
environment: DEFAULT_ENV,
101+
isOnRampEnabled: DEFAULT_ON_RAMP_ENABLED,
102+
isSwapEnabled: DEFAULT_SWAP_ENABLED,
103+
isBridgeEnabled: DEFAULT_BRIDGE_ENABLED,
104+
});
105+
106+
expect(
107+
withDefaultWidgetConfigs({
108+
theme: WidgetTheme.LIGHT,
109+
}),
110+
).toEqual({
111+
theme: WidgetTheme.LIGHT,
112+
environment: DEFAULT_ENV,
113+
isOnRampEnabled: DEFAULT_ON_RAMP_ENABLED,
114+
isSwapEnabled: DEFAULT_SWAP_ENABLED,
115+
isBridgeEnabled: DEFAULT_BRIDGE_ENABLED,
116+
});
117+
118+
expect(
119+
withDefaultWidgetConfigs({
120+
theme: 'unknown' as Environment,
121+
}),
122+
).toEqual({
123+
theme: DEFAULT_THEME,
124+
environment: DEFAULT_ENV,
125+
isOnRampEnabled: DEFAULT_ON_RAMP_ENABLED,
61126
isSwapEnabled: DEFAULT_SWAP_ENABLED,
62127
isBridgeEnabled: DEFAULT_BRIDGE_ENABLED,
63128
});

packages/checkout/widgets-lib/src/lib/withDefaultWidgetConfig.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,14 @@ export type StrongCheckoutWidgetsConfig = {
1818

1919
function getValidTheme(theme?: string): WidgetTheme {
2020
if (!theme) return DEFAULT_THEME;
21-
if (theme === WidgetTheme.LIGHT) return WidgetTheme.LIGHT;
22-
if (theme === WidgetTheme.DARK) return WidgetTheme.DARK;
23-
if (theme === WidgetTheme.CUSTOM) return WidgetTheme.CUSTOM;
24-
return DEFAULT_THEME;
21+
if (!Object.values(WidgetTheme).includes(theme as WidgetTheme)) return DEFAULT_THEME;
22+
return theme as WidgetTheme;
2523
}
2624

2725
function getValidEnvironment(env?: string): Environment {
2826
if (!env) return DEFAULT_ENV;
29-
if (env === Environment.PRODUCTION) return Environment.PRODUCTION;
30-
if (env === Environment.SANDBOX) return Environment.SANDBOX;
31-
return DEFAULT_ENV;
27+
if (!Object.values(Environment).includes(env as Environment)) return DEFAULT_ENV;
28+
return env as Environment;
3229
}
3330

3431
function getValidBoolean(defaultValue: boolean, value?: string): boolean {

packages/checkout/widgets-lib/src/widgets/ImmutableWebComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export abstract class ImmutableWebComponent extends HTMLElement {
4646
this.updateCheckout();
4747
}
4848

49-
private parseWidgetConfig(widgetsConfig?: string):StrongCheckoutWidgetsConfig {
49+
private parseWidgetConfig(widgetsConfig?: string): StrongCheckoutWidgetsConfig {
5050
try {
5151
return withDefaultWidgetConfigs(
5252
JSON.parse(widgetsConfig || '{}'),

packages/checkout/widgets/src/definitions/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
export enum WidgetTheme {
55
LIGHT = 'light',
66
DARK = 'dark',
7-
CUSTOM = 'custom',
87
}
98

109
/**

0 commit comments

Comments
 (0)