Skip to content

Commit

Permalink
fix: only reset appearance if not set via config
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Mar 6, 2023
1 parent 05eb5aa commit bc5f164
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import { useCallback, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Dialog } from '../../components/Dialog';
import { useTools } from '../../hooks';
import { useWidgetConfig } from '../../providers';
import { useSettingsStore } from '../../stores';

export const ResetSettingsButton: React.FC = () => {
const { t } = useTranslation();
const { tools } = useTools();
const config = useWidgetConfig();
const resetSettings = useSettingsStore((state) => state.reset);
const [open, setOpen] = useState(false);

Expand All @@ -25,6 +27,7 @@ export const ResetSettingsButton: React.FC = () => {
const handleReset = () => {
if (tools) {
resetSettings(
config,
tools.bridges.map((tool) => tool.key),
tools.exchanges.map((tool) => tool.key),
);
Expand Down
4 changes: 2 additions & 2 deletions packages/widget/src/stores/settings/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Order } from '@lifi/sdk';
import type { Appearance } from '../../types';
import type { Appearance, WidgetConfig } from '../../types';

export type ValueSetter<S> = <K extends keyof S>(
key: K,
Expand Down Expand Up @@ -39,7 +39,7 @@ export interface SettingsState extends SettingsProps {
tools: string[],
availableTools: string[],
): void;
reset(bridges: string[], exchanges: string[]): void;
reset(config: WidgetConfig, bridges: string[], exchanges: string[]): void;
}

export interface SendToWalletState {
Expand Down
3 changes: 2 additions & 1 deletion packages/widget/src/stores/settings/useSettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ export const useSettingsStore = create<SettingsState>(
return values;
}, {} as Record<string, boolean>),
})),
reset: (bridges, exchanges) => {
reset: (config, bridges, exchanges) => {
set(() => ({
...defaultSettings,
...defaultConfigurableSettings,
appearance: config.appearance ?? defaultSettings.appearance,
}));
get().initializeTools('Bridges', bridges, true);
get().initializeTools('Exchanges', exchanges, true);
Expand Down

0 comments on commit bc5f164

Please sign in to comment.