diff --git a/lib/providers/my_wallets.dart b/lib/providers/my_wallets.dart index 0c4a4b8..6760027 100644 --- a/lib/providers/my_wallets.dart +++ b/lib/providers/my_wallets.dart @@ -24,6 +24,7 @@ class MyWalletsProvider with ChangeNotifier { // configBox.delete('endpoint'); if (!configBox.containsKey('endpoint') || configBox.get('endpoint') == '') { log.d('No endpoint, configure...'); + // configBox.put('endpoint', 'wss://gdev.librelois.fr/ws'); configBox.put('endpoint', 'ws://127.0.0.1:9944'); } @@ -62,10 +63,11 @@ class MyWalletsProvider with ChangeNotifier { return _targetedWallet; } - WalletData? getDefaultWallet(int? chest) { + WalletData? getDefaultWallet([int? chest]) { if (chestBox.isEmpty) { return WalletData(chest: 0, number: 0); } else { + chest ??= getCurrentChest(); int? defaultWalletNumber = chestBox.get(chest)!.defaultWallet; return getWalletData([chest, defaultWalletNumber]); } diff --git a/lib/providers/substrate_sdk.dart b/lib/providers/substrate_sdk.dart index 1ee42d8..a91d6fb 100644 --- a/lib/providers/substrate_sdk.dart +++ b/lib/providers/substrate_sdk.dart @@ -26,6 +26,8 @@ class SubstrateSdk with ChangeNotifier { bool importIsLoading = false; int blocNumber = 0; bool isLoadingEndpoint = false; + String debugConnection = ''; + String transactionStatus = ''; TextEditingController jsonKeystore = TextEditingController(); TextEditingController keystorePassword = TextEditingController(); @@ -48,7 +50,7 @@ class SubstrateSdk with ChangeNotifier { n.endpoint = configBox.get('endpoint'); n.ss58 = ss58; node.add(n); - int timeout = 7000; + int timeout = 10000; // if (n.endpoint!.startsWith('ws://')) { // timeout = 5000; @@ -85,20 +87,19 @@ class SubstrateSdk with ChangeNotifier { notifyListeners(); if (res != null) { nodeConnected = true; - notifyListeners(); - snackNode(ctx, true); - } else { - nodeConnected = false; - notifyListeners(); - snackNode(ctx, false); - } - // Subscribe bloc number - if (nodeConnected) { + // Subscribe bloc number sdk.api.setting.subscribeBestNumber((res) { blocNumber = int.parse(res.toString()); notifyListeners(); }); + notifyListeners(); + snackNode(ctx, true); + } else { + nodeConnected = false; + debugConnection = res.toString(); + notifyListeners(); + snackNode(ctx, false); } log.d(sdk.api.connectedNode?.endpoint); @@ -299,6 +300,8 @@ class SubstrateSdk with ChangeNotifier { required String destAddress, required double amount, required String password}) async { + transactionStatus = ''; + setCurrentWallet(fromAddress); log.d(keyring.current.address); @@ -317,15 +320,31 @@ class SubstrateSdk with ChangeNotifier { [destAddress, amount * 100], password, onStatusChange: (status) { - print('status: ' + status); + log.d('Transaction status: ' + status); if (status == 'Ready') { - snack(context, 'Transaction terminé'); + transactionStatus = 'sent'; + notifyListeners(); + // snack(context, 'Transaction terminé'); } }, + ).timeout( + const Duration(seconds: 12), + onTimeout: () => {}, ); print(hash.toString()); - return 'confirmed'; + if (hash.isEmpty) { + transactionStatus = 'timeout'; + notifyListeners(); + + return 'timeout'; + } else { + transactionStatus = hash.toString(); + notifyListeners(); + return hash.toString(); + } } catch (e) { + transactionStatus = e.toString(); + notifyListeners(); return e.toString(); } } @@ -371,12 +390,12 @@ class SubstrateSdk with ChangeNotifier { ); try { - final tata = await sdk.api.tx.signAndSend( + final result = await sdk.api.tx.signAndSend( txInfo, [name], password, ); - log.d(tata); + log.d(result); return 'confirmed'; } on Exception catch (e) { log.e(e); diff --git a/lib/providers/wallets_profiles.dart b/lib/providers/wallets_profiles.dart index e26291e..f32cb35 100644 --- a/lib/providers/wallets_profiles.dart +++ b/lib/providers/wallets_profiles.dart @@ -265,6 +265,10 @@ class WalletsProfilesProvider with ChangeNotifier { return balance; } + + void reload() { + notifyListeners(); + } } snackCopyKey(context) { diff --git a/lib/screens/common_elements.dart b/lib/screens/common_elements.dart index df3231d..cfba0f7 100644 --- a/lib/screens/common_elements.dart +++ b/lib/screens/common_elements.dart @@ -13,7 +13,7 @@ class CommonElements { return Container( padding: const EdgeInsets.all(0), width: 440, - height: boxHeight, + height: isTall ? boxHeight : boxHeight * 0.9, decoration: BoxDecoration( gradient: const LinearGradient( begin: Alignment.topLeft, @@ -37,7 +37,9 @@ class CommonElements { textAlign: TextAlign.justify, text: TextSpan( style: TextStyle( - fontSize: size, color: Colors.black, letterSpacing: 0.3), + fontSize: isTall ? size : size * 0.9, + color: Colors.black, + letterSpacing: 0.3), children: text, ), ), @@ -47,8 +49,8 @@ class CommonElements { Widget nextButton( BuildContext context, String text, nextScreen, bool isFast) { return SizedBox( - width: 410, - height: 70, + width: 380 * ratio, + height: 60 * ratio, child: ElevatedButton( style: ElevatedButton.styleFrom( elevation: 4, @@ -61,7 +63,7 @@ class CommonElements { }, child: Text( text, - style: const TextStyle(fontSize: 24, fontWeight: FontWeight.w600), + style: TextStyle(fontSize: 23 * ratio, fontWeight: FontWeight.w600), ), ), ); @@ -105,7 +107,7 @@ class CommonElements { ), ), // const SizedBox(height: 40), - SizedBox(height: isTall ? 40 : 10), + SizedBox(height: isTall ? 40 : 20), ]); } diff --git a/lib/screens/home.dart b/lib/screens/home.dart index f796033..6429d7d 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -221,11 +221,12 @@ Widget geckHome(context) { child: Material( color: orangeC, // button color child: InkWell( - child: const Padding( - padding: EdgeInsets.all(18), + child: Padding( + padding: const EdgeInsets.all(18), child: Image( - image: AssetImage('assets/home/loupe.png'), - height: 70), + image: + const AssetImage('assets/home/loupe.png'), + height: 62 * ratio), ), onTap: () { Navigator.push( @@ -249,12 +250,12 @@ Widget geckHome(context) { ), ), const SizedBox(height: 12), - const Text( + Text( "Rechercher un\nportefeuille", textAlign: TextAlign.center, style: TextStyle( color: Colors.white, - fontSize: 17, + fontSize: 15 * ratio, fontWeight: FontWeight.w500), ) ]), @@ -266,15 +267,15 @@ Widget geckHome(context) { child: Material( color: orangeC, // button color child: InkWell( - child: const Padding( - padding: EdgeInsets.all(18), + child: Padding( + padding: const EdgeInsets.all(18), child: Image( - image: AssetImage('assets/home/wallet.png'), - height: 75)), + image: const AssetImage( + 'assets/home/wallet.png'), + height: 68 * ratio)), onTap: () { WalletData? defaultWallet = - _myWalletProvider.getDefaultWallet( - configBox.get('currentChest')); + _myWalletProvider.getDefaultWallet(); Navigator.push( context, MaterialPageRoute( @@ -304,18 +305,18 @@ Widget geckHome(context) { ), ), const SizedBox(height: 12), - const Text( + Text( "Gérer mes\nportefeuilles", textAlign: TextAlign.center, style: TextStyle( color: Colors.white, - fontSize: 17, + fontSize: 15 * ratio, fontWeight: FontWeight.w500), ) ]) ]), Padding( - padding: const EdgeInsets.only(top: 40), + padding: EdgeInsets.only(top: 35 * ratio), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -325,12 +326,12 @@ Widget geckHome(context) { child: Material( color: orangeC, // button color child: InkWell( - child: const Padding( - padding: EdgeInsets.all(18), + child: Padding( + padding: const EdgeInsets.all(18), child: Image( - image: AssetImage( + image: const AssetImage( 'assets/home/qrcode.png'), - height: 75)), + height: 68 * ratio)), onTap: () async { await _historyProvider.scan(context); }), @@ -348,12 +349,12 @@ Widget geckHome(context) { ), ), const SizedBox(height: 12), - const Text( + Text( "Scanner un\nQR code", textAlign: TextAlign.center, style: TextStyle( color: Colors.white, - fontSize: 17, + fontSize: 15 * ratio, fontWeight: FontWeight.w500), ) ]) diff --git a/lib/screens/myWallets/choose_chest.dart b/lib/screens/myWallets/choose_chest.dart index c9b7aad..0f09b48 100644 --- a/lib/screens/myWallets/choose_chest.dart +++ b/lib/screens/myWallets/choose_chest.dart @@ -3,9 +3,10 @@ import 'package:gecko/globals.dart'; import 'package:gecko/providers/my_wallets.dart'; import 'package:gecko/models/wallet_data.dart'; import 'package:flutter/material.dart'; -import 'package:gecko/screens/myWallets/generate_wallets.dart'; +import 'package:gecko/screens/myWallets/restore_chest.dart'; import 'package:gecko/screens/myWallets/unlocking_wallet.dart'; import 'package:carousel_slider/carousel_slider.dart'; +import 'package:gecko/screens/onBoarding/5.dart'; import 'package:provider/provider.dart'; class ChooseChest extends StatefulWidget { @@ -114,7 +115,7 @@ class _ChooseChestState extends State { onPressed: () { configBox.put('currentChest', currentChest); WalletData? defaultWallet = - _myWalletProvider.getDefaultWallet(currentChest); + _myWalletProvider.getDefaultWallet(); _myWalletProvider.rebuildWidget(); Navigator.pushAndRemoveUntil( context, @@ -136,28 +137,54 @@ class _ChooseChestState extends State { ), ), ), - const SizedBox(height: 20), + // const SizedBox(height: 20), + Expanded( + child: Align( + alignment: Alignment.bottomCenter, + child: InkWell( + key: const Key('createNewChest'), + onTap: () { + Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return const OnboardingStepFive(skipIntro: true); + }), + ); + }, + child: SizedBox( + width: 400, + height: 50, + child: Center( + child: Text('Créer un nouveau coffre', + style: TextStyle( + fontSize: 22, + color: orangeC, + fontWeight: FontWeight.w600))), + ), + ), + ), + ), InkWell( - key: const Key('createNewChest'), + key: const Key('importChest'), onTap: () { Navigator.push( context, MaterialPageRoute(builder: (context) { - return GenerateFastChestScreen(); + return const RestoreChest(skipIntro: true); }), ); }, child: SizedBox( width: 400, - height: 70, + height: 50, child: Center( - child: Text('Créer un nouveau coffre', + child: Text('Importer un coffre', style: TextStyle( fontSize: 22, color: orangeC, fontWeight: FontWeight.w600))), )), - const SizedBox(height: 10), + const SizedBox(height: 20), ]), )); } diff --git a/lib/screens/myWallets/choose_wallet.dart b/lib/screens/myWallets/choose_wallet.dart index 7fabd0c..4bb756a 100644 --- a/lib/screens/myWallets/choose_wallet.dart +++ b/lib/screens/myWallets/choose_wallet.dart @@ -22,9 +22,7 @@ class ChooseWalletScreen extends StatelessWidget { @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); - SubstrateSdk _sub = Provider.of(context, listen: false); - WalletsProfilesProvider _walletViewProvider = - Provider.of(context, listen: false); + // HomeProvider _homeProvider = Provider.of(context); return Scaffold( appBar: AppBar( @@ -50,19 +48,12 @@ class ChooseWalletScreen extends StatelessWidget { onPrimary: Colors.white, // foreground ), onPressed: () async { - final acc = _sub.getCurrentWallet(); - log.d( - "fromAddress: ${acc.address!},destAddress: ${_walletViewProvider.outputPubkey.text}, amount: ${double.parse(_walletViewProvider.payAmount.text)}, password: $pin"); - final resultPay = await _sub.pay(context, - fromAddress: acc.address!, - destAddress: _walletViewProvider.outputPubkey.text, - amount: - double.parse(_walletViewProvider.payAmount.text), - password: pin.toUpperCase()); - await paymentsResult(context, resultPay); + Navigator.pop(context); + Navigator.pop(context); + Navigator.pop(context); }, child: const Text( - 'Valider le paiement', + 'Choisir ce portefeuille', style: TextStyle(fontSize: 24, fontWeight: FontWeight.w600), ), @@ -80,9 +71,11 @@ class ChooseWalletScreen extends StatelessWidget { Provider.of(context); final bool isWalletsExists = _myWalletProvider.checkIfWalletExist(); SubstrateSdk _sub = Provider.of(context, listen: false); + WalletsProfilesProvider _walletViewProvider = + Provider.of(context, listen: false); WalletData? defaultWallet = - _myWalletProvider.getDefaultWallet(currentChest); + _myWalletProvider.getDefaultWallet(); _selectedId ??= defaultWallet!.id(); _derivation ??= defaultWallet!.derivation!; @@ -129,8 +122,12 @@ class ChooseWalletScreen extends StatelessWidget { onTap: () { _derivation = _repository.derivation!; _selectedId = _repository.id(); + chestBox.get(currentChest)!.defaultWallet = + _repository.number; + _sub.setCurrentWallet(_repository.address!); _myWalletProvider.rebuildWidget(); + _walletViewProvider.reload(); }, child: ClipOvalShadow( shadow: const Shadow( @@ -196,8 +193,13 @@ class ChooseWalletScreen extends StatelessWidget { onTap: () { _derivation = _repository.derivation!; _selectedId = _repository.id(); + chestBox.get(currentChest)!.defaultWallet = + _repository.number; + _sub.setCurrentWallet(_repository.address!); _myWalletProvider.rebuildWidget(); + _walletViewProvider.reload(); + _sub.reload(); }, ) ]), @@ -208,34 +210,3 @@ class ChooseWalletScreen extends StatelessWidget { ]); } } - -Future paymentsResult(context, String resultPay) { - final bool isValid = resultPay == "confirmed"; - if (!isValid) log.e(resultPay); - - return showDialog( - context: context, - barrierDismissible: true, // user must tap button! - builder: (BuildContext context) { - return AlertDialog( - title: Text(isValid - ? 'Paiement effecuté avec succès !' - : "Une erreur s'est produite lors du paiement:\n$resultPay"), - content: const SingleChildScrollView(child: Text('')), - actions: [ - TextButton( - child: const Text("OK"), - onPressed: () async { - isValid - ? await Navigator.of(context).pushNamedAndRemoveUntil( - '/', - ModalRoute.withName('/'), - ) - : Navigator.pop(context); - }, - ), - ], - ); - }, - ); -} diff --git a/lib/screens/myWallets/confirm_wallet_storage.dart b/lib/screens/myWallets/confirm_wallet_storage.dart index 3f2352c..74d23c0 100644 --- a/lib/screens/myWallets/confirm_wallet_storage.dart +++ b/lib/screens/myWallets/confirm_wallet_storage.dart @@ -164,10 +164,8 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier { Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (context) { return UnlockingWallet( - wallet: - _myWalletProvider.getDefaultWallet( - configBox.get('currentChest'), - ), + wallet: _myWalletProvider + .getDefaultWallet(), action: "mywallets", ); }), ModalRoute.withName('/')); diff --git a/lib/screens/myWallets/generate_wallets.dart b/lib/screens/myWallets/generate_wallets.dart deleted file mode 100644 index f6c91a7..0000000 --- a/lib/screens/myWallets/generate_wallets.dart +++ /dev/null @@ -1,222 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:flutter/services.dart'; -import 'package:gecko/globals.dart'; -import 'package:gecko/providers/generate_wallets.dart'; -import 'package:gecko/screens/myWallets/confirm_wallet_storage.dart'; -import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; - -// ignore: must_be_immutable -class GenerateFastChestScreen extends StatelessWidget { - bool hasError = false; - String validPin = 'NO PIN'; - String currentText = ""; - var pinColor = Colors.grey[300]; - - final GlobalKey _toolTipSentence = GlobalKey(); - final GlobalKey _toolTipSecret = GlobalKey(); - - GenerateFastChestScreen({Key? key}) : super(key: key); - - @override - Widget build(BuildContext context) { - SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); - GenerateWalletsProvider _generateWalletProvider = - Provider.of(context, listen: false); - - _generateWalletProvider.pin.text = kDebugMode && debugPin - ? 'AAAAA' - : _generateWalletProvider.changePinCode(reload: false).toUpperCase(); - - return WillPopScope( - onWillPop: () { - _generateWalletProvider.pin.text = ''; - _generateWalletProvider.mnemonicController.text = ''; - return Future.value(true); - }, - child: Scaffold( - appBar: AppBar( - toolbarHeight: 60 * ratio, - leading: IconButton( - icon: const Icon(Icons.arrow_back, color: Colors.black), - onPressed: () { - _generateWalletProvider.pin.text = ''; - _generateWalletProvider.mnemonicController.text = ''; - Navigator.of(context).pop(); - }), - title: const SizedBox( - height: 22, - child: Text('Générer un coffre'), - )), - floatingActionButton: SizedBox( - height: 80.0, - width: 80.0, - child: FittedBox( - child: FloatingActionButton( - heroTag: "buttonGenerateWallet", - onPressed: () { - _generateWalletProvider.reloadBuild(); - }, - child: SizedBox( - height: 40.0, - width: 40.0, - child: Icon(Icons.replay, color: Colors.grey[850]), - ), - backgroundColor: - floattingYellow, //smoothYellow, //Color.fromARGB(500, 204, 255, 255), - ))), - body: Builder( - builder: (ctx) => SafeArea( - child: Column(children: [ - const SizedBox(height: 20), - toolTips(_toolTipSentence, 'Phrase de restauration:', - "Notez et gardez cette phrase précieusement sur un papier, elle vous servira à restaurer votre portefeuille sur un autre appareil"), - Consumer(builder: (context, _gWP, _) { - return FutureBuilder( - future: _gWP.generateWordList(context), - builder: (BuildContext context, AsyncSnapshot _data) { - if (!_data.hasData) { - return const Text(''); - } else { - return Text(_gWP.generatedMnemonic!, - maxLines: 3, - textAlign: TextAlign.center, - style: const TextStyle( - fontSize: 22.0, - color: Colors.black, - fontWeight: FontWeight.w400)); - } - }); - }), - const SizedBox(height: 8), - toolTips(_toolTipSecret, 'Code secret:', - "Retenez bien votre code secret, il vous sera demandé à chaque paiement, ainsi que pour configurer votre portefeuille"), - Stack( - alignment: Alignment.centerRight, - children: [ - TextField( - key: const Key('generatedPin'), - enabled: false, - controller: _generateWalletProvider.pin, - maxLines: 1, - textAlign: TextAlign.center, - decoration: const InputDecoration(), - style: const TextStyle( - fontSize: 30.0, - color: Colors.black, - fontWeight: FontWeight.bold)), - IconButton( - icon: const Icon(Icons.replay), - color: orangeC, - onPressed: () { - _generateWalletProvider.changePinCode(reload: false); - }, - ), - ], - ), - const SizedBox(height: 20), - ElevatedButton( - key: const Key('storeKeychain'), - style: ElevatedButton.styleFrom( - primary: yellowC, // background - onPrimary: Colors.black, // foreground - ), - onPressed: _generateWalletProvider.walletIsGenerated - ? () async { - _generateWalletProvider.nbrWord = - _generateWalletProvider.getRandomInt(); - await Navigator.push( - context, - MaterialPageRoute(builder: (context) { - return ConfirmStoreWallet( - generatedMnemonic: - _generateWalletProvider.generatedMnemonic, - generatedWallet: - _generateWalletProvider.actualWallet); - }), - ); - } - : null, - child: const Text('Enregistrer ce coffre', - style: TextStyle(fontSize: 20))), - const SizedBox(height: 20), - // GestureDetector( - // onTap: () { - // Navigator.push( - // context, - // MaterialPageRoute(builder: (context) { - // return PrintWallet( - // _generateWalletProvider.generatedMnemonic); - // }), - // ); - // }, - // child: const Icon(Icons.print)) - ]), - ), - ), - ), - ); - } - - Widget toolTips(_key, _text, _message) { - return GestureDetector( - onTap: () { - final dynamic _toolTip = _key.currentState; - _toolTip.ensureTooltipVisible(); - }, - child: Tooltip( - padding: const EdgeInsets.all(10), - key: _key, - showDuration: const Duration(seconds: 5), - message: _message, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const SizedBox(width: 20), - Column(children: [ - SizedBox( - width: 30, - height: 25, - child: - Icon(Icons.info_outline, size: 22, color: orangeC)), - const SizedBox(height: 1) - ]), - Text( - _text, - style: TextStyle( - fontSize: 15.0, - color: Colors.grey[600], - fontWeight: FontWeight.w400), - ), - const SizedBox(width: 45) - ]))); - } -} - -// // ignore: must_be_immutable -// class PrintWallet extends StatelessWidget { -// const PrintWallet(this.sentence, {Key? key}) : super(key: key); - -// final String? sentence; - -// @override -// Widget build(BuildContext context) { -// GenerateWalletsProvider _generateWalletProvider = -// Provider.of(context); -// return MaterialApp( -// home: Scaffold( -// appBar: AppBar( -// leading: IconButton( -// icon: const Icon(Icons.arrow_back, color: Colors.white), -// onPressed: () { -// Navigator.pop(context); -// }), -// toolbarHeight: 60 * ratio, -// title: const Text('Imprimer ce coffre')), -// body: PdfPreview( -// build: (format) => _generateWalletProvider.printWallet(sentence), -// ), -// ), -// ); -// } -// } diff --git a/lib/screens/myWallets/restore_chest.dart b/lib/screens/myWallets/restore_chest.dart index 3772eac..3ac4833 100644 --- a/lib/screens/myWallets/restore_chest.dart +++ b/lib/screens/myWallets/restore_chest.dart @@ -5,13 +5,15 @@ import 'package:flutter/material.dart'; import 'package:gecko/providers/generate_wallets.dart'; import 'package:gecko/providers/substrate_sdk.dart'; import 'package:gecko/screens/common_elements.dart'; +import 'package:gecko/screens/onBoarding/7.dart'; import 'package:gecko/screens/onBoarding/9.dart'; import 'package:provider/provider.dart'; // import 'package:gecko/models/home.dart'; // import 'package:provider/provider.dart'; class RestoreChest extends StatelessWidget { - const RestoreChest({Key? key}) : super(key: key); + const RestoreChest({Key? key, this.skipIntro = false}) : super(key: key); + final bool skipIntro; @override Widget build(BuildContext context) { @@ -98,7 +100,9 @@ class RestoreChest extends StatelessWidget { await Navigator.push( context, FaderTransition( - page: const OnboardingStepThirteen(), + page: skipIntro + ? const OnboardingStepNine() + : const OnboardingStepSeven(), isFast: true), ); } else { diff --git a/lib/screens/myWallets/unlocking_wallet.dart b/lib/screens/myWallets/unlocking_wallet.dart index a91563b..78a2eb0 100644 --- a/lib/screens/myWallets/unlocking_wallet.dart +++ b/lib/screens/myWallets/unlocking_wallet.dart @@ -8,9 +8,11 @@ import 'package:gecko/providers/my_wallets.dart'; import 'package:gecko/models/wallet_data.dart'; import 'package:gecko/providers/wallet_options.dart'; import 'package:flutter/material.dart'; +import 'package:gecko/providers/wallets_profiles.dart'; import 'package:gecko/screens/myWallets/choose_chest.dart'; import 'package:gecko/screens/myWallets/choose_wallet.dart'; import 'package:gecko/screens/myWallets/wallets_home.dart'; +import 'package:gecko/screens/transaction_in_progress.dart'; import 'package:pin_code_fields/pin_code_fields.dart'; import 'package:provider/provider.dart'; import 'package:gecko/globals.dart'; @@ -212,21 +214,49 @@ class UnlockingWallet extends StatelessWidget { pinFocus.requestFocus(); } else { pinColor = Colors.green[400]; - if (action == "mywallets") { - Navigator.push( - context, - MaterialPageRoute(builder: (context) { - return const WalletsHome(); - }), - ); - } else if (action == "pay") { - Navigator.push( - context, - MaterialPageRoute(builder: (context) { - return ChooseWalletScreen( - chest: currentChestNumber, pin: _pin.toUpperCase()); - }), - ); + switch (action) { + case "mywallets": + Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return const WalletsHome(); + }), + ); + break; + case "changeWallet": + Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return ChooseWalletScreen( + chest: currentChestNumber, pin: _pin.toUpperCase()); + }), + ); + break; + case "pay": + // Navigator.pop(context); + // Navigator.pop(context); + // Payment workflow ! + WalletsProfilesProvider _walletViewProvider = + Provider.of(context, + listen: false); + final acc = _sub.getCurrentWallet(); + log.d( + "fromAddress: ${acc.address!},destAddress: ${_walletViewProvider.outputPubkey.text}, amount: ${double.parse(_walletViewProvider.payAmount.text)}, password: $_pin"); + _sub.pay(context, + fromAddress: acc.address!, + destAddress: _walletViewProvider.outputPubkey.text, + amount: + double.parse(_walletViewProvider.payAmount.text), + password: _pin.toUpperCase()); + // await paymentsResult(context, resultPay); + Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return TransactionInProgress( + chest: currentChestNumber, pin: _pin.toUpperCase()); + }), + ); + break; } } }, diff --git a/lib/screens/myWallets/wallet_options.dart b/lib/screens/myWallets/wallet_options.dart index fa9bdcf..a740335 100644 --- a/lib/screens/myWallets/wallet_options.dart +++ b/lib/screens/myWallets/wallet_options.dart @@ -29,7 +29,7 @@ class WalletOptions extends StatelessWidget { final int _currentChest = _myWalletProvider.getCurrentChest()!; - // final currentWallet = _myWalletProvider.getDefaultWallet(_currentChest); + // final currentWallet = _myWalletProvider.getDefaultWallet(); // log.d(_walletOptions.getAddress(_currentChest, 3)); log.d("Wallet options: $_currentChest:${wallet.derivation}"); @@ -336,7 +336,7 @@ class WalletOptions extends StatelessWidget { WalletOptionsProvider _walletOptions, int _currentChest) { WalletData defaultWallet = - _myWalletProvider.getDefaultWallet(_currentChest)!; + _myWalletProvider.getDefaultWallet()!; _walletOptions.isDefaultWallet = (defaultWallet.number == wallet.id()[1]); diff --git a/lib/screens/myWallets/wallets_home.dart b/lib/screens/myWallets/wallets_home.dart index eab5beb..98895b3 100644 --- a/lib/screens/myWallets/wallets_home.dart +++ b/lib/screens/myWallets/wallets_home.dart @@ -155,7 +155,7 @@ class WalletsHome extends StatelessWidget { List _listWallets = _myWalletProvider.listWallets; WalletData? defaultWallet = - _myWalletProvider.getDefaultWallet(configBox.get('currentChest')); + _myWalletProvider.getDefaultWallet(); final double screenWidth = MediaQuery.of(context).size.width; int nTule = 2; diff --git a/lib/screens/onBoarding/10.dart b/lib/screens/onBoarding/10.dart index c4fd8bd..ff99af3 100644 --- a/lib/screens/onBoarding/10.dart +++ b/lib/screens/onBoarding/10.dart @@ -14,8 +14,8 @@ import 'package:pin_code_fields/pin_code_fields.dart'; import 'package:provider/provider.dart'; // ignore: must_be_immutable -class OnboardingStepFourteen extends StatelessWidget { - OnboardingStepFourteen({ +class OnboardingStepTen extends StatelessWidget { + OnboardingStepTen({ Key? validationKey, }) : super(key: validationKey); @@ -146,7 +146,7 @@ class OnboardingStepFourteen extends StatelessWidget { Navigator.push( context, FaderTransition( - page: const OnboardingStepFiveteen(), isFast: false), + page: const OnboardingStepEleven(), isFast: false), ); } else { errorController.add(ErrorAnimationType diff --git a/lib/screens/onBoarding/11_congratulations.dart b/lib/screens/onBoarding/11_congratulations.dart index 67f0777..acf67c7 100644 --- a/lib/screens/onBoarding/11_congratulations.dart +++ b/lib/screens/onBoarding/11_congratulations.dart @@ -7,8 +7,8 @@ import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/myWallets/wallets_home.dart'; // ignore: must_be_immutable -class OnboardingStepFiveteen extends StatelessWidget { - const OnboardingStepFiveteen({Key? key}) : super(key: key); +class OnboardingStepEleven extends StatelessWidget { + const OnboardingStepEleven({Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -54,8 +54,8 @@ class OnboardingStepFiveteen extends StatelessWidget { Widget finishButton(BuildContext context) { return SizedBox( - width: 410, - height: 70, + width: 380 * ratio, + height: 60 * ratio, child: ElevatedButton( key: const Key('goWalletHome'), style: ElevatedButton.styleFrom( @@ -72,7 +72,8 @@ Widget finishButton(BuildContext context) { ModalRoute.withName('/'), ); }, - child: const Text("Accéder à mon coffre", - style: TextStyle(fontSize: 24, fontWeight: FontWeight.w600))), + child: Text("Accéder à mon coffre", + style: + TextStyle(fontSize: 22 * ratio, fontWeight: FontWeight.w600))), ); } diff --git a/lib/screens/onBoarding/5.dart b/lib/screens/onBoarding/5.dart index fca4806..a495fe8 100644 --- a/lib/screens/onBoarding/5.dart +++ b/lib/screens/onBoarding/5.dart @@ -13,7 +13,9 @@ import 'package:provider/provider.dart'; AsyncSnapshot? mnemoList; class OnboardingStepFive extends StatelessWidget { - const OnboardingStepFive({Key? key}) : super(key: key); + const OnboardingStepFive({Key? key, this.skipIntro = false}) + : super(key: key); + final bool skipIntro; @override Widget build(BuildContext context) { @@ -47,9 +49,9 @@ class OnboardingStepFive extends StatelessWidget { 'Gecko a généré votre phrase de restauration ! Tâchez de la garder bien secrète, car elle permet à quiconque la connaît d’accéder à tous vos portefeuilles.'), ], ), - const SizedBox(height: 40), + SizedBox(height: 35 * ratio), sentanceArray(context), - const SizedBox(height: 20), + SizedBox(height: 17 * ratio), GestureDetector( onTap: () { Navigator.push( @@ -61,7 +63,7 @@ class OnboardingStepFive extends StatelessWidget { }, child: Image.asset( 'assets/printer.png', - height: 45, + height: 42 * ratio, ), ), const SizedBox(height: 40), @@ -69,8 +71,8 @@ class OnboardingStepFive extends StatelessWidget { child: Align( alignment: Alignment.bottomCenter, child: SizedBox( - width: 410, - height: 70, + width: 380 * ratio, + height: 60 * ratio, child: ElevatedButton( key: const Key('generateMnemonic'), style: ElevatedButton.styleFrom( @@ -82,15 +84,16 @@ class OnboardingStepFive extends StatelessWidget { _generateWalletProvider.reloadBuild(); // setState(() {}); }, - child: const Text("Choisir une autre phrase", + child: Text("Choisir une autre phrase", style: TextStyle( - fontSize: 24, fontWeight: FontWeight.w600))), + fontSize: 22 * ratio, + fontWeight: FontWeight.w600))), ), ), ), - const SizedBox(height: 25), - nextButton(context, "J'ai noté ma phrase", false), - const SizedBox(height: 40), + SizedBox(height: 22 * ratio), + nextButton(context, "J'ai noté ma phrase", false, skipIntro), + SizedBox(height: 35 * ratio), ]), ), ); @@ -157,12 +160,12 @@ Widget arrayCell(dataWord) { child: Column(children: [ Text( dataWord.split(':')[0], - style: const TextStyle(fontSize: 15, color: Color(0xff6b6b52)), + style: TextStyle(fontSize: 13 * ratio, color: const Color(0xff6b6b52)), ), Text( dataWord.split(':')[1], key: Key('word${dataWord.split(':')[0]}'), - style: const TextStyle(fontSize: 20, color: Colors.black), + style: TextStyle(fontSize: 17 * ratio, color: Colors.black), ), ]), ); @@ -207,14 +210,15 @@ class PrintWallet extends StatelessWidget { } } -Widget nextButton(BuildContext context, String text, bool isFast) { +Widget nextButton( + BuildContext context, String text, bool isFast, bool skipIntro) { GenerateWalletsProvider _generateWalletProvider = Provider.of(context, listen: false); MyWalletsProvider _myWalletProvider = Provider.of(context, listen: false); return SizedBox( - width: 410, - height: 70, + width: 380 * ratio, + height: 60 * ratio, child: ElevatedButton( style: ElevatedButton.styleFrom( elevation: 4, @@ -232,13 +236,14 @@ Widget nextButton(BuildContext context, String text, bool isFast) { context, FaderTransition( page: OnboardingStepSix( - generatedMnemonic: _generateWalletProvider.generatedMnemonic), + generatedMnemonic: _generateWalletProvider.generatedMnemonic, + skipIntro: skipIntro), isFast: true), ); }, child: Text( text, - style: const TextStyle(fontSize: 24, fontWeight: FontWeight.w600), + style: TextStyle(fontSize: 22 * ratio, fontWeight: FontWeight.w600), ), ), ); diff --git a/lib/screens/onBoarding/6.dart b/lib/screens/onBoarding/6.dart index ba256c0..c76ec4d 100644 --- a/lib/screens/onBoarding/6.dart +++ b/lib/screens/onBoarding/6.dart @@ -6,13 +6,16 @@ import 'package:gecko/globals.dart'; import 'package:gecko/providers/generate_wallets.dart'; import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/onBoarding/7.dart'; +import 'package:gecko/screens/onBoarding/9.dart'; import 'package:provider/provider.dart'; // ignore: must_be_immutable class OnboardingStepSix extends StatelessWidget { - OnboardingStepSix({Key? key, required this.generatedMnemonic}) + OnboardingStepSix( + {Key? key, required this.skipIntro, required this.generatedMnemonic}) : super(key: key); + final bool skipIntro; String? generatedMnemonic; TextEditingController wordController = TextEditingController(); final TextEditingController _mnemonicController = TextEditingController(); @@ -116,8 +119,13 @@ class OnboardingStepSix extends StatelessWidget { child: Expanded( child: Align( alignment: Alignment.bottomCenter, - child: nextButton(context, 'Continuer', - const OnboardingStepSeven(), false), + child: nextButton( + context, + 'Continuer', + skipIntro + ? const OnboardingStepNine() + : const OnboardingStepSeven(), + false), ), ), ), @@ -130,7 +138,7 @@ class OnboardingStepSix extends StatelessWidget { // ), // ), // ), - const SizedBox(height: 40), + SizedBox(height: 35 * ratio), ]), ), ), @@ -217,8 +225,8 @@ Widget nextButton(BuildContext context, String text, nextScreen, bool isFast) { _generateWalletProvider.askedWordColor = Colors.black; return SizedBox( - width: 410, - height: 70, + width: 380 * ratio, + height: 60 * ratio, child: ElevatedButton( style: ElevatedButton.styleFrom( elevation: 4, diff --git a/lib/screens/onBoarding/8.dart b/lib/screens/onBoarding/8.dart index dd7ce56..22b9fc2 100644 --- a/lib/screens/onBoarding/8.dart +++ b/lib/screens/onBoarding/8.dart @@ -40,7 +40,7 @@ class OnboardingStepEight extends StatelessWidget { ], 'coffre-fort-protege-les-portefeuilles.png', '>', - const OnboardingStepThirteen(), + const OnboardingStepNine(), 7), ), ); diff --git a/lib/screens/onBoarding/9.dart b/lib/screens/onBoarding/9.dart index d7d7d2f..b8021b9 100644 --- a/lib/screens/onBoarding/9.dart +++ b/lib/screens/onBoarding/9.dart @@ -9,8 +9,8 @@ import 'package:gecko/screens/onBoarding/10.dart'; import 'package:provider/provider.dart'; // ignore: must_be_immutable -class OnboardingStepThirteen extends StatelessWidget { - const OnboardingStepThirteen({Key? key}) : super(key: key); +class OnboardingStepNine extends StatelessWidget { + const OnboardingStepNine({Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -84,8 +84,8 @@ class OnboardingStepThirteen extends StatelessWidget { child: Align( alignment: Alignment.bottomCenter, child: SizedBox( - width: 410, - height: 70, + width: 380 * ratio, + height: 60 * ratio, child: ElevatedButton( key: const Key('changeSecretCode'), style: ElevatedButton.styleFrom( @@ -96,14 +96,15 @@ class OnboardingStepThirteen extends StatelessWidget { onPressed: () { _generateWalletProvider.changePinCode(reload: true); }, - child: const Text("Choisir un autre code secret", + child: Text("Choisir un autre code secret", style: TextStyle( - fontSize: 24, fontWeight: FontWeight.w600))), + fontSize: 22 * ratio, + fontWeight: FontWeight.w600))), ))), - const SizedBox(height: 25), + SizedBox(height: 22 * ratio), common.nextButton(context, "J'ai noté mon code secret", - OnboardingStepFourteen(), false), - const SizedBox(height: 40), + OnboardingStepTen(), false), + SizedBox(height: 35 * ratio), ]), )); } diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index 4f4c60a..bd13ad4 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -3,11 +3,11 @@ import 'package:durt/durt.dart'; import 'package:flutter/services.dart'; import 'package:gecko/providers/my_wallets.dart'; import 'package:gecko/providers/substrate_sdk.dart'; -import 'package:gecko/screens/myWallets/generate_wallets.dart'; import 'dart:io'; // import 'package:gecko/screens/myWallets/import_cesium_wallet.dart'; import 'package:gecko/globals.dart'; import 'package:gecko/screens/myWallets/restore_chest.dart'; +import 'package:gecko/screens/onBoarding/5.dart'; import 'package:provider/provider.dart'; // ignore: must_be_immutable @@ -91,7 +91,7 @@ class SettingsScreen extends StatelessWidget { onPressed: () => Navigator.push( context, MaterialPageRoute(builder: (context) { - return GenerateFastChestScreen(); + return const OnboardingStepFive(skipIntro: true); }), ), child: const Text( @@ -114,7 +114,7 @@ class SettingsScreen extends StatelessWidget { onPressed: () => Navigator.push( context, MaterialPageRoute(builder: (context) { - return const RestoreChest(); + return const RestoreChest(skipIntro: true); }), ), child: const Text( diff --git a/lib/screens/substrate_sandbox.dart b/lib/screens/substrate_sandbox.dart index 08136f0..5177d0c 100644 --- a/lib/screens/substrate_sandbox.dart +++ b/lib/screens/substrate_sandbox.dart @@ -160,7 +160,10 @@ class SubstrateSandBox extends StatelessWidget { _sub.generatedMnemonic, textAlign: TextAlign.center, ), - ) + ), + const Text('--------'), + const SizedBox(height: 10), + Text(_sub.debugConnection) ]) ]), ); diff --git a/lib/screens/transaction_in_progress.dart b/lib/screens/transaction_in_progress.dart new file mode 100644 index 0000000..1adb453 --- /dev/null +++ b/lib/screens/transaction_in_progress.dart @@ -0,0 +1,184 @@ +import 'package:flutter/services.dart'; +import 'package:gecko/globals.dart'; +import 'package:flutter/material.dart'; +import 'package:gecko/providers/my_wallets.dart'; +import 'package:gecko/providers/substrate_sdk.dart'; +import 'package:gecko/providers/wallets_profiles.dart'; +import 'package:provider/provider.dart'; +// import 'package:gecko/models/home.dart'; +// import 'package:provider/provider.dart'; + +// ignore: must_be_immutable +class TransactionInProgress extends StatelessWidget { + const TransactionInProgress( + {Key? key, required this.chest, required this.pin}) + : super(key: key); + final int chest; + final String pin; + + @override + Widget build(BuildContext context) { + SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); + SubstrateSdk _sub = Provider.of(context, listen: true); + WalletsProfilesProvider _walletViewProvider = + Provider.of(context, listen: false); + MyWalletsProvider _myWalletProvider = + Provider.of(context, listen: false); + + String _resultText; + bool isLoading = true; + // Map jsonResult; + final _result = _sub.transactionStatus; + + final from = _myWalletProvider.getDefaultWallet()!.name!; + final to = _walletViewProvider + .getShortPubkey(_walletViewProvider.outputPubkey.text); + final amount = _walletViewProvider.payAmount.text; + + switch (_result) { + case '': + { + _resultText = 'Envoi en cours ...'; + } + break; + case 'sent': + { + _resultText = 'En cours de validation ...'; + } + break; + default: + { + isLoading = false; + // jsonResult = json.decode(_result); + log.d(_result); + if (_result.contains('blockHash: ')) { + _resultText = 'Transcation validé !'; + } else { + _resultText = "Une erreur s'est produite:\n\n$_result"; + } + } + } + + return WillPopScope( + onWillPop: () { + _sub.transactionStatus = ''; + Navigator.pop(context); + Navigator.pop(context); + Navigator.pop(context); + return Future.value(true); + }, + child: Scaffold( + appBar: AppBar( + toolbarHeight: 60 * ratio, + elevation: 0, + automaticallyImplyLeading: false, + title: SizedBox( + height: 22, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: const [Text('Transaction en cours')]), + )), + body: SafeArea( + child: Align( + alignment: FractionalOffset.bottomCenter, + child: Column(children: [ + Container( + width: double.infinity, + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + colors: [ + yellowC, + const Color(0xfffafafa), + ], + )), + child: Column(children: [ + const SizedBox(height: 10), + Text( + '$amount $currencyName', + textAlign: TextAlign.center, + style: const TextStyle( + fontSize: 18, fontWeight: FontWeight.w600), + ), + const SizedBox(height: 10), + const Text( + 'de', + textAlign: TextAlign.center, + style: TextStyle(fontSize: 18), + ), + Text( + from, + textAlign: TextAlign.center, + style: const TextStyle( + fontSize: 18, fontWeight: FontWeight.w600), + ), + const SizedBox(height: 10), + const Text( + 'vers', + textAlign: TextAlign.center, + style: TextStyle(fontSize: 18), + ), + Text( + to, + textAlign: TextAlign.center, + style: const TextStyle( + fontSize: 18, fontWeight: FontWeight.w600), + ), + const SizedBox(height: 20), + ]), + ), + // const SizedBox(height: 20, width: double.infinity), + const Spacer(), + Row(mainAxisAlignment: MainAxisAlignment.center, children: [ + Text( + _resultText, + textAlign: TextAlign.center, + style: TextStyle(fontSize: 19 * ratio), + ), + Visibility( + visible: isLoading, + child: SizedBox( + height: 15, + width: 15, + child: CircularProgressIndicator( + color: orangeC, + strokeWidth: 2, + ), + ), + ), + ]), + const Spacer(), + Expanded( + child: Align( + alignment: Alignment.bottomCenter, + child: SizedBox( + width: 380 * ratio, + height: 60 * ratio, + child: ElevatedButton( + style: ElevatedButton.styleFrom( + elevation: 4, + primary: orangeC, // background + onPrimary: Colors.white, // foreground + ), + onPressed: () { + Navigator.pop(context); + Navigator.pop(context); + Navigator.pop(context); + }, + child: Text( + 'Fermer', + style: TextStyle( + fontSize: 23 * ratio, + fontWeight: FontWeight.w600), + ), + ), + ), + ), + ), + SizedBox(height: isTall ? 80 : 20) + ])), + ), + )); + } +} diff --git a/lib/screens/wallet_view.dart b/lib/screens/wallet_view.dart index 18cabb5..2eca815 100644 --- a/lib/screens/wallet_view.dart +++ b/lib/screens/wallet_view.dart @@ -2,6 +2,7 @@ import 'package:flutter/services.dart'; import 'package:gecko/globals.dart'; import 'package:flutter/material.dart'; import 'package:gecko/providers/cesium_plus.dart'; +import 'package:gecko/providers/substrate_sdk.dart'; import 'package:gecko/providers/wallet_options.dart'; import 'package:gecko/providers/my_wallets.dart'; import 'package:gecko/models/wallet_data.dart'; @@ -23,11 +24,11 @@ class WalletViewScreen extends StatelessWidget { @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); - WalletsProfilesProvider _historyProvider = + WalletsProfilesProvider _walletViewProvider = Provider.of(context, listen: false); CesiumPlusProvider _cesiumPlusProvider = Provider.of(context, listen: false); - _historyProvider.pubkey = pubkey!; + _walletViewProvider.pubkey = pubkey!; return Scaffold( resizeToAvoidBottomInset: true, @@ -41,7 +42,8 @@ class WalletViewScreen extends StatelessWidget { ), body: SafeArea( child: Column(children: [ - headerProfileView(context, _historyProvider, _cesiumPlusProvider), + headerProfileView( + context, _walletViewProvider, _cesiumPlusProvider), SizedBox(height: isTall ? 120 : 70), Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Column(children: [ @@ -163,7 +165,7 @@ class WalletViewScreen extends StatelessWidget { image: AssetImage('assets/vector_white.png'), )), onTap: () { - paymentPopup(context, _historyProvider); + paymentPopup(context, _walletViewProvider); }), ), ), @@ -183,12 +185,17 @@ class WalletViewScreen extends StatelessWidget { void paymentPopup( BuildContext context, WalletsProfilesProvider _walletViewProvider) { // WalletsProfilesProvider _walletViewProvider = - // Provider.of(context); - const double shapeSize = 20; + // Provider.of(context, listen: false); + MyWalletsProvider _myWalletProvider = Provider.of(context, listen: false); - WalletData? defaultWallet = - _myWalletProvider.getDefaultWallet(configBox.get('currentChest')); + // SubstrateSdk _sub = Provider.of(context, listen: false); + + const double shapeSize = 20; + WalletData? defaultWallet = _myWalletProvider.getDefaultWallet(); + + bool canValidate = false; + _walletViewProvider.outputPubkey.text = pubkey!; showModalBottomSheet( @@ -203,6 +210,15 @@ class WalletViewScreen extends StatelessWidget { builder: (BuildContext context) { return StatefulBuilder( builder: (BuildContext context, StateSetter setState) { + if (_walletViewProvider.payAmount.text != '' && + double.parse(_walletViewProvider.payAmount.text) <= + double.parse( + balanceCache[defaultWallet!.address]!.split(' ')[0]) && + _walletViewProvider.pubkey != defaultWallet.address) { + canValidate = true; + } else { + canValidate = false; + } return Padding( padding: EdgeInsets.only( bottom: MediaQuery.of(context).viewInsets.bottom), @@ -218,7 +234,8 @@ class WalletViewScreen extends StatelessWidget { ), ), child: Padding( - padding: const EdgeInsets.all(24), + padding: const EdgeInsets.only( + top: 24, bottom: 0, left: 24, right: 24), child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, @@ -230,86 +247,169 @@ class WalletViewScreen extends StatelessWidget { ), const SizedBox(height: 20), Text( - 'Saisissez dans le champ ci-dessous le montant à virer.', + 'Depuis:', style: TextStyle( fontSize: 19, fontWeight: FontWeight.w500, color: Colors.grey[600]), ), - const Spacer(), - Center( - child: Column(children: [ - TextField( - controller: _walletViewProvider.payAmount, - autofocus: true, - maxLines: 1, - textAlign: TextAlign.center, - keyboardType: TextInputType.number, - onChanged: (_) => setState(() {}), - inputFormatters: [ - FilteringTextInputFormatter.allow( - RegExp(r'^\d+\.?\d{0,2}')), - ], - // onChanged: (v) => _searchProvider.rebuildWidget(), - decoration: InputDecoration( - hintText: '0.00', - suffix: Text(currencyName), - filled: true, - fillColor: Colors.transparent, + const SizedBox(height: 10), + Consumer(builder: (context, _sub, _) { + return InkWell( + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) { + return UnlockingWallet( + wallet: defaultWallet, + action: "changeWallet"); + }, + ), + ); + }, + child: Container( + width: double.infinity, + // height: 25, + decoration: BoxDecoration( // border: OutlineInputBorder( // borderSide: // BorderSide(color: Colors.grey[500], width: 2), // borderRadius: BorderRadius.circular(8)), - focusedBorder: OutlineInputBorder( - borderSide: BorderSide( - color: Colors.grey[500]!, width: 2), - borderRadius: BorderRadius.circular(8), - ), - contentPadding: const EdgeInsets.all(20), - ), - style: const TextStyle( - fontSize: 40, - color: Colors.black, - fontWeight: FontWeight.w600, + border: Border.all( + color: Colors.blueAccent + .shade200, // Set border color + width: 2), // Set border width + borderRadius: const BorderRadius.all( + Radius.circular(10.0)), // Set ro ), + padding: const EdgeInsets.all(10), + + child: Row(children: [ + Text(defaultWallet!.name!), + const Spacer(), + FutureBuilder( + future: + _sub.getBalance(defaultWallet.address!), + builder: (BuildContext context, + AsyncSnapshot _balance) { + if (_balance.connectionState != + ConnectionState.done || + _balance.hasError) { + if (balanceCache[ + defaultWallet.address!] != + null) { + return Text( + balanceCache[ + defaultWallet.address!]!, + style: const TextStyle( + fontSize: 20, + )); + } else { + return SizedBox( + height: 15, + width: 15, + child: CircularProgressIndicator( + color: orangeC, + strokeWidth: 2, + ), + ); + } + } + balanceCache[defaultWallet.address!] = + "${_balance.data.toString()} $currencyName"; + return Text( + balanceCache[defaultWallet.address!]!, + style: const TextStyle( + fontSize: 20, + ), + ); + }), + ]), ), - const SizedBox(height: 40), - // const Spacer(), - SizedBox( - width: double.infinity, - height: 60, - child: ElevatedButton( - style: ElevatedButton.styleFrom( - elevation: 4, - primary: orangeC, // background - onPrimary: Colors.white, // foreground - ), - onPressed: - _walletViewProvider.payAmount.text != '' - ? () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) { - return UnlockingWallet( - wallet: defaultWallet, - action: "pay"); - }, - ), - ); - } - : null, - child: const Text( - 'Effectuer le virement', - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.w600), - ), - ), - ), - const SizedBox(height: 20), - ]), + ); + }), + const Spacer(), + + // const SizedBox(height: 10), + Text( + 'Montant:', + style: TextStyle( + fontSize: 19, + fontWeight: FontWeight.w500, + color: Colors.grey[600]), ), + const SizedBox(height: 10), + TextField( + controller: _walletViewProvider.payAmount, + autofocus: true, + maxLines: 1, + textAlign: TextAlign.center, + keyboardType: TextInputType.number, + onChanged: (_) => setState(() { + // _walletViewProvider.reload(); + }), + inputFormatters: [ + FilteringTextInputFormatter.allow( + RegExp(r'^\d+\.?\d{0,2}')), + ], + // onChanged: (v) => _searchProvider.rebuildWidget(), + decoration: InputDecoration( + hintText: '0.00', + suffix: Text(currencyName), + filled: true, + fillColor: Colors.transparent, + // border: OutlineInputBorder( + // borderSide: + // BorderSide(color: Colors.grey[500], width: 2), + // borderRadius: BorderRadius.circular(8)), + + focusedBorder: OutlineInputBorder( + borderSide: BorderSide( + color: Colors.grey[500]!, width: 2), + borderRadius: BorderRadius.circular(8), + ), + contentPadding: const EdgeInsets.all(20), + ), + style: const TextStyle( + fontSize: 40, + color: Colors.black, + fontWeight: FontWeight.w600, + ), + ), + // const SizedBox(height: 40), + const Spacer(), + SizedBox( + width: double.infinity, + height: 60, + child: ElevatedButton( + style: ElevatedButton.styleFrom( + elevation: 4, + primary: orangeC, // background + onPrimary: Colors.white, // foreground + ), + onPressed: canValidate + ? () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) { + return UnlockingWallet( + wallet: defaultWallet, + action: "pay"); + }, + ), + ); + } + : null, + child: const Text( + 'Effectuer le virement', + style: TextStyle( + fontSize: 20, fontWeight: FontWeight.w600), + ), + ), + ), + const Spacer(), ]), ), ), diff --git a/pubspec.yaml b/pubspec.yaml index 2a652f6..c0e7a6e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ description: Pay with G1. # pub.dev using `pub publish`. This is preferred for private packages. publish_to: 'none' # Remove this line if you wish to publish to pub.dev -version: 0.0.6+3 +version: 0.0.6+4 environment: sdk: '>=2.12.0 <3.0.0'