From a78492a24ebd66061b187e1ec6fbe7d626e5e1f2 Mon Sep 17 00:00:00 2001 From: kiwiidb Date: Thu, 23 Mar 2023 17:57:30 +0100 Subject: [PATCH] add recovery --- lib/controllers/auth_controller.dart | 6 +++--- lib/views/recover_page.dart | 14 ++++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/controllers/auth_controller.dart b/lib/controllers/auth_controller.dart index 05f5745..4043306 100644 --- a/lib/controllers/auth_controller.dart +++ b/lib/controllers/auth_controller.dart @@ -48,14 +48,14 @@ class AuthController extends GetxController with WidgetsBindingObserver { await Clipboard.setData(ClipboardData(text: nsec)); } - void loginHex(String privkeyHex) async { - await accountStorage.write("identity-privkey-hex", privkeyHex); + Future loginHex(String privkeyHex) async { keychain = Keychain(privkeyHex); - await accountStorage.write("identity-pubkey-hex", keychain.public); var npub = bech32.encode(Decoded( prefix: "npub", words: bech32.toWords(Uint8List.fromList(hex.decode(keychain.public))))); + await accountStorage.write("identity-pubkey-hex", keychain.public); + await accountStorage.write("identity-privkey-hex", privkeyHex); await accountStorage.write("identity-pubkey-npub", npub); pubkey.value = keychain.public; this.npub.value = npub; diff --git a/lib/views/recover_page.dart b/lib/views/recover_page.dart index b7fc0f4..d04adf9 100644 --- a/lib/views/recover_page.dart +++ b/lib/views/recover_page.dart @@ -5,6 +5,7 @@ import 'package:get/get.dart'; import 'package:nygma/app_theme.dart'; import 'package:nygma/controllers/auth_controller.dart'; import 'package:nygma/controllers/shamir_controller.dart'; +import 'package:nygma/views/index_or_login.dart'; import '../components/buttons/gradient_button.dart'; import '../components/labeled_text_form_field.dart'; @@ -99,10 +100,15 @@ class RecoverPage extends StatelessWidget { width: double.infinity, height: 60, child: GradientButton( - onPressed: () { - var secret = shamirController - .combineShares(controller.getShares()); - authController.loginHex(secret); + onPressed: () async { + try { + var secret = shamirController + .combineShares(controller.getShares()); + await authController.loginHex(secret); + Get.offAll(IndexOrLogin()); + } catch (e) { + Get.snackbar("Something went wrong", e.toString()); + } }, child: const Text( 'Recover',