Skip to content

Commit

Permalink
fix: wallet_addEthereumChain does not attach a result under certa…
Browse files Browse the repository at this point in the history
…in conditions (#26726)

## **Description**

Fix issue where `wallet_addEthereumChain` does not attach a result to
the response object when the currently selected rpcUrl matches the
request.

This would cause the request to get "stuck" in the
`QueuedRequestController` queue, preventing the queue from progressing
and causing confusing behavior.

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

## **Related issues**

Fixes: #26706

## **Manual testing steps**

1. Go to https://chainlist.org/?chain=56&search=blast
2. Connect the wallet and add Blast Mainnet 
(For other chains it appears Chainlist cycles to the next rpcUrl you
don't have which avoids this bug, so use Blast)
3. After successfully adding the network, attempt to add Blast again.
Nothing should happen.
4. Then go to https://faucet.quicknode.com/blast/sepolia (or any dapp
where your wallet isn't already connected) and attempt to connect
5. You should be able to connect as usual

## **Screenshots/Recordings**

### **Before**


https://github.com/user-attachments/assets/b997027f-1c62-4279-87c6-0fe70989abb3


### **After**


https://github.com/user-attachments/assets/08307a88-8f6f-44cd-9b75-877aadb1805a


## **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
adonesky1 authored Aug 28, 2024
1 parent 46bf4e8 commit fb61b0f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ async function addEthereumChainHandler(
} else {
networkClientId = existingNetwork.id ?? existingNetwork.type;
const currentRpcUrl = getCurrentRpcUrl();

if (
currentChainIdForDomain === chainId &&
currentRpcUrl === firstValidRPCUrl
) {
res.result = null;
return end();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,4 +541,45 @@ describe('addEthereumChainHandler', () => {
}),
);
});

it('should add result set to null to response object if the requested rpcUrl (and chainId) is currently selected', async () => {
const CURRENT_RPC_CONFIG = createMockNonInfuraConfiguration();

const mocks = makeMocks({
permissionsFeatureFlagIsActive: false,
overrides: {
getCurrentChainIdForDomain: jest
.fn()
.mockReturnValue(CURRENT_RPC_CONFIG.chainId),
findNetworkConfigurationBy: jest
.fn()
.mockReturnValue(CURRENT_RPC_CONFIG),
getCurrentRpcUrl: jest.fn().mockReturnValue(CURRENT_RPC_CONFIG.rpcUrl),
},
});
const res = {};

await addEthereumChainHandler(
{
origin: 'example.com',
params: [
{
chainId: CURRENT_RPC_CONFIG.chainId,
chainName: 'Custom Network',
rpcUrls: [CURRENT_RPC_CONFIG.rpcUrl],
nativeCurrency: {
symbol: CURRENT_RPC_CONFIG.ticker,
decimals: 18,
},
blockExplorerUrls: ['https://custom.blockexplorer'],
},
],
},
res,
jest.fn(),
jest.fn(),
mocks,
);
expect(res.result).toBeNull();
});
});

0 comments on commit fb61b0f

Please sign in to comment.