Skip to content

Commit

Permalink
Updated read mode feature
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek-01k committed Feb 20, 2024
1 parent 1b339f1 commit 9547e78
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
18 changes: 14 additions & 4 deletions src/contexts/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const AppContext = createContext<AppContextType | null>(null);
const AppContextProvider = ({ children }) => {
const { connect, provider, account, wallet, connecting } = useAccount();
const web3onboardToast = useToast();
const { setReadOnlyWallet, readOnlyWallet, setMode } = useContext(GlobalContext);

const [web3NameList, setWeb3NameList] = useState<Web3NameListType>({});
const [snapInstalled, setSnapInstalled] = useState(false);
Expand Down Expand Up @@ -98,6 +97,7 @@ const AppContextProvider = ({ children }) => {


const initialisePushSdkGuestMode = async () => {
console.log("Initialising Push SDK Guest Mode");
let userInstance;
userInstance = await PushAPI.initialize({
account: '0x0000000000000000000000000000000000000000',
Expand All @@ -106,6 +106,16 @@ const AppContextProvider = ({ children }) => {
dispatch(setUserPushSDKInstance(userInstance));
}

const initialisePushSdkReadMode = async () => {
console.log("Initialising Push SDK Read Mode");
let userInstance;
userInstance = await PushAPI.initialize({
env: appConfig.appEnv,
account: account,
});
dispatch(setUserPushSDKInstance(userInstance));
}



// To reformat errors
Expand Down Expand Up @@ -220,8 +230,8 @@ const AppContextProvider = ({ children }) => {
let userInstance;
try {
const librarySigner = provider?.getSigner(account);
userInstance = await PushAPI.initialize(librarySigner, {
env: appConfig.appEnv, // defaults to staging
userInstance = await PushAPI.initialize(librarySigner!,{
env: appConfig.appEnv,
account: account,
progressHook: onboardingProgressReformatter,
});
Expand Down Expand Up @@ -290,7 +300,7 @@ const AppContextProvider = ({ children }) => {
const librarySigner = provider?.getSigner(account);
// if (!account || !appConfig?.appEnv) return;
if (wallet?.accounts?.length > 0) {
initializePushSDK();
initialisePushSdkReadMode();
} else {
initialisePushSdkGuestMode();
}
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useAccount.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useConnectWallet, useSetChain } from '@web3-onboard/react';
import { appConfig } from 'config';
import { GlobalContext } from 'contexts/GlobalContext';
import { GlobalContext, ReadOnlyWalletMode } from 'contexts/GlobalContext';
import { ethers } from 'ethers';
import { useContext, useMemo } from 'react';

Expand Down
4 changes: 3 additions & 1 deletion src/primaries/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ const Profile = ({ isDarkMode }) => {
value: '',
function: async () => {
if (readOnlyWallet) {
setReadOnlyWallet('');
setReadOnlyWallet('0x0000000000000000000000000000000000000000');
} else {
await disconnect(wallet);
setMode(ReadOnlyWalletMode.GUEST_MODE);
setReadOnlyWallet('0x0000000000000000000000000000000000000000');
}
},
title: 'Logout',
Expand Down

0 comments on commit 9547e78

Please sign in to comment.