Skip to content

Commit

Permalink
Refactor useHatsTree and useKeyValuePairs hooks to remove unused vari…
Browse files Browse the repository at this point in the history
…ables and improve logic
  • Loading branch information
Da-Colon committed Dec 9, 2024
1 parent 9bb71ce commit 3d324ce
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/hooks/DAO/loaders/useHatsTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,23 @@ import { SablierV2LockupLinearAbi } from '../../../assets/abi/SablierV2LockupLin
import { useFractal } from '../../../providers/App/AppProvider';
import useIPFSClient from '../../../providers/App/hooks/useIPFSClient';
import { useNetworkConfig } from '../../../providers/NetworkConfig/NetworkConfigProvider';
import { useDaoInfoStore } from '../../../store/daoInfo/useDaoInfoStore';
import { DecentHatsError } from '../../../store/roles/rolesStoreUtils';
import { useRolesStore } from '../../../store/roles/useRolesStore';
import { SablierPayment } from '../../../types/roles';
import { convertStreamIdToBigInt } from '../../streams/useCreateSablierStream';
import { CacheExpiry, CacheKeys } from '../../utils/cache/cacheDefaults';
import { getValue, setValue } from '../../utils/cache/useLocalStorage';
import { useParseSafeAddress } from '../useParseSafeAddress';

const hatsSubgraphClient = new HatsSubgraphClient({});

const useHatsTree = () => {
const { t } = useTranslation('roles');
const { safeAddress } = useParseSafeAddress();
const {
governanceContracts: {
linearVotingErc20WithHatsWhitelistingAddress,
linearVotingErc721WithHatsWhitelistingAddress,
},
} = useFractal();
const { safe } = useDaoInfoStore();
const {
hatsTreeId,
contextChainId,
Expand Down Expand Up @@ -297,10 +293,10 @@ const useHatsTree = () => {
}, [hatsTree, updateRolesWithStreams, getPaymentStreams, streamsFetched]);

useEffect(() => {
if (safeAddress && safe?.address && safeAddress !== safe.address && hatsTree) {
if (!hatsTreeId && !!hatsTree) {
resetHatsStore();
}
}, [resetHatsStore, safeAddress, safe?.address, hatsTree]);
}, [resetHatsStore, hatsTree, hatsTreeId]);
};

export { useHatsTree };
7 changes: 1 addition & 6 deletions src/hooks/DAO/useKeyValuePairs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { abis } from '@fractal-framework/fractal-contracts';
import { hatIdToTreeId } from '@hatsprotocol/sdk-v1-core';
import { useEffect } from 'react';
import { useSearchParams } from 'react-router-dom';
import { Address, GetContractEventsReturnType, getContract } from 'viem';
import { usePublicClient } from 'wagmi';
import { logError } from '../../helpers/errorLogging';
Expand Down Expand Up @@ -99,14 +98,11 @@ const useKeyValuePairs = () => {
contracts: { keyValuePairs, sablierV2LockupLinear },
} = useNetworkConfig();
const { setHatKeyValuePairData } = useRolesStore();
const [searchParams] = useSearchParams();

const safeAddress = node.safe?.address;

useEffect(() => {
const safeParam = searchParams.get('dao');

if (!publicClient || !safeAddress || safeAddress !== safeParam?.split(':')[1]) {
if (!safeAddress || !publicClient) {
return;
}

Expand Down Expand Up @@ -160,7 +156,6 @@ const useKeyValuePairs = () => {
keyValuePairs,
safeAddress,
publicClient,
searchParams,
setHatKeyValuePairData,
sablierV2LockupLinear,
]);
Expand Down

0 comments on commit 3d324ce

Please sign in to comment.