diff --git a/src/components/ChannelDetails.jsx b/src/components/ChannelDetails.jsx index d34b794c87..2be1f54f7c 100644 --- a/src/components/ChannelDetails.jsx +++ b/src/components/ChannelDetails.jsx @@ -37,7 +37,7 @@ import { CHANNEL_TYPE } from 'helpers/UtilityHelper'; const DATE_FORMAT = 'DD MMM, YYYY'; export default function ChannelDetails({ isChannelExpired, setIsChannelExpired, showEditChannel, destroyChannel }) { - const { account, chainId } = useAccount(); + const { account, chainId, wallet } = useAccount(); const { delegatees, channelDetails, @@ -48,7 +48,7 @@ export default function ChannelDetails({ isChannelExpired, setIsChannelExpired, const { userPushSDKInstance } = useSelector((state) => { return state.user; }); - const { handleConnectWallet } = useContext(AppContext); + const { handleConnectWalletAndEnableProfile } = useContext(AppContext); const { CHANNEL_ACTIVE_STATE, CHANNNEL_DEACTIVATED_STATE } = useSelector((state) => state.channels); const { processingState } = useSelector((state) => state.channelCreation); const [verifyingChannel, setVerifyingChannel] = useState([]); @@ -78,7 +78,7 @@ export default function ChannelDetails({ isChannelExpired, setIsChannelExpired, const handleDelegateModal = async () => { if (!userPushSDKInstance.signer) { - await handleConnectWallet(); + await handleConnectWalletAndEnableProfile({ wallet }); } showAddDelegateModal(); }; @@ -157,7 +157,7 @@ export default function ChannelDetails({ isChannelExpired, setIsChannelExpired, const removeDelegate = async (walletAddress) => { let userPushInstance = userPushSDKInstance; if (!userPushInstance.signer) { - userPushInstance = await handleConnectWallet(); + userPushInstance = await handleConnectWalletAndEnableProfile({ wallet }); if (!userPushInstance) { return; } diff --git a/src/components/ChannelSettingsDropdown.tsx b/src/components/ChannelSettingsDropdown.tsx index dac2bf4298..af59b629a7 100644 --- a/src/components/ChannelSettingsDropdown.tsx +++ b/src/components/ChannelSettingsDropdown.tsx @@ -24,7 +24,6 @@ import ChannelReactivateModalContent from './ChannelReactivateModalContent'; // Internal Configs import { appConfig } from 'config/index.js'; import { useAccount, useDeviceWidthCheck } from 'hooks'; -import { AppContext } from 'contexts/AppContext'; import { ethers } from 'ethers'; @@ -47,7 +46,6 @@ function ChannelSettings({ DropdownRef, isDropdownOpen, closeDropdown }: Channel const { userPushSDKInstance } = useSelector((state: any) => { return state.user; }); - const { handleConnectWallet } = React.useContext(AppContext); const theme = useTheme(); const { channelState } = channelDetails; @@ -122,10 +120,6 @@ function ChannelSettings({ DropdownRef, isDropdownOpen, closeDropdown }: Channel const userSignerToast = useToast(); const toggleChannelActivationState = () => { if (isChannelBlocked) return; - // if (!userPushSDKInstance.signer) { - // handleConnectWallet(); - // return; - // } if (isChannelDeactivated) { showReactivateChannelModal(); } else { diff --git a/src/components/NavigationButton.jsx b/src/components/NavigationButton.jsx index 5a0642badf..01f3a1297f 100644 --- a/src/components/NavigationButton.jsx +++ b/src/components/NavigationButton.jsx @@ -37,7 +37,7 @@ function NavigationButton({ item, data, sectionID, active, bg = 'none' }) { setActiveIcon(navigationIcons[data.activeSrc] ?? data.activeSrc); }, [data.src, data.activeSrc]); - const { showMetamaskPushSnap, handleConnectWallet } = useContext(AppContext); + const { showMetamaskPushSnap } = useContext(AppContext); const { readOnlyWallet, mode, sidebarCollapsed } = useContext(GlobalContext); const navigationToast = useToast(5000); @@ -83,9 +83,6 @@ function NavigationButton({ item, data, sectionID, active, bg = 'none' }) { RouteLogic = ProtectedRoute; } - const handleDisallowedNav = () => { - handleConnectWallet(); - }; return ( <> {data.loading && ( @@ -118,7 +115,6 @@ function NavigationButton({ item, data, sectionID, active, bg = 'none' }) { margin={definedMargin} bg={bg} active={active ? 1 : 0} - // onClick={disallowNavigation && handleDisallowedNav} className={data?.name?.toLowerCase()} > {data.iconFactory ? ( diff --git a/src/components/SendNotifications.tsx b/src/components/SendNotifications.tsx index f24b85aea4..df9cb9d094 100644 --- a/src/components/SendNotifications.tsx +++ b/src/components/SendNotifications.tsx @@ -114,7 +114,7 @@ const LIMITER_KEYS = ['Enter', ',']; function SendNotifications() { const theme = useTheme(); const isMobile = useDeviceWidthCheck(425); - const { account, provider, chainId } = useAccount(); + const { account, provider, chainId, wallet } = useAccount(); const { userPushSDKInstance } = useSelector((state: any) => { return state.user; }); @@ -129,7 +129,7 @@ function SendNotifications() { return state.canSend; }); const onCoreNetwork = CORE_CHAIN_ID === chainId; - const { handleConnectWallet } = useContext(AppContext); + const { handleConnectWalletAndEnableProfile } = useContext(AppContext); const [nfProcessing, setNFProcessing] = useState(0); const [channelAddress, setChannelAddress] = useState(''); const [nfRecipient, setNFRecipient] = useState(account); @@ -316,7 +316,7 @@ function SendNotifications() { let userPushInstance = userPushSDKInstance; if (!userPushInstance.signer) { - userPushInstance = await handleConnectWallet(); + userPushInstance = await handleConnectWalletAndEnableProfile({ wallet }); if (!userPushInstance) { return; } diff --git a/src/components/channel/NotificationSettings.tsx b/src/components/channel/NotificationSettings.tsx index e0eeaa1597..624c33071e 100644 --- a/src/components/channel/NotificationSettings.tsx +++ b/src/components/channel/NotificationSettings.tsx @@ -31,7 +31,7 @@ import { NotificationSetting } from '@pushprotocol/restapi/src/lib/pushNotificat const CORE_CHAIN_ID = appConfig.coreContractChain; function NotificationSettings() { - const { account, chainId } = useAccount(); + const { account, chainId, wallet } = useAccount(); const { coreChannelAdmin, delegatees } = useSelector((state: any) => state.admin); const { channelSettings } = useSelector((state: any) => state.channels); @@ -45,7 +45,7 @@ function NotificationSettings() { const [settingToEdit, setSettingToEdit] = useState(); const [isLoading, setIsLoading] = useState(false); const [isLoadingSettings, setIsLoadingSettings] = useState(true); - const { handleConnectWallet } = useContext(AppContext); + const { handleConnectWalletAndEnableProfile } = useContext(AppContext); const { userPushSDKInstance } = useSelector((state: any) => { return state.user; @@ -134,7 +134,7 @@ function NotificationSettings() { let userPushInstance = userPushSDKInstance; if (!userPushInstance.signer) { - userPushInstance = await handleConnectWallet(); + userPushInstance = await handleConnectWalletAndEnableProfile({ wallet }); if (!userPushInstance) { setIsLoading(false); return; diff --git a/src/components/chat/unlockProfile/UnlockProfile.tsx b/src/components/chat/unlockProfile/UnlockProfile.tsx index b98c6c7e7d..de08c8adf1 100644 --- a/src/components/chat/unlockProfile/UnlockProfile.tsx +++ b/src/components/chat/unlockProfile/UnlockProfile.tsx @@ -53,7 +53,7 @@ const UnlockProfile = ({ InnerComponentProps, onClose }: UnlockProfileModalProps const { type, description } = InnerComponentProps; const theme = useTheme(); - const { handleConnectWallet, initializePushSDK } = useContext(AppContext); + const { handleConnectWalletAndEnableProfile, initializePushSDK } = useContext(AppContext); const { account, wallet, connect } = useAccount(); @@ -76,7 +76,7 @@ const UnlockProfile = ({ InnerComponentProps, onClose }: UnlockProfileModalProps }; const handleChatprofileUnlock = useCallback(async () => { - const user = await handleConnectWallet({ remember: rememberMe, wallet }); + const user = await handleConnectWalletAndEnableProfile({ remember: rememberMe, wallet }); const errorExists = checkUnlockProfileErrors(user); diff --git a/src/components/dropdowns/ManageNotifSettingDropdown.tsx b/src/components/dropdowns/ManageNotifSettingDropdown.tsx index 61d55f4ba6..00db98456a 100644 --- a/src/components/dropdowns/ManageNotifSettingDropdown.tsx +++ b/src/components/dropdowns/ManageNotifSettingDropdown.tsx @@ -111,7 +111,7 @@ const ManageNotifSettingDropdownContainer: FC = (options) => { const { children, centerOnMobile, userSetting, channelDetail, onSuccessOptout } = options; const [isOpen, setIsOpen] = useState(false); - const { chainId, provider, account } = useAccount(); + const { chainId, provider, account, wallet } = useAccount(); const { userPushSDKInstance } = useSelector((state: any) => { return state.user; }); @@ -142,7 +142,7 @@ const ManageNotifSettingDropdown: FC = (options //TODO: We can change this back to use Push User // if (!userPushInstance.signer) { - // userPushInstance = await handleConnectWallet(); + // userPushInstance = await handleConnectWalletAndEnableProfile({ wallet }); // if (!userPushInstance) { // setLoadingFunc(false); // return; diff --git a/src/components/dropdowns/OptinNotifSettingDropdown.tsx b/src/components/dropdowns/OptinNotifSettingDropdown.tsx index 7e5602dcaa..0559704880 100644 --- a/src/components/dropdowns/OptinNotifSettingDropdown.tsx +++ b/src/components/dropdowns/OptinNotifSettingDropdown.tsx @@ -186,7 +186,7 @@ const OptinNotifSettingDropdown: FC = (options) const [isOpen, setIsOpen] = useState(false); const dispatch = useDispatch(); - const { handleConnectWallet, connectWallet } = useContext(AppContext); + const { handleConnectWalletAndEnableProfile, connectWallet } = useContext(AppContext); const onCoreNetwork = chainId === appConfig.coreContractChain; @@ -219,7 +219,7 @@ const OptinNotifSettingDropdown: FC = (options) let userPushInstance = userPushSDKInstance; // if (!userPushInstance.signer) { - // userPushInstance = await handleConnectWallet(); + // userPushInstance = await handleConnectWalletAndEnableProfile({ wallet }); // if (!userPushInstance) { // setLoadingFunc(false); // return; diff --git a/src/components/dropdowns/UpdateNotifSettingDropdown.tsx b/src/components/dropdowns/UpdateNotifSettingDropdown.tsx index d9b5cd6e3b..66f9158c5c 100644 --- a/src/components/dropdowns/UpdateNotifSettingDropdown.tsx +++ b/src/components/dropdowns/UpdateNotifSettingDropdown.tsx @@ -186,7 +186,7 @@ const UpdateNotifSettingDropdown: FC = ({ }) => { const [isOpen, setIsOpen] = useState(false); - const { chainId } = useAccount(); + const { chainId, wallet } = useAccount(); const { userPushSDKInstance } = useSelector((state: any) => { return state.user; }); @@ -202,7 +202,7 @@ const UpdateNotifSettingDropdown: FC = ({ setIsOpen(false); }; - const { handleConnectWallet } = useContext(AppContext); + const { handleConnectWalletAndEnableProfile } = useContext(AppContext); const subscribeToast = useToast(); const saveUserSettingHandler = async ({ @@ -219,7 +219,7 @@ const UpdateNotifSettingDropdown: FC = ({ let userPushInstance = userPushSDKInstance; if (!userPushInstance.signer) { - userPushInstance = await handleConnectWallet(); + userPushInstance = await handleConnectWalletAndEnableProfile({ wallet }); if (!userPushInstance) { setLoadingFunc(false); return; diff --git a/src/components/yield/StakingModalComponent.tsx b/src/components/yield/StakingModalComponent.tsx index 9e688a3c2a..8aa7254db8 100644 --- a/src/components/yield/StakingModalComponent.tsx +++ b/src/components/yield/StakingModalComponent.tsx @@ -35,7 +35,7 @@ const StakingModalComponent = ({ onClose, InnerComponentProps, toastObject }) => const [txnMessage, setTxnMessage] = useState(null); - const { handleConnectWallet } = useContext(AppContext); + const { handleConnectWalletAndEnableProfile } = useContext(AppContext); const [depositAmount, setDepositAmount] = useState(0); @@ -81,7 +81,6 @@ const StakingModalComponent = ({ onClose, InnerComponentProps, toastObject }) => }, []); const approveDeposit = async () => { - if (!isWalletConnected) { connect(); return; diff --git a/src/components/yield/YieldPoolCard.tsx b/src/components/yield/YieldPoolCard.tsx index 4f37aa8871..d36fae1eea 100644 --- a/src/components/yield/YieldPoolCard.tsx +++ b/src/components/yield/YieldPoolCard.tsx @@ -41,7 +41,7 @@ const YieldPoolCard = ({ tokenAddress, setActiveTab, }: any) => { - const { account, provider } = useAccount(); + const { account, provider, wallet } = useAccount(); const [txInProgressWithdraw, setTxInProgressWithdraw] = useState(false); const [txInProgressClaimRewards, setTxInProgressClaimRewards] = useState(false); @@ -55,7 +55,7 @@ const YieldPoolCard = ({ const { userPushSDKInstance } = useSelector((state: any) => { return state.user; }); - const { handleConnectWallet } = useContext(AppContext); + const { handleConnectWalletAndEnableProfile } = useContext(AppContext); const [filled, setFilled] = useState(0); @@ -65,7 +65,7 @@ const YieldPoolCard = ({ const massClaimRewardsTokensAll = async () => { if (!userPushSDKInstance.signer) { - handleConnectWallet(); + handleConnectWalletAndEnableProfile({ wallet }); return; } @@ -153,7 +153,7 @@ const YieldPoolCard = ({ const withdrawTokens = async () => { if (!userPushSDKInstance.signer) { - handleConnectWallet(); + handleConnectWalletAndEnableProfile({ wallet }); return; } @@ -234,7 +234,7 @@ const YieldPoolCard = ({ const migrateToNewPool = async () => { if (!userPushSDKInstance.signer) { - handleConnectWallet(); + handleConnectWalletAndEnableProfile({ wallet }); return; } @@ -457,7 +457,7 @@ const YieldPoolCard = ({ const depositLpToken = async (tx, withdrawAmount, totalTxnSteps) => { if (!userPushSDKInstance.signer) { - handleConnectWallet(); + handleConnectWalletAndEnableProfile({ wallet }); return; } @@ -510,7 +510,7 @@ const YieldPoolCard = ({ const depositPushToken = async (tx, withdrawAmount, totalTxnSteps) => { if (!userPushSDKInstance.signer) { - handleConnectWallet(); + handleConnectWalletAndEnableProfile({ wallet }); return; } diff --git a/src/contexts/AppContext.tsx b/src/contexts/AppContext.tsx index 457e79f5cd..96c82add27 100644 --- a/src/contexts/AppContext.tsx +++ b/src/contexts/AppContext.tsx @@ -96,8 +96,7 @@ const AppContextProvider = ({ children }) => { } }; - // TODO: Change function name to handleConnectWalletAndUser - const handleConnectWallet = async ({ + const handleConnectWalletAndEnableProfile = async ({ remember = false, showToast = false, toastMessage = undefined, @@ -126,7 +125,7 @@ const AppContextProvider = ({ children }) => { let user; - if (wallet?.accounts?.length > 0) { + if (wallet && typeof wallet === 'object' && wallet?.accounts?.length > 0) { user = await initializePushSDK(wallet); } else { const walletConnected = await connect(); @@ -535,7 +534,7 @@ const AppContextProvider = ({ children }) => { setSnapState, initializePushSDK, SnapState, - handleConnectWallet, + handleConnectWalletAndEnableProfile, connectWallet, setSnapInstalled, snapInstalled, diff --git a/src/modules/channelDashboard/ChannelOwnerDashboard.tsx b/src/modules/channelDashboard/ChannelOwnerDashboard.tsx index 4295ec09a1..2be592a9cb 100644 --- a/src/modules/channelDashboard/ChannelOwnerDashboard.tsx +++ b/src/modules/channelDashboard/ChannelOwnerDashboard.tsx @@ -43,7 +43,7 @@ let intervalID = null; // CREATE CHANNEL OWNER DASHBOARD const ChannelOwnerDashboard = () => { const theme = useTheme(); - const { account, chainId } = useAccount(); + const { account, chainId, wallet } = useAccount(); const { channelDetails, delegatees, @@ -54,7 +54,7 @@ const ChannelOwnerDashboard = () => { const { userPushSDKInstance } = useSelector((state: any) => { return state.user; }); - const { handleConnectWallet } = useContext(AppContext); + const { handleConnectWalletAndEnableProfile } = useContext(AppContext); const isChannelDetails = channelDetails && channelDetails !== 'unfetched'; @@ -175,7 +175,7 @@ const ChannelOwnerDashboard = () => { const showEditChannel = () => { // if (!userPushSDKInstance.signer) { - // handleConnectWallet(); + // handleConnectWalletAndEnableProfile({wallet}); // return; // } setEditChannel(true); diff --git a/src/modules/chat/ChatModule.tsx.deprecated b/src/modules/chat/ChatModule.tsx.deprecated index 649fc91c13..21ecf3545f 100644 --- a/src/modules/chat/ChatModule.tsx.deprecated +++ b/src/modules/chat/ChatModule.tsx.deprecated @@ -73,7 +73,7 @@ function Chat({ chatid }) { setConnectedUser, displayQR, setDisplayQR, - handleConnectWallet, + handleConnectWalletAndEnableProfile, } = useContext(AppContext); const { userPushSDKInstance } = useSelector((state: any) => { diff --git a/src/modules/createChannel/CreateChannelModule.jsx b/src/modules/createChannel/CreateChannelModule.jsx index dcfa401185..75dc3c3903 100644 --- a/src/modules/createChannel/CreateChannelModule.jsx +++ b/src/modules/createChannel/CreateChannelModule.jsx @@ -36,11 +36,11 @@ const CORE_CHAIN_ID = appConfig.coreContractChain; // Create Header function CreateChannelModule() { - const { account, provider, chainId } = useAccount(); + const { account, provider, chainId, wallet } = useAccount(); const { userPushSDKInstance } = useSelector((state) => { return state.user; }); - const { handleConnectWallet } = useContext(AppContext); + const { handleConnectWalletAndEnableProfile } = useContext(AppContext); const theme = useTheme(); const onCoreNetwork = CORE_CHAIN_ID === chainId; @@ -240,7 +240,7 @@ function CreateChannelModule() { // e.preventDefault(); if (!userPushSDKInstance.signer) { - handleConnectWallet(); + handleConnectWalletAndEnableProfile({wallet}); return; } diff --git a/src/sections/chat/ChatSidebarSection.tsx b/src/sections/chat/ChatSidebarSection.tsx index de51096557..9dedd16182 100644 --- a/src/sections/chat/ChatSidebarSection.tsx +++ b/src/sections/chat/ChatSidebarSection.tsx @@ -85,7 +85,7 @@ const ChatSidebarSection = ({ showCreateGroupModal, chatId, selectedChatId, setS // showCreateGroupModal(); // } else { // if (userPushSDKInstance.account === readOnlyWallet) { - // handleConnectWallet(); + // handleConnectWalletAndEnableProfile(); // } else { // if (userPushSDKInstance.signer === undefined) { // await initializePushSDK(); diff --git a/src/types/context.ts b/src/types/context.ts index 326ea12bef..e784ddc2bb 100644 --- a/src/types/context.ts +++ b/src/types/context.ts @@ -44,7 +44,12 @@ export interface AppContextType { initializePushSDK: () => Promise; snapInstalled: boolean; setSnapInstalled: (snapInstalled: boolean) => void; - handleConnectWallet: (showToast?: boolean, toastMessage?: string) => any; + handleConnectWalletAndEnableProfile: ( + showToast?: boolean, + toastMessage?: string, + wallet?: any, + remember?: any + ) => any; connectWallet: (showToast?: boolean, toastMessage?: string) => any; setBlockedLoading: (blockedLoading: BlockedLoadingI) => void; blockedLoading: BlockedLoadingI;