diff --git a/packages/uiweb/src/lib/components/chat/ChatPreviewList/ChatPreviewList.tsx b/packages/uiweb/src/lib/components/chat/ChatPreviewList/ChatPreviewList.tsx index 5d16295de..a31fe7d39 100644 --- a/packages/uiweb/src/lib/components/chat/ChatPreviewList/ChatPreviewList.tsx +++ b/packages/uiweb/src/lib/components/chat/ChatPreviewList/ChatPreviewList.tsx @@ -7,7 +7,14 @@ import { CONSTANTS, IFeeds, IUser } from '@pushprotocol/restapi'; import styled from 'styled-components'; // Internal Compoonents -import { getAddress, getNewChatUser, pCAIP10ToWallet, traceStackCalls, walletToPCAIP10 } from '../../../helpers'; +import { + getAddress, + getDomainIfExists, + getNewChatUser, + pCAIP10ToWallet, + traceStackCalls, + walletToPCAIP10, +} from '../../../helpers'; import { useChatData, usePushChatStream } from '../../../hooks'; import useFetchChat from '../../../hooks/chat/useFetchChat'; import useFetchMessageUtilities from '../../../hooks/chat/useFetchMessageUtilities'; @@ -609,7 +616,7 @@ export const ChatPreviewList: React.FC = (options: IChatP let userProfile: IUser | undefined = undefined; let groupProfile: Group; - if (formattedChatId.includes('.')) { + if (getDomainIfExists(formattedChatId)) { const address = await getAddress(formattedChatId, user ? user.env : CONSTANTS.ENV.PROD); if (address) formattedChatId = pCAIP10ToWallet(address); else { diff --git a/packages/uiweb/src/lib/components/chat/ChatPreviewSearchList/ChatPreviewSearchList.tsx b/packages/uiweb/src/lib/components/chat/ChatPreviewSearchList/ChatPreviewSearchList.tsx index b5a980193..3369166a0 100644 --- a/packages/uiweb/src/lib/components/chat/ChatPreviewSearchList/ChatPreviewSearchList.tsx +++ b/packages/uiweb/src/lib/components/chat/ChatPreviewSearchList/ChatPreviewSearchList.tsx @@ -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, getDomainIfExists, 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'; @@ -37,7 +21,6 @@ import { ThemeContext } from '../theme/ThemeProvider'; // Interfaces & Types import { ChatPreviewSearchListErrorCodes, - Group, IChatPreviewSearchListError, IChatPreviewSearchListProps, IChatPreviewPayload, @@ -73,7 +56,6 @@ interface IChatPreviewListMeta { } // Constants -const CHAT_PAGE_LIMIT = 10; const SCROLL_LIMIT = 25; // Exported Interfaces & Types @@ -82,9 +64,7 @@ const SCROLL_LIMIT = 25; export const ChatPreviewSearchList: React.FC = (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({ @@ -192,7 +172,7 @@ export const ChatPreviewSearchList: React.FC = (opt let derivedChatId = formattedChatId; // Check if the chatId is ENS / Web3 Name - if (formattedChatId.includes('.')) { + if (getDomainIfExists(formattedChatId)) { // resolve web3 name derivedChatId = await deriveChatId(formattedChatId, user); } @@ -211,7 +191,6 @@ export const ChatPreviewSearchList: React.FC = (opt const groupInfo = await getGroupByIDnew({ groupId: derivedChatId, }); - if (groupInfo) { searchedChat = { ...searchedChat, @@ -230,11 +209,10 @@ export const ChatPreviewSearchList: React.FC = (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: { @@ -242,7 +220,6 @@ export const ChatPreviewSearchList: React.FC = (opt messageContent: chatInfo?.list === 'CHATS' ? 'Resume Chat!' : 'Start Chat!', }, }; - resolved = true; } } else { @@ -349,22 +326,6 @@ export const ChatPreviewSearchList: React.FC = (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) { diff --git a/packages/uiweb/src/lib/components/chat/ChatProfile/ChatProfile.tsx b/packages/uiweb/src/lib/components/chat/ChatProfile/ChatProfile.tsx index 25375b0ce..4237895d1 100644 --- a/packages/uiweb/src/lib/components/chat/ChatProfile/ChatProfile.tsx +++ b/packages/uiweb/src/lib/components/chat/ChatProfile/ChatProfile.tsx @@ -12,6 +12,7 @@ import styled from 'styled-components'; import { deriveChatId, getAddress, + getDomainIfExists, pCAIP10ToWallet, resolveWeb3Name, shortenText, @@ -166,6 +167,7 @@ export const ChatProfile: React.FC = ({ profile.abbrRecipient = getAbbreiatedRecipient(recipient); profile.desc = profileInfo.profile?.desc; profile.isGroup = false; + profile.web3Name = getDomainIfExists(chatId); } else { throw new Error( 'UIWeb::ChatProfile::user.profile.info fetch error, possible push user does not exist.' @@ -180,13 +182,14 @@ export const ChatProfile: React.FC = ({ profile.icon = null; profile.chatId = derivedChatId; profile.recipient = recipient; + profile.web3Name = getDomainIfExists(chatId); 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); } } diff --git a/packages/uiweb/src/lib/components/chat/ChatProfile/ChatProfileInfoModal.tsx b/packages/uiweb/src/lib/components/chat/ChatProfile/ChatProfileInfoModal.tsx index 22e023da8..42a62b3ff 100644 --- a/packages/uiweb/src/lib/components/chat/ChatProfile/ChatProfileInfoModal.tsx +++ b/packages/uiweb/src/lib/components/chat/ChatProfile/ChatProfileInfoModal.tsx @@ -423,7 +423,6 @@ const GroupInformation = ({
{groupMembers.loading ? ( ` +const PublicEncrypted = styled(Section) <{ alert?: boolean }>` display: flex; flex-direction: row; width: 100%; @@ -1040,7 +1039,7 @@ const AddWalletContainer = styled.div` align-items: center; `; -const ConditionSection = styled(Section)<{ theme: IChatTheme }>` +const ConditionSection = styled(Section) <{ theme: IChatTheme }>` &::-webkit-scrollbar-thumb { background: ${(props) => props.theme.scrollbarColor}; border-radius: 10px; @@ -1053,7 +1052,7 @@ const ConditionSection = styled(Section)<{ theme: IChatTheme }>` } `; -const ScrollSection = styled(Section)<{ theme: IChatTheme }>` +const ScrollSection = styled(Section) <{ theme: IChatTheme }>` &::-webkit-scrollbar-thumb { background: ${(props) => props.theme.scrollbarColor}; border-radius: 10px; diff --git a/packages/uiweb/src/lib/components/chat/ChatProfile/PendingMembers.tsx b/packages/uiweb/src/lib/components/chat/ChatProfile/PendingMembers.tsx index 4c055c718..d6719a011 100644 --- a/packages/uiweb/src/lib/components/chat/ChatProfile/PendingMembers.tsx +++ b/packages/uiweb/src/lib/components/chat/ChatProfile/PendingMembers.tsx @@ -105,11 +105,10 @@ export const PendingMembers = ({ {showPendingRequests && pendingMembers && @@ -123,7 +122,7 @@ export const PendingMembers = ({ icon: item?.userInfo?.profile?.picture || null, chatId: null, web3Name: null, - recipient: shortenText(pCAIP10ToWallet(item.address?.split(':')[1]), 6, true), + recipient: pCAIP10ToWallet(item.address?.split(':')[1]), abbrRecipient: shortenText(pCAIP10ToWallet(item.address?.split(':')[1]), 6, true), desc: null, }} @@ -301,9 +300,8 @@ export const AcceptedMembers = ({ flexDirection="column" zIndex="2" justifyContent="start" - overflow="hidden auto" - maxHeight="15rem" theme={theme} + padding='10px 0 0 0' > {acceptedMembers.map((item, index) => ( ` +const ArrowImage = styled(Image) ` margin-left: auto; transform: ${(props) => (props?.setPosition ? 'rotate(0)' : 'rotate(180deg)')}; `; @@ -390,7 +388,7 @@ const Badge = styled.div` font-weight: 700; `; -const ProfileSection = styled(Section)<{ theme: IChatTheme }>` +const ProfileSection = styled(Section) <{ theme: IChatTheme }>` height: fit-content; &::-webkit-scrollbar-thumb { background: transparent; diff --git a/packages/uiweb/src/lib/components/chat/ChatViewList/ChatViewList.tsx b/packages/uiweb/src/lib/components/chat/ChatViewList/ChatViewList.tsx index 7568eb575..9317e3aca 100644 --- a/packages/uiweb/src/lib/components/chat/ChatViewList/ChatViewList.tsx +++ b/packages/uiweb/src/lib/components/chat/ChatViewList/ChatViewList.tsx @@ -300,7 +300,7 @@ export const ChatViewList: React.FC = (options: IChatViewLis } return () => { - // add comment + //Empty return }; }, [chatAcceptStream, participantJoinStream]); diff --git a/packages/uiweb/src/lib/components/chat/MessageInput/MessageInput.tsx b/packages/uiweb/src/lib/components/chat/MessageInput/MessageInput.tsx index 2c6a75eb6..104d6f28a 100644 --- a/packages/uiweb/src/lib/components/chat/MessageInput/MessageInput.tsx +++ b/packages/uiweb/src/lib/components/chat/MessageInput/MessageInput.tsx @@ -6,7 +6,7 @@ import { createPortal } from 'react-dom'; import { MdCheckCircle, MdError } from 'react-icons/md'; import styled from 'styled-components'; -import { deriveChatId, pCAIP10ToWallet, setAccessControl, walletToPCAIP10 } from '../../../helpers'; +import { deriveChatId, getDomainIfExists, pCAIP10ToWallet, setAccessControl, walletToPCAIP10 } from '../../../helpers'; import { useChatData, useClickAway, useDeviceWidthCheck, usePushChatStream } from '../../../hooks'; import useFetchChat from '../../../hooks/chat/useFetchChat'; import useGetGroupByIDnew from '../../../hooks/chat/useGetGroupByIDnew'; @@ -163,7 +163,7 @@ export const MessageInput: React.FC = ({ if (!user) return; if (chatId) { let derivedChatId = chatId; - if (derivedChatId.includes('.')) { + if (getDomainIfExists(derivedChatId)) { derivedChatId = (await deriveChatId(chatId, user))!; } diff --git a/packages/uiweb/src/lib/components/chat/helpers/helper.ts b/packages/uiweb/src/lib/components/chat/helpers/helper.ts index f5e7460ce..d03f7e3ac 100644 --- a/packages/uiweb/src/lib/components/chat/helpers/helper.ts +++ b/packages/uiweb/src/lib/components/chat/helpers/helper.ts @@ -2,7 +2,7 @@ import { Env, IFeeds, IMessageIPFSWithCID, IUser, ParticipantStatus } from '@pus import { ethers } from 'ethers'; import moment from 'moment'; import { ProfilePicture } from '../../../config'; -import { getAddress, walletToPCAIP10 } from '../../../helpers'; +import { getAddress, getDomainIfExists, walletToPCAIP10 } from '../../../helpers'; import { Group, IChatPreviewPayload, IMessagePayload, User } from '../exportedTypes'; export const profilePicture = `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAvklEQVR4AcXBsW2FMBiF0Y8r3GQb6jeBxRauYRpo4yGQkMd4A7kg7Z/GUfSKe8703fKDkTATZsJsrr0RlZSJ9r4RLayMvLmJjnQS1d6IhJkwE2bT13U/DBzp5BN73xgRZsJMmM1HOolqb/yWiWpvjJSUiRZWopIykTATZsJs5g+1N6KSMiO1N/5DmAkzYTa9Lh6MhJkwE2ZzSZlo7xvRwson3txERzqJhJkwE2bT6+JhoKTMJ2pvjAgzYSbMfgDlXixqjH6gRgAAAABJRU5ErkJggg==`; @@ -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))!; } } @@ -228,3 +226,7 @@ export const transformStreamToIMessageIPFSWithCID: (item: any) => IMessageIPFSWi }; return transformedItem; }; + +export const getChatParticipantDisplayName = (derivedChatId: string, chatId: string) => { + return derivedChatId ? getDomainIfExists(chatId) ?? derivedChatId : derivedChatId; +}; diff --git a/packages/uiweb/src/lib/components/chat/helpers/tokenGatedGroup.ts b/packages/uiweb/src/lib/components/chat/helpers/tokenGatedGroup.ts index ccea261a3..aa626cb40 100644 --- a/packages/uiweb/src/lib/components/chat/helpers/tokenGatedGroup.ts +++ b/packages/uiweb/src/lib/components/chat/helpers/tokenGatedGroup.ts @@ -1,5 +1,5 @@ import axios from 'axios'; -import { ethers } from "ethers"; +import { ethers } from 'ethers'; import { fetchERC20Info, fetchERC721nfo } from './tokenHelpers'; import { @@ -13,10 +13,7 @@ import { TYPE, } from '../types'; -const handleDefineCondition = ( - entryCriteria: CriteriaStateType, - handlePrevious: (() => void) | undefined -) => { +const handleDefineCondition = (entryCriteria: CriteriaStateType, handlePrevious: (() => void) | undefined) => { if (entryCriteria.isCondtionUpdateEnabled()) { // handle update entryCriteria.updateCondition(); @@ -30,9 +27,7 @@ const handleDefineCondition = ( } }; -const validateCustomEndpointData = async ( - condition: Rule -): Promise => { +const validateCustomEndpointData = async (condition: Rule): Promise => { const { data, type, subcategory } = condition; const errors: CriteriaValidationErrorType = {}; @@ -40,10 +35,7 @@ const validateCustomEndpointData = async ( return { url: 'URL is missing' }; } else { // Protocol Validation - if ( - !(data as PushData)?.url!.startsWith('http://') && - !(data as PushData).url!.startsWith('https://') - ) { + if (!(data as PushData)?.url!.startsWith('http://') && !(data as PushData).url!.startsWith('https://')) { return { url: 'Invalid URL protocol. Only "http://" and "https://" are allowed.', }; @@ -73,9 +65,7 @@ const validateCustomEndpointData = async ( return {}; }; -const validateGUILDData = async ( - condition: Rule -): Promise => { +const validateGUILDData = async (condition: Rule): Promise => { const { data } = condition; const errors: CriteriaValidationErrorType = {}; @@ -84,9 +74,7 @@ const validateGUILDData = async ( return { ...errors, guildId: 'Guild ID is missing' }; } else { try { - const response = await axios.get( - `https://api.guild.xyz/v1/guild/${(data as GuildData).id}` - ); + const response = await axios.get(`https://api.guild.xyz/v2/guilds/guild-page/${(data as GuildData).id}`); if (response.status !== 200) { return { ...errors, guildId: 'Guild ID is missing' }; @@ -98,8 +86,7 @@ const validateGUILDData = async ( } } else if ((data as GuildData).role) { const roleExists = response.data.roles.some( - (role: { id: number }) => - role.id.toString() === (data as GuildData).role + (role: { id: number }) => role.id.toString() === (data as GuildData).role ); if (!roleExists) { return { ...errors, guildRole: 'Invalid Guild Role ID' }; @@ -124,54 +111,49 @@ const validateGUILDData = async ( return {}; }; -const validateTokenData = async (condition:Rule):Promise =>{ - const data:PushData = condition.data; - const _contract = data.contract || "" - const _eip155Format = _contract.split(":") +const validateTokenData = async (condition: Rule): Promise => { + const data: PushData = condition.data; + const _contract = data.contract || ''; + const _eip155Format = _contract.split(':'); - if(_eip155Format.length !==3){ - return {tokenError:"Invalid contract address"} + if (_eip155Format.length !== 3) { + return { tokenError: 'Invalid contract address' }; } - const [chainId, address] = [parseInt(_eip155Format[1]), _eip155Format[2]] + const [chainId, address] = [parseInt(_eip155Format[1]), _eip155Format[2]]; - if(!ethers.utils.isAddress(address)){ - return {tokenError:`Invalid contract address`} + if (!ethers.utils.isAddress(address)) { + return { tokenError: `Invalid contract address` }; } - const [err] = condition.category === CATEGORY.ERC721 ? - await fetchERC721nfo(address, chainId) : await fetchERC20Info(address, chainId); + const [err] = + condition.category === CATEGORY.ERC721 + ? await fetchERC721nfo(address, chainId) + : await fetchERC20Info(address, chainId); - if(err){ - return {tokenError:`Invalid ${condition.category} contract`} + if (err) { + return { tokenError: `Invalid ${condition.category} contract` }; } - if(!data.amount){ - return {tokenAmount:`Amount cannot be 0`} - } - else{ - if(data.amount<0){ - return {tokenAmount:`Amount cannot be in negative`} + if (!data.amount) { + return { tokenAmount: `Amount cannot be 0` }; + } else { + if (data.amount < 0) { + return { tokenAmount: `Amount cannot be in negative` }; } } - return {} -} - -const validationCriteria = async (condition: Rule):Promise => { - if(condition.type === TYPE.GUILD) - { - return validateGUILDData(condition); - }else{ - if(condition.category === CATEGORY.INVITE){ - return {} - }else if (condition.category === CATEGORY.CustomEndpoint){ - return validateCustomEndpointData(condition); - }else{ - return validateTokenData(condition) - } - } - -} + return {}; +}; -export { - handleDefineCondition, - validationCriteria, - validateCustomEndpointData, +const validationCriteria = async (condition: Rule): Promise => { + if (condition.type === TYPE.GUILD) { + return validateGUILDData(condition); + } else { + if (condition.category === CATEGORY.INVITE) { + return {}; + } else if (condition.category === CATEGORY.CustomEndpoint) { + return validateCustomEndpointData(condition); + } else { + return validateTokenData(condition); + } + } }; + +export { handleDefineCondition, validationCriteria, validateCustomEndpointData }; diff --git a/packages/uiweb/src/lib/helpers/chat/search.ts b/packages/uiweb/src/lib/helpers/chat/search.ts index 36b73ac7c..f9eab5b15 100644 --- a/packages/uiweb/src/lib/helpers/chat/search.ts +++ b/packages/uiweb/src/lib/helpers/chat/search.ts @@ -5,6 +5,7 @@ import { pCAIP10ToWallet, walletToPCAIP10 } from '../address'; import { getUdResolverClient } from '../udResolver'; import { displayDefaultUser } from './user'; import { createWeb3Name } from '@web3-name-sdk/core'; +import { getDomainIfExists } from '../utils'; export const getObjectsWithMatchingKeys = ( obj: ChatFeedsType, @@ -61,7 +62,7 @@ export const getAddress = async (searchText: string, env: Env) => { const udResolverClient = getUdResolverClient(env); const web3NameClient = createWeb3Name(); let address: string | null = null; - if (searchText.includes('.')) { + if (getDomainIfExists(searchText)) { try { address = await web3NameClient.getAddress(searchText); if (!address) { diff --git a/packages/uiweb/src/lib/helpers/utils.ts b/packages/uiweb/src/lib/helpers/utils.ts index 8cd145e13..f865e5567 100644 --- a/packages/uiweb/src/lib/helpers/utils.ts +++ b/packages/uiweb/src/lib/helpers/utils.ts @@ -28,7 +28,7 @@ export const deriveChatId = async (chatId: string, user: PushAPI | undefined): P } else if (chatId.includes('eip155:')) { // remove eip155: chatId = chatId.replace('eip155:', ''); - } else if (chatId.includes('.')) { + } else if (getDomainIfExists(chatId)) { chatId = (await getAddress(chatId, user ? user.env : CONSTANTS.ENV.PROD))!; } @@ -40,3 +40,5 @@ export const isMessageEncrypted = (message: string) => { return message.startsWith('U2FsdGVkX1'); }; + +export const getDomainIfExists = (chatId: string) => (chatId.includes('.') ? chatId : null);