From 70bd64bcef1917c4fa8c9f9da4e00b3fabb73b7e Mon Sep 17 00:00:00 2001 From: poka Date: Sat, 9 Jan 2021 10:48:06 +0100 Subject: [PATCH] Improve padding --- lib/parsingGVA.dart | 18 ++++-- lib/ui/generateWallets.dart | 115 ++++++++++++++++++++++++++++++------ lib/ui/historyScreen.dart | 31 +++++++--- 3 files changed, 132 insertions(+), 32 deletions(-) diff --git a/lib/parsingGVA.dart b/lib/parsingGVA.dart index d8821ce..2f29888 100644 --- a/lib/parsingGVA.dart +++ b/lib/parsingGVA.dart @@ -1,6 +1,11 @@ import 'dart:math'; import 'package:intl/intl.dart'; +num removeDecimalZero(double n) { + String result = n.toStringAsFixed(n.truncateToDouble() == n ? 0 : 1); + return num.parse(result); +} + List parseHistory(txs) { var transBC = []; int i = 0; @@ -23,19 +28,20 @@ List parseHistory(txs) { transBC[i].add(date); print( "DEBUG date et comment: ${date.toString()} -- ${transaction['comment'].toString()}"); - var amountBrut = int.parse(output.split(':')[0]); + int amountBrut = int.parse(output.split(':')[0]); final base = int.parse(output.split(':')[1]); - final applyBase = base - currentBase; - final amount = amountBrut * pow(10, applyBase) / 100; - var amountUD = amount / currentUD; + final int applyBase = base - currentBase; + final num amount = removeDecimalZero(amountBrut * pow(10, applyBase) / 100); + num amountUD = amount / currentUD; + int padNbr = 14 - amount.toString().length; if (direction == "RECEIVED") { transBC[i].add(transaction['issuers'][0]); - transBC[i].add(amount); + transBC[i].add(' ' + amount.toString().padRight(padNbr)); transBC[i].add(amountUD.toStringAsFixed(2)); } else if (direction == "SENT") { final outPubkey = output.split("SIG(")[1].replaceAll(')', ''); transBC[i].add(outPubkey); - transBC[i].add(-amount); + transBC[i].add(' -' + amount.toString().padRight(padNbr - 1)); transBC[i].add(amountUD.toStringAsFixed(2)); } transBC[i].add(transaction['comment']); diff --git a/lib/ui/generateWallets.dart b/lib/ui/generateWallets.dart index 47a3073..974a914 100644 --- a/lib/ui/generateWallets.dart +++ b/lib/ui/generateWallets.dart @@ -1,6 +1,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:dubp/dubp.dart'; +import 'package:pin_code_fields/pin_code_fields.dart'; import 'package:sentry/sentry.dart' as sentry; import 'dart:io'; import 'dart:async'; @@ -21,9 +22,15 @@ class _GenerateWalletState extends State { TextEditingController _pubkey = new TextEditingController(); TextEditingController _pin = new TextEditingController(); String generatedMnemonic; + bool walletIsGenerated = false; NewWallet actualWallet; final formKey = GlobalKey(); + bool hasError = false; + String validPin = 'NO PIN'; + String currentText = ""; + var pinColor = Colors.grey[300]; + @override Widget build(BuildContext context) { return SafeArea( @@ -95,23 +102,27 @@ class _GenerateWalletState extends State { alignment: Alignment.bottomCenter, child: new RaisedButton( color: Color(0xffFFD68E), - onPressed: () { - Navigator.push( - context, - MaterialPageRoute(builder: (context) { - return ValidStoreWalletScreen( - generatedMnemonic: this.generatedMnemonic, - generatedWallet: - this.actualWallet); //, this.actualWallet); - }), - ).then((value) => setState(() { - if (value) { - _pin.clear(); - _mnemonicController.clear(); - _pubkey.clear(); - } - })); - }, + onPressed: walletIsGenerated + ? () { + Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return ValidStoreWalletScreen( + generatedMnemonic: this.generatedMnemonic, + generatedWallet: this.actualWallet); + }), + ).then((value) => setState(() { + if (value) { + _pin.clear(); + _mnemonicController.clear(); + _pubkey.clear(); + this.generatedMnemonic = null; + this.actualWallet = null; + this.walletIsGenerated = false; + } + })); + } + : null, child: Text('Enregistrer ce wallet', style: TextStyle(fontSize: 20))))), SizedBox(height: 15) @@ -132,6 +143,7 @@ class _GenerateWalletState extends State { } } this.actualWallet = await generateWallet(this.generatedMnemonic); + this.walletIsGenerated = true; return this.generatedMnemonic; } @@ -215,6 +227,75 @@ class _ValidStoreWalletScreen extends State { color: Color(0xffFFD68E), onPressed: () => storeWallet(widget.generatedWallet), child: Text('Confirmer', style: TextStyle(fontSize: 20))), + // Form( + // child: Padding( + // padding: + // const EdgeInsets.symmetric(vertical: 8.0, horizontal: 30), + // child: PinCodeTextField( + // appContext: context, + // pastedTextStyle: TextStyle( + // color: Colors.green.shade600, + // fontWeight: FontWeight.bold, + // ), + // length: 6, + // obscureText: false, + // obscuringCharacter: '*', + // animationType: AnimationType.fade, + // validator: (v) { + // if (v.length < 6) { + // return "Votre code PIN fait 6 caractères"; + // } else { + // return null; + // } + // }, + // pinTheme: PinTheme( + // shape: PinCodeFieldShape.box, + // borderRadius: BorderRadius.circular(5), + // fieldHeight: 60, + // fieldWidth: 50, + // activeFillColor: hasError ? Colors.orange : Colors.white, + // ), + // cursorColor: Colors.black, + // animationDuration: Duration(milliseconds: 300), + // textStyle: TextStyle(fontSize: 20, height: 1.6), + // backgroundColor: pinColor, + // enableActiveFill: false, + // errorAnimationController: errorController, + // controller: _enterPin, + // keyboardType: TextInputType.text, + // boxShadows: [ + // BoxShadow( + // offset: Offset(0, 1), + // color: Colors.black12, + // blurRadius: 10, + // ) + // ], + // onCompleted: (v) async { + // print("Completed"); + // final resultWallet = await readLocalWallet(v.toUpperCase()); + // if (resultWallet == 'bad') { + // errorController.add(ErrorAnimationType + // .shake); // Triggering error shake animation + // setState(() { + // hasError = true; + // pinColor = Colors.red[200]; + // }); + // } else { + // setState(() { + // pinColor = Colors.green[200]; + // }); + // } + // }, + // onChanged: (value) { + // if (pinColor != Colors.grey[300]) { + // setState(() { + // pinColor = Colors.grey[300]; + // }); + // } + // print(value); + // }, + // )), + // ) ]), ), ); diff --git a/lib/ui/historyScreen.dart b/lib/ui/historyScreen.dart index 7569a6f..181e13f 100644 --- a/lib/ui/historyScreen.dart +++ b/lib/ui/historyScreen.dart @@ -77,7 +77,7 @@ class HistoryScreenState extends State { textAlign: TextAlign.center, decoration: InputDecoration( hintText: 'Tappez/Collez une clé publique, ou scannez', - hintStyle: TextStyle(fontSize: 15), + hintStyle: TextStyle(fontSize: 14), contentPadding: EdgeInsets.symmetric(horizontal: 7, vertical: 15), border: InputBorder.none, focusedBorder: InputBorder.none, @@ -85,7 +85,7 @@ class HistoryScreenState extends State { errorBorder: InputBorder.none, disabledBorder: InputBorder.none, ), - style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold)), + style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)), historyQuery(), ]); } @@ -129,7 +129,8 @@ class HistoryScreenState extends State { final String fetchMoreCursor = pageInfo['endCursor']; - final num balance = result.data['balance']['amount'] / 100; + final num balance = + removeDecimalZero(result.data['balance']['amount'] / 100); FetchMoreOptions opts = FetchMoreOptions( variables: {'cursor': fetchMoreCursor}, @@ -181,19 +182,26 @@ class HistoryScreenState extends State { child: ListView( controller: _scrollController, children: [ + SizedBox(height: 7), if (this.pubkey != '') Text(balance.toString() + ' Ğ1', textAlign: TextAlign.center, style: TextStyle(fontSize: 30.0)), + SizedBox(height: 12), for (var repository in _transBC) ListTile( contentPadding: const EdgeInsets.all(5.0), - leading: Text(repository[3].toString()), - title: Text(repository[1].toString() + - '\n' + - truncate(repository[2], 17, - omission: "...", position: TruncatePosition.end)), - subtitle: Text(repository[5]), + leading: + Text(repository[3], style: TextStyle(fontSize: 14.0)), + title: Text( + repository[1].toString() + + '\n' + + truncate(repository[2], 17, + omission: "...", + position: TruncatePosition.end), + style: TextStyle(fontSize: 14.0)), + subtitle: + Text(repository[5], style: TextStyle(fontSize: 14.0)), dense: true, onTap: () { isPubkey(repository[2]); @@ -264,4 +272,9 @@ class HistoryScreenState extends State { return ''; } + + num removeDecimalZero(double n) { + String result = n.toStringAsFixed(n.truncateToDouble() == n ? 0 : 1); + return num.parse(result); + } }