From 819d5a4b9b3ec33de6c980383e4b3a15ee0d59ba Mon Sep 17 00:00:00 2001 From: poka Date: Fri, 3 Dec 2021 10:25:36 +0100 Subject: [PATCH] Implement new payment view --- lib/models/queries.dart | 2 - lib/models/search.dart | 7 ++ lib/models/wallets_profiles.dart | 15 ++- lib/screens/myWallets/choose_chest.dart | 7 +- lib/screens/myWallets/unlocking_wallet.dart | 16 ++- lib/screens/old_history_pay.dart | 16 +-- lib/screens/search_result.dart | 4 +- lib/screens/wallet_view.dart | 133 +++++++++++++++++++- pubspec.yaml | 2 +- 9 files changed, 178 insertions(+), 24 deletions(-) diff --git a/lib/models/queries.dart b/lib/models/queries.dart index 85b4c42..ed47ac8 100644 --- a/lib/models/queries.dart +++ b/lib/models/queries.dart @@ -29,14 +29,12 @@ const String getHistory = r''' issuers comment outputs - writtenTime } sending { currency issuers comment outputs - writtenTime } } currentUd { diff --git a/lib/models/search.dart b/lib/models/search.dart index 6c4f7b3..5fdbb61 100644 --- a/lib/models/search.dart +++ b/lib/models/search.dart @@ -3,6 +3,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:gecko/globals.dart'; import 'package:gecko/models/g1_wallets_list.dart'; +import 'package:gecko/models/wallets_profiles.dart'; class SearchProvider with ChangeNotifier { TextEditingController searchController = TextEditingController(); @@ -17,6 +18,7 @@ class SearchProvider with ChangeNotifier { Future searchBlockchain() async { searchResult.clear(); int searchTime = DateTime.now().millisecondsSinceEpoch; + WalletsProfilesProvider _walletProfiles = WalletsProfilesProvider('pubkey'); if (cacheTime + cacheDuring <= searchTime) { g1WalletsBox.clear(); @@ -60,6 +62,11 @@ class SearchProvider with ChangeNotifier { } }); + if (searchResult.isEmpty && + _walletProfiles.isPubkey(searchController.text)) { + searchResult = [G1WalletsList(pubkey: searchController.text)]; + } + return searchResult; } } diff --git a/lib/models/wallets_profiles.dart b/lib/models/wallets_profiles.dart index 5fb6901..bb13f7c 100644 --- a/lib/models/wallets_profiles.dart +++ b/lib/models/wallets_profiles.dart @@ -42,7 +42,7 @@ class WalletsProfilesProvider with ChangeNotifier { log.e(e); return 'false'; } - if (barcode != null && isPubkey(context, barcode)) { + if (barcode != null && isPubkey(barcode)) { outputPubkey.text = barcode; Navigator.push( context, @@ -62,10 +62,17 @@ class WalletsProfilesProvider with ChangeNotifier { WalletData defaultWallet = _myWalletModel.getDefaultWallet(currentChest); String dewif = chestBox.get(currentChest).dewif; + int derivation; + + if (chestBox.get(currentChest).isCesium) { + derivation = 0; + } else { + derivation = defaultWallet.derivation; + } try { await DubpRust.simplePaymentFromTransparentAccount( - accountIndex: defaultWallet.derivation, + accountIndex: derivation, amount: double.parse(payAmount.text), txComment: payComment.text, dewif: dewif, @@ -80,7 +87,7 @@ class WalletsProfilesProvider with ChangeNotifier { } } - bool isPubkey(context, pubkey) { + bool isPubkey(pubkey) { final RegExp regExp = RegExp( r'^[a-zA-Z0-9]+$', caseSensitive: false, @@ -193,6 +200,8 @@ class WalletsProfilesProvider with ChangeNotifier { FetchMoreOptions checkQueryResult(result, opts, _pubkey) { final List blockchainTX = (result.data['txsHistoryBc']['both']['edges'] as List); + // final List mempoolTX = + // (result.data['txsHistoryMp']['receiving'] as List); pageInfo = result.data['txsHistoryBc']['both']['pageInfo']; fetchMoreCursor = pageInfo['endCursor']; diff --git a/lib/screens/myWallets/choose_chest.dart b/lib/screens/myWallets/choose_chest.dart index aafb524..7179903 100644 --- a/lib/screens/myWallets/choose_chest.dart +++ b/lib/screens/myWallets/choose_chest.dart @@ -9,7 +9,8 @@ import 'package:carousel_slider/carousel_slider.dart'; import 'package:provider/provider.dart'; class ChooseChest extends StatefulWidget { - const ChooseChest({Key key}) : super(key: key); + const ChooseChest({this.action, Key key}) : super(key: key); + final String action; @override State createState() { @@ -29,6 +30,8 @@ class _ChooseChestState extends State { MyWalletsProvider _myWalletProvider = Provider.of(context); + log.d(widget.action); + return Scaffold( appBar: AppBar( toolbarHeight: 60 * ratio, @@ -118,7 +121,7 @@ class _ChooseChestState extends State { MaterialPageRoute(builder: (context) { return UnlockingWallet( wallet: defaultWallet, - action: "mywallets", + action: widget.action ?? "mywallets", ); }), ModalRoute.withName('/'), diff --git a/lib/screens/myWallets/unlocking_wallet.dart b/lib/screens/myWallets/unlocking_wallet.dart index 98da502..77701af 100644 --- a/lib/screens/myWallets/unlocking_wallet.dart +++ b/lib/screens/myWallets/unlocking_wallet.dart @@ -95,7 +95,7 @@ class UnlockingWallet extends StatelessWidget { Navigator.push( context, MaterialPageRoute(builder: (context) { - return const ChooseChest(); + return ChooseChest(action: action); }), ); }, @@ -103,11 +103,14 @@ class UnlockingWallet extends StatelessWidget { width: 400, height: 70, child: Center( - child: Text('Changer de coffre', - style: TextStyle( - fontSize: 22, - color: orangeC, - fontWeight: FontWeight.w600))), + child: Text( + 'Changer de coffre', + style: TextStyle( + fontSize: 22, + color: orangeC, + fontWeight: FontWeight.w600), + ), + ), )), ]), ), @@ -222,6 +225,7 @@ class UnlockingWallet extends StatelessWidget { } Future _paymentsResult(context) { + if (resultPay != "Success") log.i(resultPay); return showDialog( context: context, barrierDismissible: true, // user must tap button! diff --git a/lib/screens/old_history_pay.dart b/lib/screens/old_history_pay.dart index b7f0dab..12571bf 100644 --- a/lib/screens/old_history_pay.dart +++ b/lib/screens/old_history_pay.dart @@ -63,7 +63,7 @@ class OldHistoryScreen extends StatelessWidget with ChangeNotifier { controller: _homeProvider.searchQuery, onChanged: (text) { log.d("Clé tappé: $text"); - if (_historyProvider.isPubkey(context, text)) { + if (_historyProvider.isPubkey(text)) { _homeProvider.currentIndex = 0; Navigator.push( context, @@ -390,11 +390,13 @@ class OldHistoryScreen extends StatelessWidget with ChangeNotifier { // _formKey.currentState.save(); // } // _historyProvider.pay(payAmount.text, payComment.text); - Navigator.push(context, - MaterialPageRoute(builder: (context) { - return UnlockingWallet( - wallet: defaultWallet, action: "pay"); - })); + Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return UnlockingWallet( + wallet: defaultWallet, action: "pay"); + }), + ); }, child: Padding( padding: const EdgeInsets.all(12), @@ -447,7 +449,7 @@ class OldHistoryScreen extends StatelessWidget with ChangeNotifier { dense: true, isThreeLine: false, onTap: () { - if (_historyProvider.isPubkey(context, repository[2])) { + if (_historyProvider.isPubkey(repository[2])) { _homeProvider.currentIndex = 0; Navigator.push( context, diff --git a/lib/screens/search_result.dart b/lib/screens/search_result.dart index 01d2efd..bcaa6c0 100644 --- a/lib/screens/search_result.dart +++ b/lib/screens/search_result.dart @@ -77,7 +77,7 @@ class SearchResultScreen extends StatelessWidget { contentPadding: const EdgeInsets.all(5), leading: g1WalletsBox .get(g1Wallet.pubkey) - .avatar != + ?.avatar != null ? ClipOval( child: g1WalletsBox @@ -150,7 +150,7 @@ class SearchResultScreen extends StatelessWidget { pubkey: g1Wallet.pubkey, username: g1WalletsBox .get(g1Wallet.pubkey) - .id + ?.id ?.username, avatar: g1WalletsBox .get(g1Wallet.pubkey) diff --git a/lib/screens/wallet_view.dart b/lib/screens/wallet_view.dart index 0c20e75..c765b64 100644 --- a/lib/screens/wallet_view.dart +++ b/lib/screens/wallet_view.dart @@ -3,11 +3,14 @@ import 'package:flutter/services.dart'; import 'package:gecko/globals.dart'; import 'package:flutter/material.dart'; import 'package:gecko/models/cesium_plus.dart'; +import 'package:gecko/models/my_wallets.dart'; +import 'package:gecko/models/wallet_data.dart'; import 'package:gecko/models/wallets_profiles.dart'; import 'package:gecko/models/queries.dart'; import 'package:gecko/screens/avatar_fullscreen.dart'; import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/history.dart'; +import 'package:gecko/screens/myWallets/unlocking_wallet.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:provider/provider.dart'; @@ -30,6 +33,7 @@ class WalletViewScreen extends StatelessWidget { Provider.of(context, listen: false); return Scaffold( + resizeToAvoidBottomInset: true, appBar: AppBar( elevation: 0, toolbarHeight: 60 * ratio, @@ -160,7 +164,7 @@ class WalletViewScreen extends StatelessWidget { image: AssetImage('assets/vector_white.png'), )), onTap: () { - null; + paymentPopup(context, _historyProvider); }), ), ), @@ -177,6 +181,133 @@ class WalletViewScreen extends StatelessWidget { )); } + void paymentPopup( + BuildContext context, WalletsProfilesProvider _walletViewProvider) { + // WalletsProfilesProvider _walletViewProvider = + // Provider.of(context); + const double shapeSize = 20; + MyWalletsProvider _myWalletProvider = MyWalletsProvider(); + WalletData defaultWallet = + _myWalletProvider.getDefaultWallet(configBox.get('currentChest')); + + showModalBottomSheet( + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.only( + topRight: Radius.circular(shapeSize), + topLeft: Radius.circular(shapeSize), + ), + ), + isScrollControlled: true, + context: context, + builder: (BuildContext context) { + return Padding( + padding: EdgeInsets.only( + bottom: MediaQuery.of(context).viewInsets.bottom), + child: Container( + height: 400, + decoration: const ShapeDecoration( + color: Color(0xffffeed1), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.only( + topRight: Radius.circular(shapeSize), + topLeft: Radius.circular(shapeSize), + ), + ), + ), + child: Padding( + padding: const EdgeInsets.all(24), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + 'Effectuer un virement', + style: TextStyle( + fontSize: 26, fontWeight: FontWeight.w700), + ), + const SizedBox(height: 20), + Text( + 'Saisissez dans le champ ci-dessous le montant à virer de ... vers ...', + 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, + inputFormatters: [ + FilteringTextInputFormatter.allow( + RegExp(r'^\d+\.?\d{0,2}')), + ], + // onChanged: (v) => _searchProvider.rebuildWidget(), + decoration: InputDecoration( + hintText: '0.00', + suffix: const Text('DU/Ğ1'), + 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: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) { + return UnlockingWallet( + wallet: defaultWallet, action: "pay"); + }, + ), + ); + }, + child: const Text( + 'Effectuer le virement', + style: TextStyle( + fontSize: 20, fontWeight: FontWeight.w600), + ), + ), + ), + const SizedBox(height: 20), + ]), + ), + ]), + ), + ), + ); + }).then((value) => _walletViewProvider.payAmount.text = ''); + } + Widget headerProfileView( BuildContext context, WalletsProfilesProvider _historyProvider, diff --git a/pubspec.yaml b/pubspec.yaml index fdcfd77..b5124f7 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.3+12 +version: 0.0.3+13 environment: sdk: ">=2.7.0 <3.0.0"