From aee39cad8f5bc8f64e7d47e278019165783d70db Mon Sep 17 00:00:00 2001 From: abhishek-01k Date: Tue, 27 Feb 2024 12:55:06 +0530 Subject: [PATCH] Issues Fixed for diff Channel Features like edit channel or add delegate --- src/components/ChannelDetails.js | 25 +++++----- src/components/ChannelSettingsDropdown.tsx | 8 +-- .../channel/NotificationSettings.tsx | 49 ++++++++++--------- .../ChannelOwnerDashboard.tsx | 8 +-- 4 files changed, 48 insertions(+), 42 deletions(-) diff --git a/src/components/ChannelDetails.js b/src/components/ChannelDetails.js index 35c8f25a1b..046219fdc4 100644 --- a/src/components/ChannelDetails.js +++ b/src/components/ChannelDetails.js @@ -49,7 +49,7 @@ export default function ChannelDetails({ isChannelExpired, setIsChannelExpired, const { userPushSDKInstance } = useSelector((state) => { return state.user; }); - const {handleConnectWallet} = useContext(AppContext); + const { handleConnectWallet } = useContext(AppContext); const { CHANNEL_ACTIVE_STATE, CHANNNEL_DEACTIVATED_STATE } = useSelector((state) => state.channels); const { processingState } = useSelector((state) => state.channelCreation); const [verifyingChannel, setVerifyingChannel] = React.useState([]); @@ -77,10 +77,9 @@ export default function ChannelDetails({ isChannelExpired, setIsChannelExpired, const addDelegateToast = useToast(); - const handleDelegateModal = () => { + const handleDelegateModal = async () => { if (!userPushSDKInstance.signer) { - handleConnectWallet(); - return; + await handleConnectWallet(); } showAddDelegateModal(); } @@ -156,17 +155,19 @@ export default function ChannelDetails({ isChannelExpired, setIsChannelExpired, } }, [account]); - const removeDelegate = (walletAddress) => { - return userPushSDKInstance.channel.delegate.remove(convertAddressToAddrCaip(walletAddress, chainId)); + const removeDelegate = async (walletAddress) => { + let userPushInstance = userPushSDKInstance; + if (!userPushInstance.signer) { + userPushInstance = await handleConnectWallet(); + if (!userPushInstance) { + return; + } + } + + return userPushInstance.channel.delegate.remove(convertAddressToAddrCaip(walletAddress, chainId)); }; const navigateToNotifSettings = () => { - - if (!userPushSDKInstance.signer) { - handleConnectWallet(); - return; - } - navigate(APP_PATHS.ChannelSettings); }; diff --git a/src/components/ChannelSettingsDropdown.tsx b/src/components/ChannelSettingsDropdown.tsx index 6e501c4ca1..7649e66aae 100644 --- a/src/components/ChannelSettingsDropdown.tsx +++ b/src/components/ChannelSettingsDropdown.tsx @@ -128,10 +128,10 @@ function ChannelSettings({ DropdownRef, isDropdownOpen, closeDropdown }: Channel const userSignerToast = useToast(); const toggleChannelActivationState = () => { if (isChannelBlocked) return; - if (!userPushSDKInstance.signer) { - handleConnectWallet(); - return; - } + // if (!userPushSDKInstance.signer) { + // handleConnectWallet(); + // return; + // } if (isChannelDeactivated) { showReactivateChannelModal(); } else { diff --git a/src/components/channel/NotificationSettings.tsx b/src/components/channel/NotificationSettings.tsx index e4ba15d8a8..c5d95b8ef7 100644 --- a/src/components/channel/NotificationSettings.tsx +++ b/src/components/channel/NotificationSettings.tsx @@ -47,7 +47,7 @@ function NotificationSettings() { const [settingToEdit, setSettingToEdit] = React.useState(undefined); const [isLoading, setIsLoading] = React.useState(false); const [isLoadingSettings, setIsLoadingSettings] = React.useState(true); - const {handleConnectWallet} = useContext(AppContext); + const { handleConnectWallet } = useContext(AppContext); const { userPushSDKInstance } = useSelector((state: any) => { return state.user; @@ -133,12 +133,17 @@ function NotificationSettings() { const saveSettings = async () => { try { - if (!userPushSDKInstance.signer) { - handleConnectWallet(); - return; + setIsLoading(true); + + let userPushInstance = userPushSDKInstance; + if (!userPushInstance.signer) { + userPushInstance = await handleConnectWallet(); + if (!userPushInstance) { + setIsLoading(false); + return; + } } - setIsLoading(true); notificationToast.showLoaderToast({ loaderMessage: 'Waiting for Confirmation...' }); const settingData: NotificationSetting[] = settings.map((setting) => { @@ -153,14 +158,14 @@ function NotificationSettings() { console.info( { type: setting.type, - description: setting.description, - default: setting.default, - data: { - lower: setting.lowerLimit, - upper: setting.upperLimit, - ticker: setting.ticker, - enabled: setting.enabled, - }, + description: setting.description, + default: setting.default, + data: { + lower: setting.lowerLimit, + upper: setting.upperLimit, + ticker: setting.ticker, + enabled: setting.enabled, + }, } ) return { @@ -178,14 +183,14 @@ function NotificationSettings() { console.info( { type: setting.type, - description: setting.description, - default: setting.default, - data: { - lower: setting.lowerLimit, - upper: setting.upperLimit, - ticker: setting.ticker, - enabled: setting.enabled, - }, + description: setting.description, + default: setting.default, + data: { + lower: setting.lowerLimit, + upper: setting.upperLimit, + ticker: setting.ticker, + enabled: setting.enabled, + }, } ) return { @@ -202,7 +207,7 @@ function NotificationSettings() { } }); console.info(settingData); - await userPushSDKInstance.channel.setting(settingData); + await userPushInstance.channel.setting(settingData); dispatch(updateChannelSetting({ channelAddress, settings })); setIsLoading(false); diff --git a/src/modules/channelDashboard/ChannelOwnerDashboard.tsx b/src/modules/channelDashboard/ChannelOwnerDashboard.tsx index 76a5d93406..350b41ddf8 100644 --- a/src/modules/channelDashboard/ChannelOwnerDashboard.tsx +++ b/src/modules/channelDashboard/ChannelOwnerDashboard.tsx @@ -149,10 +149,10 @@ const ChannelOwnerDashboard = () => { } const showEditChannel = () => { - if (!userPushSDKInstance.signer) { - handleConnectWallet(); - return; - } + // if (!userPushSDKInstance.signer) { + // handleConnectWallet(); + // return; + // } setEditChannel(true); }