From c68e152040094287b398544132e5b5620eda8dc0 Mon Sep 17 00:00:00 2001 From: poka Date: Sat, 3 Apr 2021 02:39:09 +0200 Subject: [PATCH] Fix buggies stuff --- lib/main.dart | 1 + lib/models/myWallets.dart | 6 +- lib/models/walletOptions.dart | 3 +- lib/screens/history.dart | 13 +- lib/screens/myWallets/unlockingWallet.dart | 5 +- lib/screens/myWallets/walletOptions-old.dart | 166 ------------------- 6 files changed, 22 insertions(+), 172 deletions(-) delete mode 100644 lib/screens/myWallets/walletOptions-old.dart diff --git a/lib/main.dart b/lib/main.dart index 8d8cc68..8597171 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -44,6 +44,7 @@ Future main() async { await _homeProvider.getAppPath(); await _homeProvider.createDefaultAvatar(); await _walletsProvider.initWalletFolder(); + _walletsProvider.getDefaultWallet(); appVersion = await _homeProvider.getAppVersion(); prefs = await SharedPreferences.getInstance(); // final HiveStore _store = diff --git a/lib/models/myWallets.dart b/lib/models/myWallets.dart index ed26c7e..1329598 100644 --- a/lib/models/myWallets.dart +++ b/lib/models/myWallets.dart @@ -11,7 +11,7 @@ class MyWalletsProvider with ChangeNotifier { int pinLenght; Future initWalletFolder() async { - getDefaultWallet(); + // getDefaultWallet(); final bool isWalletFolderExist = await walletsDirectory.exists(); if (!isWalletFolderExist) { @@ -32,6 +32,7 @@ class MyWalletsProvider with ChangeNotifier { await File('${walletsDirectory.path}/0/order.conf').create(); await File('${walletsDirectory.path}/1/list.conf').create(); await File('${walletsDirectory.path}/1/order.conf').create(); + getDefaultWallet(); } } @@ -89,6 +90,7 @@ class MyWalletsProvider with ChangeNotifier { if (!defaultWalletFile.existsSync()) { File(defaultWalletFile.path).createSync(); + defaultWalletFile.writeAsStringSync("0:0"); } defaultWallet = getWalletData(defaultWalletFile.readAsStringSync()); @@ -102,7 +104,9 @@ class MyWalletsProvider with ChangeNotifier { if (_answer) { await walletsDirectory.delete(recursive: true); + await defaultWalletFile.delete(); await walletsDirectory.create(); + await defaultWalletFile.create(); await initWalletFolder(); notifyListeners(); Navigator.pop(context); diff --git a/lib/models/walletOptions.dart b/lib/models/walletOptions.dart index 43ea41e..3ee1d97 100644 --- a/lib/models/walletOptions.dart +++ b/lib/models/walletOptions.dart @@ -74,11 +74,12 @@ class WalletOptionsProvider with ChangeNotifier { Future readLocalWallet( context, WalletData _wallet, String _pin, int _pinLenght) async { isWalletUnlock = false; - // MyWalletsProvider _myWalletProvider = MyWalletsProvider(); try { File _walletFile = File('${walletsDirectory.path}/0/wallet.dewif'); String _localDewif = await _walletFile.readAsString(); String _localPubkey; + // log.d("_wallet:"); + log.d(_pin); if ((_localPubkey = await _getPubkeyFromDewif( _localDewif, _pin, _pinLenght, _wallet.derivation)) != diff --git a/lib/screens/history.dart b/lib/screens/history.dart index 4fbe61b..3b877ab 100644 --- a/lib/screens/history.dart +++ b/lib/screens/history.dart @@ -337,7 +337,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { mainAxisSize: MainAxisSize.min, children: [ SizedBox(height: 20), - Text('Commentaire:'), + Text('Commentaire:', style: TextStyle(fontSize: 20.0)), Padding( padding: EdgeInsets.all(8.0), child: TextField( @@ -346,18 +346,25 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { textAlign: TextAlign.center, decoration: InputDecoration(), style: TextStyle( - fontSize: 14.0, + fontSize: 22, color: Colors.black, fontWeight: FontWeight.bold))), SizedBox(height: 20), - Text('Montant (Ğ1):'), + Text('Montant (DU/Ğ1):', style: TextStyle(fontSize: 20.0)), Padding( padding: EdgeInsets.all(8.0), child: TextFormField( + style: TextStyle(fontSize: 22), controller: _historyProvider.payAmount, textAlign: TextAlign.center, maxLines: 1, keyboardType: TextInputType.number, + decoration: InputDecoration( + contentPadding: + EdgeInsets.symmetric(vertical: 25.0, horizontal: 10.0), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10.0)), + ), inputFormatters: [ FilteringTextInputFormatter.allow(RegExp(r'(^\d*\.?\d*)')) ], diff --git a/lib/screens/myWallets/unlockingWallet.dart b/lib/screens/myWallets/unlockingWallet.dart index d84f983..735d09f 100644 --- a/lib/screens/myWallets/unlockingWallet.dart +++ b/lib/screens/myWallets/unlockingWallet.dart @@ -32,7 +32,9 @@ class UnlockingWallet extends StatelessWidget { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); WalletOptionsProvider _walletOptions = Provider.of(context); - final int _pinLenght = _walletOptions.getPinLenght(this.wallet.number); + + log.d("defaultWallet: " + defaultWallet.toString()); + final int _pinLenght = _walletOptions.getPinLenght(wallet.number); errorController = StreamController(); return Scaffold( @@ -127,6 +129,7 @@ class UnlockingWallet extends StatelessWidget { ], onCompleted: (_pin) async { log.d("Completed"); + _myWalletProvider.pinCode = _pin; final resultWallet = await _walletOptions.readLocalWallet( context, this.wallet, _pin.toUpperCase(), _pinLenght); // _myWalletProvider.pinCode = _pin.toUpperCase(); diff --git a/lib/screens/myWallets/walletOptions-old.dart b/lib/screens/myWallets/walletOptions-old.dart deleted file mode 100644 index f2ea7b2..0000000 --- a/lib/screens/myWallets/walletOptions-old.dart +++ /dev/null @@ -1,166 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; -import 'package:gecko/models/myWallets.dart'; -import 'package:gecko/models/walletOptions.dart'; -import 'dart:async'; -import 'package:provider/provider.dart'; -import 'package:flutter/services.dart'; -import 'package:gecko/globals.dart'; - -// ignore: must_be_immutable -class WalletOptionsOld extends StatelessWidget with ChangeNotifier { - WalletOptionsOld( - {Key keyMyWallets, - @required this.walletNbr, - @required this.walletName, - @required this.derivation}) - : super(key: keyMyWallets); - int walletNbr; - String walletName; - int derivation; - - @override - Widget build(BuildContext context) { - SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); - log.d("Build walletOptions"); - WalletOptionsProvider _walletOptions = - Provider.of(context); - MyWalletsProvider _myWalletProvider = - Provider.of(context); - - final int _currentChest = _myWalletProvider.getCurrentChest(); - - return WillPopScope( - onWillPop: () { - _walletOptions.isWalletUnlock = false; - Navigator.popUntil( - context, - ModalRoute.withName('/mywallets'), - ); - return Future.value(true); - }, - child: Scaffold( - resizeToAvoidBottomInset: false, - appBar: AppBar( - leading: IconButton( - icon: Icon(Icons.arrow_back, color: Colors.black), - onPressed: () { - _walletOptions.isWalletUnlock = false; - Navigator.popUntil( - context, - ModalRoute.withName('/mywallets'), - ); - }), - title: SizedBox( - height: 22, - child: Text(walletName), - )), - body: Builder( - builder: (ctx) => SafeArea( - child: Column(children: [ - Expanded( - child: Column(children: [ - SizedBox(height: 15), - Text( - 'Clé publique:', - style: TextStyle( - fontSize: 15.0, - color: Colors.grey[600], - fontWeight: FontWeight.w400), - ), - SizedBox(height: 15), - GestureDetector( - onTap: () { - Clipboard.setData(ClipboardData( - text: _walletOptions.pubkey.text)); - _walletOptions.snackCopyKey(ctx); - }, - child: Text( - _walletOptions.pubkey.text, - style: TextStyle( - fontSize: 14.0, - color: Colors.black, - fontWeight: FontWeight.bold, - fontFamily: 'Monospace'), - )), - Expanded( - child: Align( - alignment: Alignment.bottomCenter, - child: SizedBox( - height: 50, - width: 300, - child: ElevatedButton( - style: ElevatedButton.styleFrom( - elevation: 5, - primary: Color( - 0xffFFD68E), //Color(0xffFFD68E), // background - onPrimary: Colors.black, // foreground - ), - onPressed: () => _walletOptions - .renameWalletAlerte( - context, - walletName, - walletNbr, - derivation) - .then((_result) { - if (_result == true) { - WidgetsBinding.instance - .addPostFrameCallback((_) { - _myWalletProvider - .listWallets = - _myWalletProvider - .readAllWallets( - _currentChest); - _myWalletProvider - .rebuildWidget(); - }); - Navigator.popUntil( - context, - ModalRoute.withName( - '/mywallets'), - ); - } - }), - child: Text('Renommer ce portefeuille', - style: TextStyle(fontSize: 20)))))), - SizedBox(height: 30), - SizedBox( - height: 50, - width: 300, - child: ElevatedButton( - style: ElevatedButton.styleFrom( - elevation: 6, - primary: Colors - .redAccent, //Color(0xffFFD68E), // background - onPrimary: Colors.black, // foreground - ), - onPressed: () async { - await _walletOptions.deleteWallet( - context, - _myWalletProvider.getWalletData( - _walletOptions.walletID)); - WidgetsBinding.instance - .addPostFrameCallback((_) { - _myWalletProvider.listWallets = - _myWalletProvider - .readAllWallets(_currentChest); - _myWalletProvider.rebuildWidget(); - }); - }, - child: Text('Supprimer ce portefeuille', - style: TextStyle(fontSize: 20)))), - SizedBox(height: 50), - Text( - 'Portefeuille déverrouillé', - style: TextStyle( - color: Colors.green, - fontWeight: FontWeight.w700, - fontSize: 15), - ), - SizedBox(height: 10) - ])), - ]), - )), - )); - } -}