From c29bdb9423aabebc3368d8cb7748805f7a773e92 Mon Sep 17 00:00:00 2001
From: julian <julian@cypherstack.com>
Date: Tue, 17 Oct 2023 15:26:03 -0600
Subject: [PATCH] add extra check to prevent full failure in case of server
 indexing issue

---
 .../ethereum/ethereum_token_service.dart      | 27 +++++++++++++------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/lib/services/ethereum/ethereum_token_service.dart b/lib/services/ethereum/ethereum_token_service.dart
index a42867485..239d8770e 100644
--- a/lib/services/ethereum/ethereum_token_service.dart
+++ b/lib/services/ethereum/ethereum_token_service.dart
@@ -468,7 +468,7 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
     }
 
     final response2 = await EthereumAPI.getEthTokenTransactionsByTxids(
-      response.value!.map((e) => e.transactionHash).toList(),
+      response.value!.map((e) => e.transactionHash).toSet().toList(),
     );
 
     if (response2.value == null) {
@@ -477,14 +477,25 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
     }
     final List<Tuple2<EthTokenTxDto, EthTokenTxExtraDTO>> data = [];
     for (final tokenDto in response.value!) {
-      data.add(
-        Tuple2(
-          tokenDto,
-          response2.value!.firstWhere(
-            (e) => e.hash == tokenDto.transactionHash,
+      try {
+        final txExtra = response2.value!.firstWhere(
+          (e) => e.hash == tokenDto.transactionHash,
+        );
+        data.add(
+          Tuple2(
+            tokenDto,
+            txExtra,
           ),
-        ),
-      );
+        );
+      } catch (_) {
+        // Server indexing failed for some reason. Instead of hard crashing or
+        // showing no transactions we just skip it here. Not ideal but better
+        // than nothing showing up
+        Logging.instance.log(
+          "Server error: Transaction ${tokenDto.transactionHash} not found.",
+          level: LogLevel.Error,
+        );
+      }
     }
 
     final List<Tuple2<Transaction, Address?>> txnsData = [];