diff --git a/src/main/java/bisq/desktop/main/dao/BaseBsqTxListItem.java b/src/main/java/bisq/desktop/main/dao/TxConfidenceListItem.java similarity index 94% rename from src/main/java/bisq/desktop/main/dao/BaseBsqTxListItem.java rename to src/main/java/bisq/desktop/main/dao/TxConfidenceListItem.java index 802ba54c22..ab635d2b28 100644 --- a/src/main/java/bisq/desktop/main/dao/BaseBsqTxListItem.java +++ b/src/main/java/bisq/desktop/main/dao/TxConfidenceListItem.java @@ -32,19 +32,18 @@ import lombok.Data; @Data -public class BaseBsqTxListItem { +public class TxConfidenceListItem { protected final BsqWalletService bsqWalletService; protected final String txId; protected int confirmations = 0; protected TxConfidenceIndicator txConfidenceIndicator; protected TxConfidenceListener txConfidenceListener; - protected BaseBsqTxListItem(Transaction transaction, - BsqWalletService bsqWalletService) { + protected TxConfidenceListItem(Transaction transaction, + BsqWalletService bsqWalletService) { this.bsqWalletService = bsqWalletService; txId = transaction.getHashAsString(); - setupConfidence(bsqWalletService); } diff --git a/src/main/java/bisq/desktop/main/dao/bonding/unlock/LockupTxListItem.java b/src/main/java/bisq/desktop/main/dao/bonding/unlock/LockupTxListItem.java index 918da837a0..f5ded35d30 100644 --- a/src/main/java/bisq/desktop/main/dao/bonding/unlock/LockupTxListItem.java +++ b/src/main/java/bisq/desktop/main/dao/bonding/unlock/LockupTxListItem.java @@ -19,7 +19,7 @@ package bisq.desktop.main.dao.bonding.unlock; import bisq.desktop.components.AutoTooltipButton; import bisq.desktop.components.indicator.TxConfidenceIndicator; -import bisq.desktop.main.dao.BaseBsqTxListItem; +import bisq.desktop.main.dao.TxConfidenceListItem; import bisq.core.btc.listeners.TxConfidenceListener; import bisq.core.btc.wallet.BsqWalletService; @@ -43,14 +43,13 @@ import static com.google.common.base.Preconditions.checkNotNull; @EqualsAndHashCode(callSuper = true) @Data -class LockupTxListItem extends BaseBsqTxListItem { +class LockupTxListItem extends TxConfidenceListItem { private final BtcWalletService btcWalletService; private final DaoFacade daoFacade; private final BsqFormatter bsqFormatter; private final Date date; - private int confirmations = 0; private Coin amount = Coin.ZERO; private int lockTime; private AutoTooltipButton button; diff --git a/src/main/java/bisq/desktop/main/dao/bonding/unlock/UnlockView.java b/src/main/java/bisq/desktop/main/dao/bonding/unlock/UnlockView.java index 7c5cd46003..1d0d01587f 100644 --- a/src/main/java/bisq/desktop/main/dao/bonding/unlock/UnlockView.java +++ b/src/main/java/bisq/desktop/main/dao/bonding/unlock/UnlockView.java @@ -228,6 +228,74 @@ public class UnlockView extends ActivatableView implements BsqBa // Private /////////////////////////////////////////////////////////////////////////////////////////// + private void onButtonClick() { + if (GUIUtil.isReadyForTxBroadcast(p2PService, walletsSetup)) { + Optional lockupTxOutput = daoFacade.getLockupTxOutput(selectedItem.getTxId()); + if (!lockupTxOutput.isPresent()) { + log.warn("Lockup output not found, txId = ", selectedItem.getTxId()); + return; + } + + Coin unlockAmount = Coin.valueOf(lockupTxOutput.get().getValue()); + Optional opLockTime = daoFacade.getLockTime(selectedItem.getTxId()); + int lockTime = opLockTime.orElse(-1); + + try { + new Popup<>().headLine(Res.get("dao.bonding.unlock.sendTx.headline")) + .confirmation(Res.get("dao.bonding.unlock.sendTx.details", + bsqFormatter.formatCoinWithCode(unlockAmount), + lockTime + )) + .actionButtonText(Res.get("shared.yes")) + .onAction(() -> { + daoFacade.publishUnlockTx(selectedItem.getTxId(), + () -> { + new Popup<>().confirmation(Res.get("dao.tx.published.success")).show(); + }, + errorMessage -> new Popup<>().warning(errorMessage.toString()).show() + ); + }) + .closeButtonText(Res.get("shared.cancel")) + .show(); + } catch (Throwable t) { + log.error(t.toString()); + t.printStackTrace(); + new Popup<>().warning(t.getMessage()).show(); + } + } else { + GUIUtil.showNotReadyForTxBroadcastPopups(p2PService, walletsSetup); + } + log.info("unlock tx: {}", selectedItem.getTxId()); + } + + private void openTxInBlockExplorer(LockupTxListItem item) { + if (item.getTxId() != null) + GUIUtil.openWebPage(preferences.getBsqBlockChainExplorer().txUrl + item.getTxId()); + } + + private void updateList() { + observableList.forEach(LockupTxListItem::cleanup); + + // copy list to avoid ConcurrentModificationException + final List walletTransactions = new ArrayList<>(bsqWalletService.getWalletTransactions()); + List items = walletTransactions.stream() + .map(transaction -> { + return new LockupTxListItem(transaction, + bsqWalletService, + btcWalletService, + daoFacade, + transaction.getUpdateTime(), + bsqFormatter); + }) + .collect(Collectors.toList()); + observableList.setAll(items); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Table columns + /////////////////////////////////////////////////////////////////////////////////////////// + private void addTxIdColumn() { TableColumn column = new AutoTooltipTableColumn<>(Res.get("shared.txId")); @@ -373,67 +441,4 @@ public class UnlockView extends ActivatableView implements BsqBa unlockColumn.setComparator(Comparator.comparing(LockupTxListItem::getConfirmations)); tableView.getColumns().add(unlockColumn); } - - private void onButtonClick() { - if (GUIUtil.isReadyForTxBroadcast(p2PService, walletsSetup)) { - Optional lockupTxOutput = daoFacade.getLockupTxOutput(selectedItem.getTxId()); - if (!lockupTxOutput.isPresent()) { - log.warn("Lockup output not found, txId = ", selectedItem.getTxId()); - return; - } - - Coin unlockAmount = Coin.valueOf(lockupTxOutput.get().getValue()); - Optional opLockTime = daoFacade.getLockTime(selectedItem.getTxId()); - int lockTime = opLockTime.orElse(-1); - - try { - new Popup<>().headLine(Res.get("dao.bonding.unlock.sendTx.headline")) - .confirmation(Res.get("dao.bonding.unlock.sendTx.details", - bsqFormatter.formatCoinWithCode(unlockAmount), - lockTime - )) - .actionButtonText(Res.get("shared.yes")) - .onAction(() -> { - daoFacade.publishUnlockTx(selectedItem.getTxId(), - () -> { - new Popup<>().confirmation(Res.get("dao.tx.published.success")).show(); - }, - errorMessage -> new Popup<>().warning(errorMessage.toString()).show() - ); - }) - .closeButtonText(Res.get("shared.cancel")) - .show(); - } catch (Throwable t) { - log.error(t.toString()); - t.printStackTrace(); - new Popup<>().warning(t.getMessage()).show(); - } - } else { - GUIUtil.showNotReadyForTxBroadcastPopups(p2PService, walletsSetup); - } - log.info("unlock tx: {}", selectedItem.getTxId()); - } - - private void openTxInBlockExplorer(LockupTxListItem item) { - if (item.getTxId() != null) - GUIUtil.openWebPage(preferences.getBsqBlockChainExplorer().txUrl + item.getTxId()); - } - - private void updateList() { - observableList.forEach(LockupTxListItem::cleanup); - - // copy list to avoid ConcurrentModificationException - final List walletTransactions = new ArrayList<>(bsqWalletService.getWalletTransactions()); - List items = walletTransactions.stream() - .map(transaction -> { - return new LockupTxListItem(transaction, - bsqWalletService, - btcWalletService, - daoFacade, - transaction.getUpdateTime(), - bsqFormatter); - }) - .collect(Collectors.toList()); - observableList.setAll(items); - } } diff --git a/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxListItem.java b/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxListItem.java index 9a63052eef..7eba0c478e 100644 --- a/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxListItem.java +++ b/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxListItem.java @@ -18,7 +18,7 @@ package bisq.desktop.main.dao.wallet.tx; import bisq.desktop.components.indicator.TxConfidenceIndicator; -import bisq.desktop.main.dao.BaseBsqTxListItem; +import bisq.desktop.main.dao.TxConfidenceListItem; import bisq.core.btc.listeners.TxConfidenceListener; import bisq.core.btc.wallet.BsqWalletService; @@ -37,19 +37,20 @@ import java.util.Date; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.extern.slf4j.Slf4j; import static com.google.common.base.Preconditions.checkNotNull; +@Slf4j @EqualsAndHashCode(callSuper = true) @Data -class BsqTxListItem extends BaseBsqTxListItem { +class BsqTxListItem extends TxConfidenceListItem { private final BtcWalletService btcWalletService; private final DaoFacade daoFacade; private final BsqFormatter bsqFormatter; private final Date date; private final boolean isBurnedBsqTx; - private int confirmations = 0; private final String address; private final String direction; private Coin amount;