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: issue where wallet_addEtherumChain was incorrectly enforcing inclusion of a blockExplorerUrls property which is not required #26938

Merged
merged 2 commits into from
Sep 5, 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 @@ -120,6 +120,35 @@ describe('addEthereumChainHandler', () => {
expect(mocks.setActiveNetwork).toHaveBeenCalledWith(123);
});

it('creates a new networkConfiguration when called without "blockExplorerUrls" property', async () => {
const mocks = makeMocks({
permissionsFeatureFlagIsActive: false,
});
await addEthereumChainHandler(
{
origin: 'example.com',
params: [
{
chainId: CHAIN_IDS.OPTIMISM,
chainName: 'Optimism Mainnet',
rpcUrls: ['https://optimism.llamarpc.com'],
nativeCurrency: {
symbol: 'ETH',
decimals: 18,
},
iconUrls: ['https://optimism.icon.com'],
},
],
},
{},
jest.fn(),
jest.fn(),
mocks,
);
expect(mocks.upsertNetworkConfiguration).toHaveBeenCalledTimes(1);
expect(mocks.setActiveNetwork).toHaveBeenCalledTimes(1);
});

describe('if a networkConfiguration for the given chainId already exists', () => {
it('creates a new network configuration for the given chainid and switches to it if proposed networkConfiguration has a different rpcUrl from all existing networkConfigurations', async () => {
const mocks = makeMocks({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,18 @@ export function validateAddEthereumChainParams(params, end) {
};

const firstValidRPCUrl = rpcUrls.find((rpcUrl) => isLocalhostOrHttps(rpcUrl));
const firstValidBlockExplorerUrl =
blockExplorerUrls !== null && Array.isArray(blockExplorerUrls)
? blockExplorerUrls.find((blockExplorerUrl) =>
isLocalhostOrHttps(blockExplorerUrl),
)
: null;
const firstValidBlockExplorerUrl = Array.isArray(blockExplorerUrls)
? blockExplorerUrls.find((blockExplorerUrl) =>
isLocalhostOrHttps(blockExplorerUrl),
)
: null;

if (!firstValidRPCUrl) {
throw ethErrors.rpc.invalidParams({
message: `Expected an array with at least one valid string HTTPS url 'rpcUrls', Received:\n${rpcUrls}`,
});
}

if (blockExplorerUrls !== null && !firstValidBlockExplorerUrl) {
throw ethErrors.rpc.invalidParams({
message: `Expected null or array with at least one valid string HTTPS URL 'blockExplorerUrl'. Received: ${blockExplorerUrls}`,
});
}

if (typeof chainName !== 'string' || !chainName) {
throw ethErrors.rpc.invalidParams({
message: `Expected non-empty string 'chainName'. Received:\n${chainName}`,
Expand Down