Skip to content

Commit

Permalink
Merge pull request #2386 from ripcurlx/add-warning-for-bonded-role-if…
Browse files Browse the repository at this point in the history
…-insufficient-funds

Show warning for bonded role if user has insufficient funds
  • Loading branch information
ripcurlx authored Feb 11, 2019
2 parents 8cdc759 + fd3e947 commit a47f1de
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
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 @@ -1597,6 +1597,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 @@ -1749,6 +1750,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 @@ -101,6 +102,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 @@ -128,6 +130,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 @@ -136,6 +139,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 @@ -265,11 +269,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 @@ -296,6 +311,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

0 comments on commit a47f1de

Please sign in to comment.