Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: adjust code to deal with missing rewards on current epoch #168

Merged
merged 1 commit into from
Feb 14, 2025
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.9.5] - 2025-02-14

### Fixed

- Adjusted rewards calculation to work with new scheme where rewards were unavailable on current epoch

## [1.9.4] - 2025-02-13

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ar-io/network-portal",
"private": true,
"version": "1.9.4",
"version": "1.9.5",
"type": "module",
"scripts": {
"build": "yarn clean && tsc --build tsconfig.build.json && NODE_OPTIONS=--max-old-space-size=32768 vite build",
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useGatewaysPerEpoch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const useGatewaysPerEpoch = () => {
epochIndex: epoch.epochIndex,
totalEligibleGateways:
epoch.distributions.totalEligibleGateways ||
Object.keys(epoch.distributions.rewards.eligible).length,
Object.keys(epoch.distributions.rewards?.eligible ?? {}).length,
};
});
},
Expand Down
15 changes: 8 additions & 7 deletions src/hooks/useRewardsEarned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ const useRewardsEarned = (walletAddress?: string) => {

useEffect(() => {
if (epochs && walletAddress) {
const sorted = epochs.sort((a, b) => (a?.epochIndex || 0) - (b?.epochIndex || 0));
const sorted = epochs.sort(
(a, b) => (a?.epochIndex || 0) - (b?.epochIndex || 0),
);
const previousEpoch = sorted[sorted.length - 2];
// rewards are not avialable on current epoch
const previousEpochDistributed =
previousEpoch?.distributions.rewards.distributed;
const previousEpochRewards = previousEpochDistributed
? previousEpochDistributed[walletAddress] || 0
: 0;
previousEpoch?.distributions.rewards?.distributed ?? {};
const previousEpochRewards = previousEpochDistributed[walletAddress] || 0;

const totalForPastAvailableEpochs = epochs.reduce((acc, epoch) => {
const distributed = epoch?.distributions.rewards.distributed;
return acc + (distributed ? distributed[walletAddress] || 0 : 0);
const distributed = epoch?.distributions.rewards?.distributed ?? {};
return acc + (distributed[walletAddress] || 0);
}, 0);

setRewardsEarned({
Expand Down