From dbed4eae8646efd4d24e726feef05d50bd1eed92 Mon Sep 17 00:00:00 2001 From: Kellar Date: Tue, 9 Apr 2024 14:08:09 +0100 Subject: [PATCH 1/3] dont cache dao name --- src/hooks/DAO/useDAOName.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/hooks/DAO/useDAOName.ts b/src/hooks/DAO/useDAOName.ts index 7e52d7fc36..e727006f23 100644 --- a/src/hooks/DAO/useDAOName.ts +++ b/src/hooks/DAO/useDAOName.ts @@ -32,7 +32,7 @@ export default function useDAOName({ address: address as Address, chainId, }); - const { setValue, getValue } = useLocalStorage(); + const { getValue } = useLocalStorage(); const getDaoName = useCallback(async () => { if (!address || !baseContracts) { @@ -69,10 +69,9 @@ export default function useDAOName({ } const { daoName } = latestEvent.args; - setValue(CacheKeys.DAO_NAME_PREFIX + address, daoName, 60); setDAORegistryName(daoName); } - }, [address, ensName, baseContracts, getValue, setValue, registryName]); + }, [address, ensName, baseContracts, getValue, registryName]); useEffect(() => { (async () => { @@ -93,7 +92,7 @@ export default function useDAOName({ * @dev this is used on initial load of the DAO Node, after subGraph data is loaded */ export function useLazyDAOName() { - const { setValue, getValue } = useLocalStorage(); + const { getValue } = useLocalStorage(); const provider = useEthersProvider(); const getDaoName = useCallback( async (_address: string, _registryName?: string | null): Promise => { @@ -105,19 +104,17 @@ export function useLazyDAOName() { // check if ens name resolves const ensName = await provider.lookupAddress(_address).catch(() => null); if (ensName) { - setValue(CacheKeys.DAO_NAME_PREFIX + _address, ensName, 5); return ensName; } } if (_registryName) { - setValue(CacheKeys.DAO_NAME_PREFIX + _address, _registryName, 5); return _registryName; } return createAccountSubstring(_address); }, - [getValue, setValue, provider], + [getValue, provider], ); return { getDaoName }; From 34de0dc97d2eb1bf84e7073a66d9dae92c03c227 Mon Sep 17 00:00:00 2001 From: Kellar Date: Tue, 9 Apr 2024 14:08:55 +0100 Subject: [PATCH 2/3] add fallback to dao name breadcrumb link when still fetching --- src/components/ui/page/Header/PageHeader.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/ui/page/Header/PageHeader.tsx b/src/components/ui/page/Header/PageHeader.tsx index c65b0507bd..6dace80ae1 100644 --- a/src/components/ui/page/Header/PageHeader.tsx +++ b/src/components/ui/page/Header/PageHeader.tsx @@ -11,6 +11,7 @@ import { } from '@chakra-ui/react'; import { ReactNode, useEffect, useState } from 'react'; import { DAO_ROUTES } from '../../../../constants/routes'; +import { createAccountSubstring } from '../../../../hooks/utils/useDisplayName'; import { useFractal } from '../../../../providers/App/AppProvider'; import { useNetworkConfig } from '../../../../providers/NetworkConfig/NetworkConfigProvider'; import AddressCopier from '../../links/AddressCopier'; @@ -56,7 +57,7 @@ function PageHeader({ if (hasDAOLink && daoAddress) { setLinks([ { - terminus: daoName || '', + terminus: daoName || (daoAddress && createAccountSubstring(daoAddress)) || '', path: DAO_ROUTES.dao.relative(addressPrefix, daoAddress), }, ...breadcrumbs, From 5e6d4ce79118f2e90678534e1a29397435c25c09 Mon Sep 17 00:00:00 2001 From: Kellar Date: Tue, 9 Apr 2024 21:13:16 +0100 Subject: [PATCH 3/3] Remove DAO_NAME_PREFIX cache key --- src/hooks/DAO/useDAOName.ts | 17 ++--------------- src/hooks/utils/cache/cacheDefaults.ts | 1 - 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/src/hooks/DAO/useDAOName.ts b/src/hooks/DAO/useDAOName.ts index e727006f23..cd5df65a7e 100644 --- a/src/hooks/DAO/useDAOName.ts +++ b/src/hooks/DAO/useDAOName.ts @@ -6,8 +6,6 @@ import { getEventRPC } from '../../helpers'; import { useFractal } from '../../providers/App/AppProvider'; import { useEthersProvider } from '../../providers/Ethers/hooks/useEthersProvider'; import { useNetworkConfig } from '../../providers/NetworkConfig/NetworkConfigProvider'; -import { CacheKeys } from '../utils/cache/cacheDefaults'; -import { useLocalStorage } from '../utils/cache/useLocalStorage'; import { createAccountSubstring } from '../utils/useDisplayName'; /** @@ -32,7 +30,6 @@ export default function useDAOName({ address: address as Address, chainId, }); - const { getValue } = useLocalStorage(); const getDaoName = useCallback(async () => { if (!address || !baseContracts) { @@ -45,11 +42,6 @@ export default function useDAOName({ return; } - const cachedName = getValue(CacheKeys.DAO_NAME_PREFIX + address); - if (cachedName) { - setDAORegistryName(cachedName); - return; - } const { fractalRegistryContract } = baseContracts; if (!fractalRegistryContract) { setDAORegistryName(createAccountSubstring(address)); @@ -71,7 +63,7 @@ export default function useDAOName({ const { daoName } = latestEvent.args; setDAORegistryName(daoName); } - }, [address, ensName, baseContracts, getValue, registryName]); + }, [address, ensName, baseContracts, registryName]); useEffect(() => { (async () => { @@ -92,14 +84,9 @@ export default function useDAOName({ * @dev this is used on initial load of the DAO Node, after subGraph data is loaded */ export function useLazyDAOName() { - const { getValue } = useLocalStorage(); const provider = useEthersProvider(); const getDaoName = useCallback( async (_address: string, _registryName?: string | null): Promise => { - const cachedName = getValue(CacheKeys.DAO_NAME_PREFIX + _address); - if (cachedName) { - return cachedName; - } if (provider) { // check if ens name resolves const ensName = await provider.lookupAddress(_address).catch(() => null); @@ -114,7 +101,7 @@ export function useLazyDAOName() { return createAccountSubstring(_address); }, - [getValue, provider], + [provider], ); return { getDaoName }; diff --git a/src/hooks/utils/cache/cacheDefaults.ts b/src/hooks/utils/cache/cacheDefaults.ts index efd89ad7ed..29c61ccd63 100644 --- a/src/hooks/utils/cache/cacheDefaults.ts +++ b/src/hooks/utils/cache/cacheDefaults.ts @@ -26,7 +26,6 @@ export enum CacheKeys { FAVORITES = 'favorites', AUDIT_WARNING_SHOWN = 'audit_warning_shown', ENS_RESOLVE_PREFIX = 'ens_resolve_', // name.eth -> 0x0 caching - DAO_NAME_PREFIX = 'dao_name_', DECODED_TRANSACTION_PREFIX = 'decode_trans_', MULTISIG_METADATA_PREFIX = 'm_m_', MASTER_COPY_PREFIX = 'master_copy_of_',