mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-19 23:36:00 -04:00
put trade price into trade and contract
This commit is contained in:
parent
13a62b1342
commit
bc07df2d7a
@ -43,8 +43,8 @@ public final class BuyerAsTakerTrade extends BuyerTrade implements TakerTrade {
|
||||
// Constructor, initialization
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public BuyerAsTakerTrade(Offer offer, Coin tradeAmount, NodeAddress tradingPeerNodeAddress, Storage<? extends TradableList> storage) {
|
||||
super(offer, tradeAmount, tradingPeerNodeAddress, storage);
|
||||
public BuyerAsTakerTrade(Offer offer, Coin tradeAmount, long tradePrice, NodeAddress tradingPeerNodeAddress, Storage<? extends TradableList> storage) {
|
||||
super(offer, tradeAmount, tradePrice, tradingPeerNodeAddress, storage);
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
|
@ -38,8 +38,8 @@ public abstract class BuyerTrade extends Trade {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BuyerAsOffererTrade.class);
|
||||
|
||||
BuyerTrade(Offer offer, Coin tradeAmount, NodeAddress tradingPeerNodeAddress, Storage<? extends TradableList> storage) {
|
||||
super(offer, tradeAmount, tradingPeerNodeAddress, storage);
|
||||
BuyerTrade(Offer offer, Coin tradeAmount, long tradePrice, NodeAddress tradingPeerNodeAddress, Storage<? extends TradableList> storage) {
|
||||
super(offer, tradeAmount, tradePrice, tradingPeerNodeAddress, storage);
|
||||
}
|
||||
|
||||
BuyerTrade(Offer offer, Storage<? extends TradableList> storage) {
|
||||
@ -65,7 +65,7 @@ public abstract class BuyerTrade extends Trade {
|
||||
log::warn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Coin getPayoutAmount() {
|
||||
checkNotNull(getTradeAmount(), "Invalid state: getTradeAmount() = null");
|
||||
|
@ -25,6 +25,7 @@ import io.bitsquare.p2p.NodeAddress;
|
||||
import io.bitsquare.payment.PaymentAccountContractData;
|
||||
import io.bitsquare.trade.offer.Offer;
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.utils.Fiat;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import java.util.Arrays;
|
||||
@ -40,6 +41,7 @@ public final class Contract implements Payload {
|
||||
|
||||
public final Offer offer;
|
||||
private final long tradeAmount;
|
||||
private final long tradePrice;
|
||||
public final String takeOfferFeeTxID;
|
||||
public final NodeAddress arbitratorNodeAddress;
|
||||
private final boolean isBuyerOffererAndSellerTaker;
|
||||
@ -64,6 +66,7 @@ public final class Contract implements Payload {
|
||||
|
||||
public Contract(Offer offer,
|
||||
Coin tradeAmount,
|
||||
Fiat tradePrice,
|
||||
String takeOfferFeeTxID,
|
||||
NodeAddress buyerNodeAddress,
|
||||
NodeAddress sellerNodeAddress,
|
||||
@ -80,6 +83,7 @@ public final class Contract implements Payload {
|
||||
byte[] offererBtcPubKey,
|
||||
byte[] takerBtcPubKey) {
|
||||
this.offer = offer;
|
||||
this.tradePrice = tradePrice.value;
|
||||
this.buyerNodeAddress = buyerNodeAddress;
|
||||
this.sellerNodeAddress = sellerNodeAddress;
|
||||
this.tradeAmount = tradeAmount.value;
|
||||
@ -154,6 +158,10 @@ public final class Contract implements Payload {
|
||||
return Coin.valueOf(tradeAmount);
|
||||
}
|
||||
|
||||
public Fiat getTradePrice() {
|
||||
return Fiat.valueOf(offer.getCurrencyCode(), tradePrice);
|
||||
}
|
||||
|
||||
public NodeAddress getBuyerNodeAddress() {
|
||||
return buyerNodeAddress;
|
||||
}
|
||||
@ -171,6 +179,7 @@ public final class Contract implements Payload {
|
||||
Contract contract = (Contract) o;
|
||||
|
||||
if (tradeAmount != contract.tradeAmount) return false;
|
||||
if (tradePrice != contract.tradePrice) return false;
|
||||
if (isBuyerOffererAndSellerTaker != contract.isBuyerOffererAndSellerTaker) return false;
|
||||
if (offer != null ? !offer.equals(contract.offer) : contract.offer != null) return false;
|
||||
if (takeOfferFeeTxID != null ? !takeOfferFeeTxID.equals(contract.takeOfferFeeTxID) : contract.takeOfferFeeTxID != null)
|
||||
@ -206,6 +215,7 @@ public final class Contract implements Payload {
|
||||
public int hashCode() {
|
||||
int result = offer != null ? offer.hashCode() : 0;
|
||||
result = 31 * result + (int) (tradeAmount ^ (tradeAmount >>> 32));
|
||||
result = 31 * result + (int) (tradePrice ^ (tradePrice >>> 32));
|
||||
result = 31 * result + (takeOfferFeeTxID != null ? takeOfferFeeTxID.hashCode() : 0);
|
||||
result = 31 * result + (arbitratorNodeAddress != null ? arbitratorNodeAddress.hashCode() : 0);
|
||||
result = 31 * result + (isBuyerOffererAndSellerTaker ? 1 : 0);
|
||||
@ -229,6 +239,7 @@ public final class Contract implements Payload {
|
||||
return "Contract{" +
|
||||
"\n\toffer=" + offer +
|
||||
"\n\ttradeAmount=" + tradeAmount +
|
||||
"\n\ttradePrice=" + tradePrice +
|
||||
"\n\ttakeOfferFeeTxID='" + takeOfferFeeTxID + '\'' +
|
||||
"\n\tarbitratorAddress=" + arbitratorNodeAddress +
|
||||
"\n\tisBuyerOffererAndSellerTaker=" + isBuyerOffererAndSellerTaker +
|
||||
|
@ -42,8 +42,8 @@ public final class SellerAsTakerTrade extends SellerTrade implements TakerTrade
|
||||
// Constructor, initialization
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public SellerAsTakerTrade(Offer offer, Coin tradeAmount, NodeAddress tradingPeerNodeAddress, Storage<? extends TradableList> storage) {
|
||||
super(offer, tradeAmount, tradingPeerNodeAddress, storage);
|
||||
public SellerAsTakerTrade(Offer offer, Coin tradeAmount, long tradePrice, NodeAddress tradingPeerNodeAddress, Storage<? extends TradableList> storage) {
|
||||
super(offer, tradeAmount, tradePrice, tradingPeerNodeAddress, storage);
|
||||
}
|
||||
|
||||
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
|
@ -37,8 +37,8 @@ public abstract class SellerTrade extends Trade {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BuyerAsTakerTrade.class);
|
||||
|
||||
SellerTrade(Offer offer, Coin tradeAmount, NodeAddress tradingPeerNodeAddress, Storage<? extends TradableList> storage) {
|
||||
super(offer, tradeAmount, tradingPeerNodeAddress, storage);
|
||||
SellerTrade(Offer offer, Coin tradeAmount, long tradePrice, NodeAddress tradingPeerNodeAddress, Storage<? extends TradableList> storage) {
|
||||
super(offer, tradeAmount, tradePrice, tradingPeerNodeAddress, storage);
|
||||
}
|
||||
|
||||
SellerTrade(Offer offer, Storage<? extends TradableList> storage) {
|
||||
@ -69,7 +69,7 @@ public abstract class SellerTrade extends Trade {
|
||||
public Coin getPayoutAmount() {
|
||||
return FeePolicy.getSecurityDeposit();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Setter for Mutable objects
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -41,6 +41,7 @@ import javafx.beans.property.*;
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.core.Transaction;
|
||||
import org.bitcoinj.core.TransactionConfidence;
|
||||
import org.bitcoinj.utils.ExchangeRate;
|
||||
import org.bitcoinj.utils.Fiat;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
@ -167,6 +168,7 @@ public abstract class Trade implements Tradable, Model {
|
||||
transient private ObjectProperty<Fiat> tradeVolumeProperty;
|
||||
@Nullable
|
||||
private String takeOfferFeeTxId;
|
||||
private long tradePrice;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -189,11 +191,12 @@ public abstract class Trade implements Tradable, Model {
|
||||
}
|
||||
|
||||
// taker
|
||||
protected Trade(Offer offer, Coin tradeAmount, NodeAddress tradingPeerNodeAddress,
|
||||
protected Trade(Offer offer, Coin tradeAmount, long tradePrice, NodeAddress tradingPeerNodeAddress,
|
||||
Storage<? extends TradableList> storage) {
|
||||
|
||||
this(offer, storage);
|
||||
this.tradeAmount = tradeAmount;
|
||||
this.tradePrice = tradePrice;
|
||||
this.tradingPeerNodeAddress = tradingPeerNodeAddress;
|
||||
tradeAmountProperty.set(tradeAmount);
|
||||
tradeVolumeProperty.set(getTradeVolume());
|
||||
@ -381,8 +384,8 @@ public abstract class Trade implements Tradable, Model {
|
||||
|
||||
@Nullable
|
||||
public Fiat getTradeVolume() {
|
||||
if (tradeAmount != null)
|
||||
return offer.getVolumeByAmount(tradeAmount);
|
||||
if (tradeAmount != null && getTradePrice() != null)
|
||||
return new ExchangeRate(getTradePrice()).coinToFiat(tradeAmount);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
@ -452,6 +455,14 @@ public abstract class Trade implements Tradable, Model {
|
||||
tradeVolumeProperty.set(getTradeVolume());
|
||||
}
|
||||
|
||||
public void setTradePrice(long tradePrice) {
|
||||
this.tradePrice = tradePrice;
|
||||
}
|
||||
|
||||
public Fiat getTradePrice() {
|
||||
return Fiat.valueOf(offer.getCurrencyCode(), tradePrice);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Coin getTradeAmount() {
|
||||
return tradeAmount;
|
||||
|
@ -113,7 +113,7 @@ public class TradeManager {
|
||||
tradableListStorage = new Storage<>(storageDir);
|
||||
trades = new TradableList<>(tradableListStorage, "PendingTrades");
|
||||
trades.forEach(e -> e.getOffer().setPriceFeed(priceFeed));
|
||||
|
||||
|
||||
p2PService.addDecryptedDirectMessageListener(new DecryptedDirectMessageListener() {
|
||||
@Override
|
||||
public void onDirectMessage(DecryptedMsgWithPubKey decryptedMsgWithPubKey, NodeAddress peerNodeAddress) {
|
||||
@ -264,6 +264,7 @@ public class TradeManager {
|
||||
|
||||
// First we check if offer is still available then we create the trade with the protocol
|
||||
public void onTakeOffer(Coin amount,
|
||||
long tradePrice,
|
||||
Coin fundsNeededForTrade,
|
||||
Offer offer,
|
||||
String paymentAccountId,
|
||||
@ -273,11 +274,12 @@ public class TradeManager {
|
||||
offer.checkOfferAvailability(model,
|
||||
() -> {
|
||||
if (offer.getState() == Offer.State.AVAILABLE)
|
||||
createTrade(amount, fundsNeededForTrade, offer, paymentAccountId, useSavingsWallet, model, tradeResultHandler);
|
||||
createTrade(amount, tradePrice, fundsNeededForTrade, offer, paymentAccountId, useSavingsWallet, model, tradeResultHandler);
|
||||
});
|
||||
}
|
||||
|
||||
private void createTrade(Coin amount,
|
||||
long tradePrice,
|
||||
Coin fundsNeededForTrade,
|
||||
Offer offer,
|
||||
String paymentAccountId,
|
||||
@ -286,9 +288,9 @@ public class TradeManager {
|
||||
TradeResultHandler tradeResultHandler) {
|
||||
Trade trade;
|
||||
if (offer.getDirection() == Offer.Direction.BUY)
|
||||
trade = new SellerAsTakerTrade(offer, amount, model.getPeerNodeAddress(), tradableListStorage);
|
||||
trade = new SellerAsTakerTrade(offer, amount, tradePrice, model.getPeerNodeAddress(), tradableListStorage);
|
||||
else
|
||||
trade = new BuyerAsTakerTrade(offer, amount, model.getPeerNodeAddress(), tradableListStorage);
|
||||
trade = new BuyerAsTakerTrade(offer, amount, tradePrice, model.getPeerNodeAddress(), tradableListStorage);
|
||||
|
||||
trade.setTakerPaymentAccountId(paymentAccountId);
|
||||
|
||||
|
@ -229,7 +229,7 @@ public final class Offer implements StoragePayload, RequiresOwnerIsOnlinePayload
|
||||
|
||||
public Fiat getVolumeByAmount(Coin amount) {
|
||||
if (fiatPrice != 0 && amount != null && !amount.isZero())
|
||||
return new ExchangeRate(Fiat.valueOf(currencyCode, fiatPrice)).coinToFiat(amount);
|
||||
return new ExchangeRate(getPrice()).coinToFiat(amount);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
@ -335,6 +335,13 @@ public final class Offer implements StoragePayload, RequiresOwnerIsOnlinePayload
|
||||
double marketPriceAsDouble = marketPrice.getPrice(priceFeedType);
|
||||
double factor = direction == Offer.Direction.BUY ? 1 - marketPriceMargin : 1 + marketPriceMargin;
|
||||
double targetPrice = marketPriceAsDouble * factor;
|
||||
|
||||
// round
|
||||
long factor1 = (long) Math.pow(10, 2);
|
||||
targetPrice = targetPrice * factor1;
|
||||
long tmp = Math.round(targetPrice);
|
||||
targetPrice = (double) tmp / factor1;
|
||||
|
||||
try {
|
||||
return Fiat.parseFiat(currencyCode, String.valueOf(targetPrice));
|
||||
} catch (Exception e) {
|
||||
|
@ -35,6 +35,7 @@ public final class PayDepositRequest extends TradeMessage implements MailboxMess
|
||||
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
|
||||
|
||||
public final long tradeAmount;
|
||||
public final long tradePrice;
|
||||
public final byte[] takerMultiSigPubKey;
|
||||
public final ArrayList<RawTransactionInput> rawTransactionInputs;
|
||||
public final long changeOutputValue;
|
||||
@ -52,6 +53,7 @@ public final class PayDepositRequest extends TradeMessage implements MailboxMess
|
||||
public PayDepositRequest(NodeAddress senderNodeAddress,
|
||||
String tradeId,
|
||||
long tradeAmount,
|
||||
long tradePrice,
|
||||
ArrayList<RawTransactionInput> rawTransactionInputs,
|
||||
long changeOutputValue,
|
||||
String changeOutputAddress,
|
||||
@ -66,6 +68,7 @@ public final class PayDepositRequest extends TradeMessage implements MailboxMess
|
||||
super(tradeId);
|
||||
this.senderNodeAddress = senderNodeAddress;
|
||||
this.tradeAmount = tradeAmount;
|
||||
this.tradePrice = tradePrice;
|
||||
this.rawTransactionInputs = rawTransactionInputs;
|
||||
this.changeOutputValue = changeOutputValue;
|
||||
this.changeOutputAddress = changeOutputAddress;
|
||||
|
@ -60,6 +60,7 @@ public class CreateAndSignContract extends TradeTask {
|
||||
Contract contract = new Contract(
|
||||
processModel.getOffer(),
|
||||
trade.getTradeAmount(),
|
||||
trade.getTradePrice(),
|
||||
trade.getTakeOfferFeeTxId(),
|
||||
buyerNodeAddress,
|
||||
sellerNodeAddress,
|
||||
|
@ -77,13 +77,14 @@ public class ProcessPayDepositRequest extends TradeTask {
|
||||
failed("acceptedArbitratorNames size must be at least 1");
|
||||
trade.setArbitratorNodeAddress(checkNotNull(payDepositRequest.arbitratorNodeAddress));
|
||||
checkArgument(payDepositRequest.tradeAmount > 0);
|
||||
trade.setTradePrice(payDepositRequest.tradePrice);
|
||||
trade.setTradeAmount(Coin.valueOf(payDepositRequest.tradeAmount));
|
||||
|
||||
// update to the latest peer address of our peer if the payDepositRequest is correct
|
||||
trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
||||
|
||||
removeMailboxMessageAfterProcessing();
|
||||
|
||||
|
||||
complete();
|
||||
} catch (Throwable t) {
|
||||
failed(t);
|
||||
|
@ -49,6 +49,7 @@ public class SendPayDepositRequest extends TradeTask {
|
||||
processModel.getMyAddress(),
|
||||
processModel.getId(),
|
||||
trade.getTradeAmount().value,
|
||||
trade.getTradePrice().value,
|
||||
processModel.getRawTransactionInputs(),
|
||||
processModel.getChangeOutputValue(),
|
||||
processModel.getChangeOutputAddress(),
|
||||
|
@ -61,6 +61,7 @@ public class VerifyAndSignContract extends TradeTask {
|
||||
Contract contract = new Contract(
|
||||
processModel.getOffer(),
|
||||
trade.getTradeAmount(),
|
||||
trade.getTradePrice(),
|
||||
trade.getTakeOfferFeeTxId(),
|
||||
buyerNodeAddress,
|
||||
sellerNodeAddress,
|
||||
|
@ -93,14 +93,12 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
||||
private TextField currencyTextField;
|
||||
private Label directionLabel, amountDescriptionLabel, addressLabel, balanceLabel, totalToPayLabel, totalToPayInfoIconLabel, amountBtcLabel, priceCurrencyLabel,
|
||||
volumeCurrencyLabel, minAmountBtcLabel, priceDescriptionLabel, volumeDescriptionLabel, currencyTextFieldLabel,
|
||||
currencyComboBoxLabel, spinnerInfoLabel;
|
||||
currencyComboBoxLabel, spinnerInfoLabel, priceAsPercentageLabel;
|
||||
private TextFieldWithCopyIcon totalToPayTextField;
|
||||
private ComboBox<PaymentAccount> paymentAccountsComboBox;
|
||||
private ComboBox<TradeCurrency> currencyComboBox;
|
||||
private PopOver totalToPayInfoPopover;
|
||||
private Label priceAsPercentageLabel;
|
||||
private ToggleButton fixedPriceButton;
|
||||
private ToggleButton percentagePriceButton;
|
||||
private ToggleButton fixedPriceButton, percentagePriceButton;
|
||||
|
||||
private OfferView.CloseHandler closeHandler;
|
||||
|
||||
|
@ -576,8 +576,9 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
||||
long shiftDivisor = checkedPow(10, priceAsFiat.smallestUnitExponent());
|
||||
double offerPrice = ((double) priceAsFiat.longValue()) / ((double) shiftDivisor);
|
||||
double percentage = Math.abs(1 - (offerPrice / marketPriceAsDouble));
|
||||
percentage = formatter.roundDouble(percentage, 2);
|
||||
if (marketPriceAsDouble != 0 && percentage > preferences.getMaxPriceDistanceInPercent()) {
|
||||
displayPriceOutofRangePopup();
|
||||
displayPriceOutOfRangePopup();
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
@ -587,7 +588,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
||||
}
|
||||
}
|
||||
|
||||
private void displayPriceOutofRangePopup() {
|
||||
private void displayPriceOutOfRangePopup() {
|
||||
Popup popup = new Popup();
|
||||
popup.warning("The price you have entered is outside the max. allowed deviation from the market price.\n" +
|
||||
"The max. allowed deviation is " +
|
||||
|
@ -92,6 +92,7 @@ class TakeOfferDataModel extends ActivatableDataModel {
|
||||
boolean useSavingsWallet;
|
||||
Coin totalAvailableBalance;
|
||||
private Notification walletFundedNotification;
|
||||
Fiat tradePrice;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -158,6 +159,7 @@ class TakeOfferDataModel extends ActivatableDataModel {
|
||||
// called before activate
|
||||
void initWithData(Offer offer) {
|
||||
this.offer = offer;
|
||||
tradePrice = offer.getPrice();
|
||||
|
||||
addressEntry = walletService.getOrCreateAddressEntry(offer.getId(), AddressEntry.Context.OFFER_FUNDING);
|
||||
checkNotNull(addressEntry, "addressEntry must not be null");
|
||||
@ -227,6 +229,7 @@ class TakeOfferDataModel extends ActivatableDataModel {
|
||||
// have it persisted as well.
|
||||
void onTakeOffer(TradeResultHandler tradeResultHandler) {
|
||||
tradeManager.onTakeOffer(amountAsCoin.get(),
|
||||
tradePrice.getValue(),
|
||||
totalToPayAsCoin.get().subtract(takerFeeAsCoin),
|
||||
offer,
|
||||
paymentAccount.getId(),
|
||||
@ -308,7 +311,7 @@ class TakeOfferDataModel extends ActivatableDataModel {
|
||||
if (offer != null &&
|
||||
amountAsCoin.get() != null &&
|
||||
!amountAsCoin.get().isZero()) {
|
||||
volumeAsFiat.set(new ExchangeRate(offer.getPrice()).coinToFiat(amountAsCoin.get()));
|
||||
volumeAsFiat.set(new ExchangeRate(tradePrice).coinToFiat(amountAsCoin.get()));
|
||||
|
||||
updateBalance();
|
||||
}
|
||||
|
@ -90,9 +90,9 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
||||
private TitledGroupBg payFundsPane;
|
||||
private Button nextButton, cancelButton1, cancelButton2, fundFromSavingsWalletButton, fundFromExternalWalletButton, takeOfferButton;
|
||||
private InputTextField amountTextField;
|
||||
private TextField paymentMethodTextField, currencyTextField, priceTextField, volumeTextField, amountRangeTextField;
|
||||
private TextField paymentMethodTextField, currencyTextField, priceTextField, priceAsPercentageTextField, volumeTextField, amountRangeTextField;
|
||||
private Label directionLabel, amountDescriptionLabel, addressLabel, balanceLabel, totalToPayLabel, totalToPayInfoIconLabel,
|
||||
amountBtcLabel, priceCurrencyLabel,
|
||||
amountBtcLabel, priceCurrencyLabel, priceAsPercentageLabel,
|
||||
volumeCurrencyLabel, amountRangeBtcLabel, priceDescriptionLabel, volumeDescriptionLabel, spinnerInfoLabel, offerAvailabilitySpinnerLabel;
|
||||
private TextFieldWithCopyIcon totalToPayTextField;
|
||||
private PopOver totalToPayInfoPopover;
|
||||
@ -228,6 +228,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
||||
amountDescriptionLabel.setText(model.getAmountDescription());
|
||||
amountRangeTextField.setText(model.getAmountRange());
|
||||
priceTextField.setText(model.getPrice());
|
||||
priceAsPercentageTextField.setText(model.marketPriceMargin);
|
||||
addressTextField.setPaymentLabel(model.getPaymentLabel());
|
||||
addressTextField.setAddress(model.dataModel.getAddressEntry().getAddressString());
|
||||
}
|
||||
@ -269,7 +270,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
||||
offerDetailsWindow.hide();
|
||||
offerDetailsWindowDisplayed = false;
|
||||
})
|
||||
).show(model.getOffer(), model.dataModel.amountAsCoin.get());
|
||||
).show(model.getOffer(), model.dataModel.amountAsCoin.get(), model.dataModel.tradePrice);
|
||||
offerDetailsWindowDisplayed = true;
|
||||
} else {
|
||||
new Popup().warning("You have no arbitrator selected.\n" +
|
||||
@ -285,6 +286,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
||||
|
||||
amountTextField.setMouseTransparent(true);
|
||||
priceTextField.setMouseTransparent(true);
|
||||
priceAsPercentageTextField.setMouseTransparent(true);
|
||||
volumeTextField.setMouseTransparent(true);
|
||||
|
||||
balanceTextField.setTargetAmount(model.dataModel.totalToPayAsCoin.get());
|
||||
@ -389,6 +391,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
||||
addressTextField.amountAsCoinProperty().bind(model.dataModel.missingCoin);
|
||||
amountTextField.validationResultProperty().bind(model.amountValidationResult);
|
||||
priceCurrencyLabel.textProperty().bind(createStringBinding(() -> model.dataModel.getCurrencyCode() + "/" + model.btcCode.get(), model.btcCode));
|
||||
priceAsPercentageLabel.prefWidthProperty().bind(priceCurrencyLabel.widthProperty());
|
||||
amountRangeBtcLabel.textProperty().bind(model.btcCode);
|
||||
nextButton.disableProperty().bind(model.isNextButtonDisabled);
|
||||
|
||||
@ -414,6 +417,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
||||
addressTextField.amountAsCoinProperty().unbind();
|
||||
amountTextField.validationResultProperty().unbind();
|
||||
priceCurrencyLabel.textProperty().unbind();
|
||||
priceAsPercentageLabel.prefWidthProperty().unbind();
|
||||
amountRangeBtcLabel.textProperty().unbind();
|
||||
nextButton.disableProperty().unbind();
|
||||
|
||||
@ -638,8 +642,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
||||
gridPane.getChildren().add(imageVBox);
|
||||
|
||||
addAmountPriceFields();
|
||||
|
||||
addAmountRangeBox();
|
||||
addSecondRow();
|
||||
|
||||
HBox hBox = new HBox();
|
||||
hBox.setSpacing(10);
|
||||
@ -839,18 +842,42 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
||||
gridPane.getChildren().add(hBox);
|
||||
}
|
||||
|
||||
private void addAmountRangeBox() {
|
||||
private void addSecondRow() {
|
||||
Tuple3<HBox, TextField, Label> priceAsPercentageTuple = getValueCurrencyBox();
|
||||
HBox priceAsPercentageValueCurrencyBox = priceAsPercentageTuple.first;
|
||||
priceAsPercentageTextField = priceAsPercentageTuple.second;
|
||||
priceAsPercentageLabel = priceAsPercentageTuple.third;
|
||||
|
||||
Tuple2<Label, VBox> priceAsPercentageInputBoxTuple = getTradeInputBox(priceAsPercentageValueCurrencyBox, "Distance in % from market price");
|
||||
priceAsPercentageInputBoxTuple.first.setPrefWidth(200);
|
||||
VBox priceAsPercentageInputBox = priceAsPercentageInputBoxTuple.second;
|
||||
|
||||
priceAsPercentageTextField.setPromptText("Enter % value");
|
||||
priceAsPercentageLabel.setText("% dist.");
|
||||
priceAsPercentageLabel.setStyle("-fx-alignment: center;");
|
||||
|
||||
|
||||
Tuple3<HBox, TextField, Label> amountValueCurrencyBoxTuple = getValueCurrencyBox();
|
||||
HBox amountValueCurrencyBox = amountValueCurrencyBoxTuple.first;
|
||||
amountRangeTextField = amountValueCurrencyBoxTuple.second;
|
||||
amountRangeBtcLabel = amountValueCurrencyBoxTuple.third;
|
||||
|
||||
Tuple2<Label, VBox> amountInputBoxTuple = getTradeInputBox(amountValueCurrencyBox, BSResources.get("takeOffer.amountPriceBox.amountRangeDescription"));
|
||||
VBox box = amountInputBoxTuple.second;
|
||||
GridPane.setRowIndex(box, ++gridRow);
|
||||
GridPane.setColumnIndex(box, 1);
|
||||
GridPane.setMargin(box, new Insets(5, 10, 5, 0));
|
||||
gridPane.getChildren().add(box);
|
||||
|
||||
Label xLabel = new Label("x");
|
||||
xLabel.setFont(Font.font("Helvetica-Bold", 20));
|
||||
xLabel.setPadding(new Insets(14, 3, 0, 3));
|
||||
xLabel.setVisible(false); // we just use it to get the same layout as the upper row
|
||||
|
||||
HBox hBox = new HBox();
|
||||
hBox.setSpacing(5);
|
||||
hBox.setAlignment(Pos.CENTER_LEFT);
|
||||
hBox.getChildren().addAll(amountInputBoxTuple.second, xLabel, priceAsPercentageInputBox);
|
||||
GridPane.setRowIndex(hBox, ++gridRow);
|
||||
GridPane.setColumnIndex(hBox, 1);
|
||||
GridPane.setMargin(hBox, new Insets(5, 10, 5, 0));
|
||||
GridPane.setColumnSpan(hBox, 2);
|
||||
gridPane.getChildren().add(hBox);
|
||||
}
|
||||
|
||||
|
||||
|
@ -96,6 +96,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
||||
private ConnectionListener connectionListener;
|
||||
// private Subscription isFeeSufficientSubscription;
|
||||
private Runnable takeOfferSucceededHandler;
|
||||
String marketPriceMargin;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -162,7 +163,8 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
||||
}
|
||||
|
||||
amountRange = formatter.formatCoin(offer.getMinAmount()) + " - " + formatter.formatCoin(offer.getAmount());
|
||||
price = formatter.formatFiat(offer.getPrice());
|
||||
price = formatter.formatFiat(dataModel.tradePrice);
|
||||
marketPriceMargin = formatter.formatToPercentWithSymbol(offer.getMarketPriceMargin());
|
||||
paymentLabel = BSResources.get("takeOffer.fundsBox.paymentLabel", offer.getId());
|
||||
|
||||
checkNotNull(dataModel.getAddressEntry(), "dataModel.getAddressEntry() must not be null");
|
||||
|
@ -123,7 +123,7 @@ public class ContractWindow extends Overlay<ContractWindow> {
|
||||
addLabelTextField(gridPane, ++rowIndex, "Offer date:", formatter.formatDateTime(offer.getDate()));
|
||||
addLabelTextField(gridPane, ++rowIndex, "Trade date:", formatter.formatDateTime(dispute.getTradeDate()));
|
||||
addLabelTextField(gridPane, ++rowIndex, "Trade type:", formatter.getDirectionBothSides(offer.getDirection()));
|
||||
addLabelTextField(gridPane, ++rowIndex, "Price:", formatter.formatFiat(offer.getPrice()) + " " + offer.getCurrencyCode());
|
||||
addLabelTextField(gridPane, ++rowIndex, "Trade price:", formatter.formatFiat(contract.getTradePrice()) + " " + offer.getCurrencyCode());
|
||||
addLabelTextField(gridPane, ++rowIndex, "Trade amount:", formatter.formatCoinWithCode(contract.getTradeAmount()));
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "Buyer bitcoin address:",
|
||||
contract.getBuyerPayoutAddressString()).second.setMouseTransparent(false);
|
||||
|
@ -47,6 +47,7 @@ import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
import org.bitcoinj.core.AddressFormatException;
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.utils.ExchangeRate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -232,8 +233,8 @@ public class DisputeSummaryWindow extends Overlay<DisputeSummaryWindow> {
|
||||
}
|
||||
addLabelTextField(gridPane, ++rowIndex, "Traders role:", role);
|
||||
addLabelTextField(gridPane, ++rowIndex, "Trade amount:", formatter.formatCoinWithCode(contract.getTradeAmount()));
|
||||
addLabelTextField(gridPane, ++rowIndex, "Trade volume:", formatter.formatFiatWithCode(contract.offer.getVolumeByAmount(contract.getTradeAmount())));
|
||||
addLabelTextField(gridPane, ++rowIndex, "Price:", formatter.formatFiatWithCode(contract.offer.getPrice()));
|
||||
addLabelTextField(gridPane, ++rowIndex, "Trade price:", formatter.formatFiatWithCode(contract.getTradePrice()));
|
||||
addLabelTextField(gridPane, ++rowIndex, "Trade volume:", formatter.formatFiatWithCode(new ExchangeRate(contract.getTradePrice()).coinToFiat(contract.getTradeAmount())));
|
||||
}
|
||||
|
||||
private void addCheckboxes() {
|
||||
|
@ -41,6 +41,7 @@ import javafx.geometry.Insets;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.ImageView;
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.utils.Fiat;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -61,6 +62,7 @@ public class OfferDetailsWindow extends Overlay<OfferDetailsWindow> {
|
||||
private final Navigation navigation;
|
||||
private Offer offer;
|
||||
private Coin tradeAmount;
|
||||
private Fiat tradePrice;
|
||||
private Optional<Runnable> placeOfferHandlerOptional = Optional.empty();
|
||||
private Optional<Runnable> takeOfferHandlerOptional = Optional.empty();
|
||||
private ProgressIndicator spinner;
|
||||
@ -80,9 +82,10 @@ public class OfferDetailsWindow extends Overlay<OfferDetailsWindow> {
|
||||
type = Type.Confirmation;
|
||||
}
|
||||
|
||||
public void show(Offer offer, Coin tradeAmount) {
|
||||
public void show(Offer offer, Coin tradeAmount, Fiat tradePrice) {
|
||||
this.offer = offer;
|
||||
this.tradeAmount = tradeAmount;
|
||||
this.tradePrice = tradePrice;
|
||||
|
||||
rowIndex = -1;
|
||||
width = 900;
|
||||
@ -172,7 +175,10 @@ public class OfferDetailsWindow extends Overlay<OfferDetailsWindow> {
|
||||
addLabelTextField(gridPane, ++rowIndex, CurrencyUtil.getNameByCode(offer.getCurrencyCode()) + " amount" + fiatDirectionInfo, formatter.formatFiatWithCode(offer.getVolumeByAmount(offer.getAmount())));
|
||||
}
|
||||
|
||||
addLabelTextField(gridPane, ++rowIndex, "Price:", formatter.formatFiat(offer.getPrice()) + " " + offer.getCurrencyCode() + "/" + "BTC");
|
||||
if (takeOfferHandlerOptional.isPresent())
|
||||
addLabelTextField(gridPane, ++rowIndex, "Price:", formatter.formatFiat(tradePrice) + " " + offer.getCurrencyCode() + "/" + "BTC");
|
||||
else
|
||||
addLabelTextField(gridPane, ++rowIndex, "Price:", formatter.formatFiat(offer.getPrice()) + " " + offer.getCurrencyCode() + "/" + "BTC");
|
||||
|
||||
if (offer.isMyOffer(keyRing) && user.getPaymentAccount(offer.getOffererPaymentAccountId()) != null)
|
||||
addLabelTextField(gridPane, ++rowIndex, "Payment account:", user.getPaymentAccount(offer.getOffererPaymentAccountId()).getAccountName());
|
||||
|
@ -127,7 +127,7 @@ public class TradeDetailsWindow extends Overlay<TradeDetailsWindow> {
|
||||
|
||||
addLabelTextField(gridPane, ++rowIndex, "Bitcoin amount" + btcDirectionInfo, formatter.formatCoinWithCode(trade.getTradeAmount()));
|
||||
addLabelTextField(gridPane, ++rowIndex, CurrencyUtil.getNameByCode(offer.getCurrencyCode()) + " amount" + fiatDirectionInfo, formatter.formatFiatWithCode(trade.getTradeVolume()));
|
||||
addLabelTextField(gridPane, ++rowIndex, "Price:", formatter.formatPriceWithCode(offer.getPrice()));
|
||||
addLabelTextField(gridPane, ++rowIndex, "Trade price:", formatter.formatPriceWithCode(trade.getTradePrice()));
|
||||
addLabelTextField(gridPane, ++rowIndex, "Payment method:", BSResources.get(offer.getPaymentMethod().getId()));
|
||||
|
||||
// second group
|
||||
|
@ -81,7 +81,13 @@ public class ClosedTradesView extends ActivatableViewAndModel<VBox, ClosedTrades
|
||||
tradeIdColumn.setComparator((o1, o2) -> o1.getTradable().getId().compareTo(o2.getTradable().getId()));
|
||||
dateColumn.setComparator((o1, o2) -> o1.getTradable().getDate().compareTo(o2.getTradable().getDate()));
|
||||
directionColumn.setComparator((o1, o2) -> o1.getTradable().getOffer().getDirection().compareTo(o2.getTradable().getOffer().getDirection()));
|
||||
priceColumn.setComparator((o1, o2) -> o1.getTradable().getOffer().getPrice().compareTo(o2.getTradable().getOffer().getPrice()));
|
||||
priceColumn.setComparator((o1, o2) -> {
|
||||
Tradable tradable = o1.getTradable();
|
||||
if (tradable instanceof Trade)
|
||||
return ((Trade) o1.getTradable()).getTradePrice().compareTo(((Trade) o2.getTradable()).getTradePrice());
|
||||
else
|
||||
return o1.getTradable().getOffer().getPrice().compareTo(o2.getTradable().getOffer().getPrice());
|
||||
});
|
||||
volumeColumn.setComparator((o1, o2) -> {
|
||||
if (o1.getTradable() instanceof Trade && o2.getTradable() instanceof Trade) {
|
||||
Fiat tradeVolume1 = ((Trade) o1.getTradable()).getTradeVolume();
|
||||
|
@ -21,6 +21,7 @@ import com.google.inject.Inject;
|
||||
import io.bitsquare.gui.common.model.ActivatableWithDataModel;
|
||||
import io.bitsquare.gui.common.model.ViewModel;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
import io.bitsquare.trade.Tradable;
|
||||
import io.bitsquare.trade.Trade;
|
||||
import io.bitsquare.trade.offer.OpenOffer;
|
||||
import javafx.collections.ObservableList;
|
||||
@ -54,7 +55,13 @@ class ClosedTradesViewModel extends ActivatableWithDataModel<ClosedTradesDataMod
|
||||
}
|
||||
|
||||
String getPrice(ClosedTradableListItem item) {
|
||||
return (item != null) ? formatter.formatFiat(item.getTradable().getOffer().getPrice()) : "";
|
||||
if (item == null)
|
||||
return "";
|
||||
Tradable tradable = item.getTradable();
|
||||
if (tradable instanceof Trade)
|
||||
return formatter.formatFiat(((Trade) tradable).getTradePrice());
|
||||
else
|
||||
return formatter.formatFiat(tradable.getOffer().getPrice());
|
||||
}
|
||||
|
||||
String getVolume(ClosedTradableListItem item) {
|
||||
|
@ -62,7 +62,7 @@ public class FailedTradesView extends ActivatableViewAndModel<VBox, FailedTrades
|
||||
|
||||
tradeIdColumn.setComparator((o1, o2) -> o1.getTrade().getId().compareTo(o2.getTrade().getId()));
|
||||
dateColumn.setComparator((o1, o2) -> o1.getTrade().getDate().compareTo(o2.getTrade().getDate()));
|
||||
priceColumn.setComparator((o1, o2) -> o1.getTrade().getOffer().getPrice().compareTo(o2.getTrade().getOffer().getPrice()));
|
||||
priceColumn.setComparator((o1, o2) -> o1.getTrade().getTradePrice().compareTo(o2.getTrade().getTradePrice()));
|
||||
volumeColumn.setComparator((o1, o2) -> o1.getTrade().getTradeVolume().compareTo(o2.getTrade().getTradeVolume()));
|
||||
amountColumn.setComparator((o1, o2) -> o1.getTrade().getTradeAmount().compareTo(o2.getTrade().getTradeAmount()));
|
||||
stateColumn.setComparator((o1, o2) -> model.getState(o1).compareTo(model.getState(o2)));
|
||||
|
@ -51,7 +51,7 @@ class FailedTradesViewModel extends ActivatableWithDataModel<FailedTradesDataMod
|
||||
}
|
||||
|
||||
String getPrice(FailedTradesListItem item) {
|
||||
return (item != null) ? formatter.formatFiat(item.getTrade().getOffer().getPrice()) : "";
|
||||
return (item != null) ? formatter.formatFiat(item.getTrade().getTradePrice()) : "";
|
||||
}
|
||||
|
||||
String getVolume(FailedTradesListItem item) {
|
||||
|
@ -46,7 +46,7 @@ public class PendingTradesListItem {
|
||||
}
|
||||
|
||||
public Fiat getPrice() {
|
||||
return trade.getOffer().getPrice();
|
||||
return trade.getTradePrice();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -380,7 +380,7 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
||||
public void updateItem(final PendingTradesListItem item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (item != null && !empty)
|
||||
setText(formatter.formatPriceWithCode(item.getTrade().getTradeVolume()));
|
||||
setText(formatter.formatFiatWithCode(item.getTrade().getTradeVolume()));
|
||||
else
|
||||
setText(null);
|
||||
}
|
||||
|
@ -372,7 +372,6 @@ public class BSFormatter {
|
||||
|
||||
public double roundDouble(double value, int places) {
|
||||
if (places < 0) throw new IllegalArgumentException();
|
||||
|
||||
long factor = (long) Math.pow(10, places);
|
||||
value = value * factor;
|
||||
long tmp = Math.round(value);
|
||||
|
Loading…
x
Reference in New Issue
Block a user