Page MenuHomePhabricator

D7627.diff
No OneTemporary

D7627.diff

diff --git a/native/avatars/avatar-hooks.js b/native/avatars/avatar-hooks.js
--- a/native/avatars/avatar-hooks.js
+++ b/native/avatars/avatar-hooks.js
@@ -23,7 +23,6 @@
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js';
import type {
ImageAvatarDBContent,
- ENSAvatarDBContent,
UpdateUserAvatarRemoveRequest,
} from 'lib/types/avatar-types.js';
import type { SetState } from 'lib/types/hook-types.js';
@@ -368,38 +367,6 @@
);
}
-function useENSUserAvatar(): [() => void, boolean] {
- const dispatchActionPromise = useDispatchActionPromise();
- const updateUserAvatarCall = useServerCall(updateUserAvatar);
-
- const updateUserAvatarLoadingStatus: LoadingStatus = useSelector(
- updateUserAvatarLoadingStatusSelector,
- );
-
- const saveENSUserAvatar = React.useCallback(() => {
- const ensAvatarRequest: ENSAvatarDBContent = {
- type: 'ens',
- };
-
- dispatchActionPromise(
- updateUserAvatarActionTypes,
- (async () => {
- try {
- return await updateUserAvatarCall(ensAvatarRequest);
- } catch (e) {
- Alert.alert('Avatar update failed', 'Unable to update avatar.');
- throw e;
- }
- })(),
- );
- }, [dispatchActionPromise, updateUserAvatarCall]);
-
- return React.useMemo(
- () => [saveENSUserAvatar, updateUserAvatarLoadingStatus === 'loading'],
- [saveENSUserAvatar, updateUserAvatarLoadingStatus],
- );
-}
-
type ShowAvatarActionSheetOptions = {
+id: 'emoji' | 'image' | 'ens' | 'cancel' | 'remove',
+onPress?: () => mixed,
@@ -520,5 +487,4 @@
useSelectFromGalleryAndUpdateUserAvatar,
useSelectFromGalleryAndUpdateThreadAvatar,
useRemoveThreadAvatar,
- useENSUserAvatar,
};
diff --git a/native/avatars/edit-user-avatar-provider.react.js b/native/avatars/edit-user-avatar-provider.react.js
--- a/native/avatars/edit-user-avatar-provider.react.js
+++ b/native/avatars/edit-user-avatar-provider.react.js
@@ -8,7 +8,10 @@
updateUserAvatarActionTypes,
} from 'lib/actions/user-actions.js';
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js';
-import type { UpdateUserAvatarRemoveRequest } from 'lib/types/avatar-types.js';
+import type {
+ ENSAvatarDBContent,
+ UpdateUserAvatarRemoveRequest,
+} from 'lib/types/avatar-types.js';
import type { LoadingStatus } from 'lib/types/loading-types.js';
import {
useDispatchActionPromise,
@@ -19,6 +22,7 @@
export type EditUserAvatarContextType = {
+userAvatarSaveInProgress: boolean,
+ +setENSUserAvatar: () => void,
+removeUserAvatar: () => void,
};
@@ -44,6 +48,24 @@
const userAvatarSaveInProgress = updateUserAvatarLoadingStatus === 'loading';
+ const setENSUserAvatar = React.useCallback(() => {
+ const ensAvatarRequest: ENSAvatarDBContent = {
+ type: 'ens',
+ };
+
+ dispatchActionPromise(
+ updateUserAvatarActionTypes,
+ (async () => {
+ try {
+ return await updateUserAvatarCall(ensAvatarRequest);
+ } catch (e) {
+ Alert.alert('Avatar update failed', 'Unable to update avatar.');
+ throw e;
+ }
+ })(),
+ );
+ }, [dispatchActionPromise, updateUserAvatarCall]);
+
const removeUserAvatar = React.useCallback(() => {
const removeAvatarRequest: UpdateUserAvatarRemoveRequest = {
type: 'remove',
@@ -65,9 +87,10 @@
const context = React.useMemo(
() => ({
userAvatarSaveInProgress,
+ setENSUserAvatar,
removeUserAvatar,
}),
- [removeUserAvatar, userAvatarSaveInProgress],
+ [removeUserAvatar, setENSUserAvatar, userAvatarSaveInProgress],
);
return (
diff --git a/native/avatars/edit-user-avatar.react.js b/native/avatars/edit-user-avatar.react.js
--- a/native/avatars/edit-user-avatar.react.js
+++ b/native/avatars/edit-user-avatar.react.js
@@ -8,7 +8,6 @@
import { getETHAddressForUserInfo } from 'lib/shared/account-utils.js';
import {
- useENSUserAvatar,
useSelectFromGalleryAndUpdateUserAvatar,
useShowAvatarActionSheet,
} from './avatar-hooks.js';
@@ -29,7 +28,8 @@
const editUserAvatarContext = React.useContext(EditUserAvatarContext);
invariant(editUserAvatarContext, 'editUserAvatarContext should be set');
- const { userAvatarSaveInProgress, removeUserAvatar } = editUserAvatarContext;
+ const { userAvatarSaveInProgress, setENSUserAvatar, removeUserAvatar } =
+ editUserAvatarContext;
const currentUserInfo = useSelector(state => state.currentUserInfo);
const ethAddress = React.useMemo(
@@ -41,12 +41,8 @@
const [selectFromGalleryAndUpdateUserAvatar, isGalleryAvatarUpdateLoading] =
useSelectFromGalleryAndUpdateUserAvatar();
- const [saveENSUserAvatar, isENSAvatarUpdateLoading] = useENSUserAvatar();
-
const isAvatarUpdateInProgress =
- isGalleryAvatarUpdateLoading ||
- isENSAvatarUpdateLoading ||
- userAvatarSaveInProgress;
+ isGalleryAvatarUpdateLoading || userAvatarSaveInProgress;
const actionSheetConfig = React.useMemo(() => {
const configOptions = [
@@ -55,7 +51,7 @@
];
if (ensAvatarURI) {
- configOptions.push({ id: 'ens', onPress: saveENSUserAvatar });
+ configOptions.push({ id: 'ens', onPress: setENSUserAvatar });
}
configOptions.push({ id: 'remove', onPress: removeUserAvatar });
@@ -65,7 +61,7 @@
ensAvatarURI,
onPressEmojiAvatarFlow,
removeUserAvatar,
- saveENSUserAvatar,
+ setENSUserAvatar,
selectFromGalleryAndUpdateUserAvatar,
]);

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 15, 8:05 AM (17 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2493395
Default Alt Text
D7627.diff (5 KB)

Event Timeline