diff --git a/modules/web3/connections/index.ts b/modules/web3/connections/index.ts index a8407f195..a645d4eef 100644 --- a/modules/web3/connections/index.ts +++ b/modules/web3/connections/index.ts @@ -118,23 +118,25 @@ export const gnosisSafeConnection: Connection = { type: ConnectionType.GNOSIS_SAFE }; -const { TENDERLY_RPC_URL } = tenderlyTestnetData; - //mock connector -const { address, key } = TEST_ACCOUNTS.normal; -const rpcUrl = TENDERLY_RPC_URL || `https://virtual.mainnet.rpc.tenderly.co/${config.TENDERLY_RPC_KEY}`; -const provider = new providers.JsonRpcProvider(rpcUrl, SupportedChainId.TENDERLY); -const signer = new Wallet(key, provider); -const bridge = new CustomizedBridge(signer, provider); -bridge.setAddress(address); -const [web3Injected, web3InjectedHooks] = initializeConnector( - actions => new EIP1193({ provider: bridge, actions }) -); -const mockConnection: Connection = { - connector: web3Injected, - hooks: web3InjectedHooks, - type: ConnectionType.MOCK -}; +let mockConnection: Connection | undefined = undefined; +if (config.USE_MOCK_WALLET && process.env.NODE_ENV !== 'production') { + const { TENDERLY_RPC_URL } = tenderlyTestnetData; + const { address, key } = TEST_ACCOUNTS.normal; + const rpcUrl = TENDERLY_RPC_URL || `https://virtual.mainnet.rpc.tenderly.co/${config.TENDERLY_RPC_KEY}`; + const provider = new providers.JsonRpcProvider(rpcUrl, SupportedChainId.TENDERLY); + const signer = new Wallet(key, provider); + const bridge = new CustomizedBridge(signer, provider); + bridge.setAddress(address); + const [web3Injected, web3InjectedHooks] = initializeConnector( + actions => new EIP1193({ provider: bridge, actions }) + ); + mockConnection = { + connector: web3Injected, + hooks: web3InjectedHooks, + type: ConnectionType.MOCK + }; +} export const orderedConnectionTypes = [ @@ -143,7 +145,7 @@ export const orderedConnectionTypes = [ walletConnectConnection.type, metamaskConnection.type, networkConnection.type, - mockConnection.type + ...(mockConnection ? [mockConnection.type] : []) ]; const CONNECTIONS = [ @@ -152,7 +154,7 @@ const CONNECTIONS = [ walletConnectConnection, metamaskConnection, networkConnection, - mockConnection + ...(mockConnection ? [mockConnection] : []) ]; export function getConnection(c: Connector | ConnectionType): Connection { @@ -176,7 +178,7 @@ export function getConnection(c: Connector | ConnectionType): Connection { case ConnectionType.GNOSIS_SAFE: return gnosisSafeConnection; case ConnectionType.MOCK: - return mockConnection; + return mockConnection || networkConnection; default: return networkConnection; } diff --git a/modules/web3/constants/wallets.ts b/modules/web3/constants/wallets.ts index 890567ba1..5fd7edc3b 100644 --- a/modules/web3/constants/wallets.ts +++ b/modules/web3/constants/wallets.ts @@ -42,7 +42,7 @@ export const SUPPORTED_WALLETS: { } }; -if (config.USE_MOCK_WALLET) { +if (config.USE_MOCK_WALLET && process.env.NODE_ENV !== 'production') { SUPPORTED_WALLETS[SupportedConnectors.MOCK] = { name: SupportedConnectors.MOCK, connectionType: ConnectionType.MOCK diff --git a/modules/web3/hooks/useTenderlyWindowBindings.tsx b/modules/web3/hooks/useTenderlyWindowBindings.tsx index 31ba1998f..0a2d2c86d 100644 --- a/modules/web3/hooks/useTenderlyWindowBindings.tsx +++ b/modules/web3/hooks/useTenderlyWindowBindings.tsx @@ -18,13 +18,12 @@ import { EIP1193 } from '@web3-react/eip1193'; import { config } from 'lib/config'; export function useTenderlyWindowBindings(): void { - // TODO this should only run in non-prod environments // Define a window function that changes the account for testing purposes const { addConnector } = useContext(Web3ProviderContext); useEffect(() => { - if (typeof window !== 'undefined') { + if (typeof window !== 'undefined' && config.USE_MOCK_WALLET && process.env.NODE_ENV !== 'production') { (window as any).setAccount = (address: string, key: string) => { if (address && key) { try {