Skip to content

Commit

Permalink
Merge pull request #907 from makerdao/master
Browse files Browse the repository at this point in the history
Master -> Develop
  • Loading branch information
tyler17 authored Aug 5, 2024
2 parents ee3a14c + ea3a39d commit 14a8643
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
40 changes: 21 additions & 19 deletions modules/web3/connections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<EIP1193>(
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<EIP1193>(
actions => new EIP1193({ provider: bridge, actions })
);
mockConnection = {
connector: web3Injected,
hooks: web3InjectedHooks,
type: ConnectionType.MOCK
};
}


export const orderedConnectionTypes = [
Expand All @@ -143,7 +145,7 @@ export const orderedConnectionTypes = [
walletConnectConnection.type,
metamaskConnection.type,
networkConnection.type,
mockConnection.type
...(mockConnection ? [mockConnection.type] : [])
];

const CONNECTIONS = [
Expand All @@ -152,7 +154,7 @@ const CONNECTIONS = [
walletConnectConnection,
metamaskConnection,
networkConnection,
mockConnection
...(mockConnection ? [mockConnection] : [])
];

export function getConnection(c: Connector | ConnectionType): Connection {
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/web3/constants/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions modules/web3/hooks/useTenderlyWindowBindings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 14a8643

Please sign in to comment.