mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 23:06:39 +01:00
Check that min comp req is more than comp req fee
This commit is contained in:
parent
a5364c9f3f
commit
fa2c33e5d1
8 changed files with 44 additions and 9 deletions
|
@ -1102,7 +1102,7 @@ dao.compensation.create.confirm.info=Requested amount: {0}\n\
|
|||
Are you sure you want to publish the compensation request?
|
||||
dao.compensation.create.missingFunds=You don''t have sufficient funds for creating the compensation request.\n\
|
||||
Missing: {0}
|
||||
|
||||
dao.compensation.create.amountTooLow=You need to request to issue more than {0}
|
||||
|
||||
####################################################################
|
||||
# Windows
|
||||
|
|
|
@ -139,7 +139,7 @@ public class BtcWalletService extends WalletService {
|
|||
// inputs [1-n] BTC inputs for BSQ issuance and miner fee
|
||||
// outputs [0-1] BSQ request fee change output
|
||||
// outputs [1] BSQ issuance output
|
||||
// outputs [0-1] BTC change output from issuance and miner fee inputs
|
||||
// outputs [0-1] BTC change output from issuance and miner fee inputs
|
||||
// outputs [0-1] OP_RETURN with opReturnData
|
||||
// mining fee: BTC mining fee + burned BSQ fee
|
||||
|
||||
|
|
|
@ -141,7 +141,10 @@ public class CompensationRequestManager implements PersistedDataHost, BsqBlockCh
|
|||
}
|
||||
|
||||
public CompensationRequest prepareCompensationRequest(CompensationRequestPayload compensationRequestPayload)
|
||||
throws InsufficientMoneyException, ChangeBelowDustException, TransactionVerificationException, WalletException, IOException {
|
||||
throws InsufficientMoneyException, ChangeBelowDustException, TransactionVerificationException, WalletException, IOException, CompensationAmountException {
|
||||
if (compensationRequestPayload.getRequestedBsq().compareTo(feeService.getCreateCompensationRequestFee()) <= 0) {
|
||||
throw new CompensationAmountException(feeService.getCreateCompensationRequestFee(), compensationRequestPayload.getRequestedBsq());
|
||||
}
|
||||
CompensationRequest compensationRequest = new CompensationRequest(compensationRequestPayload);
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
||||
compensationRequest.setCompensationRequestFee(feeService.getCreateCompensationRequestFee());
|
||||
|
|
|
@ -20,6 +20,7 @@ package io.bisq.gui.main.dao.compensation;
|
|||
import io.bisq.common.locale.Res;
|
||||
import io.bisq.core.btc.wallet.BsqWalletService;
|
||||
import io.bisq.core.dao.compensation.CompensationRequestPayload;
|
||||
import io.bisq.core.provider.fee.FeeService;
|
||||
import io.bisq.gui.components.HyperlinkWithIcon;
|
||||
import io.bisq.gui.components.InputTextField;
|
||||
import io.bisq.gui.components.TxIdTextField;
|
||||
|
@ -27,9 +28,11 @@ import io.bisq.gui.util.BsqFormatter;
|
|||
import io.bisq.gui.util.GUIUtil;
|
||||
import io.bisq.gui.util.Layout;
|
||||
import io.bisq.gui.util.validation.BsqAddressValidator;
|
||||
import io.bisq.gui.util.validation.BsqValidator;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.layout.GridPane;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.bisq.gui.util.FormBuilder.*;
|
||||
|
@ -44,11 +47,13 @@ public class CompensationRequestDisplay {
|
|||
public TextArea descriptionTextArea;
|
||||
private HyperlinkWithIcon linkHyperlinkWithIcon;
|
||||
public TxIdTextField txIdTextField;
|
||||
private FeeService feeService;
|
||||
|
||||
public CompensationRequestDisplay(GridPane gridPane, BsqFormatter bsqFormatter, BsqWalletService bsqWalletService) {
|
||||
public CompensationRequestDisplay(GridPane gridPane, BsqFormatter bsqFormatter, BsqWalletService bsqWalletService, @Nullable FeeService feeService) {
|
||||
this.gridPane = gridPane;
|
||||
this.bsqFormatter = bsqFormatter;
|
||||
this.bsqWalletService = bsqWalletService;
|
||||
this.feeService = feeService;
|
||||
}
|
||||
|
||||
public void createAllFields(String title, double top) {
|
||||
|
@ -64,7 +69,11 @@ public class CompensationRequestDisplay {
|
|||
linkHyperlinkWithIcon.setManaged(false);
|
||||
linkInputTextField.setPromptText(Res.get("dao.compensation.display.link.prompt"));
|
||||
requestedBsqTextField = addLabelInputTextField(gridPane, ++gridRow, Res.get("dao.compensation.display.requestedBsq")).second;
|
||||
|
||||
if (feeService != null) {
|
||||
BsqValidator bsqValidator = new BsqValidator(bsqFormatter);
|
||||
bsqValidator.setMinCompensationRequest(feeService.getCreateCompensationRequestFee());
|
||||
requestedBsqTextField.setValidator(bsqValidator);
|
||||
}
|
||||
// TODO validator, addressTF
|
||||
bsqAddressTextField = addLabelInputTextField(gridPane, ++gridRow,
|
||||
Res.get("dao.compensation.display.bsqAddress")).second;
|
||||
|
|
|
@ -306,7 +306,7 @@ public class ActiveCompensationRequestView extends ActivatableView<SplitPane, Vo
|
|||
AnchorPane.setTopAnchor(detailsGridPane, -20d);
|
||||
bottomAnchorPane.getChildren().add(detailsGridPane);
|
||||
|
||||
compensationRequestDisplay = new CompensationRequestDisplay(detailsGridPane, bsqFormatter, bsqWalletService);
|
||||
compensationRequestDisplay = new CompensationRequestDisplay(detailsGridPane, bsqFormatter, bsqWalletService, null);
|
||||
}
|
||||
compensationRequestDisplay.removeAllFields();
|
||||
compensationRequestDisplay.createAllFields(Res.get("dao.compensation.active.selectedRequest"), Layout.GROUP_DISTANCE);
|
||||
|
|
|
@ -23,6 +23,7 @@ import io.bisq.common.locale.Res;
|
|||
import io.bisq.core.btc.exceptions.TransactionVerificationException;
|
||||
import io.bisq.core.btc.exceptions.WalletException;
|
||||
import io.bisq.core.btc.wallet.*;
|
||||
import io.bisq.core.dao.compensation.CompensationAmountException;
|
||||
import io.bisq.core.dao.compensation.CompensationRequest;
|
||||
import io.bisq.core.dao.compensation.CompensationRequestManager;
|
||||
import io.bisq.core.dao.compensation.CompensationRequestPayload;
|
||||
|
@ -98,7 +99,7 @@ public class CreateCompensationRequestView extends ActivatableView<GridPane, Voi
|
|||
|
||||
@Override
|
||||
public void initialize() {
|
||||
compensationRequestDisplay = new CompensationRequestDisplay(root, bsqFormatter, bsqWalletService);
|
||||
compensationRequestDisplay = new CompensationRequestDisplay(root, bsqFormatter, bsqWalletService, feeService);
|
||||
compensationRequestDisplay.createAllFields(Res.get("dao.compensation.create.createNew"), 0);
|
||||
createButton = addButtonAfterGroup(root, compensationRequestDisplay.incrementAndGetGridRow(), Res.get("dao.compensation.create.create.button"));
|
||||
}
|
||||
|
@ -158,6 +159,8 @@ public class CreateCompensationRequestView extends ActivatableView<GridPane, Voi
|
|||
} catch (InsufficientMoneyException e) {
|
||||
BSFormatter formatter = e instanceof InsufficientBsqException ? bsqFormatter : btcFormatter;
|
||||
new Popup<>().warning(Res.get("dao.compensation.create.missingFunds", formatter.formatCoinWithCode(e.missing))).show();
|
||||
} catch (CompensationAmountException e) {
|
||||
new Popup<>().warning(Res.get("dao.compensation.create.amountTooLow", bsqFormatter.formatCoinWithCode(e.neededAmount))).show();
|
||||
} catch (IOException | TransactionVerificationException | WalletException | ChangeBelowDustException e) {
|
||||
log.error(e.toString());
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -118,7 +118,7 @@ public class CompensationViewItem {
|
|||
AnchorPane.setLeftAnchor(gridPane, 25d);
|
||||
AnchorPane.setTopAnchor(gridPane, -20d);
|
||||
|
||||
CompensationRequestDisplay compensationRequestDisplay = new CompensationRequestDisplay(gridPane, bsqFormatter, bsqWalletService);
|
||||
CompensationRequestDisplay compensationRequestDisplay = new CompensationRequestDisplay(gridPane, bsqFormatter, bsqWalletService, null);
|
||||
compensationRequestDisplay.createAllFields(Res.get("dao.voting.item.title"), Layout.GROUP_DISTANCE);
|
||||
compensationRequestDisplay.setAllFieldsEditable(false);
|
||||
compensationRequestDisplay.fillWithData(compensationRequestPayload);
|
||||
|
|
|
@ -36,6 +36,8 @@ public class BsqValidator extends AltcoinValidator {
|
|||
protected Coin maxValue;
|
||||
@Nullable
|
||||
private Coin availableBalance;
|
||||
@Nullable
|
||||
private Coin minCompensationRequest;
|
||||
|
||||
@Override
|
||||
protected double getMinValue() {
|
||||
|
@ -49,6 +51,10 @@ public class BsqValidator extends AltcoinValidator {
|
|||
//setMaxValue(bsqFormatter.parseToCoin("2500000"));
|
||||
}
|
||||
|
||||
public void setMinCompensationRequest(@NotNull Coin minCompensationRequest) {
|
||||
this.minCompensationRequest = minCompensationRequest;
|
||||
}
|
||||
|
||||
public void setMaxValue(@NotNull Coin maxValue) {
|
||||
this.maxValue = maxValue;
|
||||
}
|
||||
|
@ -71,7 +77,8 @@ public class BsqValidator extends AltcoinValidator {
|
|||
.and(validateIfNotFractionalBtcValue(input))
|
||||
.and(validateIfNotExceedsMaxBtcValue(input))
|
||||
.and(validateIfSufficientAvailableBalance(input))
|
||||
.and(validateIfAboveDust(input));
|
||||
.and(validateIfAboveDust(input))
|
||||
.and(validateIfMoreThanMinCompensationRequest(input));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -118,4 +125,17 @@ public class BsqValidator extends AltcoinValidator {
|
|||
return new ValidationResult(false, Res.get("validation.invalidInput", t.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
protected ValidationResult validateIfMoreThanMinCompensationRequest(String input) {
|
||||
try {
|
||||
final Coin coin = bsqFormatter.parseToCoin(input);
|
||||
if (minCompensationRequest != null && coin.compareTo(minCompensationRequest) <= 0)
|
||||
return new ValidationResult(false, Res.get("dao.compensation.create.amountTooLow",
|
||||
bsqFormatter.formatCoinWithCode(minCompensationRequest)));
|
||||
else
|
||||
return new ValidationResult(true);
|
||||
} catch (Throwable t) {
|
||||
return new ValidationResult(false, Res.get("validation.invalidInput", t.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue