From 25515905ec9a6df9cfa2d0cdfaf5b5e77d518293 Mon Sep 17 00:00:00 2001 From: poka Date: Mon, 14 Dec 2020 11:04:13 +0100 Subject: [PATCH] Improve history view --- lib/api.dart | 11 +++++++++-- lib/main.dart | 31 ++++++++++++++++++++----------- pubspec.lock | 7 +++++++ pubspec.yaml | 1 + scripts/build-apk.sh | 4 ++++ 5 files changed, 41 insertions(+), 13 deletions(-) create mode 100755 scripts/build-apk.sh diff --git a/lib/api.dart b/lib/api.dart index 0ac3d24..aaa0a89 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -57,7 +57,7 @@ Future getBalance(String pubkey) async { Future getHistory(String pubkey) async { print(pubkey); var query = """{ - transactionsHistory(pubkey: "$pubkey") { + txsHistoryBc(pubkeyOrScript: "$pubkey") { received { writtenTime issuers @@ -74,7 +74,14 @@ Future getHistory(String pubkey) async { final res = await buildQ(query); // Parse history - var result = res.data["transactionsHistory"]["received"]; + var result; + try { + result = res.data["txsHistoryBc"]["received"]; + } catch (e) { + print("DEBUG: " + e.toString()); + print(res.data); + return false; + } var i = 0; // String outPubkey; var trans = []; diff --git a/lib/main.dart b/lib/main.dart index 35167c1..ce75049 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,6 +5,8 @@ import 'package:flutter/material.dart'; // import 'package:image_gallery_saver/image_gallery_saver.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:qrscan/qrscan.dart' as scanner; +import 'package:intl/intl.dart'; +// import 'package:flutter_html_view'; import 'api.dart'; void main() { @@ -59,6 +61,7 @@ class _MyAppState extends State { enabled: false, controller: this._outputPubkey, maxLines: 1, + textAlign: TextAlign.center, decoration: InputDecoration( hintText: 'Clé publique scanné', hintStyle: TextStyle(fontSize: 15), @@ -81,7 +84,7 @@ class _MyAppState extends State { horizontal: 7, vertical: 15), ), style: - TextStyle(fontSize: 18.0, color: Colors.black)), + TextStyle(fontSize: 30.0, color: Colors.black)), TextField( enabled: false, controller: this._outputHistory, @@ -95,7 +98,7 @@ class _MyAppState extends State { horizontal: 7, vertical: 15), ), style: TextStyle( - fontSize: 14.0, + fontSize: 13.0, height: 1.5, color: Colors.black)), SizedBox(height: 20), @@ -171,27 +174,33 @@ class _MyAppState extends State { this._outputBalance.text = ""; this._outputHistory.text = ""; // final udValue = await getUD(); - final myBalance = await getBalance(barcode.toString()); - final myHistory = await getHistory(barcode.toString()); this._outputPubkey.text = barcode; - this._outputBalance.text = myBalance.toString() + " Ḡ1"; + final myBalance = await getBalance(barcode.toString()); + this._outputBalance.text = myBalance.toString() + " Ğ1"; + + final myHistory = await getHistory(barcode.toString()); + if (myHistory == false) { + return false; + } String historyBloc = ""; var j = 0; for (var i in myHistory) { - print(i); - var date = i[0]; - date = DateTime.fromMillisecondsSinceEpoch(date * 1000); + // print(i); + var dateBrut = i[0]; + dateBrut = DateTime.fromMillisecondsSinceEpoch(dateBrut * 1000); + final DateFormat formatter = DateFormat('dd-MM-yy - H:M'); + final String date = formatter.format(dateBrut); final issuer = i[1]; final amount = i[2]; // final amountUD = i[3]; final comment = i[4]; historyBloc += date.toString() + - " | " + + " \n " + issuer.toString() + - " | " + + " \n " + amount.toString() + - " | " + + " Ğ1\n " + comment.toString() + "\n---\n"; j++; diff --git a/pubspec.lock b/pubspec.lock index f06ab37..3b954c7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -144,6 +144,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.1" + intl: + dependency: "direct main" + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.16.1" matcher: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index c74d6a6..6a1b3ca 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -31,6 +31,7 @@ dependencies: gql_dio_link: gql_exec: gql_link: + intl: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. diff --git a/scripts/build-apk.sh b/scripts/build-apk.sh new file mode 100755 index 0000000..df291f0 --- /dev/null +++ b/scripts/build-apk.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +flutter build apk --split-per-abi +