Skip to content

Commit

Permalink
Merge pull request #1530 from decentdao/1482-dao-name-doesnt-update-c…
Browse files Browse the repository at this point in the history
…orrectly

Fix DAO name doesn't update after edit
  • Loading branch information
DarksightKellar authored Apr 11, 2024
2 parents 7d72e7d + 5e6d4ce commit 711987c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/components/ui/page/Header/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 2 additions & 18 deletions src/hooks/DAO/useDAOName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -32,7 +30,6 @@ export default function useDAOName({
address: address as Address,
chainId,
});
const { setValue, getValue } = useLocalStorage();

const getDaoName = useCallback(async () => {
if (!address || !baseContracts) {
Expand All @@ -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));
Expand All @@ -69,10 +61,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, registryName]);

useEffect(() => {
(async () => {
Expand All @@ -93,31 +84,24 @@ 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 provider = useEthersProvider();
const getDaoName = useCallback(
async (_address: string, _registryName?: string | null): Promise<string> => {
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);
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],
[provider],
);

return { getDaoName };
Expand Down
1 change: 0 additions & 1 deletion src/hooks/utils/cache/cacheDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_',
Expand Down

0 comments on commit 711987c

Please sign in to comment.