Skip to content

Commit

Permalink
Move updating network specific buttons to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
Montoya committed Dec 20, 2024
1 parent a60f48d commit 82a175b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
8 changes: 8 additions & 0 deletions src/components/ppom/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ERC721_SAMPLE_CONTRACTS,
MALICIOUS_CONTRACT_ADDRESSES,
} from '../../onchain-sample-contracts';
import { isBaseNetworkId, isSepoliaNetworkId } from '../../utils';

export function ppomMaliciousTransactionsAndSignatures(parentContainer) {
parentContainer.insertAdjacentHTML(
Expand Down Expand Up @@ -136,6 +137,13 @@ export function ppomMaliciousTransactionsAndSignatures(parentContainer) {
maliciousSeaport.disabled = true;
});

document.addEventListener('newNetwork', function (e) {
mintSepoliaERC20.hidden = !isSepoliaNetworkId(e.detail.networkId);
maliciousContractInteractionButton.hidden =
isBaseNetworkId(e.detail.networkId) ||
isSepoliaNetworkId(e.detail.networkId);
});

// Malicious raw ETH transfer
maliciousRawEthButton.onclick = async () => {
const result = await globalContext.provider.request({
Expand Down
21 changes: 4 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import MetaMaskOnboarding from '@metamask/onboarding';
// eslint-disable-next-line camelcase
import { ethers } from 'ethers';
import { isSepoliaNetworkId, isBaseNetworkId } from './utils';
import {
handleSdkConnect,
handleWalletConnect,
Expand Down Expand Up @@ -191,11 +190,6 @@ ppomMaliciousTransactionsAndSignatures(ppomRow);
ppomMaliciousBatchingAndQueueing(ppomRow);
ppomMaliciousWarningBypasses(ppomRow);

const mintSepoliaERC20 = document.getElementById('mintSepoliaERC20');
const maliciousContractInteractionButton = document.getElementById(
'maliciousContractInteractionButton',
);

const encryptionSection = document.createElement('section');
mainContainer.appendChild(encryptionSection);
encryptDecryptComponent(encryptionSection);
Expand Down Expand Up @@ -453,20 +447,13 @@ const handleNewChain = (chainId) => {
}
};

function toggleSepoliaMintButton(networkId) {
mintSepoliaERC20.hidden = !isSepoliaNetworkId(networkId);
}

function toggleMaliciousContractInteractionButton(networkId) {
maliciousContractInteractionButton.hidden =
isBaseNetworkId(networkId) || isSepoliaNetworkId(networkId);
}

function handleNewNetwork(networkId) {
networkDiv.innerHTML = networkId;

toggleSepoliaMintButton(networkId);
toggleMaliciousContractInteractionButton(networkId);
const changeEvent = new CustomEvent('newNetwork', {
detail: { networkId },
});
document.dispatchEvent(changeEvent);
}

const getNetworkAndChainId = async () => {
Expand Down

0 comments on commit 82a175b

Please sign in to comment.