Commit a947450a authored by tom's avatar tom

fix: block rewards fields can be null

parent c3ff0d15
......@@ -172,8 +172,8 @@ export interface BlockEpoch {
carbon_offsetting_transfer: TokenTransfer | null;
community_transfer: TokenTransfer | null;
reserve_bolster_transfer: TokenTransfer | null;
};
aggregated_election_rewards: Record<EpochRewardsType, BlockEpochElectionReward | null>;
} | null;
aggregated_election_rewards: Record<EpochRewardsType, BlockEpochElectionReward | null> | null;
}
export interface BlockEpochElectionRewardDetails {
......
......@@ -25,7 +25,7 @@ const BlockEpochRewards = ({ heightOrHash }: Props) => {
return <DataFetchAlert/>;
}
if (!query.data) {
if (!query.data || (!query.data.aggregated_election_rewards && !query.data.distribution)) {
return <span>No block epoch rewards data</span>;
}
......
......@@ -12,6 +12,10 @@ interface Props {
}
const BlockEpochElectionRewards = ({ data, isLoading }: Props) => {
if (!data.aggregated_election_rewards) {
return null;
}
return (
<Box mt={ 8 }>
<Heading as="h4" size="sm" mb={ 3 }>Election rewards</Heading>
......
......@@ -15,6 +15,10 @@ interface Props {
const BlockEpochRewardsDistribution = ({ data, isLoading }: Props) => {
const isMobile = useIsMobile();
if (!data.distribution) {
return null;
}
if (!data.distribution.community_transfer && !data.distribution.carbon_offsetting_transfer && !data.distribution.reserve_bolster_transfer) {
return null;
}
......
import type { BlockEpoch } from 'types/api/block';
import type { ExcludeNull } from 'types/utils';
export function getRewardNumText(type: keyof BlockEpoch['aggregated_election_rewards'], num: number) {
const postfix1 = num !== 1 ? 's' : '';
......@@ -26,7 +27,7 @@ export function getRewardNumText(type: keyof BlockEpoch['aggregated_election_rew
return `${ num } ${ text }`;
}
export function getRewardDetailsTableTitles(type: keyof BlockEpoch['aggregated_election_rewards']): [string, string] {
export function getRewardDetailsTableTitles(type: keyof ExcludeNull<BlockEpoch['aggregated_election_rewards']>): [string, string] {
switch (type) {
case 'delegated_payment':
return [ 'Beneficiary', 'Validator' ];
......@@ -39,6 +40,6 @@ export function getRewardDetailsTableTitles(type: keyof BlockEpoch['aggregated_e
}
}
export function formatRewardType(type: keyof BlockEpoch['aggregated_election_rewards']) {
export function formatRewardType(type: keyof ExcludeNull<BlockEpoch['aggregated_election_rewards']>) {
return type.replaceAll('_', '-');
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment