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
This commit is contained in:
Josh 2021-06-23 13:49:52 -07:00 committed by GitHub
parent 77c3ffe4cf
commit 483a1477f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 23 deletions

View File

@ -61,8 +61,8 @@ export function RewardsCard({ pubkey }: { pubkey: PublicKey }) {
</tr>
);
});
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 }) {
</div>
</div>
<div className="table-responsive mb-0">
<table className="table table-sm table-nowrap card-table">
<thead>
<tr>
<th className="w-1 text-muted">Epoch</th>
<th className="text-muted">Effective Slot</th>
<th className="text-muted">Reward Amount</th>
<th className="text-muted">Post Balance</th>
</tr>
</thead>
<tbody className="list">{rewardsList}</tbody>
</table>
</div>
{rewardsFound ? (
<div className="table-responsive mb-0">
<table className="table table-sm table-nowrap card-table">
<thead>
<tr>
<th className="w-1 text-muted">Epoch</th>
<th className="text-muted">Effective Slot</th>
<th className="text-muted">Reward Amount</th>
<th className="text-muted">Post Balance</th>
</tr>
</thead>
<tbody className="list">{rewardsList}</tbody>
</table>
</div>
) : (
<div className="card-body">
No rewards issued between epochs {lowestFetchedEpoch} and{" "}
{highestFetchedEpoch}
</div>
)}
<div className="card-footer">
{foundOldest ? (

View File

@ -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, number>([
[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,
},
});
}