2022-06-17 01:13:14 +02:00
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-05-29 00:00:57 +02:00
|
|
|
|
import 'package:flutter/services.dart';
|
2022-11-30 05:22:37 +01:00
|
|
|
|
|
2022-05-29 00:00:57 +02:00
|
|
|
|
import 'package:gecko/globals.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
2022-05-29 01:38:27 +02:00
|
|
|
|
import 'package:gecko/models/wallet_data.dart';
|
2022-08-23 00:25:16 +02:00
|
|
|
|
import 'package:gecko/models/widgets_keys.dart';
|
2022-05-29 00:00:57 +02:00
|
|
|
|
import 'package:gecko/providers/my_wallets.dart';
|
|
|
|
|
import 'package:gecko/providers/substrate_sdk.dart';
|
2022-12-03 10:44:48 +01:00
|
|
|
|
import 'package:gecko/providers/wallets_profiles.dart';
|
2022-12-10 08:16:38 +01:00
|
|
|
|
import 'package:gecko/widgets/commons/build_text.dart';
|
2022-05-29 00:00:57 +02:00
|
|
|
|
import 'package:pdf/pdf.dart';
|
|
|
|
|
import 'package:printing/printing.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:pdf/widgets.dart' as pw;
|
|
|
|
|
|
|
|
|
|
class ShowSeed extends StatelessWidget {
|
|
|
|
|
const ShowSeed(
|
|
|
|
|
{Key? keyMyWallets,
|
|
|
|
|
required this.walletName,
|
|
|
|
|
required this.walletProvider})
|
|
|
|
|
: super(key: keyMyWallets);
|
|
|
|
|
final String? walletName;
|
|
|
|
|
final MyWalletsProvider walletProvider;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2022-11-30 05:42:08 +01:00
|
|
|
|
final myWalletProvider =
|
2022-05-29 01:38:27 +02:00
|
|
|
|
Provider.of<MyWalletsProvider>(context, listen: false);
|
2022-11-30 05:42:08 +01:00
|
|
|
|
final sub = Provider.of<SubstrateSdk>(context, listen: false);
|
2022-05-29 00:00:57 +02:00
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
|
WalletData defaultWallet = myWalletProvider.getDefaultWallet();
|
2022-05-29 00:00:57 +02:00
|
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
backgroundColor: backgroundColor,
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
toolbarHeight: 60 * ratio,
|
2022-06-18 00:48:07 +02:00
|
|
|
|
title: SizedBox(
|
2022-05-29 00:00:57 +02:00
|
|
|
|
height: 22,
|
2022-06-18 00:48:07 +02:00
|
|
|
|
child: Text('myMnemonic'.tr()),
|
2022-05-29 00:00:57 +02:00
|
|
|
|
)),
|
|
|
|
|
body: SafeArea(
|
|
|
|
|
child: Column(children: <Widget>[
|
|
|
|
|
const Spacer(flex: 1),
|
|
|
|
|
FutureBuilder(
|
2022-08-06 02:22:41 +02:00
|
|
|
|
future:
|
2022-12-06 22:33:42 +01:00
|
|
|
|
sub.getSeed(defaultWallet.address, walletProvider.pinCode),
|
2022-08-06 02:22:41 +02:00
|
|
|
|
builder: (BuildContext context, AsyncSnapshot<String?> seed) {
|
|
|
|
|
if (seed.connectionState != ConnectionState.done ||
|
|
|
|
|
seed.hasError) {
|
2022-09-12 12:38:32 +02:00
|
|
|
|
return const SizedBox(
|
2022-05-29 00:00:57 +02:00
|
|
|
|
height: 15,
|
|
|
|
|
width: 15,
|
|
|
|
|
child: CircularProgressIndicator(
|
|
|
|
|
color: orangeC,
|
|
|
|
|
strokeWidth: 2,
|
|
|
|
|
),
|
|
|
|
|
);
|
2022-08-06 02:22:41 +02:00
|
|
|
|
} else if (!seed.hasData) {
|
2022-05-29 00:00:57 +02:00
|
|
|
|
return const Text('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
Column(children: [
|
2022-12-10 08:16:38 +01:00
|
|
|
|
BuildText(text: 'keepYourMnemonicSecret'.tr()),
|
2022-05-29 00:00:57 +02:00
|
|
|
|
SizedBox(height: 35 * ratio),
|
2022-08-06 02:22:41 +02:00
|
|
|
|
sentanceArray(context, seed.data!.split(' ')),
|
2022-05-29 00:00:57 +02:00
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 40,
|
|
|
|
|
child: ElevatedButton(
|
|
|
|
|
style: ElevatedButton.styleFrom(
|
2022-09-05 08:12:24 +02:00
|
|
|
|
foregroundColor: Colors.black,
|
|
|
|
|
shape: RoundedRectangleBorder(
|
2022-05-29 00:00:57 +02:00
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
2022-09-05 08:12:24 +02:00
|
|
|
|
),
|
|
|
|
|
backgroundColor: orangeC,
|
2022-09-05 04:15:27 +02:00
|
|
|
|
elevation: 1, // foreground
|
2022-05-29 00:00:57 +02:00
|
|
|
|
),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Clipboard.setData(
|
2022-08-06 02:22:41 +02:00
|
|
|
|
ClipboardData(text: seed.data));
|
2022-12-03 10:44:48 +01:00
|
|
|
|
snackCopySeed(context);
|
2022-05-29 00:00:57 +02:00
|
|
|
|
},
|
|
|
|
|
child: Row(children: <Widget>[
|
|
|
|
|
Image.asset(
|
|
|
|
|
'assets/walletOptions/copy-white.png',
|
|
|
|
|
height: 25,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 7),
|
|
|
|
|
Text(
|
2022-06-17 01:13:14 +02:00
|
|
|
|
'copy'.tr(),
|
2022-05-29 00:00:57 +02:00
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 15, color: Colors.grey[50]),
|
|
|
|
|
)
|
|
|
|
|
]),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 30),
|
|
|
|
|
GestureDetector(
|
|
|
|
|
onTap: () {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(builder: (context) {
|
2022-08-06 02:22:41 +02:00
|
|
|
|
return PrintWallet(seed.data);
|
2022-05-29 00:00:57 +02:00
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
child: Image.asset(
|
|
|
|
|
'assets/printer.png',
|
|
|
|
|
height: 42 * ratio,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
]),
|
|
|
|
|
]);
|
|
|
|
|
}),
|
2022-06-02 15:43:22 +02:00
|
|
|
|
const Spacer(flex: 2),
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: 380 * ratio,
|
|
|
|
|
height: 60 * ratio,
|
|
|
|
|
child: ElevatedButton(
|
|
|
|
|
style: ElevatedButton.styleFrom(
|
2022-09-05 08:12:24 +02:00
|
|
|
|
foregroundColor: Colors.white, elevation: 4,
|
|
|
|
|
backgroundColor: orangeC, // foreground
|
2022-06-02 15:43:22 +02:00
|
|
|
|
),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
},
|
|
|
|
|
child: Text(
|
2022-06-18 00:48:07 +02:00
|
|
|
|
'close'.tr(),
|
2022-06-02 15:43:22 +02:00
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 23 * ratio, fontWeight: FontWeight.w600),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const Spacer(flex: 2),
|
2022-05-29 00:00:57 +02:00
|
|
|
|
]),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
|
Widget sentanceArray(BuildContext context, List mnemonic) {
|
2022-05-29 00:00:57 +02:00
|
|
|
|
return Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 3),
|
|
|
|
|
child: Container(
|
|
|
|
|
constraints: const BoxConstraints(maxWidth: 450),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
border: Border.all(color: Colors.black),
|
|
|
|
|
color: const Color(0xffeeeedd),
|
|
|
|
|
borderRadius: const BorderRadius.all(
|
|
|
|
|
Radius.circular(10),
|
|
|
|
|
)),
|
|
|
|
|
padding: const EdgeInsets.all(20),
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Row(children: <Widget>[
|
2022-08-06 02:22:41 +02:00
|
|
|
|
arrayCell(mnemonic[0], 1),
|
|
|
|
|
arrayCell(mnemonic[1], 2),
|
|
|
|
|
arrayCell(mnemonic[2], 3),
|
|
|
|
|
arrayCell(mnemonic[3], 4),
|
2022-05-29 00:00:57 +02:00
|
|
|
|
]),
|
|
|
|
|
const SizedBox(height: 15),
|
|
|
|
|
Row(children: <Widget>[
|
2022-08-06 02:22:41 +02:00
|
|
|
|
arrayCell(mnemonic[4], 5),
|
|
|
|
|
arrayCell(mnemonic[5], 6),
|
|
|
|
|
arrayCell(mnemonic[6], 7),
|
|
|
|
|
arrayCell(mnemonic[7], 8),
|
2022-05-29 00:00:57 +02:00
|
|
|
|
]),
|
|
|
|
|
const SizedBox(height: 15),
|
|
|
|
|
Row(children: <Widget>[
|
2022-08-06 02:22:41 +02:00
|
|
|
|
arrayCell(mnemonic[8], 9),
|
|
|
|
|
arrayCell(mnemonic[9], 10),
|
|
|
|
|
arrayCell(mnemonic[10], 11),
|
|
|
|
|
arrayCell(mnemonic[11], 12),
|
2022-05-29 00:00:57 +02:00
|
|
|
|
]),
|
|
|
|
|
])),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget arrayCell(dataWord, int nbr) {
|
|
|
|
|
log.d(nbr);
|
|
|
|
|
|
|
|
|
|
return SizedBox(
|
|
|
|
|
width: 100,
|
|
|
|
|
child: Column(children: <Widget>[
|
|
|
|
|
Text(
|
|
|
|
|
nbr.toString(),
|
|
|
|
|
style:
|
|
|
|
|
TextStyle(fontSize: 13 * ratio, color: const Color(0xff6b6b52)),
|
|
|
|
|
),
|
|
|
|
|
Text(
|
|
|
|
|
dataWord,
|
2022-08-23 00:25:16 +02:00
|
|
|
|
key: keyMnemonicWord(dataWord),
|
2022-05-29 00:00:57 +02:00
|
|
|
|
style: TextStyle(fontSize: 17 * ratio, color: Colors.black),
|
|
|
|
|
),
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PrintWallet extends StatelessWidget {
|
|
|
|
|
const PrintWallet(this.sentence, {Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
final String? sentence;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return MaterialApp(
|
|
|
|
|
home: Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
leading: IconButton(
|
|
|
|
|
icon: const Icon(Icons.arrow_back, color: Colors.black),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
}),
|
|
|
|
|
backgroundColor: yellowC,
|
|
|
|
|
foregroundColor: Colors.black,
|
|
|
|
|
toolbarHeight: 60 * ratio,
|
2022-06-18 00:48:07 +02:00
|
|
|
|
title: SizedBox(
|
2022-05-29 00:00:57 +02:00
|
|
|
|
height: 22,
|
|
|
|
|
child: Text(
|
2022-06-18 00:48:07 +02:00
|
|
|
|
'printMyMnemonic'.tr(),
|
|
|
|
|
style: const TextStyle(fontWeight: FontWeight.w600),
|
2022-05-29 00:00:57 +02:00
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
body: PdfPreview(
|
|
|
|
|
canDebug: false,
|
|
|
|
|
canChangeOrientation: false,
|
|
|
|
|
build: (format) => printWallet(sentence!),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
|
Future<Uint8List> printWallet(String seed) async {
|
2022-05-29 00:00:57 +02:00
|
|
|
|
final ByteData fontData =
|
|
|
|
|
await rootBundle.load("assets/OpenSans-Regular.ttf");
|
|
|
|
|
final pw.Font ttf = pw.Font.ttf(fontData.buffer.asByteData());
|
|
|
|
|
final pdf = pw.Document();
|
|
|
|
|
int nbr = 1;
|
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
|
final seedList = seed.split(' ');
|
2022-05-29 00:00:57 +02:00
|
|
|
|
|
|
|
|
|
// const imageProvider = AssetImage('assets/icon/gecko_final.png');
|
|
|
|
|
// final geckoLogo = await flutterImageProvider(imageProvider);
|
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
|
pw.Widget arrayCell(String dataWord, int nbr) {
|
2022-05-29 00:00:57 +02:00
|
|
|
|
nbr++;
|
|
|
|
|
|
|
|
|
|
return pw.SizedBox(
|
|
|
|
|
width: 120,
|
|
|
|
|
child: pw.Column(children: <pw.Widget>[
|
|
|
|
|
pw.Text(
|
2022-08-06 02:22:41 +02:00
|
|
|
|
nbr.toString(),
|
2022-05-29 00:00:57 +02:00
|
|
|
|
style: pw.TextStyle(
|
|
|
|
|
fontSize: 15, color: const PdfColor(0.5, 0, 0), font: ttf),
|
|
|
|
|
),
|
|
|
|
|
pw.Text(
|
|
|
|
|
dataWord,
|
|
|
|
|
style: pw.TextStyle(
|
|
|
|
|
fontSize: 20, color: const PdfColor(0, 0, 0), font: ttf),
|
|
|
|
|
),
|
|
|
|
|
pw.SizedBox(height: 10)
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pdf.addPage(
|
|
|
|
|
pw.Page(
|
|
|
|
|
pageFormat: PdfPageFormat.a4,
|
|
|
|
|
build: (context) {
|
|
|
|
|
return pw.Column(
|
|
|
|
|
// mainAxisAlignment: pw.MainAxisAlignment.center,
|
|
|
|
|
// mainAxisSize: pw.MainAxisSize.max,
|
|
|
|
|
// crossAxisAlignment: pw.CrossAxisAlignment.center,
|
|
|
|
|
children: <pw.Widget>[
|
|
|
|
|
pw.Row(children: <pw.Widget>[
|
2022-08-06 02:22:41 +02:00
|
|
|
|
arrayCell(seedList[0], nbr),
|
|
|
|
|
arrayCell(seedList[1], nbr),
|
|
|
|
|
arrayCell(seedList[2], nbr),
|
|
|
|
|
arrayCell(seedList[3], nbr),
|
2022-05-29 00:00:57 +02:00
|
|
|
|
]),
|
|
|
|
|
pw.Row(children: <pw.Widget>[
|
2022-08-06 02:22:41 +02:00
|
|
|
|
arrayCell(seedList[4], nbr),
|
|
|
|
|
arrayCell(seedList[5], nbr),
|
|
|
|
|
arrayCell(seedList[6], nbr),
|
|
|
|
|
arrayCell(seedList[7], nbr),
|
2022-05-29 00:00:57 +02:00
|
|
|
|
]),
|
|
|
|
|
pw.Row(children: <pw.Widget>[
|
2022-08-06 02:22:41 +02:00
|
|
|
|
arrayCell(seedList[8], nbr),
|
|
|
|
|
arrayCell(seedList[9], nbr),
|
|
|
|
|
arrayCell(seedList[10], nbr),
|
|
|
|
|
arrayCell(seedList[11], nbr)
|
2022-05-29 00:00:57 +02:00
|
|
|
|
]),
|
|
|
|
|
pw.Expanded(
|
|
|
|
|
child: pw.Align(
|
|
|
|
|
alignment: pw.Alignment.bottomCenter,
|
|
|
|
|
child: pw.Text(
|
|
|
|
|
"Gardez cette feuille préciseusement, à l’abri des lézards indiscrets.",
|
|
|
|
|
style: pw.TextStyle(fontSize: 15, font: ttf),
|
|
|
|
|
)))
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return pdf.save();
|
|
|
|
|
}
|
|
|
|
|
}
|