Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3516725
D14165.id46587.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D14165.id46587.diff
View Options
diff --git a/native/account/restore-backup-screen.react.js b/native/account/restore-backup-screen.react.js
--- a/native/account/restore-backup-screen.react.js
+++ b/native/account/restore-backup-screen.react.js
@@ -4,11 +4,21 @@
import { Text, View } from 'react-native';
import * as Progress from 'react-native-progress';
+import { getMessageForException } from 'lib/utils/errors.js';
+
+import { setNativeCredentials } from './native-credentials.js';
import RegistrationContainer from './registration/registration-container.react.js';
import RegistrationContentContainer from './registration/registration-content-container.react.js';
+import { useRestore } from './restore.js';
import type { SignInNavigationProp } from './sign-in-navigator.react.js';
import type { NavigationRoute } from '../navigation/route-names.js';
import { useColors, useStyles } from '../themes/colors.js';
+import {
+ appOutOfDateAlertDetails,
+ unknownErrorAlertDetails,
+ userNotFoundAlertDetails,
+} from '../utils/alert-messages.js';
+import Alert from '../utils/alert.js';
type Props = {
+navigation: SignInNavigationProp<'RestoreBackupScreen'>,
@@ -30,10 +40,60 @@
},
};
-// eslint-disable-next-line no-unused-vars
function RestoreBackupScreen(props: Props): React.Node {
const styles = useStyles(unboundStyles);
const colors = useColors();
+
+ const { userIdentifier, credentials } = props.route.params;
+
+ const restore = useRestore();
+ React.useEffect(() => {
+ void (async () => {
+ try {
+ if (credentials.type === 'password') {
+ await restore(userIdentifier, credentials.password);
+ await setNativeCredentials({
+ username: userIdentifier,
+ password: credentials.password,
+ });
+ } else {
+ await restore(
+ userIdentifier,
+ credentials.secret,
+ credentials.message,
+ credentials.signature,
+ );
+ }
+ } catch (e) {
+ const messageForException = getMessageForException(e);
+ console.log(
+ `Backup restore error: ${messageForException ?? 'unknown error'}`,
+ );
+ let alertDetails = unknownErrorAlertDetails;
+ if (
+ messageForException === 'user_not_found' ||
+ messageForException === 'login_failed'
+ ) {
+ alertDetails = userNotFoundAlertDetails;
+ } else if (
+ messageForException === 'unsupported_version' ||
+ messageForException === 'client_version_unsupported' ||
+ messageForException === 'use_new_flow'
+ ) {
+ alertDetails = appOutOfDateAlertDetails;
+ }
+ Alert.alert(
+ alertDetails.title,
+ alertDetails.message,
+ [{ text: 'OK', onPress: props.navigation.goBack }],
+ { cancelable: false },
+ );
+ }
+ })();
+ // We want this effect to run exactly once
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
return (
<RegistrationContainer>
<RegistrationContentContainer style={styles.scrollViewContentContainer}>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 3:16 PM (14 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2692628
Default Alt Text
D14165.id46587.diff (3 KB)
Attached To
Mode
D14165: [native] Perform the backup restoration
Attached
Detach File
Event Timeline
Log In to Comment