Skip to content

Commit ab72092

Browse files
committed
Add enabled checks on all queries
1 parent ea7d300 commit ab72092

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

Diff for: src/widgets/bundledrop.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
} from "@chakra-ui/react";
2323
import { css, Global } from "@emotion/react";
2424
import { BigNumber, BigNumberish } from "ethers";
25-
import React, { useEffect, useMemo, useRef, useState } from "react";
25+
import React, { useEffect, useMemo, useState } from "react";
2626
import ReactDOM from "react-dom";
2727
import { IoDiamondOutline } from "react-icons/io5";
2828
import {
@@ -78,6 +78,7 @@ interface HeaderProps extends ModuleInProps {
7878
activeTab: Tab;
7979
setActiveTab: (tab: Tab) => void;
8080
tokenId: string;
81+
expectedChainId: number;
8182
}
8283

8384
const Header: React.FC<HeaderProps> = ({
@@ -86,9 +87,15 @@ const Header: React.FC<HeaderProps> = ({
8687
activeTab,
8788
setActiveTab,
8889
module,
90+
expectedChainId,
8991
tokenId,
9092
}) => {
9193
const address = useAddress();
94+
const [{ data: network }] = useNetwork();
95+
const chainId = useMemo(() => network?.chain?.id, [network]);
96+
97+
const isEnabled = !!module && !!address && chainId === expectedChainId
98+
9299
const activeButtonProps: ButtonProps = {
93100
borderBottom: "4px solid",
94101
borderBottomColor: "blue.500",
@@ -103,7 +110,7 @@ const Header: React.FC<HeaderProps> = ({
103110
async () => {
104111
return module?.getActiveClaimCondition(tokenId);
105112
},
106-
{ enabled: !!module && tokenId.length > 0 },
113+
{ enabled: isEnabled && tokenId.length > 0 },
107114
);
108115

109116
const owned = useQuery(
@@ -112,7 +119,7 @@ const Header: React.FC<HeaderProps> = ({
112119
return module?.balanceOf(address || "", tokenId);
113120
},
114121
{
115-
enabled: !!module && tokenId.length > 0 && !!address,
122+
enabled: isEnabled && tokenId.length > 0 && !!address,
116123
},
117124
);
118125

Diff for: src/widgets/drop.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,17 @@ interface HeaderProps extends ModuleInProps {
6464
tokenAddress?: string;
6565
activeTab: Tab;
6666
setActiveTab: (tab: Tab) => void;
67+
expectedChainId: number;
6768
}
6869

69-
const Header: React.FC<HeaderProps> = ({ sdk, tokenAddress, activeTab, setActiveTab, module }) => {
70+
const Header: React.FC<HeaderProps> = ({ sdk, expectedChainId, tokenAddress, activeTab, setActiveTab, module }) => {
7071
const address = useAddress();
72+
const [{ data: network }] = useNetwork();
73+
const chainId = useMemo(() => network?.chain?.id, [network]);
74+
75+
// Enable all queries
76+
const isEnabled = !!module && !!address && chainId === expectedChainId
77+
7178
const activeButtonProps: ButtonProps = {
7279
borderBottom: "4px solid",
7380
borderBottomColor: "blue.500",
@@ -517,6 +524,7 @@ const DropWidget: React.FC<DropWidgetProps> = ({
517524
>
518525
<Header
519526
sdk={sdk}
527+
expectedChainId={expectedChainId}
520528
tokenAddress={claimCondition.data?.currency}
521529
activeTab={activeTab}
522530
setActiveTab={(tab) => setActiveTab(tab)}

0 commit comments

Comments
 (0)