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: wallet_addEthereumChain does not attach a result under certain conditions #26726

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

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

Not a blocker, but curious how the JsonRpcEngine didn't end up throwing for this. AFAIK if we process all middlewares without a result we end up throwing an error?

Copy link
Member

Choose a reason for hiding this comment

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

It did throw an error in this case, and it was returned to the dapp. But the QueuedRequestController missed it for some reason.

But yeah, good point, how was this missed 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It actually did throw an error to the dapp as you can see in the after video

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But the QueuedRequestController missed it for some reason.

Yeah... we should investigate this. I can create a ticket

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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();
});
});