From 399d0cab8b85ebdb904cb1c1947335b7e0e998b2 Mon Sep 17 00:00:00 2001
From: Matthew Fosse <matt@fosse.co>
Date: Fri, 19 Jul 2024 00:06:23 -0700
Subject: [PATCH] coin control edge cases

---
 cw_bitcoin/lib/electrum_wallet.dart | 2 +-
 cw_bitcoin/lib/litecoin_wallet.dart | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart
index 38fded49e..276d192b9 100644
--- a/cw_bitcoin/lib/electrum_wallet.dart
+++ b/cw_bitcoin/lib/electrum_wallet.dart
@@ -1168,7 +1168,7 @@ abstract class ElectrumWalletBase
   Future<void> updateUnspent() async {
     await updateAllUnspents();
 
-    if (unspentCoinsInfo.isEmpty) {
+    if (unspentCoinsInfo.length != unspentCoins.length) {
       unspentCoins.forEach((coin) => addCoinInfo(coin));
       return;
     }
diff --git a/cw_bitcoin/lib/litecoin_wallet.dart b/cw_bitcoin/lib/litecoin_wallet.dart
index 22fb8ebc7..684562eaf 100644
--- a/cw_bitcoin/lib/litecoin_wallet.dart
+++ b/cw_bitcoin/lib/litecoin_wallet.dart
@@ -205,6 +205,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
       }
     });
     processMwebUtxos();
+    updateUnspent();
   }
 
   @action
@@ -514,6 +515,12 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
       });
     }
 
+    print(unspentCoins);
+    print(updatedUnspentCoins);
+    print(updatedUnspentCoins.length);
+
+    // print(updatedUnspentCoins[2].address);
+
     unspentCoins = updatedUnspentCoins;
   }
 
@@ -575,6 +582,8 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
       }
     }
 
+    await updateUnspent();
+
     return ElectrumBalance(confirmed: confirmed, unconfirmed: unconfirmed, frozen: balance.frozen);
   }