From 50b41369ee0efb53febb3e5f609e628cfe5511c3 Mon Sep 17 00:00:00 2001 From: Jeffrey Ko Date: Sat, 5 Jan 2019 00:07:08 +0700 Subject: [PATCH] Update offer button state on account change Add updateButtonDisabledState() to onPaymentAccountSelected() in TakeOfferViewModel since changing the account dropdown in the take offer screen does not trigger an update of the "Next Step" button. The default amount of an offer should not change to less than what is actually offered, change onPaymentAccountSelected() in TakeOfferDataModel to take into account the min. amount offered. In TakeOfferView, the payment account defaults to the last one selected. Make sure TakeOfferViewModel and TakeOfferDataModel take this into account in a couple locations. --- .../desktop/main/offer/takeoffer/TakeOfferDataModel.java | 4 ++-- .../bisq/desktop/main/offer/takeoffer/TakeOfferView.java | 5 +++-- .../desktop/main/offer/takeoffer/TakeOfferViewModel.java | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferDataModel.java index 2d47c5f3321..64a35a7995e 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferDataModel.java @@ -178,7 +178,7 @@ void initWithData(Offer offer) { ObservableList possiblePaymentAccounts = getPossiblePaymentAccounts(); checkArgument(!possiblePaymentAccounts.isEmpty(), "possiblePaymentAccounts.isEmpty()"); - paymentAccount = possiblePaymentAccounts.get(0); + paymentAccount = getLastSelectedPaymentAccount(); long myLimit = accountAgeWitnessService.getMyTradeLimit(paymentAccount, getCurrencyCode()); this.amount.set(Coin.valueOf(Math.min(offer.getAmount().value, myLimit))); @@ -411,7 +411,7 @@ public void onPaymentAccountSelected(PaymentAccount paymentAccount) { this.paymentAccount = paymentAccount; long myLimit = accountAgeWitnessService.getMyTradeLimit(paymentAccount, getCurrencyCode()); - this.amount.set(Coin.valueOf(Math.min(amount.get().value, myLimit))); + this.amount.set(Coin.valueOf(Math.max(offer.getMinAmount().value, Math.min(amount.get().value, myLimit)))); preferences.setTakeOfferSelectedPaymentAccountId(paymentAccount.getId()); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferView.java index 2b252d53b9a..e766e04941e 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferView.java @@ -282,9 +282,10 @@ protected void activate() { volumeDescriptionLabel.setText(model.volumeDescriptionLabel.get()); if (model.getPossiblePaymentAccounts().size() > 1) { + PaymentAccount lastPaymentAccount = model.getLastSelectedPaymentAccount(); paymentAccountsComboBox.setItems(model.getPossiblePaymentAccounts()); - paymentAccountsComboBox.getSelectionModel().select(model.getLastSelectedPaymentAccount()); - + paymentAccountsComboBox.getSelectionModel().select(lastPaymentAccount); + model.onPaymentAccountSelected(lastPaymentAccount); paymentAccountTitledGroupBg.setText(Res.get("shared.selectTradingAccount")); // TODO if we have multiple payment accounts we should show some info/warning to diff --git a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java index c16696bd0d1..0d0def08011 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java @@ -246,6 +246,7 @@ void onTakeOffer(Runnable resultHandler) { public void onPaymentAccountSelected(PaymentAccount paymentAccount) { dataModel.onPaymentAccountSelected(paymentAccount); btcValidator.setMaxTradeLimit(Coin.valueOf(Math.min(dataModel.getMaxTradeLimit(), offer.getAmount().value))); + updateButtonDisableState(); } public void onShowPayFundsScreen() {