Skip to content

Commit

Permalink
fix: check chain before simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
yum0e committed Jul 21, 2023
1 parent 9ce14f3 commit fdfe053
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 3 additions & 7 deletions front/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ export default function Home() {
chain: CHAIN,
});

// Get the SismoConnectConfig and Sismo Connect Request from the contract
// Set react state accordingly to display the Sismo Connect Button

useEffect(() => {
setClaimError(error);
if (!responseBytes) return;
Expand All @@ -88,7 +85,6 @@ export default function Home() {
/* ************ Handle the airdrop claim button click ******************* */
async function claimAirdrop() {
if (!address) return;
setClaimError("");
try {
if (chain?.id !== CHAIN.id) await switchNetworkAsync?.(CHAIN.id);
setPageState("confirmingTransaction");
Expand Down Expand Up @@ -159,7 +155,7 @@ export default function Home() {
/>
</>
)}
{claimError !== null && (
{!claimError && (
<div className="status-wrapper">
{pageState == "responseReceived" && (
<button onClick={() => claimAirdrop()}>{"Claim"}</button>
Expand All @@ -179,8 +175,8 @@ export default function Home() {
{claimError.slice(0, 50) ===
'The contract function "balanceOf" returned no data' && (
<p style={{ color: "#0BDA51" }}>
Please restart your frontend with "yarn dev" command and try again, it will
automatically deploy a new contract for you!
If you are developing on a local fork, please restart your frontend with "yarn
dev" command and try again, it will automatically deploy a new contract for you!
</p>
)}
{claimError.slice(0, 16) === "Please switch to" && (
Expand Down
9 changes: 7 additions & 2 deletions front/src/utils/useContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ export default function useContract({

/* ************* Handle simulateContract call & chain errors ************ */
useEffect(() => {
if (currentChain?.id !== chain.id) return setError(`Please switch to ${chain.name} network`);
if (currentChain?.id !== chain.id) {
return setError(`Please switch to ${chain.name} network`);
}
setError("");
}, [currentChain]);

useEffect(() => {
if (!isConnected) return;
if (!responseBytes) return;
if (currentChain?.id !== chain.id) {
return setError(`Please switch to ${chain.name} network`);
}
async function simulate() {
try {
await airdropContract.simulate.claimWithSismo([responseBytes, address]);
Expand All @@ -64,7 +69,7 @@ export default function useContract({
}

simulate();
}, [address, isConnected, responseBytes]);
}, [address, isConnected, responseBytes, currentChain]);

async function waitingForTransaction(
hash: `0x${string}`
Expand Down

0 comments on commit fdfe053

Please sign in to comment.