Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(per-dapp-selected-network): restore per-dapp network picker in permissions view #13686

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

EtherWizard33
Copy link
Contributor

Description

This PR fixes the regression on PR #10788, and then restores the network picker functionality in the permissions view that was previously removed, while properly integrating with the per-dapp network selection feature. Changes include:

Add a touchable favicon to the permission summary header that enables network
switching for dapps. This combines the dapp's identity (favicon/token) with
network selection in a single interactive component.

  • Replace static WebsiteIcon with touchable BadgeWrapper pattern
  • Add network badge to indicate current network
  • Enable network switching via network selector bottom sheet
  • Add fallback to AvatarToken when favicon unavailable
  • Guard implementation behind per-dapp network selection feature flag
  • Preserve original WebsiteIcon when feature disabled
  • Add proper network info display in permissions view
  • Integrate with @metamask/selected-network-controller for per-dapp network state

Related issues

Contributes to: https://github.com/MetaMask/MetaMask-planning/issues/4104

Manual testing steps

Testing:

  1. Enable feature flags below if they are not enabled already
  2. Connect to a dapp and verify network picker appears in permissions view
  3. Switch networks and verify correct network displays for that specific dapp
  4. Verify network switching works properly and modal dismisses correctly
  5. Verify network info displays correctly in permissions view

Make sure to include all env vars:

export MM_MULTICHAIN_V1_ENABLED="true"
export MM_CHAIN_PERMISSIONS="true"
export MM_PER_DAPP_SELECTED_NETWORK="true"
export MULTICHAIN_V1="true"

Screenshots/Recordings

Before After
Screenshot 2024-04-18 at 3 56 43 PM Screenshot 2024-04-18 at 3 56 43 PM

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

EtherWizard33 and others added 13 commits February 19, 2025 19:05
…ature can work when its feature flags are enabled

make sure to include all env vars:
export MM_MULTICHAIN_V1_ENABLED="true"
export MM_CHAIN_PERMISSIONS="true"
export MM_PER_DAPP_SELECTED_NETWORK="1"
export MULTICHAIN_V1="true"
- Replace direct checks of process.env.MM_PER_DAPP_SELECTED_NETWORK in AccountPermissionsConnected.tsx with the isPerDappSelectedNetworkEnabled function.
- Update ethereum-chain-utils.js to use isPerDappSelectedNetworkEnabled when switching networks.
- Modify selectedNetworkController selectors to use isPerDappSelectedNetworkEnabled for feature flag checks.
- Add the isPerDappSelectedNetworkEnabled utility in util/networks/index.js.

This change centralizes the per-DApp network logic for better consistency and maintainability.
Add a touchable favicon to the permission summary header that enables network
switching for dapps. This combines the dapp's identity (favicon/token) with
network selection in a single interactive component.

- Replace static WebsiteIcon with touchable BadgeWrapper pattern
- Add network badge to indicate current network
- Enable network switching via network selector bottom sheet
- Add fallback to AvatarToken when favicon unavailable
- Guard implementation behind per-dapp network selection feature flag
- Preserve original WebsiteIcon when feature disabled

This matches the interaction pattern from AccountPermissionsConnected,
providing a consistent way to manage dapp-specific networks across the app.
…flag

The domain logo container view was incorrectly placed outside the per-dapp network
feature flag check. This change moves the container view inside the feature flag
condition to ensure consistent UI behavior when the feature is enabled/disabled.

- Moved View wrapper inside isPerDappSelectedNetworkEnabled() check
- Simplified conditional rendering logic
- Maintains existing functionality but with proper feature flag control
…permission sumamry is displayed, keep showing the WebsiteIcon rather than the AvatarFavicon.
…1Enabled rather than its 'corresponding' env variable MULTICHAIN_V1
@EtherWizard33 EtherWizard33 added Run Smoke E2E Triggers smoke e2e on Bitrise team-wallet-ux labels Feb 24, 2025
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

Copy link
Contributor

https://bitrise.io/ Bitrise

🔄🔄🔄 pr_smoke_e2e_pipeline started on Bitrise...🔄🔄🔄

Commit hash: e7fa261
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/4f65be5a-ae35-4448-8715-34c3d577eb2f

Note

  • This comment will auto-update when build completes
  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
56.8% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@EtherWizard33
Copy link
Contributor Author

EtherWizard33 commented Feb 24, 2025

Status: after QA tested Alex Donesky's per dapp work, in hope of getting per do to switch like on his video

  1. different bugs are reported on different dapps, some during switching some during confirming
  2. of these bugs, the one closest to a complete dapp transaction flow working is on pancakeswap where the confirmation displayed the wrong network (displayed global wallet network and its balance etc), but when accepting the transaction the transaction was made on the per dapp network.
  3. Confirmations team, codeowner of confirmations screens like this one, offered to answer questions but wont do the fix
  4. Point 2. above seems the lowest hanging fruit at this time, and the one to get working

We can see the following are not as expected:

  • In the 'From:' box, the network name, network badge, and balance are from main net, not from Linea as expected
  • EDIT: still working on it, got some the per dapp network showing as expected but still working on account balance (of the From token), to show for the network of the dapp rather than the one from the wallet, i've put the latest status in the 'After' column below.
Before (wallet on 0x1, dapp on Linea) After (still working on it)
Screenshot 2024-04-18 at 3 56 43 PM Screenshot 2024-04-18 at 3 56 43 PM

@EtherWizard33 EtherWizard33 added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Feb 25, 2025
Remove the permission check for non-permitted network flows in dapps, paving the way for the per-dapp-selected-network feature. Temporary screens handling these flows are pending removal upon feature completion.
- Replace global network selectors with origin-specific useNetworkInfo hook
- Update network name and image source to be origin-aware
- Update test snapshot for network name changes
- Add origin prop to AccountFromToInfoCard for per-dapp network info
- Add debug logs for transaction review flow
@EtherWizard33
Copy link
Contributor Author

EtherWizard33 commented Feb 27, 2025

In regards to switching from the wallet, 008 bug pointed it didnt, but per dapp, it looks like it does as expected

dapp chain switches from wallet
Screenshot 2024-04-18 at 3 56 43 PM Screenshot 2024-04-18 at 3 56 43 PM

Comment on lines +57 to +59
// FIXME: this could be the wrong selector, probably needs to be per dapp (per origin)
// console.log('>>> AddressFrom origin', origin);
const { networkName, networkImageSource } = useNetworkInfo(origin);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 if you're passing in the origin here, the useNetworkInfo selector should be selecting the correct state based on that parameter. Is the comment outdated?

Comment on lines +146 to +178
return isPerDappSelectedNetworkEnabled() ? (
<View style={[styles.domainLogoContainer, styles.assetLogoContainer]}>
<TouchableOpacity
onPress={switchNetwork}
testID={ConnectedAccountsSelectorsIDs.NETWORK_PICKER}
>
<BadgeWrapper
badgeElement={
<Badge
variant={BadgeVariant.Network}
name={networkName}
imageSource={networkImageSource}
/>
}
>
{icon ? (
<AvatarFavicon
imageSource={{
uri: typeof icon === 'string' ? icon : icon?.uri,
}}
size={AvatarSize.Md}
/>
) : (
<AvatarToken
name={iconTitle}
isHaloEnabled
size={AvatarSize.Md}
/>
)}
</BadgeWrapper>
</TouchableOpacity>
</View>
) : (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this conditional required? Not understanding what's changed here. Could you explain?

@@ -700,8 +642,6 @@ export const BrowserTab: React.FC<BrowserTabProps> = ({
name: siteInfo.title,
url: getMaskedUrl(siteInfo.url, sessionENSNamesRef.current),
});

checkTabPermissions();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this no longer required?

} else {
const { networkClientId } = rpcEndpoints[defaultRpcEndpointIndex];
try {
await MultichainNetworkController.setActiveNetwork(networkClientId);
} catch (error) {
Logger.error(new Error(`Error in setActiveNetwork: ${error}`));
Logger.error(new Error(`Error i setActiveNetwork: ${error}`));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 whats this change about?

const relevantNetworkClientId =
domainNetworkClientId || globalNetworkClientId;

const relevantChainId = chainIdToUse || chainId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const relevantChainId = chainIdToUse || chainId;
const relevantChainId = chainIdToUse || globalChainId;

@@ -77,6 +83,34 @@ const selectProviderNetworkImageSource = createSelector(
}),
);

const selectChainIdToUse = createSelector(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const selectChainIdToUse = createSelector(
const selectOriginSelectedChainId = createSelector(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Run Smoke E2E Triggers smoke e2e on Bitrise team-wallet-ux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants