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

feat: Implement See Rewards details drawer - MEED-7483 - Meeds-io/MIPs#154 #602

Merged
merged 1 commit into from
Oct 22, 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
17 changes: 10 additions & 7 deletions wallet-api/src/main/java/io/meeds/wallet/model/WalletReward.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ void testSendRewards() throws Exception {
Set<WalletReward> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ protected RewardReport createRewardReportInstance(boolean isSucceeded) {
Set<WalletReward> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
</v-list-item-title>
</v-list-item-content>
<v-list-item-action class="d-inline-block ma-auto pe-1">
<span class="fundsLabels"> MEED {{ tokenBalance }} </span>
<span class="fundsLabels"> MEED {{ tokenBalanceLabel }} </span>
</v-list-item-action>
</v-list-item>
<v-list-item>
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
</template>
</v-data-table>
<v-toolbar
Expand All @@ -132,6 +133,10 @@
:to-date-in-second="endDateInSeconds"
go-back-button
relative />
<wallet-rewards-details-drawer
ref="rewardsDetailsDrawer"
:wallet-reward="selectedWalletReward"
:token-symbol="tokenSymbol" />
</v-card>
</template>

Expand Down Expand Up @@ -172,6 +177,7 @@ export default {
day: 'numeric',
},
walletRewards: [],
selectedWalletReward: null,
status: 'VALID',
sortBy: 'tokensToSend',
sortDescending: true,
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
display-no-address />
</td>
<td class="text-center">
<v-btn icon @click="openContributionDetails">
<v-btn
text
@click="openContributionDetails">
{{ points }}
</v-btn>
</td>
Expand Down Expand Up @@ -97,12 +99,16 @@
</v-tooltip>
</td>
<td class="text-center">
<span
<v-btn
v-if="amount"
:title="$t('exoplatform.wallet.label.amountSent')"
class="grey--text text--darken-1">
<span class="symbol fundsLabels"> {{ tokenSymbol }} </span>{{ walletUtils.toFixed(amount) }}
</span>
text
@click="openRewardsDetails">
<span
:title="$t('exoplatform.wallet.label.amountSent')"
class="grey--text text--darken-1">
<span class="symbol fundsLabels"> {{ tokenSymbol }} </span>{{ walletUtils.toFixed(amount) }}
</span>
</v-btn>
<span
v-else
:title="$t('exoplatform.wallet.label.noRewardsForPeriod')"
Expand Down Expand Up @@ -293,6 +299,9 @@ export default {
},
openContributionDetails() {
this.$emit('open-contribution-details', this.walletTechnicalId);
},
openRewardsDetails() {
this.$emit('open-rewards-details', this.reward);
}
}
};
Expand Down
Loading