From 3157e86f8b4218f6915364a707698b81df57192e Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sat, 17 Nov 2018 13:29:52 -0500 Subject: [PATCH 1/3] Persist last selected payment account at take offer The last selected payment account gets persisted so that at the next take offer attempt that same account is selected in the combo box in case there are multiple accounts for that currency. --- common/src/main/proto/pb.proto | 1 + .../main/java/bisq/core/user/Preferences.java | 7 ++++++ .../bisq/core/user/PreferencesPayload.java | 6 ++++- .../offer/takeoffer/TakeOfferDataModel.java | 22 ++++++++++++++++++- .../main/offer/takeoffer/TakeOfferView.java | 2 +- .../offer/takeoffer/TakeOfferViewModel.java | 5 ++++- 6 files changed, 39 insertions(+), 4 deletions(-) diff --git a/common/src/main/proto/pb.proto b/common/src/main/proto/pb.proto index af0f3c01229..b3702dbba4d 100644 --- a/common/src/main/proto/pb.proto +++ b/common/src/main/proto/pb.proto @@ -1281,6 +1281,7 @@ message PreferencesPayload { bool is_dao_full_node = 46; string rpc_user = 47; string rpc_pw = 48; + string take_offer_selected_payment_account_id = 49; } /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/core/src/main/java/bisq/core/user/Preferences.java b/core/src/main/java/bisq/core/user/Preferences.java index ef87b2eebb5..8a21523c9d9 100644 --- a/core/src/main/java/bisq/core/user/Preferences.java +++ b/core/src/main/java/bisq/core/user/Preferences.java @@ -631,6 +631,11 @@ public void setRpcPw(String value) { persist(); } + public void setTakeOfferSelectedPaymentAccountId(String value) { + prefPayload.setTakeOfferSelectedPaymentAccountId(value); + persist(); + } + /////////////////////////////////////////////////////////////////////////////////////////// // Getter @@ -839,5 +844,7 @@ private interface ExcludesDelegateMethods { void setRpcUser(String value); void setRpcPw(String value); + + void setTakeOfferSelectedPaymentAccountId(String value); } } diff --git a/core/src/main/java/bisq/core/user/PreferencesPayload.java b/core/src/main/java/bisq/core/user/PreferencesPayload.java index d4699a4270e..662126bfa34 100644 --- a/core/src/main/java/bisq/core/user/PreferencesPayload.java +++ b/core/src/main/java/bisq/core/user/PreferencesPayload.java @@ -115,6 +115,8 @@ public final class PreferencesPayload implements PersistableEnvelope { String rpcUser; @Nullable String rpcPw; + @Nullable + String takeOfferSelectedPaymentAccountId; /////////////////////////////////////////////////////////////////////////////////////////// @@ -185,6 +187,7 @@ public Message toProtoMessage() { Optional.ofNullable(phoneKeyAndToken).ifPresent(builder::setPhoneKeyAndToken); Optional.ofNullable(rpcUser).ifPresent(builder::setRpcUser); Optional.ofNullable(rpcPw).ifPresent(builder::setRpcPw); + Optional.ofNullable(takeOfferSelectedPaymentAccountId).ifPresent(builder::setTakeOfferSelectedPaymentAccountId); return PB.PersistableEnvelope.newBuilder().setPreferencesPayload(builder).build(); } @@ -249,6 +252,7 @@ public static PersistableEnvelope fromProto(PB.PreferencesPayload proto, CorePro proto.getUseStandbyMode(), proto.getIsDaoFullNode(), proto.getRpcUser().isEmpty() ? null : proto.getRpcUser(), - proto.getRpcPw().isEmpty() ? null : proto.getRpcPw()); + proto.getRpcPw().isEmpty() ? null : proto.getRpcPw(), + proto.getTakeOfferSelectedPaymentAccountId().isEmpty() ? null : proto.getTakeOfferSelectedPaymentAccountId()); } } 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 b5eadc52933..87dee78b333 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 @@ -63,6 +63,7 @@ import javafx.collections.ObservableList; import java.util.List; +import java.util.Set; import javax.annotation.Nullable; @@ -411,6 +412,8 @@ public void onPaymentAccountSelected(PaymentAccount paymentAccount) { long myLimit = accountAgeWitnessService.getMyTradeLimit(paymentAccount, getCurrencyCode()); this.amount.set(Coin.valueOf(Math.min(amount.get().value, myLimit))); + + preferences.setTakeOfferSelectedPaymentAccountId(paymentAccount.getId()); } } @@ -437,7 +440,24 @@ public Offer getOffer() { } ObservableList getPossiblePaymentAccounts() { - return PaymentAccountUtil.getPossiblePaymentAccounts(offer, user.getPaymentAccounts()); + Set paymentAccounts = user.getPaymentAccounts(); + checkNotNull(paymentAccounts, "paymentAccounts must not be null"); + return PaymentAccountUtil.getPossiblePaymentAccounts(offer, paymentAccounts); + } + + public PaymentAccount getLastSelectedPaymentAccount() { + ObservableList possiblePaymentAccounts = getPossiblePaymentAccounts(); + checkArgument(!possiblePaymentAccounts.isEmpty(), "possiblePaymentAccounts must not be empty"); + PaymentAccount firstItem = possiblePaymentAccounts.get(0); + + String id = preferences.getTakeOfferSelectedPaymentAccountId(); + if (id == null) + return firstItem; + + return possiblePaymentAccounts.stream() + .filter(e -> e.getId().equals(id)) + .findAny() + .orElse(firstItem); } boolean hasAcceptedArbitrators() { 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 9913313e4b2..e5661137059 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,7 +282,7 @@ protected void activate() { if (model.getPossiblePaymentAccounts().size() > 1) { paymentAccountsComboBox.setItems(model.getPossiblePaymentAccounts()); - paymentAccountsComboBox.getSelectionModel().select(0); + paymentAccountsComboBox.getSelectionModel().select(model.getLastSelectedPaymentAccount()); paymentAccountTitledGroupBg.setText(Res.get("shared.selectTradingAccount")); 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 4e992eba814..bfbe50810db 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 @@ -734,6 +734,10 @@ ObservableList getPossiblePaymentAccounts() { return dataModel.getPossiblePaymentAccounts(); } + public PaymentAccount getLastSelectedPaymentAccount() { + return dataModel.getLastSelectedPaymentAccount(); + } + boolean hasAcceptedArbitrators() { return dataModel.hasAcceptedArbitrators(); } @@ -769,5 +773,4 @@ public String getSellerSecurityDeposit() { private BSFormatter getFormatterForTakerFee() { return dataModel.isCurrencyForTakerFeeBtc() ? btcFormatter : bsqFormatter; } - } From 89825a3ef8a47b091258a2982eb9428749b34490 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sat, 17 Nov 2018 13:35:53 -0500 Subject: [PATCH 2/3] Cleanup --- .../bisq/desktop/main/offer/takeoffer/TakeOfferDataModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 87dee78b333..2d47c5f3321 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 @@ -328,7 +328,7 @@ void onTakeOffer(TradeResultHandler tradeResultHandler) { // leading to a smaller tx and too high fees. Simply updating the fee estimation would lead to changed required funds // and if funds get higher (if tx get larger) the user would get confused (adding small inputs would increase total required funds). // So that would require more thoughts how to deal with all those cases. - public void estimateTxSize() { + private void estimateTxSize() { Address fundingAddress = btcWalletService.getFreshAddressEntry().getAddress(); int txSize = 0; if (btcWalletService.getBalance(Wallet.BalanceType.AVAILABLE).isPositive()) { From 71162dddc32643eaf47f0c69045ad9c7bd6d44b4 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 26 Nov 2018 00:53:28 +0100 Subject: [PATCH 3/3] Fix missing currency check at create offer At create offer the last selected currency was applied without checking if the currency matches. So when browsing an altcoin you got the last fiat account selected in case u had multiple fiat accounts and selected one in the past. --- .../main/java/bisq/desktop/main/offer/MutableOfferDataModel.java | 1 + 1 file changed, 1 insertion(+) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index 43f1a603d7e..045f474c455 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -259,6 +259,7 @@ public boolean initWithData(OfferPayload.Direction direction, TradeCurrency trad PaymentAccount lastSelectedPaymentAccount = getPreselectedPaymentAccount(); if (lastSelectedPaymentAccount != null && + lastSelectedPaymentAccount.getTradeCurrencies().contains(tradeCurrency) && user.getPaymentAccounts() != null && user.getPaymentAccounts().stream().anyMatch(paymentAccount -> paymentAccount.getId().equals(lastSelectedPaymentAccount.getId()))) { account = lastSelectedPaymentAccount;