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

Display appropriate account age info header #3490

Merged
merged 1 commit into from
Oct 27, 2019
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
3 changes: 2 additions & 1 deletion core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2655,7 +2655,8 @@ peerInfo.title=Peer info
peerInfo.nrOfTrades=Number of completed trades
peerInfo.notTradedYet=You have not traded with that user so far.
peerInfo.setTag=Set tag for that peer
peerInfo.age=Payment account age
peerInfo.age.noRisk=Payment account age
peerInfo.age.chargeBackRisk=Time since signing
peerInfo.unknownAge=Age not known

addressTextField.openWallet=Open your default Bitcoin wallet
Expand Down
22 changes: 14 additions & 8 deletions desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

import bisq.network.p2p.NodeAddress;

import bisq.common.util.Tuple2;

import com.google.common.base.Charsets;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -134,7 +136,7 @@ private PeerInfoIcon(NodeAddress nodeAddress,
peerTagMap = preferences.getPeerTagMap();

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

String accountAge = isFiatCurrency ?
peersAccountAge > -1 ? Res.get("peerInfoIcon.tooltip.age", DisplayUtils.formatAccountAge(peersAccountAge)) :
peersAccount.first > -1 ? Res.get("peerInfoIcon.tooltip.age", DisplayUtils.formatAccountAge(peersAccount.first)) :
Res.get("peerInfoIcon.tooltip.unknownAge") :
"";
tooltipText = hasTraded ?
Expand All @@ -156,7 +158,7 @@ private PeerInfoIcon(NodeAddress nodeAddress,
Color ringColor;
if (isFiatCurrency) {

switch (accountAgeWitnessService.getPeersAccountAgeCategory(peersAccountAge)) {
switch (accountAgeWitnessService.getPeersAccountAgeCategory(peersAccount.first)) {
case TWO_MONTHS_OR_MORE:
ringColor = Color.rgb(0, 225, 0); // > 2 months green
break;
Expand Down Expand Up @@ -253,22 +255,24 @@ private PeerInfoIcon(NodeAddress nodeAddress,
accountSigningState = StringUtils.capitalize(accountAgeWitnessService.getSignState(offer).getPresentation());
}

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

private long getPeersAccountAge(@Nullable Trade trade, @Nullable Offer offer) {
private Tuple2<Long, String> getPeersAccountAge(@Nullable Trade trade, @Nullable Offer offer) {
if (trade != null) {
offer = trade.getOffer();
if (offer == null) {
// unexpected
return -1;
return new Tuple2<>(-1L, Res.get("peerInfo.age.noRisk"));
}
}
checkNotNull(offer, "Offer must not be null if trade is null.");
if (PaymentMethod.hasChargebackRisk(offer.getPaymentMethod(), offer.getCurrencyCode())) {
return accountAgeWitnessService.getWitnessSignAge(offer, new Date());
return new Tuple2<>(accountAgeWitnessService.getWitnessSignAge(offer, new Date()),
Res.get("peerInfo.age.chargeBackRisk"));
}
return accountAgeWitnessService.getAccountAge(offer);
return new Tuple2<>(accountAgeWitnessService.getAccountAge(offer), Res.get("peerInfo.age.noRisk"));
}

protected void addMouseListener(int numTrades,
Expand All @@ -279,6 +283,7 @@ protected void addMouseListener(int numTrades,
boolean useDevPrivilegeKeys,
boolean isFiatCurrency,
long makersAccountAge,
String makersAccountAgeInfo,
String accountSigningState) {
final String accountAgeTagEditor = isFiatCurrency ?
makersAccountAge > -1 ?
Expand All @@ -290,6 +295,7 @@ protected void addMouseListener(int numTrades,
.fullAddress(fullAddress)
.numTrades(numTrades)
.accountAge(accountAgeTagEditor)
.accountAgeInfo(makersAccountAgeInfo)
.accountSigningState(accountSigningState)
.position(localToScene(new Point2D(0, 0)))
.onSave(newTag -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ protected double getScaleFactor() {
@Override
protected void addMouseListener(int numTrades,
PrivateNotificationManager privateNotificationManager,
Offer offer, Preferences preferences,
Offer offer,
Preferences preferences,
BSFormatter formatter,
boolean useDevPrivilegeKeys,
boolean isFiatCurrency, long makersAccountAge, String accountSigningState) {
boolean isFiatCurrency,
long makersAccountAge,
String makersAccountAgeInfo,
String accountSigningState) {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public class PeerInfoWithTagEditor extends Overlay<PeerInfoWithTagEditor> {
private EventHandler<KeyEvent> keyEventEventHandler;
@Nullable
private String accountAge;
private String accountAgeInfo;
@Nullable
private String accountSigningState;

Expand Down Expand Up @@ -128,6 +129,11 @@ public PeerInfoWithTagEditor accountAge(@Nullable String accountAge) {
return this;
}

public PeerInfoWithTagEditor accountAgeInfo(String accountAgeInfo) {
this.accountAgeInfo = accountAgeInfo;
return this;
}

public PeerInfoWithTagEditor accountSigningState(@Nullable String accountSigningState) {
this.accountSigningState = accountSigningState;
return this;
Expand Down Expand Up @@ -198,8 +204,9 @@ private void addContent() {
GridPane.setColumnSpan(addCompactTopLabelTextField(gridPane, ++rowIndex,
Res.get("peerInfo.nrOfTrades"),
numTrades > 0 ? String.valueOf(numTrades) : Res.get("peerInfo.notTradedYet")).third, 2);
if (accountAge != null)
GridPane.setColumnSpan(addCompactTopLabelTextField(gridPane, ++rowIndex, Res.get("peerInfo.age"), accountAge).third, 2);
if (accountAge != null) {
GridPane.setColumnSpan(addCompactTopLabelTextField(gridPane, ++rowIndex, accountAgeInfo, accountAge).third, 2);
}

if (accountSigningState != null) {
GridPane.setColumnSpan(addCompactTopLabelTextField(gridPane, ++rowIndex, Res.get("shared.accountSigningState"), accountSigningState).third, 2);
Expand Down