Skip to content

Commit af41680

Browse files
authored
fix: handle wallet:{namespace} request (#36459)
<!-- 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** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> This Pr fixes the handling of `wallet:{namespace}` permission requests. Previously when there is an existing chain permission, this gets ignored. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/36459?quickstart=1) ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: Fix requesting additional wallet namespace request when there is an existing permission. ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to matcha.xyz 2. Connect with a solana account 3. Then connect with an evm account 4. See that both are connected. ## **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** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Properly handles wallet:{namespace} permission requests by auto-including matching non-test chains for EIP-1193 requests and updating default selected chains. > > - **Multichain Connect Page (`ui/pages/.../multichain-accounts-connect-page.tsx`)**: > - **Wallet namespace handling**: Detects `wallet:{namespace}` requests; when `isEip1193Request`, auto-includes additional non-test chains whose namespaces match `requestedNamespacesWithoutWallet`, merging with supported requested chains and de-duplicating. > - **State/props**: Extracts `isEip1193Request` from `request.metadata`. > - **Memo deps**: Updates dependencies to reflect new inputs (`isEip1193Request`, `requestedNamespacesWithoutWallet`, `currentlySelectedNetwork.chainId`). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 4f80d44. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent aaf52e0 commit af41680

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

ui/pages/multichain-accounts/multichain-accounts-connect-page/multichain-accounts-connect-page.tsx

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export const MultichainAccountsConnectPage: React.FC<
132132
const [pageMode, setPageMode] = useState<MultichainAccountsConnectPageMode>(
133133
MultichainAccountsConnectPageMode.Summary,
134134
);
135+
const { isEip1193Request } = request.metadata ?? {};
135136
const { formatCurrencyWithMinThreshold } = useFormatters();
136137
const allBalances = useSelector(selectBalanceForAllWallets);
137138
const wallets = allBalances?.wallets;
@@ -238,9 +239,30 @@ export const MultichainAccountsConnectPage: React.FC<
238239
...testNetworkConfigurations,
239240
].map(({ caipChainId }) => caipChainId);
240241

241-
const supportedRequestedCaipChainIds = requestedCaipChainIds.filter(
242-
(requestedCaipChainId) =>
243-
allNetworksList.includes(requestedCaipChainId as CaipChainId),
242+
const walletRequest =
243+
requestedCaipChainIds.filter(
244+
(caipChainId) =>
245+
parseCaipChainId(caipChainId).namespace === KnownCaipNamespace.Wallet,
246+
).length > 0;
247+
248+
let additionalChains: CaipChainId[] = [];
249+
if (walletRequest && isEip1193Request) {
250+
additionalChains = nonTestNetworkConfigurations
251+
.map(({ caipChainId }) => caipChainId)
252+
.filter((caipChainId) =>
253+
requestedNamespacesWithoutWallet.includes(
254+
parseCaipChainId(caipChainId).namespace,
255+
),
256+
);
257+
}
258+
259+
const supportedRequestedCaipChainIds = Array.from(
260+
new Set([
261+
...requestedCaipChainIds.filter((requestedCaipChainId) =>
262+
allNetworksList.includes(requestedCaipChainId as CaipChainId),
263+
),
264+
...additionalChains,
265+
]),
244266
);
245267

246268
// If globally selected network is a test network, include that in the default selected networks for connection request
@@ -278,12 +300,14 @@ export const MultichainAccountsConnectPage: React.FC<
278300

279301
return defaultSelectedNetworkList;
280302
}, [
281-
alreadyConnectedCaipChainIds,
282-
currentlySelectedNetwork,
283-
testNetworkConfigurations,
284303
nonTestNetworkConfigurations,
304+
testNetworkConfigurations,
285305
requestedCaipChainIds,
306+
isEip1193Request,
307+
currentlySelectedNetwork.chainId,
286308
requestedNamespaces,
309+
requestedNamespacesWithoutWallet,
310+
alreadyConnectedCaipChainIds,
287311
]);
288312

289313
const {

0 commit comments

Comments
 (0)