Skip to content

Commit ce7835f

Browse files
committed
refactor(web): refetch-on-address-change-and-set-empty-email-invalid
1 parent c58fb70 commit ce7835f

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

web/src/context/AtlasProvider.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const AtlasProvider: React.FC<{ children?: React.ReactNode }> = ({ children }) =
9090
return () => {
9191
clearInterval(intervalId);
9292
};
93-
}, [authToken, verifySession]);
93+
}, [authToken, verifySession, address]);
9494

9595
const {
9696
data: user,
@@ -110,6 +110,11 @@ const AtlasProvider: React.FC<{ children?: React.ReactNode }> = ({ children }) =
110110
},
111111
});
112112

113+
useEffect(() => {
114+
if (!isVerified) return;
115+
refetchUser();
116+
}, [isVerified, refetchUser]);
117+
113118
// this would change based on the fields we have and what defines a user to be existing
114119
const userExists = useMemo(() => {
115120
if (!user) return false;
@@ -129,7 +134,6 @@ const AtlasProvider: React.FC<{ children?: React.ReactNode }> = ({ children }) =
129134
const signature = await signMessageAsync({ message });
130135

131136
const token = await loginUser(atlasGqlClient, { message, signature });
132-
133137
setAuthToken(token);
134138
} catch (err: any) {
135139
// eslint-disable-next-line

web/src/layout/Header/navbar/Menu/Settings/Notifications/FormContactDetails/FormContact.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const FormContact: React.FC<IForm> = ({
3838
isEditing,
3939
}) => {
4040
useEffect(() => {
41-
setContactIsValid(contactInput === "" ? true : validator.test(contactInput));
41+
setContactIsValid(validator.test(contactInput));
4242
}, [contactInput, setContactIsValid, validator]);
4343

4444
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
@@ -51,7 +51,7 @@ const FormContact: React.FC<IForm> = ({
5151
return undefined;
5252
}
5353
return contactIsValid ? "success" : "error";
54-
}, [contactInput, contactIsValid]);
54+
}, [contactInput, contactIsValid, isEditing]);
5555

5656
return (
5757
<>

web/src/layout/Header/navbar/Menu/Settings/Notifications/FormContactDetails/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@ const FormContactDetails: React.FC<ISettings> = ({ toggleIsSettingsOpen }) => {
4141
const { user, isAddingUser, isFetchingUser, addUser, updateUser, isUpdatingUser, userExists } = useAtlasProvider();
4242

4343
const isEditingEmail = useMemo(() => {
44-
if (!user?.email && emailInput === "") return false;
4544
return user?.email !== emailInput;
4645
}, [user, emailInput]);
4746

4847
useEffect(() => {
49-
if (!user) return;
48+
if (!user || !userExists) return;
5049

5150
setEmailInput(user.email);
52-
}, [user]);
51+
}, [user, userExists]);
5352

5453
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
5554
e.preventDefault();

web/src/utils/atlas/updateUser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { OPTIONS } from "utils/wrapWithToast";
55

66
const query = gql`
77
mutation UpdateUser($settings: UpdateUserDto!) {
8-
updateUser(updatedUserSettings: $settings)
8+
updateUser(updateUserSettings: $settings)
99
}
1010
`;
1111

0 commit comments

Comments
 (0)