Skip to content

Commit

Permalink
fix: changed userAlice to pushUser
Browse files Browse the repository at this point in the history
pritipsingh committed Nov 16, 2023
1 parent f6a3607 commit fdb5eb6
Showing 7 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions packages/uiweb/src/lib/components/supportChat/AddressInfo.tsx
Original file line number Diff line number Diff line change
@@ -6,22 +6,22 @@ import { copyToClipboard, pCAIP10ToWallet } from '../../helpers';
import { CopySvg } from '../../icons/CopySvg';

export const AddressInfo: React.FC = () => {
const { supportAddress, env, theme, userAlice } = useContext<any>(SupportChatPropsContext);
const { supportAddress, env, theme, pushUser } = useContext<any>(SupportChatPropsContext);
const [ensName, setEnsName] = useState<string>('');
const [user, setUser] = useState<any>({});
const [isCopied, setIsCopied] = useState<boolean>(false);
const walletAddress = pCAIP10ToWallet(supportAddress);

useEffect(() => {
const getUser = async () => {
if(userAlice){
const user = await userAlice.info();
if(pushUser){
const user = await pushUser.info();
setUser(user);
}

};
getUser();
}, [supportAddress, userAlice]);
}, [supportAddress, pushUser]);

return (
<Container theme={theme}>
10 changes: 5 additions & 5 deletions packages/uiweb/src/lib/components/supportChat/Chat.tsx
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ export type ButtonStyleProps = {
const [toastType, setToastType] = useState<'error' | 'success'>();
const [chats, setChats] = useState<IMessageIPFS[]>([]);
const [accountadd, setAccountadd] = useState<string | null>(account)
const [userAlice, setUserAlice] = useState<PushAPI | null>(null);
const [pushUser, setPushUser] = useState<PushAPI | null>(null);
const setChatsSorted = (chats: IMessageIPFS[]) => {

const chatsWithNumericTimestamps = chats.map(item => ({
@@ -71,7 +71,7 @@ export type ButtonStyleProps = {
account: accountadd,
env,
apiKey,
userAlice: userAlice!,
pushUser: pushUser!,
supportAddress,
signer
});
@@ -80,7 +80,7 @@ export type ButtonStyleProps = {
const chatPropsData = {
account : accountadd,
signer,
userAlice,
pushUser,
supportAddress,
greetingMsg,
modalTitle,
@@ -112,8 +112,8 @@ export type ButtonStyleProps = {
(
async() =>{
if(Object.keys(signer || {}).length && accountadd){
const userAlice = await PushAPI.initialize(signer!, {env: env , account:accountadd!});
setUserAlice(userAlice)
const pushUser = await PushAPI.initialize(signer!, {env: env , account:accountadd!});
setPushUser(pushUser)
}
}
)()
4 changes: 2 additions & 2 deletions packages/uiweb/src/lib/components/supportChat/ChatInput.tsx
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ export const ChatInput: React.FC = () => {
const fileInputRef = useRef<HTMLInputElement>(null);
const [filesUploading, setFileUploading] = useState<boolean>(false);
const [loading, setLoading] = useState<boolean>(false);
const { account, env, supportAddress, apiKey, theme, userAlice } =
const { account, env, supportAddress, apiKey, theme, pushUser } =
useContext<any>(SupportChatPropsContext);

const {
@@ -40,7 +40,7 @@ export const ChatInput: React.FC = () => {
setLoading(true);
if (message.trim() !== '' && connectedUser) {

const sendResponse = await userAlice.chat.send(supportAddress ,{
const sendResponse = await pushUser.chat.send(supportAddress ,{

type: 'Text',
content: message,
8 changes: 4 additions & 4 deletions packages/uiweb/src/lib/components/supportChat/Modal.tsx
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ export const Modal: React.FC = () => {
string | null
>(null);
const [wasLastListPresent, setWasLastListPresent] = useState<boolean>(false);
const { supportAddress, userAlice, env, account, signer, greetingMsg, theme } =
const { supportAddress, pushUser, env, account, signer, greetingMsg, theme } =
useContext<any>(SupportChatPropsContext);
const {
chats,
@@ -90,7 +90,7 @@ export const Modal: React.FC = () => {
setLoading(true);
const { chatsResponse, lastThreadHash, lastListPresent } = await getChats({
account,
userAlice,
pushUser,
// pgpPrivateKey: connectedUser.privateKey,
supportAddress,
threadHash: lastThreadHashFetched!,
@@ -109,7 +109,7 @@ export const Modal: React.FC = () => {
if (!socketData.epnsSDKSocket?.connected) {
socketData.epnsSDKSocket?.connect();
}
const user = await createUserIfNecessary({ account, signer, env, userAlice });
const user = await createUserIfNecessary({ account, signer, env, pushUser });
setConnectedUser(user);
setLoading(false);
} catch (err:any) {
@@ -132,7 +132,7 @@ export const Modal: React.FC = () => {
useEffect(() => {

getChatCall();
}, [connectedUser, env, account,signer, supportAddress, userAlice]);
}, [connectedUser, env, account,signer, supportAddress, pushUser]);

useEffect(() => {
scrollToBottom();
12 changes: 6 additions & 6 deletions packages/uiweb/src/lib/helpers/chat/chat.ts
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ type HandleOnChatIconClickProps = {
type GetChatsType = {
pgpPrivateKey?: string;
supportAddress: string;
userAlice: PushAPI;
pushUser: PushAPI;
limit: number;
threadHash?: string;
env?: Env;
@@ -41,10 +41,10 @@ export const handleOnChatIconClick = ({
export const createUserIfNecessary = async (
options: AccountEnvOptionsType
): Promise<IConnectedUser> => {
const { account, signer, env = Constants.ENV.PROD, userAlice } = options || {};
const { account, signer, env = Constants.ENV.PROD, pushUser } = options || {};
let connectedUser;
if(userAlice){
connectedUser = await userAlice.info();
if(pushUser){
connectedUser = await pushUser.info();
}

return { ...connectedUser, privateKey: connectedUser!.encryptedPrivateKey };
@@ -63,14 +63,14 @@ export const getChats = async (
account,
pgpPrivateKey,
supportAddress,
userAlice,
pushUser,
threadHash = null,
limit = 40,
env = Constants.ENV.PROD,
} = options || {};


const chats = await userAlice?.chat.history(
const chats = await pushUser?.chat.history(
supportAddress
);

8 changes: 4 additions & 4 deletions packages/uiweb/src/lib/hooks/useSDKSocket.ts
Original file line number Diff line number Diff line change
@@ -12,12 +12,12 @@ export type SDKSocketHookOptions = {
env?: ENV,
socketType?: 'chat' | 'notification',
apiKey: string,
userAlice: PushAPI ,
pushUser: PushAPI ,
supportAddress: string | null,
signer: SignerType | null
};

export const useSDKSocket =({ account, env = ENV.PROD, socketType = 'chat',apiKey, userAlice, supportAddress, signer }: SDKSocketHookOptions) => {
export const useSDKSocket =({ account, env = ENV.PROD, socketType = 'chat',apiKey, pushUser, supportAddress, signer }: SDKSocketHookOptions) => {

// const [epnsSDKSocket, setEpnsSDKSocket] = useState<any>(null);
const [messagesSinceLastConnection, setMessagesSinceLastConnection] = useState<any>('');
@@ -82,7 +82,7 @@ export const useSDKSocket =({ account, env = ENV.PROD, socketType = 'chat',apiKe
stream?.disconnect();
}
const main = async () => {
const newstream = await userAlice.initStream(
const newstream = await pushUser.initStream(
[
CONSTANTS.STREAM.CHAT,
],
@@ -97,7 +97,7 @@ export const useSDKSocket =({ account, env = ENV.PROD, socketType = 'chat',apiKe
}

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [account, env, userAlice, supportAddress, signer, isSDKSocketConnected]);
}, [account, env, pushUser, supportAddress, signer, isSDKSocketConnected]);

return {
stream,
2 changes: 1 addition & 1 deletion packages/uiweb/src/lib/types/index.ts
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ export interface AccountEnvOptionsType {
env?: ENV;
account: string;
signer: SignerType;
userAlice: PushAPI;
pushUser: PushAPI;
}

export interface ITheme {

0 comments on commit fdb5eb6

Please sign in to comment.