Implement new payment view

This commit is contained in:
poka 2021-12-03 10:25:36 +01:00
parent d4e715e01a
commit 819d5a4b9b
9 changed files with 178 additions and 24 deletions

View File

@ -29,14 +29,12 @@ const String getHistory = r'''
issuers
comment
outputs
writtenTime
}
sending {
currency
issuers
comment
outputs
writtenTime
}
}
currentUd {

View File

@ -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<List> 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;
}
}

View File

@ -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<dynamic> blockchainTX =
(result.data['txsHistoryBc']['both']['edges'] as List<dynamic>);
// final List<dynamic> mempoolTX =
// (result.data['txsHistoryMp']['receiving'] as List<dynamic>);
pageInfo = result.data['txsHistoryBc']['both']['pageInfo'];
fetchMoreCursor = pageInfo['endCursor'];

View File

@ -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<StatefulWidget> createState() {
@ -29,6 +30,8 @@ class _ChooseChestState extends State<ChooseChest> {
MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context);
log.d(widget.action);
return Scaffold(
appBar: AppBar(
toolbarHeight: 60 * ratio,
@ -118,7 +121,7 @@ class _ChooseChestState extends State<ChooseChest> {
MaterialPageRoute(builder: (context) {
return UnlockingWallet(
wallet: defaultWallet,
action: "mywallets",
action: widget.action ?? "mywallets",
);
}),
ModalRoute.withName('/'),

View File

@ -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<bool> _paymentsResult(context) {
if (resultPay != "Success") log.i(resultPay);
return showDialog<bool>(
context: context,
barrierDismissible: true, // user must tap button!

View File

@ -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,

View File

@ -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)

View File

@ -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<CesiumPlusProvider>(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<WalletsProfilesProvider>(context);
const double shapeSize = 20;
MyWalletsProvider _myWalletProvider = MyWalletsProvider();
WalletData defaultWallet =
_myWalletProvider.getDefaultWallet(configBox.get('currentChest'));
showModalBottomSheet<void>(
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: <Widget>[
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: <Widget>[
TextField(
controller: _walletViewProvider.payAmount,
autofocus: true,
maxLines: 1,
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
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,

View File

@ -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"