diff --git a/packages/uiweb/src/lib/components/chatAndNotification/MinimisedModalHeader.tsx b/packages/uiweb/src/lib/components/chatAndNotification/MinimisedModalHeader.tsx index 24a7205e0..627a4b56b 100644 --- a/packages/uiweb/src/lib/components/chatAndNotification/MinimisedModalHeader.tsx +++ b/packages/uiweb/src/lib/components/chatAndNotification/MinimisedModalHeader.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useEffect, useState } from 'react'; +import React, { useContext } from 'react'; import styled from 'styled-components'; import { MaximizeIcon } from '../../icons/Maximize'; import { NewChatIcon } from '../../icons/NewChat'; @@ -13,12 +13,13 @@ import { } from '../../context'; import type { PushSubTabs, PushTabs } from '../../types'; import { PUSH_SUB_TABS, PUSH_TABS } from '../../types'; -import { pCAIP10ToWallet, resolveWeb3Name, shortenText } from '../../helpers'; +import { pCAIP10ToWallet, shortenText } from '../../helpers'; import { PushSubTabTitle } from '../../config'; import { Tooltip } from '../reusables'; import type { ChatAndNotificationMainContextType } from '../../context/chatAndNotification/chatAndNotificationMainContext'; import type { ChatMainStateContextType } from '../../context/chatAndNotification/chat/chatMainStateContext'; import { ChatSnap } from './modal/sidebar/chatSidebar/ChatSnap'; +import { useDomianName } from '../../hooks'; type MinimisedModalHeaderPropType = { onMaximizeMinimizeToggle: () => void; @@ -49,7 +50,6 @@ export const UnreadChats = ({ }; export const MessageBoxHeader = () => { - const [web3Name, setWeb3Name] = useState(null); const { activeTab, setActiveTab, setActiveSubTab, activeSubTab } = useContext(ChatAndNotificationMainContext); const { selectedChatId, chatsFeed, requestsFeed, searchedChats, setSearchedChats, setSelectedChatId } = @@ -60,6 +60,7 @@ export const MessageBoxHeader = () => { chatsFeed[selectedChatId as string] || requestsFeed[selectedChatId as string] || (Object.keys(searchedChats || {}).length ? searchedChats![selectedChatId as string] : null); + const web3Name = useDomianName(selectedChat?.did, env); const handleBack = () => { if ( @@ -78,16 +79,6 @@ export const MessageBoxHeader = () => { } }; - useEffect(() => { - (async () => { - try { - const result = await resolveWeb3Name(selectedChat?.did, env); - if (result) setWeb3Name(result); - } catch (e) { - //console.debug(e); - } - })(); - }); return selectedChat ? (
= ({ chat, id, modalOpen }) => { - const [web3Name, setWeb3Name] = useState(null); const { setSelectedChatId } = useContext(ChatMainStateContext); const { env } = useContext(ChatAndNotificationPropsContext); - + const web3Name = useDomianName(chat?.did, env); const isMobile = useDeviceWidthCheck(425); const digitsToDisplay = chat?.name ? (isMobile ? 15 : 30) : isMobile ? 6 : 8; @@ -88,17 +87,6 @@ export const ChatSnap: React.FC = ({ chat, id, modalOpen }) => }; const open = modalOpen === undefined ? true : modalOpen; - useEffect(() => { - (async () => { - try { - const result = await resolveWeb3Name(chat?.did, env); - if (result) setWeb3Name(result); - } catch (e) { - //console.debug(e); - } - })(); - }); - return ( { + const [name, setName] = useState(null); + + const getName = useCallback(async () => { + const result = await resolveWeb3Name(address, env); + if (result) setName(result); + }, [address, env]); + + useEffect(() => { + (async () => { + await getName(); + })(); + }, [address, env]); + + return name; +};