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 7, 2024
1 parent 90994a1 commit 8e37a48
Showing 1 changed file with 44 additions and 12 deletions.
56 changes: 44 additions & 12 deletions lib/pages/bootstrap/tom_bootstrap_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,18 @@ class TomBootstrapDialogState extends State<TomBootstrapDialog>
Future<RecoveryWords?> _getRecoveryWords() async {
return await _getRecoveryWordsInteractor.execute().then(
(either) => either.fold(
(failure) => null,
(success) => success.words,
(failure) {
Logs().e(
'TomBootstrapDialog::_getRecoveryWords(): $failure',
);
return null;
},
(success) {
Logs().d(
'TomBootstrapDialog::_getRecoveryWords(): ${success.words}',
);
return success.words;
},
),
);
}
Expand All @@ -86,8 +96,24 @@ class TomBootstrapDialogState extends State<TomBootstrapDialog>
_uploadRecoveryKeyState = UploadRecoveryKeyState.checkingRecoveryWork;
});
await _getRecoveryKeyState();
bootstrap =
widget.client.encryption!.bootstrap(onUpdate: (_) => setState(() {}));
if (widget.client.encryption != null) {
WidgetsBinding.instance.addPostFrameCallback((_) async {
bootstrap = widget.client.encryption!.bootstrap(
onUpdate: (_) {
if (mounted) {
setState(() {});
}
},
);
});
} else {
Logs().e(
'TomBootstrapDialog::_loadingData(): encryption is null',
);
setState(() {
_uploadRecoveryKeyState = UploadRecoveryKeyState.uploadError;
});
}
}

Future<void> _getRecoveryKeyState() async {
Expand All @@ -104,14 +130,18 @@ class TomBootstrapDialogState extends State<TomBootstrapDialog>
widget.client.isUnknownSession && mounted) {
final recoveryWords = await _getRecoveryWords();
if (recoveryWords != null) {
_recoveryWords = recoveryWords;
_uploadRecoveryKeyState = UploadRecoveryKeyState.useExisting;
setState(() {
_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();
WidgetsBinding.instance.addPostFrameCallback((_) async {
Navigator.pop(context);
await BootstrapDialog(client: widget.client).show();
});
}
}
} else {
Expand All @@ -121,13 +151,15 @@ class TomBootstrapDialogState extends State<TomBootstrapDialog>
final recoveryWords = await _getRecoveryWords();
_wipe = recoveryWords != null;
if (recoveryWords != null) {
_uploadRecoveryKeyState = UploadRecoveryKeyState.wipeRecovery;
setState(() {
_uploadRecoveryKeyState = UploadRecoveryKeyState.wipeRecovery;
});
} else {
_uploadRecoveryKeyState = UploadRecoveryKeyState.initial;
setState(() {
_uploadRecoveryKeyState = UploadRecoveryKeyState.initial;
});
}
}

setState(() {});
}

bool get isDataLoadingState =>
Expand Down

0 comments on commit 8e37a48

Please sign in to comment.