Skip to content

Commit

Permalink
fix: clean up + bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
salimtb committed Dec 13, 2024
1 parent 0d4ba12 commit bcad469
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion app/components/Views/NetworkSelector/NetworkSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import BottomSheet, {
} from '../../../component-library/components/BottomSheets/BottomSheet';
import { IconName } from '../../../component-library/components/Icons/Icon';
import { useSelector } from 'react-redux';
import { selectNetworkConfigurations } from '../../../selectors/networkController';
import {
selectIsAllNetworks,
selectNetworkConfigurations,
} from '../../../selectors/networkController';
import { selectShowTestNetworks } from '../../../selectors/preferencesController';
import Networks, {
getAllNetworks,
Expand Down Expand Up @@ -123,6 +126,7 @@ const NetworkSelector = () => {
const styles = createStyles(colors);
const sheetRef = useRef<BottomSheetRef>(null);
const showTestNetworks = useSelector(selectShowTestNetworks);
const isAllNetwork = useSelector(selectIsAllNetworks);

const networkConfigurations = useSelector(selectNetworkConfigurations);

Expand Down Expand Up @@ -173,6 +177,23 @@ const NetworkSelector = () => {
isReadOnly: false,
});

const setTokenNetworkFilter = useCallback(
(chainId: string) => {
const isPopularNetwork =
chainId === CHAIN_IDS.MAINNET ||
chainId === CHAIN_IDS.LINEA_MAINNET ||
PopularList.some((network) => network.chainId === chainId);

const { PreferencesController } = Engine.context;
if (!isAllNetwork && isPopularNetwork) {
PreferencesController.setTokenNetworkFilter({
[chainId]: true,
});
}
},
[isAllNetwork],
);

const onRpcSelect = useCallback(
async (clientId: string, chainId: `0x${string}`) => {
const { NetworkController } = Engine.context;
Expand Down Expand Up @@ -262,6 +283,7 @@ const NetworkSelector = () => {
await NetworkController.setActiveNetwork(networkClientId);
}

setTokenNetworkFilter(chainId);
sheetRef.current?.onCloseBottomSheet();
endTrace({ name: TraceName.SwitchCustomNetwork });
endTrace({ name: TraceName.NetworkSwitch });
Expand Down Expand Up @@ -376,6 +398,7 @@ const NetworkSelector = () => {
networkConfiguration.defaultRpcEndpointIndex
].networkClientId ?? type;

setTokenNetworkFilter(networkConfiguration.chainId);
NetworkController.setActiveNetwork(clientId);
closeRpcModal();
AccountTrackerController.refresh();
Expand Down

0 comments on commit bcad469

Please sign in to comment.