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

Add offer age in user offers #3038

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ static class Trader {
Optional<Long> optionalProfileAge = reputationService.getProfileAgeService().getProfileAge(userProfile);
profileAge = optionalProfileAge.orElse(0L);
profileAgeString = optionalProfileAge
.map(TimeFormatter::formatAgeInDays)
.map(TimeFormatter::formatAgeInDaysAndYears)
.orElse(Res.get("data.na"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
import bisq.offer.price.PriceUtil;
import bisq.offer.price.spec.FixPriceSpec;
import bisq.offer.price.spec.PriceSpecFormatter;
import bisq.presentation.formatters.DateFormatter;
import bisq.presentation.formatters.PercentageFormatter;
import bisq.presentation.formatters.TimeFormatter;
import bisq.user.profile.UserProfile;
import bisq.user.reputation.ReputationScore;
import bisq.user.reputation.ReputationService;
Expand All @@ -60,15 +62,17 @@ public class OfferbookListItem {
private final ReputationService reputationService;
private final UserProfile senderUserProfile;
private final String userNickname, formattedRangeQuoteAmount, bitcoinPaymentMethodsAsString,
fiatPaymentMethodsAsString, authorUserProfileId, marketCurrencyCode, offerType;
fiatPaymentMethodsAsString, authorUserProfileId, marketCurrencyCode, offerType,
formattedOfferAge, offerAgeTooltipText;
private final ReputationScore reputationScore;
private final List<FiatPaymentMethod> fiatPaymentMethods;
private final List<BitcoinPaymentMethod> bitcoinPaymentMethods;
private final boolean isFixPrice;
private final Monetary quoteSideMinAmount;
private final long totalScore;
private double priceSpecAsPercent;
private final Pin marketPriceByCurrencyMapPin;
private final long offerAgeInDays;
private double priceSpecAsPercent;
private String formattedPercentagePrice, priceTooltipText;

public OfferbookListItem(BisqEasyOfferbookMessage bisqEasyOfferbookMessage,
Expand Down Expand Up @@ -101,6 +105,10 @@ public OfferbookListItem(BisqEasyOfferbookMessage bisqEasyOfferbookMessage,

reputationScore = reputationService.getReputationScore(senderUserProfile);
totalScore = reputationScore.getTotalScore();
offerAgeInDays = TimeFormatter.getAgeInDays(bisqEasyOffer.getDate());
formattedOfferAge = TimeFormatter.formatAgeInDays(bisqEasyOffer.getDate());
offerAgeTooltipText = Res.get("user.profileCard.offers.table.columns.offerAge.tooltip",
DateFormatter.formatDateTime(bisqEasyOffer.getDate()));

marketPriceByCurrencyMapPin = marketPriceService.getMarketPriceByCurrencyMap().addObserver(() ->
UIThread.run(this::updatePriceSpecAsPercent));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public ListItem(TwoPartyPrivateChatChannel channel,
Optional<Long> optionalProfileAge = reputationService.getProfileAgeService().getProfileAge(peersUserProfile);
profileAge = optionalProfileAge.orElse(0L);
profileAgeString = optionalProfileAge
.map(TimeFormatter::formatAgeInDays)
.map(TimeFormatter::formatAgeInDaysAndYears)
.orElse(Res.get("data.na"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public ListItem(ReputationSource reputationSource,
dateString = DateFormatter.formatDate(blockTime);
timeString = DateFormatter.formatTime(blockTime);
age = TimeFormatter.getAgeInDays(blockTime);
ageString = TimeFormatter.formatAgeInDays(blockTime);
ageString = TimeFormatter.formatAgeInDaysAndYears(blockTime);
sourceString = reputationSource.getDisplayString();
amountString = optionalAmount.map(amount -> AmountFormatter.formatAmountWithCode(Coin.fromValue(amount, "BSQ"))).orElse("-");
scoreString = String.valueOf(score);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public static class ListItem {
Optional<Long> optionalProfileAge = reputationService.getProfileAgeService().getProfileAge(userProfile);
profileAge = optionalProfileAge.orElse(0L);
profileAgeString = optionalProfileAge
.map(TimeFormatter::formatAgeInDays)
.map(TimeFormatter::formatAgeInDaysAndYears)
.orElse(Res.get("data.na"));

// applyReputationScore gets called from selectedToggleChanged
Expand Down Expand Up @@ -402,7 +402,7 @@ private String formatReputationSourceValue(ReputationSource reputationSource, lo
return switch (reputationSource) {
case BURNED_BSQ, BSQ_BOND -> AmountFormatter.formatAmount(Coin.asBsqFromValue(value));
case PROFILE_AGE, BISQ1_ACCOUNT_AGE, BISQ1_SIGNED_ACCOUNT_AGE_WITNESS ->
value > 0 ? TimeFormatter.formatAgeInDays(value) : "";
value > 0 ? TimeFormatter.formatAgeInDaysAndYears(value) : "";
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void updateUserProfileData(UserProfile userProfile) {
model.getTotalReputationScore().set(String.valueOf(reputationScore.getTotalScore()));
}));
model.getProfileAge().set(reputationService.getProfileAgeService().getProfileAge(userProfile)
.map(TimeFormatter::formatAgeInDays)
.map(TimeFormatter::formatAgeInDaysAndYears)
.orElse(Res.get("data.na")));
if (livenessUpdateScheduler != null) {
livenessUpdateScheduler.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,25 @@ protected void onViewDetached() {
}

private void configTableView() {
tableView.getColumns().add(new BisqTableColumn.Builder<OfferbookListItem>()
BisqTableColumn<OfferbookListItem> marketColumn = new BisqTableColumn.Builder<OfferbookListItem>()
.title(Res.get("user.profileCard.offers.table.columns.market"))
.left()
.comparator(Comparator.comparing(OfferbookListItem::getMarketCurrencyCode))
.comparator(Comparator.comparing(OfferbookListItem::getMarketCurrencyCode)
.thenComparing(OfferbookListItem::getOfferAgeInDays))
.setCellFactory(getMarketCellFactory())
.build();
tableView.getColumns().add(marketColumn);
tableView.getSortOrder().add(marketColumn);

tableView.getColumns().add(new BisqTableColumn.Builder<OfferbookListItem>()
.title(Res.get("user.profileCard.offers.table.columns.offerAge"))
.left()
.comparator(Comparator.comparing(OfferbookListItem::getOfferAgeInDays))
.setCellFactory(getOfferAgeCellFactory())
.build());

tableView.getColumns().add(new BisqTableColumn.Builder<OfferbookListItem>()
.title(Res.get("user.profileCard.offers.table.columns.offerType"))
.title(Res.get("user.profileCard.offers.table.columns.offer"))
.left()
.comparator(Comparator.comparing(OfferbookListItem::getOfferType))
.valueSupplier(OfferbookListItem::getOfferType)
Expand Down Expand Up @@ -136,6 +146,30 @@ protected void updateItem(OfferbookListItem item, boolean empty) {
};
}

private Callback<TableColumn<OfferbookListItem, OfferbookListItem>,
TableCell<OfferbookListItem, OfferbookListItem>> getOfferAgeCellFactory() {
return column -> new TableCell<>() {
private final Label offerAgeLabel = new Label();
private final BisqTooltip tooltip = new BisqTooltip();

@Override
protected void updateItem(OfferbookListItem item, boolean empty) {
super.updateItem(item, empty);

if (item != null && !empty) {
tooltip.setText(item.getOfferAgeTooltipText());
offerAgeLabel.setText(item.getFormattedOfferAge());
offerAgeLabel.setTooltip(tooltip);
setGraphic(offerAgeLabel);
} else {
offerAgeLabel.setText("");
offerAgeLabel.setTooltip(null);
setGraphic(null);
}
}
};
}

private Callback<TableColumn<OfferbookListItem, OfferbookListItem>,
TableCell<OfferbookListItem, OfferbookListItem>> getPriceCellFactory() {
return column -> new TableCell<>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public ListItem(ReputationSource reputationSource,
dateString = DateFormatter.formatDate(blockTime);
timeString = DateFormatter.formatTime(blockTime);
age = TimeFormatter.getAgeInDays(blockTime);
ageString = TimeFormatter.formatAgeInDays(blockTime);
ageString = TimeFormatter.formatAgeInDaysAndYears(blockTime);
sourceString = reputationSource.getDisplayString();
amountString = optionalAmount.map(amount -> AmountFormatter.formatAmountWithCode(Coin.fromValue(amount, "BSQ"))).orElse("-");
scoreString = String.valueOf(score);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void onActivate() {
model.getTerms().set(userProfile.getTerms());

model.getProfileAge().set(profileAgeService.getProfileAge(userIdentity.getUserProfile())
.map(TimeFormatter::formatAgeInDays)
.map(TimeFormatter::formatAgeInDaysAndYears)
.orElse(Res.get("data.na")));

if (livenessUpateScheduler != null) {
Expand Down
1 change: 1 addition & 0 deletions i18n/src/main/resources/default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ temporal.year.1={0} year
# suppress inspection "UnusedProperty"
temporal.year.*={0} years
temporal.at=at
temporal.today=Today



Expand Down
4 changes: 3 additions & 1 deletion i18n/src/main/resources/user.properties
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ user.profileCard.details.profileAge=Profile age
user.profileCard.details.lastUserActivity=Last user activity
user.profileCard.details.version=Software version
user.profileCard.offers.table.columns.market=Market
user.profileCard.offers.table.columns.offerType=Offer
user.profileCard.offers.table.columns.offer=Offer
user.profileCard.offers.table.columns.amount=Amount
user.profileCard.offers.table.columns.price=Price
user.profileCard.offers.table.columns.paymentMethods=Payment methods
user.profileCard.offers.table.columns.offerAge=Offer age
user.profileCard.offers.table.columns.offerAge.tooltip=Creation date:\n{0}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static String formatAge(long duration) {
}
}

public static String formatAgeInDays(long date) {
public static String formatAgeInDaysAndYears(long date) {
long totalDays = getAgeInDays(date);
long years = totalDays / 365;
long days = totalDays - years * 365;
Expand All @@ -90,4 +90,11 @@ public static String formatAgeInDays(long date) {
return dayString;
}
}

public static String formatAgeInDays(long date) {
long days = getAgeInDays(date);
return days == 0
? Res.get("temporal.today")
: Res.getPluralization("temporal.day", days);
}
}
Loading