Commit a947450a authored by tom's avatar tom

fix: block rewards fields can be null

parent c3ff0d15
...@@ -172,8 +172,8 @@ export interface BlockEpoch { ...@@ -172,8 +172,8 @@ export interface BlockEpoch {
carbon_offsetting_transfer: TokenTransfer | null; carbon_offsetting_transfer: TokenTransfer | null;
community_transfer: TokenTransfer | null; community_transfer: TokenTransfer | null;
reserve_bolster_transfer: TokenTransfer | null; reserve_bolster_transfer: TokenTransfer | null;
}; } | null;
aggregated_election_rewards: Record<EpochRewardsType, BlockEpochElectionReward | null>; aggregated_election_rewards: Record<EpochRewardsType, BlockEpochElectionReward | null> | null;
} }
export interface BlockEpochElectionRewardDetails { export interface BlockEpochElectionRewardDetails {
......
...@@ -25,7 +25,7 @@ const BlockEpochRewards = ({ heightOrHash }: Props) => { ...@@ -25,7 +25,7 @@ const BlockEpochRewards = ({ heightOrHash }: Props) => {
return <DataFetchAlert/>; return <DataFetchAlert/>;
} }
if (!query.data) { if (!query.data || (!query.data.aggregated_election_rewards && !query.data.distribution)) {
return <span>No block epoch rewards data</span>; return <span>No block epoch rewards data</span>;
} }
......
...@@ -12,6 +12,10 @@ interface Props { ...@@ -12,6 +12,10 @@ interface Props {
} }
const BlockEpochElectionRewards = ({ data, isLoading }: Props) => { const BlockEpochElectionRewards = ({ data, isLoading }: Props) => {
if (!data.aggregated_election_rewards) {
return null;
}
return ( return (
<Box mt={ 8 }> <Box mt={ 8 }>
<Heading as="h4" size="sm" mb={ 3 }>Election rewards</Heading> <Heading as="h4" size="sm" mb={ 3 }>Election rewards</Heading>
......
...@@ -15,6 +15,10 @@ interface Props { ...@@ -15,6 +15,10 @@ interface Props {
const BlockEpochRewardsDistribution = ({ data, isLoading }: Props) => { const BlockEpochRewardsDistribution = ({ data, isLoading }: Props) => {
const isMobile = useIsMobile(); const isMobile = useIsMobile();
if (!data.distribution) {
return null;
}
if (!data.distribution.community_transfer && !data.distribution.carbon_offsetting_transfer && !data.distribution.reserve_bolster_transfer) { if (!data.distribution.community_transfer && !data.distribution.carbon_offsetting_transfer && !data.distribution.reserve_bolster_transfer) {
return null; return null;
} }
......
import type { BlockEpoch } from 'types/api/block'; import type { BlockEpoch } from 'types/api/block';
import type { ExcludeNull } from 'types/utils';
export function getRewardNumText(type: keyof BlockEpoch['aggregated_election_rewards'], num: number) { export function getRewardNumText(type: keyof BlockEpoch['aggregated_election_rewards'], num: number) {
const postfix1 = num !== 1 ? 's' : ''; const postfix1 = num !== 1 ? 's' : '';
...@@ -26,7 +27,7 @@ export function getRewardNumText(type: keyof BlockEpoch['aggregated_election_rew ...@@ -26,7 +27,7 @@ export function getRewardNumText(type: keyof BlockEpoch['aggregated_election_rew
return `${ num } ${ text }`; 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) { switch (type) {
case 'delegated_payment': case 'delegated_payment':
return [ 'Beneficiary', 'Validator' ]; return [ 'Beneficiary', 'Validator' ];
...@@ -39,6 +40,6 @@ export function getRewardDetailsTableTitles(type: keyof BlockEpoch['aggregated_e ...@@ -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('_', '-'); 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