diff --git a/core/src/main/java/bisq/core/btc/wallet/BsqWalletService.java b/core/src/main/java/bisq/core/btc/wallet/BsqWalletService.java index b8ccad5aba0..aec48649658 100644 --- a/core/src/main/java/bisq/core/btc/wallet/BsqWalletService.java +++ b/core/src/main/java/bisq/core/btc/wallet/BsqWalletService.java @@ -82,11 +82,13 @@ @Slf4j public class BsqWalletService extends WalletService implements DaoStateListener { + public interface WalletTransactionsChangeListener { void onWalletTransactionsChange(); } + private final DaoKillSwitch daoKillSwitch; private final BsqCoinSelector bsqCoinSelector; private final NonBsqCoinSelector nonBsqCoinSelector; private final DaoStateService daoStateService; @@ -124,7 +126,8 @@ public BsqWalletService(WalletsSetup walletsSetup, DaoStateService daoStateService, UnconfirmedBsqChangeOutputListService unconfirmedBsqChangeOutputListService, Preferences preferences, - FeeService feeService) { + FeeService feeService, + DaoKillSwitch daoKillSwitch) { super(walletsSetup, preferences, feeService); @@ -133,73 +136,75 @@ public BsqWalletService(WalletsSetup walletsSetup, this.nonBsqCoinSelector = nonBsqCoinSelector; this.daoStateService = daoStateService; this.unconfirmedBsqChangeOutputListService = unconfirmedBsqChangeOutputListService; + this.daoKillSwitch = daoKillSwitch; - walletsSetup.addSetupCompletedHandler(() -> { - wallet = walletsSetup.getBsqWallet(); - if (wallet != null) { - wallet.setCoinSelector(bsqCoinSelector); - wallet.addEventListener(walletEventListener); + walletsSetup.addSetupCompletedHandler(this::setupComplete); - //noinspection deprecation - wallet.addEventListener(new AbstractWalletEventListener() { - @Override - public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) { - updateBsqWalletTransactions(); - } + daoStateService.addDaoStateListener(this); + } - @Override - public void onCoinsSent(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) { - updateBsqWalletTransactions(); - } + void setupComplete() { + wallet = walletsSetup.getBsqWallet(); + if (wallet != null) { + wallet.setCoinSelector(bsqCoinSelector); + wallet.addEventListener(walletEventListener); - @Override - public void onReorganize(Wallet wallet) { - log.warn("onReorganize "); - updateBsqWalletTransactions(); - unconfirmedBsqChangeOutputListService.onReorganize(); - } + //noinspection deprecation + wallet.addEventListener(new AbstractWalletEventListener() { + @Override + public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) { + updateBsqWalletTransactions(); + } - @Override - public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx) { - // We are only interested in updates from unconfirmed txs and confirmed txs at the - // time when it gets into a block. Otherwise we would get called - // updateBsqWalletTransactions for each tx as the block depth changes for all. - if (tx.getConfidence().getDepthInBlocks() <= 1 && - daoStateService.isParseBlockChainComplete()) { - updateBsqWalletTransactions(); - } - unconfirmedBsqChangeOutputListService.onTransactionConfidenceChanged(tx); - } + @Override + public void onCoinsSent(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) { + updateBsqWalletTransactions(); + } - @Override - public void onKeysAdded(List keys) { - updateBsqWalletTransactions(); - } + @Override + public void onReorganize(Wallet wallet) { + log.warn("onReorganize "); + updateBsqWalletTransactions(); + unconfirmedBsqChangeOutputListService.onReorganize(); + } - @Override - public void onScriptsChanged(Wallet wallet, List