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

fixes ui representation for domain resolution #1336

Merged
merged 8 commits into from
Jun 7, 2024
Original file line number Diff line number Diff line change
@@ -1,33 +1,17 @@
// React + Web3 Essentials
import { ethers } from 'ethers';
import React, { useContext, useEffect, useRef, useState } from 'react';

// External Packages
import { CONSTANTS, IFeeds, IUser } from '@pushprotocol/restapi';
import styled from 'styled-components';

// Internal Compoonents
import {
deriveChatId,
getAddress,
getNewChatUser,
pCAIP10ToWallet,
traceStackCalls,
walletToPCAIP10,
} from '../../../helpers';
import { useChatData, usePushChatStream } from '../../../hooks';
import { deriveChatId, pCAIP10ToWallet } from '../../../helpers';
import { useChatData } from '../../../hooks';
import useFetchChat from '../../../hooks/chat/useFetchChat';
import useFetchMessageUtilities from '../../../hooks/chat/useFetchMessageUtilities';
import useGetGroupByIDnew from '../../../hooks/chat/useGetGroupByIDnew';
import usePushUser from '../../../hooks/usePushUser';
import { Button, Section, Span, Spinner } from '../../reusables';
import { ChatPreview } from '../ChatPreview';
import {
displayDefaultUser,
generateRandomNonce,
transformChatItems,
transformStreamToIChatPreviewPayload,
} from '../helpers';
import { generateRandomNonce, getChatParticipantDisplayName, transformStreamToIChatPreviewPayload } from '../helpers';

// Internal Configs
import { ThemeContext } from '../theme/ThemeProvider';
Expand All @@ -37,7 +21,6 @@ import { ThemeContext } from '../theme/ThemeProvider';
// Interfaces & Types
import {
ChatPreviewSearchListErrorCodes,
Group,
IChatPreviewSearchListError,
IChatPreviewSearchListProps,
IChatPreviewPayload,
Expand Down Expand Up @@ -73,7 +56,6 @@ interface IChatPreviewListMeta {
}

// Constants
const CHAT_PAGE_LIMIT = 10;
const SCROLL_LIMIT = 25;

// Exported Interfaces & Types
Expand All @@ -82,9 +64,7 @@ const SCROLL_LIMIT = 25;
export const ChatPreviewSearchList: React.FC<IChatPreviewSearchListProps> = (options: IChatPreviewSearchListProps) => {
// get hooks
const { user } = useChatData();
const { fetchUserProfile } = usePushUser();
const { getGroupByIDnew } = useGetGroupByIDnew();
const { fetchLatestMessage, fetchChatList } = useFetchMessageUtilities();

// set chat preview list
const [chatPreviewList, setChatPreviewList] = useState<IChatPreviewList>({
Expand Down Expand Up @@ -211,7 +191,6 @@ export const ChatPreviewSearchList: React.FC<IChatPreviewSearchListProps> = (opt
const groupInfo = await getGroupByIDnew({
groupId: derivedChatId,
});

if (groupInfo) {
searchedChat = {
...searchedChat,
Expand All @@ -230,19 +209,17 @@ export const ChatPreviewSearchList: React.FC<IChatPreviewSearchListProps> = (opt
} else {
const userProfile = await user?.info({ overrideAccount: chatInfo.recipient });
console.debug('UIWeb::components::ChatPreviewSearchList::loadMoreChats::userProfile', userProfile);

searchedChat = {
...searchedChat,
chatId: derivedChatId,
chatParticipant: derivedChatId,
chatParticipant: getChatParticipantDisplayName(derivedChatId, formattedChatId),
chatGroup: false,
chatPic: userProfile?.profile?.picture || null,
chatMsg: {
messageType: 'Text',
messageContent: chatInfo?.list === 'CHATS' ? 'Resume Chat!' : 'Start Chat!',
},
};

resolved = true;
}
} else {
Expand Down Expand Up @@ -349,22 +326,6 @@ export const ChatPreviewSearchList: React.FC<IChatPreviewSearchListProps> = (opt
});
};

//Transform group creation stream
const transformGroupCreationStream: (item: any) => void = async (item: any) => {
const transformedItem: IChatPreviewPayload = {
chatId: item?.chatId,
chatPic: item?.meta.image,
chatParticipant: item?.meta.name,
chatGroup: true,
chatTimestamp: undefined,
chatMsg: {
messageType: '',
messageContent: '',
},
};
addChatItems([transformedItem], false);
};

// Transform stream message
const transformStreamMessage: (item: any) => void = async (item: any) => {
if (!user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export const ChatProfile: React.FC<IChatProfile> = ({
profile.abbrRecipient = getAbbreiatedRecipient(recipient);
profile.desc = profileInfo.profile?.desc;
profile.isGroup = false;
profile.web3Name = chatId.includes('.') ? chatId : null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mishramonalisha76 I meant using the function everywhere so we don't have to use .includes everywhere and keep this logic in a single function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

understood

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rohitmalhotra1420 this logic is only in two places , most of the places we have to check if chatID.includes('.') then it doesnot something or something else. Should we just make a function to check if a string includes another substring?

} else {
throw new Error(
'UIWeb::ChatProfile::user.profile.info fetch error, possible push user does not exist.'
Expand All @@ -180,13 +181,14 @@ export const ChatProfile: React.FC<IChatProfile> = ({
profile.icon = null;
profile.chatId = derivedChatId;
profile.recipient = recipient;
profile.web3Name = chatId.includes('.') ? chatId : null;
profile.abbrRecipient = getAbbreiatedRecipient(recipient);
profile.desc = '';
profile.isGroup = false;
}

// get and set web3 name asynchrounously
if (profile.recipient) {
if (profile.recipient && !profile.web3Name) {
setupWeb3Name(profile.recipient);
}
}
Expand Down
6 changes: 4 additions & 2 deletions packages/uiweb/src/lib/components/chat/helpers/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ export const formatAddress = async (chatPreviewPayload: IChatPreviewPayload, env
// check and remove eip155:
if (formattedAddress.includes('eip155:')) {
formattedAddress = formattedAddress.replace('eip155:', '');
} else if (formattedAddress.includes('.')) {
formattedAddress = (await getAddress(formattedAddress, env))!;
}
}

Expand Down Expand Up @@ -228,3 +226,7 @@ export const transformStreamToIMessageIPFSWithCID: (item: any) => IMessageIPFSWi
};
return transformedItem;
};

export const getChatParticipantDisplayName = (derivedChatId: string, chatId: string) => {
return derivedChatId ? (chatId.includes('.') ? chatId : derivedChatId) : derivedChatId;
};
Loading