Skip to content

Commit

Permalink
Fix trade view peer info (#3549)
Browse files Browse the repository at this point in the history
* Rename: PeerInfoIcon makersAccount -> peersAccount

* Fix peer info in trade view peerinfoicon popup, fix #3548
  • Loading branch information
sqrrm authored and ripcurlx committed Nov 6, 2019
1 parent fee7850 commit 61e51a0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ public long getAccountAge(Offer offer) {
.orElse(-1L);
}

public long getAccountAge(Trade trade) {
return findTradePeerWitness(trade)
.map(accountAgeWitness -> getAccountAge(accountAgeWitness, new Date()))
.orElse(-1L);
}

///////////////////////////////////////////////////////////////////////////////////////////
// Signed age
///////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -290,6 +296,12 @@ public long getWitnessSignAge(Offer offer, Date now) {
.orElse(-1L);
}

public long getWitnessSignAge(Trade trade, Date now) {
return findTradePeerWitness(trade)
.map(witness -> getWitnessSignAge(witness, now))
.orElse(-1L);
}

public AccountAge getPeersAccountAgeCategory(long peersAccountAge) {
return getAccountAgeCategory(peersAccountAge);
}
Expand Down Expand Up @@ -697,6 +709,12 @@ public SignState getSignState(Offer offer) {
.orElse(SignState.UNSIGNED);
}

public SignState getSignState(Trade trade) {
return findTradePeerWitness(trade)
.map(this::getSignState)
.orElse(SignState.UNSIGNED);
}

public SignState getSignState(AccountAgeWitness accountAgeWitness) {
if (signedWitnessService.isSignedByArbitrator(accountAgeWitness)) {
return SignState.ARBITRATOR;
Expand Down
59 changes: 31 additions & 28 deletions desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

import bisq.network.p2p.NodeAddress;

import bisq.common.util.Tuple2;
import bisq.common.util.Tuple3;

import com.google.common.base.Charsets;

Expand Down Expand Up @@ -136,7 +136,7 @@ private PeerInfoIcon(NodeAddress nodeAddress,
peerTagMap = preferences.getPeerTagMap();

boolean hasTraded = numTrades > 0;
Tuple2<Long, String> peersAccount = getPeersAccountAge(trade, offer);
Tuple3<Long, String, String> peersAccount = getPeersAccountAge(trade, offer);
if (offer == null) {
checkNotNull(trade, "Trade must not be null if offer is null.");
offer = trade.getOffer();
Expand All @@ -147,7 +147,7 @@ private PeerInfoIcon(NodeAddress nodeAddress,
boolean isFiatCurrency = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode());

String accountAge = isFiatCurrency ?
peersAccount.first > -1 ? Res.get("peerInfoIcon.tooltip.age", DisplayUtils.formatAccountAge(peersAccount.first)) :
peersAccount.first > -1 ? Res.get("peerInfoIcon.tooltip.age", DisplayUtils.formatAccountAge(peersAccount.first)) :
Res.get("peerInfoIcon.tooltip.unknownAge") :
"";
tooltipText = hasTraded ?
Expand Down Expand Up @@ -249,36 +249,39 @@ private PeerInfoIcon(NodeAddress nodeAddress,

getChildren().addAll(outerBackground, innerBackground, avatarImageView, tagPane, numTradesPane);

boolean needsSigning = PaymentMethod.hasChargebackRisk(offer.getPaymentMethod(), offer.getCurrencyCode());
String accountSigningState = null;
String accountAgeInfo = peersAccount.second;

if (needsSigning) {
AccountAgeWitnessService.SignState signState = accountAgeWitnessService.getSignState(offer);
accountSigningState = StringUtils.capitalize(signState.getPresentation());

if (signState.equals(AccountAgeWitnessService.SignState.UNSIGNED))
accountAgeInfo = null;
}

addMouseListener(numTrades, privateNotificationManager, offer, preferences, formatter, useDevPrivilegeKeys,
isFiatCurrency, peersAccount.first, accountAgeInfo, accountSigningState);
isFiatCurrency, peersAccount.first, peersAccount.second, peersAccount.third);
}

private Tuple2<Long, String> getPeersAccountAge(@Nullable Trade trade, @Nullable Offer offer) {
// Return Sign age, account info, sign state
private Tuple3<Long, String, String> getPeersAccountAge(@Nullable Trade trade, @Nullable Offer offer) {
AccountAgeWitnessService.SignState signState;
long signAge = -1L;
long accountAge = -1L;
if (trade != null) {
offer = trade.getOffer();
if (offer == null) {
// unexpected
return new Tuple2<>(-1L, Res.get("peerInfo.age.noRisk"));
return new Tuple3<>(-1L, Res.get("peerInfo.age.noRisk"), null);
}
signState = accountAgeWitnessService.getSignState(trade);
signAge = accountAgeWitnessService.getWitnessSignAge(trade, new Date());
accountAge = accountAgeWitnessService.getAccountAge(trade);
} else {
checkNotNull(offer, "Offer must not be null if trade is null.");
signState = accountAgeWitnessService.getSignState(offer);
signAge = accountAgeWitnessService.getWitnessSignAge(offer, new Date());
accountAge = accountAgeWitnessService.getAccountAge(offer);
}
checkNotNull(offer, "Offer must not be null if trade is null.");
if (PaymentMethod.hasChargebackRisk(offer.getPaymentMethod(), offer.getCurrencyCode())) {
return new Tuple2<>(accountAgeWitnessService.getWitnessSignAge(offer, new Date()),
Res.get("peerInfo.age.chargeBackRisk"));
String accountAgeInfo = Res.get("peerInfo.age.chargeBackRisk");
String accountSigningState = StringUtils.capitalize(signState.getPresentation());
if (signState.equals(AccountAgeWitnessService.SignState.UNSIGNED))
accountAgeInfo = null;

return new Tuple3<>(signAge, accountAgeInfo, accountSigningState);
}
return new Tuple2<>(accountAgeWitnessService.getAccountAge(offer), Res.get("peerInfo.age.noRisk"));
return new Tuple3<>(accountAge, Res.get("peerInfo.age.noRisk"), null);
}

protected void addMouseListener(int numTrades,
Expand All @@ -288,21 +291,21 @@ protected void addMouseListener(int numTrades,
BSFormatter formatter,
boolean useDevPrivilegeKeys,
boolean isFiatCurrency,
long makersAccountAge,
String makersAccountAgeInfo,
long peersAccountAge,
String peersAccountAgeInfo,
String accountSigningState) {

final String accountAgeTagEditor = isFiatCurrency && makersAccountAgeInfo != null ?
makersAccountAge > -1 ?
DisplayUtils.formatAccountAge(makersAccountAge) :
final String accountAgeTagEditor = isFiatCurrency && peersAccountAgeInfo != null ?
peersAccountAge > -1 ?
DisplayUtils.formatAccountAge(peersAccountAge) :
Res.get("peerInfo.unknownAge") :
null;

setOnMouseClicked(e -> new PeerInfoWithTagEditor(privateNotificationManager, offer, preferences, useDevPrivilegeKeys)
.fullAddress(fullAddress)
.numTrades(numTrades)
.accountAge(accountAgeTagEditor)
.accountAgeInfo(makersAccountAgeInfo)
.accountAgeInfo(peersAccountAgeInfo)
.accountSigningState(accountSigningState)
.position(localToScene(new Point2D(0, 0)))
.onSave(newTag -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ protected void addMouseListener(int numTrades,
BSFormatter formatter,
boolean useDevPrivilegeKeys,
boolean isFiatCurrency,
long makersAccountAge,
String makersAccountAgeInfo,
long peersAccountAge,
String peersAccountAgeInfo,
String accountSigningState) {
}

Expand Down

0 comments on commit 61e51a0

Please sign in to comment.