Skip to content

Commit

Permalink
add recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwiidb committed Mar 23, 2023
1 parent 2b70131 commit a78492a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/controllers/auth_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> 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;
Expand Down
14 changes: 10 additions & 4 deletions lib/views/recover_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit a78492a

Please sign in to comment.