Skip to content

Commit

Permalink
Merge pull request #1938 from ManfredKarrer/persist-selected-account-…
Browse files Browse the repository at this point in the history
…at-takeoffer

Persist selected account at takeoffer
  • Loading branch information
ripcurlx authored Nov 26, 2018
2 parents 0e64a71 + 71162dd commit 502d99f
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 5 deletions.
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;
}

}

0 comments on commit 502d99f

Please sign in to comment.