From 714860790674f8031aa8f8d2e047b2d3f1a31dc5 Mon Sep 17 00:00:00 2001 From: Alex Donesky Date: Thu, 10 Feb 2022 13:23:52 -0600 Subject: [PATCH] remove infura project_id from networks form field (#13539) * remove infura project_id from networks form field --- shared/constants/network.js | 16 ++++++++-------- test/e2e/tests/custom-rpc-history.spec.js | 3 +-- .../networks-form/networks-form.test.js | 6 ++++-- .../networks-tab/networks-tab.constants.js | 16 ++++++---------- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/shared/constants/network.js b/shared/constants/network.js index a678dd270..252669635 100644 --- a/shared/constants/network.js +++ b/shared/constants/network.js @@ -41,14 +41,14 @@ export const GOERLI_DISPLAY_NAME = 'Goerli'; export const LOCALHOST_DISPLAY_NAME = 'Localhost 8545'; const infuraProjectId = process.env.INFURA_PROJECT_ID; -const getRpcUrl = (network) => - `https://${network}.infura.io/v3/${infuraProjectId}`; - -export const ROPSTEN_RPC_URL = getRpcUrl('ropsten'); -export const RINKEBY_RPC_URL = getRpcUrl('rinkeby'); -export const KOVAN_RPC_URL = getRpcUrl('kovan'); -export const MAINNET_RPC_URL = getRpcUrl('mainnet'); -export const GOERLI_RPC_URL = getRpcUrl('goerli'); +export const getRpcUrl = ({ network, excludeProjectId = false }) => + `https://${network}.infura.io/v3/${excludeProjectId ? '' : infuraProjectId}`; + +export const ROPSTEN_RPC_URL = getRpcUrl({ network: ROPSTEN }); +export const RINKEBY_RPC_URL = getRpcUrl({ network: RINKEBY }); +export const KOVAN_RPC_URL = getRpcUrl({ network: KOVAN }); +export const MAINNET_RPC_URL = getRpcUrl({ network: MAINNET }); +export const GOERLI_RPC_URL = getRpcUrl({ network: GOERLI }); export const LOCALHOST_RPC_URL = 'http://localhost:8545'; export const ETH_SYMBOL = 'ETH'; diff --git a/test/e2e/tests/custom-rpc-history.spec.js b/test/e2e/tests/custom-rpc-history.spec.js index 101bb7757..025f7f53a 100644 --- a/test/e2e/tests/custom-rpc-history.spec.js +++ b/test/e2e/tests/custom-rpc-history.spec.js @@ -75,8 +75,7 @@ describe('Stores custom RPC history', function () { await driver.press('#password', driver.Key.ENTER); // duplicate network - const duplicateRpcUrl = - 'https://mainnet.infura.io/v3/00000000000000000000000000000000'; + const duplicateRpcUrl = 'https://mainnet.infura.io/v3/'; await driver.clickElement('.network-display'); diff --git a/ui/pages/settings/networks-tab/networks-form/networks-form.test.js b/ui/pages/settings/networks-tab/networks-form/networks-form.test.js index b1a170894..5c2a5d5ce 100644 --- a/ui/pages/settings/networks-tab/networks-form/networks-form.test.js +++ b/ui/pages/settings/networks-tab/networks-form/networks-form.test.js @@ -4,7 +4,7 @@ import { fireEvent, screen } from '@testing-library/react'; import nock from 'nock'; import { renderWithProvider } from '../../../../../test/jest/rendering'; import { defaultNetworksData } from '../networks-tab.constants'; -import { MAINNET_RPC_URL } from '../../../../../shared/constants/network'; +import { MAINNET, getRpcUrl } from '../../../../../shared/constants/network'; import NetworksForm from '.'; const renderComponent = (props) => { @@ -169,7 +169,9 @@ describe('NetworkForm Component', () => { expect(await screen.findByText('Invalid RPC URL')).toBeInTheDocument(); await fireEvent.change(rpcUrlField, { - target: { value: MAINNET_RPC_URL }, + target: { + value: getRpcUrl({ network: MAINNET, excludeProjectId: true }), + }, }); expect( diff --git a/ui/pages/settings/networks-tab/networks-tab.constants.js b/ui/pages/settings/networks-tab/networks-tab.constants.js index 26a57c7bd..c1479394a 100644 --- a/ui/pages/settings/networks-tab/networks-tab.constants.js +++ b/ui/pages/settings/networks-tab/networks-tab.constants.js @@ -1,19 +1,15 @@ import { GOERLI, GOERLI_CHAIN_ID, - GOERLI_RPC_URL, KOVAN, KOVAN_CHAIN_ID, - KOVAN_RPC_URL, MAINNET, MAINNET_CHAIN_ID, - MAINNET_RPC_URL, RINKEBY, RINKEBY_CHAIN_ID, - RINKEBY_RPC_URL, ROPSTEN, ROPSTEN_CHAIN_ID, - ROPSTEN_RPC_URL, + getRpcUrl, } from '../../../../shared/constants/network'; const defaultNetworksData = [ @@ -21,7 +17,7 @@ const defaultNetworksData = [ labelKey: MAINNET, iconColor: '#29B6AF', providerType: MAINNET, - rpcUrl: MAINNET_RPC_URL, + rpcUrl: getRpcUrl({ network: MAINNET, excludeProjectId: true }), chainId: MAINNET_CHAIN_ID, ticker: 'ETH', blockExplorerUrl: 'https://etherscan.io', @@ -30,7 +26,7 @@ const defaultNetworksData = [ labelKey: ROPSTEN, iconColor: '#FF4A8D', providerType: ROPSTEN, - rpcUrl: ROPSTEN_RPC_URL, + rpcUrl: getRpcUrl({ network: ROPSTEN, excludeProjectId: true }), chainId: ROPSTEN_CHAIN_ID, ticker: 'ETH', blockExplorerUrl: 'https://ropsten.etherscan.io', @@ -39,7 +35,7 @@ const defaultNetworksData = [ labelKey: RINKEBY, iconColor: '#F6C343', providerType: RINKEBY, - rpcUrl: RINKEBY_RPC_URL, + rpcUrl: getRpcUrl({ network: RINKEBY, excludeProjectId: true }), chainId: RINKEBY_CHAIN_ID, ticker: 'ETH', blockExplorerUrl: 'https://rinkeby.etherscan.io', @@ -48,7 +44,7 @@ const defaultNetworksData = [ labelKey: GOERLI, iconColor: '#3099f2', providerType: GOERLI, - rpcUrl: GOERLI_RPC_URL, + rpcUrl: getRpcUrl({ network: GOERLI, excludeProjectId: true }), chainId: GOERLI_CHAIN_ID, ticker: 'ETH', blockExplorerUrl: 'https://goerli.etherscan.io', @@ -57,7 +53,7 @@ const defaultNetworksData = [ labelKey: KOVAN, iconColor: '#9064FF', providerType: KOVAN, - rpcUrl: KOVAN_RPC_URL, + rpcUrl: getRpcUrl({ network: KOVAN, excludeProjectId: true }), chainId: KOVAN_CHAIN_ID, ticker: 'ETH', blockExplorerUrl: 'https://kovan.etherscan.io',