From 61e51a0b7aecbd2b1df19ac1ff532f35f209ef94 Mon Sep 17 00:00:00 2001 From: sqrrm Date: Wed, 6 Nov 2019 18:55:09 +0100 Subject: [PATCH] Fix trade view peer info (#3549) * Rename: PeerInfoIcon makersAccount -> peersAccount * Fix peer info in trade view peerinfoicon popup, fix #3548 --- .../witness/AccountAgeWitnessService.java | 18 ++++++ .../bisq/desktop/components/PeerInfoIcon.java | 59 ++++++++++--------- .../desktop/components/PeerInfoIconSmall.java | 4 +- 3 files changed, 51 insertions(+), 30 deletions(-) diff --git a/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java b/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java index 37df8b9a634..9bc2d7b38db 100644 --- a/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java +++ b/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java @@ -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 /////////////////////////////////////////////////////////////////////////////////////////// @@ -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); } @@ -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; diff --git a/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java b/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java index af5428d188f..c7c15810f39 100644 --- a/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java +++ b/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java @@ -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; @@ -136,7 +136,7 @@ private PeerInfoIcon(NodeAddress nodeAddress, peerTagMap = preferences.getPeerTagMap(); boolean hasTraded = numTrades > 0; - Tuple2 peersAccount = getPeersAccountAge(trade, offer); + Tuple3 peersAccount = getPeersAccountAge(trade, offer); if (offer == null) { checkNotNull(trade, "Trade must not be null if offer is null."); offer = trade.getOffer(); @@ -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 ? @@ -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 getPeersAccountAge(@Nullable Trade trade, @Nullable Offer offer) { + // Return Sign age, account info, sign state + private Tuple3 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, @@ -288,13 +291,13 @@ 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; @@ -302,7 +305,7 @@ protected void addMouseListener(int numTrades, .fullAddress(fullAddress) .numTrades(numTrades) .accountAge(accountAgeTagEditor) - .accountAgeInfo(makersAccountAgeInfo) + .accountAgeInfo(peersAccountAgeInfo) .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 e506ffc2d55..28e0d681807 100644 --- a/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java +++ b/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java @@ -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) { }