Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show warning for bonded role if user has insufficient funds #2386

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,7 @@ dao.proposal.create.phase.inactive=Please wait until the next proposal phase
dao.proposal.create.proposalType=Proposal type
dao.proposal.create.createNew=Make new proposal
dao.proposal.create.create.button=Make proposal
dao.proposal.create.publish=Publish proposal
dao.proposal=proposal
dao.proposal.display.type=Proposal type
dao.proposal.display.name=Name/nickname
Expand Down Expand Up @@ -1745,6 +1746,11 @@ dao.proposal.create.missingBsqFunds=You don''t have sufficient BSQ funds for cre
unconfirmed BSQ transaction you need to wait for a blockchain confirmation because BSQ is validated only if it is \
included in a block.\n\
Missing: {0}

dao.proposal.create.missingBsqFundsForBond=You don''t have sufficient BSQ funds for this role. You can still \
publish this proposal, but you''ll need the full BSQ amount required for this role if it gets accepted. \n\
Missing: {0}

dao.proposal.create.missingMinerFeeFunds=You don''t have sufficient BTC funds for creating the proposal transaction. \
Any BSQ transaction require also a miner fee in BTC.\n\
Missing: {0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import bisq.core.btc.exceptions.InsufficientBsqException;
import bisq.core.btc.setup.WalletsSetup;
import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.dao.DaoFacade;
import bisq.core.dao.exceptions.ValidationException;
import bisq.core.dao.governance.bond.Bond;
Expand Down Expand Up @@ -100,6 +101,7 @@ public class MakeProposalView extends ActivatableView<GridPane, Void> implements
private final BSFormatter btcFormatter;
private final BsqFormatter bsqFormatter;
private final Navigation navigation;
private final BsqWalletService bsqWalletService;

@Nullable
private ProposalDisplay proposalDisplay;
Expand Down Expand Up @@ -127,6 +129,7 @@ public class MakeProposalView extends ActivatableView<GridPane, Void> implements
private MakeProposalView(DaoFacade daoFacade,
WalletsSetup walletsSetup,
P2PService p2PService,
BsqWalletService bsqWalletService,
PhasesView phasesView,
ChangeParamValidator changeParamValidator,
BSFormatter btcFormatter,
Expand All @@ -135,6 +138,7 @@ private MakeProposalView(DaoFacade daoFacade,
this.daoFacade = daoFacade;
this.walletsSetup = walletsSetup;
this.p2PService = p2PService;
this.bsqWalletService = bsqWalletService;
this.phasesView = phasesView;
this.changeParamValidator = changeParamValidator;
this.btcFormatter = btcFormatter;
Expand Down Expand Up @@ -268,11 +272,22 @@ private void publishMyProposal(ProposalType type) {
int txSize = transaction.bitcoinSerialize().length;
Coin fee = daoFacade.getProposalFee(daoFacade.getChainHeight());

if (!DevEnv.isDevMode()) {
GUIUtil.showBsqFeeInfoPopup(fee, miningFee, txSize, bsqFormatter, btcFormatter,
Res.get("dao.proposal"), () -> doPublishMyProposal(proposal, transaction));
if (type.equals(ProposalType.BONDED_ROLE)) {
final long requiredBond = proposalDisplay.bondedRoleTypeComboBox.getSelectionModel().getSelectedItem().getRequiredBond();
final long availableBalance = bsqWalletService.getAvailableBalance().value;

if (requiredBond > availableBalance) {
final long missing = requiredBond - availableBalance;
new Popup<>().warning(Res.get("dao.proposal.create.missingBsqFundsForBond",
bsqFormatter.formatCoinWithCode(missing)))
.actionButtonText(Res.get("dao.proposal.create.publish"))
.onAction(() -> {
showFeeInfoAndPublishMyProposal(proposal, transaction, miningFee, txSize, fee);
})
.show();
}
} else {
doPublishMyProposal(proposal, transaction);
showFeeInfoAndPublishMyProposal(proposal, transaction, miningFee, txSize, fee);
}
} catch (InsufficientMoneyException e) {
if (e instanceof InsufficientBsqException) {
Expand All @@ -299,6 +314,15 @@ private void publishMyProposal(ProposalType type) {
}
}

private void showFeeInfoAndPublishMyProposal(Proposal proposal, Transaction transaction, Coin miningFee, int txSize, Coin fee) {
if (!DevEnv.isDevMode()) {
GUIUtil.showBsqFeeInfoPopup(fee, miningFee, txSize, bsqFormatter, btcFormatter,
Res.get("dao.proposal"), () -> doPublishMyProposal(proposal, transaction));
} else {
doPublishMyProposal(proposal, transaction);
}
}

private void doPublishMyProposal(Proposal proposal, Transaction transaction) {
daoFacade.publishMyProposal(proposal,
transaction,
Expand Down