Skip to content

Commit

Permalink
Don't try to load hats tree if loaded DAO is stuck with the same hats…
Browse files Browse the repository at this point in the history
… tree id as the previously viewed DAO
  • Loading branch information
DarksightKellar committed Dec 19, 2024
1 parent 8ceb565 commit e72e445
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/hooks/DAO/loaders/useHatsTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,33 @@ const useHatsTree = () => {
);
const node = useDaoInfoStore();
const safeAddress = node.safe?.address;
const loadKey = useRef<string | null | undefined>(undefined);
const daoHatTreeloadKey = useRef<string | null>();
useEffect(() => {
const key = safeAddress && hatsTreeId ? `${safeAddress}:${hatsTreeId}` : null;

const previousSafeAddress = daoHatTreeloadKey.current?.split(':')[0];
const previousHatsTreeId = daoHatTreeloadKey.current?.split(':')[1];

if (
!!hatsTreeId &&
!!contextChainId &&
!!publicClient &&
key !== null &&
key !== loadKey.current
key !== daoHatTreeloadKey.current &&
previousHatsTreeId !== `${hatsTreeId}` // don't try to load hats tree if this new DAO is stuck with the same hats tree id as the previous DAO
) {
getHatsTree({
hatsTreeId,
contextChainId,
publicClient,
});

console.log('setting loadKey.current', key);
daoHatTreeloadKey.current = key;
} else if (!!safeAddress && safeAddress !== previousSafeAddress) {
// If the safe address changes, reset the load key
daoHatTreeloadKey.current = key;
}
loadKey.current = key;
}, [contextChainId, getHatsTree, hatsTreeId, publicClient, safeAddress]);
};

Expand Down

0 comments on commit e72e445

Please sign in to comment.