Skip to content

Commit

Permalink
fix: filter tools we no longer have
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Sep 2, 2022
1 parent 7c0857e commit edc5fb8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
11 changes: 3 additions & 8 deletions packages/widget/src/pages/SettingsPage/EnabledBridgesSelect.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) => (
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 0.5 }}>
Expand All @@ -45,7 +40,7 @@ export const EnabledBridgesSelect: React.FC = () => {
</Box>
)}
>
{tools?.bridges?.map((bridge) => (
{tools.bridges.map((bridge: Bridge) => (
<MenuItem key={bridge.key} value={bridge.key}>
{bridge.name}
</MenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -45,7 +43,7 @@ export const EnabledExchangesSelect: React.FC = () => {
</Box>
)}
>
{tools?.exchanges.map((exchange) => (
{tools.exchanges.map((exchange) => (
<MenuItem key={exchange.key} value={exchange.key}>
{exchange.key}
</MenuItem>
Expand Down
11 changes: 9 additions & 2 deletions packages/widget/src/stores/settings/useSettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,25 @@ export const useSettingsStore = create<SettingsStore>()(
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,
),
)
.reduce((values, tool) => {
values[tool] = true;
return values;
}, state[`_enabled${toolType}`] as Record<string, boolean>);
// 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;
Expand Down

0 comments on commit edc5fb8

Please sign in to comment.