116 lines
3.0 KiB
Dart
116 lines
3.0 KiB
Dart
// restore_from_recovery_phrase.dart
|
|
|
|
import 'package:flutter/material.dart';
|
|
import './widgets/key_management.dart';
|
|
|
|
class RestoreFromRecoveryPhrasePage extends StatefulWidget {
|
|
const RestoreFromRecoveryPhrasePage({super.key});
|
|
|
|
@override
|
|
_RestoreFromRecoveryPhrasePageState createState() => _RestoreFromRecoveryPhrasePageState();
|
|
}
|
|
|
|
class _RestoreFromRecoveryPhrasePageState extends State<RestoreFromRecoveryPhrasePage> {
|
|
final KeyManagement _keyManagement = KeyManagement();
|
|
final TextEditingController _controller = TextEditingController();
|
|
bool _isRestoring = false;
|
|
|
|
Future<void> _restoreKeyPair() async {
|
|
String mnemonic = _controller.text.trim();
|
|
|
|
if (mnemonic.isEmpty) {
|
|
_showErrorDialog('Please enter your recovery phrase.');
|
|
return;
|
|
}
|
|
|
|
setState(() {
|
|
_isRestoring = true;
|
|
});
|
|
|
|
try {
|
|
EcdsaKeyPair keyPair = await _keyManagement.restoreKeyPair(mnemonic);
|
|
_showSuccessDialog('Key pair restored successfully.');
|
|
} catch (e) {
|
|
_showErrorDialog('Failed to restore key pair: $e');
|
|
} finally {
|
|
setState(() {
|
|
_isRestoring = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
void _showSuccessDialog(String message) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text('Success'),
|
|
content: Text(message),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('OK'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
void _showErrorDialog(String message) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text('Error'),
|
|
content: Text(message),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('OK'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.black,
|
|
appBar: AppBar(
|
|
title: const Text('Restore Key Pair'),
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: _isRestoring
|
|
? const Center(child: CircularProgressIndicator())
|
|
: Column(
|
|
children: [
|
|
const Text(
|
|
'Enter your 12-word recovery phrase to restore your key pair.',
|
|
style: TextStyle(color: Colors.white),
|
|
),
|
|
const SizedBox(height: 20),
|
|
TextField(
|
|
controller: _controller,
|
|
decoration: const InputDecoration(
|
|
border: OutlineInputBorder(),
|
|
labelText: 'Recovery Phrase',
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
ElevatedButton(
|
|
onPressed: _restoreKeyPair,
|
|
child: const Text('Restore Key Pair'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|