mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Fix account age display of peer
We only showed makers account age before also at trade screens. This PR fixes that so that the trade peers account age is displayed at the peer info icon.
This commit is contained in:
parent
ad4be15eea
commit
f88af6b450
@ -161,7 +161,7 @@ public class AccountAgeWitnessService {
|
||||
return new AccountAgeWitness(hash, new Date().getTime());
|
||||
}
|
||||
|
||||
private Optional<AccountAgeWitness> findWitness(PaymentAccountPayload paymentAccountPayload, PubKeyRing pubKeyRing) {
|
||||
public Optional<AccountAgeWitness> findWitness(PaymentAccountPayload paymentAccountPayload, PubKeyRing pubKeyRing) {
|
||||
byte[] accountInputDataWithSalt = getAccountInputDataWithSalt(paymentAccountPayload);
|
||||
byte[] hash = Hash.getSha256Ripemd160hash(Utilities.concatenateByteArrays(accountInputDataWithSalt,
|
||||
pubKeyRing.getSignaturePubKeyBytes()));
|
||||
|
@ -23,12 +23,18 @@ import bisq.core.alert.PrivateNotificationManager;
|
||||
import bisq.core.locale.CurrencyUtil;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.offer.Offer;
|
||||
import bisq.core.payment.AccountAgeWitness;
|
||||
import bisq.core.payment.AccountAgeWitnessService;
|
||||
import bisq.core.payment.payload.PaymentAccountPayload;
|
||||
import bisq.core.trade.Trade;
|
||||
import bisq.core.trade.protocol.TradingPeer;
|
||||
import bisq.core.user.Preferences;
|
||||
import bisq.core.util.BSFormatter;
|
||||
|
||||
import bisq.network.p2p.NodeAddress;
|
||||
|
||||
import bisq.common.crypto.PubKeyRing;
|
||||
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
@ -45,13 +51,19 @@ import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@Slf4j
|
||||
public class PeerInfoIcon extends Group {
|
||||
private final String tooltipText;
|
||||
private final int numTrades;
|
||||
private final AccountAgeWitnessService accountAgeWitnessService;
|
||||
private final Map<String, String> peerTagMap;
|
||||
private final Label numTradesLabel;
|
||||
private final Label tagLabel;
|
||||
@ -69,7 +81,52 @@ public class PeerInfoIcon extends Group {
|
||||
AccountAgeWitnessService accountAgeWitnessService,
|
||||
BSFormatter formatter,
|
||||
boolean useDevPrivilegeKeys) {
|
||||
this(nodeAddress,
|
||||
role,
|
||||
numTrades,
|
||||
privateNotificationManager,
|
||||
offer,
|
||||
null,
|
||||
preferences,
|
||||
accountAgeWitnessService,
|
||||
formatter,
|
||||
useDevPrivilegeKeys);
|
||||
|
||||
}
|
||||
|
||||
public PeerInfoIcon(NodeAddress nodeAddress,
|
||||
String role,
|
||||
int numTrades,
|
||||
PrivateNotificationManager privateNotificationManager,
|
||||
Trade trade,
|
||||
Preferences preferences,
|
||||
AccountAgeWitnessService accountAgeWitnessService,
|
||||
BSFormatter formatter,
|
||||
boolean useDevPrivilegeKeys) {
|
||||
this(nodeAddress,
|
||||
role,
|
||||
numTrades,
|
||||
privateNotificationManager,
|
||||
null,
|
||||
trade,
|
||||
preferences,
|
||||
accountAgeWitnessService,
|
||||
formatter,
|
||||
useDevPrivilegeKeys);
|
||||
}
|
||||
|
||||
private PeerInfoIcon(NodeAddress nodeAddress,
|
||||
String role,
|
||||
int numTrades,
|
||||
PrivateNotificationManager privateNotificationManager,
|
||||
@Nullable Offer offer,
|
||||
@Nullable Trade trade,
|
||||
Preferences preferences,
|
||||
AccountAgeWitnessService accountAgeWitnessService,
|
||||
BSFormatter formatter,
|
||||
boolean useDevPrivilegeKeys) {
|
||||
this.numTrades = numTrades;
|
||||
this.accountAgeWitnessService = accountAgeWitnessService;
|
||||
|
||||
scaleFactor = getScaleFactor();
|
||||
fullAddress = nodeAddress != null ? nodeAddress.getFullAddress() : "";
|
||||
@ -77,10 +134,18 @@ public class PeerInfoIcon extends Group {
|
||||
peerTagMap = preferences.getPeerTagMap();
|
||||
|
||||
boolean hasTraded = numTrades > 0;
|
||||
final boolean isFiatCurrency = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode());
|
||||
final long makersAccountAge = accountAgeWitnessService.getMakersAccountAge(offer, new Date());
|
||||
final String accountAge = isFiatCurrency ?
|
||||
makersAccountAge > -1 ? Res.get("peerInfoIcon.tooltip.age", formatter.formatAccountAge(makersAccountAge)) :
|
||||
long peersAccountAge = getPeersAccountAge(trade, offer);
|
||||
if (offer == null) {
|
||||
checkNotNull(trade, "Trade must not be null if offer is null.");
|
||||
offer = trade.getOffer();
|
||||
}
|
||||
|
||||
checkNotNull(offer, "Offer must not be null");
|
||||
|
||||
boolean isFiatCurrency = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode());
|
||||
|
||||
String accountAge = isFiatCurrency ?
|
||||
peersAccountAge > -1 ? Res.get("peerInfoIcon.tooltip.age", formatter.formatAccountAge(peersAccountAge)) :
|
||||
Res.get("peerInfoIcon.tooltip.unknownAge") :
|
||||
"";
|
||||
tooltipText = hasTraded ?
|
||||
@ -90,7 +155,7 @@ public class PeerInfoIcon extends Group {
|
||||
// outer circle
|
||||
Color ringColor;
|
||||
if (isFiatCurrency) {
|
||||
switch (accountAgeWitnessService.getAccountAgeCategory(makersAccountAge)) {
|
||||
switch (accountAgeWitnessService.getAccountAgeCategory(peersAccountAge)) {
|
||||
case TWO_MONTHS_OR_MORE:
|
||||
ringColor = Color.rgb(0, 225, 0); // > 2 months green
|
||||
break;
|
||||
@ -178,10 +243,43 @@ public class PeerInfoIcon extends Group {
|
||||
|
||||
getChildren().addAll(outerBackground, innerBackground, avatarImageView, tagPane, numTradesPane);
|
||||
|
||||
addMouseListener(numTrades, privateNotificationManager, offer, preferences, formatter, useDevPrivilegeKeys, isFiatCurrency, makersAccountAge);
|
||||
addMouseListener(numTrades, privateNotificationManager, offer, preferences, formatter, useDevPrivilegeKeys, isFiatCurrency, peersAccountAge);
|
||||
}
|
||||
|
||||
protected void addMouseListener(int numTrades, PrivateNotificationManager privateNotificationManager, Offer offer, Preferences preferences, BSFormatter formatter, boolean useDevPrivilegeKeys, boolean isFiatCurrency, long makersAccountAge) {
|
||||
private long getPeersAccountAge(@Nullable Trade trade, @Nullable Offer offer) {
|
||||
if (trade != null) {
|
||||
offer = trade.getOffer();
|
||||
if (offer == null) {
|
||||
// unexpected
|
||||
return -1;
|
||||
}
|
||||
|
||||
TradingPeer tradingPeer = trade.getProcessModel().getTradingPeer();
|
||||
if (tradingPeer.getPaymentAccountPayload() == null || tradingPeer.getPubKeyRing() == null) {
|
||||
// unexpected
|
||||
return -1;
|
||||
}
|
||||
PaymentAccountPayload peersPaymentAccountPayload = tradingPeer.getPaymentAccountPayload();
|
||||
PubKeyRing peersPubKeyRing = tradingPeer.getPubKeyRing();
|
||||
|
||||
Optional<AccountAgeWitness> witness = accountAgeWitnessService.findWitness(peersPaymentAccountPayload, peersPubKeyRing);
|
||||
return witness.map(accountAgeWitness -> accountAgeWitnessService.getAccountAge(accountAgeWitness, new Date()))
|
||||
.orElse(-1L);
|
||||
} else {
|
||||
checkNotNull(offer, "Offer must not be null if trade is null.");
|
||||
|
||||
return accountAgeWitnessService.getMakersAccountAge(offer, new Date());
|
||||
}
|
||||
}
|
||||
|
||||
protected void addMouseListener(int numTrades,
|
||||
PrivateNotificationManager privateNotificationManager,
|
||||
Offer offer,
|
||||
Preferences preferences,
|
||||
BSFormatter formatter,
|
||||
boolean useDevPrivilegeKeys,
|
||||
boolean isFiatCurrency,
|
||||
long makersAccountAge) {
|
||||
final String accountAgeTagEditor = isFiatCurrency ?
|
||||
makersAccountAge > -1 ?
|
||||
formatter.formatAccountAge(makersAccountAge) :
|
||||
|
@ -9,10 +9,22 @@ import bisq.core.util.BSFormatter;
|
||||
import bisq.network.p2p.NodeAddress;
|
||||
|
||||
public class PeerInfoIconSmall extends PeerInfoIcon {
|
||||
public PeerInfoIconSmall(NodeAddress nodeAddress, String role, Offer offer, Preferences preferences, AccountAgeWitnessService accountAgeWitnessService, BSFormatter formatter, boolean useDevPrivilegeKeys) {
|
||||
public PeerInfoIconSmall(NodeAddress nodeAddress,
|
||||
String role, Offer offer,
|
||||
Preferences preferences,
|
||||
AccountAgeWitnessService accountAgeWitnessService,
|
||||
BSFormatter formatter,
|
||||
boolean useDevPrivilegeKeys) {
|
||||
// We don't want to show number of trades in that case as it would be unreadable.
|
||||
// Also we don't need the privateNotificationManager as no interaction will take place with this icon.
|
||||
super(nodeAddress, role, 0, null, offer, preferences, accountAgeWitnessService, formatter, useDevPrivilegeKeys);
|
||||
super(nodeAddress, role,
|
||||
0,
|
||||
null,
|
||||
offer,
|
||||
preferences,
|
||||
accountAgeWitnessService,
|
||||
formatter,
|
||||
useDevPrivilegeKeys);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -21,7 +33,13 @@ public class PeerInfoIconSmall extends PeerInfoIcon {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addMouseListener(int numTrades, PrivateNotificationManager privateNotificationManager, Offer offer, Preferences preferences, BSFormatter formatter, boolean useDevPrivilegeKeys, boolean isFiatCurrency, long makersAccountAge) {
|
||||
protected void addMouseListener(int numTrades,
|
||||
PrivateNotificationManager privateNotificationManager,
|
||||
Offer offer, Preferences preferences,
|
||||
BSFormatter formatter,
|
||||
boolean useDevPrivilegeKeys,
|
||||
boolean isFiatCurrency,
|
||||
long makersAccountAge) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -90,7 +90,10 @@ public class PeerInfoWithTagEditor extends Overlay<PeerInfoWithTagEditor> {
|
||||
@Nullable
|
||||
private String accountAge;
|
||||
|
||||
public PeerInfoWithTagEditor(PrivateNotificationManager privateNotificationManager, Offer offer, Preferences preferences, boolean useDevPrivilegeKeys) {
|
||||
public PeerInfoWithTagEditor(PrivateNotificationManager privateNotificationManager,
|
||||
Offer offer,
|
||||
Preferences preferences,
|
||||
boolean useDevPrivilegeKeys) {
|
||||
this.privateNotificationManager = privateNotificationManager;
|
||||
this.offer = offer;
|
||||
this.preferences = preferences;
|
||||
|
@ -32,7 +32,6 @@ import bisq.core.app.AppOptionKeys;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.monetary.Price;
|
||||
import bisq.core.monetary.Volume;
|
||||
import bisq.core.offer.Offer;
|
||||
import bisq.core.offer.OpenOffer;
|
||||
import bisq.core.trade.Tradable;
|
||||
import bisq.core.trade.Trade;
|
||||
@ -49,8 +48,6 @@ import com.google.inject.name.Named;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
|
||||
import javafx.stage.Stage;
|
||||
@ -335,14 +332,12 @@ public class ClosedTradesView extends ActivatableViewAndModel<VBox, ClosedTrades
|
||||
Trade trade = (Trade) newItem.getTradable();
|
||||
int numPastTrades = model.getNumPastTrades(trade);
|
||||
final NodeAddress tradingPeerNodeAddress = trade.getTradingPeerNodeAddress();
|
||||
final Offer offer = trade.getOffer();
|
||||
Preconditions.checkNotNull(offer, "Offer must not be null");
|
||||
String role = Res.get("peerInfoIcon.tooltip.tradePeer");
|
||||
Node peerInfoIcon = new PeerInfoIcon(tradingPeerNodeAddress,
|
||||
role,
|
||||
numPastTrades,
|
||||
privateNotificationManager,
|
||||
offer,
|
||||
trade,
|
||||
preferences,
|
||||
model.accountAgeWitnessService,
|
||||
formatter,
|
||||
|
@ -28,7 +28,6 @@ import bisq.desktop.main.overlays.windows.TradeDetailsWindow;
|
||||
import bisq.core.alert.PrivateNotificationManager;
|
||||
import bisq.core.app.AppOptionKeys;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.offer.Offer;
|
||||
import bisq.core.trade.Trade;
|
||||
import bisq.core.user.Preferences;
|
||||
import bisq.core.util.BSFormatter;
|
||||
@ -70,8 +69,6 @@ import javafx.util.Callback;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@FxmlView
|
||||
public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTradesViewModel> {
|
||||
|
||||
@ -488,14 +485,12 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
||||
final Trade trade = newItem.getTrade();
|
||||
final NodeAddress tradingPeerNodeAddress = trade.getTradingPeerNodeAddress();
|
||||
int numPastTrades = model.getNumPastTrades(trade);
|
||||
final Offer offer = trade.getOffer();
|
||||
checkNotNull(offer, "Offer must not be null in PendingTradesView");
|
||||
String role = Res.get("peerInfoIcon.tooltip.tradePeer");
|
||||
Node peerInfoIcon = new PeerInfoIcon(tradingPeerNodeAddress,
|
||||
role,
|
||||
numPastTrades,
|
||||
privateNotificationManager,
|
||||
offer,
|
||||
trade,
|
||||
preferences,
|
||||
model.accountAgeWitnessService,
|
||||
formatter,
|
||||
|
Loading…
Reference in New Issue
Block a user