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 @@ -3,7 +3,10 @@ import invariant from 'invariant'; import * as React from 'react'; -import { setSyncedMetadataEntryActionType } from '../actions/synced-metadata-actions.js'; +import { + setSyncedMetadataEntryActionType, + clearSyncedMetadataEntryActionType, +} from '../actions/synced-metadata-actions.js'; import { IdentityClientContext } from '../shared/identity-client-context.js'; import { syncedMetadataNames } from '../types/synced-metadata-types.js'; import { useSelector, useDispatch } from '../utils/redux-utils.js'; @@ -42,4 +45,25 @@ ); } -export { useCurrentUserFID, useLinkFID }; +function useUnlinkFID(): () => Promise { + const identityClientContext = React.useContext(IdentityClientContext); + invariant(identityClientContext, 'identityClientContext should be set'); + + const { identityClient } = identityClientContext; + const { unlinkFarcasterAccount } = identityClient; + + const dispatch = useDispatch(); + + return React.useCallback(async () => { + await unlinkFarcasterAccount(); + + dispatch({ + type: clearSyncedMetadataEntryActionType, + payload: { + name: syncedMetadataNames.CURRENT_USER_FID, + }, + }); + }, [dispatch, unlinkFarcasterAccount]); +} + +export { useCurrentUserFID, useLinkFID, useUnlinkFID }; diff --git a/native/profile/farcaster-account-settings.react.js b/native/profile/farcaster-account-settings.react.js --- a/native/profile/farcaster-account-settings.react.js +++ b/native/profile/farcaster-account-settings.react.js @@ -3,10 +3,11 @@ import * as React from 'react'; import { View } from 'react-native'; -import { clearSyncedMetadataEntryActionType } from 'lib/actions/synced-metadata-actions.js'; -import { syncedMetadataNames } from 'lib/types/synced-metadata-types.js'; -import { useCurrentUserFID, useLinkFID } from 'lib/utils/farcaster-utils.js'; -import { useDispatch } from 'lib/utils/redux-utils.js'; +import { + useCurrentUserFID, + useLinkFID, + useUnlinkFID, +} from 'lib/utils/farcaster-utils.js'; import type { ProfileNavigationProp } from './profile.react.js'; import RegistrationButton from '../account/registration/registration-button.react.js'; @@ -23,20 +24,11 @@ // eslint-disable-next-line no-unused-vars function FarcasterAccountSettings(props: Props): React.Node { - const dispatch = useDispatch(); - const fid = useCurrentUserFID(); const styles = useStyles(unboundStyles); - const onPressDisconnect = React.useCallback(() => { - dispatch({ - type: clearSyncedMetadataEntryActionType, - payload: { - name: syncedMetadataNames.CURRENT_USER_FID, - }, - }); - }, [dispatch]); + const unlinkFID = useUnlinkFID(); const [webViewState, setWebViewState] = React.useState('closed'); @@ -63,7 +55,7 @@ if (fid) { return ( @@ -77,7 +69,7 @@ variant={connectButtonVariant} /> ); - }, [connectButtonVariant, fid, onPressConnectFarcaster, onPressDisconnect]); + }, [connectButtonVariant, fid, onPressConnectFarcaster, unlinkFID]); const farcasterAccountSettings = React.useMemo( () => (