Skip to content

Commit

Permalink
chore: remove unnecessary function declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
gratestas authored and 0xferit committed Jun 12, 2023
1 parent a23a778 commit 7259426
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
14 changes: 4 additions & 10 deletions src/data/ethereumProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,11 @@ export const networkMap = {
explorerURL: (address) => `https://etherscan.io/address/${address}`,
deployments: environment.networkMap["0x1"].deployments,
},
"0x5": {
name: "Ethereum Testnet Görli",
shortname: "Görli",
explorerURL: (address) => `https://goerli.etherscan.io/address/${address}`,
contractInstances: environment.networkMap["0x5"].contractInstances,
},
};

const LONGPOLLING_PERIOD_MS = 20000;

const isSupportedChain = (chainId) => Object.keys(networkMap).includes(chainId);
const isDeployedOn = (chainId) => networkMap[chainId].deployments !== null;
const initializeContract = (chainId) => new ethers.Contract(Object.keys(networkMap[chainId].deployments)[0], ABI);
const getDefaultNetwork = () => {
const defaultNetworkKeys = Object.keys(networkMap).filter((key) => networkMap[key].default);
Expand Down Expand Up @@ -91,7 +84,7 @@ const EthereumProvider = ({ children }) => {
useEffect(() => {
if (!chainId) return;

const isDeployed = isDeployedOn(chainId);
const isDeployed = networkMap[chainId].deployments !== null;
setDeployedOnThisChain(isDeployed);
if (isDeployed) setContractInstance(initializeContract(chainId));

Expand All @@ -111,14 +104,15 @@ const EthereumProvider = ({ children }) => {

const handleMessage = (message) => setBlockNumber(message.data.result.number);
const handleAccountsChange = (newAccounts) => setAccounts(newAccounts);

const handleChainChange = (targetChainId) => {
setMetamaskChainId(targetChainId);
if (!chainId) switchAppChain(targetChainId);
if (isSupportedChain(targetChainId)) setEthersProvider(new ethers.providers.Web3Provider(window.ethereum));
if (Object.keys(networkMap).includes(targetChainId))
setEthersProvider(new ethers.providers.Web3Provider(window.ethereum));
};

const switchAppChain = (targetChainId) => {
console.log("swithcing app chain");
setChainId(targetChainId);
};

Expand Down
7 changes: 0 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2236,13 +2236,6 @@ hastscript@^7.0.0:
property-information "^6.0.0"
space-separated-tokens "^2.0.0"

history@^5.2.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/history/-/history-5.3.0.tgz#1548abaa245ba47992f063a0783db91ef201c73b"
integrity sha512-ZqaKwjjrAYUYfLG+htGaIIZ4nioX2L70ZUMIFysS3xvBsSG4x/n1V6TXV3N8ZYNuFGlDirFg32T7B6WOUPDYcQ==
dependencies:
"@babel/runtime" "^7.7.6"

hmac-drbg@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"
Expand Down

0 comments on commit 7259426

Please sign in to comment.