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

fix: Fix wrong label for points in reward details - MEED-7644 - Meeds-io/MIPs#154 #598

Merged
merged 1 commit into from
Oct 21, 2024
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 @@ -36,6 +36,8 @@ public class RewardReportStatus {

private int achievementsCount;

private double points;

private double tokensSent;

private double tokensToSend;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ public interface RewardReportService {
*/
Page<WalletReward> findWalletRewardsByPeriodIdAndStatus(long periodId, String status, ZoneId zoneId, Pageable pageable);

/**
* Count wallet rewards points by PeriodId and status
*
* @param periodId Reward Period id
* @param isValid Wallet reward status
*/
double countWalletRewardsPointsByPeriodIdAndStatus(long periodId, boolean isValid);


/**
* Set isChanged data map for periods not sent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ Page<WalletRewardEntity> findWalletRewardsByPeriodIdAndStatus(@Param("periodId")
@Param("isValid") boolean isValid,
Pageable pageable);

@Query("""
SELECT SUM(rw.points) FROM Reward rw WHERE rw.period.id = :periodId AND
(:isValid = TRUE AND (rw.tokensSent > 0 OR rw.tokensToSend > 0) OR :isValid = FALSE AND (rw.tokensSent <= 0 AND rw.tokensToSend <= 0))
""")
Double countWalletRewardsPointsByPeriodIdAndStatus(@Param("periodId") long periodId,
@Param("isValid") boolean isValid);

List<WalletRewardEntity> findWalletRewardEntitiesByIdentityId(long identityId, Pageable pageable);

double countWalletRewardEntitiesByIdentityId(long identityId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public RewardReportStatus getReport(RewardPeriod rewardPeriod) {
rewardSettingChangedMap.put(storedRewardPeriod.getId(), false);
setRewardSettingChanged(rewardSettingChangedMap);
}
return buildReportStatus(rewardReport, rewardPeriod);
return buildReportStatus(rewardReport, storedRewardPeriod != null ? storedRewardPeriod : rewardPeriod);
}

@Override
Expand Down Expand Up @@ -394,6 +394,11 @@ public void replaceRewardTransactions(String oldHash, String newHash) {
public Page<WalletReward> findWalletRewardsByPeriodIdAndStatus(long periodId, String status, ZoneId zoneId, Pageable pageable) {
boolean isValid = !status.equals("INVALID");
return rewardReportStorage.findWalletRewardsByPeriodIdAndStatus(periodId, isValid, zoneId, pageable);
}

@Override
public double countWalletRewardsPointsByPeriodIdAndStatus(long periodId, boolean isValid) {
return rewardReportStorage.countWalletRewardsPointsByPeriodIdAndStatus(periodId, isValid);
}

public void setRewardSettingChanged(Map<Long, Boolean> updatedSettings) {
Expand Down Expand Up @@ -632,6 +637,7 @@ private RewardReportStatus buildReportStatus(RewardReport rewardReport, RewardPe
if (participantsCount > 0) {
rewardReport = computeRewards(rewardPeriod.getPeriodMedianDate());
saveRewardReport(rewardReport);
rewardPeriod = getRewardPeriod(rewardPeriod.getRewardPeriodType(), rewardPeriod.getPeriodMedianDate());
} else {
rewardReport = new RewardReport();
rewardReport.setPeriod(rewardPeriod);
Expand All @@ -644,11 +650,14 @@ private RewardReportStatus buildReportStatus(RewardReport rewardReport, RewardPe
.findFirst()
.orElse(null);

double points = rewardPeriod.getId() > 0 ? countWalletRewardsPointsByPeriodIdAndStatus(rewardPeriod.getId(), true) : 0;

return new RewardReportStatus(succeededTransaction != null ? succeededTransaction.getTransaction().getSentTimestamp() : 0,
rewardReport.getPeriod(),
participantsCount,
rewardReport.getValidRewardCount(),
achievementsCount,
points,
rewardReport.getTokensSent(),
rewardReport.getTokensToSend(),
CollectionUtils.isNotEmpty(rewardReport.getRewards()) && rewardReport.isCompletelyProcessed());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ public Page<WalletReward> findWalletRewardsByPeriodIdAndStatus(long periodId, bo
return walletRewardEntities.map(walletRewardEntity -> toDTO(walletRewardEntity, zoneId));
}

public double countWalletRewardsPointsByPeriodIdAndStatus(long periodId, boolean isValid) {
Double countWalletRewardsPoints = rewardDAO.countWalletRewardsPointsByPeriodIdAndStatus(periodId, isValid);
return countWalletRewardsPoints != null ? countWalletRewardsPoints : 0;
}

private RewardPeriod toDTO(WalletRewardPeriodEntity period) {
if (period == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export default {
return this.valueFormatted(this.tokensToSend);
},
points() {
return this.valueFormatted(this.validRewards?.map(x => x?.points || 0).reduce((x, y) => x + y, 0), 0);
return this.rewardReport?.points;
},
rewardsToSend() {
return this.$t('wallet.administration.rewardDetails.label.rewardsToSend', {
Expand Down