2021-07-12 04:32:49 -07:00
|
|
|
import 'package:flutter/material.dart';
|
2022-03-13 08:49:39 -07:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2021-07-12 04:32:49 -07:00
|
|
|
|
|
|
|
import 'main.dart';
|
|
|
|
import 'store.dart';
|
2021-08-15 09:18:09 -07:00
|
|
|
import 'generated/l10n.dart';
|
2022-03-07 06:53:18 -08:00
|
|
|
import 'accounts.dart' show getBackup;
|
|
|
|
|
|
|
|
class AccountId {
|
|
|
|
final int coin;
|
|
|
|
final int id;
|
|
|
|
AccountId(this.coin, this.id);
|
2022-08-21 23:37:29 -07:00
|
|
|
|
|
|
|
bool operator ==(covariant AccountId other) {
|
|
|
|
return coin == other.coin && id == other.id;
|
|
|
|
}
|
2022-03-07 06:53:18 -08:00
|
|
|
}
|
2021-07-12 04:32:49 -07:00
|
|
|
|
|
|
|
class BackupPage extends StatefulWidget {
|
2022-03-07 06:53:18 -08:00
|
|
|
final AccountId? accountId;
|
2021-09-11 18:16:53 -07:00
|
|
|
|
|
|
|
BackupPage(this.accountId);
|
|
|
|
|
2021-07-12 04:32:49 -07:00
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => BackupState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class BackupState extends State<BackupPage> {
|
2021-09-10 02:56:15 -07:00
|
|
|
late Backup backup;
|
2021-07-12 04:32:49 -07:00
|
|
|
final _backupController = TextEditingController();
|
|
|
|
final _skController = TextEditingController();
|
|
|
|
final _ivkController = TextEditingController();
|
2021-11-11 17:44:46 -08:00
|
|
|
final _shareController = TextEditingController();
|
2021-07-12 04:32:49 -07:00
|
|
|
|
|
|
|
Future<bool> _init() async {
|
2022-06-07 10:00:08 -07:00
|
|
|
backup =
|
|
|
|
await getBackup(widget.accountId ?? AccountId(active.coin, active.id));
|
2022-03-07 06:53:18 -08:00
|
|
|
_backupController.text = backupData;
|
2021-09-10 23:05:48 -07:00
|
|
|
_skController.text = backup.sk ?? "";
|
2021-09-10 02:56:15 -07:00
|
|
|
_ivkController.text = backup.ivk;
|
2021-11-11 17:44:46 -08:00
|
|
|
final share = backup.share;
|
|
|
|
_shareController.text = share?.value ?? "";
|
2021-07-12 04:32:49 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-26 23:12:24 -07:00
|
|
|
String get backupData => backup.value() + (backup.index != 0 ? " [${backup.index}]" : "");
|
2022-03-07 06:53:18 -08:00
|
|
|
|
2021-07-12 04:32:49 -07:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-04-07 05:59:43 -07:00
|
|
|
return Scaffold(appBar: AppBar(title: Text(S.of(context).backup)),
|
|
|
|
body: FutureBuilder(
|
2021-07-12 04:32:49 -07:00
|
|
|
future: _init(),
|
|
|
|
builder: _build,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _build(BuildContext context, AsyncSnapshot<void> snapshot) {
|
|
|
|
if (!snapshot.hasData) return LinearProgressIndicator();
|
2022-02-28 07:36:37 -08:00
|
|
|
final s = S.of(context);
|
2021-11-11 17:44:46 -08:00
|
|
|
final name = backup.name;
|
|
|
|
final share = backup.share;
|
2021-07-12 04:32:49 -07:00
|
|
|
final type = backup.type;
|
2021-09-11 18:16:53 -07:00
|
|
|
final theme = Theme.of(context);
|
2021-09-11 19:27:31 -07:00
|
|
|
return SingleChildScrollView(child: Card(
|
2021-07-12 04:32:49 -07:00
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
TextField(
|
|
|
|
decoration: InputDecoration(
|
2022-03-07 06:53:18 -08:00
|
|
|
labelText: s.backupDataRequiredForRestore(name), prefixIcon: IconButton(icon: Icon(Icons.save),
|
|
|
|
onPressed: () => _showQR(backupData, "$name - backup"))),
|
2021-07-12 04:32:49 -07:00
|
|
|
controller: _backupController,
|
|
|
|
minLines: 3,
|
2021-08-06 19:18:20 -07:00
|
|
|
maxLines: 10,
|
2021-07-12 04:32:49 -07:00
|
|
|
readOnly: true,
|
2021-09-11 18:16:53 -07:00
|
|
|
style: TextStyle(color: theme.primaryColor, fontWeight: FontWeight.bold),
|
2021-07-12 04:32:49 -07:00
|
|
|
),
|
|
|
|
if (type == 0) TextField(
|
2022-02-28 07:36:37 -08:00
|
|
|
decoration: InputDecoration(labelText: s.secretKey, prefixIcon: IconButton(icon: Icon(Icons.vpn_key),
|
2021-11-11 17:44:46 -08:00
|
|
|
onPressed: () => _showQR(backup.sk!, "$name - sk"))),
|
2021-07-12 04:32:49 -07:00
|
|
|
controller: _skController,
|
|
|
|
minLines: 3,
|
|
|
|
maxLines: 10,
|
|
|
|
readOnly: true,
|
2021-09-11 18:16:53 -07:00
|
|
|
style: theme.textTheme.caption
|
2021-07-12 04:32:49 -07:00
|
|
|
),
|
|
|
|
if (type != 2) TextField(
|
2022-02-28 07:36:37 -08:00
|
|
|
decoration: InputDecoration(labelText: s.viewingKey, prefixIcon: IconButton(icon: Icon(Icons.visibility),
|
2021-11-11 17:44:46 -08:00
|
|
|
onPressed: () => _showQR(backup.ivk, "$name - vk"))),
|
2021-07-12 04:32:49 -07:00
|
|
|
controller: _ivkController,
|
|
|
|
minLines: 3,
|
2021-08-06 19:18:20 -07:00
|
|
|
maxLines: 10,
|
2021-07-12 04:32:49 -07:00
|
|
|
readOnly: true,
|
2021-09-11 18:16:53 -07:00
|
|
|
style: theme.textTheme.caption
|
2021-07-12 04:32:49 -07:00
|
|
|
),
|
2021-11-11 17:44:46 -08:00
|
|
|
if (share != null) TextField(
|
2022-03-13 08:49:39 -07:00
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: s.secretShare,
|
|
|
|
prefixIcon: IconButton(
|
|
|
|
icon: Icon(Icons.share),
|
|
|
|
onPressed: () => _showQR(share.value,
|
|
|
|
"$name - ms ${share.index}/${share.participants}"))),
|
2021-11-11 17:44:46 -08:00
|
|
|
controller: _shareController,
|
|
|
|
minLines: 3,
|
|
|
|
maxLines: 10,
|
|
|
|
readOnly: true,
|
2022-03-13 08:49:39 -07:00
|
|
|
style: theme.textTheme.caption),
|
|
|
|
Padding(padding: EdgeInsets.symmetric(vertical: 4)),
|
|
|
|
Text(s.tapAnIconToShowTheQrCode),
|
2022-09-02 01:47:48 -07:00
|
|
|
Container(
|
|
|
|
margin: EdgeInsets.all(8),
|
|
|
|
padding: EdgeInsets.all(8),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border.all(width: 2, color: theme.primaryColor),
|
|
|
|
borderRadius: BorderRadius.circular(4)),
|
|
|
|
child: Text(s.backupWarning,
|
|
|
|
style: theme.textTheme.subtitle1!
|
|
|
|
.copyWith(color: theme.primaryColor))),
|
2022-04-07 05:59:43 -07:00
|
|
|
ElevatedButton.icon(
|
|
|
|
icon: Icon(Icons.check),
|
|
|
|
label: Text(S.of(context).iHaveMadeABackup),
|
2022-07-07 20:26:20 -07:00
|
|
|
onPressed: () {
|
|
|
|
final nav = Navigator.of(context);
|
|
|
|
if (nav.canPop())
|
|
|
|
nav.pop();
|
|
|
|
else
|
|
|
|
nav.pushReplacementNamed('/account');
|
|
|
|
},
|
2022-04-07 05:59:43 -07:00
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.symmetric(vertical: 4)),
|
2022-03-13 08:49:39 -07:00
|
|
|
]),
|
2021-09-11 19:27:31 -07:00
|
|
|
));
|
2021-07-12 04:32:49 -07:00
|
|
|
}
|
|
|
|
|
2021-11-11 17:44:46 -08:00
|
|
|
_showQR(String text, String title) => showQR(context, text, title);
|
2021-07-12 04:32:49 -07:00
|
|
|
}
|