From 483a1477f335b6f98aaed787851b83c6aa5c101e Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 23 Jun 2021 13:49:52 -0700 Subject: [PATCH] Explorer: display message when block rewards not found for interval (#17943) * fix: disable block not found error message and give feedback for rewards not found * feat: add lowest available epochs for rewards * feat: make sure current epoch is not fetched --- .../src/components/account/RewardsCard.tsx | 37 +++++++++++-------- explorer/src/providers/accounts/rewards.tsx | 27 ++++++++++---- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/explorer/src/components/account/RewardsCard.tsx b/explorer/src/components/account/RewardsCard.tsx index 39d2cb3eb5..e4d48e54bc 100644 --- a/explorer/src/components/account/RewardsCard.tsx +++ b/explorer/src/components/account/RewardsCard.tsx @@ -61,8 +61,8 @@ export function RewardsCard({ pubkey }: { pubkey: PublicKey }) { ); }); - - const { foundOldest } = rewards.data; + const rewardsFound = rewardsList.some((r) => r); + const { foundOldest, lowestFetchedEpoch, highestFetchedEpoch } = rewards.data; const fetching = rewards.status === FetchStatus.Fetching; return ( @@ -76,19 +76,26 @@ export function RewardsCard({ pubkey }: { pubkey: PublicKey }) { -
- - - - - - - - - - {rewardsList} -
EpochEffective SlotReward AmountPost Balance
-
+ {rewardsFound ? ( +
+ + + + + + + + + + {rewardsList} +
EpochEffective SlotReward AmountPost Balance
+
+ ) : ( +
+ No rewards issued between epochs {lowestFetchedEpoch} and{" "} + {highestFetchedEpoch} +
+ )}
{foundOldest ? ( diff --git a/explorer/src/providers/accounts/rewards.tsx b/explorer/src/providers/accounts/rewards.tsx index 4b3517ad05..32fc4a0078 100644 --- a/explorer/src/providers/accounts/rewards.tsx +++ b/explorer/src/providers/accounts/rewards.tsx @@ -6,6 +6,11 @@ import { ActionType } from "providers/block"; import { FetchStatus } from "providers/cache"; import { reportError } from "utils/sentry"; +const REWARDS_AVAILABLE_EPOCH = new Map([ + [Cluster.MainnetBeta, 132], + [Cluster.Testnet, 43], +]); + const PAGE_SIZE = 15; export type Rewards = { @@ -17,6 +22,8 @@ export type Rewards = { export type RewardsUpdate = { rewards: (InflationReward | null)[]; + highestFetchedEpoch: number; + lowestFetchedEpoch: number; foundOldest?: boolean; }; @@ -39,8 +46,9 @@ function reconcile( return { rewards: combined, - highestFetchedEpoch: combined[0]?.epoch, - lowestFetchedEpoch: combined[combined.length - 1]?.epoch, + highestFetchedEpoch: + rewards?.highestFetchedEpoch || update.highestFetchedEpoch, + lowestFetchedEpoch: update.lowestFetchedEpoch, foundOldest, }; } @@ -84,12 +92,9 @@ async function fetchRewards( url, }); + const lowestAvailableEpoch = REWARDS_AVAILABLE_EPOCH.get(cluster) || 0; const connection = new Connection(url); - if (!fromEpoch && highestEpoch) { - fromEpoch = highestEpoch; - } - if (!fromEpoch) { try { const epochInfo = await connection.getEpochInfo(); @@ -106,6 +111,10 @@ async function fetchRewards( url, }); } + + if (highestEpoch && highestEpoch < fromEpoch) { + fromEpoch = highestEpoch; + } } const getInflationReward = async (epoch: number) => { @@ -128,7 +137,7 @@ async function fetchRewards( } const results = await Promise.all(requests); - fromEpoch = fromEpoch - requests.length; + const lowestFetchedEpoch = fromEpoch - requests.length; dispatch({ type: ActionType.Update, @@ -137,7 +146,9 @@ async function fetchRewards( status: FetchStatus.Fetched, data: { rewards: results || [], - foundOldest: fromEpoch <= 0, + foundOldest: lowestFetchedEpoch <= lowestAvailableEpoch, + highestFetchedEpoch: fromEpoch, + lowestFetchedEpoch, }, }); }