Skip to content

Commit

Permalink
fix: added common resolveweb3 for domain name
Browse files Browse the repository at this point in the history
  • Loading branch information
mishramonalisha76 committed Sep 5, 2024
1 parent cf8e91e commit d51767f
Show file tree
Hide file tree
Showing 5 changed files with 17,127 additions and 23,186 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext } from 'react';
import React, { useContext, useEffect, useState } from 'react';
import styled from 'styled-components';
import { MaximizeIcon } from '../../icons/Maximize';
import { NewChatIcon } from '../../icons/NewChat';
Expand All @@ -13,9 +13,7 @@ import {
} from '../../context';
import type { PushSubTabs, PushTabs } from '../../types';
import { PUSH_SUB_TABS, PUSH_TABS } from '../../types';
import { useResolveWeb3Name } from '../../hooks';
import { pCAIP10ToWallet, shortenText } from '../../helpers';
import { ethers } from 'ethers';
import { pCAIP10ToWallet, resolveWeb3Name, shortenText } from '../../helpers';
import { PushSubTabTitle } from '../../config';
import { Tooltip } from '../reusables';
import type { ChatAndNotificationMainContextType } from '../../context/chatAndNotification/chatAndNotificationMainContext';
Expand Down Expand Up @@ -51,40 +49,23 @@ export const UnreadChats = ({
};

export const MessageBoxHeader = () => {
const [web3Name, setWeb3Name] = useState<string | null>(null);
const { activeTab, setActiveTab, setActiveSubTab, activeSubTab } =
useContext<ChatAndNotificationMainContextType>(
ChatAndNotificationMainContext
);
const {
selectedChatId,
chatsFeed,
requestsFeed,
web3NameList,
searchedChats,
setSearchedChats,
setSelectedChatId,
} = useContext<ChatMainStateContextType>(ChatMainStateContext);
useContext<ChatAndNotificationMainContextType>(ChatAndNotificationMainContext);
const { selectedChatId, chatsFeed, requestsFeed, searchedChats, setSearchedChats, setSelectedChatId } =
useContext<ChatMainStateContextType>(ChatMainStateContext);
const { env } = useContext<any>(ChatAndNotificationPropsContext);
const { spamNotifsFeed } = useContext<any>(NotificationMainStateContext);
const selectedChat =
chatsFeed[selectedChatId as string] ||
requestsFeed[selectedChatId as string] ||
(Object.keys(searchedChats || {}).length
? searchedChats![selectedChatId as string]
: null);
useResolveWeb3Name(selectedChat?.did, env);
const walletLowercase = pCAIP10ToWallet(selectedChat?.did)?.toLowerCase();
const checksumWallet = walletLowercase
? ethers.utils.getAddress(walletLowercase)
: null;
const web3Name = checksumWallet ? web3NameList[checksumWallet.toLowerCase()] : null;
(Object.keys(searchedChats || {}).length ? searchedChats![selectedChatId as string] : null);

const handleBack = () => {
if (
activeSubTab &&
((activeSubTab === PUSH_SUB_TABS.REQUESTS &&
Object.keys(requestsFeed || {}).length) ||
(activeSubTab === PUSH_SUB_TABS.SPAM &&
Object.keys(spamNotifsFeed || {}).length))
((activeSubTab === PUSH_SUB_TABS.REQUESTS && Object.keys(requestsFeed || {}).length) ||
(activeSubTab === PUSH_SUB_TABS.SPAM && Object.keys(spamNotifsFeed || {}).length))
) {
setActiveSubTab(PUSH_SUB_TABS[activeSubTab as PushSubTabs]);
} else {
Expand All @@ -96,8 +77,21 @@ export const MessageBoxHeader = () => {
setSearchedChats(null);
}
};

useEffect(() => {
(async () => {
try {
const result = await resolveWeb3Name(selectedChat?.did, env);
if (result) setWeb3Name(result);
} catch (e) {
//console.debug(e);
}
})();
});
return selectedChat ? (
<Section gap="12px" padding='23px 2px'
<Section
gap="12px"
padding="23px 2px"
>
<Div
width="16px"
Expand All @@ -120,7 +114,11 @@ export const MessageBoxHeader = () => {
content={pCAIP10ToWallet(selectedChat?.did)}
direction="bottom-right"
>
<Span fontWeight="700" fontSize="16px" cursor="pointer">
<Span
fontWeight="700"
fontSize="16px"
cursor="pointer"
>
{' '}
{selectedChat?.name
? shortenText(selectedChat?.name, 30)
Expand All @@ -134,16 +132,14 @@ export const MessageBoxHeader = () => {

export const SubTabHeader = () => {
const { activeTab, setActiveTab, activeSubTab } =
useContext<ChatAndNotificationMainContextType>(
ChatAndNotificationMainContext
);
const { setSearchedChats, setSelectedChatId } =
useContext<ChatMainStateContextType>(ChatMainStateContext);
const { setSearchedNotifications } = useContext<any>(
NotificationMainStateContext
);
useContext<ChatAndNotificationMainContextType>(ChatAndNotificationMainContext);
const { setSearchedChats, setSelectedChatId } = useContext<ChatMainStateContextType>(ChatMainStateContext);
const { setSearchedNotifications } = useContext<any>(NotificationMainStateContext);
return (
<Section gap="12px" padding='23px 2px'>
<Section
gap="12px"
padding="23px 2px"
>
<Div
width="16px"
height="16px"
Expand All @@ -162,7 +158,10 @@ export const SubTabHeader = () => {
<BackIcon />
</Div>

<Span fontWeight="700" fontSize="16px">
<Span
fontWeight="700"
fontSize="16px"
>
{PushSubTabTitle[activeSubTab as PushSubTabs].title}
</Span>
</Section>
Expand All @@ -174,26 +173,16 @@ export const MinimisedModalHeader: React.FC<MinimisedModalHeaderPropType> = ({
modalOpen,
}) => {
const { newChat, setNewChat, setActiveTab, activeSubTab } =
useContext<ChatAndNotificationMainContextType>(
ChatAndNotificationMainContext
);
useContext<ChatAndNotificationMainContextType>(ChatAndNotificationMainContext);

const {
selectedChatId,
chatsFeed,
requestsFeed,
setSearchedChats,
setSelectedChatId,
searchedChats,
} = useContext<ChatMainStateContextType>(ChatMainStateContext);
const { selectedChatId, chatsFeed, requestsFeed, setSearchedChats, setSelectedChatId, searchedChats } =
useContext<ChatMainStateContextType>(ChatMainStateContext);

const SnapMessageHeader = () => {
const selectedChat =
chatsFeed[selectedChatId as string] ||
requestsFeed[selectedChatId as string] ||
(Object.keys(searchedChats || {}).length
? searchedChats![selectedChatId as string]
: null);
chatsFeed[selectedChatId as string] ||
requestsFeed[selectedChatId as string] ||
(Object.keys(searchedChats || {}).length ? searchedChats![selectedChatId as string] : null);
return (
<ChatSnap
chat={selectedChat}
Expand All @@ -203,20 +192,16 @@ export const MinimisedModalHeader: React.FC<MinimisedModalHeaderPropType> = ({
);
};

const condition =
(selectedChatId && modalOpen) ||
(!selectedChatId && modalOpen && activeSubTab);
const snapCondition =
(selectedChatId && !modalOpen);
const condition = (selectedChatId && modalOpen) || (!selectedChatId && modalOpen && activeSubTab);
const snapCondition = selectedChatId && !modalOpen;
return (
<Container
justifyContent="space-between"
alignItems="center"
padding={`${snapCondition ? '12px' : '0'} 0 `}
borderWidth={`0 0 ${condition ? '1px' : '0'} 0 `}
borderStyle={`none none ${condition ? 'dashed' : 'none'} none `}
borderColor={`transparent transparent ${condition ? '#ededee' : 'transparent'
} transparent`}
borderColor={`transparent transparent ${condition ? '#ededee' : 'transparent'} transparent`}
>
{selectedChatId &&
!!(
Expand All @@ -229,13 +214,12 @@ export const MinimisedModalHeader: React.FC<MinimisedModalHeaderPropType> = ({
{selectedChatId && !modalOpen && <SnapMessageHeader />}

{!selectedChatId && modalOpen && activeSubTab && <SubTabHeader />}
{((!selectedChatId && modalOpen && !activeSubTab) ||
(!modalOpen && !selectedChatId)) && (
{((!selectedChatId && modalOpen && !activeSubTab) || (!modalOpen && !selectedChatId)) && (
<Section gap="4px">
<Span
fontWeight="700"
fontSize="18px"
padding='24px 2px'
padding="24px 2px"
cursor={!modalOpen ? 'default' : 'pointer'}
onClick={() => {
setActiveTab(PUSH_TABS.CHATS);
Expand All @@ -251,8 +235,7 @@ export const MinimisedModalHeader: React.FC<MinimisedModalHeaderPropType> = ({
</Section>
)}
<Section gap="20px">
{((!selectedChatId && modalOpen && !activeSubTab && !newChat) ||
(!modalOpen && !selectedChatId)) && (
{((!selectedChatId && modalOpen && !activeSubTab && !newChat) || (!modalOpen && !selectedChatId)) && (
<Div
width="20px"
height="20px"
Expand All @@ -272,7 +255,7 @@ export const MinimisedModalHeader: React.FC<MinimisedModalHeaderPropType> = ({
cursor="pointer"
// alignSelf={selectedChatId && !modalOpen ? 'center' : 'baseline'}
margin="0 0 10px 0"
alignSelf='center'
alignSelf="center"
onClick={onMaximizeMinimizeToggle}
>
{modalOpen ? <MinimizeIcon /> : <MaximizeIcon />}
Expand All @@ -286,5 +269,3 @@ export const MinimisedModalHeader: React.FC<MinimisedModalHeaderPropType> = ({
const Container = styled(Section)`
box-sizing: border-box;
`;


Loading

0 comments on commit d51767f

Please sign in to comment.