@@ -38,9 +38,13 @@ function CommunityListItem({
subscribed,
handleUpdateCommunitySubscription,
}) {
- const { data: community, isLoading } = useCommunityDetails(communityId);
+ const {
+ data: community,
+ isLoading,
+ error,
+ } = useCommunityDetails(communityId);
const { name, logo, slug } = community ?? {};
- if (isLoading) return null;
+ if (isLoading || error) return null;
return (
diff --git a/frontend/packages/client/src/components/Settings/NotificationSettingsSection/EmailAddressInput.js b/frontend/packages/client/src/components/Settings/NotificationSettingsSection/EmailAddressInput.js
index ff3636f36..e0b42fae6 100644
--- a/frontend/packages/client/src/components/Settings/NotificationSettingsSection/EmailAddressInput.js
+++ b/frontend/packages/client/src/components/Settings/NotificationSettingsSection/EmailAddressInput.js
@@ -5,10 +5,10 @@ import { EMAIL_REGEX } from 'const';
import { yupResolver } from '@hookform/resolvers/yup';
import * as yup from 'yup';
-export default function EmailAddressInput({ email, setUserEmail }) {
- const { register, handleSubmit, formState } = useForm({
+export default function EmailAddressInput({ defaultEmail, setUserEmail }) {
+ const { register, handleSubmit, formState, setValue } = useForm({
defaultValues: {
- email: email,
+ email: defaultEmail,
},
resolver: yupResolver(
yup.object().shape({
@@ -20,8 +20,12 @@ export default function EmailAddressInput({ email, setUserEmail }) {
})
),
});
- const onSubmit = ({ email }) => {
- setUserEmail(email);
+ const onSubmit = async ({ email }) => {
+ try {
+ await setUserEmail(email);
+ } catch (e) {
+ setValue('email', defaultEmail);
+ }
};
const { isSubmitting, errors, isDirty } = formState;
diff --git a/frontend/packages/client/src/components/Settings/NotificationSettingsSection/index.js b/frontend/packages/client/src/components/Settings/NotificationSettingsSection/index.js
index dd205b7a0..6aab651ba 100644
--- a/frontend/packages/client/src/components/Settings/NotificationSettingsSection/index.js
+++ b/frontend/packages/client/src/components/Settings/NotificationSettingsSection/index.js
@@ -1,4 +1,3 @@
-import { Fragment } from 'react';
import { useNotificationServiceContext } from 'contexts/NotificationService';
import CommunitiesList from './CommunitiesList';
import EmailAddressInput from './EmailAddressInput';
@@ -27,7 +26,7 @@ export default function NotificationSettingsSection() {
)}
{communitySubscription.length > 0 && (
<>
-
+
{
const onSubmit = async (formData) => {
try {
- onSubscribe(signupAll);
+ onSubscribe(formData.email, signupAll);
onClose();
} catch (e) {
setErrorMessage(e.message);
@@ -83,6 +83,7 @@ const SignUpForm = ({ setErrorMessage, onSubscribe, onClose }) => {
Close
+ }
+ onClose={closeModal}
+ />,
+ { isErrorModal: true }
+ );
+ throw new Error();
+ }
+ };
+ };
+ const getUserSettings = async () => {
try {
- //here we call api to init the leanplum sdk
+ const { communitySubscription, isSubscribedFromCommunityUpdates, email } =
+ await getUser(addr);
setNotificationSettings((prevState) => ({
...prevState,
- walletId,
+ communitySubscription,
+ isSubscribedFromCommunityUpdates,
+ email,
}));
} catch {
- throw new Error('cannot set user id for leanplum');
+ throw new Error('cannot get user settings');
}
};
-
- const setUserEmail = async (email) => {
+ const setUserEmail = handleNotificationServiceError(async (email) => {
try {
- //here we call api
+ await setEmail(email);
setNotificationSettings((prevState) => ({
...prevState,
email,
@@ -80,71 +125,41 @@ const NotificationServiceProvider = ({ children }) => {
} catch {
throw new Error('cannot set user email');
}
- };
+ });
- const getUserSettings = async () => {
- try {
- //here we call api
- const { communitySubscription, isSubscribedFromCommunityUpdates } =
- INIT_NOTIFICATION_SETTINGS;
- setNotificationSettings((prevState) => ({
- ...prevState,
- communitySubscription,
- isSubscribedFromCommunityUpdates,
- }));
- } catch {
- throw new Error('cannot get user settings');
+ const updateCommunitySubscription = handleNotificationServiceError(
+ async (communitySubIntentions) => {
+ try {
+ await updateCommunity(communitySubIntentions);
+ await new Promise((r) => setTimeout(r, 500));
+ await getUserSettings();
+ } catch {
+ throw new Error('cannot update community subscription');
+ }
+ // throw Error();
}
- };
+ );
- const updateCommunitySubscription = async (
- communityId,
- subscribeIntention
- ) => {
- try {
- if (subscribeIntention === subscribeNotificationIntentions.subscribe) {
- //call api to subscribe community
+ const updateAllEmailNotificationSubscription = handleNotificationServiceError(
+ async (subscribeIntention) => {
+ if (subscribeIntention === subscribeNotificationIntentions.resubscribe) {
+ subscribeToEmailNotifications(addr);
} else if (
subscribeIntention === subscribeNotificationIntentions.unsubscribe
) {
- //call api to unsubscribe community
+ unsubscribeFromEmailNotifications(addr);
}
- setNotificationSettings((prevState) => {
- const newCommunitySubscription = updateCommunitySubscriptionState(
- prevState.communitySubscription,
- communityId,
- subscribeIntention === subscribeNotificationIntentions.subscribe
- );
- return {
- ...prevState,
- communitySubscription: newCommunitySubscription,
- };
- });
- } catch {
- throw new Error('cannot subscribe community');
- }
- };
-
- const updateAllEmailNotificationSubscription = async (subscribeIntention) => {
- if (subscribeIntention === subscribeNotificationIntentions.resubscribe) {
- //call api to resubscribe all email notifications
- } else if (
- subscribeIntention === subscribeNotificationIntentions.unsubscribe
- ) {
- //call api to unsubscribe all email notifications
+ setNotificationSettings((prevState) => ({
+ ...prevState,
+ isSubscribedFromCommunityUpdates:
+ subscribeIntention === subscribeNotificationIntentions.resubscribe,
+ }));
}
- setNotificationSettings((prevState) => ({
- ...prevState,
- isSubscribedFromCommunityUpdates:
- subscribeIntention === subscribeNotificationIntentions.resubscribe,
- }));
- };
+ );
const providerProps = {
notificationSettings,
- setUserID,
setUserEmail,
- getUserSettings,
updateCommunitySubscription,
updateAllEmailNotificationSubscription,
};
diff --git a/frontend/packages/client/src/pages/Home.js b/frontend/packages/client/src/pages/Home.js
index 6ffcfe452..590facfbf 100644
--- a/frontend/packages/client/src/pages/Home.js
+++ b/frontend/packages/client/src/pages/Home.js
@@ -38,6 +38,7 @@ export default function HomePage() {
// missing fields
isComingSoon: datum.isComingSoon || false,
}));
+
const browserName = useBrowserName();
const [showToolTip, setValue] = useLocalStorage('dw-safary-tooltip', null);
diff --git a/frontend/packages/client/src/pages/Settings.js b/frontend/packages/client/src/pages/Settings.js
index 64fb0c2e5..38354f182 100644
--- a/frontend/packages/client/src/pages/Settings.js
+++ b/frontend/packages/client/src/pages/Settings.js
@@ -1,4 +1,4 @@
-import { useNotificationServiceContext } from 'contexts/NotificationService';
+import { useWebContext } from 'contexts/Web3';
import { HomeFooter } from 'components';
import {
ConnectWalletPrompt,
@@ -8,19 +8,20 @@ import {
import SectionContainer from 'layout/SectionContainer';
export default function Settings() {
- const { notificationSettings } = useNotificationServiceContext();
- const { walletId } = notificationSettings;
+ const {
+ user: { addr },
+ } = useWebContext();
return (
- {walletId && (
+ {addr && (
-
+
)}
- {!walletId &&
}
+ {!addr &&
}