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 1 commit
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 with no "blockExplorerUrls" property', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it('creates a new networkConfiguration when called with no "blockExplorerUrls" property', async () => {
it('creates a new networkConfiguration when called without "blockExplorerUrls" property', async () => {

Copy link
Contributor

Choose a reason for hiding this comment

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

nit of course

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done here cb9d89e

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 @@ -120,7 +120,7 @@ export function validateAddEthereumChainParams(params, end) {

const firstValidRPCUrl = rpcUrls.find((rpcUrl) => isLocalhostOrHttps(rpcUrl));
const firstValidBlockExplorerUrl =
blockExplorerUrls !== null && Array.isArray(blockExplorerUrls)
blockExplorerUrls && Array.isArray(blockExplorerUrls)
Copy link
Contributor

Choose a reason for hiding this comment

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

> Array.isArray(null)
false
> Array.isArray(undefined)
false
> Array.isArray(undefined)
false
> Array.isArray('')
false
> Array.isArray([])
true

Does the first part of the check need to be there in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like we can scrap it!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done here cb9d89e

? blockExplorerUrls.find((blockExplorerUrl) =>
isLocalhostOrHttps(blockExplorerUrl),
)
Expand All @@ -132,12 +132,6 @@ export function validateAddEthereumChainParams(params, end) {
});
}

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