Skip to content

Commit

Permalink
feat: in non permitted chain flow, ensure the current active chain is…
Browse files Browse the repository at this point in the history
… not showing as part of the network list, since the user had the option to select it two screen prior in the navigation flow
  • Loading branch information
EtherWizard33 committed Nov 20, 2024
1 parent a293f1e commit fdb5432
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ const AccountPermissions = (props: AccountPermissionsProps) => {
)
}
isRenderedAsBottomSheet={isRenderedAsBottomSheet}
hideActiveNetwork={isNonDappNetworkSwitch}
/>
),
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ import { NetworkConnectMultiSelectorProps } from './NetworkConnectMultiSelector.
import Routes from '../../../../constants/navigation/Routes';
import Checkbox from '../../../../component-library/components/Checkbox';
import NetworkSelectorList from '../../../UI/NetworkSelectorList/NetworkSelectorList';
import { selectNetworkConfigurations } from '../../../../selectors/networkController';
import {
selectNetworkConfigurations,
selectChainId,
} from '../../../../selectors/networkController';
import Engine from '../../../../core/Engine';
import { PermissionKeys } from '../../../../core/Permissions/specifications';
import { CaveatTypes } from '../../../../core/Permissions/constants';
Expand All @@ -45,12 +48,14 @@ const NetworkConnectMultiSelector = ({
initialChainId,
selectedChainIds: propSelectedChainIds,
isInitializedWithPermittedChains = true,
hideActiveNetwork = false,
}: NetworkConnectMultiSelectorProps) => {
const { styles } = useStyles(styleSheet, { isRenderedAsBottomSheet });
const { navigate } = useNavigation();
const [selectedChainIds, setSelectedChainIds] = useState<string[]>([]);
const [originalChainIds, setOriginalChainIds] = useState<string[]>([]);
const networkConfigurations = useSelector(selectNetworkConfigurations);
const currentChainId = useSelector(selectChainId);

useEffect(() => {
if (propSelectedChainIds && !isInitializedWithPermittedChains) {
Expand Down Expand Up @@ -129,8 +134,8 @@ const NetworkConnectMultiSelector = ({
}
}, [selectedChainIds, hostname, onUserAction, onNetworksSelected]);

const networks = Object.entries(networkConfigurations).map(
([key, network]: [string, NetworkConfiguration]) => ({
const networks = Object.entries(networkConfigurations)
.map(([key, network]: [string, NetworkConfiguration]) => ({
id: key,
name: network.name,
rpcUrl: network.rpcEndpoints[network.defaultRpcEndpointIndex].url,
Expand All @@ -139,8 +144,11 @@ const NetworkConnectMultiSelector = ({
imageSource: getNetworkImageSource({
chainId: network?.chainId,
}),
}),
);
}))
.filter((network) => {
if (!hideActiveNetwork) return true;
return network.id !== currentChainId;
});

const onSelectNetwork = useCallback(
(clickedChainId) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export interface NetworkConnectMultiSelectorProps {
initialChainId?: string;
selectedChainIds?: string[];
isInitializedWithPermittedChains?: boolean;
hideActiveNetwork?: boolean;
}

0 comments on commit fdb5432

Please sign in to comment.