diff --git a/src/components/chat/unlockProfile/UnlockProfile.tsx b/src/components/chat/unlockProfile/UnlockProfile.tsx index 26fc9ee51c..b98c6c7e7d 100644 --- a/src/components/chat/unlockProfile/UnlockProfile.tsx +++ b/src/components/chat/unlockProfile/UnlockProfile.tsx @@ -1,5 +1,5 @@ // React + Web3 Essentials -import { useContext, useEffect, useMemo, useState } from 'react'; +import { useCallback, useContext, useEffect, useState } from 'react'; // External Packages import styled, { useTheme } from 'styled-components'; @@ -66,20 +66,24 @@ const UnlockProfile = ({ InnerComponentProps, onClose }: UnlockProfileModalProps body: 'Sign with wallet to continue.', }); - const handleRememberMeChange = (event) => { + // const handleRememberMeChange = (event: any) => { + const handleRememberMeChange = (event: React.ChangeEvent) => { setRememberMe(event.target.checked); }; - const handleChatprofileUnlock = async () => { - const user = await handleConnectWallet({ remember: rememberMe }); + const connectWallet = () => { + connect(); + }; + + const handleChatprofileUnlock = useCallback(async () => { + const user = await handleConnectWallet({ remember: rememberMe, wallet }); - // reject unlock profile listener const errorExists = checkUnlockProfileErrors(user); if (errorExists && onClose) { onClose(); } - }; + }, [wallet, rememberMe]); useEffect(() => { if (wallet?.accounts?.length > 0) { @@ -228,7 +232,7 @@ const UnlockProfile = ({ InnerComponentProps, onClose }: UnlockProfileModalProps activeStatus={activeStatus.status} status={PROFILESTATE.CONNECT_WALLET} disabled={activeStatus.status !== PROFILESTATE.CONNECT_WALLET && true} - onClick={() => connect()} + onClick={() => connectWallet()} > Connect Wallet diff --git a/src/contexts/AppContext.tsx b/src/contexts/AppContext.tsx index 704f098cdb..457e79f5cd 100644 --- a/src/contexts/AppContext.tsx +++ b/src/contexts/AppContext.tsx @@ -33,6 +33,7 @@ const AppContextProvider = ({ children }) => { const shouldInitializeRef = useRef(true); // Using a ref to control useEffect execution const { connect, provider, account, wallet, connecting } = useAccount(); + const web3onboardToast = useToast(); const { readOnlyWallet } = useContext(GlobalContext); @@ -96,7 +97,17 @@ const AppContextProvider = ({ children }) => { }; // TODO: Change function name to handleConnectWalletAndUser - const handleConnectWallet = async ({ remember = false, showToast = false, toastMessage = undefined } = {}) => { + const handleConnectWallet = async ({ + remember = false, + showToast = false, + toastMessage = undefined, + wallet, + }: { + wallet?: any; + remember?: any; + showToast?: boolean; + toastMessage?: string; + }) => { shouldInitializeRef.current = false; // Directly modify the ref to disable useEffect execution if (showToast) { @@ -116,7 +127,7 @@ const AppContextProvider = ({ children }) => { let user; if (wallet?.accounts?.length > 0) { - user = await initializePushSDK(); + user = await initializePushSDK(wallet); } else { const walletConnected = await connect(); if (walletConnected.length > 0) {