Skip to content

Commit

Permalink
fix: fixed code
Browse files Browse the repository at this point in the history
  • Loading branch information
mishramonalisha76 committed Nov 16, 2023
1 parent 153336a commit bff2e19
Show file tree
Hide file tree
Showing 23 changed files with 192 additions and 254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const ChatViewComponentTest = () => {
'bafyreidesy6f4iu34eqccmqh55g35wu36lvlz42c63ivtmgjjhezlzdqta',
'bafyreig3gs4tpwxumiz5fxypyt4omlxhvrvuj66kfoyioeshawlau6lgem',
];

console.log('in chat view component')
return (
<div>
<h2>Chat UI Test page</h2>
{/* <CreateGroupModal onClose={()=>{console.log('in close')}} /> */}
<CreateGroupModal onClose={()=>{console.log('in close')}} />
<ChatViewComponentCard>
{/* <CreateGroupModal onClose={()=>{console.log('in close')}} modalBackground={MODAL_BACKGROUND_TYPE.OVERLAY} modalPositionType={MODAL_POSITION_TYPE.RELATIVE}/> */}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import CloseIcon from '../../../icons/close.svg';
import { ChatSearchInput, CustomStyleParamsType, ModalHeader } from '../reusables';
import useGetChatProfile from '../../../hooks/useGetChatProfile';
import { BackIcon } from '../../../icons/Back';
import useChatProfile from '../../../hooks/chat/useChatProfile';


type AddWalletContentProps = {
Expand All @@ -50,7 +51,7 @@ export const AddWalletContent = ({
const [filteredUserData, setFilteredUserData] = useState<any>(null);
const { account, env } = useChatData();
const isMobile = useMediaQuery(device.mobileL);
const {fetchChatProfile} = useGetChatProfile();
const {fetchUserChatProfile} = useChatProfile();
const groupInfoToast = useToast();
const customSearchStyle:CustomStyleParamsType = {
background:theme.backgroundColor?.modalInputBackground,
Expand All @@ -64,7 +65,7 @@ export const AddWalletContent = ({
//fix ens search
const newChatUser = await getNewChatUser({
searchText: searchedText,
fetchChatProfile,
fetchChatProfile:fetchUserChatProfile,
env,
});
if(newChatUser){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const ChatProfile: React.FC<IChatProfile> = ({

const fetchProfileData = async () => {
if (isValidETHAddress(chatId)) {
const ChatProfile = await fetchUserChatProfile({ profileId: chatId });
const ChatProfile = await fetchUserChatProfile({ profileId: chatId,env });
const result = await resolveNewEns(chatId, provider);
setEnsName(result);
setChatInfo(ChatProfile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const SenderMessageAddress = ({ chat }: { chat: IMessagePayload }) => {
const theme = useContext(ThemeContext);
return (
<>
{(chat.fromDID).split(':')[1] !== account && (
{(chat.fromCAIP10).split(':')[1] !== account && (
<Span
theme={theme}
alignSelf="start"
Expand All @@ -41,8 +41,8 @@ const SenderMessageAddress = ({ chat }: { chat: IMessagePayload }) => {
fontWeight={theme.fontWeight?.chatReceivedBubbleAddressText}
color={theme.textColor?.chatReceivedBubbleAddressText}
>
{chat.fromDID.split(':')[1].slice(0, 6)}...
{chat.fromDID.split(':')[1].slice(-6)}
{chat.fromCAIP10.split(':')[1].slice(0, 6)}...
{chat.fromCAIP10.split(':')[1].slice(-6)}
</Span>
)}
</>
Expand All @@ -54,7 +54,7 @@ const SenderMessageProfilePicture = ({ chat }: { chat: IMessagePayload }) => {
const [pfp, setPfp] = useState<string>('');
const getUserPfp = async () => {
const pfp = await getPfp({
account: chat.fromDID.split(':')[1],
account: chat.fromCAIP10.split(':')[1],
env: env,
});
if (pfp) {
Expand All @@ -63,10 +63,10 @@ const SenderMessageProfilePicture = ({ chat }: { chat: IMessagePayload }) => {
};
useEffect(() => {
getUserPfp();
}, [account, chat.fromDID]);
}, [account, chat.fromCAIP10]);
return (
<Section justifyContent="start" alignItems="start">
{(chat.fromDID || chat.fromDID).split(':')[1] !== account && (
{(chat.fromCAIP10).split(':')[1] !== account && (
<Section alignItems="start">
{pfp && (
<Image
Expand Down Expand Up @@ -340,15 +340,15 @@ const TwitterCard = ({
export const ChatViewBubble = ({ decryptedMessagePayload }: { decryptedMessagePayload: IMessagePayload }) => {
const { account } = useChatData();
const position =
pCAIP10ToWallet(decryptedMessagePayload.fromDID).toLowerCase() !== account?.toLowerCase()
pCAIP10ToWallet(decryptedMessagePayload.fromCAIP10).toLowerCase() !== account?.toLowerCase()
? 0
: 1;
const { tweetId, messageType }: TwitterFeedReturnType = checkTwitterUrl({
message: decryptedMessagePayload?.messageContent,
});
const [isGroup, setIsGroup] = useState<boolean>(false);
useEffect(() => {
if ((decryptedMessagePayload.toDID).split(':')[0] === 'eip155') {
if ((decryptedMessagePayload.toCAIP10).split(':')[0] === 'eip155') {
if (isGroup) {
setIsGroup(false);
}
Expand All @@ -357,7 +357,7 @@ export const ChatViewBubble = ({ decryptedMessagePayload }: { decryptedMessagePa
setIsGroup(true);
}
}
}, [decryptedMessagePayload.toDID, isGroup]);
}, [decryptedMessagePayload.toCAIP10, isGroup]);

if (messageType === 'TwitterFeedLink') {
decryptedMessagePayload.messageType = 'TwitterFeedLink';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import useGetChatProfile from '../../../hooks/useGetChatProfile';
import useFetchChat from '../../../hooks/chat/useFetchChat';
import { ApproveRequestBubble } from './ApproveRequestBubble';
import { formatTime } from '../../../helpers/timestamp';
import useChatProfile from '../../../hooks/chat/useChatProfile';

/**
* @interface IThemeProps
Expand Down Expand Up @@ -64,7 +65,7 @@ export const ChatViewList: React.FC<IChatViewListProps> = (
const listInnerRef = useRef<HTMLDivElement>(null);
const [isMember, setIsMember] = useState<boolean>(false);
const { fetchChat } = useFetchChat();
const { fetchChatProfile } = useGetChatProfile();
const { fetchUserChatProfile } = useChatProfile();
const { getGroup } = useGetGroup();

const { messagesSinceLastConnection, groupInformationSinceLastConnection } =
Expand All @@ -86,20 +87,17 @@ export const ChatViewList: React.FC<IChatViewListProps> = (
useEffect(() => {
(async () => {
if (alias) {
// console.log('chatss');
// console.log(account, env, 'chatss')

const chat = await fetchChat();
// console.log(chat, 'chatss calling main', alias)
if (chat) {
setConversationHash(chat?.threadhash as string);
setChatFeed(chat as IFeeds);
} else {
console.log('chatss calling elsez')
let newChatFeed;
let group;
const result = await getNewChatUser({
searchText: chatId,
fetchChatProfile,
fetchChatProfile:fetchUserChatProfile,
env,
});
if (result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import useDecryptPGPKey from '../../../hooks/useDecryptPGPKey';
import { getAddressFromSigner } from '../../../helpers';
import { IChatTheme } from '../theme';
import { device } from '../../../config';
import useChatProfile from '../../../hooks/chat/useChatProfile';

/**
* @interface IThemeProps
Expand All @@ -37,7 +38,7 @@ export const ConnectButtonSub = ({autoConnect = false}) => {
setAlias
} = useChatData();
const theme = useContext(ThemeContext);
const {fetchChatProfile} = useGetChatProfile();
const {fetchUserChatProfile} = useChatProfile();
const {decryptPGPKey} = useDecryptPGPKey();


Expand All @@ -61,17 +62,18 @@ export const ConnectButtonSub = ({autoConnect = false}) => {
setUserData()
}, [wallet])

useEffect(() => {
(async () => {
if (!alias && signer) {
const user = await fetchChatProfile({signer: signer, env});
console.log("calllingggg in connect button")
if (user) {
setAlias(user);
}
}
})();
}, [alias, signer]);
//initialise user hook

// useEffect(() => {
// (async () => {
// if (!alias && signer) {
// const user = await fetchChatProfile({signer: signer, env});
// if (user) {
// setAlias(user);
// }
// }
// })();
// }, [alias, signer]);

return !signer ? (
<ConnectButtonDiv theme={theme}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
setAccessControl,
} from '../../../helpers';
import useFetchChat from '../../../hooks/chat/useFetchChat';
import useGetChatProfile from '../../../hooks/useGetChatProfile';
import useChatProfile from '../../../hooks/chat/useChatProfile';
import useGetGroup from '../../../hooks/chat/useGetGroup';
import useApproveChatRequest from '../../../hooks/chat/useApproveChatRequest';
import {
Expand Down Expand Up @@ -120,7 +120,7 @@ export const MessageInput: React.FC<MessageInputProps> = ({
setAlias
} = useChatData();
const { fetchChat } = useFetchChat();
const { fetchChatProfile } = useGetChatProfile();
const { fetchUserChatProfile } = useChatProfile();
const { getGroup } = useGetGroup();
const statusToast = useToast();
const textAreaRef = useRef<HTMLTextAreaElement>(null);
Expand All @@ -142,15 +142,16 @@ export const MessageInput: React.FC<MessageInputProps> = ({
}, [textAreaRef, typedMessage]);

//need to do something about fetching connectedUser in every component
useEffect(() => {
(async () => {
if (!alias && signer) {
const user = await fetchChatProfile({ signer: signer, env });
console.log("calllingggg in message input")
if (user) setAlias(user);
}
})();
}, [alias]);
//initalization not needed here

// useEffect(() => {
// (async () => {
// if (!alias && signer) {
// const user = await fetchUserChatProfile({ profileId: account!,env });
// if (user) setAlias(user);
// }
// })();
// }, [alias]);

useEffect(() => {
const storedTimestampJSON = localStorage.getItem(chatId);
Expand Down Expand Up @@ -209,7 +210,7 @@ export const MessageInput: React.FC<MessageInputProps> = ({
let group;
const result = await getNewChatUser({
searchText: chatId,
fetchChatProfile,
fetchChatProfile:fetchUserChatProfile,
env,
});
if (result) {
Expand Down
8 changes: 4 additions & 4 deletions packages/uiweb/src/lib/context/chatContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export interface IChatDataContextValues {
setIsPushChatSocketConnected: React.Dispatch<React.SetStateAction<boolean>>;
connectedProfile: IUser | undefined;
setConnectedProfile: (connectedProfile: IUser) => void;
alias: any;
setAlias: React.Dispatch<React.SetStateAction<any>>;
pushUser: any;
setPushUser: React.Dispatch<React.SetStateAction<any>>;
}

export const initialChatDataContextValues: IChatDataContextValues = {
Expand Down Expand Up @@ -45,8 +45,8 @@ export const initialChatDataContextValues: IChatDataContextValues = {
setConnectedProfile: () => {
/** */
},
alias: null,
setAlias: () => {
pushUser: null,
setPushUser: () => {
/** */
},

Expand Down
Loading

0 comments on commit bff2e19

Please sign in to comment.