From 0d34fed1bdda81e12262940e4890b27756011870 Mon Sep 17 00:00:00 2001 From: sqrrm Date: Sun, 27 Oct 2019 16:26:34 +0100 Subject: [PATCH] Display appropriate account age info header Depending on charge back risk type, accounts should show accountAgeWitness age or time since signing --- .../resources/i18n/displayStrings.properties | 3 ++- .../bisq/desktop/components/PeerInfoIcon.java | 22 ++++++++++++------- .../desktop/components/PeerInfoIconSmall.java | 8 +++++-- .../editor/PeerInfoWithTagEditor.java | 11 ++++++++-- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index b9c727b0c26..446f4891480 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -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 diff --git a/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java b/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java index ef119ec47f7..53d15f567ec 100644 --- a/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java +++ b/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java @@ -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; @@ -134,7 +136,7 @@ private PeerInfoIcon(NodeAddress nodeAddress, peerTagMap = preferences.getPeerTagMap(); boolean hasTraded = numTrades > 0; - long peersAccountAge = getPeersAccountAge(trade, offer); + Tuple2 peersAccount = getPeersAccountAge(trade, offer); if (offer == null) { checkNotNull(trade, "Trade must not be null if offer is null."); offer = trade.getOffer(); @@ -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 ? @@ -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; @@ -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 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, @@ -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 ? @@ -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 -> { diff --git a/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java b/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java index d72b2568e45..e506ffc2d55 100644 --- a/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java +++ b/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java @@ -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 diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/editor/PeerInfoWithTagEditor.java b/desktop/src/main/java/bisq/desktop/main/overlays/editor/PeerInfoWithTagEditor.java index ab2bb338817..4bf6f2dc91c 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/editor/PeerInfoWithTagEditor.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/editor/PeerInfoWithTagEditor.java @@ -90,6 +90,7 @@ public class PeerInfoWithTagEditor extends Overlay { private EventHandler keyEventEventHandler; @Nullable private String accountAge; + private String accountAgeInfo; @Nullable private String accountSigningState; @@ -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; @@ -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);