Skip to content
This repository was archived by the owner on Jan 9, 2026. It is now read-only.

Commit 1463104

Browse files
authored
Block reward for blocks without transactions + block referenced with hashes resolved + minor reward details issues (#23)
1 parent 0aca1df commit 1463104

File tree

4 files changed

+148
-113
lines changed

4 files changed

+148
-113
lines changed

lib/block/getBlockReward.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Block } from 'types/api/block';
44

55
export default function getBlockReward(block: Block) {
66
const txFees = BigNumber(block.transaction_fees || 0);
7+
const priorityFee = BigNumber(block.priority_fee || 0);
78
const burntFees = BigNumber(block.burnt_fees || 0);
89
const minerReward = block.rewards?.find(({ type }) => type === 'Miner Reward' || type === 'Validator Reward')?.reward;
910
const totalReward = BigNumber(minerReward || 0);
@@ -14,5 +15,6 @@ export default function getBlockReward(block: Block) {
1415
staticReward,
1516
txFees,
1617
burntFees,
18+
priorityFee,
1719
};
1820
}

ui/block/BlockDetails.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,17 @@ const BlockDetails = ({ query }: Props) => {
7878

7979
const validatorTitle = getNetworkValidatorTitle();
8080

81+
const shouldHideRewardBreakdown = () => {
82+
return (
83+
rollupFeature.isEnabled ||
84+
totalReward.isEqualTo(ZERO) ||
85+
txFees.isEqualTo(ZERO) ||
86+
burntFees.isEqualTo(ZERO)
87+
) && data.withdrawals_count === 0;
88+
};
89+
8190
const rewardBreakDown = (() => {
82-
if (rollupFeature.isEnabled || totalReward.isEqualTo(ZERO) || txFees.isEqualTo(ZERO) || burntFees.isEqualTo(ZERO)) {
91+
if (shouldHideRewardBreakdown()) {
8392
return null;
8493
}
8594

@@ -345,19 +354,26 @@ const BlockDetails = ({ query }: Props) => {
345354
</>
346355
) }
347356

348-
{ !rollupFeature.isEnabled && !totalReward.isEqualTo(ZERO) && (
357+
{ !rollupFeature.isEnabled && (data.withdrawals_count ?? 0) > 0 && (
349358
<>
350359
<DetailedInfo.ItemLabel
351360
hint={
352-
`For each block, the ${ validatorTitle } is rewarded with a finite amount of ${ config.chain.currency.symbol || 'native token' }
353-
on top of the fees paid for all transactions in the block`
361+
data.transactions_count > 0 && data.burnt_fees !== '0' ?
362+
`For each block, the ${ validatorTitle } is rewarded with a finite amount of ${ config.chain.currency.symbol || 'native token' }
363+
on top of the fees paid for all transactions in the block` :
364+
'Mining rewards'
354365
}
355366
isLoading={ isPlaceholderData }
356367
>
357368
Block reward
358369
</DetailedInfo.ItemLabel>
359370
<DetailedInfo.ItemValue columnGap={ 1 }>
360-
<Skeleton loading={ isPlaceholderData } minH="140px" minW={{ base: '100%', md: '400px' }} w={{ base: '100%', md: 'min-content' }}>
371+
<Skeleton
372+
loading={ isPlaceholderData }
373+
minH={ data.transactions_count > 0 && data.burnt_fees !== '0' ? '140px' : '24px' }
374+
minW={{ base: '100%', md: '400px' }}
375+
w={{ base: '100%', md: 'min-content' }}
376+
>
361377
{ rewardBreakDown }
362378
</Skeleton>
363379
</DetailedInfo.ItemValue>

ui/block/BlockRewards.tsx

Lines changed: 111 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ const KDABlockRewards = ({ query }: Props) => {
158158
const handleBurntFeesValuesMouseLeave = useCallback(() => onMouseLeaveValues(burntFeesValuesRef), [ onMouseLeaveValues ]);
159159

160160
if (isLoading) {
161-
return <Skeleton loading={ isLoading } minH="140px" maxW="380px" w="100%"/>;
161+
return <Skeleton loading={ isLoading } minH={ hasTxFees && hasBurntFees ? '140px' : '24px' } maxW="380px" w="100%"/>;
162162
}
163163

164164
if (!calculatedValues) {
@@ -170,110 +170,118 @@ const KDABlockRewards = ({ query }: Props) => {
170170
<chakra.span fontFamily="var(--kda-typography-family-monospace-font)">
171171
{ rewardAmount } { currencyUnits.ether }
172172
</chakra.span>
173-
<chakra.div>
174-
<Text color="text.primary" fontWeight="bold" fontSize="sm" display="inline">
175-
Breakdown{ space }
176-
</Text>
177-
<chakra.div display={{ base: 'none', md: 'flex' }} flexDirection="row" gap={ 2 } alignItems="center" mt={ 3 }>
178-
<KDABreakdownItem
179-
ref={ blockRewardValuesRef }
180-
isLoading={ isLoading }
181-
onMouseEnter={ handleBlockRewardMouseEnter }
182-
onMouseLeave={ handleBlockRewardMouseLeave }>
183-
<Text color="text.primary" fontSize="sm" display="inline" fontFamily="var(--global-font-body, var(--font-fallback))">
184-
<chakra.span whiteSpace="nowrap">
185-
<Hint label="PoW mining reward"/>
186-
Mining reward
187-
</chakra.span>
188-
</Text>
189-
</KDABreakdownItem>
190-
+
191-
<KDABreakdownItem
192-
ref={ txFeesValuesRef }
193-
isLoading={ isLoading }
194-
onMouseEnter={ handleTxFeesMouseEnter }
195-
onMouseLeave={ handleTxFeesMouseLeave }>
196-
<Text color="text.primary" fontSize="sm" display="inline" fontFamily="var(--global-font-body, var(--font-fallback))">
197-
<chakra.span whiteSpace="nowrap">
198-
<Hint label="Total transaction fees collected from all transactions in the block"/>
199-
Transaction fees
200-
</chakra.span>
201-
</Text>
202-
</KDABreakdownItem>
203-
-
204-
<KDABreakdownItem
205-
ref={ burntFeesValuesRef }
206-
isLoading={ isLoading }
207-
onMouseEnter={ handleBurntFeesMouseEnter }
208-
onMouseLeave={ handleBurntFeesMouseLeave }>
209-
<Text color="text.primary" fontSize="sm" display="inline" fontFamily="var(--global-font-body, var(--font-fallback))">
210-
<chakra.span whiteSpace="nowrap">
211-
<Hint label="Base fees burned (EIP-1559 mechanism)"/>
212-
Burnt fees
213-
</chakra.span>
214-
</Text>
215-
</KDABreakdownItem>
216-
</chakra.div>
217-
<RawDataSnippet
218-
data={ (
219-
<Text
220-
display="flex"
221-
flexDirection={{ base: 'column', md: 'row' }}
222-
color="text.secondary"
223-
fontSize="sm"
224-
whiteSpace="nowrap"
225-
gap={ 1 }
226-
fontFamily="var(--kda-typography-family-monospace-font)">
227-
{ hasRewardBaseFee && (
228-
<Tooltip content="Block reward">
229-
<BreakdownLabel
230-
ref={ blockRewardLabelRef }
231-
onMouseEnterValues={ handleBlockRewardValuesMouseEnter }
232-
onMouseLeaveValues={ handleBlockRewardValuesMouseLeave }
233-
>
234-
<chakra.span display={{ base: '', md: 'none' }} fontFamily="var(--global-font-body, var(--font-fallback))">
235-
Reward fee:
236-
</chakra.span>
237-
<span>{ rewardBaseFee }</span>
238-
</BreakdownLabel>
239-
</Tooltip>
240-
)
241-
}
242-
{ space }+{ space }
243-
{ hasTxFees && (
244-
<Tooltip content="Total transaction fees">
245-
<BreakdownLabel
246-
ref={ txFeesLabelRef }
247-
onMouseEnterValues={ handleTxFeesValuesMouseEnter }
248-
onMouseLeaveValues={ handleTxFeesValuesMouseLeave }
249-
>
250-
<chakra.span display={{ base: '', md: 'none' }} fontFamily="var(--global-font-body, var(--font-fallback))">
251-
Transaction fees:
252-
</chakra.span>
253-
<span>{ txFees }</span>
254-
</BreakdownLabel>
255-
</Tooltip>
256-
) }
257-
{ space }-{ space }
258-
{ hasBurntFees && (
259-
<Tooltip content="Burnt fees">
260-
<BreakdownLabel
261-
ref={ burntFeesLabelRef }
262-
onMouseEnterValues={ handleBurntFeesValuesMouseEnter }
263-
onMouseLeaveValues={ handleBurntFeesValuesMouseLeave }
264-
>
265-
<chakra.span display={{ base: '', md: 'none' }} fontFamily="var(--global-font-body, var(--font-fallback))">
266-
Burnt fees:{ ' ' }
267-
</chakra.span>
268-
<span>{ burntFees }</span>
269-
</BreakdownLabel>
270-
</Tooltip>
173+
{ hasTxFees && hasBurntFees && (
174+
<chakra.div>
175+
<Text color="text.primary" fontWeight="bold" fontSize="sm" display="inline">
176+
Breakdown{ space }
177+
</Text>
178+
<chakra.div display={{ base: 'none', md: 'flex' }} flexDirection="row" gap={ 2 } alignItems="center" mt={ 3 }>
179+
<KDABreakdownItem
180+
ref={ blockRewardValuesRef }
181+
isLoading={ isLoading }
182+
onMouseEnter={ handleBlockRewardMouseEnter }
183+
onMouseLeave={ handleBlockRewardMouseLeave }>
184+
<Text color="text.primary" fontSize="sm" display="inline" fontFamily="var(--global-font-body, var(--font-fallback))">
185+
<chakra.span whiteSpace="nowrap">
186+
<Hint label="PoW mining reward"/>
187+
Mining reward
188+
</chakra.span>
189+
</Text>
190+
</KDABreakdownItem>
191+
+
192+
<KDABreakdownItem
193+
ref={ txFeesValuesRef }
194+
isLoading={ isLoading }
195+
onMouseEnter={ handleTxFeesMouseEnter }
196+
onMouseLeave={ handleTxFeesMouseLeave }>
197+
<Text color="text.primary" fontSize="sm" display="inline" fontFamily="var(--global-font-body, var(--font-fallback))">
198+
<chakra.span whiteSpace="nowrap">
199+
<Hint label="Total transaction fees collected from all transactions in the block"/>
200+
Transaction fees
201+
</chakra.span>
202+
</Text>
203+
</KDABreakdownItem>
204+
-
205+
<KDABreakdownItem
206+
ref={ burntFeesValuesRef }
207+
isLoading={ isLoading }
208+
onMouseEnter={ handleBurntFeesMouseEnter }
209+
onMouseLeave={ handleBurntFeesMouseLeave }>
210+
<Text color="text.primary" fontSize="sm" display="inline" fontFamily="var(--global-font-body, var(--font-fallback))">
211+
<chakra.span whiteSpace="nowrap">
212+
<Hint label="Base fees burned (EIP-1559 mechanism)"/>
213+
Burnt fees
214+
</chakra.span>
215+
</Text>
216+
</KDABreakdownItem>
217+
</chakra.div>
218+
{ hasTxFees && hasBurntFees && (
219+
<RawDataSnippet
220+
data={ (
221+
<Text
222+
display="flex"
223+
flexDirection={{ base: 'column', md: 'row' }}
224+
color="text.secondary"
225+
fontSize="sm"
226+
whiteSpace="nowrap"
227+
gap={ 1 }
228+
fontFamily="var(--kda-typography-family-monospace-font)">
229+
{ hasRewardBaseFee && (
230+
<Tooltip content="Block reward">
231+
<BreakdownLabel
232+
ref={ blockRewardLabelRef }
233+
onMouseEnterValues={ handleBlockRewardValuesMouseEnter }
234+
onMouseLeaveValues={ handleBlockRewardValuesMouseLeave }
235+
>
236+
<chakra.span display={{ base: '', md: 'none' }} fontFamily="var(--global-font-body, var(--font-fallback))">
237+
Reward fee:
238+
</chakra.span>
239+
<span>{ rewardBaseFee }</span>
240+
</BreakdownLabel>
241+
</Tooltip>
242+
)
243+
}
244+
{ hasTxFees && (
245+
<>
246+
{ space }+{ space }
247+
<Tooltip content="Total transaction fees">
248+
<BreakdownLabel
249+
ref={ txFeesLabelRef }
250+
onMouseEnterValues={ handleTxFeesValuesMouseEnter }
251+
onMouseLeaveValues={ handleTxFeesValuesMouseLeave }
252+
>
253+
<chakra.span display={{ base: '', md: 'none' }} fontFamily="var(--global-font-body, var(--font-fallback))">
254+
Transaction fees:
255+
</chakra.span>
256+
<span>{ txFees }</span>
257+
</BreakdownLabel>
258+
</Tooltip>
259+
</>
260+
) }
261+
{ hasBurntFees && (
262+
<>
263+
{ space }-{ space }
264+
<Tooltip content="Burnt fees">
265+
<BreakdownLabel
266+
ref={ burntFeesLabelRef }
267+
onMouseEnterValues={ handleBurntFeesValuesMouseEnter }
268+
onMouseLeaveValues={ handleBurntFeesValuesMouseLeave }
269+
>
270+
<chakra.span display={{ base: '', md: 'none' }} fontFamily="var(--global-font-body, var(--font-fallback))">
271+
Burnt fees:{ ' ' }
272+
</chakra.span>
273+
<span>{ burntFees }</span>
274+
</BreakdownLabel>
275+
</Tooltip>
276+
</>
277+
) }
278+
</Text>
271279
) }
272-
</Text>
280+
isLoading={ isLoading }
281+
/>
273282
) }
274-
isLoading={ isLoading }
275-
/>
276-
</chakra.div>
283+
</chakra.div>
284+
) }
277285
</chakra.div>
278286
);
279287
};

ui/block/useKDABlockRewards.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import BigNumber from 'bignumber.js';
2+
import { useRouter } from 'next/router';
23
import { useMemo } from 'react';
34

45
import useApiQuery from 'lib/api/useApiQuery';
6+
import getBlockReward from 'lib/block/getBlockReward';
7+
import getQueryParamString from 'lib/router/getQueryParamString';
58
import { WEI, ZERO } from 'toolkit/utils/consts';
69

7-
import getBlockReward from '../../lib/block/getBlockReward';
810
import type { BlockQuery } from './useBlockQuery';
911

1012
export type TKDABlockRewardsData = {
@@ -24,42 +26,48 @@ export type TKDABlockRewardsData = {
2426
burntFees: BigNumber;
2527
hasRewardBaseFee: boolean;
2628
hasTxFees: boolean;
29+
hasPriorityFee: boolean;
2730
hasBurntFees: boolean;
2831
} | null;
2932
formattedValues: {
3033
rewardAmount?: string;
3134
rewardBaseFee?: string;
3235
txFees?: string;
36+
priorityFee?: string;
3337
burntFees?: string;
3438
};
3539
};
3640

3741
export const useKDABlockRewardsData = (query: BlockQuery): TKDABlockRewardsData => {
42+
const router = useRouter();
3843
const { data, isLoading: queryIsLoading } = query;
44+
const heightOrHash = getQueryParamString(router.query.height_or_hash ?? data?.height.toString() ?? data?.hash ?? '');
3945
const { data: withdrawalsData, isLoading: withdrawalsIsLoading } = useApiQuery('general:block_withdrawals', {
40-
queryParams: { height_or_hash: `${ data?.height }` },
46+
queryParams: { height_or_hash: heightOrHash },
4147
});
42-
const { totalReward, burntFees, txFees } = data ? getBlockReward(data) : { totalReward: ZERO, burntFees: ZERO, txFees: ZERO };
48+
const { totalReward, burntFees, txFees, priorityFee } = data ? getBlockReward(data) : { totalReward: ZERO, burntFees: ZERO, txFees: ZERO, priorityFee: ZERO };
4349

4450
const calculatedValues = useMemo(() => {
4551
if (!withdrawalsData?.items?.length) {
4652
return null;
4753
}
4854

4955
const [ reward ] = withdrawalsData.items;
50-
const rewardAmount = BigNumber(reward.amount ?? 0);
56+
const rewardAmount = BigNumber((reward.amount ?? 0)).plus(priorityFee.toNumber());
5157
const rewardBaseFee = BigNumber(rewardAmount.toNumber() - totalReward.toNumber() + burntFees.toNumber());
5258

5359
return {
5460
rewardAmount: rewardAmount.dividedBy(WEI),
5561
rewardBaseFee: rewardBaseFee.dividedBy(WEI),
5662
txFees: txFees.dividedBy(WEI),
63+
priorityFee: priorityFee.dividedBy(WEI),
5764
burntFees: burntFees.dividedBy(WEI),
5865
hasRewardBaseFee: !rewardBaseFee.isEqualTo(ZERO),
5966
hasTxFees: !txFees.isEqualTo(ZERO),
67+
hasPriorityFee: !priorityFee.isEqualTo(ZERO),
6068
hasBurntFees: !burntFees.isEqualTo(ZERO),
6169
};
62-
}, [ withdrawalsData, totalReward, burntFees, txFees ]);
70+
}, [ withdrawalsData, totalReward, burntFees, txFees, priorityFee ]);
6371

6472
return {
6573
isLoading: withdrawalsIsLoading || queryIsLoading,
@@ -76,6 +84,7 @@ export const useKDABlockRewardsData = (query: BlockQuery): TKDABlockRewardsData
7684
rewardAmount: calculatedValues?.rewardAmount ? BigNumber(calculatedValues.rewardAmount).toFixed() : undefined,
7785
rewardBaseFee: calculatedValues?.rewardBaseFee ? BigNumber(calculatedValues.rewardBaseFee).toFixed() : undefined,
7886
txFees: calculatedValues?.txFees ? BigNumber(calculatedValues.txFees).toFixed() : undefined,
87+
priorityFee: calculatedValues?.priorityFee ? BigNumber(calculatedValues.priorityFee).toFixed() : undefined,
7988
burntFees: calculatedValues?.burntFees ? BigNumber(calculatedValues.burntFees).toFixed() : undefined,
8089
},
8190
};

0 commit comments

Comments
 (0)