Skip to content

Commit

Permalink
Fix preload, web3Modal config
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonmanRolls committed Jan 25, 2024
1 parent 5a77e69 commit f8ab0d3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 31 deletions.
15 changes: 7 additions & 8 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import EnteryourDelegate from "./pages/EnteryourDelegate";
import Home from "./pages/Home";
import { useGetDelegates, useQueryString } from "./utils/hooks";
import { initWeb3Read } from "./web3modal";
import { initWeb3Read, rpcUrl } from "./web3modal";

const PROJECT_ID = "02f438d1701ea8029113972850066224";

Expand All @@ -35,14 +35,14 @@ const mainnet = {
name: "Ethereum",
currency: "ETH",
explorerUrl: "https://etherscan.io",
rpcUrl: "https://cloudflare-eth.com",
rpcUrl: rpcUrl,
};

const metadata = {
name: "My Website",
description: "My Website description",
url: "https://mywebsite.com",
icons: ["https://avatars.mywebsite.com/"],
name: "ENS Delegation App",
description: "Delegate your ENS name to a delegate of your choice",
url: "https://delegate.ens.domains",
icons: ["https://delegate.ens.domains/favicon-32x32.png"],
};

createWeb3Modal({
Expand Down Expand Up @@ -156,8 +156,6 @@ function App() {
}
}, [address]);

useGetDelegates(isConnected);

return (
<>
<Header />
Expand Down Expand Up @@ -196,6 +194,7 @@ function App() {

function Index() {
useInit();
useGetDelegates();
return (
<Router>
<App />
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const Header = () => {
)}
</RightContainer>
</HeaderContainerInner>
{network !== null && network !== 1 && <NetworkWarning />}
{isConnected && network !== null && network !== 1 && <NetworkWarning />}
</HeaderContainer>
);
};
Expand Down
15 changes: 7 additions & 8 deletions src/utils/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import ENSDelegateAbi from "../assets/abis/ENSDelegate.json";
import ENSTokenAbi from "../assets/abis/ENSToken.json";
import ReverseRecordsAbi from "../assets/abis/ReverseRecords.json";
import { getDelegateReferral } from "../pages/ENSConstitution/delegateHelpers";
import { getEthersProvider } from "../web3modal";
import { getEthersProvider, rpcUrl } from "../web3modal";
import {
ALLOCATION_ENDPOINT,
getENSDelegateContractAddress,
Expand Down Expand Up @@ -188,13 +188,15 @@ export const rankDelegates = (
return sortedList;
};

export const useGetDelegates = (isConnected) => {
export const useGetDelegates = () => {
const [delegates, setDelegates] = useState({});
const [loading, setLoading] = useState(true);
const { walletProvider } = useWeb3ModalProvider();

useEffect(() => {
const provider = getEthersProvider(walletProvider);
const provider =
getEthersProvider(walletProvider) ||
new ethers.providers.JsonRpcProvider(rpcUrl);

const run = async () => {
const delegateDataRaw = await Promise.all([
Expand Down Expand Up @@ -262,14 +264,11 @@ export const useGetDelegates = (isConnected) => {
};

try {
if (isConnected) {
run();
}
run();
} catch (error) {
console.error("Error getting delegates: ", error);
}
}, [isConnected]);

}, []);
delegatesReactive({ delegates, loading });
};

Expand Down
15 changes: 2 additions & 13 deletions src/utils/token.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
import { BigNumber, Contract, utils, ethers } from "ethers";
import { Contract, utils, ethers } from "ethers";
import { network } from "../apollo";
import ENSTokenAbi from "../assets/abis/ENSToken.json";
import MerkleAirdropAbi from "../assets/abis/MerkleAirdrop.json";
import ep2MerkleRoot from "../assets/root-ep2.json";
import merkleRoot from "../assets/root.json";
// import ShardedMerkleTree, { getIndex } from "../merkle";
import { getDelegateChoice } from "../pages/ENSConstitution/delegateHelpers";
import { getEthersProvider } from "../web3modal";
import {
DELEGATE_GAS_LIMIT,
GAS_LIMIT,
generateMerkleShardUrl,
getENSTokenContractAddress,
getMerkleAirdropContractAddress,
} from "./consts";
import { DELEGATE_GAS_LIMIT, getENSTokenContractAddress } from "./consts";
import { sendToDelegateJsonRpc } from "./utils";

export async function delegate(
Expand Down
3 changes: 2 additions & 1 deletion src/web3modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { ethers } from "ethers";

import { isConnected, network } from "./apollo";

export const rpcUrl = "https://web3.ens.domains/v1/mainnet";
export const rpcUrl =
"https://mainnet.infura.io/v3/4d6e2605d0b1497fad8373ba11ddee8c";

let ethersProvider;
let ensInstance;
Expand Down

0 comments on commit f8ab0d3

Please sign in to comment.