From 644761d6e020f3d5c9f735f20dadab41b8a0fef6 Mon Sep 17 00:00:00 2001 From: Azmi TOUIL <42934070+AzmiTouil@users.noreply.github.com> Date: Tue, 22 Oct 2024 14:19:36 +0200 Subject: [PATCH] feat: Implement See Rewards details drawer - MEED-7483 - Meeds-io/MIPs#154 (#600) This PR will implement a new drawer for rewards details item. --- .../io/meeds/wallet/model/WalletReward.java | 17 +- .../io/meeds/wallet/reward/dao/RewardDAO.java | 6 + .../storage/WalletRewardReportStorage.java | 2 + .../RewardSuccessNotificationPluginTest.java | 2 +- .../RewardSuccessTemplateBuilderTest.java | 2 +- .../reward/rest/TestRewardReportREST.java | 2 +- .../WalletRewardReportServiceTest.java | 6 +- .../WalletRewardReportStorageTest.java | 6 +- .../locale/addon/Wallet_en.properties | 1 + .../vue-app/wallet-common/js/WalletUtils.js | 7 +- .../components/reward/CurrentBalance.vue | 7 +- .../components/reward/RewardDetails.vue | 12 +- .../components/reward/RewardDetailsItem.vue | 21 +- .../reward/RewardsDetailsDrawer.vue | 243 ++++++++++++++++++ .../vue-app/wallet-reward/initComponents.js | 2 + 15 files changed, 309 insertions(+), 27 deletions(-) create mode 100644 wallet-webapps/src/main/webapp/vue-app/wallet-reward/components/reward/RewardsDetailsDrawer.vue diff --git a/wallet-api/src/main/java/io/meeds/wallet/model/WalletReward.java b/wallet-api/src/main/java/io/meeds/wallet/model/WalletReward.java index 502718729..1fc5b68a6 100644 --- a/wallet-api/src/main/java/io/meeds/wallet/model/WalletReward.java +++ b/wallet-api/src/main/java/io/meeds/wallet/model/WalletReward.java @@ -30,23 +30,26 @@ @AllArgsConstructor @NoArgsConstructor public class WalletReward implements Serializable { - private static final long serialVersionUID = -4328398843364453949L; + private static final long serialVersionUID = -4328398843364453949L; - private Wallet wallet; + private Wallet wallet; @Exclude - private TransactionDetail transaction; + private TransactionDetail transaction; - private long identityId; + private long identityId; @Exclude - private double points; + private double points; @Exclude - private double amount; + private double amount; @Exclude - private RewardPeriod period; + private RewardPeriod period; + + @Exclude + private int rank; public long getIdentityId() { return wallet == null ? 0 : wallet.getTechnicalId(); diff --git a/wallet-reward-services/src/main/java/io/meeds/wallet/reward/dao/RewardDAO.java b/wallet-reward-services/src/main/java/io/meeds/wallet/reward/dao/RewardDAO.java index b22933d51..0d6f6cafe 100644 --- a/wallet-reward-services/src/main/java/io/meeds/wallet/reward/dao/RewardDAO.java +++ b/wallet-reward-services/src/main/java/io/meeds/wallet/reward/dao/RewardDAO.java @@ -68,4 +68,10 @@ Double countWalletRewardsPointsByPeriodIdAndStatus(@Param("periodId") long perio UPDATE Reward rw SET rw.transactionHash = :newHash WHERE rw.transactionHash = :oldHash """) void replaceRewardTransactions(@Param("oldHash") String oldHash, @Param("newHash") String newHash); + + @Query(value = "SELECT Ranked_Reward.reward_rank FROM ( " + + " SELECT rw.id AS reward_id, RANK() OVER(ORDER BY rw.points DESC) AS reward_rank " + + " FROM Reward rw WHERE rw.period.id = :periodId" + + ") Ranked_Reward WHERE Ranked_Reward.reward_id = :id") + Integer findRankById(@Param("id") long id, @Param("periodId") long periodId); } diff --git a/wallet-reward-services/src/main/java/io/meeds/wallet/reward/storage/WalletRewardReportStorage.java b/wallet-reward-services/src/main/java/io/meeds/wallet/reward/storage/WalletRewardReportStorage.java index b312c55f9..9675855b5 100644 --- a/wallet-reward-services/src/main/java/io/meeds/wallet/reward/storage/WalletRewardReportStorage.java +++ b/wallet-reward-services/src/main/java/io/meeds/wallet/reward/storage/WalletRewardReportStorage.java @@ -283,6 +283,8 @@ private WalletReward toDTO(WalletRewardEntity rewardEntity, ZoneId zoneId) { RewardPeriodType rewardPeriodType = periodEntity.getPeriodType(); ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(periodEntity.getStartTime()), zoneId); walletReward.setPeriod(rewardPeriodType.getPeriodOfTime(zonedDateTime)); + Integer rank = rewardDAO.findRankById(rewardEntity.getId(), periodEntity.getId()); + walletReward.setRank(rank != null ? rank : 0); } return walletReward; } diff --git a/wallet-reward-services/src/test/java/io/meeds/wallet/reward/notification/RewardSuccessNotificationPluginTest.java b/wallet-reward-services/src/test/java/io/meeds/wallet/reward/notification/RewardSuccessNotificationPluginTest.java index 40ba096cb..f97024dba 100644 --- a/wallet-reward-services/src/test/java/io/meeds/wallet/reward/notification/RewardSuccessNotificationPluginTest.java +++ b/wallet-reward-services/src/test/java/io/meeds/wallet/reward/notification/RewardSuccessNotificationPluginTest.java @@ -66,7 +66,7 @@ public void testMakeMessage() { transaction.setHash("hash"); transaction.setContractAmount(2); transaction.setPending(true); - rewards.add(new WalletReward(null, transaction, 0, 0, 0, null)); + rewards.add(new WalletReward(null, transaction, 0, 0, 0, null, 1)); } rewardReport.setRewards(rewards); diff --git a/wallet-reward-services/src/test/java/io/meeds/wallet/reward/notification/RewardSuccessTemplateBuilderTest.java b/wallet-reward-services/src/test/java/io/meeds/wallet/reward/notification/RewardSuccessTemplateBuilderTest.java index 9192f6dc6..4bcbb30ed 100644 --- a/wallet-reward-services/src/test/java/io/meeds/wallet/reward/notification/RewardSuccessTemplateBuilderTest.java +++ b/wallet-reward-services/src/test/java/io/meeds/wallet/reward/notification/RewardSuccessTemplateBuilderTest.java @@ -81,7 +81,7 @@ public void testBuildMessage() { transaction.setHash("hash"); transaction.setContractAmount(2); transaction.setPending(true); - rewards.add(new WalletReward(null, transaction, 0, 0, 0, null)); + rewards.add(new WalletReward(null, transaction, 0, 0, 0, null, 1)); } rewardReport.setRewards(rewards); ctx.append(REWARD_REPORT_NOTIFICATION_PARAM, rewardReport); diff --git a/wallet-reward-services/src/test/java/io/meeds/wallet/reward/rest/TestRewardReportREST.java b/wallet-reward-services/src/test/java/io/meeds/wallet/reward/rest/TestRewardReportREST.java index f06896890..c1ac59f7c 100644 --- a/wallet-reward-services/src/test/java/io/meeds/wallet/reward/rest/TestRewardReportREST.java +++ b/wallet-reward-services/src/test/java/io/meeds/wallet/reward/rest/TestRewardReportREST.java @@ -381,7 +381,7 @@ private RewardPeriod rewardPeriod() { } private WalletReward walletReward() { - return new WalletReward(new Wallet(), new TransactionDetail(), 1L, 100.0, 40.0, rewardPeriod()); + return new WalletReward(new Wallet(), new TransactionDetail(), 1L, 100.0, 40.0, rewardPeriod(), 1); } @SneakyThrows diff --git a/wallet-reward-services/src/test/java/io/meeds/wallet/reward/service/WalletRewardReportServiceTest.java b/wallet-reward-services/src/test/java/io/meeds/wallet/reward/service/WalletRewardReportServiceTest.java index 8af98bd34..242d47c0e 100644 --- a/wallet-reward-services/src/test/java/io/meeds/wallet/reward/service/WalletRewardReportServiceTest.java +++ b/wallet-reward-services/src/test/java/io/meeds/wallet/reward/service/WalletRewardReportServiceTest.java @@ -300,9 +300,9 @@ void testSendRewards() throws Exception { Set walletRewards = new HashSet<>(); TransactionDetail transactionDetail = new TransactionDetail(); transactionDetail.setSucceeded(true); - walletRewards.add(new WalletReward(wallet, transactionDetail, 1L, 100, 10, rewardPeriod)); - walletRewards.add(new WalletReward(wallet4, transactionDetail, 4L, 200, 50, rewardPeriod)); - walletRewards.add(new WalletReward(wallet5, transactionDetail, 5L, 300, 40, rewardPeriod)); + walletRewards.add(new WalletReward(wallet, transactionDetail, 1L, 100, 10, rewardPeriod, 3)); + walletRewards.add(new WalletReward(wallet4, transactionDetail, 4L, 200, 50, rewardPeriod, 2)); + walletRewards.add(new WalletReward(wallet5, transactionDetail, 5L, 300, 40, rewardPeriod, 1)); rewardReport.setRewards(walletRewards); when(rewardReportStorage.getRewardReport(newSettings.getPeriodType(), date, newSettings.zoneId())).thenReturn(rewardReport); diff --git a/wallet-reward-services/src/test/java/io/meeds/wallet/reward/storage/WalletRewardReportStorageTest.java b/wallet-reward-services/src/test/java/io/meeds/wallet/reward/storage/WalletRewardReportStorageTest.java index ddcd802ee..2a71fa112 100644 --- a/wallet-reward-services/src/test/java/io/meeds/wallet/reward/storage/WalletRewardReportStorageTest.java +++ b/wallet-reward-services/src/test/java/io/meeds/wallet/reward/storage/WalletRewardReportStorageTest.java @@ -207,9 +207,9 @@ protected RewardReport createRewardReportInstance(boolean isSucceeded) { Set walletRewards = new HashSet<>(); TransactionDetail transactionDetail = new TransactionDetail(); transactionDetail.setSucceeded(isSucceeded); - walletRewards.add(new WalletReward(wallet, transactionDetail, 1L, 100, 10, rewardPeriod)); - walletRewards.add(new WalletReward(wallet4, transactionDetail, 4L, 200, 50, rewardPeriod)); - walletRewards.add(new WalletReward(wallet5, transactionDetail, 5L, 300, 40, rewardPeriod)); + walletRewards.add(new WalletReward(wallet, transactionDetail, 1L, 100, 10, rewardPeriod, 3)); + walletRewards.add(new WalletReward(wallet4, transactionDetail, 4L, 200, 50, rewardPeriod, 2)); + walletRewards.add(new WalletReward(wallet5, transactionDetail, 5L, 300, 40, rewardPeriod, 1)); rewardReport.setRewards(walletRewards); return rewardReport; diff --git a/wallet-services/src/main/resources/locale/addon/Wallet_en.properties b/wallet-services/src/main/resources/locale/addon/Wallet_en.properties index ff8a2bc07..a58a53daa 100644 --- a/wallet-services/src/main/resources/locale/addon/Wallet_en.properties +++ b/wallet-services/src/main/resources/locale/addon/Wallet_en.properties @@ -573,6 +573,7 @@ wallet.administration.rewardDetails.label.latestRewardsSent=Latest Rewards Sent wallet.administration.rewardDetails.label.rewardsToSend={0} MEED for {1} points wallet.administration.rewardDetails.label.reward=Reward wallet.administration.rewardDetails.label.notSentYet=Not sent yet +wallet.administration.rewardDetails.label=Rewards Details wallet.overview.rewards.title=Wallet History wallet.overview.points=Points diff --git a/wallet-webapps/src/main/webapp/vue-app/wallet-common/js/WalletUtils.js b/wallet-webapps/src/main/webapp/vue-app/wallet-common/js/WalletUtils.js index a4be01920..42aec3e4e 100644 --- a/wallet-webapps/src/main/webapp/vue-app/wallet-common/js/WalletUtils.js +++ b/wallet-webapps/src/main/webapp/vue-app/wallet-common/js/WalletUtils.js @@ -668,9 +668,12 @@ export function toFixed(value, decimals) { decimals = DEFAULT_DECIMALS; } try { - return Number.parseFloat(value).toFixed(decimals).replace(/(\..*[1-9])0+$/, '$1').replace(/\.0*$/, ''); + const factor = Math.pow(10, decimals); + const truncatedValue = Math.floor(value * factor) / factor; + const formattedValue = truncatedValue.toFixed(decimals); + return formattedValue.replace(/(\.\d*?[1-9])0+$/, '$1').replace(/\.0*$/, ''); } catch (e) { - console.error('Error parsing value ', value, ' same value will be retruned', e); + console.error('Error parsing value ', value, ' same value will be returned', e); return value; } } diff --git a/wallet-webapps/src/main/webapp/vue-app/wallet-reward/components/reward/CurrentBalance.vue b/wallet-webapps/src/main/webapp/vue-app/wallet-reward/components/reward/CurrentBalance.vue index 8f855d002..76bc40353 100644 --- a/wallet-webapps/src/main/webapp/vue-app/wallet-reward/components/reward/CurrentBalance.vue +++ b/wallet-webapps/src/main/webapp/vue-app/wallet-reward/components/reward/CurrentBalance.vue @@ -81,7 +81,7 @@ - MEED {{ tokenBalance }} + MEED {{ tokenBalanceLabel }} @@ -134,11 +134,14 @@ export default { tokenBalance() { return this.adminWallet?.tokenBalance || 0; }, + tokenBalanceLabel() { + return this.walletUtils?.toFixed(this.tokenBalance, 2); + }, etherBalance() { return this.adminWallet?.etherBalance || 0; }, etherBalanceLabel() { - return `${this.contractDetails?.cryptocurrency} ${this.walletUtils?.toFixed(this.etherBalance)}`; + return `${this.contractDetails?.cryptocurrency} ${this.walletUtils?.toFixed(this.etherBalance, 2)}`; }, useWalletAdmin() { return this.etherBalance && Number(this.etherBalance) >= 0.002 && this.tokenBalance && Number(this.tokenBalance) >= 0.02; diff --git a/wallet-webapps/src/main/webapp/vue-app/wallet-reward/components/reward/RewardDetails.vue b/wallet-webapps/src/main/webapp/vue-app/wallet-reward/components/reward/RewardDetails.vue index 2cab39800..d6f6bb26e 100644 --- a/wallet-webapps/src/main/webapp/vue-app/wallet-reward/components/reward/RewardDetails.vue +++ b/wallet-webapps/src/main/webapp/vue-app/wallet-reward/components/reward/RewardDetails.vue @@ -106,7 +106,8 @@ :token-symbol="tokenSymbol" :completely-processed="completelyProcessed" :transaction-ether-scan-link="transactionEtherScanLink" - @open-contribution-details="openContributionDetails" /> + @open-contribution-details="openContributionDetails" + @open-rewards-details="openRewardsDetails" /> + @@ -172,6 +177,7 @@ export default { day: 'numeric', }, walletRewards: [], + selectedWalletReward: null, status: 'VALID', sortBy: 'tokensToSend', sortDescending: true, @@ -365,6 +371,10 @@ export default { openContributionDetails(userId) { this.$refs?.profileStatsDrawer?.openByIdentityId(userId, this.rewardPeriodType); }, + openRewardsDetails(walletReward) { + this.selectedWalletReward = walletReward; + this.$refs?.rewardsDetailsDrawer?.open(); + }, sortUpdated() { if (!this.loading) { this.loading = true; diff --git a/wallet-webapps/src/main/webapp/vue-app/wallet-reward/components/reward/RewardDetailsItem.vue b/wallet-webapps/src/main/webapp/vue-app/wallet-reward/components/reward/RewardDetailsItem.vue index fef76bcb5..2ff85f4d0 100644 --- a/wallet-webapps/src/main/webapp/vue-app/wallet-reward/components/reward/RewardDetailsItem.vue +++ b/wallet-webapps/src/main/webapp/vue-app/wallet-reward/components/reward/RewardDetailsItem.vue @@ -41,7 +41,9 @@ display-no-address /> - + {{ points }} @@ -97,12 +99,16 @@ - - {{ tokenSymbol }} {{ walletUtils.toFixed(amount) }} - + text + @click="openRewardsDetails"> + + {{ tokenSymbol }} {{ walletUtils.toFixed(amount) }} + + + + \ No newline at end of file diff --git a/wallet-webapps/src/main/webapp/vue-app/wallet-reward/initComponents.js b/wallet-webapps/src/main/webapp/vue-app/wallet-reward/initComponents.js index cfd247f5b..a4b49aafc 100644 --- a/wallet-webapps/src/main/webapp/vue-app/wallet-reward/initComponents.js +++ b/wallet-webapps/src/main/webapp/vue-app/wallet-reward/initComponents.js @@ -9,6 +9,7 @@ import BudgetConfigurationDrawer from './components/reward/BudgetConfigurationDr import DistributionForecast from './components/reward/DistributionForecast.vue'; import TimeZoneSelectBox from './components/reward/TimeZoneSelectBox.vue'; import RewardCardMaskContent from './components/reward/RewardCardMaskContent.vue'; +import RewardsDetailsDrawer from './components/reward/RewardsDetailsDrawer.vue'; const components = { 'wallet-reward-app': RewardApp, @@ -16,6 +17,7 @@ const components = { 'wallet-reward-card': RewardCard, 'wallet-reward-details': RewardDetails, 'wallet-reward-details-item': RewardDetailsItem, + 'wallet-rewards-details-drawer': RewardsDetailsDrawer, 'wallet-current-balance': CurrentBalance, 'wallet-budget-configuration': BudgetConfiguration, 'wallet-budget-configuration-drawer': BudgetConfigurationDrawer,