Skip to content

Commit

Permalink
feat: recovery keychain creation
Browse files Browse the repository at this point in the history
  • Loading branch information
damian-molinski committed Oct 11, 2024
1 parent 836fe35 commit c229cc2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ class _UnlockPasswordPanelState extends State<UnlockPasswordPanel> {
}

Future<void> _createKeychain() async {
// TODO(damian-molinski): to be implemented
final registrationCubit = RegistrationCubit.of(context);

final isSuccess = await registrationCubit.recover.createKeychain();

if (isSuccess) {
registrationCubit.nextStep();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ abstract interface class RecoverManager implements UnlockPasswordManager {
void setSeedPhraseWords(List<SeedPhraseWord> words);

Future<void> recoverAccount();

Future<bool> createKeychain();
}

final class RecoverCubit extends Cubit<RecoverStateData>
Expand Down Expand Up @@ -101,6 +103,34 @@ final class RecoverCubit extends Cubit<RecoverStateData>
}
}

@override
Future<bool> createKeychain() async {
try {
final seedPhrase = _seedPhrase;
final password = this.password;

if (seedPhrase == null) {
throw const LocalizedRegistrationSeedPhraseNotFoundException();
}
if (password.isNotValid) {
throw const LocalizedRegistrationUnlockPasswordNotFoundException();
}

await _registrationService.createKeychain(
seedPhrase: seedPhrase,
unlockPassword: password.value,
);

return true;
} catch (error, stack) {
_logger.severe('Create keychain', error, stack);

emitError(error);

return false;
}
}

@override
void onUnlockPasswordStateChanged(UnlockPasswordState data) {
emit(state.copyWith(unlockPasswordState: data));
Expand Down

0 comments on commit c229cc2

Please sign in to comment.