mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 23:18:17 +01:00
apply code inspection
This commit is contained in:
parent
a5027d50dc
commit
5121e759d1
3 changed files with 51 additions and 51 deletions
|
@ -27,10 +27,8 @@ import io.bitsquare.btc.listeners.BalanceListener;
|
|||
import io.bitsquare.btc.provider.fee.FeeService;
|
||||
import io.bitsquare.btc.provider.price.PriceFeedService;
|
||||
import io.bitsquare.btc.wallet.BtcWalletService;
|
||||
import io.bitsquare.btc.wallet.TradeWalletService;
|
||||
import io.bitsquare.common.crypto.KeyRing;
|
||||
import io.bitsquare.common.util.Utilities;
|
||||
import io.bitsquare.gui.Navigation;
|
||||
import io.bitsquare.gui.common.model.ActivatableDataModel;
|
||||
import io.bitsquare.gui.main.offer.createoffer.monetary.Price;
|
||||
import io.bitsquare.gui.main.offer.createoffer.monetary.Volume;
|
||||
|
@ -66,7 +64,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
class CreateOfferDataModel extends ActivatableDataModel {
|
||||
private final OpenOfferManager openOfferManager;
|
||||
private final BtcWalletService walletService;
|
||||
private final TradeWalletService tradeWalletService;
|
||||
private final Preferences preferences;
|
||||
private final User user;
|
||||
private final KeyRing keyRing;
|
||||
|
@ -74,7 +71,6 @@ class CreateOfferDataModel extends ActivatableDataModel {
|
|||
private final PriceFeedService priceFeedService;
|
||||
final String shortOfferId;
|
||||
private final FeeService feeService;
|
||||
private final Navigation navigation;
|
||||
private final BSFormatter formatter;
|
||||
private final String offerId;
|
||||
private final AddressEntry addressEntry;
|
||||
|
@ -122,19 +118,17 @@ class CreateOfferDataModel extends ActivatableDataModel {
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Inject
|
||||
CreateOfferDataModel(OpenOfferManager openOfferManager, BtcWalletService walletService, TradeWalletService tradeWalletService,
|
||||
CreateOfferDataModel(OpenOfferManager openOfferManager, BtcWalletService walletService,
|
||||
Preferences preferences, User user, KeyRing keyRing, P2PService p2PService, PriceFeedService priceFeedService,
|
||||
FeeService feeService, Navigation navigation, BSFormatter formatter) {
|
||||
FeeService feeService, BSFormatter formatter) {
|
||||
this.openOfferManager = openOfferManager;
|
||||
this.walletService = walletService;
|
||||
this.tradeWalletService = tradeWalletService;
|
||||
this.preferences = preferences;
|
||||
this.user = user;
|
||||
this.keyRing = keyRing;
|
||||
this.p2PService = p2PService;
|
||||
this.priceFeedService = priceFeedService;
|
||||
this.feeService = feeService;
|
||||
this.navigation = navigation;
|
||||
this.formatter = formatter;
|
||||
|
||||
offerId = Utilities.getRandomPrefix(5, 8) + "-" +
|
||||
|
@ -226,7 +220,7 @@ class CreateOfferDataModel extends ActivatableDataModel {
|
|||
fillPaymentAccounts();
|
||||
|
||||
PaymentAccount account = user.findFirstPaymentAccountWithCurrency(tradeCurrency);
|
||||
if (account != null && !isUSBankAccount(account)) {
|
||||
if (account != null && isNotUSBankAccount(account)) {
|
||||
paymentAccount = account;
|
||||
this.tradeCurrency = tradeCurrency;
|
||||
} else {
|
||||
|
@ -240,7 +234,8 @@ class CreateOfferDataModel extends ActivatableDataModel {
|
|||
}
|
||||
}
|
||||
|
||||
tradeCurrencyCode.set(this.tradeCurrency.getCode());
|
||||
if (this.tradeCurrency != null)
|
||||
tradeCurrencyCode.set(this.tradeCurrency.getCode());
|
||||
|
||||
if (!preferences.getUseStickyMarketPrice())
|
||||
priceFeedService.setCurrencyCode(tradeCurrencyCode.get());
|
||||
|
@ -556,6 +551,7 @@ class CreateOfferDataModel extends ActivatableDataModel {
|
|||
log.debug("missingCoin " + missingCoin.get().toFriendlyString());
|
||||
|
||||
isWalletFunded.set(isBalanceSufficient(balance.get()));
|
||||
//noinspection PointlessBooleanExpression
|
||||
if (totalToPayAsCoin.get() != null && isWalletFunded.get() && walletFundedNotification == null && !DevFlags.DEV_MODE) {
|
||||
walletFundedNotification = new Notification()
|
||||
.headLine("Trading wallet update")
|
||||
|
@ -599,15 +595,16 @@ class CreateOfferDataModel extends ActivatableDataModel {
|
|||
|
||||
private void fillPaymentAccounts() {
|
||||
paymentAccounts.setAll(user.getPaymentAccounts().stream()
|
||||
.filter(e -> !isUSBankAccount(e))
|
||||
.filter(this::isNotUSBankAccount)
|
||||
.collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
private boolean isUSBankAccount(PaymentAccount paymentAccount) {
|
||||
private boolean isNotUSBankAccount(PaymentAccount paymentAccount) {
|
||||
//noinspection SimplifiableIfStatement
|
||||
if (paymentAccount instanceof SameCountryRestrictedBankAccount && paymentAccount.getContractData() instanceof BankAccountContractData)
|
||||
return ((SameCountryRestrictedBankAccount) paymentAccount).getCountryCode().equals("US");
|
||||
return !((SameCountryRestrictedBankAccount) paymentAccount).getCountryCode().equals("US");
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void setAmount(Coin amount) {
|
||||
|
|
|
@ -121,14 +121,14 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
|||
private EventHandler<ActionEvent> currencyComboBoxSelectionHandler;
|
||||
private int gridRow = 0;
|
||||
private final Preferences preferences;
|
||||
private BSFormatter formatter;
|
||||
private final BSFormatter formatter;
|
||||
private ChangeListener<String> tradeCurrencyCodeListener;
|
||||
private ImageView qrCodeImageView;
|
||||
private HBox fundingHBox;
|
||||
private Subscription isWaitingForFundsSubscription;
|
||||
private Subscription cancelButton2StyleSubscription;
|
||||
private Subscription balanceSubscription;
|
||||
private List<Node> editOfferElements = new ArrayList<>();
|
||||
private final List<Node> editOfferElements = new ArrayList<>();
|
||||
private boolean isActivated;
|
||||
private Label xLabel;
|
||||
private VBox fixedPriceBox;
|
||||
|
@ -172,7 +172,9 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
|||
paymentAccountsComboBox.setConverter(new StringConverter<PaymentAccount>() {
|
||||
@Override
|
||||
public String toString(PaymentAccount paymentAccount) {
|
||||
return paymentAccount.getAccountName() + " (" + paymentAccount.getSingleTradeCurrency().getCode() + ", " +
|
||||
TradeCurrency singleTradeCurrency = paymentAccount.getSingleTradeCurrency();
|
||||
String code = singleTradeCurrency != null ? singleTradeCurrency.getCode() : "";
|
||||
return paymentAccount.getAccountName() + " (" + code + ", " +
|
||||
Res.get(paymentAccount.getPaymentMethod().getId()) + ")";
|
||||
}
|
||||
|
||||
|
@ -299,10 +301,10 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
|||
if (model.isBootstrapped()) {
|
||||
if (model.hasAcceptedArbitrators()) {
|
||||
Offer offer = model.createAndGetOffer();
|
||||
//noinspection PointlessBooleanExpression
|
||||
if (!DevFlags.DEV_MODE)
|
||||
offerDetailsWindow.onPlaceOffer(() ->
|
||||
model.onPlaceOffer(offer, () ->
|
||||
offerDetailsWindow.hide()))
|
||||
model.onPlaceOffer(offer, offerDetailsWindow::hide))
|
||||
.show(offer);
|
||||
else
|
||||
model.onPlaceOffer(offer, () -> {
|
||||
|
@ -330,6 +332,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
|||
|
||||
balanceTextField.setTargetAmount(model.dataModel.totalToPayAsCoin.get());
|
||||
|
||||
//noinspection PointlessBooleanExpression
|
||||
if (!DevFlags.DEV_MODE) {
|
||||
String key = "securityDepositInfo";
|
||||
new Popup().backgroundInfo("To ensure that both traders follow the trade protocol they need to pay a security deposit.\n\n" +
|
||||
|
@ -416,7 +419,9 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
|||
|
||||
model.onPaymentAccountSelected(paymentAccount);
|
||||
} else {
|
||||
currencyTextField.setText(paymentAccount.getSingleTradeCurrency().getNameAndCode());
|
||||
TradeCurrency singleTradeCurrency = paymentAccount.getSingleTradeCurrency();
|
||||
if (singleTradeCurrency != null)
|
||||
currencyTextField.setText(singleTradeCurrency.getNameAndCode());
|
||||
model.onPaymentAccountSelected(paymentAccount);
|
||||
model.onCurrencySelected(paymentAccount.getSingleTradeCurrency());
|
||||
}
|
||||
|
@ -563,7 +568,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
|||
cancelButton2StyleSubscription = EasyBind.subscribe(placeOfferButton.visibleProperty(),
|
||||
isVisible -> cancelButton2.setId(isVisible ? "cancel-button" : null));
|
||||
|
||||
balanceSubscription = EasyBind.subscribe(model.dataModel.balance, newValue -> balanceTextField.setBalance(newValue));
|
||||
balanceSubscription = EasyBind.subscribe(model.dataModel.balance, balanceTextField::setBalance);
|
||||
}
|
||||
|
||||
private void removeSubscriptions() {
|
||||
|
@ -574,27 +579,27 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
|||
|
||||
private void createListeners() {
|
||||
amountFocusedListener = (o, oldValue, newValue) -> {
|
||||
model.onFocusOutAmountTextField(oldValue, newValue, amountTextField.getText());
|
||||
model.onFocusOutAmountTextField(oldValue, newValue);
|
||||
amountTextField.setText(model.amount.get());
|
||||
};
|
||||
minAmountFocusedListener = (o, oldValue, newValue) -> {
|
||||
model.onFocusOutMinAmountTextField(oldValue, newValue, minAmountTextField.getText());
|
||||
model.onFocusOutMinAmountTextField(oldValue, newValue);
|
||||
minAmountTextField.setText(model.minAmount.get());
|
||||
};
|
||||
priceFocusedListener = (o, oldValue, newValue) -> {
|
||||
model.onFocusOutPriceTextField(oldValue, newValue, fixedPriceTextField.getText());
|
||||
model.onFocusOutPriceTextField(oldValue, newValue);
|
||||
fixedPriceTextField.setText(model.price.get());
|
||||
};
|
||||
priceAsPercentageFocusedListener = (o, oldValue, newValue) -> {
|
||||
model.onFocusOutPriceAsPercentageTextField(oldValue, newValue, marketBasedPriceTextField.getText());
|
||||
model.onFocusOutPriceAsPercentageTextField(oldValue, newValue);
|
||||
marketBasedPriceTextField.setText(model.marketPriceMargin.get());
|
||||
};
|
||||
volumeFocusedListener = (o, oldValue, newValue) -> {
|
||||
model.onFocusOutVolumeTextField(oldValue, newValue, volumeTextField.getText());
|
||||
model.onFocusOutVolumeTextField(oldValue, newValue);
|
||||
volumeTextField.setText(model.volume.get());
|
||||
};
|
||||
securityDepositFocusedListener = (o, oldValue, newValue) -> {
|
||||
model.onFocusOutSecurityDepositTextField(oldValue, newValue, securityDepositTextField.getText());
|
||||
model.onFocusOutSecurityDepositTextField(oldValue, newValue);
|
||||
securityDepositTextField.setText(model.securityDeposit.get());
|
||||
};
|
||||
errorMessageListener = (o, oldValue, newValue) -> {
|
||||
|
@ -664,9 +669,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
|||
};
|
||||
|
||||
|
||||
marketPriceAvailableListener = (observable, oldValue, newValue) -> {
|
||||
updateMarketPriceAvailable();
|
||||
};
|
||||
marketPriceAvailableListener = (observable, oldValue, newValue) -> updateMarketPriceAvailable();
|
||||
}
|
||||
|
||||
private void updateMarketPriceAvailable() {
|
||||
|
@ -693,7 +696,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
|||
marketBasedPriceTextField.focusedProperty().addListener(priceAsPercentageFocusedListener);
|
||||
volumeTextField.focusedProperty().addListener(volumeFocusedListener);
|
||||
securityDepositTextField.focusedProperty().addListener(securityDepositFocusedListener);
|
||||
|
||||
|
||||
// warnings
|
||||
model.errorMessage.addListener(errorMessageListener);
|
||||
// model.dataModel.feeFromFundingTxProperty.addListener(feeFromFundingTxListener);
|
||||
|
@ -1054,9 +1057,9 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
|||
model.dataModel.setUseMarketBasedPrice(!fixedPriceSelected);
|
||||
|
||||
if (!fixedPriceButton.isSelected() && fixedPriceSelected)
|
||||
fixedPriceButton.setSelected(fixedPriceSelected);
|
||||
fixedPriceButton.setSelected(true);
|
||||
if (useMarketBasedPriceButton.isSelected() && !fixedPriceSelected)
|
||||
useMarketBasedPriceButton.setSelected(!fixedPriceSelected);
|
||||
useMarketBasedPriceButton.setSelected(false);
|
||||
}
|
||||
|
||||
fixedPriceButton.setMouseTransparent(fixedPriceSelected);
|
||||
|
|
|
@ -63,10 +63,10 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
private final BtcValidator btcValidator;
|
||||
private final SecurityDepositValidator securityDepositValidator;
|
||||
private final P2PService p2PService;
|
||||
private PriceFeedService priceFeedService;
|
||||
private Preferences preferences;
|
||||
private Navigation navigation;
|
||||
final BSFormatter formatter;
|
||||
private final PriceFeedService priceFeedService;
|
||||
private final Preferences preferences;
|
||||
private final Navigation navigation;
|
||||
private final BSFormatter formatter;
|
||||
private final FiatValidator fiatValidator;
|
||||
|
||||
private String amountDescription;
|
||||
|
@ -103,7 +103,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
final BooleanProperty isNextButtonDisabled = new SimpleBooleanProperty(true);
|
||||
final BooleanProperty placeOfferCompleted = new SimpleBooleanProperty();
|
||||
final BooleanProperty showPayFundsScreenDisplayed = new SimpleBooleanProperty();
|
||||
final BooleanProperty showTransactionPublishedScreen = new SimpleBooleanProperty();
|
||||
private final BooleanProperty showTransactionPublishedScreen = new SimpleBooleanProperty();
|
||||
final BooleanProperty isWaitingForFunds = new SimpleBooleanProperty();
|
||||
|
||||
final ObjectProperty<InputValidator.ValidationResult> amountValidationResult = new SimpleObjectProperty<>();
|
||||
|
@ -113,7 +113,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
final ObjectProperty<InputValidator.ValidationResult> securityDepositValidationResult = new SimpleObjectProperty<>();
|
||||
|
||||
// Those are needed for the addressTextField
|
||||
final ObjectProperty<Address> address = new SimpleObjectProperty<>();
|
||||
private final ObjectProperty<Address> address = new SimpleObjectProperty<>();
|
||||
|
||||
private ChangeListener<String> amountStringListener;
|
||||
private ChangeListener<String> minAmountStringListener;
|
||||
|
@ -178,7 +178,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
minAmount.set(amount.get());
|
||||
UserThread.runAfter(() -> {
|
||||
price.set("1000");
|
||||
onFocusOutPriceAsPercentageTextField(true, false, "");
|
||||
onFocusOutPriceAsPercentageTextField(true, false);
|
||||
}, 1);
|
||||
|
||||
setAmountToModel();
|
||||
|
@ -578,7 +578,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
"You need " + formatter.formatCoinWithCode(dataModel.totalToPayAsCoin.get()) + " but you have only " +
|
||||
formatter.formatCoinWithCode(dataModel.totalAvailableBalance) + " in your Bitsquare wallet.\n\n" +
|
||||
"Please fund that trade from an external Bitcoin wallet or fund your Bitsquare " +
|
||||
"wallet at \"Funds/Depost funds\".")
|
||||
"wallet at \"Funds/Deposit funds\".")
|
||||
.actionButtonText("Go to \"Funds/Deposit funds\"")
|
||||
.onAction(() -> navigation.navigateTo(MainView.class, FundsView.class, DepositView.class))
|
||||
.show();
|
||||
|
@ -593,7 +593,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// On focus out we do validation and apply the data to the model
|
||||
void onFocusOutAmountTextField(boolean oldValue, boolean newValue, String userInput) {
|
||||
void onFocusOutAmountTextField(boolean oldValue, boolean newValue) {
|
||||
if (oldValue && !newValue) {
|
||||
InputValidator.ValidationResult result = isBtcInputValid(amount.get());
|
||||
amountValidationResult.set(result);
|
||||
|
@ -615,7 +615,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
}
|
||||
}
|
||||
|
||||
void onFocusOutMinAmountTextField(boolean oldValue, boolean newValue, String userInput) {
|
||||
void onFocusOutMinAmountTextField(boolean oldValue, boolean newValue) {
|
||||
if (oldValue && !newValue) {
|
||||
InputValidator.ValidationResult result = isBtcInputValid(minAmount.get());
|
||||
minAmountValidationResult.set(result);
|
||||
|
@ -634,7 +634,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
}
|
||||
}
|
||||
|
||||
void onFocusOutPriceTextField(boolean oldValue, boolean newValue, String userInput) {
|
||||
void onFocusOutPriceTextField(boolean oldValue, boolean newValue) {
|
||||
if (oldValue && !newValue) {
|
||||
InputValidator.ValidationResult result = isPriceInputValid(price.get());
|
||||
boolean isValid = result.isValid;
|
||||
|
@ -651,13 +651,13 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
}
|
||||
}
|
||||
|
||||
void onFocusOutPriceAsPercentageTextField(boolean oldValue, boolean newValue, String userInput) {
|
||||
void onFocusOutPriceAsPercentageTextField(boolean oldValue, boolean newValue) {
|
||||
inputIsMarketBasedPrice = !oldValue && newValue;
|
||||
if (oldValue && !newValue)
|
||||
marketPriceMargin.set(formatter.formatRoundedDoubleWithPrecision(dataModel.getMarketPriceMargin() * 100, 2));
|
||||
}
|
||||
|
||||
void onFocusOutVolumeTextField(boolean oldValue, boolean newValue, String userInput) {
|
||||
void onFocusOutVolumeTextField(boolean oldValue, boolean newValue) {
|
||||
if (oldValue && !newValue) {
|
||||
InputValidator.ValidationResult result = isVolumeInputValid(volume.get());
|
||||
volumeValidationResult.set(result);
|
||||
|
@ -685,7 +685,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
}
|
||||
}
|
||||
|
||||
void onFocusOutSecurityDepositTextField(boolean oldValue, boolean newValue, String userInput) {
|
||||
void onFocusOutSecurityDepositTextField(boolean oldValue, boolean newValue) {
|
||||
if (oldValue && !newValue) {
|
||||
InputValidator.ValidationResult result = securityDepositValidator.validate(securityDeposit.get());
|
||||
securityDepositValidationResult.set(result);
|
||||
|
@ -708,17 +708,17 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
ignoreSecurityDepositStringListener = false;
|
||||
})
|
||||
.closeButtonText("Yes, use my lower value")
|
||||
.onClose(() -> applySecurityDepositOnFocusOut(result))
|
||||
.onClose(() -> applySecurityDepositOnFocusOut())
|
||||
.dontShowAgainId(securityDepositLowerAsDefault, preferences)
|
||||
.show();
|
||||
} else {
|
||||
applySecurityDepositOnFocusOut(result);
|
||||
applySecurityDepositOnFocusOut();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void applySecurityDepositOnFocusOut(InputValidator.ValidationResult result) {
|
||||
private void applySecurityDepositOnFocusOut() {
|
||||
setSecurityDepositToModel();
|
||||
ignoreSecurityDepositStringListener = true;
|
||||
securityDeposit.set(formatter.formatCoin(dataModel.securityDeposit.get()));
|
||||
|
@ -750,7 +750,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
formatter.formatToPercentWithSymbol(preferences.getMaxPriceDistanceInPercent()) +
|
||||
" and can be adjusted in the preferences.")
|
||||
.actionButtonText("Change price")
|
||||
.onAction(() -> popup.hide())
|
||||
.onAction(popup::hide)
|
||||
.closeButtonText("Go to \"Preferences\"")
|
||||
.onClose(() -> navigation.navigateTo(MainView.class, SettingsView.class, PreferencesView.class))
|
||||
.show();
|
||||
|
|
Loading…
Add table
Reference in a new issue