Skip to content

Commit

Permalink
update unlock profile steps (#1733)
Browse files Browse the repository at this point in the history
  • Loading branch information
corlard3y authored Jul 16, 2024
1 parent e08a14e commit 3a49fe9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
18 changes: 11 additions & 7 deletions src/components/chat/unlockProfile/UnlockProfile.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<HTMLInputElement>) => {
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) {
Expand Down Expand Up @@ -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
</DefaultButton>
Expand Down
15 changes: 13 additions & 2 deletions src/contexts/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 3a49fe9

Please sign in to comment.