From c279066a5aaad8f28317038cdcb639581ac733f9 Mon Sep 17 00:00:00 2001
From: poka <poka@p2p.legal>
Date: Wed, 3 Feb 2021 18:45:08 +0100
Subject: [PATCH] Fix transaction amount parsing for multi-receivers

---
 lib/models/history.dart  | 18 ++++++++++++++----
 lib/screens/history.dart |  3 ++-
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/lib/models/history.dart b/lib/models/history.dart
index 59cb1268..9442e6bd 100644
--- a/lib/models/history.dart
+++ b/lib/models/history.dart
@@ -63,7 +63,9 @@ class HistoryProvider with ChangeNotifier {
     return '';
   }
 
-  List parseHistory(txs) {
+// Boris: JE6mkuzSpT3ePciCPRTpuMT9fqPUVVLJz2618d33p7tn
+
+  List parseHistory(txs, _pubkey) {
     var transBC = [];
     int i = 0;
 
@@ -73,7 +75,15 @@ class HistoryProvider with ChangeNotifier {
     for (final trans in txs) {
       var direction = trans['direction'];
       final transaction = trans['node'];
-      var output = transaction['outputs'][0];
+      var output;
+      for (String line in transaction['outputs']) {
+        if (line.contains(_pubkey)) {
+          output = line;
+        }
+      }
+      if (output == null) {
+        continue;
+      }
 
       transBC.add(i);
       transBC[i] = [];
@@ -108,7 +118,7 @@ class HistoryProvider with ChangeNotifier {
     return transBC;
   }
 
-  FetchMoreOptions checkQueryResult(result, opts) {
+  FetchMoreOptions checkQueryResult(result, opts, _pubkey) {
     final List<dynamic> blockchainTX =
         (result.data['txsHistoryBc']['both']['edges'] as List<dynamic>);
 
@@ -136,7 +146,7 @@ class HistoryProvider with ChangeNotifier {
     print(
         "###### DEBUG H Parse blockchainTX list. Cursor: $fetchMoreCursor ######");
     if (fetchMoreCursor != null) {
-      transBC = parseHistory(blockchainTX);
+      transBC = parseHistory(blockchainTX, _pubkey);
       isTheEnd = false;
     } else {
       print("###### DEBUG H - Début de l'historique");
diff --git a/lib/screens/history.dart b/lib/screens/history.dart
index aca33f3f..92ad765e 100644
--- a/lib/screens/history.dart
+++ b/lib/screens/history.dart
@@ -126,7 +126,8 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
             final num balance = _historyProvider
                 .removeDecimalZero(result.data['balance']['amount'] / 100);
 
-            opts = _historyProvider.checkQueryResult(result, opts);
+            opts = _historyProvider.checkQueryResult(
+                result, opts, _outputPubkey.text);
 
             // Build history list
             // _cesiumPlusProvider.cesiumName.text = "NAMEE";
-- 
GitLab