Skip to content

Commit

Permalink
Handle error for _getRecoveryWords
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Jun 5, 2024
1 parent 90994a1 commit 57fa40d
Showing 1 changed file with 45 additions and 33 deletions.
78 changes: 45 additions & 33 deletions lib/pages/bootstrap/tom_bootstrap_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ class TomBootstrapDialogState extends State<TomBootstrapDialog>
}

Future<RecoveryWords?> _getRecoveryWords() async {
return await _getRecoveryWordsInteractor.execute().then(
(either) => either.fold(
(failure) => null,
(success) => success.words,
),
);
try {
return await _getRecoveryWordsInteractor.execute().then(
(either) => either.fold(
(failure) => null,
(success) => success.words,
),
);
} catch (_) {
rethrow;
}
}

Future<void> _loadingData() async {
Expand All @@ -91,40 +95,48 @@ class TomBootstrapDialogState extends State<TomBootstrapDialog>
}

Future<void> _getRecoveryKeyState() async {
await widget.client.onSync.stream.first;
await widget.client.initCompleter?.future;
try {
await widget.client.onSync.stream.first;
await widget.client.initCompleter?.future;

// Display first login bootstrap if enabled
if (widget.client.encryption?.keyManager.enabled == true) {
Logs().d(
'TomBootstrapDialog::_initializeRecoveryKeyState: Showing bootstrap dialog when encryption is enabled',
);
if (await widget.client.encryption?.keyManager.isCached() == false ||
await widget.client.encryption?.crossSigning.isCached() == false ||
widget.client.isUnknownSession && mounted) {
// Display first login bootstrap if enabled
if (widget.client.encryption?.keyManager.enabled == true) {
Logs().d(
'TomBootstrapDialog::_initializeRecoveryKeyState: Showing bootstrap dialog when encryption is enabled',
);
if (await widget.client.encryption?.keyManager.isCached() == false ||
await widget.client.encryption?.crossSigning.isCached() == false ||
widget.client.isUnknownSession && mounted) {
final recoveryWords = await _getRecoveryWords();
if (recoveryWords != null) {
_recoveryWords = recoveryWords;
_uploadRecoveryKeyState = UploadRecoveryKeyState.useExisting;
} else {
Logs().d(
'TomBootstrapDialog::_initializeRecoveryKeyState(): no recovery existed then call bootstrap',
);
Navigator.pop(context);
await BootstrapDialog(client: widget.client).show();
}
}
} else {
Logs().d(
'TomBootstrapDialog::_initializeRecoveryKeyState(): encryption is not enabled',
);
final recoveryWords = await _getRecoveryWords();
_wipe = recoveryWords != null;
if (recoveryWords != null) {
_recoveryWords = recoveryWords;
_uploadRecoveryKeyState = UploadRecoveryKeyState.useExisting;
_uploadRecoveryKeyState = UploadRecoveryKeyState.wipeRecovery;
} else {
Logs().d(
'TomBootstrapDialog::_initializeRecoveryKeyState(): no recovery existed then call bootstrap',
);
Navigator.pop(context);
await BootstrapDialog(client: widget.client).show();
_uploadRecoveryKeyState = UploadRecoveryKeyState.initial;
}
}
} else {
Logs().d(
'TomBootstrapDialog::_initializeRecoveryKeyState(): encryption is not enabled',
} catch (e) {
Logs().e(
'TomBootstrapDialog::_initializeRecoveryKeyState(): $e',
);
final recoveryWords = await _getRecoveryWords();
_wipe = recoveryWords != null;
if (recoveryWords != null) {
_uploadRecoveryKeyState = UploadRecoveryKeyState.wipeRecovery;
} else {
_uploadRecoveryKeyState = UploadRecoveryKeyState.initial;
}
Navigator.pop(context);
await BootstrapDialog(client: widget.client).show();
}

setState(() {});
Expand Down

0 comments on commit 57fa40d

Please sign in to comment.