Skip to content

Commit

Permalink
fix: Fix wrong label for points in reward details - MEED-7644 - Meeds…
Browse files Browse the repository at this point in the history
…-io/MIPs#154 (#598)

This PR will fix the wrong label for points in reward details
  • Loading branch information
AzmiTouil authored and exo-swf committed Nov 4, 2024
1 parent 1097e6c commit 9536d74
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
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

0 comments on commit 9536d74

Please sign in to comment.