From 5c6ef41511d51cccae9acd184dd1a9bb7f043753 Mon Sep 17 00:00:00 2001
From: woodser <woodser@protonmail.com>
Date: Mon, 10 Jul 2023 16:23:23 -0400
Subject: [PATCH] process unposted offers after app bootstrapped

---
 .../haveno/core/offer/OpenOfferManager.java   | 64 +++++++++----------
 1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/core/src/main/java/haveno/core/offer/OpenOfferManager.java b/core/src/main/java/haveno/core/offer/OpenOfferManager.java
index 29f0cbb7..1af60a41 100644
--- a/core/src/main/java/haveno/core/offer/OpenOfferManager.java
+++ b/core/src/main/java/haveno/core/offer/OpenOfferManager.java
@@ -287,38 +287,6 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
         }
 
         cleanUpAddressEntries();
-
-        // TODO: add to invalid offers on failure
-//        openOffers.stream()
-//                .forEach(openOffer -> OfferUtil.getInvalidMakerFeeTxErrorMessage(openOffer.getOffer(), btcWalletService)
-//                        .ifPresent(errorMsg -> invalidOffers.add(new Tuple2<>(openOffer, errorMsg))));
-
-        // process unposted offers
-        processUnpostedOffers((transaction) -> {}, (errorMessage) -> {
-            log.warn("Error processing unposted offers: " + errorMessage);
-        });
-
-        // register to process unposted offers when unlocked balance increases
-        if (xmrWalletService.getWallet() != null) lastUnlockedBalance = xmrWalletService.getWallet().getUnlockedBalance(0);
-        xmrWalletService.addWalletListener(new MoneroWalletListener() {
-            @Override
-            public void onBalancesChanged(BigInteger newBalance, BigInteger newUnlockedBalance) {
-                if (lastUnlockedBalance == null || lastUnlockedBalance.compareTo(newUnlockedBalance) < 0) {
-                    processUnpostedOffers((transaction) -> {}, (errorMessage) -> {
-                        log.warn("Error processing unposted offers on new unlocked balance: " + errorMessage); // TODO: popup to notify user that offer did not post
-                    });
-                }
-                lastUnlockedBalance = newUnlockedBalance;
-            }
-        });
-
-        // initialize key image poller for signed offers
-        maybeInitializeKeyImagePoller();
-
-        // poll spent status of key images
-        for (SignedOffer signedOffer : signedOffers.getList()) {
-            signedOfferKeyImagePoller.addKeyImages(signedOffer.getReserveTxKeyImages());
-        }
     }
 
     private void cleanUpAddressEntries() {
@@ -449,6 +417,38 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
                     REPUBLISH_AGAIN_AT_STARTUP_DELAY_SEC);
 
         p2PService.getPeerManager().addListener(this);
+
+        // TODO: add to invalid offers on failure
+//        openOffers.stream()
+//                .forEach(openOffer -> OfferUtil.getInvalidMakerFeeTxErrorMessage(openOffer.getOffer(), btcWalletService)
+//                        .ifPresent(errorMsg -> invalidOffers.add(new Tuple2<>(openOffer, errorMsg))));
+
+        // process unposted offers
+        processUnpostedOffers((transaction) -> {}, (errorMessage) -> {
+            log.warn("Error processing unposted offers: " + errorMessage);
+        });
+
+        // register to process unposted offers when unlocked balance increases
+        if (xmrWalletService.getWallet() != null) lastUnlockedBalance = xmrWalletService.getWallet().getUnlockedBalance(0);
+        xmrWalletService.addWalletListener(new MoneroWalletListener() {
+            @Override
+            public void onBalancesChanged(BigInteger newBalance, BigInteger newUnlockedBalance) {
+                if (lastUnlockedBalance == null || lastUnlockedBalance.compareTo(newUnlockedBalance) < 0) {
+                    processUnpostedOffers((transaction) -> {}, (errorMessage) -> {
+                        log.warn("Error processing unposted offers on new unlocked balance: " + errorMessage); // TODO: popup to notify user that offer did not post
+                    });
+                }
+                lastUnlockedBalance = newUnlockedBalance;
+            }
+        });
+
+        // initialize key image poller for signed offers
+        maybeInitializeKeyImagePoller();
+
+        // poll spent status of key images
+        for (SignedOffer signedOffer : signedOffers.getList()) {
+            signedOfferKeyImagePoller.addKeyImages(signedOffer.getReserveTxKeyImages());
+        }
     }