Skip to content

Commit 767c9ef

Browse files
authored
Merge pull request #2803 from input-output-hk/feature/ddw-614-add-display-of-current-rewards-balance
[DDW-614] Show unspent ADA amount in rewards table
2 parents 10222ac + b7432a0 commit 767c9ef

26 files changed

+537
-170
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Features
66

7+
- Added display of current/unspent rewards ([PR 2803](https://github.com/input-output-hk/daedalus/pull/2803))
78
- Improve the syncing screen by showing syncing progress split into three stages ([PR 2877](https://github.com/input-output-hk/daedalus/pull/2877))
89
- Improved stake pool searchbar ([PR 2847](https://github.com/input-output-hk/daedalus/pull/2847))
910
- Implemented catalyst dynamic content ([PR 2856](https://github.com/input-output-hk/daedalus/pull/2856))

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"@testing-library/jest-dom": "5.15.1",
9393
"@testing-library/react": "12.1.2",
9494
"@types/aes-js": "^3.1.1",
95+
"@types/jest": "27.4.0",
9596
"@types/node": "^17.0.12",
9697
"@types/qrcode.react": "^1.0.2",
9798
"@types/react": "^17.0.38",

source/renderer/app/api/staking/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ export type AdaApiStakePools = Array<AdaApiStakePool>;
5656
export type Reward = {
5757
date?: string;
5858
wallet: string;
59-
reward: BigNumber;
59+
total: BigNumber;
60+
unspent: BigNumber;
6061
rewardsAddress: string;
62+
isRestoring: boolean;
63+
syncingProgress: number;
6164
pool?: StakePool;
6265
};
6366
export type EpochData = {

source/renderer/app/components/staking/rewards/StakingRewards.scss

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@
180180
visibility: visible;
181181
}
182182
}
183+
184+
&.total,
185+
&.unspent {
186+
padding-right: 10px;
187+
text-align: right;
188+
}
183189
}
184190

185191
td {
@@ -209,12 +215,9 @@
209215

210216
.syncingProgress {
211217
position: absolute;
212-
right: 10px;
213-
top: 0;
214-
218+
right: 22px;
219+
top: 10px;
215220
:global .LoadingSpinner_component.LoadingSpinner_medium {
216-
margin: 10px auto !important;
217-
218221
.LoadingSpinner_icon svg path {
219222
fill: var(--theme-loading-spinner-color);
220223
opacity: 0.3;
@@ -273,16 +276,11 @@
273276

274277
&.rewardWallet {
275278
max-width: 200px;
276-
min-width: 200px;
277279
overflow: hidden;
278280
text-overflow: ellipsis;
279281
white-space: nowrap;
280282
}
281283

282-
&.rewardAmount {
283-
min-width: 250px;
284-
}
285-
286284
&.rewardsAddress {
287285
min-width: 100px;
288286

@@ -301,7 +299,7 @@
301299
overflow: hidden;
302300
text-overflow: ellipsis;
303301
white-space: nowrap;
304-
width: 237px;
302+
width: 200px;
305303

306304
&:hover {
307305
cursor: pointer;
@@ -325,6 +323,12 @@
325323
}
326324
}
327325
}
326+
327+
&.rewardTotal,
328+
&.rewardUnspent {
329+
padding-right: 23px;
330+
text-align: right;
331+
}
328332
}
329333
}
330334
}

source/renderer/app/components/staking/rewards/StakingRewards.tsx

Lines changed: 64 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,15 @@ const messages = defineMessages({
5757
defaultMessage: '!!!Wallet',
5858
description: 'Table header "Wallet" label on staking rewards page',
5959
},
60-
tableHeaderReward: {
61-
id: 'staking.rewards.tableHeader.reward',
60+
tableHeaderRewardTotal: {
61+
id: 'staking.rewards.tableHeader.total',
6262
defaultMessage: '!!!Total rewards earned (ADA)',
63-
description: 'Table header "Reward" label on staking rewards page',
63+
description: 'Table header "Total Reward" label on staking rewards page',
64+
},
65+
tableHeaderRewardUnspent: {
66+
id: 'staking.rewards.tableHeader.unspent',
67+
defaultMessage: '!!!Unspent (ADA)',
68+
description: 'Table header "Unspent" label on staking rewards page',
6469
},
6570
tableHeaderRewardsAddress: {
6671
id: 'staking.rewards.tableHeader.rewardsAddress',
@@ -93,7 +98,8 @@ const REWARD_FIELDS = {
9398
WALLET_NAME: 'wallet',
9499
IS_RESTORING: 'isRestoring',
95100
SYNCING_PROGRESS: 'syncingProgress',
96-
REWARD: 'reward',
101+
REWARD_TOTAL: 'total',
102+
REWARD_UNSPENT: 'unspent',
97103
REWARDS_ADDRESS: 'rewardsAddress',
98104
};
99105
const REWARD_ORDERS = {
@@ -148,14 +154,18 @@ class StakingRewards extends Component<Props, State> {
148154
const exportedBody = sortedRewards.map((reward) => {
149155
const rewardWallet = get(reward, REWARD_FIELDS.WALLET_NAME);
150156
const isRestoring = get(reward, REWARD_FIELDS.IS_RESTORING);
151-
const rewardAmount = get(reward, REWARD_FIELDS.REWARD).toFormat(
157+
const rewardTotal = get(reward, REWARD_FIELDS.REWARD_TOTAL).toFormat(
158+
DECIMAL_PLACES_IN_ADA
159+
);
160+
const rewardUnspent = get(reward, REWARD_FIELDS.REWARD_UNSPENT).toFormat(
152161
DECIMAL_PLACES_IN_ADA
153162
);
154163
const rewardsAddress = get(reward, REWARD_FIELDS.REWARDS_ADDRESS);
155164
return [
156165
rewardWallet,
157166
rewardsAddress,
158-
isRestoring ? '-' : rewardAmount,
167+
isRestoring ? '-' : rewardTotal,
168+
isRestoring ? '-' : rewardUnspent,
159169
date,
160170
];
161171
});
@@ -169,9 +179,14 @@ class StakingRewards extends Component<Props, State> {
169179
const { rewards } = this.props;
170180
const { rewardsOrder, rewardsSortBy } = this.state;
171181
return rewards.slice().sort((rewardA: Reward, rewardB: Reward) => {
172-
const rewardCompareResult = bigNumberComparator(
173-
rewardA.reward,
174-
rewardB.reward,
182+
const totalCompareResult = bigNumberComparator(
183+
rewardA.total,
184+
rewardB.total,
185+
rewardsOrder === REWARD_ORDERS.ASCENDING
186+
);
187+
const unspentCompareResult = bigNumberComparator(
188+
rewardA.unspent,
189+
rewardB.unspent,
175190
rewardsOrder === REWARD_ORDERS.ASCENDING
176191
);
177192
const walletNameCompareResult = stringComparator(
@@ -185,40 +200,28 @@ class StakingRewards extends Component<Props, State> {
185200
rewardsOrder === REWARD_ORDERS.ASCENDING
186201
);
187202

188-
if (rewardsSortBy === REWARD_FIELDS.REWARD) {
189-
if (rewardCompareResult === 0 && walletAddressCompareResult === 0) {
190-
return walletNameCompareResult;
191-
}
192-
193-
if (rewardCompareResult === 0 && walletNameCompareResult === 0) {
194-
return walletAddressCompareResult;
195-
}
203+
if (rewardsSortBy === REWARD_FIELDS.REWARD_TOTAL) {
204+
if (totalCompareResult !== 0) return totalCompareResult;
205+
if (walletNameCompareResult !== 0) return walletNameCompareResult;
206+
return walletAddressCompareResult;
207+
}
196208

197-
return rewardCompareResult;
209+
if (rewardsSortBy === REWARD_FIELDS.REWARD_UNSPENT) {
210+
if (unspentCompareResult !== 0) return unspentCompareResult;
211+
if (walletNameCompareResult !== 0) return walletNameCompareResult;
212+
return walletAddressCompareResult;
198213
}
199214

200215
if (rewardsSortBy === REWARD_FIELDS.WALLET_NAME) {
201-
if (walletNameCompareResult === 0 && walletAddressCompareResult) {
202-
return rewardCompareResult;
203-
}
204-
205-
if (rewardCompareResult === 0 && walletNameCompareResult === 0) {
206-
return walletAddressCompareResult;
207-
}
208-
209-
return walletNameCompareResult;
216+
if (walletNameCompareResult !== 0) return walletNameCompareResult;
217+
if (totalCompareResult !== 0) return totalCompareResult;
218+
return walletAddressCompareResult;
210219
}
211220

212221
if (rewardsSortBy === REWARD_FIELDS.REWARDS_ADDRESS) {
213-
if (walletAddressCompareResult === 0 && rewardCompareResult === 0) {
214-
return walletNameCompareResult;
215-
}
216-
217-
if (walletAddressCompareResult === 0 && walletNameCompareResult === 0) {
218-
return rewardCompareResult;
219-
}
220-
221-
return walletAddressCompareResult;
222+
if (walletAddressCompareResult !== 0) return walletAddressCompareResult;
223+
if (walletNameCompareResult !== 0) return walletNameCompareResult;
224+
return totalCompareResult;
222225
}
223226

224227
return 0;
@@ -253,9 +256,15 @@ class StakingRewards extends Component<Props, State> {
253256
title: intl.formatMessage(messages.tableHeaderRewardsAddress),
254257
},
255258
{
256-
name: REWARD_FIELDS.REWARD,
259+
name: REWARD_FIELDS.REWARD_TOTAL,
257260
title: `${intl.formatMessage(
258-
messages.tableHeaderReward
261+
messages.tableHeaderRewardTotal
262+
)} (${intl.formatMessage(globalMessages.adaUnit)})`,
263+
},
264+
{
265+
name: REWARD_FIELDS.REWARD_UNSPENT,
266+
title: `${intl.formatMessage(
267+
messages.tableHeaderRewardUnspent
259268
)} (${intl.formatMessage(globalMessages.adaUnit)})`,
260269
},
261270
];
@@ -323,6 +332,7 @@ class StakingRewards extends Component<Props, State> {
323332
]);
324333
return (
325334
<th
335+
className={styles[tableHeader.name]}
326336
key={tableHeader.name}
327337
onClick={() =>
328338
this.handleRewardsSort(tableHeader.name)
@@ -346,9 +356,13 @@ class StakingRewards extends Component<Props, State> {
346356
reward,
347357
REWARD_FIELDS.SYNCING_PROGRESS
348358
);
349-
const rewardAmount = get(
359+
const rewardTotal = get(
350360
reward,
351-
REWARD_FIELDS.REWARD
361+
REWARD_FIELDS.REWARD_TOTAL
362+
).toFormat(DECIMAL_PLACES_IN_ADA);
363+
const rewardUnspent = get(
364+
reward,
365+
REWARD_FIELDS.REWARD_UNSPENT
352366
).toFormat(DECIMAL_PLACES_IN_ADA);
353367
const rewardsAddress = get(
354368
reward,
@@ -397,11 +411,9 @@ class StakingRewards extends Component<Props, State> {
397411
</div>
398412
)}
399413
</td>
400-
<td className={styles.rewardAmount}>
401-
{isRestoring ? (
402-
'-'
403-
) : (
404-
<RewardAmount amount={rewardAmount} />
414+
<td className={styles.rewardTotal}>
415+
{!isRestoring && (
416+
<RewardAmount amount={rewardTotal} />
405417
)}
406418
{isRestoring && (
407419
<div className={styles.syncingProgress}>
@@ -418,6 +430,13 @@ class StakingRewards extends Component<Props, State> {
418430
</div>
419431
)}
420432
</td>
433+
<td className={styles.rewardUnspent}>
434+
{isRestoring ? (
435+
'-'
436+
) : (
437+
<RewardAmount amount={rewardUnspent} />
438+
)}
439+
</td>
421440
</tr>
422441
);
423442
})}

source/renderer/app/components/wallet/summary/WalletSummary.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { Component } from 'react';
22
import { observer } from 'mobx-react';
33
import { defineMessages, intlShape } from 'react-intl';
4+
import type { Reward } from '../../../api/staking/types';
45
import Wallet from '../../../domains/Wallet';
56
import type { Currency } from '../../../types/currencyTypes';
67
import WalletSummaryHeader from './WalletSummaryHeader';
@@ -18,6 +19,7 @@ const messages = defineMessages({
1819
});
1920
type Props = {
2021
wallet: Wallet;
22+
reward: Reward;
2123
numberOfRecentTransactions: number;
2224
numberOfTransactions?: number;
2325
numberOfPendingTransactions: number;
@@ -50,6 +52,7 @@ class WalletSummary extends Component<Props> {
5052
render() {
5153
const {
5254
wallet,
55+
reward,
5356
numberOfPendingTransactions,
5457
numberOfRecentTransactions,
5558
numberOfTransactions,
@@ -78,6 +81,7 @@ class WalletSummary extends Component<Props> {
7881
<>
7982
<WalletSummaryHeader
8083
wallet={wallet}
84+
reward={reward}
8185
numberOfRecentTransactions={numberOfRecentTransactions}
8286
numberOfTransactions={numberOfTransactions}
8387
numberOfPendingTransactions={numberOfPendingTransactions}

source/renderer/app/components/wallet/summary/WalletSummaryCurrency.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
font-family: var(--font-bold);
3333
font-size: 16px;
3434
line-height: 1;
35-
margin-bottom: 5.5px;
35+
margin-bottom: 8.5px;
3636
user-select: text;
3737
word-break: break-all;
3838

source/renderer/app/components/wallet/summary/WalletSummaryHeader.scss

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
}
1515

1616
.walletContent {
17-
align-items: center;
1817
display: flex;
1918
flex-direction: row;
2019
justify-content: space-between;
2120
}
2221

22+
.currency {
23+
min-width: 187px;
24+
padding-top: 6px;
25+
}
26+
2327
.walletName {
2428
color: var(--theme-bordered-box-text-color);
2529
font-family: var(--font-regular);
@@ -40,28 +44,28 @@
4044
word-break: break-all;
4145

4246
.currencyCode {
43-
font-size: 16px;
4447
font-size: 16px;
4548
margin-left: 6px;
4649
opacity: 0.7;
4750
}
4851
}
4952

53+
.rewards {
54+
@extend %smallText;
55+
height: auto;
56+
}
57+
58+
.rewardsAmount {
59+
font-family: var(--font-medium);
60+
}
61+
5062
.transactionsCountWrapper {
51-
.numberOfTransactions,
52-
.numberOfPendingTransactions {
63+
.numberOfTransactions {
5364
@extend %smallText;
54-
55-
span:first-child {
65+
font-family: var(--font-light);
66+
span {
5667
font-family: var(--font-medium);
57-
opacity: 0.7;
5868
}
59-
60-
span:last-child {
61-
font-family: var(--font-light);
62-
opacity: 1;
63-
}
64-
6569
&.isLoadingNumberOfTransactions {
6670
@include animated-ellipsis($width: 16px);
6771
}

0 commit comments

Comments
 (0)