mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 23:06:39 +01:00
Handle merits better
We did not update the merit correctly in case there was no proposal selected.
This commit is contained in:
parent
69b134b99e
commit
d422a732e7
1 changed files with 46 additions and 36 deletions
|
@ -40,6 +40,7 @@ import bisq.core.btc.listeners.BsqBalanceListener;
|
||||||
import bisq.core.btc.wallet.BsqWalletService;
|
import bisq.core.btc.wallet.BsqWalletService;
|
||||||
import bisq.core.dao.DaoFacade;
|
import bisq.core.dao.DaoFacade;
|
||||||
import bisq.core.dao.governance.blindvote.BlindVoteConsensus;
|
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.governance.myvote.MyVote;
|
||||||
import bisq.core.dao.state.DaoStateListener;
|
import bisq.core.dao.state.DaoStateListener;
|
||||||
import bisq.core.dao.state.DaoStateService;
|
import bisq.core.dao.state.DaoStateService;
|
||||||
|
@ -113,6 +114,7 @@ public class ProposalsView extends ActivatableView<GridPane, Void> implements Bs
|
||||||
private final BsqWalletService bsqWalletService;
|
private final BsqWalletService bsqWalletService;
|
||||||
private final PhasesView phasesView;
|
private final PhasesView phasesView;
|
||||||
private final DaoStateService daoStateService;
|
private final DaoStateService daoStateService;
|
||||||
|
private final MyBlindVoteListService myBlindVoteListService;
|
||||||
private final Preferences preferences;
|
private final Preferences preferences;
|
||||||
private final BsqFormatter bsqFormatter;
|
private final BsqFormatter bsqFormatter;
|
||||||
private final BSFormatter btcFormatter;
|
private final BSFormatter btcFormatter;
|
||||||
|
@ -162,6 +164,7 @@ public class ProposalsView extends ActivatableView<GridPane, Void> implements Bs
|
||||||
BsqWalletService bsqWalletService,
|
BsqWalletService bsqWalletService,
|
||||||
PhasesView phasesView,
|
PhasesView phasesView,
|
||||||
DaoStateService daoStateService,
|
DaoStateService daoStateService,
|
||||||
|
MyBlindVoteListService myBlindVoteListService,
|
||||||
Preferences preferences,
|
Preferences preferences,
|
||||||
BsqFormatter bsqFormatter,
|
BsqFormatter bsqFormatter,
|
||||||
BSFormatter btcFormatter,
|
BSFormatter btcFormatter,
|
||||||
|
@ -170,6 +173,7 @@ public class ProposalsView extends ActivatableView<GridPane, Void> implements Bs
|
||||||
this.bsqWalletService = bsqWalletService;
|
this.bsqWalletService = bsqWalletService;
|
||||||
this.phasesView = phasesView;
|
this.phasesView = phasesView;
|
||||||
this.daoStateService = daoStateService;
|
this.daoStateService = daoStateService;
|
||||||
|
this.myBlindVoteListService = myBlindVoteListService;
|
||||||
this.preferences = preferences;
|
this.preferences = preferences;
|
||||||
this.bsqFormatter = bsqFormatter;
|
this.bsqFormatter = bsqFormatter;
|
||||||
this.btcFormatter = btcFormatter;
|
this.btcFormatter = btcFormatter;
|
||||||
|
@ -197,15 +201,12 @@ public class ProposalsView extends ActivatableView<GridPane, Void> implements Bs
|
||||||
protected void activate() {
|
protected void activate() {
|
||||||
phasesView.activate();
|
phasesView.activate();
|
||||||
|
|
||||||
phaseSubscription = EasyBind.subscribe(daoFacade.phaseProperty(), this::onPhaseChanged);
|
|
||||||
selectedProposalSubscription = EasyBind.subscribe(tableView.getSelectionModel().selectedItemProperty(), this::onSelectProposal);
|
selectedProposalSubscription = EasyBind.subscribe(tableView.getSelectionModel().selectedItemProperty(), this::onSelectProposal);
|
||||||
|
|
||||||
sortedList.comparatorProperty().bind(tableView.comparatorProperty());
|
sortedList.comparatorProperty().bind(tableView.comparatorProperty());
|
||||||
|
tableView.setPrefHeight(100);
|
||||||
daoFacade.getActiveOrMyUnconfirmedProposals().addListener(proposalListChangeListener);
|
root.getScene().heightProperty().addListener(sceneHeightListener);
|
||||||
daoFacade.getAllBallots().addListener(ballotListChangeListener);
|
UserThread.execute(() -> updateTableHeight(root.getScene().getHeight()));
|
||||||
daoFacade.addBsqStateListener(this);
|
|
||||||
bsqWalletService.addBsqBalanceListener(this);
|
|
||||||
|
|
||||||
stakeInputTextField.textProperty().addListener(stakeListener);
|
stakeInputTextField.textProperty().addListener(stakeListener);
|
||||||
voteButton.setOnAction(e -> onVote());
|
voteButton.setOnAction(e -> onVote());
|
||||||
|
@ -218,21 +219,20 @@ public class ProposalsView extends ActivatableView<GridPane, Void> implements Bs
|
||||||
bsqWalletService.getLockupBondsBalance(),
|
bsqWalletService.getLockupBondsBalance(),
|
||||||
bsqWalletService.getUnlockingBondsBalance());
|
bsqWalletService.getUnlockingBondsBalance());
|
||||||
|
|
||||||
updateListItems();
|
if (daoStateService.isParseBlockChainComplete()) {
|
||||||
tableView.setPrefHeight(100);
|
addListenersAfterParseBlockChainComplete();
|
||||||
updateViews();
|
|
||||||
|
|
||||||
updateListItems();
|
updateListItems();
|
||||||
applyMerit();
|
applyMerit();
|
||||||
|
updateViews();
|
||||||
root.getScene().heightProperty().addListener(sceneHeightListener);
|
}
|
||||||
UserThread.execute(() -> updateTableHeight(root.getScene().getHeight()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void deactivate() {
|
protected void deactivate() {
|
||||||
phasesView.deactivate();
|
phasesView.deactivate();
|
||||||
|
|
||||||
|
if (phaseSubscription != null)
|
||||||
phaseSubscription.unsubscribe();
|
phaseSubscription.unsubscribe();
|
||||||
selectedProposalSubscription.unsubscribe();
|
selectedProposalSubscription.unsubscribe();
|
||||||
|
|
||||||
|
@ -284,20 +284,36 @@ public class ProposalsView extends ActivatableView<GridPane, Void> implements Bs
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onParseBlockCompleteAfterBatchProcessing(Block block) {
|
public void onParseBlockCompleteAfterBatchProcessing(Block block) {
|
||||||
updateViews();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onParseBlockChainComplete() {
|
|
||||||
updateListItems();
|
updateListItems();
|
||||||
applyMerit();
|
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() {
|
private void fillListItems() {
|
||||||
if (daoFacade.phaseProperty().get().ordinal() < DaoPhase.Phase.BLIND_VOTE.ordinal()) {
|
if (daoFacade.phaseProperty().get().ordinal() < DaoPhase.Phase.BLIND_VOTE.ordinal()) {
|
||||||
// proposal phase
|
// proposal phase
|
||||||
|
@ -316,16 +332,8 @@ public class ProposalsView extends ActivatableView<GridPane, Void> implements Bs
|
||||||
updateViews();
|
updateViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateListItems() {
|
|
||||||
listItems.forEach(ProposalsListItem::cleanup);
|
|
||||||
listItems.clear();
|
|
||||||
|
|
||||||
fillListItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showVoteOnProposalWindow(Proposal proposal, @Nullable Ballot ballot,
|
private void showVoteOnProposalWindow(Proposal proposal, @Nullable Ballot ballot,
|
||||||
@Nullable EvaluatedProposal evaluatedProposal) {
|
@Nullable EvaluatedProposal evaluatedProposal) {
|
||||||
|
|
||||||
if (!shownVoteOnProposalWindowForTxId.equals(proposal.getTxId())) {
|
if (!shownVoteOnProposalWindowForTxId.equals(proposal.getTxId())) {
|
||||||
shownVoteOnProposalWindowForTxId = proposal.getTxId();
|
shownVoteOnProposalWindowForTxId = proposal.getTxId();
|
||||||
|
|
||||||
|
@ -404,13 +412,15 @@ public class ProposalsView extends ActivatableView<GridPane, Void> implements Bs
|
||||||
// use the merit based on all past issuance with the time decay applied.
|
// 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()
|
// 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).
|
// decreases with every block a bit (over 2 years it goes to zero).
|
||||||
boolean hasConfirmedVoteTxInCycle = daoFacade.getMyVoteListForCycle().stream()
|
Optional<MyVote> optionalMyVote = daoFacade.getMyVoteListForCycle().stream()
|
||||||
.map(myVote -> daoFacade.getTx(myVote.getTxId()))
|
.filter(myVote -> daoFacade.getTx(myVote.getBlindVoteTxId()).isPresent())
|
||||||
.findAny()
|
.findAny();
|
||||||
.isPresent();
|
boolean hasConfirmedMyVoteInCycle = optionalMyVote.isPresent();
|
||||||
long merit;
|
long merit;
|
||||||
if (selectedItem != null && hasConfirmedVoteTxInCycle) {
|
if (selectedItem != null && hasConfirmedMyVoteInCycle) {
|
||||||
merit = daoFacade.getMeritAndStakeForProposal(selectedItem.getProposal().getTxId()).first;
|
merit = daoFacade.getMeritAndStakeForProposal(selectedItem.getProposal().getTxId()).first;
|
||||||
|
} else if (selectedItem == null && hasConfirmedMyVoteInCycle) {
|
||||||
|
merit = optionalMyVote.get().getMerit(myBlindVoteListService, daoStateService);
|
||||||
} else {
|
} else {
|
||||||
merit = daoFacade.getAvailableMerit();
|
merit = daoFacade.getAvailableMerit();
|
||||||
}
|
}
|
||||||
|
@ -540,8 +550,8 @@ public class ProposalsView extends ActivatableView<GridPane, Void> implements Bs
|
||||||
Coin stake = Coin.valueOf(myVote.getBlindVote().getStake());
|
Coin stake = Coin.valueOf(myVote.getBlindVote().getStake());
|
||||||
stakeInputTextField.setText(bsqFormatter.formatCoinWithCode(stake));
|
stakeInputTextField.setText(bsqFormatter.formatCoinWithCode(stake));
|
||||||
|
|
||||||
if (myVote.getTxId() != null) {
|
if (myVote.getBlindVoteTxId() != null) {
|
||||||
blindVoteTxIdTextField.setup(myVote.getTxId());
|
blindVoteTxIdTextField.setup(myVote.getBlindVoteTxId());
|
||||||
blindVoteTxIdContainer.setVisible(true);
|
blindVoteTxIdContainer.setVisible(true);
|
||||||
blindVoteTxIdContainer.setManaged(true);
|
blindVoteTxIdContainer.setManaged(true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue