Skip to content

Commit

Permalink
added option to import wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
YannMarti committed May 31, 2022
1 parent 47ea047 commit 7014498
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 39 deletions.
79 changes: 43 additions & 36 deletions vidaia/lib/pages/settings_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:vidaia/utils/wallet.dart';

class SettingsPage extends StatefulWidget {
const SettingsPage({Key? key}) : super(key: key);
Expand All @@ -24,44 +25,50 @@ class _SettingsPageState extends State<SettingsPage> {
),
body: Column(
children: [
Text(
'changeLanguage'.tr(),
style: Theme.of(context).textTheme.headline5,
),
DropdownButton(
hint: Text(
'currentLanguage'.tr(),
),
isExpanded: true,
items: const [
DropdownMenuItem<String>(
value: 'de',
child: Text(
'Deutsch',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Colors.black,
),
ListTile(
title: Text('Change Languge'),
trailing: SizedBox(
width: 100,
child: DropdownButton(
hint: Text(
'currentLanguage'.tr(),
),
),
DropdownMenuItem<String>(
value: 'en',
child: Text(
'English',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Colors.black,
isExpanded: true,
items: const [
DropdownMenuItem<String>(
value: 'de',
child: Text(
'Deutsch',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
),
),
),
],
onChanged: (String? value) {
setState(() {
context.setLocale(Locale(value!));
});
})
DropdownMenuItem<String>(
value: 'en',
child: Text(
'English',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
),
],
onChanged: (String? value) {
setState(() {
context.setLocale(Locale(value!));
});
}),
),
),
ListTile(
title: Text('Import Wallet'),
onTap: () {importWallet(context);},
)
],
),
);
Expand Down
39 changes: 36 additions & 3 deletions vidaia/lib/utils/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ setPriv() async {
await storage.write(key: "privateKey", value: priv);
}

recoverWalletFromWords(List<String> words) async {
recoverWalletFromWords(String words) async {
if (!Mnemonic.validate(words.split(' '))){
throw Exception('Invalid Mnemonic phrase');
}
final storage = FlutterSecureStorage();
await storage.write(key: "mnemonicPhrase", value: words.join(' '));
await storage.write(key: "mnemonicPhrase", value: words);

var priv = Mnemonic.derivePrivateKey(words);
var priv = Mnemonic.derivePrivateKey(words.split(' '));
await storage.write(key: "privateKey", value: bytesToHex(priv));
}

Expand Down Expand Up @@ -215,3 +218,33 @@ confirmPurchase(BuildContext context) {
},
);
}

Future<void> importWallet(BuildContext context) async {
TextEditingController _textFieldController = TextEditingController();
return showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text('TextField in Dialog'),
content: TextField(
controller: _textFieldController,
decoration: InputDecoration(hintText: "Enter Seed-Words"),
),
actions: <Widget>[
ElevatedButton(
child: Text('CANCEL'),
onPressed: () {
Navigator.pop(context);
},
),
ElevatedButton(
child: Text('Import'),
onPressed: () {
print(_textFieldController.value.text);
recoverWalletFromWords(_textFieldController.value.text);
},
),
],
);
});
}

0 comments on commit 7014498

Please sign in to comment.