Skip to content

Commit

Permalink
Fixed issues in the Opt In flow
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek-01k committed Feb 26, 2024
1 parent d99e8b0 commit 0bbe270
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 68 deletions.
2 changes: 1 addition & 1 deletion src/AppLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const AppLogin = ({ toggleDarkMode }) => {
}

const initiateGuestModa = () => {
const guestModeAddress = '0x0000000000000000000000000000000000000000';
const guestModeAddress = '0x0000000000000000000000000000000000000001';
setMode(ReadOnlyWalletMode.GUEST_MODE);
setReadOnlyWallet(guestModeAddress);
hideOnboardModal();
Expand Down
17 changes: 13 additions & 4 deletions src/components/dropdowns/ManageNotifSettingDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,20 @@ const ManageNotifSettingDropdown: React.FC<ManageNotifSettingDropdownProps> = (o
const optOutHandler = async ({ setLoading }: { setLoading?: React.Dispatch<React.SetStateAction<boolean>> }) => {
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 {
Expand All @@ -149,7 +158,7 @@ const ManageNotifSettingDropdown: React.FC<ManageNotifSettingDropdownProps> = (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 }));
Expand Down
95 changes: 52 additions & 43 deletions src/components/dropdowns/OptinNotifSettingDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,48 +71,48 @@ const OptinNotifSettingDropdownContainer: React.FC<OptinNotifSettingDropdownCont
key={index}
hasBottomBorder={index !== settings.length - 1}
>
<DropdownSwitchItem>
<SpanV2 color={theme.settingsModalPrimaryTextColor} fontSize="15px" fontWeight='500' textAlign="left">{setting.description}</SpanV2>
<Switch
onChange={() => handleSwitchChange(index)} checked={setting.type === 1 ? setting.default : setting.enabled}
checkedIcon={false}
uncheckedIcon={false}
onColor="#D53A94"
offColor="#A0A3B1"
height={16}
width={32}
handleDiameter={12}
/>
</DropdownSwitchItem>
{setting.type === 2 && setting.enabled === true && (
<DropdownSliderItem>
<SpanV2 color={theme.fontColor} fontSize="18px" fontWeight='600' alignSelf="flex-start">
{setting.default}
</SpanV2>
<InputSlider
val={setting.default}
max={setting.upperLimit}
min={setting.lowerLimit}
step={setting.ticker || 1}
defaultVal={setting.default}
onChange={({ x }) => handleSliderChange(index, x)}
/>
</DropdownSliderItem>
)}
<DropdownSwitchItem>
<SpanV2 color={theme.settingsModalPrimaryTextColor} fontSize="15px" fontWeight='500' textAlign="left">{setting.description}</SpanV2>
<Switch
onChange={() => handleSwitchChange(index)} checked={setting.type === 1 ? setting.default : setting.enabled}
checkedIcon={false}
uncheckedIcon={false}
onColor="#D53A94"
offColor="#A0A3B1"
height={16}
width={32}
handleDiameter={12}
/>
</DropdownSwitchItem>
{setting.type === 2 && setting.enabled === true && (
<DropdownSliderItem>
<SpanV2 color={theme.fontColor} fontSize="18px" fontWeight='600' alignSelf="flex-start">
{setting.default}
</SpanV2>
<InputSlider
val={setting.default}
max={setting.upperLimit}
min={setting.lowerLimit}
step={setting.ticker || 1}
defaultVal={setting.default}
onChange={({ x }) => handleSliderChange(index, x)}
/>
</DropdownSliderItem>
)}
{setting.type === 3 && setting.enabled === true && (
<DropdownSliderItem>
<SpanV2 color={theme.fontColor} fontSize="18px" fontWeight='600' alignSelf="flex-start">
{setting.default.lower} - {setting.default.upper}
{setting.default.lower} - {setting.default.upper}
</SpanV2>
<RangeSlider
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})}
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 })}
/>
</DropdownSliderItem>
)}
Expand Down Expand Up @@ -171,12 +171,21 @@ const OptinNotifSettingDropdown: React.FC<OptinNotifSettingDropdownProps> = (opt

const optInHandler = async ({ channelSettings, setLoading }: { channelSettings?: ChannelSetting[], setLoading?: React.Dispatch<React.SetStateAction<boolean>> }) => {
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 {
Expand All @@ -187,7 +196,7 @@ const OptinNotifSettingDropdown: React.FC<OptinNotifSettingDropdownProps> = (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: () => {
Expand Down
17 changes: 13 additions & 4 deletions src/components/dropdowns/UpdateNotifSettingDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,19 @@ const UpdateNotifSettingDropdown: React.FC<UpdateNotifSettingDropdownProps> = ({
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);

Expand All @@ -193,7 +202,7 @@ const UpdateNotifSettingDropdown: React.FC<UpdateNotifSettingDropdownProps> = ({

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: () => {
Expand Down
24 changes: 18 additions & 6 deletions src/contexts/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}

}
Expand All @@ -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;
}


Expand Down Expand Up @@ -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,
Expand All @@ -227,9 +237,11 @@ const AppContextProvider = ({ children }) => {
}

dispatch(setUserPushSDKInstance(userInstance));
return userInstance;
} catch (error) {
// Handle initialization error
console.log("Errror !!!!!", error);
return null;
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/contexts/GlobalContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type GlobalContextType = {
export const GlobalContext = createContext<GlobalContextType | null>(null);

const GlobalContextProvider = ({ children }) => {
const [readOnlyWallet, setReadOnlyWallet] = useState<string>('0x0000000000000000000000000000000000000000');
const [readOnlyWallet, setReadOnlyWallet] = useState<string>('0x0000000000000000000000000000000000000001');
const [mode, setMode] = useState<ReadOnlyWalletMode>(ReadOnlyWalletMode.GUEST_MODE);
const [sidebarCollapsed, setSidebarCollapsed] = useState<boolean>(false);

Expand Down
12 changes: 8 additions & 4 deletions src/primaries/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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',
Expand All @@ -87,6 +87,10 @@ const Profile = ({ isDarkMode }) => {
setShowDropdown(false);
});

const ConnectWallet = ()=>{
connect();
}


// to create blockies
return (
Expand All @@ -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
</Wallet>
Expand Down Expand Up @@ -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
</Wallet>
Expand Down
4 changes: 2 additions & 2 deletions src/sections/chat/ChatSidebarSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion src/segments/Feedbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Item } from "primaries/SharedStyling";
import {
addPaginatedNotifications,
incrementPage,
resetNotificationsSlice,
setFinishedFetching,
updateTopNotifications
} from "redux/slices/notificationSlice";
Expand All @@ -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";
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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]);
Expand Down
Loading

0 comments on commit 0bbe270

Please sign in to comment.