Add check for payments which would result in unspendable rest for seller (fee+dust)

This commit is contained in:
Manfred Karrer 2016-01-30 23:29:25 +01:00
parent 26270b209a
commit d933110a8d
4 changed files with 17 additions and 6 deletions

View File

@ -40,6 +40,7 @@ import javafx.beans.property.*;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.utils.ExchangeRate;
import org.bitcoinj.utils.Fiat;
import org.jetbrains.annotations.NotNull;
@ -289,6 +290,16 @@ class TakeOfferDataModel extends ActivatableDataModel {
return true;
}
boolean isAmountLargerThanOfferAmountMinusFee() {
//noinspection SimplifiableIfStatement
if (amountAsCoin.get() != null && offer != null)
return amountAsCoin.get()
.add(FeePolicy.getFeePerKb())
.add(Transaction.MIN_NONDUST_OUTPUT)
.isGreaterThan(offer.getAmount());
return true;
}
public PaymentMethod getPaymentMethod() {
return offer.getPaymentMethod();
}

View File

@ -22,7 +22,6 @@ import de.jensd.fx.fontawesome.AwesomeIcon;
import io.bitsquare.app.BitsquareApp;
import io.bitsquare.common.util.Tuple2;
import io.bitsquare.common.util.Tuple3;
import io.bitsquare.common.util.Utilities;
import io.bitsquare.gui.Navigation;
import io.bitsquare.gui.common.view.ActivatableViewAndModel;
import io.bitsquare.gui.common.view.FxmlView;
@ -485,11 +484,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
totalToPayTextField.setFocusTraversable(false);
totalToPayTextField.setVisible(false);
totalToPayTextField.setPromptText(BSResources.get("createOffer.fundsBox.totalsNeeded.prompt"));
totalToPayTextField.setHandler(value -> {
String[] strings = value.split(" ");
if (strings.length > 1)
Utilities.copyToClipboard(strings[0]); // exclude the BTC postfix
});
totalToPayTextField.setCopyWithoutCurrencyPostFix(true);
GridPane.setRowIndex(totalToPayTextField, gridRow);
GridPane.setColumnIndex(totalToPayTextField, 1);
GridPane.setMargin(totalToPayTextField, new Insets(Layout.FIRST_ROW_AND_GROUP_DISTANCE, 0, 0, 0));

View File

@ -223,6 +223,10 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
if (dataModel.isAmountLargerThanOfferAmount())
amountValidationResult.set(new InputValidator.ValidationResult(false,
BSResources.get("takeOffer.validation.amountLargerThanOfferAmount")));
if (dataModel.isAmountLargerThanOfferAmountMinusFee())
amountValidationResult.set(new InputValidator.ValidationResult(false,
BSResources.get("takeOffer.validation.amountLargerThanOfferAmountMinusFee")));
}
}
}

View File

@ -101,6 +101,7 @@ takeOffer.amountPriceBox.next=Next step
takeOffer.amountPriceBox.warning.invalidBtcDecimalPlaces=The amount you have entered exceeds the number of allowed decimal places.\nThe amount has been adjusted to 4 decimal places.
takeOffer.validation.amountSmallerThanMinAmount=Amount cannot be smaller than minimum amount defined in the offer.
takeOffer.validation.amountLargerThanOfferAmount=Input amount cannot be higher than the amount defined in the offer.
takeOffer.validation.amountLargerThanOfferAmountMinusFee=That input amount would create a dust change for the seller.
takeOffer.fundsBox.title=Fund your trade wallet
takeOffer.fundsBox.isOfferAvailable=Check if offer is available...