Skip to content

Commit

Permalink
fix: timestamp helper created, removed extra code
Browse files Browse the repository at this point in the history
  • Loading branch information
pritipsingh committed Nov 15, 2023
1 parent 697ab6a commit f6a3607
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const ChatSupportTest = () => {
<SupportChat

signer={librarySigner}
supportAddress="0x80f93506dd28cBcb235EF1D84BBCFF91F5B02D06"
supportAddress="0x99A08ac6254dcf7ccc37CeC662aeba8eFA666666"
apiKey="tAWEnggQ9Z.UaDBNjrvlJZx3giBTIQDcT8bKQo1O1518uF1Tea7rPwfzXv2ouV5rX9ViwgJUrXm"
env={env}
greetingMsg="How can i help you?"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const ChatInput: React.FC = () => {
content: message,

});
console.log(sendResponse);

if (!sendResponse) {
setToastMessage(sendResponse);
setToastType('error');
Expand Down
16 changes: 2 additions & 14 deletions packages/uiweb/src/lib/components/supportChat/Chats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useContext, useState } from 'react';
import styled from 'styled-components';
import { SupportChatMainStateContext, SupportChatPropsContext } from '../../context';
import type { IMessageIPFS } from '../../types';
import { formatTime } from '../../helpers/timestamp';

type ChatsPropType = {
msg: IMessageIPFS;
Expand Down Expand Up @@ -32,22 +33,9 @@ export const Chats: React.FC<ChatsPropType> = ({
const [showImageModal, setShowImageModal] = useState<boolean>(false);
const [imageUrl, setImageUrl] = useState<string>('');

let date;
let timestamp;

if (typeof msg.timestamp === "string") {
timestamp = parseInt(msg.timestamp);
}else{
timestamp = msg.timestamp
}
const time = new Date(timestamp!);
const date = formatTime(msg.timestamp)

if (!isNaN(time.getTime())){

const time1 = time.toLocaleTimeString('en-US');

date = time1.slice(0, -6) + time1.slice(-2);
}


return (
Expand Down
11 changes: 0 additions & 11 deletions packages/uiweb/src/lib/components/supportChat/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,6 @@ export const Modal: React.FC = () => {
}
};

// const getUpdatedChats = (message:IMessageIPFS) =>{
// console.log(message)
// if (message && (supportAddress === pCAIP10ToWallet(message?.from))) {
// const chat = await decryptChat({ message, connectedUser, env });
// socketData.messagesSinceLastConnection.decrypted = true;

// setChatsSorted([...chats, message]);
// }
// }



useEffect(() => {

Expand Down
2 changes: 1 addition & 1 deletion packages/uiweb/src/lib/helpers/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const createUserIfNecessary = async (
connectedUser = await userAlice.info();
}

return { ...connectedUser, privateKey: connectedUser.encryptedPrivateKey };
return { ...connectedUser, privateKey: connectedUser!.encryptedPrivateKey };
};

type GetChatsResponseType = {
Expand Down
19 changes: 19 additions & 0 deletions packages/uiweb/src/lib/helpers/timestamp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const formatTime = (timestamp : any) => {
let date;
let timestamp1;
if (typeof timestamp === "string") {
timestamp1 = parseInt(timestamp );
}else{
timestamp1 = timestamp
}
const time = new Date(timestamp1!);

if (!isNaN(time.getTime())){

const time1 = time.toLocaleTimeString('en-US');

date = time1.slice(0, -6) + time1.slice(-2);
}

return date;
}

0 comments on commit f6a3607

Please sign in to comment.