Skip to content

Commit 541cf0b

Browse files
committed
[TOOL-3259] Dashboard: Fix Claimable Module UI crashing on for ERC20 token currency set in claim condition (#6114)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on enhancing the `ClaimableModule` component by integrating the `useQuery` hook for fetching currency decimals and refining the logic for determining when to fetch this data. ### Detailed summary - Added `useQuery` to fetch currency decimals based on the `claimConditionCurrency`. - Refactored the logic to check if currency decimals should be fetched. - Updated the conditional rendering of fetched data in the `ClaimableModule`. - Made the "Add Claim Condition" button disabled based on `props.isOwnerAccount`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent c650221 commit 541cf0b

File tree

1 file changed

+33
-14
lines changed
  • apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/modules/components

1 file changed

+33
-14
lines changed

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/modules/components/Claimable.tsx

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { ToolTipLabel } from "@/components/ui/tooltip";
2626
import type { Account } from "@3rdweb-sdk/react/hooks/useApi";
2727
import { zodResolver } from "@hookform/resolvers/zod";
2828
import { useMutation } from "@tanstack/react-query";
29+
import { useQuery } from "@tanstack/react-query";
2930
import { TransactionButton } from "components/buttons/TransactionButton";
3031
import { addDays, fromUnixTime } from "date-fns";
3132
import { useAllChainsData } from "hooks/chains/allChains";
@@ -119,22 +120,39 @@ function ClaimableModule(props: ModuleInstanceProps) {
119120
claimConditionQuery.data?.startTimestamp === 0 &&
120121
claimConditionQuery.data?.endTimestamp === 0;
121122

122-
const currencyContract = getContract({
123-
address: claimConditionQuery.data?.currency || "",
124-
chain: props.contract.chain,
125-
client: props.contract.client,
126-
});
123+
const claimConditionCurrency = claimConditionQuery.data?.currency;
127124

128-
const shouldFetchTokenDecimals =
129-
claimConditionQuery.data &&
130-
claimConditionQuery.data?.currency !== ZERO_ADDRESS;
125+
const shouldFetchCurrencyDecimals =
126+
!!claimConditionCurrency && claimConditionCurrency !== ZERO_ADDRESS;
131127

132-
const currencyDecimalsQuery = useReadContract(decimals, {
133-
contract: currencyContract,
134-
queryOptions: {
135-
enabled: shouldFetchTokenDecimals,
128+
const currencyDecimalsQuery = useQuery({
129+
queryKey: [
130+
"currency-decimals",
131+
{
132+
contractAddress: props.contract.address,
133+
chainId: props.contract.chain.id,
134+
claimConditionCurrency,
135+
},
136+
],
137+
queryFn: async () => {
138+
if (!claimConditionCurrency) {
139+
throw new Error();
140+
}
141+
const currencyContract = getContract({
142+
address: claimConditionCurrency,
143+
chain: props.contract.chain,
144+
client: props.contract.client,
145+
});
146+
147+
const decimalsVal = await decimals({
148+
contract: currencyContract,
149+
});
150+
151+
return decimalsVal;
136152
},
153+
enabled: shouldFetchCurrencyDecimals,
137154
});
155+
138156
const tokenDecimalsQuery = useReadContract(decimals, {
139157
contract: contract,
140158
queryOptions: {
@@ -265,7 +283,7 @@ function ClaimableModule(props: ModuleInstanceProps) {
265283
// claim conditions data is present
266284
claimConditionQuery.data &&
267285
// token decimals is fetched if it should be fetched
268-
(shouldFetchTokenDecimals ? currencyDecimalsQuery.isFetched : true)
286+
(shouldFetchCurrencyDecimals ? currencyDecimalsQuery.isFetched : true)
269287
? {
270288
claimCondition: claimConditionQuery.data,
271289
currencyDecimals: currencyDecimalsQuery.data,
@@ -276,7 +294,7 @@ function ClaimableModule(props: ModuleInstanceProps) {
276294
tokenId,
277295
isLoading:
278296
claimConditionQuery.isLoading ||
279-
(!!shouldFetchTokenDecimals && currencyDecimalsQuery.isLoading),
297+
(!!shouldFetchCurrencyDecimals && currencyDecimalsQuery.isLoading),
280298
}}
281299
isOwnerAccount={!!ownerAccount}
282300
name={props.contractInfo.name}
@@ -565,6 +583,7 @@ function ClaimConditionSection(props: {
565583
onClick={() => setAddClaimConditionButtonClicked(true)}
566584
variant="outline"
567585
className="w-full"
586+
disabled={!props.isOwnerAccount}
568587
>
569588
Add Claim Condition
570589
</Button>

0 commit comments

Comments
 (0)