2021-01-06 21:17:01 +01:00
|
|
|
import 'package:flutter/foundation.dart';
|
2021-01-06 05:04:54 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:dubp/dubp.dart';
|
|
|
|
import 'package:sentry/sentry.dart' as sentry;
|
2021-01-06 21:17:01 +01:00
|
|
|
import 'dart:io';
|
2021-01-08 05:02:27 +01:00
|
|
|
import 'dart:async';
|
2021-01-06 21:17:01 +01:00
|
|
|
import 'package:path_provider/path_provider.dart';
|
2021-01-06 05:04:54 +01:00
|
|
|
|
|
|
|
class GenerateWalletScreen extends StatefulWidget {
|
|
|
|
@override
|
2021-01-08 05:02:27 +01:00
|
|
|
_GenerateWalletState createState() => _GenerateWalletState();
|
2021-01-06 05:04:54 +01:00
|
|
|
}
|
|
|
|
|
2021-01-08 05:02:27 +01:00
|
|
|
class _GenerateWalletState extends State<GenerateWalletScreen> {
|
2021-01-06 05:04:54 +01:00
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
DubpRust.setup();
|
|
|
|
}
|
|
|
|
|
2021-01-09 09:17:01 +01:00
|
|
|
TextEditingController _mnemonicController = new TextEditingController();
|
2021-01-06 05:04:54 +01:00
|
|
|
TextEditingController _pubkey = new TextEditingController();
|
|
|
|
TextEditingController _pin = new TextEditingController();
|
2021-01-09 09:17:01 +01:00
|
|
|
String generatedMnemonic;
|
|
|
|
NewWallet actualWallet;
|
2021-01-08 05:02:27 +01:00
|
|
|
final formKey = GlobalKey<FormState>();
|
2021-01-06 05:04:54 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return SafeArea(
|
|
|
|
child: Column(children: <Widget>[
|
2021-01-09 09:17:01 +01:00
|
|
|
SizedBox(height: 8),
|
|
|
|
Text(
|
|
|
|
'Clé publique:',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 15.0,
|
|
|
|
color: Colors.grey[600],
|
|
|
|
fontWeight: FontWeight.w400),
|
|
|
|
),
|
2021-01-06 05:04:54 +01:00
|
|
|
TextField(
|
|
|
|
enabled: false,
|
2021-01-09 09:17:01 +01:00
|
|
|
controller: this._pubkey,
|
|
|
|
maxLines: 1,
|
2021-01-06 05:04:54 +01:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
decoration: InputDecoration(),
|
|
|
|
style: TextStyle(
|
2021-01-09 09:17:01 +01:00
|
|
|
fontSize: 14.0,
|
2021-01-06 05:04:54 +01:00
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.bold)),
|
2021-01-09 09:17:01 +01:00
|
|
|
SizedBox(height: 8),
|
|
|
|
Text(
|
|
|
|
'Phrase secrète:',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 15.0,
|
|
|
|
color: Colors.grey[600],
|
|
|
|
fontWeight: FontWeight.w400),
|
|
|
|
),
|
2021-01-06 05:04:54 +01:00
|
|
|
TextField(
|
|
|
|
enabled: false,
|
2021-01-09 09:17:01 +01:00
|
|
|
controller: this._mnemonicController,
|
|
|
|
maxLines: 3,
|
2021-01-06 05:04:54 +01:00
|
|
|
textAlign: TextAlign.center,
|
2021-01-09 09:17:01 +01:00
|
|
|
decoration: InputDecoration(
|
|
|
|
contentPadding: EdgeInsets.all(15.0),
|
|
|
|
),
|
2021-01-06 05:04:54 +01:00
|
|
|
style: TextStyle(
|
2021-01-09 09:17:01 +01:00
|
|
|
fontSize: 22.0,
|
2021-01-06 05:04:54 +01:00
|
|
|
color: Colors.black,
|
2021-01-09 09:17:01 +01:00
|
|
|
fontWeight: FontWeight.w400)),
|
|
|
|
SizedBox(height: 8),
|
|
|
|
Text(
|
|
|
|
'Code PIN:',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 15.0,
|
|
|
|
color: Colors.grey[600],
|
|
|
|
fontWeight: FontWeight.w400),
|
|
|
|
),
|
2021-01-06 05:04:54 +01:00
|
|
|
TextField(
|
|
|
|
enabled: false,
|
|
|
|
controller: this._pin,
|
|
|
|
maxLines: 1,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
decoration: InputDecoration(),
|
|
|
|
style: TextStyle(
|
2021-01-09 09:17:01 +01:00
|
|
|
fontSize: 30.0,
|
2021-01-06 05:04:54 +01:00
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.bold)),
|
2021-01-06 21:17:01 +01:00
|
|
|
SizedBox(height: 12),
|
2021-01-06 05:04:54 +01:00
|
|
|
new RaisedButton(
|
2021-01-09 09:17:01 +01:00
|
|
|
color: Color(0xffFFD68E),
|
2021-01-06 05:04:54 +01:00
|
|
|
onPressed: () => generateMnemonic(),
|
|
|
|
child: Text('Générer un wallet', style: TextStyle(fontSize: 20))),
|
2021-01-09 09:17:01 +01:00
|
|
|
SizedBox(height: 30),
|
|
|
|
Expanded(
|
|
|
|
child: Align(
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
child: new RaisedButton(
|
|
|
|
color: Color(0xffFFD68E),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) {
|
|
|
|
return ValidStoreWalletScreen(
|
|
|
|
generatedMnemonic: this.generatedMnemonic,
|
|
|
|
generatedWallet:
|
|
|
|
this.actualWallet); //, this.actualWallet);
|
|
|
|
}),
|
|
|
|
).then((value) => setState(() {
|
|
|
|
if (value) {
|
|
|
|
_pin.clear();
|
|
|
|
_mnemonicController.clear();
|
|
|
|
_pubkey.clear();
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
child: Text('Enregistrer ce wallet',
|
|
|
|
style: TextStyle(fontSize: 20))))),
|
|
|
|
SizedBox(height: 15)
|
2021-01-06 05:04:54 +01:00
|
|
|
]));
|
|
|
|
}
|
|
|
|
|
|
|
|
Future generateMnemonic() async {
|
|
|
|
try {
|
2021-01-09 09:17:01 +01:00
|
|
|
this.generatedMnemonic =
|
|
|
|
await DubpRust.genMnemonic(language: Language.french);
|
2021-01-06 05:04:54 +01:00
|
|
|
} catch (e, stack) {
|
|
|
|
print(e);
|
2021-01-06 21:17:01 +01:00
|
|
|
if (kReleaseMode) {
|
|
|
|
await sentry.Sentry.captureException(
|
|
|
|
e,
|
|
|
|
stackTrace: stack,
|
|
|
|
);
|
|
|
|
}
|
2021-01-06 05:04:54 +01:00
|
|
|
}
|
2021-01-09 09:17:01 +01:00
|
|
|
this.actualWallet = await generateWallet(this.generatedMnemonic);
|
|
|
|
return this.generatedMnemonic;
|
2021-01-06 05:04:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Future generateWallet(generatedMnemonic) async {
|
|
|
|
try {
|
2021-01-09 09:17:01 +01:00
|
|
|
this.actualWallet = await DubpRust.genWalletFromMnemonic(
|
2021-01-06 05:04:54 +01:00
|
|
|
language: Language.french, mnemonic: generatedMnemonic);
|
|
|
|
} catch (e, stack) {
|
|
|
|
print(e);
|
2021-01-06 21:17:01 +01:00
|
|
|
if (kReleaseMode) {
|
|
|
|
await sentry.Sentry.captureException(
|
|
|
|
e,
|
|
|
|
stackTrace: stack,
|
|
|
|
);
|
|
|
|
}
|
2021-01-06 05:04:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
setState(() {
|
2021-01-09 09:17:01 +01:00
|
|
|
this._mnemonicController.text = generatedMnemonic;
|
|
|
|
this._pubkey.text = actualWallet.publicKey;
|
|
|
|
this._pin.text = actualWallet.pin;
|
2021-01-06 05:04:54 +01:00
|
|
|
});
|
2021-01-06 21:17:01 +01:00
|
|
|
|
2021-01-09 09:17:01 +01:00
|
|
|
return actualWallet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ValidStoreWalletScreen extends StatefulWidget {
|
|
|
|
final String generatedMnemonic;
|
|
|
|
final NewWallet generatedWallet;
|
|
|
|
|
|
|
|
ValidStoreWalletScreen(
|
|
|
|
{Key validationKey,
|
|
|
|
@required this.generatedMnemonic,
|
|
|
|
@required this.generatedWallet})
|
|
|
|
: super(key: validationKey);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_ValidStoreWalletScreen createState() => _ValidStoreWalletScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ValidStoreWalletScreen extends State<ValidStoreWalletScreen> {
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
// DubpRust.setup();
|
|
|
|
this._mnemonicController.text = widget.generatedMnemonic;
|
|
|
|
this._pubkey.text = widget.generatedWallet.publicKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextEditingController _mnemonicController = new TextEditingController();
|
|
|
|
TextEditingController _pubkey = new TextEditingController();
|
|
|
|
TextEditingController _pin = new TextEditingController();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(),
|
|
|
|
body: Center(
|
|
|
|
child: Column(children: <Widget>[
|
|
|
|
TextField(
|
|
|
|
enabled: false,
|
|
|
|
controller: this._mnemonicController,
|
|
|
|
maxLines: 2,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
decoration: InputDecoration(),
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 15.0,
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.bold)),
|
|
|
|
TextField(
|
|
|
|
enabled: false,
|
|
|
|
controller: this._pubkey,
|
|
|
|
maxLines: 1,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
decoration: InputDecoration(),
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14.0,
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.bold)),
|
|
|
|
new RaisedButton(
|
|
|
|
color: Color(0xffFFD68E),
|
|
|
|
onPressed: () => storeWallet(widget.generatedWallet),
|
|
|
|
child: Text('Confirmer', style: TextStyle(fontSize: 20))),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future storeWallet(actualWallet) async {
|
|
|
|
final walletFile = await _localWallet;
|
|
|
|
walletFile.writeAsString('${widget.generatedWallet.dewif}');
|
|
|
|
_pin.clear();
|
|
|
|
Navigator.pop(context, true);
|
|
|
|
FocusScope.of(context).unfocus();
|
2021-01-06 21:17:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<String> get _localPath async {
|
|
|
|
final directory = await getApplicationDocumentsDirectory();
|
|
|
|
|
|
|
|
return directory.path;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<File> get _localWallet async {
|
|
|
|
final path = await _localPath;
|
|
|
|
return File('$path/wallet.dewif');
|
2021-01-06 05:04:54 +01:00
|
|
|
}
|
|
|
|
}
|