From bc5f16471235ffb6afe9bf39839375a1090323a6 Mon Sep 17 00:00:00 2001 From: Eugene Chybisov Date: Mon, 6 Mar 2023 17:12:56 +0800 Subject: [PATCH] fix: only reset appearance if not set via config --- .../widget/src/pages/SettingsPage/ResetSettingsButton.tsx | 3 +++ packages/widget/src/stores/settings/types.ts | 4 ++-- packages/widget/src/stores/settings/useSettingsStore.ts | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/widget/src/pages/SettingsPage/ResetSettingsButton.tsx b/packages/widget/src/pages/SettingsPage/ResetSettingsButton.tsx index 138141555..dfa77dccb 100644 --- a/packages/widget/src/pages/SettingsPage/ResetSettingsButton.tsx +++ b/packages/widget/src/pages/SettingsPage/ResetSettingsButton.tsx @@ -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); @@ -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), ); diff --git a/packages/widget/src/stores/settings/types.ts b/packages/widget/src/stores/settings/types.ts index b7e123c4a..43ce47190 100644 --- a/packages/widget/src/stores/settings/types.ts +++ b/packages/widget/src/stores/settings/types.ts @@ -1,5 +1,5 @@ import type { Order } from '@lifi/sdk'; -import type { Appearance } from '../../types'; +import type { Appearance, WidgetConfig } from '../../types'; export type ValueSetter = ( key: K, @@ -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 { diff --git a/packages/widget/src/stores/settings/useSettingsStore.ts b/packages/widget/src/stores/settings/useSettingsStore.ts index bd46f871a..3079c502d 100644 --- a/packages/widget/src/stores/settings/useSettingsStore.ts +++ b/packages/widget/src/stores/settings/useSettingsStore.ts @@ -91,10 +91,11 @@ export const useSettingsStore = create( return values; }, {} as Record), })), - 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);