From d96b184e0aeee85f59030b217d8ef84792f67d20 Mon Sep 17 00:00:00 2001 From: poka Date: Tue, 30 Mar 2021 02:00:46 +0200 Subject: [PATCH] WIP: Simple wallet Unlocking --- lib/models/history.dart | 5 +---- lib/models/myWallets.dart | 16 ++++++++++++++++ lib/screens/history.dart | 7 ++++++- lib/screens/myWallets/unlockingWallet.dart | 15 +++++---------- lib/screens/myWallets/walletOptions.dart | 6 +----- lib/screens/myWallets/walletsHome.dart | 9 ++------- 6 files changed, 31 insertions(+), 27 deletions(-) diff --git a/lib/models/history.dart b/lib/models/history.dart index 679e83e..8249b6c 100644 --- a/lib/models/history.dart +++ b/lib/models/history.dart @@ -6,7 +6,6 @@ import 'package:flutter/material.dart'; import 'package:gecko/globals.dart'; import 'package:gecko/models/home.dart'; import 'package:gecko/screens/history.dart'; -import 'package:gecko/screens/myWallets/unlockingWallet.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:jdenticon_dart/jdenticon_dart.dart'; import 'package:permission_handler/permission_handler.dart'; @@ -49,9 +48,7 @@ class HistoryProvider with ChangeNotifier { return barcode; } - void pay(amount, comment) { - UnlockingWallet(); - + void pay(context, amount, comment) { String dewif = File(walletsDirectory.path + '${defaultWallet.split(':')[0]}/wallet.dewif') .readAsLinesSync()[0]; diff --git a/lib/models/myWallets.dart b/lib/models/myWallets.dart index 832c917..2d556e3 100644 --- a/lib/models/myWallets.dart +++ b/lib/models/myWallets.dart @@ -84,6 +84,22 @@ class MyWalletsProvider with ChangeNotifier { return listWallets; } + int getDerivationNbr(String _id) { + int chest = int.parse(_id.split(':')[0]); + // int nbr = int.parse(_id.split(':')[1]); + final _walletConfig = File('${walletsDirectory.path}/$chest/list.conf'); + + int derivation; + + _walletConfig.readAsLinesSync().forEach((element) { + if ("${element.split(':')[0]}:${element.split(':')[1]}" == _id) { + derivation = int.parse(element.split(':')[3]); + } + }); + + return derivation; + } + void getDefaultWallet() { defaultWalletFile = File('${appPath.path}/defaultWallet'); diff --git a/lib/screens/history.dart b/lib/screens/history.dart index 14c47bc..df948e8 100644 --- a/lib/screens/history.dart +++ b/lib/screens/history.dart @@ -381,7 +381,12 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { // if (_formKey.currentState.validate()) { // _formKey.currentState.save(); // } - _historyProvider.pay(payAmount.text, payComment.text); + // _historyProvider.pay(payAmount.text, payComment.text); + Navigator.push(context, + MaterialPageRoute(builder: (context) { + return UnlockingWallet( + walletNbr: int.parse(defaultWallet)); + })); }, child: Padding( padding: const EdgeInsets.all(12), diff --git a/lib/screens/myWallets/unlockingWallet.dart b/lib/screens/myWallets/unlockingWallet.dart index c52fe45..f01372b 100644 --- a/lib/screens/myWallets/unlockingWallet.dart +++ b/lib/screens/myWallets/unlockingWallet.dart @@ -13,12 +13,10 @@ import 'package:provider/provider.dart'; // ignore: must_be_immutable class UnlockingWallet extends StatelessWidget { - UnlockingWallet( - {Key keyUnlockWallet, - @required this.walletNbr, - @required this.walletName, - @required this.derivation}) - : super(key: keyUnlockWallet); + UnlockingWallet({ + Key keyUnlockWallet, + @required this.walletNbr, + }) : super(key: keyUnlockWallet); int walletNbr; String walletName; int derivation; @@ -146,10 +144,7 @@ class UnlockingWallet extends StatelessWidget { Navigator.push( formKey.currentContext, SmoothTransition( - page: WalletOptions( - walletNbr: walletNbr, - walletName: walletName, - derivation: derivation))); + page: WalletOptions(walletNbr: walletNbr))); } }, onChanged: (value) { diff --git a/lib/screens/myWallets/walletOptions.dart b/lib/screens/myWallets/walletOptions.dart index 88d731d..868e4a2 100644 --- a/lib/screens/myWallets/walletOptions.dart +++ b/lib/screens/myWallets/walletOptions.dart @@ -13,11 +13,7 @@ import 'package:flutter/services.dart'; // ignore: must_be_immutable class WalletOptions extends StatelessWidget { - WalletOptions( - {Key keyMyWallets, - @required this.walletNbr, - @required this.walletName, - @required this.derivation}) + WalletOptions({Key keyMyWallets, @required this.walletNbr}) : super(key: keyMyWallets); int walletNbr; String walletName; diff --git a/lib/screens/myWallets/walletsHome.dart b/lib/screens/myWallets/walletsHome.dart index ff9f033..4c77571 100644 --- a/lib/screens/myWallets/walletsHome.dart +++ b/lib/screens/myWallets/walletsHome.dart @@ -108,9 +108,7 @@ class WalletsHome extends StatelessWidget { Navigator.push(context, MaterialPageRoute(builder: (context) { return UnlockingWallet( - walletNbr: int.parse(_repository.split(':')[1]), - walletName: _repository.split(':')[2], - derivation: int.parse(_repository.split(':')[3])); + walletNbr: int.parse(_repository.split(':')[1])); })); }, child: ClipRRect( @@ -165,10 +163,7 @@ class WalletsHome extends StatelessWidget { MaterialPageRoute(builder: (context) { return UnlockingWallet( walletNbr: - int.parse(_repository.split(':')[1]), - walletName: _repository.split(':')[2], - derivation: - int.parse(_repository.split(':')[3])); + int.parse(_repository.split(':')[1])); })); }, )