diff --git a/packages/companion-app/.yarn/install-state.gz b/packages/companion-app/.yarn/install-state.gz deleted file mode 100644 index dd5d1c6b2e..0000000000 Binary files a/packages/companion-app/.yarn/install-state.gz and /dev/null differ diff --git a/packages/fetch-extension/src/components/agents/address-input/index.tsx b/packages/fetch-extension/src/components/agents/address-input/index.tsx index b7cf4ebddd..609a3e1961 100644 --- a/packages/fetch-extension/src/components/agents/address-input/index.tsx +++ b/packages/fetch-extension/src/components/agents/address-input/index.tsx @@ -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({ @@ -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({ diff --git a/packages/fetch-extension/src/components/agents/ibc-chain-selector/index.tsx b/packages/fetch-extension/src/components/agents/ibc-chain-selector/index.tsx index 9b07dc24eb..dfa37c331d 100644 --- a/packages/fetch-extension/src/components/agents/ibc-chain-selector/index.tsx +++ b/packages/fetch-extension/src/components/agents/ibc-chain-selector/index.tsx @@ -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({ @@ -97,7 +97,8 @@ export const IBCChainSelector: FunctionComponent<{ current.chainId, "/cancel", accountInfo.bech32Address, - targetAddress + targetAddress, + chatStore.messagesStore ); } catch (e) { console.log(e); diff --git a/packages/fetch-extension/src/components/agents/sign-transaction/index.tsx b/packages/fetch-extension/src/components/agents/sign-transaction/index.tsx index 41764c725c..faf085f609 100644 --- a/packages/fetch-extension/src/components/agents/sign-transaction/index.tsx +++ b/packages/fetch-extension/src/components/agents/sign-transaction/index.tsx @@ -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, { @@ -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({ @@ -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({ diff --git a/packages/fetch-extension/src/components/agents/tokens-dropdown/index.tsx b/packages/fetch-extension/src/components/agents/tokens-dropdown/index.tsx index e5d3a18d5c..39e5a3e55b 100644 --- a/packages/fetch-extension/src/components/agents/tokens-dropdown/index.tsx +++ b/packages/fetch-extension/src/components/agents/tokens-dropdown/index.tsx @@ -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({ @@ -115,7 +115,8 @@ export const TokenDropdown: FunctionComponent<{ current.chainId, "/cancel", accountInfo.bech32Address, - targetAddress + targetAddress, + chatStore.messagesStore ); } catch (e) { console.log(e); diff --git a/packages/fetch-extension/src/components/chat-actions-popup/index.tsx b/packages/fetch-extension/src/components/chat-actions-popup/index.tsx index 14ae16bf67..22b598be0d 100644 --- a/packages/fetch-extension/src/components/chat-actions-popup/index.tsx +++ b/packages/fetch-extension/src/components/chat-actions-popup/index.tsx @@ -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, @@ -17,7 +16,6 @@ export const ChatActionsPopup = ({ setConfirmAction: React.Dispatch>; handleAction?: () => void; }) => { - const { chatStore } = useStore(); const [processing, setProcessing] = useState(false); /// Target address for one to one chat const targetAddress = useLocation().pathname.split("/")[2]; @@ -36,7 +34,6 @@ export const ChatActionsPopup = ({ )} {action === "delete" && ( diff --git a/packages/fetch-extension/src/components/chat-actions-popup/unblock-user-popup.tsx b/packages/fetch-extension/src/components/chat-actions-popup/unblock-user-popup.tsx index 808253cd67..611668d391 100644 --- a/packages/fetch-extension/src/components/chat-actions-popup/unblock-user-popup.tsx +++ b/packages/fetch-extension/src/components/chat-actions-popup/unblock-user-popup.tsx @@ -6,18 +6,17 @@ import { useStore } from "../../stores"; export const UnblockUserPopup = ({ userName, setConfirmAction, - accessToken, }: { userName: string; setConfirmAction: React.Dispatch>; - 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); diff --git a/packages/fetch-extension/src/components/chat-message/index.tsx b/packages/fetch-extension/src/components/chat-message/index.tsx index 2c4a2f95fd..41fb2daeb1 100644 --- a/packages/fetch-extension/src/components/chat-message/index.tsx +++ b/packages/fetch-extension/src/components/chat-message/index.tsx @@ -5,19 +5,22 @@ 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 = observer( ({ chainId, message, @@ -25,13 +28,6 @@ export const ChatMessage = observer( timestamp, showDate, groupLastSeenTimestamp, - }: { - chainId: string; - isSender: boolean; - message: string; - timestamp: number; - showDate: boolean; - groupLastSeenTimestamp: number; }) => { const [decryptedMessage, setDecryptedMessage] = useState(); @@ -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 = ; diff --git a/packages/fetch-extension/src/components/chat/chat-init-popup.tsx b/packages/fetch-extension/src/components/chat/chat-init-popup.tsx index 84886bda68..08ecb0a567 100644 --- a/packages/fetch-extension/src/components/chat/chat-init-popup.tsx +++ b/packages/fetch-extension/src/components/chat/chat-init-popup.tsx @@ -13,11 +13,9 @@ import { observer } from "mobx-react-lite"; export const ChatInitPopup = observer( ({ - openDialog, setIsOpendialog, setLoadingChats, }: { - openDialog: boolean; setIsOpendialog: any; setLoadingChats: any; }) => { @@ -71,7 +69,7 @@ export const ChatInitPopup = observer( } }; - return openDialog && userState.accessToken.length > 0 ? ( + return (
@@ -128,8 +126,6 @@ export const ChatInitPopup = observer(
- ) : ( - ); } ); diff --git a/packages/fetch-extension/src/graphQL/messages-api.ts b/packages/fetch-extension/src/graphQL/messages-api.ts index 012d286447..9a597bca1e 100644 --- a/packages/fetch-extension/src/graphQL/messages-api.ts +++ b/packages/fetch-extension/src/graphQL/messages-api.ts @@ -191,7 +191,8 @@ export const deliverMessages = async ( chainId: string, newMessage: any, senderAddress: string, - targetAddress: string + targetAddress: string, + messagesStore: MessagesStore ) => { try { if (newMessage) { @@ -219,7 +220,7 @@ export const deliverMessages = async ( }); if (data?.dispatchMessages?.length > 0) { - return data?.dispatchMessages[0]; + messagesStore.updateLatestSentMessage(data?.dispatchMessages[0]); } return null; } diff --git a/packages/fetch-extension/src/graphQL/recieve-messages.ts b/packages/fetch-extension/src/graphQL/recieve-messages.ts index ec349f9c6d..321c2495bb 100644 --- a/packages/fetch-extension/src/graphQL/recieve-messages.ts +++ b/packages/fetch-extension/src/graphQL/recieve-messages.ts @@ -37,7 +37,7 @@ export const recieveMessages = async ( messageStore ); } - messageStore.updateChatList(userAddress, messagesObj, pagination) + messageStore.updateChatList(userAddress, messagesObj, pagination); } }; diff --git a/packages/fetch-extension/src/pages/agent-chat-section/chats-view-section.tsx b/packages/fetch-extension/src/pages/agent-chat-section/chats-view-section.tsx index 3c126931b1..cc5871f915 100644 --- a/packages/fetch-extension/src/pages/agent-chat-section/chats-view-section.tsx +++ b/packages/fetch-extension/src/pages/agent-chat-section/chats-view-section.tsx @@ -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(""); diff --git a/packages/fetch-extension/src/pages/chat-section/chats-view-section.tsx b/packages/fetch-extension/src/pages/chat-section/chats-view-section.tsx index e84b02f067..3729e5e76d 100644 --- a/packages/fetch-extension/src/pages/chat-section/chats-view-section.tsx +++ b/packages/fetch-extension/src/pages/chat-section/chats-view-section.tsx @@ -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(""); diff --git a/packages/fetch-extension/src/pages/chat/index.tsx b/packages/fetch-extension/src/pages/chat/index.tsx index b974aa8a17..9c726fd42b 100644 --- a/packages/fetch-extension/src/pages/chat/index.tsx +++ b/packages/fetch-extension/src/pages/chat/index.tsx @@ -247,11 +247,12 @@ const ChatView = observer(() => { >
- + {openDialog && userState.accessToken.length > 0 && ( + + )}
Chats
= ({ addresses, blockedAddresses }) => { - const { chatStore } = useStore(); - const user = chatStore.userDetailsStore; const [confirmAction, setConfirmAction] = useState(false); const [userName, setUserName] = useState(""); @@ -69,7 +67,6 @@ const BlockAddresses: React.FC<{ )}
diff --git a/packages/fetch-extension/src/utils/format.ts b/packages/fetch-extension/src/utils/format.ts index 8e8a05ab66..b20d950905 100644 --- a/packages/fetch-extension/src/utils/format.ts +++ b/packages/fetch-extension/src/utils/format.ts @@ -1,4 +1,5 @@ import { AGENT_ADDRESS } from "../config.ui.var"; +import { isToday, isYesterday, format } from "date-fns"; export const formatAddress = (address: string) => { if (Object.values(AGENT_ADDRESS).includes(address)) return "Fetchbot"; @@ -101,3 +102,19 @@ export const formatAmount = (amount: string) => { amount.split(" ")[1]; return formattedAmount; }; + +export const formatTime = (timestamp: number): string => { + const date = new Date(timestamp); + return format(date, "p"); +}; + +export 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"); +}; diff --git a/yarn.lock b/yarn.lock index 9321b2d997..dc5fa04bda 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5159,7 +5159,7 @@ __metadata: languageName: node linkType: hard -"@babel/runtime@npm:^7.1.2, @babel/runtime@npm:^7.10.4, @babel/runtime@npm:^7.10.5, @babel/runtime@npm:^7.12.1, @babel/runtime@npm:^7.16.3, @babel/runtime@npm:^7.20.13, @babel/runtime@npm:^7.20.7, @babel/runtime@npm:^7.21.0, @babel/runtime@npm:^7.5.5, @babel/runtime@npm:^7.8.7, @babel/runtime@npm:^7.9.2": +"@babel/runtime@npm:^7.1.2, @babel/runtime@npm:^7.10.4, @babel/runtime@npm:^7.10.5, @babel/runtime@npm:^7.12.1, @babel/runtime@npm:^7.16.3, @babel/runtime@npm:^7.20.13, @babel/runtime@npm:^7.20.7, @babel/runtime@npm:^7.21.0, @babel/runtime@npm:^7.5.5, @babel/runtime@npm:^7.8.7": version: 7.22.5 resolution: "@babel/runtime@npm:7.22.5" dependencies: @@ -9198,7 +9198,6 @@ __metadata: "@ledgerhq/devices": ^6.20.0 "@metamask/jazzicon": ^2.0.0 "@react-spring/web": ^9.6.1 - "@reduxjs/toolkit": ^1.8.5 "@solana/web3.js": ^1.31.0 "@storybook/addon-actions": ^6.5.12 "@storybook/addon-essentials": ^6.5.12 @@ -9279,12 +9278,10 @@ __metadata: react-is: ^16.13.1 react-markdown: ^8.0.7 react-modal: ^3.11.1 - react-redux: ^8.0.2 react-router: ^6.8.1 react-router-dom: ^6.8.1 react-textarea-autosize: ^8.3.4 reactstrap: ^8.4.1 - redux-persist: ^6.0.0 remark-gfm: ^3.0.1 sass: ^1.60.0 sass-loader: ^13.2.1 @@ -12179,26 +12176,6 @@ __metadata: languageName: node linkType: hard -"@reduxjs/toolkit@npm:^1.8.5": - version: 1.9.5 - resolution: "@reduxjs/toolkit@npm:1.9.5" - dependencies: - immer: ^9.0.21 - redux: ^4.2.1 - redux-thunk: ^2.4.2 - reselect: ^4.1.8 - peerDependencies: - react: ^16.9.0 || ^17.0.0 || ^18 - react-redux: ^7.2.1 || ^8.0.2 - peerDependenciesMeta: - react: - optional: true - react-redux: - optional: true - checksum: 54672c5593d05208af577e948a338f23128d3aa01ef056ab0d40bcfa14400cf6566be99e11715388f12c1d7655cdf7c5c6b63cb92eb0fecf996c454a46a3914c - languageName: node - linkType: hard - "@remix-run/router@npm:1.3.2": version: 1.3.2 resolution: "@remix-run/router@npm:1.3.2" @@ -15368,13 +15345,6 @@ __metadata: languageName: node linkType: hard -"@types/use-sync-external-store@npm:^0.0.3": - version: 0.0.3 - resolution: "@types/use-sync-external-store@npm:0.0.3" - checksum: 161ddb8eec5dbe7279ac971531217e9af6b99f7783213566d2b502e2e2378ea19cf5e5ea4595039d730aa79d3d35c6567d48599f69773a02ffcff1776ec2a44e - languageName: node - linkType: hard - "@types/uuid@npm:^8.3.1": version: 8.3.4 resolution: "@types/uuid@npm:8.3.4" @@ -21943,18 +21913,6 @@ __metadata: languageName: node linkType: hard -"cross-env@npm:^7.0.3": - version: 7.0.3 - resolution: "cross-env@npm:7.0.3" - dependencies: - cross-spawn: ^7.0.1 - bin: - cross-env: src/bin/cross-env.js - cross-env-shell: src/bin/cross-env-shell.js - checksum: 26f2f3ea2ab32617f57effb70d329c2070d2f5630adc800985d8b30b56e8bf7f5f439dd3a0358b79cee6f930afc23cf8e23515f17ccfb30092c6b62c6b630a79 - languageName: node - linkType: hard - "cross-fetch@npm:3.1.5": version: 3.1.5 resolution: "cross-fetch@npm:3.1.5" @@ -28866,13 +28824,6 @@ __metadata: languageName: node linkType: hard -"immer@npm:^9.0.21": - version: 9.0.21 - resolution: "immer@npm:9.0.21" - checksum: 70e3c274165995352f6936695f0ef4723c52c92c92dd0e9afdfe008175af39fa28e76aafb3a2ca9d57d1fb8f796efc4dd1e1cc36f18d33fa5b74f3dfb0375432 - languageName: node - linkType: hard - "immutable@npm:^4.0.0": version: 4.3.0 resolution: "immutable@npm:4.3.0" @@ -40874,38 +40825,6 @@ __metadata: languageName: node linkType: hard -"react-redux@npm:^8.0.2": - version: 8.1.1 - resolution: "react-redux@npm:8.1.1" - dependencies: - "@babel/runtime": ^7.12.1 - "@types/hoist-non-react-statics": ^3.3.1 - "@types/use-sync-external-store": ^0.0.3 - hoist-non-react-statics: ^3.3.2 - react-is: ^18.0.0 - use-sync-external-store: ^1.0.0 - peerDependencies: - "@types/react": ^16.8 || ^17.0 || ^18.0 - "@types/react-dom": ^16.8 || ^17.0 || ^18.0 - react: ^16.8 || ^17.0 || ^18.0 - react-dom: ^16.8 || ^17.0 || ^18.0 - react-native: ">=0.59" - redux: ^4 || ^5.0.0-beta.0 - peerDependenciesMeta: - "@types/react": - optional: true - "@types/react-dom": - optional: true - react-dom: - optional: true - react-native: - optional: true - redux: - optional: true - checksum: 370676330727764d78f35e9c5a0ed0591d79482fe9b70fffcab4aa6bcccc6194e4f1ebd818b4b390351dea5557e70d3bd4d95d7a0ac9baa1f45d6bf2230ee713 - languageName: node - linkType: hard - "react-refresh@npm:^0.11.0": version: 0.11.0 resolution: "react-refresh@npm:0.11.0" @@ -41516,33 +41435,6 @@ __metadata: languageName: node linkType: hard -"redux-persist@npm:^6.0.0": - version: 6.0.0 - resolution: "redux-persist@npm:6.0.0" - peerDependencies: - redux: ">4.0.0" - checksum: edaf10dbf17351ce8058d0802357adae8665b3a1ff39371834e37838ddbe1a79cccbc717b8ba54acb5307651ccf51d0f7dc1cbc8dbae0726ff952d11ef61c6b8 - languageName: node - linkType: hard - -"redux-thunk@npm:^2.4.2": - version: 2.4.2 - resolution: "redux-thunk@npm:2.4.2" - peerDependencies: - redux: ^4 - checksum: c7f757f6c383b8ec26152c113e20087818d18ed3edf438aaad43539e9a6b77b427ade755c9595c4a163b6ad3063adf3497e5fe6a36c68884eb1f1cfb6f049a5c - languageName: node - linkType: hard - -"redux@npm:^4.2.1": - version: 4.2.1 - resolution: "redux@npm:4.2.1" - dependencies: - "@babel/runtime": ^7.9.2 - checksum: f63b9060c3a1d930ae775252bb6e579b42415aee7a23c4114e21a0b4ba7ec12f0ec76936c00f546893f06e139819f0e2855e0d55ebfce34ca9c026241a6950dd - languageName: node - linkType: hard - "regenerate-unicode-properties@npm:^10.1.0": version: 10.1.0 resolution: "regenerate-unicode-properties@npm:10.1.0" @@ -42932,7 +42824,7 @@ __metadata: languageName: node linkType: hard -"reselect@npm:^4.1.7, reselect@npm:^4.1.8": +"reselect@npm:^4.1.7": version: 4.1.8 resolution: "reselect@npm:4.1.8" checksum: a4ac87cedab198769a29be92bc221c32da76cfdad6911eda67b4d3e7136dca86208c3b210e31632eae31ebd2cded18596f0dd230d3ccc9e978df22f233b5583e