diff --git a/desktop/src/main/java/bisq/desktop/main/dao/governance/proposals/ProposalsView.java b/desktop/src/main/java/bisq/desktop/main/dao/governance/proposals/ProposalsView.java index a1f658709b..7a7da8268f 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/governance/proposals/ProposalsView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/governance/proposals/ProposalsView.java @@ -40,6 +40,7 @@ import bisq.core.btc.listeners.BsqBalanceListener; import bisq.core.btc.wallet.BsqWalletService; import bisq.core.dao.DaoFacade; import bisq.core.dao.governance.blindvote.BlindVoteConsensus; +import bisq.core.dao.governance.blindvote.MyBlindVoteListService; import bisq.core.dao.governance.myvote.MyVote; import bisq.core.dao.state.DaoStateListener; import bisq.core.dao.state.DaoStateService; @@ -113,6 +114,7 @@ public class ProposalsView extends ActivatableView implements Bs private final BsqWalletService bsqWalletService; private final PhasesView phasesView; private final DaoStateService daoStateService; + private final MyBlindVoteListService myBlindVoteListService; private final Preferences preferences; private final BsqFormatter bsqFormatter; private final BSFormatter btcFormatter; @@ -162,6 +164,7 @@ public class ProposalsView extends ActivatableView implements Bs BsqWalletService bsqWalletService, PhasesView phasesView, DaoStateService daoStateService, + MyBlindVoteListService myBlindVoteListService, Preferences preferences, BsqFormatter bsqFormatter, BSFormatter btcFormatter, @@ -170,6 +173,7 @@ public class ProposalsView extends ActivatableView implements Bs this.bsqWalletService = bsqWalletService; this.phasesView = phasesView; this.daoStateService = daoStateService; + this.myBlindVoteListService = myBlindVoteListService; this.preferences = preferences; this.bsqFormatter = bsqFormatter; this.btcFormatter = btcFormatter; @@ -197,15 +201,12 @@ public class ProposalsView extends ActivatableView implements Bs protected void activate() { phasesView.activate(); - phaseSubscription = EasyBind.subscribe(daoFacade.phaseProperty(), this::onPhaseChanged); selectedProposalSubscription = EasyBind.subscribe(tableView.getSelectionModel().selectedItemProperty(), this::onSelectProposal); sortedList.comparatorProperty().bind(tableView.comparatorProperty()); - - daoFacade.getActiveOrMyUnconfirmedProposals().addListener(proposalListChangeListener); - daoFacade.getAllBallots().addListener(ballotListChangeListener); - daoFacade.addBsqStateListener(this); - bsqWalletService.addBsqBalanceListener(this); + tableView.setPrefHeight(100); + root.getScene().heightProperty().addListener(sceneHeightListener); + UserThread.execute(() -> updateTableHeight(root.getScene().getHeight())); stakeInputTextField.textProperty().addListener(stakeListener); voteButton.setOnAction(e -> onVote()); @@ -218,22 +219,21 @@ public class ProposalsView extends ActivatableView implements Bs bsqWalletService.getLockupBondsBalance(), bsqWalletService.getUnlockingBondsBalance()); - updateListItems(); - tableView.setPrefHeight(100); - updateViews(); + if (daoStateService.isParseBlockChainComplete()) { + addListenersAfterParseBlockChainComplete(); - updateListItems(); - applyMerit(); - - root.getScene().heightProperty().addListener(sceneHeightListener); - UserThread.execute(() -> updateTableHeight(root.getScene().getHeight())); + updateListItems(); + applyMerit(); + updateViews(); + } } @Override protected void deactivate() { phasesView.deactivate(); - phaseSubscription.unsubscribe(); + if (phaseSubscription != null) + phaseSubscription.unsubscribe(); selectedProposalSubscription.unsubscribe(); sortedList.comparatorProperty().unbind(); @@ -284,20 +284,36 @@ public class ProposalsView extends ActivatableView implements Bs @Override public void onParseBlockCompleteAfterBatchProcessing(Block block) { - updateViews(); - } - - @Override - public void onParseBlockChainComplete() { updateListItems(); applyMerit(); } + @Override + public void onParseBlockChainComplete() { + addListenersAfterParseBlockChainComplete(); + } + /////////////////////////////////////////////////////////////////////////////////////////// - // Protected + // Private /////////////////////////////////////////////////////////////////////////////////////////// + private void addListenersAfterParseBlockChainComplete() { + daoFacade.getActiveOrMyUnconfirmedProposals().addListener(proposalListChangeListener); + daoFacade.getAllBallots().addListener(ballotListChangeListener); + daoFacade.addBsqStateListener(this); + bsqWalletService.addBsqBalanceListener(this); + + phaseSubscription = EasyBind.subscribe(daoFacade.phaseProperty(), this::onPhaseChanged); + } + + private void updateListItems() { + listItems.forEach(ProposalsListItem::cleanup); + listItems.clear(); + + fillListItems(); + } + private void fillListItems() { if (daoFacade.phaseProperty().get().ordinal() < DaoPhase.Phase.BLIND_VOTE.ordinal()) { // proposal phase @@ -316,16 +332,8 @@ public class ProposalsView extends ActivatableView implements Bs updateViews(); } - private void updateListItems() { - listItems.forEach(ProposalsListItem::cleanup); - listItems.clear(); - - fillListItems(); - } - private void showVoteOnProposalWindow(Proposal proposal, @Nullable Ballot ballot, @Nullable EvaluatedProposal evaluatedProposal) { - if (!shownVoteOnProposalWindowForTxId.equals(proposal.getTxId())) { shownVoteOnProposalWindowForTxId = proposal.getTxId(); @@ -404,13 +412,15 @@ public class ProposalsView extends ActivatableView implements Bs // use the merit based on all past issuance with the time decay applied. // The merit from the vote stays the same over blocks, the merit from daoFacade.getMeritAndStake() // decreases with every block a bit (over 2 years it goes to zero). - boolean hasConfirmedVoteTxInCycle = daoFacade.getMyVoteListForCycle().stream() - .map(myVote -> daoFacade.getTx(myVote.getTxId())) - .findAny() - .isPresent(); + Optional optionalMyVote = daoFacade.getMyVoteListForCycle().stream() + .filter(myVote -> daoFacade.getTx(myVote.getBlindVoteTxId()).isPresent()) + .findAny(); + boolean hasConfirmedMyVoteInCycle = optionalMyVote.isPresent(); long merit; - if (selectedItem != null && hasConfirmedVoteTxInCycle) { + if (selectedItem != null && hasConfirmedMyVoteInCycle) { merit = daoFacade.getMeritAndStakeForProposal(selectedItem.getProposal().getTxId()).first; + } else if (selectedItem == null && hasConfirmedMyVoteInCycle) { + merit = optionalMyVote.get().getMerit(myBlindVoteListService, daoStateService); } else { merit = daoFacade.getAvailableMerit(); } @@ -540,8 +550,8 @@ public class ProposalsView extends ActivatableView implements Bs Coin stake = Coin.valueOf(myVote.getBlindVote().getStake()); stakeInputTextField.setText(bsqFormatter.formatCoinWithCode(stake)); - if (myVote.getTxId() != null) { - blindVoteTxIdTextField.setup(myVote.getTxId()); + if (myVote.getBlindVoteTxId() != null) { + blindVoteTxIdTextField.setup(myVote.getBlindVoteTxId()); blindVoteTxIdContainer.setVisible(true); blindVoteTxIdContainer.setManaged(true); }