mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 23:18:17 +01:00
Remove mining fee check
This commit is contained in:
parent
9f42c5ac61
commit
f9a33a00ff
6 changed files with 142 additions and 125 deletions
|
@ -17,21 +17,19 @@
|
|||
|
||||
package io.bitsquare.gui.main.offer.createoffer;
|
||||
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
import com.google.inject.Inject;
|
||||
import io.bitsquare.arbitration.Arbitrator;
|
||||
import io.bitsquare.btc.*;
|
||||
import io.bitsquare.btc.AddressEntry;
|
||||
import io.bitsquare.btc.FeePolicy;
|
||||
import io.bitsquare.btc.TradeWalletService;
|
||||
import io.bitsquare.btc.WalletService;
|
||||
import io.bitsquare.btc.blockchain.BlockchainService;
|
||||
import io.bitsquare.btc.listeners.BalanceListener;
|
||||
import io.bitsquare.btc.pricefeed.PriceFeed;
|
||||
import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.common.crypto.KeyRing;
|
||||
import io.bitsquare.gui.Navigation;
|
||||
import io.bitsquare.gui.common.model.ActivatableDataModel;
|
||||
import io.bitsquare.gui.main.overlays.notifications.Notification;
|
||||
import io.bitsquare.gui.main.overlays.popups.Popup;
|
||||
import io.bitsquare.gui.main.overlays.windows.WalletPasswordWindow;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
import io.bitsquare.locale.TradeCurrency;
|
||||
|
@ -50,7 +48,6 @@ 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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -92,10 +89,10 @@ class CreateOfferDataModel extends ActivatableDataModel {
|
|||
final StringProperty btcCode = new SimpleStringProperty();
|
||||
|
||||
final BooleanProperty isWalletFunded = new SimpleBooleanProperty();
|
||||
final BooleanProperty isMainNet = new SimpleBooleanProperty();
|
||||
//final BooleanProperty isMainNet = new SimpleBooleanProperty();
|
||||
final BooleanProperty isFeeFromFundingTxSufficient = new SimpleBooleanProperty();
|
||||
|
||||
final ObjectProperty<Coin> feeFromFundingTxProperty = new SimpleObjectProperty(Coin.NEGATIVE_SATOSHI);
|
||||
|
||||
// final ObjectProperty<Coin> feeFromFundingTxProperty = new SimpleObjectProperty(Coin.NEGATIVE_SATOSHI);
|
||||
final ObjectProperty<Coin> amountAsCoin = new SimpleObjectProperty<>();
|
||||
final ObjectProperty<Coin> minAmountAsCoin = new SimpleObjectProperty<>();
|
||||
final ObjectProperty<Fiat> priceAsFiat = new SimpleObjectProperty<>();
|
||||
|
@ -135,7 +132,7 @@ class CreateOfferDataModel extends ActivatableDataModel {
|
|||
this.blockchainService = blockchainService;
|
||||
this.formatter = formatter;
|
||||
|
||||
isMainNet.set(preferences.getBitcoinNetwork() == BitcoinNetwork.MAINNET);
|
||||
// isMainNet.set(preferences.getBitcoinNetwork() == BitcoinNetwork.MAINNET);
|
||||
|
||||
offerId = UUID.randomUUID().toString();
|
||||
addressEntry = walletService.getTradeAddressEntry(offerId);
|
||||
|
@ -148,7 +145,7 @@ class CreateOfferDataModel extends ActivatableDataModel {
|
|||
public void onBalanceChanged(Coin balance, Transaction tx) {
|
||||
updateBalance();
|
||||
|
||||
if (preferences.getBitcoinNetwork() == BitcoinNetwork.MAINNET) {
|
||||
/* if (isMainNet.get()) {
|
||||
SettableFuture<Coin> future = blockchainService.requestFee(tx.getHashAsString());
|
||||
Futures.addCallback(future, new FutureCallback<Coin>() {
|
||||
public void onSuccess(Coin fee) {
|
||||
|
@ -168,9 +165,7 @@ class CreateOfferDataModel extends ActivatableDataModel {
|
|||
.show());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
feeFromFundingTxProperty.set(FeePolicy.getMinRequiredFeeForFundingTx());
|
||||
}
|
||||
}*/
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -362,9 +357,9 @@ class CreateOfferDataModel extends ActivatableDataModel {
|
|||
return user.getAcceptedArbitrators().size() > 0;
|
||||
}
|
||||
|
||||
boolean isFeeFromFundingTxSufficient() {
|
||||
return feeFromFundingTxProperty.get().compareTo(FeePolicy.getMinRequiredFeeForFundingTx()) >= 0;
|
||||
}
|
||||
/*boolean isFeeFromFundingTxSufficient() {
|
||||
return !isMainNet.get() || feeFromFundingTxProperty.get().compareTo(FeePolicy.getMinRequiredFeeForFundingTx()) >= 0;
|
||||
}*/
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -416,6 +411,8 @@ class CreateOfferDataModel extends ActivatableDataModel {
|
|||
}
|
||||
|
||||
missingCoin.set(totalToPayAsCoin.get().subtract(balance.get()));
|
||||
if (missingCoin.get().isNegative())
|
||||
missingCoin.set(Coin.ZERO);
|
||||
|
||||
isWalletFunded.set(isBalanceSufficient(balance.get()));
|
||||
if (isWalletFunded.get()) {
|
||||
|
|
|
@ -112,7 +112,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
|||
private ChangeListener<Boolean> showWarningAdjustedVolumeListener;
|
||||
private ChangeListener<String> errorMessageListener;
|
||||
private ChangeListener<Boolean> placeOfferCompletedListener;
|
||||
private ChangeListener<Coin> feeFromFundingTxListener;
|
||||
// private ChangeListener<Coin> feeFromFundingTxListener;
|
||||
private EventHandler<ActionEvent> paymentAccountsComboBoxSelectionHandler;
|
||||
|
||||
private EventHandler<ActionEvent> currencyComboBoxSelectionHandler;
|
||||
|
@ -123,6 +123,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
|||
private ChangeListener<Coin> balanceListener;
|
||||
private HBox fundingHBox;
|
||||
private Subscription isSpinnerVisibleSubscription;
|
||||
private Subscription cancelButton2StyleSubscription;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -267,7 +268,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
|||
.show();
|
||||
}
|
||||
} else {
|
||||
new Popup().information("You need to wait until your are bootstrapped to the network.\n" +
|
||||
new Popup().information("You need to wait until bootstrapping to the network is completed.\n" +
|
||||
"That might take up to about 2 minutes at startup.").show();
|
||||
}
|
||||
}
|
||||
|
@ -484,10 +485,13 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
|||
isSpinnerVisibleSubscription = EasyBind.subscribe(model.isSpinnerVisible,
|
||||
isSpinnerVisible -> spinner.setProgress(isSpinnerVisible ? -1 : 0));
|
||||
|
||||
cancelButton2StyleSubscription = EasyBind.subscribe(placeOfferButton.visibleProperty(),
|
||||
isVisible -> cancelButton2.setId(isVisible ? "cancel-button" : null));
|
||||
}
|
||||
|
||||
private void removeSubscriptions() {
|
||||
isSpinnerVisibleSubscription.unsubscribe();
|
||||
cancelButton2StyleSubscription.unsubscribe();
|
||||
}
|
||||
|
||||
private void createListeners() {
|
||||
|
@ -535,7 +539,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
|||
.show(), 100, TimeUnit.MILLISECONDS);
|
||||
};
|
||||
|
||||
feeFromFundingTxListener = (observable, oldValue, newValue) -> {
|
||||
/* feeFromFundingTxListener = (observable, oldValue, newValue) -> {
|
||||
log.debug("feeFromFundingTxListener " + newValue);
|
||||
if (!model.dataModel.isFeeFromFundingTxSufficient()) {
|
||||
new Popup().warning("The mining fee from your funding transaction is not sufficiently high.\n\n" +
|
||||
|
@ -556,7 +560,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
|||
})
|
||||
.show();
|
||||
}
|
||||
};
|
||||
};*/
|
||||
|
||||
paymentAccountsComboBoxSelectionHandler = e -> onPaymentAccountsComboBoxSelected();
|
||||
currencyComboBoxSelectionHandler = e -> onCurrencyComboBoxSelected();
|
||||
|
@ -609,7 +613,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
|||
model.showWarningInvalidFiatDecimalPlaces.addListener(showWarningInvalidFiatDecimalPlacesPlacesListener);
|
||||
model.showWarningAdjustedVolume.addListener(showWarningAdjustedVolumeListener);
|
||||
model.errorMessage.addListener(errorMessageListener);
|
||||
model.dataModel.feeFromFundingTxProperty.addListener(feeFromFundingTxListener);
|
||||
// model.dataModel.feeFromFundingTxProperty.addListener(feeFromFundingTxListener);
|
||||
|
||||
model.placeOfferCompleted.addListener(placeOfferCompletedListener);
|
||||
|
||||
|
@ -633,7 +637,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
|||
model.showWarningInvalidFiatDecimalPlaces.removeListener(showWarningInvalidFiatDecimalPlacesPlacesListener);
|
||||
model.showWarningAdjustedVolume.removeListener(showWarningAdjustedVolumeListener);
|
||||
model.errorMessage.removeListener(errorMessageListener);
|
||||
model.dataModel.feeFromFundingTxProperty.removeListener(feeFromFundingTxListener);
|
||||
// model.dataModel.feeFromFundingTxProperty.removeListener(feeFromFundingTxListener);
|
||||
|
||||
model.placeOfferCompleted.removeListener(placeOfferCompletedListener);
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
private String directionLabel;
|
||||
private String addressAsString;
|
||||
private final String paymentLabel;
|
||||
private boolean createOfferRequested;
|
||||
|
||||
final StringProperty amount = new SimpleStringProperty();
|
||||
final StringProperty minAmount = new SimpleStringProperty();
|
||||
|
@ -109,7 +110,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
private ChangeListener<Fiat> priceAsFiatListener;
|
||||
private ChangeListener<Fiat> volumeAsFiatListener;
|
||||
private ChangeListener<Boolean> isWalletFundedListener;
|
||||
private ChangeListener<Coin> feeFromFundingTxListener;
|
||||
//private ChangeListener<Coin> feeFromFundingTxListener;
|
||||
private ChangeListener<String> errorMessageListener;
|
||||
private Offer offer;
|
||||
private Timer timeoutTimer;
|
||||
|
@ -254,9 +255,9 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
isWalletFundedListener = (ov, oldValue, newValue) -> {
|
||||
updateButtonDisableState();
|
||||
};
|
||||
feeFromFundingTxListener = (ov, oldValue, newValue) -> {
|
||||
/* feeFromFundingTxListener = (ov, oldValue, newValue) -> {
|
||||
updateButtonDisableState();
|
||||
};
|
||||
};*/
|
||||
}
|
||||
|
||||
private void addListeners() {
|
||||
|
@ -273,7 +274,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
dataModel.priceAsFiat.addListener(priceAsFiatListener);
|
||||
dataModel.volumeAsFiat.addListener(volumeAsFiatListener);
|
||||
|
||||
dataModel.feeFromFundingTxProperty.addListener(feeFromFundingTxListener);
|
||||
// dataModel.feeFromFundingTxProperty.addListener(feeFromFundingTxListener);
|
||||
dataModel.isWalletFunded.addListener(isWalletFundedListener);
|
||||
}
|
||||
|
||||
|
@ -289,7 +290,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
dataModel.priceAsFiat.removeListener(priceAsFiatListener);
|
||||
dataModel.volumeAsFiat.removeListener(volumeAsFiatListener);
|
||||
|
||||
dataModel.feeFromFundingTxProperty.removeListener(feeFromFundingTxListener);
|
||||
//dataModel.feeFromFundingTxProperty.removeListener(feeFromFundingTxListener);
|
||||
dataModel.isWalletFunded.removeListener(isWalletFundedListener);
|
||||
|
||||
if (offer != null && errorMessageListener != null)
|
||||
|
@ -314,24 +315,24 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
|
||||
void onPlaceOffer(Offer offer, Runnable resultHandler) {
|
||||
errorMessage.set(null);
|
||||
|
||||
isPlaceOfferButtonDisabled.set(true);
|
||||
cancelButtonDisabled.set(true);
|
||||
createOfferRequested = true;
|
||||
|
||||
if (timeoutTimer == null) {
|
||||
timeoutTimer = UserThread.runAfter(() -> {
|
||||
stopTimeoutTimer();
|
||||
isPlaceOfferButtonDisabled.set(false);
|
||||
cancelButtonDisabled.set(false);
|
||||
createOfferRequested = false;
|
||||
errorMessage.set("A timeout occurred at publishing the offer.");
|
||||
|
||||
updateButtonDisableState();
|
||||
updateSpinnerInfo();
|
||||
|
||||
resultHandler.run();
|
||||
}, 30);
|
||||
}
|
||||
errorMessageListener = (observable, oldValue, newValue) -> {
|
||||
if (newValue != null) {
|
||||
stopTimeoutTimer();
|
||||
isPlaceOfferButtonDisabled.set(false);
|
||||
cancelButtonDisabled.set(false);
|
||||
createOfferRequested = false;
|
||||
if (offer.getState() == Offer.State.OFFER_FEE_PAID)
|
||||
errorMessage.set(newValue +
|
||||
"\n\nThe offer fee is already paid. In the worst case you have lost that fee. " +
|
||||
|
@ -340,10 +341,15 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
else
|
||||
errorMessage.set(newValue);
|
||||
|
||||
updateButtonDisableState();
|
||||
updateSpinnerInfo();
|
||||
|
||||
resultHandler.run();
|
||||
}
|
||||
};
|
||||
|
||||
offer.errorMessageProperty().addListener(errorMessageListener);
|
||||
|
||||
dataModel.onPlaceOffer(offer, transaction -> {
|
||||
stopTimeoutTimer();
|
||||
resultHandler.run();
|
||||
|
@ -351,16 +357,10 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
errorMessage.set(null);
|
||||
});
|
||||
|
||||
updateButtonDisableState();
|
||||
updateSpinnerInfo();
|
||||
}
|
||||
|
||||
private void stopTimeoutTimer() {
|
||||
if (timeoutTimer != null) {
|
||||
timeoutTimer.stop();
|
||||
timeoutTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void onPaymentAccountSelected(PaymentAccount paymentAccount) {
|
||||
btcValidator.setMaxTradeLimitInBitcoin(paymentAccount.getPaymentMethod().getMaxTradeLimitInBitcoin());
|
||||
dataModel.onPaymentAccountSelected(paymentAccount);
|
||||
|
@ -370,33 +370,6 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
dataModel.onCurrencySelected(tradeCurrency);
|
||||
}
|
||||
|
||||
public boolean isPriceInRange() {
|
||||
MarketPrice marketPrice = priceFeed.getMarketPrice(getTradeCurrency().getCode());
|
||||
if (marketPrice != null) {
|
||||
double marketPriceAsDouble = marketPrice.getPrice(PriceFeed.Type.LAST);
|
||||
Fiat priceAsFiat = dataModel.priceAsFiat.get();
|
||||
long shiftDivisor = checkedPow(10, priceAsFiat.smallestUnitExponent());
|
||||
double offerPrice = ((double) priceAsFiat.longValue()) / ((double) shiftDivisor);
|
||||
if (marketPriceAsDouble != 0 && Math.abs(1 - (offerPrice / marketPriceAsDouble)) > preferences.getMaxPriceDistanceInPercent()) {
|
||||
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 " +
|
||||
formatter.formatToPercent(preferences.getMaxPriceDistanceInPercent()) +
|
||||
" and can be adjusted in the preferences.")
|
||||
.actionButtonText("Change price")
|
||||
.onAction(() -> popup.hide())
|
||||
.closeButtonText("Go to \"Preferences\"")
|
||||
.onClose(() -> navigation.navigateTo(MainView.class, SettingsView.class, PreferencesView.class))
|
||||
.show();
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void onShowPayFundsScreen() {
|
||||
showPayFundsScreenDisplayed.set(true);
|
||||
updateSpinnerInfo();
|
||||
|
@ -514,6 +487,33 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
// Getters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public boolean isPriceInRange() {
|
||||
MarketPrice marketPrice = priceFeed.getMarketPrice(getTradeCurrency().getCode());
|
||||
if (marketPrice != null) {
|
||||
double marketPriceAsDouble = marketPrice.getPrice(PriceFeed.Type.LAST);
|
||||
Fiat priceAsFiat = dataModel.priceAsFiat.get();
|
||||
long shiftDivisor = checkedPow(10, priceAsFiat.smallestUnitExponent());
|
||||
double offerPrice = ((double) priceAsFiat.longValue()) / ((double) shiftDivisor);
|
||||
if (marketPriceAsDouble != 0 && Math.abs(1 - (offerPrice / marketPriceAsDouble)) > preferences.getMaxPriceDistanceInPercent()) {
|
||||
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 " +
|
||||
formatter.formatToPercent(preferences.getMaxPriceDistanceInPercent()) +
|
||||
" and can be adjusted in the preferences.")
|
||||
.actionButtonText("Change price")
|
||||
.onAction(() -> popup.hide())
|
||||
.closeButtonText("Go to \"Preferences\"")
|
||||
.onClose(() -> navigation.navigateTo(MainView.class, SettingsView.class, PreferencesView.class))
|
||||
.show();
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
BSFormatter getFormatter() {
|
||||
return formatter;
|
||||
}
|
||||
|
@ -579,6 +579,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
return p2PService.isBootstrapped();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Utils
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -660,9 +661,16 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
isFiatInputValid(volume.get()).isValid &&
|
||||
dataModel.isMinAmountLessOrEqualAmount();
|
||||
isNextButtonDisabled.set(!inputDataValid);
|
||||
isPlaceOfferButtonDisabled.set(!(inputDataValid &&
|
||||
dataModel.isWalletFunded.get() &&
|
||||
(dataModel.useSavingsWallet || dataModel.isFeeFromFundingTxSufficient()))
|
||||
);
|
||||
// boolean notSufficientFees = dataModel.isWalletFunded.get() && dataModel.isMainNet.get() && !dataModel.isFeeFromFundingTxSufficient.get();
|
||||
//isPlaceOfferButtonDisabled.set(createOfferRequested || !inputDataValid || notSufficientFees);
|
||||
isPlaceOfferButtonDisabled.set(createOfferRequested || !inputDataValid || !dataModel.isWalletFunded.get());
|
||||
}
|
||||
|
||||
|
||||
private void stopTimeoutTimer() {
|
||||
if (timeoutTimer != null) {
|
||||
timeoutTimer.stop();
|
||||
timeoutTimer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,20 +17,18 @@
|
|||
|
||||
package io.bitsquare.gui.main.offer.takeoffer;
|
||||
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
import com.google.inject.Inject;
|
||||
import io.bitsquare.app.BitsquareApp;
|
||||
import io.bitsquare.arbitration.Arbitrator;
|
||||
import io.bitsquare.btc.*;
|
||||
import io.bitsquare.btc.AddressEntry;
|
||||
import io.bitsquare.btc.FeePolicy;
|
||||
import io.bitsquare.btc.TradeWalletService;
|
||||
import io.bitsquare.btc.WalletService;
|
||||
import io.bitsquare.btc.blockchain.BlockchainService;
|
||||
import io.bitsquare.btc.listeners.BalanceListener;
|
||||
import io.bitsquare.btc.pricefeed.PriceFeed;
|
||||
import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.gui.common.model.ActivatableDataModel;
|
||||
import io.bitsquare.gui.main.overlays.notifications.Notification;
|
||||
import io.bitsquare.gui.main.overlays.popups.Popup;
|
||||
import io.bitsquare.gui.main.overlays.windows.WalletPasswordWindow;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
import io.bitsquare.locale.CurrencyUtil;
|
||||
|
@ -47,10 +45,8 @@ import javafx.collections.FXCollections;
|
|||
import javafx.collections.ObservableList;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -77,15 +73,15 @@ class TakeOfferDataModel extends ActivatableDataModel {
|
|||
private final Coin takerFeeAsCoin;
|
||||
private final Coin networkFeeAsCoin;
|
||||
private final Coin securityDepositAsCoin;
|
||||
Coin feeFromFundingTx = Coin.NEGATIVE_SATOSHI;
|
||||
|
||||
// Coin feeFromFundingTx = Coin.NEGATIVE_SATOSHI;
|
||||
|
||||
private Offer offer;
|
||||
|
||||
private AddressEntry addressEntry;
|
||||
final StringProperty btcCode = new SimpleStringProperty();
|
||||
final BooleanProperty isWalletFunded = new SimpleBooleanProperty();
|
||||
final BooleanProperty isFeeFromFundingTxSufficient = new SimpleBooleanProperty();
|
||||
final BooleanProperty isMainNet = new SimpleBooleanProperty();
|
||||
// final BooleanProperty isFeeFromFundingTxSufficient = new SimpleBooleanProperty();
|
||||
// final BooleanProperty isMainNet = new SimpleBooleanProperty();
|
||||
final ObjectProperty<Coin> amountAsCoin = new SimpleObjectProperty<>();
|
||||
final ObjectProperty<Fiat> volumeAsFiat = new SimpleObjectProperty<>();
|
||||
final ObjectProperty<Coin> totalToPayAsCoin = new SimpleObjectProperty<>();
|
||||
|
@ -124,7 +120,7 @@ class TakeOfferDataModel extends ActivatableDataModel {
|
|||
networkFeeAsCoin = FeePolicy.getFixedTxFeeForTrades();
|
||||
securityDepositAsCoin = FeePolicy.getSecurityDeposit();
|
||||
|
||||
isMainNet.set(preferences.getBitcoinNetwork() == BitcoinNetwork.MAINNET);
|
||||
// isMainNet.set(preferences.getBitcoinNetwork() == BitcoinNetwork.MAINNET);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -179,20 +175,16 @@ class TakeOfferDataModel extends ActivatableDataModel {
|
|||
if (BitsquareApp.DEV_MODE)
|
||||
amountAsCoin.set(offer.getAmount());
|
||||
|
||||
calculateTotalToPay();
|
||||
calculateVolume();
|
||||
calculateTotalToPay();
|
||||
updateBalance();
|
||||
|
||||
balanceListener = new BalanceListener(addressEntry.getAddress()) {
|
||||
@Override
|
||||
public void onBalanceChanged(Coin balance, Transaction tx) {
|
||||
updateBalance();
|
||||
|
||||
if (tx.getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING) {
|
||||
|
||||
}
|
||||
|
||||
if (isMainNet.get()) {
|
||||
/*if (isMainNet.get()) {
|
||||
SettableFuture<Coin> future = blockchainService.requestFee(tx.getHashAsString());
|
||||
Futures.addCallback(future, new FutureCallback<Coin>() {
|
||||
public void onSuccess(Coin fee) {
|
||||
|
@ -215,7 +207,7 @@ class TakeOfferDataModel extends ActivatableDataModel {
|
|||
} else {
|
||||
setFeeFromFundingTx(FeePolicy.getMinRequiredFeeForFundingTx());
|
||||
isFeeFromFundingTxSufficient.set(feeFromFundingTx.compareTo(FeePolicy.getMinRequiredFeeForFundingTx()) >= 0);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -347,20 +339,23 @@ class TakeOfferDataModel extends ActivatableDataModel {
|
|||
Coin savingWalletBalance = walletService.getSavingWalletBalance();
|
||||
totalAvailableBalance = savingWalletBalance.add(tradeWalletBalance);
|
||||
|
||||
if (totalAvailableBalance.compareTo(totalToPayAsCoin.get()) > 0)
|
||||
if (totalToPayAsCoin.get() != null && totalAvailableBalance.compareTo(totalToPayAsCoin.get()) > 0)
|
||||
balance.set(totalToPayAsCoin.get());
|
||||
else
|
||||
balance.set(totalAvailableBalance);
|
||||
} else {
|
||||
balance.set(tradeWalletBalance);
|
||||
}
|
||||
|
||||
missingCoin.set(totalToPayAsCoin.get().subtract(balance.get()));
|
||||
if (totalToPayAsCoin.get() != null) {
|
||||
missingCoin.set(totalToPayAsCoin.get().subtract(balance.get()));
|
||||
if (missingCoin.get().isNegative())
|
||||
missingCoin.set(Coin.ZERO);
|
||||
}
|
||||
|
||||
isWalletFunded.set(isBalanceSufficient(balance.get()));
|
||||
if (isWalletFunded.get()) {
|
||||
// walletService.removeBalanceListener(balanceListener);
|
||||
if (walletFundedNotification == null) {
|
||||
if (totalToPayAsCoin.get() != null && walletFundedNotification == null) {
|
||||
walletFundedNotification = new Notification()
|
||||
.headLine("Trading wallet update")
|
||||
.notification("Your trading wallet is sufficiently funded.\n" +
|
||||
|
@ -378,13 +373,13 @@ class TakeOfferDataModel extends ActivatableDataModel {
|
|||
|
||||
public void swapTradeToSavings() {
|
||||
walletService.swapTradeToSavings(offer.getId());
|
||||
setFeeFromFundingTx(Coin.NEGATIVE_SATOSHI);
|
||||
//setFeeFromFundingTx(Coin.NEGATIVE_SATOSHI);
|
||||
}
|
||||
|
||||
private void setFeeFromFundingTx(Coin fee) {
|
||||
/* private void setFeeFromFundingTx(Coin fee) {
|
||||
feeFromFundingTx = fee;
|
||||
isFeeFromFundingTxSufficient.set(feeFromFundingTx.compareTo(FeePolicy.getMinRequiredFeeForFundingTx()) >= 0);
|
||||
}
|
||||
}*/
|
||||
|
||||
boolean isMinAmountLessOrEqualAmount() {
|
||||
//noinspection SimplifiableIfStatement
|
||||
|
|
|
@ -64,7 +64,6 @@ import org.bitcoinj.uri.BitcoinURI;
|
|||
import org.controlsfx.control.PopOver;
|
||||
import org.fxmisc.easybind.EasyBind;
|
||||
import org.fxmisc.easybind.Subscription;
|
||||
import org.fxmisc.easybind.monadic.MonadicBinding;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -115,9 +114,10 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
|||
private ImageView qrCodeImageView;
|
||||
private HBox fundingHBox;
|
||||
private Subscription balanceSubscription;
|
||||
private Subscription noSufficientFeeSubscription;
|
||||
private MonadicBinding<Boolean> noSufficientFeeBinding;
|
||||
// private Subscription noSufficientFeeSubscription;
|
||||
// private MonadicBinding<Boolean> noSufficientFeeBinding;
|
||||
private Subscription totalToPaySubscription;
|
||||
private Subscription cancelButton2StyleSubscription;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -507,7 +507,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
|||
}
|
||||
});
|
||||
|
||||
noSufficientFeeBinding = EasyBind.combine(model.dataModel.isWalletFunded, model.dataModel.isMainNet, model.dataModel.isFeeFromFundingTxSufficient,
|
||||
/* noSufficientFeeBinding = EasyBind.combine(model.dataModel.isWalletFunded, model.dataModel.isMainNet, model.dataModel.isFeeFromFundingTxSufficient,
|
||||
(isWalletFunded, isMainNet, isFeeSufficient) -> isWalletFunded && isMainNet && !isFeeSufficient);
|
||||
noSufficientFeeSubscription = noSufficientFeeBinding.subscribe((observable, oldValue, newValue) -> {
|
||||
if (newValue)
|
||||
|
@ -527,10 +527,12 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
|||
navigation.navigateTo(MainView.class, FundsView.class, WithdrawalView.class);
|
||||
})
|
||||
.show();
|
||||
});
|
||||
});*/
|
||||
|
||||
balanceSubscription = EasyBind.subscribe(model.dataModel.balance, newValue -> balanceTextField.setBalance(newValue));
|
||||
totalToPaySubscription = EasyBind.subscribe(model.dataModel.totalToPayAsCoin, newValue -> balanceTextField.setTargetAmount(newValue));
|
||||
cancelButton2StyleSubscription = EasyBind.subscribe(takeOfferButton.visibleProperty(),
|
||||
isVisible -> cancelButton2.setId(isVisible ? "cancel-button" : null));
|
||||
}
|
||||
|
||||
private void removeSubscriptions() {
|
||||
|
@ -540,12 +542,13 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
|||
isSpinnerVisibleSubscription.unsubscribe();
|
||||
showWarningInvalidBtcDecimalPlacesSubscription.unsubscribe();
|
||||
showTransactionPublishedScreenSubscription.unsubscribe();
|
||||
noSufficientFeeSubscription.unsubscribe();
|
||||
// noSufficientFeeSubscription.unsubscribe();
|
||||
balanceSubscription.unsubscribe();
|
||||
totalToPaySubscription.unsubscribe();
|
||||
cancelButton2StyleSubscription.unsubscribe();
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Build UI elements
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -647,7 +650,10 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
|||
cancelButton1 = new Button(BSResources.get("shared.cancel"));
|
||||
cancelButton1.setDefaultButton(false);
|
||||
cancelButton1.setId("cancel-button");
|
||||
cancelButton1.setOnAction(e -> close());
|
||||
cancelButton1.setOnAction(e -> {
|
||||
model.dataModel.swapTradeToSavings();
|
||||
close();
|
||||
});
|
||||
|
||||
offerAvailabilitySpinner = new ProgressIndicator(0);
|
||||
offerAvailabilitySpinner.setPrefSize(18, 18);
|
||||
|
@ -758,15 +764,20 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
|||
|
||||
cancelButton2 = addButton(gridPane, ++gridRow, BSResources.get("shared.cancel"));
|
||||
cancelButton2.setOnAction(e -> {
|
||||
if (model.dataModel.isWalletFunded.get())
|
||||
if (model.dataModel.isWalletFunded.get()) {
|
||||
new Popup().warning("You have already paid in the funds.\n" +
|
||||
"Are you sure you want to cancel.")
|
||||
.actionButtonText("Yes, cancel")
|
||||
.onAction(() -> close())
|
||||
.closeButtonText("No")
|
||||
.actionButtonText("No")
|
||||
.onClose(() -> {
|
||||
model.dataModel.swapTradeToSavings();
|
||||
close();
|
||||
})
|
||||
.closeButtonText("Yes, cancel")
|
||||
.show();
|
||||
else
|
||||
} else {
|
||||
close();
|
||||
model.dataModel.swapTradeToSavings();
|
||||
}
|
||||
});
|
||||
cancelButton2.setDefaultButton(false);
|
||||
cancelButton2.setVisible(false);
|
||||
|
|
|
@ -42,8 +42,6 @@ import javafx.beans.value.ChangeListener;
|
|||
import javafx.collections.ObservableList;
|
||||
import org.bitcoinj.core.Address;
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.fxmisc.easybind.EasyBind;
|
||||
import org.fxmisc.easybind.Subscription;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
@ -99,7 +97,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
|||
private ChangeListener<Offer.State> offerStateListener;
|
||||
private ChangeListener<String> offerErrorListener;
|
||||
private ConnectionListener connectionListener;
|
||||
private Subscription isFeeSufficientSubscription;
|
||||
// private Subscription isFeeSufficientSubscription;
|
||||
private Runnable takeOfferSucceededHandler;
|
||||
|
||||
|
||||
|
@ -199,9 +197,11 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
|||
applyTradeState(trade.getState());
|
||||
trade.errorMessageProperty().addListener(tradeErrorListener);
|
||||
applyTradeErrorMessage(trade.errorMessageProperty().get());
|
||||
updateButtonDisableState();
|
||||
takeOfferCompleted.set(true);
|
||||
});
|
||||
|
||||
updateButtonDisableState();
|
||||
updateSpinnerInfo();
|
||||
}
|
||||
|
||||
public void onPaymentAccountSelected(PaymentAccount paymentAccount) {
|
||||
|
@ -390,8 +390,9 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
|||
&& !dataModel.isAmountLargerThanOfferAmount()
|
||||
&& isOfferAvailable.get();
|
||||
isNextButtonDisabled.set(!inputDataValid);
|
||||
boolean notSufficientFees = dataModel.isWalletFunded.get() && dataModel.isMainNet.get() && !dataModel.isFeeFromFundingTxSufficient.get();
|
||||
isTakeOfferButtonDisabled.set(takeOfferRequested || !inputDataValid || notSufficientFees);
|
||||
// boolean notSufficientFees = dataModel.isWalletFunded.get() && dataModel.isMainNet.get() && !dataModel.isFeeFromFundingTxSufficient.get();
|
||||
// isTakeOfferButtonDisabled.set(takeOfferRequested || !inputDataValid || notSufficientFees);
|
||||
isTakeOfferButtonDisabled.set(takeOfferRequested || !inputDataValid || !dataModel.isWalletFunded.get());
|
||||
}
|
||||
|
||||
|
||||
|
@ -467,11 +468,12 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
|||
showTransactionPublishedScreen.get()) {
|
||||
spinnerInfoText.set("");
|
||||
} else if (dataModel.isWalletFunded.get()) {
|
||||
if (dataModel.isFeeFromFundingTxSufficient.get()) {
|
||||
spinnerInfoText.set("");
|
||||
/* if (dataModel.isFeeFromFundingTxSufficient.get()) {
|
||||
spinnerInfoText.set("");
|
||||
} else {
|
||||
spinnerInfoText.set("Check if funding tx miner fee is sufficient...");
|
||||
}
|
||||
}*/
|
||||
} else {
|
||||
spinnerInfoText.set("Waiting for funds...");
|
||||
}
|
||||
|
@ -489,10 +491,10 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
|||
|
||||
dataModel.isWalletFunded.addListener(isWalletFundedListener);
|
||||
p2PService.getNetworkNode().addConnectionListener(connectionListener);
|
||||
isFeeSufficientSubscription = EasyBind.subscribe(dataModel.isFeeFromFundingTxSufficient, newValue -> {
|
||||
/* isFeeSufficientSubscription = EasyBind.subscribe(dataModel.isFeeFromFundingTxSufficient, newValue -> {
|
||||
updateButtonDisableState();
|
||||
updateSpinnerInfo();
|
||||
});
|
||||
});*/
|
||||
}
|
||||
|
||||
private void removeListeners() {
|
||||
|
@ -512,7 +514,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
|||
trade.errorMessageProperty().removeListener(tradeErrorListener);
|
||||
}
|
||||
p2PService.getNetworkNode().removeConnectionListener(connectionListener);
|
||||
isFeeSufficientSubscription.unsubscribe();
|
||||
//isFeeSufficientSubscription.unsubscribe();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue