From c55fb927f21063558b14189b493d81ceab8ea309 Mon Sep 17 00:00:00 2001
From: woodser <woodser@protonmail.com>
Date: Fri, 29 Dec 2023 15:28:46 -0500
Subject: [PATCH] rely on trade state to delete wallet

---
 .../main/java/haveno/core/trade/Trade.java    | 20 ++++---------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/core/src/main/java/haveno/core/trade/Trade.java b/core/src/main/java/haveno/core/trade/Trade.java
index c410e956d8..35358b4a23 100644
--- a/core/src/main/java/haveno/core/trade/Trade.java
+++ b/core/src/main/java/haveno/core/trade/Trade.java
@@ -890,26 +890,14 @@ public abstract class Trade implements Tradable, Model {
         synchronized (walletLock) {
             if (walletExists()) {
                 try {
-                    
-                    // check if synced
-                    if (!isSyncedWithinTolerance()) {
-                        log.warn("Refusing to delete wallet for {} {} because it is not synced within tolerance", getClass().getSimpleName(), getId());
-                        return;
-                    }
 
-                    // check if balance > 0
-                    if (wallet.getBalance().compareTo(BigInteger.ZERO) > 0) {
-                        log.warn("Refusing to delete wallet for {} {} because it contains a balance", getClass().getSimpleName(), getId());
-                        return;
-                    }
-
-                    // check if funds deposited but payout not unlocked
+                    // check if deposits published and payout not unlocked
                     if (isDepositsPublished() && !isPayoutUnlocked()) {
                         throw new RuntimeException("Refusing to delete wallet for " + getClass().getSimpleName() + " " + getId() + " because the deposit txs have been published but payout tx has not unlocked");
                     }
 
                     // force stop the wallet
-                    stopWallet();
+                    if (wallet != null) stopWallet();
 
                     // delete wallet
                     log.info("Deleting wallet for {} {}", getClass().getSimpleName(), getId());
@@ -918,9 +906,9 @@ public abstract class Trade implements Tradable, Model {
                     // delete trade wallet backups unless deposits requested and payouts not unlocked
                     if (isDepositRequested() && !isDepositFailed() && !isPayoutUnlocked()) {
                         log.warn("Refusing to delete backup wallet for " + getClass().getSimpleName() + " " + getId() + " in the small chance it becomes funded");
-                        return;
+                    } else {
+                        xmrWalletService.deleteWalletBackups(getWalletName());
                     }
-                    xmrWalletService.deleteWalletBackups(getWalletName());
                 } catch (Exception e) {
                     log.warn(e.getMessage());
                     e.printStackTrace();