From 162bd0a730f13273e1bc43922e500be3960af2a4 Mon Sep 17 00:00:00 2001 From: poka Date: Mon, 15 Nov 2021 03:55:08 +0100 Subject: [PATCH] Can change chest on unloncking screen --- lib/models/wallet_options.dart | 4 +- lib/screens/home.dart | 1 + lib/screens/myWallets/choose_chest.dart | 5 ++- lib/screens/myWallets/unlocking_wallet.dart | 42 ++++++++++++++++++--- lib/screens/myWallets/wallets_home.dart | 2 +- 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/lib/models/wallet_options.dart b/lib/models/wallet_options.dart index 19c8099..fcabefa 100644 --- a/lib/models/wallet_options.dart +++ b/lib/models/wallet_options.dart @@ -76,7 +76,7 @@ class WalletOptionsProvider with ChangeNotifier { context, WalletData _wallet, String _pin, int _pinLenght) async { isWalletUnlock = false; try { - String _localDewif = chestBox.get(configBox.get('currentChest')).dewif; + String _localDewif = chestBox.get(_wallet.chest).dewif; String _localPubkey; if ((_localPubkey = await _getPubkeyFromDewif( @@ -113,7 +113,7 @@ class WalletOptionsProvider with ChangeNotifier { int getPinLenght(_walletNbr) { String _localDewif; - if (_walletNbr is int) { + if (_walletNbr is int || _walletNbr == null) { _localDewif = chestBox.get(configBox.get('currentChest')).dewif; } else { _localDewif = _walletNbr; diff --git a/lib/screens/home.dart b/lib/screens/home.dart index fcc22a8..bcb0894 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -87,6 +87,7 @@ class HomeScreen extends StatelessWidget { ), ), appBar: AppBar( + toolbarHeight: 60 * ratio, leading: Builder( builder: (context) => IconButton( key: const Key('drawerMenu'), diff --git a/lib/screens/myWallets/choose_chest.dart b/lib/screens/myWallets/choose_chest.dart index 2cd337e..9058d43 100644 --- a/lib/screens/myWallets/choose_chest.dart +++ b/lib/screens/myWallets/choose_chest.dart @@ -58,6 +58,7 @@ class _ChooseChestState extends State { return Column(children: [ Image.asset( 'assets/chests/${i.value.imageName}', + height: 150, ), const SizedBox(height: 30), Text( @@ -102,8 +103,8 @@ class _ChooseChestState extends State { ), onPressed: () { configBox.put('currentChest', currentChest); - WalletData defaultWallet = _myWalletProvider - .getDefaultWallet(configBox.get('currentChest')); + WalletData defaultWallet = + _myWalletProvider.getDefaultWallet(currentChest); _myWalletProvider.rebuildWidget(); Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (context) { diff --git a/lib/screens/myWallets/unlocking_wallet.dart b/lib/screens/myWallets/unlocking_wallet.dart index d06eccf..64cb187 100644 --- a/lib/screens/myWallets/unlocking_wallet.dart +++ b/lib/screens/myWallets/unlocking_wallet.dart @@ -7,6 +7,7 @@ import 'package:gecko/models/my_wallets.dart'; import 'package:gecko/models/wallet_data.dart'; import 'package:gecko/models/wallet_options.dart'; import 'package:flutter/material.dart'; +import 'package:gecko/screens/myWallets/choose_chest.dart'; import 'package:pin_code_fields/pin_code_fields.dart'; import 'package:provider/provider.dart'; import 'package:gecko/globals.dart'; @@ -35,10 +36,17 @@ class UnlockingWallet extends StatelessWidget { WalletOptionsProvider _walletOptions = Provider.of(context); - // log.d("defaultWallet: " + defaultWallet.toString()); - final int _pinLenght = _walletOptions.getPinLenght(wallet.number); + int _pinLenght; + + ChestData currentChest = chestBox.get(configBox.get('currentChest')); + + if (currentChest.isCesium) { + _pinLenght = _walletOptions.getPinLenght(currentChest.dewif); + wallet = WalletData(derivation: -1, chest: currentChest.key); + } else { + _pinLenght = _walletOptions.getPinLenght(wallet.number); + } errorController = StreamController(); - ChestData currentChest = chestBox.get(wallet.chest); return Scaffold( // backgroundColor: Colors.brown[600], @@ -51,6 +59,7 @@ class UnlockingWallet extends StatelessWidget { Row(mainAxisAlignment: MainAxisAlignment.center, children: [ Image.asset( 'assets/chests/${currentChest.imageName}', + height: 150, ), const SizedBox(width: 5), SizedBox( @@ -75,14 +84,35 @@ class UnlockingWallet extends StatelessWidget { fontWeight: FontWeight.w400), )), const SizedBox(height: 50), - pinForm(context, _pinLenght, wallet.number, wallet.derivation), + pinForm(context, _pinLenght), + const SizedBox(height: 5), + InkWell( + key: const Key('chooseChest'), + onTap: () { + Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return const ChooseChest(); + }), + ); + }, + child: SizedBox( + width: 400, + height: 70, + child: Center( + child: Text('Changer de coffre', + style: TextStyle( + fontSize: 22, + color: orangeC, + fontWeight: FontWeight.w600))), + )), ]), ), ]), )); } - Widget pinForm(context, _pinLenght, int _walletNbr, int _derivation) { + Widget pinForm(context, _pinLenght) { // var _walletPin = ''; // ignore: close_sinks StreamController errorController = @@ -143,7 +173,7 @@ class UnlockingWallet extends StatelessWidget { onCompleted: (_pin) async { log.d("Completed"); _myWalletProvider.pinCode = _pin; - final resultWallet = await _walletOptions.readLocalWallet( + final String resultWallet = await _walletOptions.readLocalWallet( context, wallet, _pin.toUpperCase(), _pinLenght); // _myWalletProvider.pinCode = _pin.toUpperCase(); _myWalletProvider.pinLenght = _pinLenght; diff --git a/lib/screens/myWallets/wallets_home.dart b/lib/screens/myWallets/wallets_home.dart index ed2a036..d72834c 100644 --- a/lib/screens/myWallets/wallets_home.dart +++ b/lib/screens/myWallets/wallets_home.dart @@ -31,8 +31,8 @@ class WalletsHome extends StatelessWidget { if (!_currentChest.isCesium) { myWalletProvider.listWallets = myWalletProvider.readAllWallets(_currentChestNumber); - isWalletsExists = myWalletProvider.checkIfWalletExist(); } + isWalletsExists = myWalletProvider.checkIfWalletExist(); return WillPopScope( onWillPop: () {