Skip to content

Commit

Permalink
fix issue where wallet_addEthereumChain does not attach a result to t…
Browse files Browse the repository at this point in the history
…he response object when the currently selected rpcUrl matches the request
  • Loading branch information
adonesky1 committed Aug 28, 2024
1 parent d9e989e commit 2cf7859
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ async function addEthereumChainHandler(
currentChainIdForDomain === chainId &&
currentRpcUrl === firstValidRPCUrl
) {
res.result = null;
return end();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
CHAIN_IDS,
NETWORK_TYPES,
} from '../../../../../shared/constants/network';
import * as chainUtils from './ethereum-chain-utils';
import addEthereumChain from './add-ethereum-chain';

const NON_INFURA_CHAIN_ID = '0x123456789';
Expand Down Expand Up @@ -541,4 +542,42 @@ describe('addEthereumChainHandler', () => {
}),
);
});

it('should add result set to null to response object if the requested rpcUrl (and chainId) is currently selected', async () => {
jest.spyOn(chainUtils, 'findExistingNetwork').mockReturnValue({
chainId: '0x1',
rpcUrl: 'https://mainnet.infura.io/v3/',
ticker: 'ETH',
});

const mocks = makeMocks({
permissionsFeatureFlagIsActive: false,
overrides: {
getCurrentChainIdForDomain: jest.fn().mockReturnValue('0x1'),
},
});
const res = {};
await addEthereumChainHandler(
{
origin: 'example.com',
params: [
{
chainId: CHAIN_IDS.MAINNET,
chainName: 'Ethereum Mainnet',
rpcUrls: ['https://mainnet.infura.io/v3/'],
nativeCurrency: {
symbol: 'ETH',
decimals: 18,
},
blockExplorerUrls: ['https://etherscan.io'],
},
],
},
res,
jest.fn(),
jest.fn(),
mocks,
);
expect(res.result).toBeNull();
});
});

0 comments on commit 2cf7859

Please sign in to comment.