diff --git a/vidaia/lib/pages/settings_page.dart b/vidaia/lib/pages/settings_page.dart index 23f8aa5..5321e1a 100644 --- a/vidaia/lib/pages/settings_page.dart +++ b/vidaia/lib/pages/settings_page.dart @@ -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); @@ -24,44 +25,50 @@ class _SettingsPageState extends State { ), body: Column( children: [ - Text( - 'changeLanguage'.tr(), - style: Theme.of(context).textTheme.headline5, - ), - DropdownButton( - hint: Text( - 'currentLanguage'.tr(), - ), - isExpanded: true, - items: const [ - DropdownMenuItem( - 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( - value: 'en', - child: Text( - 'English', - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.w600, - color: Colors.black, + isExpanded: true, + items: const [ + DropdownMenuItem( + value: 'de', + child: Text( + 'Deutsch', + style: TextStyle( + fontSize: 12, + fontWeight: FontWeight.w600, + color: Colors.black, + ), + ), ), - ), - ), - ], - onChanged: (String? value) { - setState(() { - context.setLocale(Locale(value!)); - }); - }) + DropdownMenuItem( + 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);}, + ) ], ), ); diff --git a/vidaia/lib/utils/wallet.dart b/vidaia/lib/utils/wallet.dart index 661aff1..daf09f7 100644 --- a/vidaia/lib/utils/wallet.dart +++ b/vidaia/lib/utils/wallet.dart @@ -39,11 +39,14 @@ setPriv() async { await storage.write(key: "privateKey", value: priv); } -recoverWalletFromWords(List 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)); } @@ -215,3 +218,33 @@ confirmPurchase(BuildContext context) { }, ); } + +Future 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: [ + ElevatedButton( + child: Text('CANCEL'), + onPressed: () { + Navigator.pop(context); + }, + ), + ElevatedButton( + child: Text('Import'), + onPressed: () { + print(_textFieldController.value.text); + recoverWalletFromWords(_textFieldController.value.text); + }, + ), + ], + ); + }); +}