Skip to content

Commit 7dc888e

Browse files
fix(networks): tabs background fix + refactoring
1 parent df401df commit 7dc888e

File tree

1 file changed

+25
-50
lines changed
  • apps/next/src/pages/Settings/components/NetworkManagement/components

1 file changed

+25
-50
lines changed

apps/next/src/pages/Settings/components/NetworkManagement/components/NetworksHome.tsx

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { FC, useMemo, useState } from 'react';
2-
import { useTranslation } from 'react-i18next';
1+
import { Page } from '@/components/Page';
32
import { Tab, TabMenu } from '@/components/TabMenu';
43
import {
54
getHexAlpha,
@@ -8,13 +7,14 @@ import {
87
Typography,
98
useTheme,
109
} from '@avalabs/k2-alpine';
11-
import { MdAdd } from 'react-icons/md';
1210
import { useAnalyticsContext, useNetworkContext } from '@core/ui';
11+
import { isEmpty } from 'lodash';
12+
import { FC, useMemo, useState } from 'react';
13+
import { useTranslation } from 'react-i18next';
14+
import { MdAdd } from 'react-icons/md';
1315
import { useHistory } from 'react-router-dom';
14-
import { SearchInput } from './SearchInput';
1516
import { NetworkToggleList } from './NetworkToggle/NetworkToggleList';
16-
import { Page } from '@/components/Page';
17-
import { isEmpty } from 'lodash';
17+
import { SearchInput } from './SearchInput';
1818

1919
type Tab = 'all' | 'custom';
2020

@@ -28,28 +28,16 @@ export const NetworksHome: FC = () => {
2828

2929
const [filter, setFilter] = useState('');
3030

31-
const filteredNetworks = useMemo(() => {
32-
return networks.filter((network) => {
33-
return (
34-
network.chainName.toLowerCase().includes(filter.toLowerCase()) ||
35-
network.chainId.toString().includes(filter)
36-
);
37-
});
38-
}, [networks, filter]);
39-
40-
const filteredCustomNetworks = useMemo(() => {
41-
return customNetworks.filter((network) => {
42-
return (
43-
network.chainName.toLowerCase().includes(filter.toLowerCase()) ||
44-
network.chainId.toString().includes(filter)
45-
);
46-
});
47-
}, [customNetworks, filter]);
31+
const currentNetworks = activeTab === 'all' ? networks : customNetworks;
4832

49-
const currentNetworks = useMemo(
50-
() => (activeTab === 'all' ? filteredNetworks : filteredCustomNetworks),
51-
[activeTab, filteredNetworks, filteredCustomNetworks],
52-
);
33+
const filteredNetworks = useMemo(() => {
34+
const normalizedFilter = filter.toLowerCase();
35+
return currentNetworks.filter(
36+
(network) =>
37+
network.chainName.toLowerCase().includes(normalizedFilter) ||
38+
network.chainId.toString().includes(filter),
39+
);
40+
}, [currentNetworks, filter]);
5341

5442
return (
5543
<Page
@@ -71,38 +59,32 @@ export const NetworksHome: FC = () => {
7159
</Stack>
7260

7361
{/* Content Area */}
74-
{isEmpty(currentNetworks) && filter ? (
62+
{isEmpty(filteredNetworks) && filter ? (
7563
<Stack
76-
sx={{
77-
height: '100%',
78-
alignItems: 'center',
79-
justifyContent: 'center',
80-
flexGrow: 1,
81-
}}
64+
height="100%"
65+
alignItems="center"
66+
justifyContent="center"
67+
flexGrow={1}
8268
>
83-
<Typography
84-
variant="h1"
85-
component="span"
86-
sx={{ mb: 2, fontWeight: 'medium' }}
87-
>
69+
<Typography variant="h1" component="span" mb={2} fontWeight="medium">
8870
🌵
8971
</Typography>
90-
<Typography variant="body3" sx={{ fontWeight: 600 }}>
72+
<Typography variant="body3" fontWeight={600}>
9173
{t('No results found')}
9274
</Typography>
9375
</Stack>
9476
) : (
95-
<NetworkToggleList networks={currentNetworks} />
77+
<NetworkToggleList networks={filteredNetworks} />
9678
)}
9779
{/* Sticky Bottom Tab Menu */}
9880
<Stack
99-
width="calc(100% + 24px)" // Compensate for container padding which we don't want applied here.
81+
width="calc(100vw - 12px)"
10082
gap={1}
10183
position="sticky"
10284
bottom={0}
10385
pt={3}
10486
pb={2}
105-
px={2} // Since we increased the width, we need to bump the padding too.
87+
px={2}
10688
sx={{
10789
background: `linear-gradient(180deg, ${getHexAlpha(theme.palette.alphaMatch.backdropSolid, 0)} 0%, ${theme.palette.alphaMatch.backdropSolid} 32.5%)`,
10890
}}
@@ -118,13 +100,6 @@ export const NetworksHome: FC = () => {
118100
capture('NetworkCustomTabClicked');
119101
}
120102
}}
121-
slotProps={{
122-
root: {
123-
style: {
124-
backgroundColor: 'transparent',
125-
},
126-
},
127-
}}
128103
>
129104
<Tab label={t('All networks')} value={'all' satisfies Tab} />
130105
<Tab label="Custom" value={'custom' satisfies Tab} />

0 commit comments

Comments
 (0)