From 16dc944253f3fe39152d14b6b7b5ccef9dd818d9 Mon Sep 17 00:00:00 2001 From: Azmi Touil Date: Thu, 14 Nov 2024 15:00:18 +0100 Subject: [PATCH 1/2] feat: Export reward list of a period - MEED-7487 - Meeds-io/MIPs#154 Fix feedbacks --- .../io/meeds/wallet/utils/WalletUtils.java | 12 ++++++++ .../service/WalletRewardReportService.java | 29 +++++++++---------- .../WalletRewardReportServiceTest.java | 4 +-- .../components/reward/RewardDetails.vue | 23 +++++++++++++-- 4 files changed, 46 insertions(+), 22 deletions(-) diff --git a/wallet-api/src/main/java/io/meeds/wallet/utils/WalletUtils.java b/wallet-api/src/main/java/io/meeds/wallet/utils/WalletUtils.java index 983665cdd..e247758f0 100644 --- a/wallet-api/src/main/java/io/meeds/wallet/utils/WalletUtils.java +++ b/wallet-api/src/main/java/io/meeds/wallet/utils/WalletUtils.java @@ -818,6 +818,18 @@ public static final long getNetworkId() { return settings == null || settings.getNetwork() == null ? 0 : settings.getNetwork().getId(); } + public static String getTransactionEtherScanLink() { + return switch (Math.toIntExact(getNetworkId())) { + case 1 -> "https://etherscan.io/tx/"; + case 3 -> "https://ropsten.etherscan.io/tx/"; + case 5 -> "https://goerli.etherscan.io/tx/"; + case 137 -> "https://polygonscan.com/tx/"; + case 80001 -> "https://mumbai.polygonscan.com/tx/"; + case 80002 -> "https://amoy.polygonscan.com/tx/"; + default -> "#"; + }; + } + public static final String getWebsocketURL() { GlobalSettings settings = getSettings(); return settings == null || settings.getNetwork() == null ? null : settings.getNetwork().getWebsocketProviderURL(); diff --git a/wallet-reward-services/src/main/java/io/meeds/wallet/reward/service/WalletRewardReportService.java b/wallet-reward-services/src/main/java/io/meeds/wallet/reward/service/WalletRewardReportService.java index 8fdbc7f86..4ae948559 100644 --- a/wallet-reward-services/src/main/java/io/meeds/wallet/reward/service/WalletRewardReportService.java +++ b/wallet-reward-services/src/main/java/io/meeds/wallet/reward/service/WalletRewardReportService.java @@ -24,13 +24,7 @@ import static io.meeds.wallet.utils.RewardUtils.TRANSACTION_STATUS_PENDING; import static io.meeds.wallet.utils.RewardUtils.TRANSACTION_STATUS_SUCCESS; import static io.meeds.wallet.utils.RewardUtils.formatTime; -import static io.meeds.wallet.utils.WalletUtils.convertFromDecimals; -import static io.meeds.wallet.utils.WalletUtils.formatNumber; -import static io.meeds.wallet.utils.WalletUtils.getContractDetail; -import static io.meeds.wallet.utils.WalletUtils.getIdentityByTypeAndId; -import static io.meeds.wallet.utils.WalletUtils.getLocale; -import static io.meeds.wallet.utils.WalletUtils.getResourceBundleKey; -import static io.meeds.wallet.utils.WalletUtils.isUserRewardingAdmin; +import static io.meeds.wallet.utils.WalletUtils.*; import java.io.*; import java.math.BigInteger; @@ -53,9 +47,8 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.SystemUtils; -import org.apache.poi.ss.usermodel.CreationHelper; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.common.usermodel.HyperlinkType; +import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.exoplatform.services.resources.ResourceBundleService; import org.springframework.data.domain.Page; @@ -420,10 +413,7 @@ public Page findWalletRewardsByPeriodIdAndStatus(long periodId, St } @Override - public InputStream exportXlsx(long periodId, - String status, - ZoneId zoneId, - String fileName, Locale locale) { + public InputStream exportXlsx(long periodId, String status, ZoneId zoneId, String fileName, Locale locale) { File temp = null; try { // NOSONAR temp = createTempFile(fileName); @@ -488,7 +478,9 @@ private void appendWalletRewardRow(Sheet sheet, int rowIndex, CreationHelper hel row.createCell(cellIndex++).setCellValue(Utils.getUserFullName(String.valueOf(walletReward.getIdentityId()))); row.createCell(cellIndex++).setCellValue(walletReward.getWallet().getAddress()); row.createCell(cellIndex++).setCellValue(walletReward.getPoints()); - row.createCell(cellIndex++).setCellValue(walletReward.getAmount()); + double amount = walletReward.getAmount(); + String amountText = (amount % 1 == 0) ? String.format("MEED %.0f", amount) : String.format("MEED %.2f", amount); + row.createCell(cellIndex++).setCellValue(amountText); row.createCell(cellIndex++).setCellValue(walletReward.getStatus()); appendTransactionCells(row, cellIndex, helper, walletReward.getTransaction()); } catch (Exception e) { @@ -499,7 +491,12 @@ private void appendWalletRewardRow(Sheet sheet, int rowIndex, CreationHelper hel private void appendTransactionCells(Row row, int cellIndex, CreationHelper helper, TransactionDetail transaction) { if (transaction != null) { row.createCell(cellIndex++).setCellValue(helper.createRichTextString(String.valueOf(new Date(transaction.getSentTimestamp())))); - row.createCell(cellIndex).setCellValue(transaction.getHash()); + Cell hashCell = row.createCell(cellIndex); + String hashUrl = getTransactionEtherScanLink() + transaction.getHash(); + hashCell.setCellValue(transaction.getHash()); + Hyperlink link = helper.createHyperlink(HyperlinkType.URL); + link.setAddress(hashUrl); + hashCell.setHyperlink(link); } } 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 418c218d3..049f35312 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 @@ -28,7 +28,6 @@ import io.meeds.gamification.model.filter.RealizationFilter; import io.meeds.gamification.service.RealizationService; -import io.meeds.gamification.utils.Utils; import io.meeds.wallet.model.*; import io.meeds.wallet.utils.WalletUtils; import org.apache.commons.lang3.StringUtils; @@ -423,9 +422,8 @@ void testExportRewards() throws Exception { assertNotNull(row1); assertEquals(7, row1.getLastCellNum()); assertEquals(200, row1.getCell(2).getNumericCellValue()); - assertEquals(50, row1.getCell(3).getNumericCellValue()); + assertEquals("MEED 50", row1.getCell(3).getStringCellValue()); assertEquals("success", row1.getCell(4).getStringCellValue()); - assertEquals("transactionHash", row1.getCell(6).getStringCellValue()); } protected Wallet newWallet(long identityId) { 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 dc2d9bb80..e497f1598 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 @@ -86,8 +86,7 @@