diff --git a/src/AppLogin.tsx b/src/AppLogin.tsx index e32da8f003..610081e1b6 100644 --- a/src/AppLogin.tsx +++ b/src/AppLogin.tsx @@ -121,7 +121,7 @@ const AppLogin = ({ toggleDarkMode }) => { } const initiateGuestModa = () => { - const guestModeAddress = '0x0000000000000000000000000000000000000000'; + const guestModeAddress = '0x0000000000000000000000000000000000000001'; setMode(ReadOnlyWalletMode.GUEST_MODE); setReadOnlyWallet(guestModeAddress); hideOnboardModal(); diff --git a/src/components/dropdowns/ManageNotifSettingDropdown.tsx b/src/components/dropdowns/ManageNotifSettingDropdown.tsx index dadef23168..1fded52153 100644 --- a/src/components/dropdowns/ManageNotifSettingDropdown.tsx +++ b/src/components/dropdowns/ManageNotifSettingDropdown.tsx @@ -134,11 +134,20 @@ const ManageNotifSettingDropdown: React.FC = (o const optOutHandler = async ({ setLoading }: { setLoading?: React.Dispatch> }) => { const setLoadingFunc = setLoading || (() => {}); - if (!userPushSDKInstance.signer) { - handleConnectWallet(); - return; + let userPushInstance = userPushSDKInstance; + + console.log("User Push Instance >>>>>",userPushInstance); + + if (!userPushInstance.signer) { + userPushInstance = await handleConnectWallet(); + console.log("Res >>>>>>> ",userPushInstance); + if (!userPushInstance) { + return; + } } + console.log("User Push",userPushInstance); + setLoadingFunc(true); try { @@ -149,7 +158,7 @@ const ManageNotifSettingDropdown: React.FC = (o unsubscribeToast.showLoaderToast({ loaderMessage: 'Waiting for Confirmation...' }); - await userPushSDKInstance.notification.unsubscribe(convertAddressToAddrCaip(channelAddress, chainId), { + await userPushInstance.notification.unsubscribe(convertAddressToAddrCaip(channelAddress, chainId), { onSuccess: () => { onSuccessOptout(); dispatch(updateSubscriptionStatus({ channelAddress: channelAddress, status: false })); diff --git a/src/components/dropdowns/OptinNotifSettingDropdown.tsx b/src/components/dropdowns/OptinNotifSettingDropdown.tsx index a6c879f8a8..61f12518fa 100644 --- a/src/components/dropdowns/OptinNotifSettingDropdown.tsx +++ b/src/components/dropdowns/OptinNotifSettingDropdown.tsx @@ -71,48 +71,48 @@ const OptinNotifSettingDropdownContainer: React.FC - - {setting.description} - handleSwitchChange(index)} checked={setting.type === 1 ? setting.default : setting.enabled} - checkedIcon={false} - uncheckedIcon={false} - onColor="#D53A94" - offColor="#A0A3B1" - height={16} - width={32} - handleDiameter={12} - /> - - {setting.type === 2 && setting.enabled === true && ( - - - {setting.default} - - handleSliderChange(index, x)} - /> - - )} + + {setting.description} + handleSwitchChange(index)} checked={setting.type === 1 ? setting.default : setting.enabled} + checkedIcon={false} + uncheckedIcon={false} + onColor="#D53A94" + offColor="#A0A3B1" + height={16} + width={32} + handleDiameter={12} + /> + + {setting.type === 2 && setting.enabled === true && ( + + + {setting.default} + + handleSliderChange(index, x)} + /> + + )} {setting.type === 3 && setting.enabled === true && ( - {setting.default.lower} - {setting.default.upper} + {setting.default.lower} - {setting.default.upper} handleSliderChange(index, {lower: startVal, upper: endVal})} + startVal={setting.default.lower} + endVal={setting.default.upper} + max={setting.upperLimit} + min={setting.lowerLimit} + step={setting.ticker || 1} + defaultStartVal={setting.default.lower} + defaultEndVal={setting.default.upper} + onChange={({ startVal, endVal }) => handleSliderChange(index, { lower: startVal, upper: endVal })} /> )} @@ -171,12 +171,21 @@ const OptinNotifSettingDropdown: React.FC = (opt const optInHandler = async ({ channelSettings, setLoading }: { channelSettings?: ChannelSetting[], setLoading?: React.Dispatch> }) => { const setLoadingFunc = setLoading || (options && options.setLoading) || (() => { }); - - if (!userPushSDKInstance.signer) { - handleConnectWallet(); - return; + + let userPushInstance = userPushSDKInstance; + + console.log("User Push Instance >>>>>",userPushInstance); + + if (!userPushInstance.signer) { + userPushInstance = await handleConnectWallet(); + console.log("Res >>>>>>> ",userPushInstance); + if (!userPushInstance) { + return; + } } - + + console.log("User Push",userPushInstance); + setLoadingFunc(true); try { @@ -187,7 +196,7 @@ const OptinNotifSettingDropdown: React.FC = (opt subscribeToast.showLoaderToast({ loaderMessage: 'Waiting for Confirmation...' }); - await userPushSDKInstance.notification.subscribe(convertAddressToAddrCaip(channelAddress, chainId), { + await userPushInstance.notification.subscribe(convertAddressToAddrCaip(channelAddress, chainId), { settings: notifChannelSettingFormatString({ settings: channelSettings }), // settings: [], onSuccess: () => { diff --git a/src/components/dropdowns/UpdateNotifSettingDropdown.tsx b/src/components/dropdowns/UpdateNotifSettingDropdown.tsx index 055ea4c2fa..e47c709109 100644 --- a/src/components/dropdowns/UpdateNotifSettingDropdown.tsx +++ b/src/components/dropdowns/UpdateNotifSettingDropdown.tsx @@ -178,10 +178,19 @@ const UpdateNotifSettingDropdown: React.FC = ({ const setLoadingFunc = setLoading || (() => {}); const saveOnSuccessSettingFunc = onSuccessSave || (() => {}); - if (!userPushSDKInstance.signer) { - handleConnectWallet(); - return; + let userPushInstance = userPushSDKInstance; + + console.log("User Push Instance >>>>>",userPushInstance); + + if (!userPushInstance.signer) { + userPushInstance = await handleConnectWallet(); + console.log("Res >>>>>>> ",userPushInstance); + if (!userPushInstance) { + return; + } } + + console.log("User Push",userPushInstance); setLoadingFunc(true); @@ -193,7 +202,7 @@ const UpdateNotifSettingDropdown: React.FC = ({ subscribeToast.showLoaderToast({ loaderMessage: 'Waiting for Confirmation...' }); - await userPushSDKInstance.notification.subscribe(convertAddressToAddrCaip(channelAddress, chainId), { + await userPushInstance.notification.subscribe(convertAddressToAddrCaip(channelAddress, chainId), { settings: notifUserSettingFormatString({ settings: userSettings }), // settings: [], onSuccess: () => { diff --git a/src/contexts/AppContext.tsx b/src/contexts/AppContext.tsx index b0bfebe771..d9145c072c 100644 --- a/src/contexts/AppContext.tsx +++ b/src/contexts/AppContext.tsx @@ -67,9 +67,14 @@ const AppContextProvider = ({ children }) => { if (wallet?.accounts?.length > 0) { - await initializePushSDK(); + console.log('Wallet connected',wallet); + const userPushInstance = await initializePushSDK(); + return userPushInstance; } else { - connect(); + const walletConnected = await connect(); + console.log("Wallet connected",walletConnected); + return null; + } } @@ -80,20 +85,21 @@ const AppContextProvider = ({ children }) => { console.log("Initialising Push SDK Guest Mode"); let userInstance; userInstance = await PushAPI.initialize({ - account: '0x0000000000000000000000000000000000000000', + account: '0x0000000000000000000000000000000000000001', env: appConfig.appEnv, }); dispatch(setUserPushSDKInstance(userInstance)); } const initialisePushSdkReadMode = async () => { - console.log("Initialising Push SDK Read Mode"); let userInstance; userInstance = await PushAPI.initialize({ env: appConfig.appEnv, account: account, }); + console.log("User Instance in read Mode",userInstance); dispatch(setUserPushSDKInstance(userInstance)); + return userInstance; } @@ -206,16 +212,20 @@ const AppContextProvider = ({ children }) => { }; - const initializePushSDK = async () => { + const initializePushSDK = async (address?:string) => { let userInstance; try { + console.log("Addresss >>>>>>",address,account); const librarySigner = provider?.getSigner(account); userInstance = await PushAPI.initialize(librarySigner!, { env: appConfig.appEnv, - account: account, + account: address ? address : account, progressHook: onboardingProgressReformatter, }); + console.log("User Push SDK instance in App Context >>",userInstance); + + if (userInstance) { setBlockedLoading({ enabled: false, @@ -227,9 +237,11 @@ const AppContextProvider = ({ children }) => { } dispatch(setUserPushSDKInstance(userInstance)); + return userInstance; } catch (error) { // Handle initialization error console.log("Errror !!!!!", error); + return null; } }; diff --git a/src/contexts/GlobalContext.tsx b/src/contexts/GlobalContext.tsx index 02c8528ffa..e14ea3bdf4 100644 --- a/src/contexts/GlobalContext.tsx +++ b/src/contexts/GlobalContext.tsx @@ -17,7 +17,7 @@ export type GlobalContextType = { export const GlobalContext = createContext(null); const GlobalContextProvider = ({ children }) => { - const [readOnlyWallet, setReadOnlyWallet] = useState('0x0000000000000000000000000000000000000000'); + const [readOnlyWallet, setReadOnlyWallet] = useState('0x0000000000000000000000000000000000000001'); const [mode, setMode] = useState(ReadOnlyWalletMode.GUEST_MODE); const [sidebarCollapsed, setSidebarCollapsed] = useState(false); diff --git a/src/primaries/Profile.tsx b/src/primaries/Profile.tsx index a33eff33d2..509120cbcc 100644 --- a/src/primaries/Profile.tsx +++ b/src/primaries/Profile.tsx @@ -25,7 +25,7 @@ import { SpanV2 } from 'components/reusables/SharedStylingV2.js'; // Create Header const Profile = ({ isDarkMode }) => { - const { web3NameList,initialisePushSdkReadMode,handleConnectWallet }: AppContextType = useContext(AppContext); + const { web3NameList,initialisePushSdkReadMode }: AppContextType = useContext(AppContext); const { setReadOnlyWallet, readOnlyWallet, mode, setMode }: GlobalContextType = useContext(GlobalContext); const { authError } = useContext(ErrorContext); const toggleArrowRef = useRef(null); @@ -76,7 +76,7 @@ const Profile = ({ isDarkMode }) => { function: async () => { await disconnect(wallet); setMode(ReadOnlyWalletMode.GUEST_MODE); - setReadOnlyWallet('0x0000000000000000000000000000000000000000'); + setReadOnlyWallet('0x0000000000000000000000000000000000000001'); }, title: 'Logout', invertedIcon: './logout.svg', @@ -87,6 +87,10 @@ const Profile = ({ isDarkMode }) => { setShowDropdown(false); }); + const ConnectWallet = ()=>{ + connect(); + } + // to create blockies return ( @@ -100,7 +104,7 @@ const Profile = ({ isDarkMode }) => { bg="linear-gradient(87.17deg, #B6A0F5 0%, #F46EF7 57.29%, #FF95D5 100%)" color='#FFF' isDarkMode={isDarkMode} - onClick={()=>handleConnectWallet()} + onClick={()=>ConnectWallet()} > Connect Wallet @@ -163,7 +167,7 @@ const Profile = ({ isDarkMode }) => { bg="linear-gradient(87.17deg, #B6A0F5 0%, #F46EF7 57.29%, #FF95D5 100%)" color='#FFF' isDarkMode={isDarkMode} - onClick={()=>handleConnectWallet()} + onClick={()=>ConnectWallet()} > Connect Wallet diff --git a/src/sections/chat/ChatSidebarSection.tsx b/src/sections/chat/ChatSidebarSection.tsx index 7d0ba3863d..adee178ae9 100644 --- a/src/sections/chat/ChatSidebarSection.tsx +++ b/src/sections/chat/ChatSidebarSection.tsx @@ -103,7 +103,7 @@ const ChatSidebarSection = ({ showCreateGroupModal, autofilledSearch }) => { } return formattedChatParticipant; } else { - if (userPushSDKInstance.account === '0x0000000000000000000000000000000000000000') { + if (userPushSDKInstance.account === '0x0000000000000000000000000000000000000001') { handleConnectWallet(); } else if (userPushSDKInstance.signer === undefined || userPushSDKInstance.decryptedPgpPvtKey === undefined) { await initializePushSDK(); @@ -116,7 +116,7 @@ const ChatSidebarSection = ({ showCreateGroupModal, autofilledSearch }) => { if (userPushSDKInstance.decryptedPgpPvtKey) { showCreateGroupModal(); } else { - if (userPushSDKInstance.account === '0x0000000000000000000000000000000000000000') { + if (userPushSDKInstance.account === '0x0000000000000000000000000000000000000001') { handleConnectWallet(); } else { if (userPushSDKInstance.signer === undefined) { diff --git a/src/segments/Feedbox.tsx b/src/segments/Feedbox.tsx index f352e36153..189faa29c5 100644 --- a/src/segments/Feedbox.tsx +++ b/src/segments/Feedbox.tsx @@ -19,6 +19,7 @@ import { Item } from "primaries/SharedStyling"; import { addPaginatedNotifications, incrementPage, + resetNotificationsSlice, setFinishedFetching, updateTopNotifications } from "redux/slices/notificationSlice"; @@ -29,6 +30,7 @@ import { useAccount, useDeviceWidthCheck } from "hooks"; import { ReactComponent as MetamaskLogo } from 'assets/PushSnaps/metamasksnap.svg'; import { ReactComponent as Close } from 'assets/chat/group-chat/close.svg'; import { ReactComponent as OpenLink } from 'assets/PushSnaps/GoToImage.svg' +import { GlobalContext } from "contexts/GlobalContext"; // Internal Configs import { appConfig } from "config"; @@ -71,6 +73,7 @@ const Feedbox = ({ showFilter, setShowFilter, search, setSearch }) => { const [loadFilter, setLoadFilter] = React.useState(false); const [bgUpdateLoading, setBgUpdateLoading] = React.useState(false); const [loading, setLoading] = React.useState(false); + const {readOnlyWallet } = useContext(GlobalContext); const [showSnapInfo, setShowSnapInfo] = React.useState(true); @@ -173,11 +176,13 @@ const Feedbox = ({ showFilter, setShowFilter, search, setSearch }) => { setBgUpdateLoading(true); setLoading(true); try { + console.log("User Push sdk instance in fetch latest notifications",userPushSDKInstance); const results = await await userPushSDKInstance.notification.list('INBOX', { raw: true, page: 1, limit: NOTIFICATIONS_PER_PAGE }); + console.log("REsults >>>>",results); if (!notifications.length) { dispatch(incrementPage()); } @@ -242,7 +247,8 @@ const Feedbox = ({ showFilter, setShowFilter, search, setSearch }) => { }; React.useEffect(() => { - if (!userPushSDKInstance) return; + console.log("User Push sdk instance",userPushSDKInstance,readOnlyWallet); + if (userPushSDKInstance?.account == readOnlyWallet) return; fetchLatestNotifications(); fetchAllNotif(); }, [toggle, userPushSDKInstance]); diff --git a/src/segments/ViewChannels.tsx b/src/segments/ViewChannels.tsx index 95ad74ff7c..d2dcf15416 100644 --- a/src/segments/ViewChannels.tsx +++ b/src/segments/ViewChannels.tsx @@ -191,7 +191,8 @@ function ViewChannels({ loadTeaser, playTeaser }) { return () => { clearTimeout(timeout); }; - }, [search, userPushSDKInstance]); + // userPushSDKInstance should not be used as dependency here. + }, [search]); useEffect(() => { if (!account || !userPushSDKInstance) return; diff --git a/src/types/context.ts b/src/types/context.ts index 933238ca01..2d2cc96fcc 100644 --- a/src/types/context.ts +++ b/src/types/context.ts @@ -45,7 +45,7 @@ export interface AppContextType { initializePushSDK: () => Promise; snapInstalled: boolean; setSnapInstalled: (snapInstalled: boolean) => void; - handleConnectWallet: (showToast?: boolean, toastMessage?: string) => void; + handleConnectWallet: (showToast?: boolean, toastMessage?: string) => any; setBlockedLoading: (blockedLoading: BlockedLoadingI) => void; blockedLoading: BlockedLoadingI; getUser: () => Promise;