Skip to content

Commit

Permalink
fix: set token network filter when adding network from dapp
Browse files Browse the repository at this point in the history
  • Loading branch information
sahar-fehri committed Dec 12, 2024
1 parent 7e40e3e commit 7c40d5a
Showing 1 changed file with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { ApprovalTypes } from '../../../core/RPCMethods/RPCMethodMiddleware';
import ApprovalModal from '../ApprovalModal';
import SwitchCustomNetwork from '../../UI/SwitchCustomNetwork';
import { networkSwitched } from '../../../actions/onboardNetwork';
import { useDispatch } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import Engine from '../../../core/Engine';
import { selectIsAllNetworks } from '../../../selectors/networkController';
import { selectTokenNetworkFilter } from '../../../selectors/preferencesController';
import { isPortfolioViewEnabled } from '../../../util/networks';

const SwitchChainApproval = () => {
const {
Expand All @@ -15,17 +19,40 @@ const SwitchChainApproval = () => {
} = useApprovalRequest();

const dispatch = useDispatch();
const isAllNetworks = useSelector(selectIsAllNetworks);
const tokenNetworkFilter = useSelector(selectTokenNetworkFilter);

const onConfirm = useCallback(() => {
defaultOnConfirm();

// If portfolio view is enabled should set network filter
if (isPortfolioViewEnabled()) {
const { PreferencesController } = Engine.context;
if (!isAllNetworks) {
PreferencesController.setTokenNetworkFilter({
[approvalRequest?.requestData?.chainId]: true,
});
} else {
PreferencesController.setTokenNetworkFilter({
...tokenNetworkFilter,
[approvalRequest?.requestData?.chainId]: true,
});
}
}

dispatch(
networkSwitched({
networkUrl: approvalRequest?.requestData?.rpcUrl,
networkStatus: true,
}),
);
}, [approvalRequest, defaultOnConfirm, dispatch]);
}, [
approvalRequest,
defaultOnConfirm,
dispatch,
isAllNetworks,
tokenNetworkFilter,
]);

if (approvalRequest?.type !== ApprovalTypes.SWITCH_ETHEREUM_CHAIN)
return null;
Expand Down

0 comments on commit 7c40d5a

Please sign in to comment.