diff --git a/core/src/main/java/bisq/core/dao/DaoFacade.java b/core/src/main/java/bisq/core/dao/DaoFacade.java index acbc767739..08d0b7b70d 100644 --- a/core/src/main/java/bisq/core/dao/DaoFacade.java +++ b/core/src/main/java/bisq/core/dao/DaoFacade.java @@ -522,11 +522,11 @@ public class DaoFacade implements DaoSetupService { return bondedRolesService.getActiveBonds(); } - public List getAllActiveBonds() { - List activeReputations = bondedReputationService.getActiveBonds(); - List activeRoles = bondedRolesService.getActiveBonds(); - List bonds = new ArrayList<>(activeReputations); - bonds.addAll(activeRoles); + public List getAllBonds() { + List bondedReputations = bondedReputationService.getAllBonds(); + List bondedRoles = bondedRolesService.getAllBonds(); + List bonds = new ArrayList<>(bondedReputations); + bonds.addAll(bondedRoles); return bonds; } diff --git a/core/src/main/java/bisq/core/dao/governance/bond/BondService.java b/core/src/main/java/bisq/core/dao/governance/bond/BondService.java index 2902ff5f23..9a5afed82b 100644 --- a/core/src/main/java/bisq/core/dao/governance/bond/BondService.java +++ b/core/src/main/java/bisq/core/dao/governance/bond/BondService.java @@ -182,6 +182,10 @@ public abstract class BondService impleme .collect(Collectors.toList()); } + public List getAllBonds() { + return new ArrayList<>(bondByUidMap.values()); + } + public Optional findBondByLockupTxId(String lockupTxId) { return bondByUidMap.values().stream() .filter(bond -> lockupTxId.equals(bond.getLockupTxId())) diff --git a/core/src/main/java/bisq/core/dao/governance/bond/reputation/BondedReputationService.java b/core/src/main/java/bisq/core/dao/governance/bond/reputation/BondedReputationService.java index 61deed6327..5e9f195876 100644 --- a/core/src/main/java/bisq/core/dao/governance/bond/reputation/BondedReputationService.java +++ b/core/src/main/java/bisq/core/dao/governance/bond/reputation/BondedReputationService.java @@ -21,15 +21,15 @@ import bisq.core.btc.wallet.BsqWalletService; import bisq.core.dao.governance.bond.Bond; import bisq.core.dao.governance.bond.BondConsensus; import bisq.core.dao.governance.bond.BondService; +import bisq.core.dao.governance.bond.role.BondedRolesService; import bisq.core.dao.state.DaoStateService; import bisq.core.dao.state.model.blockchain.TxOutput; import javax.inject.Inject; -import java.util.ArrayList; -import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -37,40 +37,18 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class BondedReputationService extends BondService { + private final BondedRolesService bondedRolesService; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor /////////////////////////////////////////////////////////////////////////////////////////// @Inject - public BondedReputationService(DaoStateService daoStateService, BsqWalletService bsqWalletService) { + public BondedReputationService(DaoStateService daoStateService, BsqWalletService bsqWalletService, + BondedRolesService bondedRolesService) { super(daoStateService, bsqWalletService); - } - - /////////////////////////////////////////////////////////////////////////////////////////// - // API - /////////////////////////////////////////////////////////////////////////////////////////// - - public List getActiveBondedReputations() { - return bondByUidMap.values().stream() - .filter(e -> e.isActive()) - .collect(Collectors.toList()); - } - - public List getAllBondedReputations() { - return new ArrayList<>(bondByUidMap.values()); - } - - public List getUnconfirmedBondedReputations() { - //TODO - /* Set myWalletTransactionIds = bsqWalletService.getWalletTransactions().stream() - .map(Transaction::getHashAsString) - .collect(Collectors.toSet()); -*/ - return bondByUidMap.values().stream() - .filter(e -> e.isActive()) - .collect(Collectors.toList()); + this.bondedRolesService = bondedRolesService; } @@ -90,15 +68,14 @@ public class BondedReputationService extends BondService { bondByUidMap.put(bondedReputation.getBondedAsset().getUid(), bondedReputation); - });*/ + }); } - private Stream getBondedReputationStream() { + Set bondedRolesLockupTxIdSet = bondedRolesService.getAllBonds().stream().map(e -> e.getLockupTxId()).collect(Collectors.toSet()); return daoStateService.getLockupTxOutputs().stream() .map(lockupTxOutput -> { String lockupTxId = lockupTxOutput.getTxId(); @@ -110,14 +87,23 @@ public class BondedReputationService extends BondService !bondedRolesLockupTxIdSet.contains(e.getLockupTxId())); + } + + @Override + public void updateBond(BondedReputation bond, Reputation bondedAsset, TxOutput lockupTxOutput) { + // Lets see if we have a lock up tx. + String lockupTxId = lockupTxOutput.getTxId(); + daoStateService.getTx(lockupTxId).ifPresent(lockupTx -> { + applyBondState(daoStateService, bond, lockupTx, lockupTxOutput); + }); } } diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 55b34cb239..10c8626978 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -1333,6 +1333,7 @@ dao.bonding.dashboard.bondsHeadline=Bonded BSQ dao.bonding.dashboard.lockupAmount=Lockup funds dao.bonding.dashboard.unlockingAmount=Unlocking funds (wait until lock time is over) dao.bonding.bonds.table.lockupTxId=Lockup tx ID +dao.bonding.bonds.table.header=All bonds dao.bonding.info=Lockup Tx ID: {0} / {1} dao.bonding.reputation.salt.info=Salt: {0} @@ -1386,11 +1387,12 @@ dao.bond.bondedRoleType.details.isSingleton=Can be taken by multiple role holder dao.bond.bondedRoleType.details.blocks={0} blocks dao.bond.bondedReputation=Bonded Reputation +dao.bond.bondedRoles=Bonded roles -dao.bond.table.header=Bonded roles dao.bond.table.column.header.name=Name dao.bond.table.column.header.link=Link -dao.bond.table.column.header.bondedRoleType=Role +dao.bond.table.column.header.bondType=Bond type +dao.bond.table.column.header.details=Details dao.bond.table.column.header.startDate=Started dao.bond.table.column.header.lockupTxId=Lockup Tx ID dao.bond.table.column.header.revokeDate=Revoked diff --git a/core/src/main/resources/i18n/displayStrings_de.properties b/core/src/main/resources/i18n/displayStrings_de.properties index 9cee89f269..824d039020 100644 --- a/core/src/main/resources/i18n/displayStrings_de.properties +++ b/core/src/main/resources/i18n/displayStrings_de.properties @@ -1161,10 +1161,10 @@ dao.bond.bondedRoleType.details.link=Link zur Rollenbeschreibung dao.bond.bondedRoleType.details.isSingleton=Kann von mehreren Rollenhalter genommen werden dao.bond.bondedRoleType.details.blocks={0} Blöcke -dao.bond.table.header=Gekoppelte Rollen +dao.bond.bondedRoles=Gekoppelte Rollen dao.bond.table.column.header.name=Name dao.bond.table.column.header.link=Konto -dao.bond.table.column.header.bondedRoleType=Rolle +dao.bond.table.column.header.bondType=Rolle dao.bond.table.column.header.startDate=Gestartet dao.bond.table.column.header.lockupTxId=Sperrung Tx ID dao.bond.table.column.header.revokeDate=Widerrufen diff --git a/core/src/main/resources/i18n/displayStrings_el.properties b/core/src/main/resources/i18n/displayStrings_el.properties index 878d35883c..b12d93874f 100644 --- a/core/src/main/resources/i18n/displayStrings_el.properties +++ b/core/src/main/resources/i18n/displayStrings_el.properties @@ -1161,10 +1161,10 @@ dao.bond.bondedRoleType.details.link=Link to role description dao.bond.bondedRoleType.details.isSingleton=Can be taken by multiple role holders dao.bond.bondedRoleType.details.blocks={0} blocks -dao.bond.table.header=Bonded roles +dao.bond.bondedRoles=Bonded roles dao.bond.table.column.header.name=Όνομα dao.bond.table.column.header.link=Λογαριασμός -dao.bond.table.column.header.bondedRoleType=Ρόλος +dao.bond.table.column.header.bondType=Ρόλος dao.bond.table.column.header.startDate=Started dao.bond.table.column.header.lockupTxId=Lockup Tx ID dao.bond.table.column.header.revokeDate=Revoked diff --git a/core/src/main/resources/i18n/displayStrings_es.properties b/core/src/main/resources/i18n/displayStrings_es.properties index a01ad8cb74..af4b5862ef 100644 --- a/core/src/main/resources/i18n/displayStrings_es.properties +++ b/core/src/main/resources/i18n/displayStrings_es.properties @@ -1161,10 +1161,10 @@ dao.bond.bondedRoleType.details.link=Link to role description dao.bond.bondedRoleType.details.isSingleton=Can be taken by multiple role holders dao.bond.bondedRoleType.details.blocks={0} blocks -dao.bond.table.header=Bonded roles +dao.bond.bondedRoles=Bonded roles dao.bond.table.column.header.name=Nombre dao.bond.table.column.header.link=Cuenta -dao.bond.table.column.header.bondedRoleType=Rol +dao.bond.table.column.header.bondType=Rol dao.bond.table.column.header.startDate=Started dao.bond.table.column.header.lockupTxId=Lockup Tx ID dao.bond.table.column.header.revokeDate=Revoked diff --git a/core/src/main/resources/i18n/displayStrings_fa.properties b/core/src/main/resources/i18n/displayStrings_fa.properties index 0106d34e69..b04ad16819 100644 --- a/core/src/main/resources/i18n/displayStrings_fa.properties +++ b/core/src/main/resources/i18n/displayStrings_fa.properties @@ -1161,10 +1161,10 @@ dao.bond.bondedRoleType.details.link=Link to role description dao.bond.bondedRoleType.details.isSingleton=Can be taken by multiple role holders dao.bond.bondedRoleType.details.blocks={0} blocks -dao.bond.table.header=Bonded roles +dao.bond.bondedRoles=Bonded roles dao.bond.table.column.header.name=نام dao.bond.table.column.header.link=حساب -dao.bond.table.column.header.bondedRoleType=نقش +dao.bond.table.column.header.bondType=نقش dao.bond.table.column.header.startDate=Started dao.bond.table.column.header.lockupTxId=Lockup Tx ID dao.bond.table.column.header.revokeDate=Revoked diff --git a/core/src/main/resources/i18n/displayStrings_hu.properties b/core/src/main/resources/i18n/displayStrings_hu.properties index 8a5527ae47..5d0f417f34 100644 --- a/core/src/main/resources/i18n/displayStrings_hu.properties +++ b/core/src/main/resources/i18n/displayStrings_hu.properties @@ -1161,10 +1161,10 @@ dao.bond.bondedRoleType.details.link=Link to role description dao.bond.bondedRoleType.details.isSingleton=Can be taken by multiple role holders dao.bond.bondedRoleType.details.blocks={0} blocks -dao.bond.table.header=Bonded roles +dao.bond.bondedRoles=Bonded roles dao.bond.table.column.header.name=Név dao.bond.table.column.header.link=Fiók -dao.bond.table.column.header.bondedRoleType=Szerep +dao.bond.table.column.header.bondType=Szerep dao.bond.table.column.header.startDate=Started dao.bond.table.column.header.lockupTxId=Lockup Tx ID dao.bond.table.column.header.revokeDate=Revoked diff --git a/core/src/main/resources/i18n/displayStrings_pt.properties b/core/src/main/resources/i18n/displayStrings_pt.properties index 2376a9c8a3..b881a6def4 100644 --- a/core/src/main/resources/i18n/displayStrings_pt.properties +++ b/core/src/main/resources/i18n/displayStrings_pt.properties @@ -1161,10 +1161,10 @@ dao.bond.bondedRoleType.details.link=Link to role description dao.bond.bondedRoleType.details.isSingleton=Can be taken by multiple role holders dao.bond.bondedRoleType.details.blocks={0} blocks -dao.bond.table.header=Bonded roles +dao.bond.bondedRoles=Bonded roles dao.bond.table.column.header.name=Nome dao.bond.table.column.header.link=Conta -dao.bond.table.column.header.bondedRoleType=Função +dao.bond.table.column.header.bondType=Função dao.bond.table.column.header.startDate=Started dao.bond.table.column.header.lockupTxId=Lockup Tx ID dao.bond.table.column.header.revokeDate=Revoked diff --git a/core/src/main/resources/i18n/displayStrings_ro.properties b/core/src/main/resources/i18n/displayStrings_ro.properties index c58f1557db..9e5439f20f 100644 --- a/core/src/main/resources/i18n/displayStrings_ro.properties +++ b/core/src/main/resources/i18n/displayStrings_ro.properties @@ -1161,10 +1161,10 @@ dao.bond.bondedRoleType.details.link=Link to role description dao.bond.bondedRoleType.details.isSingleton=Can be taken by multiple role holders dao.bond.bondedRoleType.details.blocks={0} blocks -dao.bond.table.header=Bonded roles +dao.bond.bondedRoles=Bonded roles dao.bond.table.column.header.name=Nume dao.bond.table.column.header.link=Cont -dao.bond.table.column.header.bondedRoleType=Rol +dao.bond.table.column.header.bondType=Rol dao.bond.table.column.header.startDate=Started dao.bond.table.column.header.lockupTxId=Lockup Tx ID dao.bond.table.column.header.revokeDate=Revoked diff --git a/core/src/main/resources/i18n/displayStrings_ru.properties b/core/src/main/resources/i18n/displayStrings_ru.properties index 72f45fe859..7871b5d3ad 100644 --- a/core/src/main/resources/i18n/displayStrings_ru.properties +++ b/core/src/main/resources/i18n/displayStrings_ru.properties @@ -1161,10 +1161,10 @@ dao.bond.bondedRoleType.details.link=Ссылка на подробности р dao.bond.bondedRoleType.details.isSingleton=Может быть принято несколькими держателями роли dao.bond.bondedRoleType.details.blocks={0} блоков -dao.bond.table.header=Обеспеченные роли +dao.bond.bondedRoles=Обеспеченные роли dao.bond.table.column.header.name=Имя dao.bond.table.column.header.link=Счёт -dao.bond.table.column.header.bondedRoleType=Роль +dao.bond.table.column.header.bondType=Роль dao.bond.table.column.header.startDate=Начато dao.bond.table.column.header.lockupTxId=Транз. идент. блокировки dao.bond.table.column.header.revokeDate=Аннулировано diff --git a/core/src/main/resources/i18n/displayStrings_sr.properties b/core/src/main/resources/i18n/displayStrings_sr.properties index 5cc99db11f..74732beef2 100644 --- a/core/src/main/resources/i18n/displayStrings_sr.properties +++ b/core/src/main/resources/i18n/displayStrings_sr.properties @@ -1161,10 +1161,10 @@ dao.bond.bondedRoleType.details.link=Link to role description dao.bond.bondedRoleType.details.isSingleton=Can be taken by multiple role holders dao.bond.bondedRoleType.details.blocks={0} blocks -dao.bond.table.header=Bonded roles +dao.bond.bondedRoles=Bonded roles dao.bond.table.column.header.name=Ime dao.bond.table.column.header.link=Nalog -dao.bond.table.column.header.bondedRoleType=Uloga +dao.bond.table.column.header.bondType=Uloga dao.bond.table.column.header.startDate=Started dao.bond.table.column.header.lockupTxId=Lockup Tx ID dao.bond.table.column.header.revokeDate=Revoked diff --git a/core/src/main/resources/i18n/displayStrings_th.properties b/core/src/main/resources/i18n/displayStrings_th.properties index d44cd51ab7..e837096100 100644 --- a/core/src/main/resources/i18n/displayStrings_th.properties +++ b/core/src/main/resources/i18n/displayStrings_th.properties @@ -1161,10 +1161,10 @@ dao.bond.bondedRoleType.details.link=Link to role description dao.bond.bondedRoleType.details.isSingleton=Can be taken by multiple role holders dao.bond.bondedRoleType.details.blocks={0} blocks -dao.bond.table.header=Bonded roles +dao.bond.bondedRoles=Bonded roles dao.bond.table.column.header.name=ชื่อ dao.bond.table.column.header.link=บัญชี -dao.bond.table.column.header.bondedRoleType=บทบาท +dao.bond.table.column.header.bondType=บทบาท dao.bond.table.column.header.startDate=Started dao.bond.table.column.header.lockupTxId=Lockup Tx ID dao.bond.table.column.header.revokeDate=Revoked diff --git a/core/src/main/resources/i18n/displayStrings_vi.properties b/core/src/main/resources/i18n/displayStrings_vi.properties index 9c70e2dfa1..b70aa05088 100644 --- a/core/src/main/resources/i18n/displayStrings_vi.properties +++ b/core/src/main/resources/i18n/displayStrings_vi.properties @@ -1161,10 +1161,10 @@ dao.bond.bondedRoleType.details.link=Link to role description dao.bond.bondedRoleType.details.isSingleton=Can be taken by multiple role holders dao.bond.bondedRoleType.details.blocks={0} blocks -dao.bond.table.header=Bonded roles +dao.bond.bondedRoles=Bonded roles dao.bond.table.column.header.name=Tên dao.bond.table.column.header.link=Tài khoản -dao.bond.table.column.header.bondedRoleType=Vai trò +dao.bond.table.column.header.bondType=Vai trò dao.bond.table.column.header.startDate=Started dao.bond.table.column.header.lockupTxId=Lockup Tx ID dao.bond.table.column.header.revokeDate=Revoked diff --git a/core/src/main/resources/i18n/displayStrings_zh.properties b/core/src/main/resources/i18n/displayStrings_zh.properties index d4f86541e5..a7d1865639 100644 --- a/core/src/main/resources/i18n/displayStrings_zh.properties +++ b/core/src/main/resources/i18n/displayStrings_zh.properties @@ -1161,10 +1161,10 @@ dao.bond.bondedRoleType.details.link=Link to role description dao.bond.bondedRoleType.details.isSingleton=Can be taken by multiple role holders dao.bond.bondedRoleType.details.blocks={0} blocks -dao.bond.table.header=Bonded roles +dao.bond.bondedRoles=Bonded roles dao.bond.table.column.header.name=名称 dao.bond.table.column.header.link=账户 -dao.bond.table.column.header.bondedRoleType=角色 +dao.bond.table.column.header.bondType=角色 dao.bond.table.column.header.startDate=Started dao.bond.table.column.header.lockupTxId=Lockup Tx ID dao.bond.table.column.header.revokeDate=Revoked diff --git a/desktop/src/main/java/bisq/desktop/main/dao/bonding/bonds/BondListItem.java b/desktop/src/main/java/bisq/desktop/main/dao/bonding/bonds/BondListItem.java index 5a6b0ccd97..9911b15556 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/bonding/bonds/BondListItem.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/bonding/bonds/BondListItem.java @@ -17,19 +17,23 @@ package bisq.desktop.main.dao.bonding.bonds; -import bisq.desktop.components.AutoTooltipButton; import bisq.desktop.main.dao.bonding.BondingViewUtils; import bisq.core.dao.DaoFacade; import bisq.core.dao.governance.bond.Bond; +import bisq.core.dao.governance.bond.role.BondedRole; import bisq.core.dao.governance.bond.role.BondedRolesService; import bisq.core.dao.state.DaoStateListener; import bisq.core.dao.state.model.blockchain.Block; +import bisq.core.locale.Res; import bisq.core.util.BsqFormatter; +import bisq.common.util.Utilities; + import org.bitcoinj.core.Coin; import javafx.scene.control.Button; +import javafx.scene.control.Label; import java.util.Date; @@ -47,10 +51,13 @@ class BondListItem implements DaoStateListener { private final BondedRolesService bondedRolesService; private final BondingViewUtils bondingViewUtils; private final BsqFormatter bsqFormatter; - private final String info; + private final String bondType; private final String txId; private final String amount; + private final String lockupDate; private final String lockTime; + private final Label stateLabel; + private final String bondDetails; @Getter private Button button; @@ -67,56 +74,30 @@ class BondListItem implements DaoStateListener { this.bsqFormatter = bsqFormatter; - info = bond.getBondedAsset().getDisplayString(); - txId = bond.getLockupTxId(); amount = bsqFormatter.formatCoin(Coin.valueOf(bond.getAmount())); - lockTime = bsqFormatter.formatDateTime(new Date(bond.getLockupDate())); + lockTime = Integer.toString(bond.getLockTime()); + if (bond instanceof BondedRole) { + bondType = Res.get("dao.bond.bondedRoles"); + bondDetails = bond.getBondedAsset().getDisplayString(); + } else { + bondType = Res.get("dao.bond.bondedReputation"); + bondDetails = Utilities.bytesAsHexString(bond.getBondedAsset().getHash()); + } + lockupDate = bsqFormatter.formatDateTime(new Date(bond.getLockupDate())); + txId = bond.getLockupTxId(); + + stateLabel = new Label(); - button = new AutoTooltipButton(); - button.setMinWidth(70); - // label = new Label(); -/* daoFacade.addBsqStateListener(this); - button.setOnAction(e -> { - if (bondedRole.getBondState() == BondState.READY_FOR_LOCKUP) { - bondingViewUtils.lockupBondForBondedRole(role, - txId -> { - bondedRole.setLockupTxId(txId); - bondedRole.setBondState(BondState.LOCKUP_TX_PENDING); - update(); - button.setDisable(true); - }); - } else if (bondedRole.getBondState() == BondState.LOCKUP_TX_CONFIRMED) { - bondingViewUtils.unLock(bondedRole.getLockupTxId(), - txId -> { - bondedRole.setUnlockTxId(txId); - bondedRole.setBondState(BondState.UNLOCK_TX_PENDING); - update(); - button.setDisable(true); - }); - } - });*/ + update(); } private void update() { - /* label.setText(Res.get("dao.bond.bondState." + bondedRole.getBondState().name())); - - boolean showLockup = bondedRole.getBondState() == BondState.READY_FOR_LOCKUP; - boolean showRevoke = bondedRole.getBondState() == BondState.LOCKUP_TX_CONFIRMED; - if (showLockup) - button.updateText(Res.get("dao.bond.table.button.lockup")); - else if (showRevoke) - button.updateText(Res.get("dao.bond.table.button.revoke")); - - - boolean showButton = isMyRole && (showLockup || showRevoke); - button.setVisible(showButton); - button.setManaged(showButton);*/ + stateLabel.setText(Res.get("dao.bond.bondState." + bond.getBondState().name())); } public void cleanup() { - // daoFacade.removeBsqStateListener(this); - // button.setOnAction(null); + daoFacade.removeBsqStateListener(this); } // DaoStateListener diff --git a/desktop/src/main/java/bisq/desktop/main/dao/bonding/bonds/BondsView.fxml b/desktop/src/main/java/bisq/desktop/main/dao/bonding/bonds/BondsView.fxml index b7d03d7bd5..7da6f9ec12 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/bonding/bonds/BondsView.fxml +++ b/desktop/src/main/java/bisq/desktop/main/dao/bonding/bonds/BondsView.fxml @@ -27,9 +27,7 @@ AnchorPane.rightAnchor="25.0" AnchorPane.topAnchor="20.0" xmlns:fx="http://javafx.com/fxml"> - - - + diff --git a/desktop/src/main/java/bisq/desktop/main/dao/bonding/bonds/BondsView.java b/desktop/src/main/java/bisq/desktop/main/dao/bonding/bonds/BondsView.java index 75238c84c1..4d44297a66 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/bonding/bonds/BondsView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/bonding/bonds/BondsView.java @@ -22,7 +22,6 @@ import bisq.desktop.common.view.FxmlView; import bisq.desktop.components.AutoTooltipTableColumn; import bisq.desktop.components.HyperlinkWithIcon; import bisq.desktop.main.dao.bonding.BondingViewUtils; -import bisq.desktop.main.dao.wallet.BsqBalanceUtil; import bisq.desktop.util.GUIUtil; import bisq.desktop.util.validation.BsqValidator; @@ -43,13 +42,12 @@ import javax.inject.Inject; import de.jensd.fx.fontawesome.AwesomeIcon; -import javafx.scene.control.Button; +import javafx.scene.control.Label; import javafx.scene.control.TableCell; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.Tooltip; import javafx.scene.layout.GridPane; -import javafx.scene.layout.VBox; import javafx.geometry.Insets; @@ -59,19 +57,22 @@ import javafx.beans.value.ChangeListener; import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; +import javafx.collections.transformation.SortedList; import javafx.util.Callback; +import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; +import static bisq.desktop.util.FormBuilder.addTitledGroupBg; + @FxmlView public class BondsView extends ActivatableView implements BsqBalanceListener, DaoStateListener { private TableView tableView; private final BsqWalletService bsqWalletService; private final BsqFormatter bsqFormatter; - private final BsqBalanceUtil bsqBalanceUtil; private final BsqValidator bsqValidator; private final BondingViewUtils bondingViewUtils; private final BondedRolesService bondedRolesService; @@ -81,6 +82,7 @@ public class BondsView extends ActivatableView implements BsqBal private int gridRow = 0; private final ObservableList observableList = FXCollections.observableArrayList(); + private final SortedList sortedList = new SortedList<>(observableList); private ListChangeListener walletBsqTransactionsListener; private ChangeListener walletChainHeightListener; @@ -93,7 +95,6 @@ public class BondsView extends ActivatableView implements BsqBal @Inject private BondsView(BsqWalletService bsqWalletService, BsqFormatter bsqFormatter, - BsqBalanceUtil bsqBalanceUtil, BsqValidator bsqValidator, BondingViewUtils bondingViewUtils, BondedRolesService bondedRolesService, @@ -101,7 +102,6 @@ public class BondsView extends ActivatableView implements BsqBal Preferences preferences) { this.bsqWalletService = bsqWalletService; this.bsqFormatter = bsqFormatter; - this.bsqBalanceUtil = bsqBalanceUtil; this.bsqValidator = bsqValidator; this.bondingViewUtils = bondingViewUtils; this.bondedRolesService = bondedRolesService; @@ -111,27 +111,21 @@ public class BondsView extends ActivatableView implements BsqBal @Override public void initialize() { - gridRow = bsqBalanceUtil.addGroup(root, gridRow); + addTitledGroupBg(root, gridRow, 2, Res.get("dao.bonding.bonds.table.header")); tableView = new TableView<>(); + GridPane.setRowIndex(tableView, ++gridRow); + GridPane.setMargin(tableView, new Insets(30, -10, 5, -10)); + root.getChildren().add(tableView); tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); addColumns(); walletBsqTransactionsListener = change -> updateList(); walletChainHeightListener = (observable, oldValue, newValue) -> updateList(); - - VBox vBox = new VBox(); - vBox.setSpacing(10); - GridPane.setRowIndex(vBox, ++gridRow); - GridPane.setColumnSpan(vBox, 3); - GridPane.setMargin(vBox, new Insets(40, -10, 5, -10)); - vBox.getChildren().addAll(tableView); - root.getChildren().add(vBox); } @Override protected void activate() { - bsqBalanceUtil.activate(); bsqWalletService.addBsqBalanceListener(this); onUpdateBalances(bsqWalletService.getAvailableBalance(), bsqWalletService.getAvailableNonBsqBalance(), @@ -144,7 +138,8 @@ public class BondsView extends ActivatableView implements BsqBal bsqWalletService.addBsqBalanceListener(this); bsqWalletService.getChainHeightProperty().addListener(walletChainHeightListener); - tableView.setItems(observableList); + sortedList.comparatorProperty().bind(tableView.comparatorProperty()); + tableView.setItems(sortedList); daoFacade.addBsqStateListener(this); @@ -153,7 +148,6 @@ public class BondsView extends ActivatableView implements BsqBal @Override protected void deactivate() { - bsqBalanceUtil.deactivate(); bsqWalletService.removeBsqBalanceListener(this); bsqWalletService.getWalletTransactions().removeListener(walletBsqTransactionsListener); @@ -161,7 +155,9 @@ public class BondsView extends ActivatableView implements BsqBal bsqWalletService.getChainHeightProperty().removeListener(walletChainHeightListener); daoFacade.removeBsqStateListener(this); - // observableList.forEach(BondListItem::cleanup); + sortedList.comparatorProperty().unbind(); + + observableList.forEach(BondListItem::cleanup); } @@ -208,7 +204,7 @@ public class BondsView extends ActivatableView implements BsqBal } private void updateList() { - List items = daoFacade.getAllActiveBonds().stream() + List items = daoFacade.getAllBonds().stream() .map(bond -> { return new BondListItem(bond, daoFacade, @@ -216,6 +212,7 @@ public class BondsView extends ActivatableView implements BsqBal bondingViewUtils, bsqFormatter); }) + .sorted(Comparator.comparing(BondListItem::getLockupDate).reversed()) .collect(Collectors.toList()); observableList.setAll(items); GUIUtil.setFitToRowsForTableView(tableView, 37, 28, 2, 10); @@ -229,43 +226,13 @@ public class BondsView extends ActivatableView implements BsqBal private void addColumns() { TableColumn column; - column = new AutoTooltipTableColumn<>(Res.get("dao.bonding.unlock.hash")); - column.setMinWidth(160); - column.setMaxWidth(column.getMinWidth()); - - column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue())); - column.setCellFactory(new Callback<>() { - - @Override - public TableCell call(TableColumn column) { - return new TableCell<>() { - - @Override - public void updateItem(final BondListItem item, boolean empty) { - super.updateItem(item, empty); - if (item != null && !empty) { - setText(item.getInfo()); - } else - setText(""); - } - }; - } - }); - tableView.getColumns().add(column); - column = new AutoTooltipTableColumn<>(Res.get("shared.amountWithCur", "BSQ")); - column.setMinWidth(120); - column.setMaxWidth(column.getMinWidth()); - + column.setMinWidth(80); column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue())); column.setCellFactory(new Callback<>() { - @Override - public TableCell call(TableColumn column) { + public TableCell call(TableColumn column) { return new TableCell<>() { - @Override public void updateItem(final BondListItem item, boolean empty) { super.updateItem(item, empty); @@ -277,25 +244,115 @@ public class BondsView extends ActivatableView implements BsqBal }; } }); + tableView.getColumns().add(column); - - column = new AutoTooltipTableColumn<>(Res.get("dao.bonding.unlock.time")); - column.setMinWidth(140); - column.setMaxWidth(column.getMinWidth()); - + column = new AutoTooltipTableColumn<>(Res.get("dao.bond.table.column.header.lockTime")); + column.setMinWidth(40); column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue())); column.setCellFactory(new Callback<>() { - @Override - public TableCell call(TableColumn column) { + public TableCell call(TableColumn column) { + return new TableCell<>() { + @Override + public void updateItem(final BondListItem item, boolean empty) { + super.updateItem(item, empty); + if (item != null && !empty) { + setText(item.getLockTime()); + } else + setText(""); + } + }; + } + }); + tableView.getColumns().add(column); + + column = new AutoTooltipTableColumn<>(Res.get("dao.bond.table.column.header.bondState")); + column.setCellValueFactory(item -> new ReadOnlyObjectWrapper<>(item.getValue())); + column.setMinWidth(80); + column.setCellFactory( + new Callback<>() { + @Override + public TableCell call(TableColumn column) { + return new TableCell<>() { + Label label; + + @Override + public void updateItem(final BondListItem item, boolean empty) { + super.updateItem(item, empty); + + if (item != null && !empty) { + if (label == null) { + label = item.getStateLabel(); + setGraphic(label); + } + } else { + setGraphic(null); + if (label != null) + label = null; + } + } + }; + } + }); + tableView.getColumns().add(column); + + column = new AutoTooltipTableColumn<>(Res.get("dao.bond.table.column.header.bondType")); + column.setMinWidth(100); + column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue())); + column.setCellFactory(new Callback<>() { + @Override + public TableCell call(TableColumn column) { return new TableCell<>() { @Override public void updateItem(final BondListItem item, boolean empty) { super.updateItem(item, empty); if (item != null && !empty) { - setText(item.getLockTime()); + setText(item.getBondType()); + } else + setText(""); + } + }; + } + }); + tableView.getColumns().add(column); + + column = new AutoTooltipTableColumn<>(Res.get("dao.bond.table.column.header.details")); + column.setMinWidth(100); + column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue())); + column.setCellFactory(new Callback<>() { + @Override + public TableCell call(TableColumn column) { + return new TableCell<>() { + + @Override + public void updateItem(final BondListItem item, boolean empty) { + super.updateItem(item, empty); + if (item != null && !empty) { + setText(item.getBondDetails()); + } else + setText(""); + } + }; + } + }); + tableView.getColumns().add(column); + + column = new AutoTooltipTableColumn<>(Res.get("dao.bond.table.column.header.lockupDate")); + column.setMinWidth(140); + + column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue())); + column.setCellFactory(new Callback<>() { + + @Override + public TableCell call(TableColumn column) { + return new TableCell<>() { + @Override + public void updateItem(final BondListItem item, boolean empty) { + super.updateItem(item, empty); + if (item != null && !empty) { + setText(item.getLockupDate()); } else setText(""); } @@ -337,36 +394,5 @@ public class BondsView extends ActivatableView implements BsqBal } }); tableView.getColumns().add(column); - - column = new TableColumn<>(); - column.setCellValueFactory(item -> new ReadOnlyObjectWrapper<>(item.getValue())); - column.setMinWidth(80); - column.setCellFactory( - new Callback<>() { - @Override - public TableCell call(TableColumn column) { - return new TableCell<>() { - Button button; - - @Override - public void updateItem(final BondListItem item, boolean empty) { - super.updateItem(item, empty); - - if (item != null && !empty) { - if (button == null) { - button = item.getButton(); - setGraphic(button); - } - } else { - setGraphic(null); - if (button != null) - button = null; - } - } - }; - } - }); - tableView.getColumns().add(column); } } diff --git a/desktop/src/main/java/bisq/desktop/main/dao/bonding/reputation/MyBondedReputationView.java b/desktop/src/main/java/bisq/desktop/main/dao/bonding/reputation/MyBondedReputationView.java index 0a57620c46..1bc4318b6e 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/bonding/reputation/MyBondedReputationView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/bonding/reputation/MyBondedReputationView.java @@ -70,6 +70,7 @@ import javafx.beans.value.ChangeListener; import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; +import javafx.collections.transformation.SortedList; import javafx.util.Callback; @@ -100,6 +101,7 @@ public class MyBondedReputationView extends ActivatableView impl private ChangeListener amountFocusOutListener, timeFocusOutListener, saltFocusOutListener; private ChangeListener amountInputTextFieldListener, timeInputTextFieldListener, saltInputTextFieldListener; private final ObservableList observableList = FXCollections.observableArrayList(); + private final SortedList sortedList = new SortedList<>(observableList); private ListChangeListener walletBsqTransactionsListener; private ChangeListener walletChainHeightListener; @@ -190,7 +192,8 @@ public class MyBondedReputationView extends ActivatableView impl timeInputTextField.resetValidation(); setNewRandomSalt(); - tableView.setItems(observableList); + sortedList.comparatorProperty().bind(tableView.comparatorProperty()); + tableView.setItems(sortedList); onUpdateBalances(); updateList(); @@ -215,6 +218,8 @@ public class MyBondedReputationView extends ActivatableView impl lockupButton.setOnAction(null); + sortedList.comparatorProperty().unbind(); + daoFacade.removeBsqStateListener(this); } @@ -291,6 +296,7 @@ public class MyBondedReputationView extends ActivatableView impl tableView = new TableView<>(); tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); + tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); createColumns(); VBox vBox = new VBox(); diff --git a/desktop/src/main/java/bisq/desktop/main/dao/bonding/roles/BondedRolesView.java b/desktop/src/main/java/bisq/desktop/main/dao/bonding/roles/BondedRolesView.java index 1580697bc4..b03fbaae30 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/bonding/roles/BondedRolesView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/bonding/roles/BondedRolesView.java @@ -22,9 +22,7 @@ import bisq.desktop.common.view.FxmlView; import bisq.desktop.components.AutoTooltipLabel; import bisq.desktop.components.AutoTooltipTableColumn; import bisq.desktop.components.HyperlinkWithIcon; -import bisq.desktop.components.TableGroupHeadline; import bisq.desktop.main.dao.bonding.BondingViewUtils; -import bisq.desktop.main.dao.wallet.BsqBalanceUtil; import bisq.desktop.util.GUIUtil; import bisq.core.dao.DaoFacade; @@ -60,6 +58,8 @@ import javafx.util.Callback; import java.util.stream.Collectors; +import static bisq.desktop.util.FormBuilder.addTitledGroupBg; + @FxmlView public class BondedRolesView extends ActivatableView implements DaoStateListener { private TableView tableView; @@ -79,7 +79,6 @@ public class BondedRolesView extends ActivatableView implements @Inject private BondedRolesView(BsqFormatter bsqFormatter, - BsqBalanceUtil bsqBalanceUtil, BondingViewUtils bondingViewUtils, DaoFacade daoFacade, Preferences preferences) { @@ -91,31 +90,23 @@ public class BondedRolesView extends ActivatableView implements @Override public void initialize() { - TableGroupHeadline headline = new TableGroupHeadline(Res.get("dao.bond.table.header")); int gridRow = 0; - GridPane.setRowIndex(headline, gridRow); - GridPane.setMargin(headline, new Insets(0, -10, -10, -10)); - GridPane.setColumnSpan(headline, 2); - root.getChildren().add(headline); + addTitledGroupBg(root, gridRow, 2, Res.get("dao.bond.bondedRoles")); tableView = new TableView<>(); + GridPane.setRowIndex(tableView, ++gridRow); + GridPane.setMargin(tableView, new Insets(30, -10, 5, -10)); + root.getChildren().add(tableView); tableView.setPlaceholder(new AutoTooltipLabel(Res.get("table.placeholder.noData"))); tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); - createColumns(); - - GridPane.setRowIndex(tableView, gridRow); - GridPane.setMargin(tableView, new Insets(20, -10, 5, -10)); - GridPane.setColumnSpan(tableView, 2); - root.getChildren().add(tableView); - - sortedList.comparatorProperty().bind(tableView.comparatorProperty()); tableView.setItems(sortedList); } @Override protected void activate() { daoFacade.addBsqStateListener(this); + sortedList.comparatorProperty().bind(tableView.comparatorProperty()); updateList(); } @@ -123,6 +114,7 @@ public class BondedRolesView extends ActivatableView implements @Override protected void deactivate() { daoFacade.removeBsqStateListener(this); + sortedList.comparatorProperty().unbind(); observableList.forEach(BondedRolesListItem::cleanup); } @@ -226,7 +218,7 @@ public class BondedRolesView extends ActivatableView implements }); tableView.getColumns().add(column); - column = new AutoTooltipTableColumn<>(Res.get("dao.bond.table.column.header.bondedRoleType")); + column = new AutoTooltipTableColumn<>(Res.get("dao.bond.table.column.header.bondType")); column.setCellValueFactory(item -> new ReadOnlyObjectWrapper<>(item.getValue())); column.setMinWidth(80); column.setCellFactory( diff --git a/desktop/src/main/java/bisq/desktop/main/dao/governance/ProposalDisplay.java b/desktop/src/main/java/bisq/desktop/main/dao/governance/ProposalDisplay.java index 0934431aea..b5b3c97161 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/governance/ProposalDisplay.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/governance/ProposalDisplay.java @@ -305,7 +305,7 @@ public class ProposalDisplay { comboBoxValueTextFieldIndex = gridRow; checkNotNull(confiscateBondComboBox, "confiscateBondComboBox must not be null"); - confiscateBondComboBox.setItems(FXCollections.observableArrayList(daoFacade.getAllActiveBonds())); + confiscateBondComboBox.setItems(FXCollections.observableArrayList(daoFacade.getAllBonds())); confiscateBondComboBox.setConverter(new StringConverter<>() { @Override public String toString(Bond bond) {