Skip to content

Commit

Permalink
Merge pull request #1495 from decentdao/reduce-request-useERC20Claim
Browse files Browse the repository at this point in the history
[Maintenance] Investigate extra requests `useERC20Claim`
  • Loading branch information
Da-Colon authored Mar 26, 2024
2 parents 057f911 + 7b34ac6 commit 9e3e137
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/hooks/DAO/loaders/governance/useERC20Claim.ts
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;
}

0 comments on commit 9e3e137

Please sign in to comment.