diff --git a/packages/widget/src/pages/SettingsPage/EnabledBridgesSelect.tsx b/packages/widget/src/pages/SettingsPage/EnabledBridgesSelect.tsx index 070e847c1..b3a666bf6 100644 --- a/packages/widget/src/pages/SettingsPage/EnabledBridgesSelect.tsx +++ b/packages/widget/src/pages/SettingsPage/EnabledBridgesSelect.tsx @@ -1,3 +1,4 @@ +import type { Bridge } from '@lifi/sdk'; import { KeyboardArrowDown as KeyboardArrowDownIcon } from '@mui/icons-material'; import { Box, Chip, FormControl, MenuItem, Skeleton } from '@mui/material'; import { useTranslation } from 'react-i18next'; @@ -26,13 +27,7 @@ export const EnabledBridgesSelect: React.FC = () => { IconComponent={KeyboardArrowDownIcon} value={enabledBridges ?? []} onChange={(event) => { - if (tools?.bridges) { - setTools( - 'Bridges', - event.target.value as string[], - tools.bridges, - ); - } + setTools('Bridges', event.target.value as string[], tools.bridges); }} renderValue={(selected) => ( @@ -45,7 +40,7 @@ export const EnabledBridgesSelect: React.FC = () => { )} > - {tools?.bridges?.map((bridge) => ( + {tools.bridges.map((bridge: Bridge) => ( {bridge.name} diff --git a/packages/widget/src/pages/SettingsPage/EnabledExchangesSelect.tsx b/packages/widget/src/pages/SettingsPage/EnabledExchangesSelect.tsx index 064fbe5b6..06bbd0205 100644 --- a/packages/widget/src/pages/SettingsPage/EnabledExchangesSelect.tsx +++ b/packages/widget/src/pages/SettingsPage/EnabledExchangesSelect.tsx @@ -24,13 +24,11 @@ export const EnabledExchangesSelect: React.FC = () => { placeholder={t(`settings.selectEnabledExchanges`)} value={enabledExchanges ?? []} onChange={(event) => { - if (tools?.exchanges) { - setTools( - 'Exchanges', - event.target.value as string[], - tools.exchanges, - ); - } + setTools( + 'Exchanges', + event.target.value as string[], + tools.exchanges, + ); }} MenuProps={{ elevation: 2 }} IconComponent={KeyboardArrowDownIcon} @@ -45,7 +43,7 @@ export const EnabledExchangesSelect: React.FC = () => { )} > - {tools?.exchanges.map((exchange) => ( + {tools.exchanges.map((exchange) => ( {exchange.key} diff --git a/packages/widget/src/stores/settings/useSettingsStore.ts b/packages/widget/src/stores/settings/useSettingsStore.ts index 050df14c7..dd042ed36 100644 --- a/packages/widget/src/stores/settings/useSettingsStore.ts +++ b/packages/widget/src/stores/settings/useSettingsStore.ts @@ -32,11 +32,12 @@ export const useSettingsStore = create()( return; } if (state[`_enabled${toolType}`]) { - state[`_enabled${toolType}`] = tools + // Add a new tools + const enabledTools = tools .filter( (tool) => !Object.prototype.hasOwnProperty.call( - state._enabledBridges, + state[`_enabled${toolType}`], tool, ), ) @@ -44,6 +45,12 @@ export const useSettingsStore = create()( values[tool] = true; return values; }, state[`_enabled${toolType}`] as Record); + // Filter tools we no longer have + state[`_enabled${toolType}`] = Object.fromEntries( + Object.entries(enabledTools).filter(([key]) => + tools.includes(key), + ), + ); } else { state[`_enabled${toolType}`] = tools.reduce((values, tool) => { values[tool] = true;