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

Tenderly updates #906

Merged
merged 2 commits into from
Aug 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
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
Loading