diff --git a/lib/utils/config.js b/lib/utils/config.js --- a/lib/utils/config.js +++ b/lib/utils/config.js @@ -2,6 +2,7 @@ import invariant from 'invariant'; +import type { DispatchActionPromise } from './redux-promise-utils.js'; import type { CallSingleKeyserverEndpoint } from '../keyserver-conn/call-single-keyserver-endpoint.js'; import type { CallKeyserverEndpoint } from '../keyserver-conn/keyserver-conn-types.js'; import type { InitialNotifMessageOptions } from '../shared/crypto-utils.js'; @@ -10,7 +11,6 @@ import type { PlatformDetails } from '../types/device-types.js'; import type { EncryptedNotifUtilsAPI } from '../types/notif-types.js'; import type { SQLiteAPI } from '../types/sqlite-types.js'; -import type { DispatchActionPromise } from '../utils/redux-promise-utils.js'; export type Config = { +resolveKeyserverSessionInvalidationUsingNativeCredentials: ?( @@ -31,7 +31,18 @@ +olmAPI: OlmAPI, +sqliteAPI: SQLiteAPI, +encryptedNotifUtilsAPI: EncryptedNotifUtilsAPI, - +showAlert: (title: string, message: string) => mixed, + +showAlert: ( + title: string, + message: string, + buttons?: $ReadOnlyArray<{ + +text: string, + +onPress?: () => mixed, + +style?: 'cancel' | 'default' | 'destructive', + }>, + options?: { + +cancelable?: boolean, + }, + ) => mixed, +isStaffRelease: boolean, }; diff --git a/native/config.js b/native/config.js --- a/native/config.js +++ b/native/config.js @@ -1,6 +1,7 @@ // @flow -import { Alert, Platform } from 'react-native'; +import { Platform } from 'react-native'; +import type { AlertOptions, AlertButton } from 'react-native'; import { registerConfig } from 'lib/utils/config.js'; @@ -10,6 +11,7 @@ import { sqliteAPI } from './database/sqlite-api.js'; import encryptedNotifUtilsAPI from './push/encrypted-notif-utils-api.js'; import { persistConfig, codeVersion } from './redux/persist.js'; +import Alert from './utils/alert.js'; import { isStaffRelease } from './utils/staff-utils.js'; registerConfig({ @@ -25,6 +27,33 @@ olmAPI, sqliteAPI, encryptedNotifUtilsAPI, - showAlert: (title: string, message: string) => Alert.alert(title, message), + showAlert: ( + title: string, + message: string, + buttons?: $ReadOnlyArray<{ + +text: string, + +onPress?: () => mixed, + +style?: 'cancel' | 'default' | 'destructive', + }>, + options?: { + +cancelable?: ?boolean, + }, + ) => { + let alertOptions: AlertOptions | void = undefined; + if (options?.cancelable !== undefined) { + alertOptions = { + cancelable: options.cancelable, + }; + } + let alertButtons: Array | void = undefined; + if (buttons !== undefined) { + alertButtons = buttons.map(button => ({ + text: button.text, + onPress: button.onPress, + style: button.style, + })); + } + Alert.alert(title, message, alertButtons, alertOptions); + }, isStaffRelease: __DEV__ || isStaffRelease, }); 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,6 +3,7 @@ import * as React from 'react'; import { ScrollView, View } from 'react-native'; +import { getConfig } from 'lib/utils/config.js'; import { useCurrentUserFID, useCurrentUserSupportsDCs, @@ -38,7 +39,7 @@ const unlinkFID = useUnlinkFID(); - const onPressDisconnect = React.useCallback(async () => { + const unlink = React.useCallback(async () => { setIsLoadingUnlinkFID(true); try { await unlinkFID(); @@ -52,6 +53,29 @@ } }, [unlinkFID]); + const onPressDisconnect = React.useCallback(() => { + getConfig().showAlert( + 'Disconnect Farcaster account', + 'This will permanently remove all Farcaster threads and messages from' + + ' your account and backup. This action ' + + 'cannot be undone. Are you sure you want to continue?', + [ + { + text: 'No', + style: 'cancel', + }, + { + text: 'Disconnect', + onPress: unlink, + style: 'destructive', + }, + ], + { + cancelable: true, + }, + ); + }, [unlink]); + const [webViewState, setWebViewState] = React.useState('closed'); const [showConnectDCs, setShowConnectDCs] = React.useState(false);