diff --git a/common/src/main/proto/pb.proto b/common/src/main/proto/pb.proto index 36543d74f0e..6653b665363 100644 --- a/common/src/main/proto/pb.proto +++ b/common/src/main/proto/pb.proto @@ -1287,6 +1287,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/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; 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..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 @@ -63,6 +63,7 @@ import javafx.collections.ObservableList; import java.util.List; +import java.util.Set; import javax.annotation.Nullable; @@ -327,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()) { @@ -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 73cc8232682..e6ba7205271 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 @@ -283,7 +283,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; } - }