Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat backend migration #347

Merged
merged 20 commits into from
Mar 27, 2024
Merged
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"@types/react-dom": "^16.9.11",
"@typescript-eslint/eslint-plugin": "^5.52.0",
"@typescript-eslint/parser": "^5.52.0",
"cross-env": "^5.2.0",
"cross-env": "^7.0.3",
"eslint": "^8.34.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-import": "^2.27.5",
Expand Down
4 changes: 1 addition & 3 deletions packages/fetch-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"@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",
"@toruslabs/fetch-node-details": "=11.0.1",
"@toruslabs/torus.js": "=8.0.1",
Expand All @@ -79,6 +78,7 @@
"chart.js": "^2.9.3",
"classnames": "^2.3.2",
"color": "^4.2.3",
"cross-env": "^7.0.3",
"crypto-browserify": "^3.12.0",
"date-fns": "^2.29.3",
"debounce": "^1.2.1",
Expand Down Expand Up @@ -106,12 +106,10 @@
"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",
"scrypt-js": "^3.0.1",
"secp256k1": "^5.0.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/fetch-extension/src/@types/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface NewGroupDetails {
}
export interface GroupDetails {
contents: string;
description: string;
description: string | undefined;
groupId: string;
members: GroupMembers[];
name: string;
Expand Down Expand Up @@ -79,7 +79,6 @@ export interface Pagination {
lastPage: number;
}

//Redux Selectors Type Definitions
export interface Messages {
[key: string]: Message;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ 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 { store } from "@chatStore/index";
import { setMessageError } from "@chatStore/messages-slice";
import { MessagePrimitive } from "@utils/encrypt-message";
import { TokenDropdown } from "@components/agents/tokens-dropdown";
import { IBCChainSelector } from "@components/agents/ibc-chain-selector";
Expand All @@ -18,6 +16,7 @@ import parse from "react-html-parser";
import { processHyperlinks } from "@utils/process-hyperlinks";
import { RecipientAddressInput } from "@components/agents/address-input";
import { AGENT_ADDRESS } from "../../config.ui.var";
import { useStore } from "../../stores";

const formatTime = (timestamp: number): string => {
const date = new Date(timestamp);
Expand Down Expand Up @@ -48,19 +47,18 @@ export const AgentChatMessage = ({
const [decryptedMessage, setDecryptedMessage] = useState<MessagePrimitive>();
const [isHovered, setIsHovered] = useState<boolean>(false);
const targetAddress = useLocation().pathname.split("/")[3];
const { chatStore } = useStore();
useEffect(() => {
decryptMessage(chainId, message, isSender)
.then((message) => {
setDecryptedMessage(message);
})
.catch((e) => {
store.dispatch(
setMessageError({
type: "authorization",
message: "Something went wrong, Please try again in sometime.",
level: 3,
})
);
chatStore.messagesStore.setMessageError({
type: "authorization",
message: "Something went wrong, Please try again in sometime.",
level: 3,
});
console.log("Error", e.message);
});
}, [chainId, isSender, message]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { userDetails } from "@chatStore/user-slice";
import { useNotification } from "@components/notification";
import { deliverMessages } from "@graphQL/messages-api";
import React, { FunctionComponent, useMemo } from "react";
import { useSelector } from "react-redux";
import { useLocation } from "react-router";

import { useStore } from "../../../stores";
Expand All @@ -16,12 +14,13 @@ export const RecipientAddressInput: FunctionComponent<{
label: string;
disabled: boolean;
}> = observer(({ label, disabled }) => {
const { chainStore, accountStore, queriesStore, uiConfigStore } = useStore();
const { chainStore, accountStore, queriesStore, uiConfigStore, chatStore } =
useStore();
const current = chainStore.current;
const accountInfo = accountStore.getAccount(current.chainId);
const targetAddress = useLocation().pathname.split("/")[3];

const user = useSelector(userDetails);
const user = chatStore.userDetailsStore;
const notification = useNotification();
const sendConfigs = useSendTxConfig(
chainStore,
Expand Down Expand Up @@ -54,7 +53,8 @@ export const RecipientAddressInput: FunctionComponent<{
current.chainId,
messagePayload,
accountInfo.bech32Address,
targetAddress
targetAddress,
chatStore.messagesStore
);
} catch (e) {
console.log(e);
Expand All @@ -78,7 +78,8 @@ export const RecipientAddressInput: 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
@@ -1,8 +1,7 @@
import React from "react";
import { AGENT_COMMANDS } from "../../../config.ui.var";
import style from "./style.module.scss";
import { useSelector } from "react-redux";
import { userDetails } from "@chatStore/user-slice";
import { useStore } from "../../../stores";

export const CommandsDropdown = ({
newMessage,
Expand All @@ -13,7 +12,8 @@ export const CommandsDropdown = ({
showDropdown: boolean;
handleClick: (data: string) => void;
}) => {
const { hasFET } = useSelector(userDetails);
const { chatStore } = useStore();
const { hasFET } = chatStore.userDetailsStore;

return (
<React.Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import { FormattedMessage } from "react-intl";
import { IBCChannelRegistrarModal } from "@components/form";
import { Channel } from "@keplr-wallet/hooks";
import { deliverMessages } from "@graphQL/messages-api";
import { useSelector } from "react-redux";
import { userDetails } from "@chatStore/user-slice";
import { useNotification } from "@components/notification";
import { useLocation } from "react-router";
import { ChainIdHelper } from "@keplr-wallet/cosmos";
Expand All @@ -36,7 +34,7 @@ export const IBCChainSelector: FunctionComponent<{
label: ReactElement<any>[];
disabled: boolean;
}> = observer(({ label, disabled }) => {
const { accountStore, chainStore, ibcChannelStore, queriesStore } =
const { accountStore, chainStore, ibcChannelStore, queriesStore, chatStore } =
useStore();
const loadingIndicator = useLoadingIndicator();

Expand All @@ -45,7 +43,7 @@ export const IBCChainSelector: FunctionComponent<{
const accountInfo = accountStore.getAccount(current.chainId);
const targetAddress = useLocation().pathname.split("/")[3];
const notification = useNotification();
const user = useSelector(userDetails);
const user = chatStore.userDetailsStore;

const [isSelectorOpen, setIsSelectorOpen] = useState(false);
const [selectedChannel, setSelectedChannel] = useState<ChannelDetails>();
Expand Down Expand Up @@ -73,7 +71,8 @@ export const IBCChainSelector: FunctionComponent<{
current.chainId,
messagePayload,
accountInfo.bech32Address,
targetAddress
targetAddress,
chatStore.messagesStore
);
} catch (e) {
console.log(e);
Expand All @@ -98,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
@@ -1,9 +1,7 @@
import { userDetails } from "@chatStore/user-slice";
import { useNotification } from "@components/notification";
import { deliverMessages } from "@graphQL/messages-api";
import { signTransaction } from "@utils/sign-transaction";
import React from "react";
import { useSelector } from "react-redux";
import { useLocation, useNavigate } from "react-router";
import {
AGENT_ADDRESS,
Expand All @@ -23,13 +21,13 @@ export const SignTransaction = ({
chainId: string;
disabled: boolean;
}) => {
const { chainStore, accountStore } = useStore();
const { chainStore, accountStore, chatStore } = useStore();
const current = chainStore.current;
const accountInfo = accountStore.getAccount(current.chainId);
const navigate = useNavigate();
const targetAddress = useLocation().pathname.split("/")[3];

const user = useSelector(userDetails);
const user = chatStore.userDetailsStore;
const notification = useNotification();
const signTxn = async (data: string) => {
try {
Expand All @@ -44,7 +42,8 @@ export const SignTransaction = ({
signature: signResult.signature.signature,
},
accountInfo.bech32Address,
targetAddress
targetAddress,
chatStore.messagesStore
);
} catch (e) {
console.log(e);
Expand All @@ -63,7 +62,8 @@ export const SignTransaction = ({
chainId,
TRANSACTION_FAILED,
accountInfo.bech32Address,
targetAddress
targetAddress,
chatStore.messagesStore
);
navigate(`/chat/agent/${AGENT_ADDRESS[current.chainId]}`);
}
Expand All @@ -76,7 +76,8 @@ export const SignTransaction = ({
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 @@ -18,22 +18,21 @@ import {
import { useStore } from "../../../stores";
import { deliverMessages } from "@graphQL/messages-api";
import { useLocation, useNavigate } from "react-router";
import { useSelector } from "react-redux";
import { userDetails } from "@chatStore/user-slice";
import { useNotification } from "@components/notification";

export const TokenDropdown: FunctionComponent<{
label: ReactElement<any>[];
disabled: boolean;
ibc?: boolean;
}> = observer(({ label, disabled, ibc }) => {
const { accountStore, chainStore, queriesStore, uiConfigStore } = useStore();
const { accountStore, chainStore, queriesStore, uiConfigStore, chatStore } =
useStore();
const current = chainStore.current;
const accountInfo = accountStore.getAccount(current.chainId);
const navigate = useNavigate();
const targetAddress = useLocation().pathname.split("/")[3];
const notification = useNotification();
const user = useSelector(userDetails);
const user = chatStore.userDetailsStore;
const sendConfigs = useSendTxConfig(
chainStore,
queriesStore,
Expand Down Expand Up @@ -91,7 +90,8 @@ export const TokenDropdown: FunctionComponent<{
current.chainId,
messagePayload,
accountInfo.bech32Address,
targetAddress
targetAddress,
chatStore.messagesStore
);
} catch (e) {
console.log(e);
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 @@ -11,14 +11,16 @@ export const BlockUserPopup = ({
}) => {
const [processing, setProcessing] = useState(false);
const userName = useLocation().pathname.split("/")[2];
const { analyticsStore } = useStore();
const { analyticsStore, chatStore } = useStore();
const userState = chatStore.userDetailsStore;
const handleBlock = async () => {
analyticsStore.logEvent("block_contact_click", {
action: "Block",
});
setProcessing(true);
try {
await blockUser(userName);
await blockUser(userName, userState.accessToken);
chatStore.messagesStore.setBlockedUser({ blockedAddress: userName });
} catch (e) {
console.log(e);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export const DeleteGroupPopup = ({
const [processing, setProcessing] = useState(false);
const navigate = useNavigate();
const location = useLocation();
const { analyticsStore } = useStore();

const { analyticsStore, chatStore } = useStore();
const userState = chatStore.userDetailsStore;
const handleDelete = async () => {
setProcessing(true);
const groupId = location.pathname.split("/")[3];
deleteGroup(groupId);
deleteGroup(groupId, userState.accessToken);
setConfirmAction(false);
analyticsStore.logEvent("delete_group_click", { action: "Delete" });
navigate("/chat");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ export const UnblockUserPopup = ({
userName: string;
setConfirmAction: React.Dispatch<React.SetStateAction<boolean>>;
}) => {
const { chatStore, analyticsStore } = useStore();
const [processing, setProcessing] = useState(false);
const { analyticsStore } = useStore();

const user = chatStore.userDetailsStore;
const handleUnblock = async () => {
analyticsStore.logEvent("unblock_contact_click", {
action: "Unblock",
});
setProcessing(true);
try {
await unblockUser(userName);
await unblockUser(userName, user.accessToken);
chatStore.messagesStore.setUnblockedUser({ blockedAddress: userName });
} catch (e) {
console.log(e);
} finally {
Expand Down
Loading
Loading