Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DAO name doesn't update after edit #1530

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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