Skip to content

Commit

Permalink
fix: Fix snaps permission connection for CHAIN_PERMISSIONS feature …
Browse files Browse the repository at this point in the history
…flag (#27459)

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

Recent permission flow changes introduced behind the `CHAIN_PERMISSIONS`
feature flag have broken permission connection for Snaps. This PR fixes
it by removing an incorrect forced route direct in the permission
connection component.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27459?quickstart=1)

## **Related issues**

Fixes: #26635

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.
  • Loading branch information
jiexi authored and micaelae committed Oct 2, 2024
1 parent 5b755be commit 20accfa
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,16 @@ export default class PermissionPageContainer extends Component {
);

const permittedChainsPermission =
_request.permissions[PermissionNames.permittedChains];
_request.permissions?.[PermissionNames.permittedChains];
const approvedChainIds = permittedChainsPermission?.caveats.find(
(caveat) => caveat.type === CaveatTypes.restrictNetworkSwitching,
)?.value;

const request = {
..._request,
permissions: { ..._request.permissions },
...(_request.permissions.eth_accounts && { approvedAccounts }),
...(_request.permissions[PermissionNames.permittedChains] && {
...(_request.permissions?.eth_accounts && { approvedAccounts }),
...(_request.permissions?.[PermissionNames.permittedChains] && {
approvedChainIds,
}),
};
Expand Down
91 changes: 45 additions & 46 deletions ui/pages/permissions-connect/permissions-connect.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ export default class PermissionConnect extends Component {
history.replace(DEFAULT_ROUTE);
return;
}
if (process.env.CHAIN_PERMISSIONS) {
history.replace(confirmPermissionPath);
}
// if this is an incremental permission request for permitted chains, skip the account selection
if (
permissionsRequest?.diff?.permissionDiffMap?.[
Expand Down Expand Up @@ -341,33 +338,8 @@ export default class PermissionConnect extends Component {
<Route
path={connectPath}
exact
render={() => (
<ChooseAccount
accounts={accounts}
nativeCurrency={nativeCurrency}
selectAccounts={(addresses) => this.selectAccounts(addresses)}
selectNewAccountViaModal={(handleAccountClick) => {
showNewAccountModal({
onCreateNewAccount: (address) =>
handleAccountClick(address),
newAccountNumber,
});
}}
addressLastConnectedMap={addressLastConnectedMap}
cancelPermissionsRequest={(requestId) =>
this.cancelPermissionsRequest(requestId)
}
permissionsRequestId={permissionsRequestId}
selectedAccountAddresses={selectedAccountAddresses}
targetSubjectMetadata={targetSubjectMetadata}
/>
)}
/>
<Route
path={confirmPermissionPath}
exact
render={() =>
process.env.CHAIN_PERMISSIONS && !permissionsRequest?.diff ? (
process.env.CHAIN_PERMISSIONS ? (
<ConnectPage
rejectPermissionsRequest={(requestId) =>
this.cancelPermissionsRequest(requestId)
Expand All @@ -378,31 +350,58 @@ export default class PermissionConnect extends Component {
approveConnection={this.approveConnection}
/>
) : (
<PermissionPageContainer
request={permissionsRequest || {}}
approvePermissionsRequest={(...args) => {
approvePermissionsRequest(...args);
this.redirect(true);
<ChooseAccount
accounts={accounts}
nativeCurrency={nativeCurrency}
selectAccounts={(addresses) =>
this.selectAccounts(addresses)
}
selectNewAccountViaModal={(handleAccountClick) => {
showNewAccountModal({
onCreateNewAccount: (address) =>
handleAccountClick(address),
newAccountNumber,
});
}}
rejectPermissionsRequest={(requestId) =>
addressLastConnectedMap={addressLastConnectedMap}
cancelPermissionsRequest={(requestId) =>
this.cancelPermissionsRequest(requestId)
}
selectedAccounts={accounts.filter((account) =>
selectedAccountAddresses.has(account.address),
)}
permissionsRequestId={permissionsRequestId}
selectedAccountAddresses={selectedAccountAddresses}
targetSubjectMetadata={targetSubjectMetadata}
history={this.props.history}
connectPath={connectPath}
snapsInstallPrivacyWarningShown={
snapsInstallPrivacyWarningShown
}
setSnapsInstallPrivacyWarningShownStatus={
setSnapsInstallPrivacyWarningShownStatus
}
/>
)
}
/>
<Route
path={confirmPermissionPath}
exact
render={() => (
<PermissionPageContainer
request={permissionsRequest || {}}
approvePermissionsRequest={(...args) => {
approvePermissionsRequest(...args);
this.redirect(true);
}}
rejectPermissionsRequest={(requestId) =>
this.cancelPermissionsRequest(requestId)
}
selectedAccounts={accounts.filter((account) =>
selectedAccountAddresses.has(account.address),
)}
targetSubjectMetadata={targetSubjectMetadata}
history={this.props.history}
connectPath={connectPath}
snapsInstallPrivacyWarningShown={
snapsInstallPrivacyWarningShown
}
setSnapsInstallPrivacyWarningShownStatus={
setSnapsInstallPrivacyWarningShownStatus
}
/>
)}
/>
<Route
path={snapsConnectPath}
exact
Expand Down

0 comments on commit 20accfa

Please sign in to comment.