Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maintenance] Investigate extra requests useERC20Claim #1495

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/hooks/DAO/loaders/governance/useERC20Claim.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most DAOs won't have a ERC20Claim contract. (assumingly). Maybe we need a better way to check for claiming contract?

But for now. It did not have anything preventing it from reattempting the requests as the app's initial render settles. This update adds a loadkey to prevent additional loads.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useCallback } from 'react';
import { useEffect, useCallback, useRef } from 'react';
import { useFractal } from '../../../../providers/App/AppProvider';
import { FractalGovernanceAction } from '../../../../providers/App/governance/action';
import useSafeContracts from '../../../safe/useSafeContracts';
Expand All @@ -15,13 +15,19 @@ export function useERC20Claim() {
} = useFractal();
const baseContracts = useSafeContracts();
const loadTokenClaimContract = useCallback(async () => {
if (!baseContracts || !votesTokenContractAddress) return;
if (!baseContracts || !votesTokenContractAddress) {
return;
}
const { claimingMasterCopyContract } = baseContracts;

const votesTokenContract =
baseContracts.votesTokenMasterCopyContract.asProvider.attach(votesTokenContractAddress);

const approvalFilter = votesTokenContract.filters.Approval();
const approvals = await votesTokenContract.queryFilter(approvalFilter);
if (!approvals.length) return;
if (!approvals.length) {
return;
}
const possibleTokenClaimContract = claimingMasterCopyContract.asProvider.attach(
approvals[0].args[1],
);
Expand All @@ -39,11 +45,20 @@ export function useERC20Claim() {
payload: possibleTokenClaimContract,
});
}, [baseContracts, votesTokenContractAddress, action]);
const loadKey = useRef<string>();

useEffect(() => {
if (daoAddress) {
if (
daoAddress &&
votesTokenContractAddress &&
daoAddress + votesTokenContractAddress !== loadKey.current
) {
loadKey.current = daoAddress + votesTokenContractAddress;
loadTokenClaimContract();
}
}, [loadTokenClaimContract, daoAddress]);
if (!daoAddress || !votesTokenContractAddress) {
loadKey.current = undefined;
}
}, [loadTokenClaimContract, daoAddress, votesTokenContractAddress]);
return;
}