Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist selected account at takeoffer #1938

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/src/main/proto/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

///////////////////////////////////////////////////////////////////////////////////////////
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/bisq/core/user/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,11 @@ public void setRpcPw(String value) {
persist();
}

public void setTakeOfferSelectedPaymentAccountId(String value) {
prefPayload.setTakeOfferSelectedPaymentAccountId(value);
persist();
}


///////////////////////////////////////////////////////////////////////////////////////////
// Getter
Expand Down Expand Up @@ -839,5 +844,7 @@ private interface ExcludesDelegateMethods {
void setRpcUser(String value);

void setRpcPw(String value);

void setTakeOfferSelectedPaymentAccountId(String value);
}
}
6 changes: 5 additions & 1 deletion core/src/main/java/bisq/core/user/PreferencesPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public final class PreferencesPayload implements PersistableEnvelope {
String rpcUser;
@Nullable
String rpcPw;
@Nullable
String takeOfferSelectedPaymentAccountId;


///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import javafx.collections.ObservableList;

import java.util.List;
import java.util.Set;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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());
}
}

Expand All @@ -437,7 +440,24 @@ public Offer getOffer() {
}

ObservableList<PaymentAccount> getPossiblePaymentAccounts() {
return PaymentAccountUtil.getPossiblePaymentAccounts(offer, user.getPaymentAccounts());
Set<PaymentAccount> paymentAccounts = user.getPaymentAccounts();
checkNotNull(paymentAccounts, "paymentAccounts must not be null");
return PaymentAccountUtil.getPossiblePaymentAccounts(offer, paymentAccounts);
}

public PaymentAccount getLastSelectedPaymentAccount() {
ObservableList<PaymentAccount> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,10 @@ ObservableList<PaymentAccount> getPossiblePaymentAccounts() {
return dataModel.getPossiblePaymentAccounts();
}

public PaymentAccount getLastSelectedPaymentAccount() {
return dataModel.getLastSelectedPaymentAccount();
}

boolean hasAcceptedArbitrators() {
return dataModel.hasAcceptedArbitrators();
}
Expand Down Expand Up @@ -769,5 +773,4 @@ public String getSellerSecurityDeposit() {
private BSFormatter getFormatterForTakerFee() {
return dataModel.isCurrencyForTakerFeeBtc() ? btcFormatter : bsqFormatter;
}

}