Skip to content

Commit

Permalink
Update Enable Push profile function (#1743)
Browse files Browse the repository at this point in the history
* update function name, and update wallet condition

* remove unused
  • Loading branch information
corlard3y authored Jul 17, 2024
1 parent 1b7165b commit d4509b9
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 52 deletions.
8 changes: 4 additions & 4 deletions src/components/ChannelDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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([]);
Expand Down Expand Up @@ -78,7 +78,7 @@ export default function ChannelDetails({ isChannelExpired, setIsChannelExpired,

const handleDelegateModal = async () => {
if (!userPushSDKInstance.signer) {
await handleConnectWallet();
await handleConnectWalletAndEnableProfile({ wallet });
}
showAddDelegateModal();
};
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 0 additions & 6 deletions src/components/ChannelSettingsDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 1 addition & 5 deletions src/components/NavigationButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -83,9 +83,6 @@ function NavigationButton({ item, data, sectionID, active, bg = 'none' }) {
RouteLogic = ProtectedRoute;
}

const handleDisallowedNav = () => {
handleConnectWallet();
};
return (
<>
{data.loading && (
Expand Down Expand Up @@ -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 ? (
Expand Down
6 changes: 3 additions & 3 deletions src/components/SendNotifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand All @@ -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);
Expand Down Expand Up @@ -316,7 +316,7 @@ function SendNotifications() {

let userPushInstance = userPushSDKInstance;
if (!userPushInstance.signer) {
userPushInstance = await handleConnectWallet();
userPushInstance = await handleConnectWalletAndEnableProfile({ wallet });
if (!userPushInstance) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/channel/NotificationSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -45,7 +45,7 @@ function NotificationSettings() {
const [settingToEdit, setSettingToEdit] = useState<ChannelSetting>();
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;
Expand Down Expand Up @@ -134,7 +134,7 @@ function NotificationSettings() {

let userPushInstance = userPushSDKInstance;
if (!userPushInstance.signer) {
userPushInstance = await handleConnectWallet();
userPushInstance = await handleConnectWalletAndEnableProfile({ wallet });
if (!userPushInstance) {
setIsLoading(false);
return;
Expand Down
4 changes: 2 additions & 2 deletions src/components/chat/unlockProfile/UnlockProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

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

Expand Down
4 changes: 2 additions & 2 deletions src/components/dropdowns/ManageNotifSettingDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const ManageNotifSettingDropdownContainer: FC<ManageNotifSettingDropdownContaine
const ManageNotifSettingDropdown: FC<ManageNotifSettingDropdownProps> = (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;
});
Expand Down Expand Up @@ -142,7 +142,7 @@ const ManageNotifSettingDropdown: FC<ManageNotifSettingDropdownProps> = (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;
Expand Down
4 changes: 2 additions & 2 deletions src/components/dropdowns/OptinNotifSettingDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ const OptinNotifSettingDropdown: FC<OptinNotifSettingDropdownProps> = (options)
const [isOpen, setIsOpen] = useState(false);
const dispatch = useDispatch();

const { handleConnectWallet, connectWallet } = useContext(AppContext);
const { handleConnectWalletAndEnableProfile, connectWallet } = useContext(AppContext);

const onCoreNetwork = chainId === appConfig.coreContractChain;

Expand Down Expand Up @@ -219,7 +219,7 @@ const OptinNotifSettingDropdown: FC<OptinNotifSettingDropdownProps> = (options)

let userPushInstance = userPushSDKInstance;
// if (!userPushInstance.signer) {
// userPushInstance = await handleConnectWallet();
// userPushInstance = await handleConnectWalletAndEnableProfile({ wallet });
// if (!userPushInstance) {
// setLoadingFunc(false);
// return;
Expand Down
6 changes: 3 additions & 3 deletions src/components/dropdowns/UpdateNotifSettingDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ const UpdateNotifSettingDropdown: FC<UpdateNotifSettingDropdownProps> = ({
}) => {
const [isOpen, setIsOpen] = useState(false);

const { chainId } = useAccount();
const { chainId, wallet } = useAccount();
const { userPushSDKInstance } = useSelector((state: any) => {
return state.user;
});
Expand All @@ -202,7 +202,7 @@ const UpdateNotifSettingDropdown: FC<UpdateNotifSettingDropdownProps> = ({
setIsOpen(false);
};

const { handleConnectWallet } = useContext(AppContext);
const { handleConnectWalletAndEnableProfile } = useContext(AppContext);

const subscribeToast = useToast();
const saveUserSettingHandler = async ({
Expand All @@ -219,7 +219,7 @@ const UpdateNotifSettingDropdown: FC<UpdateNotifSettingDropdownProps> = ({
let userPushInstance = userPushSDKInstance;

if (!userPushInstance.signer) {
userPushInstance = await handleConnectWallet();
userPushInstance = await handleConnectWalletAndEnableProfile({ wallet });
if (!userPushInstance) {
setLoadingFunc(false);
return;
Expand Down
3 changes: 1 addition & 2 deletions src/components/yield/StakingModalComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -81,7 +81,6 @@ const StakingModalComponent = ({ onClose, InnerComponentProps, toastObject }) =>
}, []);

const approveDeposit = async () => {

if (!isWalletConnected) {
connect();
return;
Expand Down
14 changes: 7 additions & 7 deletions src/components/yield/YieldPoolCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -65,7 +65,7 @@ const YieldPoolCard = ({

const massClaimRewardsTokensAll = async () => {
if (!userPushSDKInstance.signer) {
handleConnectWallet();
handleConnectWalletAndEnableProfile({ wallet });
return;
}

Expand Down Expand Up @@ -153,7 +153,7 @@ const YieldPoolCard = ({

const withdrawTokens = async () => {
if (!userPushSDKInstance.signer) {
handleConnectWallet();
handleConnectWalletAndEnableProfile({ wallet });
return;
}

Expand Down Expand Up @@ -234,7 +234,7 @@ const YieldPoolCard = ({

const migrateToNewPool = async () => {
if (!userPushSDKInstance.signer) {
handleConnectWallet();
handleConnectWalletAndEnableProfile({ wallet });
return;
}

Expand Down Expand Up @@ -457,7 +457,7 @@ const YieldPoolCard = ({

const depositLpToken = async (tx, withdrawAmount, totalTxnSteps) => {
if (!userPushSDKInstance.signer) {
handleConnectWallet();
handleConnectWalletAndEnableProfile({ wallet });
return;
}

Expand Down Expand Up @@ -510,7 +510,7 @@ const YieldPoolCard = ({

const depositPushToken = async (tx, withdrawAmount, totalTxnSteps) => {
if (!userPushSDKInstance.signer) {
handleConnectWallet();
handleConnectWalletAndEnableProfile({ wallet });
return;
}

Expand Down
7 changes: 3 additions & 4 deletions src/contexts/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -535,7 +534,7 @@ const AppContextProvider = ({ children }) => {
setSnapState,
initializePushSDK,
SnapState,
handleConnectWallet,
handleConnectWalletAndEnableProfile,
connectWallet,
setSnapInstalled,
snapInstalled,
Expand Down
6 changes: 3 additions & 3 deletions src/modules/channelDashboard/ChannelOwnerDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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';

Expand Down Expand Up @@ -175,7 +175,7 @@ const ChannelOwnerDashboard = () => {

const showEditChannel = () => {
// if (!userPushSDKInstance.signer) {
// handleConnectWallet();
// handleConnectWalletAndEnableProfile({wallet});
// return;
// }
setEditChannel(true);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/chat/ChatModule.tsx.deprecated
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function Chat({ chatid }) {
setConnectedUser,
displayQR,
setDisplayQR,
handleConnectWallet,
handleConnectWalletAndEnableProfile,
} = useContext(AppContext);

const { userPushSDKInstance } = useSelector((state: any) => {
Expand Down
6 changes: 3 additions & 3 deletions src/modules/createChannel/CreateChannelModule.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -240,7 +240,7 @@ function CreateChannelModule() {
// e.preventDefault();

if (!userPushSDKInstance.signer) {
handleConnectWallet();
handleConnectWalletAndEnableProfile({wallet});
return;
}

Expand Down
Loading

0 comments on commit d4509b9

Please sign in to comment.