Skip to content

Commit

Permalink
chore:ui cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Feb 12, 2024
1 parent 3856901 commit a9cbbaa
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 184 deletions.
Binary file removed packages/companion-app/.yarn/install-state.gz
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ export const RecipientAddressInput: FunctionComponent<{
const sendAddressDetails = async () => {
try {
const messagePayload = sendConfigs.recipientConfig.recipient;
const message = await deliverMessages(
await deliverMessages(
user.accessToken,
current.chainId,
messagePayload,
accountInfo.bech32Address,
targetAddress
targetAddress,
chatStore.messagesStore
);
chatStore.messagesStore.updateLatestSentMessage(message);
} catch (e) {
console.log(e);
notification.push({
Expand All @@ -73,14 +73,14 @@ export const RecipientAddressInput: FunctionComponent<{

const cancel = async () => {
try {
const message = await deliverMessages(
await deliverMessages(
user.accessToken,
current.chainId,
"/cancel",
accountInfo.bech32Address,
targetAddress
targetAddress,
chatStore.messagesStore
);
chatStore.messagesStore.updateLatestSentMessage(message);
} catch (e) {
console.log(e);
notification.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ export const IBCChainSelector: FunctionComponent<{
message: `Selected Channel: ${chainInfo.chainName}`,
};
try {
const message = await deliverMessages(
await deliverMessages(
user.accessToken,
current.chainId,
messagePayload,
accountInfo.bech32Address,
targetAddress
targetAddress,
chatStore.messagesStore
);
chatStore.messagesStore.updateLatestSentMessage(message);
} catch (e) {
console.log(e);
notification.push({
Expand All @@ -97,7 +97,8 @@ export const IBCChainSelector: FunctionComponent<{
current.chainId,
"/cancel",
accountInfo.bech32Address,
targetAddress
targetAddress,
chatStore.messagesStore
);
} catch (e) {
console.log(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const SignTransaction = ({
try {
const signResult = await signTransaction(data, chainId, accountInfo);
navigate(-1);
const message = await deliverMessages(
await deliverMessages(
user.accessToken,
chainId,
{
Expand All @@ -42,9 +42,9 @@ export const SignTransaction = ({
signature: signResult.signature.signature,
},
accountInfo.bech32Address,
targetAddress
targetAddress,
chatStore.messagesStore
);
chatStore.messagesStore.updateLatestSentMessage(message);
} catch (e) {
console.log(e);
notification.push({
Expand All @@ -57,28 +57,28 @@ export const SignTransaction = ({
duration: 0.25,
},
});
const message = await deliverMessages(
await deliverMessages(
user.accessToken,
chainId,
TRANSACTION_FAILED,
accountInfo.bech32Address,
targetAddress
targetAddress,
chatStore.messagesStore
);
chatStore.messagesStore.updateLatestSentMessage(message);
navigate(`/chat/agent/${AGENT_ADDRESS[current.chainId]}`);
}
};

const cancel = async () => {
try {
const message = await deliverMessages(
await deliverMessages(
user.accessToken,
current.chainId,
"/cancel",
accountInfo.bech32Address,
targetAddress
targetAddress,
chatStore.messagesStore
);
chatStore.messagesStore.updateLatestSentMessage(message);
} catch (e) {
console.log(e);
notification.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ export const TokenDropdown: FunctionComponent<{
message: `Selected Token: ${amountConfig.sendCurrency.coinDenom}`,
};
try {
const message = await deliverMessages(
await deliverMessages(
user.accessToken,
current.chainId,
messagePayload,
accountInfo.bech32Address,
targetAddress
targetAddress,
chatStore.messagesStore
);
chatStore.messagesStore.updateLatestSentMessage(message);
} catch (e) {
console.log(e);
notification.push({
Expand All @@ -115,7 +115,8 @@ export const TokenDropdown: FunctionComponent<{
current.chainId,
"/cancel",
accountInfo.bech32Address,
targetAddress
targetAddress,
chatStore.messagesStore
);
} catch (e) {
console.log(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { BlockUserPopup } from "./block-user-popup";
import { DeleteChatPopup } from "./delete-chat-popup";
import { DeleteGroupPopup } from "./delete-group-popup";
import { UnblockUserPopup } from "./unblock-user-popup";
import { useStore } from "../../stores";

export const ChatActionsPopup = ({
action,
Expand All @@ -17,7 +16,6 @@ export const ChatActionsPopup = ({
setConfirmAction: React.Dispatch<React.SetStateAction<boolean>>;
handleAction?: () => void;
}) => {
const { chatStore } = useStore();
const [processing, setProcessing] = useState(false);
/// Target address for one to one chat
const targetAddress = useLocation().pathname.split("/")[2];
Expand All @@ -36,7 +34,6 @@ export const ChatActionsPopup = ({
<UnblockUserPopup
setConfirmAction={setConfirmAction}
userName={targetAddress}
accessToken={chatStore.userDetailsStore.accessToken}
/>
)}
{action === "delete" && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import { useStore } from "../../stores";
export const UnblockUserPopup = ({
userName,
setConfirmAction,
accessToken,
}: {
userName: string;
setConfirmAction: React.Dispatch<React.SetStateAction<boolean>>;
accessToken: string;
}) => {
const { chatStore } = useStore();
const [processing, setProcessing] = useState(false);
const user = chatStore.userDetailsStore;
const handleUnblock = async () => {
setProcessing(true);
try {
await unblockUser(userName, accessToken);
await unblockUser(userName, user.accessToken);
chatStore.messagesStore.setUnblockedUser({ blockedAddress: userName });
} catch (e) {
console.log(e);
Expand Down
35 changes: 10 additions & 25 deletions packages/fetch-extension/src/components/chat-message/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,29 @@ import deliveredIcon from "@assets/icon/chat-unseen-status.png";
import chatSeenIcon from "@assets/icon/chat-seen-status.png";
import { decryptMessage } from "@utils/decrypt-message";
import style from "./style.module.scss";
import { isToday, isYesterday, format } from "date-fns";
import { MessagePrimitive } from "@utils/encrypt-message";
import parse from "react-html-parser";
import { processHyperlinks } from "@utils/process-hyperlinks";
import { observer } from "mobx-react-lite";
import { useStore } from "../../stores";
import { formatTime, getDate } from "@utils/format";

const formatTime = (timestamp: number): string => {
const date = new Date(timestamp);
return format(date, "p");
};

export const ChatMessage = observer(
interface ChatMessageProps {
chainId: string;
isSender: boolean;
message: string;
timestamp: number;
showDate: boolean;
groupLastSeenTimestamp: number;
}
export const ChatMessage: React.FC<ChatMessageProps> = observer(
({
chainId,
message,
isSender,
timestamp,
showDate,
groupLastSeenTimestamp,
}: {
chainId: string;
isSender: boolean;
message: string;
timestamp: number;
showDate: boolean;
groupLastSeenTimestamp: number;
}) => {
const [decryptedMessage, setDecryptedMessage] =
useState<MessagePrimitive>();
Expand All @@ -51,17 +47,6 @@ export const ChatMessage = observer(
});
}, [chainId, isSender, message]);

const getDate = (timestamp: number): string => {
const d = new Date(timestamp);
if (isToday(d)) {
return "Today";
}
if (isYesterday(d)) {
return "Yesterday";
}
return format(d, "dd MMMM yyyy");
};

function decideMessageView(): ReactElement {
let messageView = <i className="fas fa-spinner fa-spin ml-1" />;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ import { observer } from "mobx-react-lite";

export const ChatInitPopup = observer(
({
openDialog,
setIsOpendialog,
setLoadingChats,
}: {
openDialog: boolean;
setIsOpendialog: any;
setLoadingChats: any;
}) => {
Expand Down Expand Up @@ -71,7 +69,7 @@ export const ChatInitPopup = observer(
}
};

return openDialog && userState.accessToken.length > 0 ? (
return (
<React.Fragment>
<div className={style["overlay"]} />
<div className={style["popupContainer"]}>
Expand Down Expand Up @@ -128,8 +126,6 @@ export const ChatInitPopup = observer(
</button>
</div>
</React.Fragment>
) : (
<React.Fragment />
);
}
);
5 changes: 3 additions & 2 deletions packages/fetch-extension/src/graphQL/messages-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ export const deliverMessages = async (
chainId: string,
newMessage: any,
senderAddress: string,
targetAddress: string
targetAddress: string,
messagesStore: MessagesStore
) => {
try {
if (newMessage) {
Expand Down Expand Up @@ -219,7 +220,7 @@ export const deliverMessages = async (
});

if (data?.dispatchMessages?.length > 0) {
return data?.dispatchMessages[0];
messagesStore.updateLatestSentMessage(data?.dispatchMessages[0]);
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/fetch-extension/src/graphQL/recieve-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const recieveMessages = async (
messageStore
);
}
messageStore.updateChatList(userAddress, messagesObj, pagination)
messageStore.updateChatList(userAddress, messagesObj, pagination);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ export const ChatsViewSection = observer(
current.chainId,
newMessage,
accountInfo.bech32Address,
targetAddress
targetAddress,
chatStore.messagesStore
);

if (message) {
chatStore.messagesStore.updateLatestSentMessage(message);
const updatedMessagesList = [...messages, message];
setMessages(updatedMessagesList);
setNewMessage("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@ export const ChatsViewSection = observer(
current.chainId,
newMessage,
accountInfo.bech32Address,
targetAddress
targetAddress,
chatStore.messagesStore
);
if (message) {
const updatedMessagesList = [...messages, message];
chatStore.messagesStore.updateLatestSentMessage(message);
setMessages(updatedMessagesList);
setLastUnreadMesageId("");
setNewMessage("");
Expand Down
11 changes: 6 additions & 5 deletions packages/fetch-extension/src/pages/chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,12 @@ const ChatView = observer(() => {
>
<ChatErrorPopup />
<div className={style["chatContainer"]}>
<ChatInitPopup
openDialog={openDialog}
setIsOpendialog={setIsOpendialog}
setLoadingChats={setLoadingChats}
/>
{openDialog && userState.accessToken.length > 0 && (
<ChatInitPopup
setIsOpendialog={setIsOpendialog}
setLoadingChats={setLoadingChats}
/>
)}

<div className={style["title"]}>Chats</div>
<ChatSearchInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ const BlockAddresses: React.FC<{
addresses: NameAddress[];
blockedAddresses: { [key: string]: boolean };
}> = ({ addresses, blockedAddresses }) => {
const { chatStore } = useStore();
const user = chatStore.userDetailsStore;
const [confirmAction, setConfirmAction] = useState<boolean>(false);
const [userName, setUserName] = useState<string>("");

Expand All @@ -69,7 +67,6 @@ const BlockAddresses: React.FC<{
<UnblockUserPopup
setConfirmAction={setConfirmAction}
userName={userName}
accessToken={user.accessToken}
/>
)}
<div className={style["messagesContainer"]}>
Expand Down
Loading

0 comments on commit a9cbbaa

Please sign in to comment.