Page MenuHomePhabricator

D13736.id.diff
No OneTemporary

D13736.id.diff

diff --git a/lib/components/farcaster-data-handler.react.js b/lib/components/farcaster-data-handler.react.js
--- a/lib/components/farcaster-data-handler.react.js
+++ b/lib/components/farcaster-data-handler.react.js
@@ -6,13 +6,15 @@
import { useUserIdentityCache } from './user-identity-cache.react.js';
import { setAuxUserFIDsActionType } from '../actions/aux-user-actions.js';
import { updateRelationshipsActionTypes } from '../actions/relationship-actions.js';
-import { setSyncedMetadataEntryActionType } from '../actions/synced-metadata-actions.js';
import { useIsLoggedInToIdentityAndAuthoritativeKeyserver } from '../hooks/account-hooks.js';
import { useUpdateRelationships } from '../hooks/relationship-hooks.js';
import { IdentityClientContext } from '../shared/identity-client-context.js';
import { relationshipActions } from '../types/relationship-types.js';
-import { syncedMetadataNames } from '../types/synced-metadata-types.js';
-import { useCurrentUserFID, useUnlinkFID } from '../utils/farcaster-utils.js';
+import {
+ useCurrentUserFID,
+ useUnlinkFID,
+ useSetLocalFID,
+} from '../utils/farcaster-utils.js';
import { useDispatchActionPromise } from '../utils/redux-promise-utils.js';
import { useSelector, useDispatch } from '../utils/redux-utils.js';
import { usingCommServicesAccessToken } from '../utils/services-utils.js';
@@ -147,6 +149,7 @@
const [fidLoaded, setFIDLoaded] = React.useState(false);
+ const setLocalFID = useSetLocalFID();
const handleCurrentUserFID = React.useCallback(async () => {
if (
canQueryHandleCurrentUserFID ===
@@ -181,13 +184,7 @@
}
if (identityFID) {
- dispatch({
- type: setSyncedMetadataEntryActionType,
- payload: {
- name: syncedMetadataNames.CURRENT_USER_FID,
- data: identityFID,
- },
- });
+ setLocalFID(identityFID);
}
setFIDLoaded(true);
@@ -198,7 +195,7 @@
neynarClient,
fid,
unlinkFID,
- dispatch,
+ setLocalFID,
getCachedUserIdentity,
]);
diff --git a/lib/utils/farcaster-utils.js b/lib/utils/farcaster-utils.js
--- a/lib/utils/farcaster-utils.js
+++ b/lib/utils/farcaster-utils.js
@@ -30,6 +30,25 @@
return currentUserFID;
}
+function useSetLocalFID(): (fid: ?string) => void {
+ const dispatch = useDispatch();
+ return React.useCallback(
+ (fid: ?string) => {
+ // If we're unsetting the FID, we should set it to NO_FID_METADATA to
+ // avoid prompting the user for it again
+ const fidToSet = fid ?? NO_FID_METADATA;
+ dispatch({
+ type: setSyncedMetadataEntryActionType,
+ payload: {
+ name: syncedMetadataNames.CURRENT_USER_FID,
+ data: fidToSet,
+ },
+ });
+ },
+ [dispatch],
+ );
+}
+
function useLinkFID(): (fid: string) => Promise<void> {
const identityClientContext = React.useContext(IdentityClientContext);
invariant(identityClientContext, 'identityClientContext should be set');
@@ -37,21 +56,14 @@
const { identityClient } = identityClientContext;
const { linkFarcasterAccount } = identityClient;
- const dispatch = useDispatch();
+ const setLocalFID = useSetLocalFID();
return React.useCallback(
async (fid: string) => {
await linkFarcasterAccount(fid);
-
- dispatch({
- type: setSyncedMetadataEntryActionType,
- payload: {
- name: syncedMetadataNames.CURRENT_USER_FID,
- data: fid,
- },
- });
+ setLocalFID(fid);
},
- [dispatch, linkFarcasterAccount],
+ [setLocalFID, linkFarcasterAccount],
);
}
@@ -62,25 +74,19 @@
const { identityClient } = identityClientContext;
const { unlinkFarcasterAccount } = identityClient;
- const dispatch = useDispatch();
+ const setLocalFID = useSetLocalFID();
return React.useCallback(async () => {
await unlinkFarcasterAccount();
-
- dispatch({
- type: setSyncedMetadataEntryActionType,
- payload: {
- name: syncedMetadataNames.CURRENT_USER_FID,
- data: NO_FID_METADATA,
- },
- });
- }, [dispatch, unlinkFarcasterAccount]);
+ setLocalFID(null);
+ }, [setLocalFID, unlinkFarcasterAccount]);
}
export {
DISABLE_CONNECT_FARCASTER_ALERT,
NO_FID_METADATA,
useCurrentUserFID,
+ useSetLocalFID,
useLinkFID,
useUnlinkFID,
};
diff --git a/native/account/registration/registration-server-call.js b/native/account/registration/registration-server-call.js
--- a/native/account/registration/registration-server-call.js
+++ b/native/account/registration/registration-server-call.js
@@ -23,7 +23,7 @@
} from 'lib/types/account-types.js';
import { syncedMetadataNames } from 'lib/types/synced-metadata-types.js';
import { getMessageForException } from 'lib/utils/errors.js';
-import { NO_FID_METADATA } from 'lib/utils/farcaster-utils.js';
+import { useSetLocalFID } from 'lib/utils/farcaster-utils.js';
import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js';
import { useDispatch } from 'lib/utils/redux-utils.js';
import { usingCommServicesAccessToken } from 'lib/utils/services-utils.js';
@@ -302,6 +302,7 @@
);
const dispatch = useDispatch();
+ const setLocalFID = useSetLocalFID();
const returnedFunc = React.useCallback(
(input: RegistrationServerCallInput) =>
new Promise<void>(
@@ -357,14 +358,7 @@
payload: passedKeyserverURL,
});
}
- const fidToSave = farcasterID ?? NO_FID_METADATA;
- dispatch({
- type: setSyncedMetadataEntryActionType,
- payload: {
- name: syncedMetadataNames.CURRENT_USER_FID,
- data: fidToSave,
- },
- });
+ setLocalFID(farcasterID);
if (siweBackupSecrets) {
await commCoreModule.setSIWEBackupSecrets(siweBackupSecrets);
}
@@ -407,6 +401,7 @@
legacyKeyserverRegisterEthereumAccount,
identityRegisterEthereumAccount,
dispatch,
+ setLocalFID,
],
);

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 19, 5:53 PM (20 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2540018
Default Alt Text
D13736.id.diff (5 KB)

Event Timeline