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

Commit 0aca1df

Browse files
authored
Block reward table fix (#22)
1 parent 79c9045 commit 0aca1df

File tree

15 files changed

+160
-131
lines changed

15 files changed

+160
-131
lines changed

.env.example.kadena

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=123456
5252
NEXT_PUBLIC_NETWORK_RPC_URL=https://evm-testnet.chainweb.com/chainweb/0.0/evm-testnet/${CHAINWEB_CHAIN_ID}/evm/rpc/
5353

5454
NEXT_PUBLIC_OG_IMAGE_URL=public/static/kadena_evm_og_image.png
55+
NEXT_PUBLIC_VIEWS_BLOCK_HIDDEN_FIELDS=[\"total_reward\"]

lib/getCurrencyValue.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import BigNumber from 'bignumber.js';
22

3-
import { ZERO } from 'toolkit/utils/consts';
3+
import { EXPONENT, ZERO } from 'toolkit/utils/consts';
44

55
interface Params {
66
value: string;
@@ -11,7 +11,7 @@ interface Params {
1111
}
1212

1313
export default function getCurrencyValue({ value, accuracy, accuracyUsd, decimals, exchangeRate }: Params) {
14-
const valueCurr = BigNumber(value).div(BigNumber(10 ** Number(decimals || '18')));
14+
const valueCurr = BigNumber(value).div(BigNumber(10 ** Number(decimals || EXPONENT)));
1515
const valueResult = accuracy ? valueCurr.dp(accuracy).toFormat() : valueCurr.toFormat();
1616

1717
let usdResult: string | undefined;

lib/web3/useAddChain.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import type { AddEthereumChainParameter } from 'viem';
33

44
import config from 'configs/app';
5-
import { SECOND } from 'toolkit/utils/consts';
5+
import { EXPONENT, SECOND } from 'toolkit/utils/consts';
66

77
import useRewardsActivity from '../hooks/useRewardsActivity';
88
import useProvider from './useProvider';
@@ -19,7 +19,7 @@ function getParams(): AddEthereumChainParameter {
1919
nativeCurrency: {
2020
name: config.chain.currency.name ?? '',
2121
symbol: config.chain.currency.symbol ?? '',
22-
decimals: config.chain.currency.decimals ?? 18,
22+
decimals: config.chain.currency.decimals ?? EXPONENT,
2323
},
2424
rpcUrls: config.chain.rpcUrls,
2525
blockExplorerUrls: [ config.app.baseUrl ],

mocks/epochs/celo.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { padStart } from 'es-toolkit/compat';
22

33
import type { CeloEpochDetails, CeloEpochElectionRewardDetails, CeloEpochElectionRewardDetailsResponse, CeloEpochListResponse } from 'types/api/epochs';
44

5+
import { EXPONENT } from 'toolkit/utils/consts';
6+
57
import * as addressMock from '../address/address';
68
import * as tokenMock from '../tokens/tokenInfo';
79
import * as tokenTransferMock from '../tokens/tokenTransfer';
@@ -24,7 +26,7 @@ export const epoch1: CeloEpochDetails = {
2426
token: tokenMock.tokenInfoERC20a,
2527
total: {
2628
value: '1000000000000000000',
27-
decimals: '18',
29+
decimals: EXPONENT.toString(),
2830
},
2931
},
3032
},
@@ -87,15 +89,15 @@ export const list: CeloEpochListResponse = {
8789
start_block_number: 18390714,
8890
distribution: {
8991
carbon_offsetting_transfer: {
90-
decimals: '18',
92+
decimals: EXPONENT.toString(),
9193
value: '1723199576750509130678',
9294
},
9395
community_transfer: {
94-
decimals: '18',
96+
decimals: EXPONENT.toString(),
9597
value: '68927983070020365227',
9698
},
9799
transfers_total: {
98-
decimals: '18',
100+
decimals: EXPONENT.toString(),
99101
value: '1792127559820529495905',
100102
},
101103
},

mocks/noves/transaction.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { NovesResponseData } from 'types/api/noves';
22

3+
import { EXPONENT } from 'toolkit/utils/consts';
34
import type { TokensData } from 'ui/tx/assetFlows/utils/getTokensData';
45

56
export const hash = '0x380400d04ebb4179a35b1d7fdef260776915f015e978f8587ef2704b843d4e53';
@@ -28,7 +29,7 @@ export const transaction: NovesResponseData = {
2829
},
2930
token: {
3031
address: '0x1bfe4298796198f8664b18a98640cec7c89b5baa',
31-
decimals: 18,
32+
decimals: EXPONENT,
3233
name: 'PQR-Test',
3334
symbol: 'PQR',
3435
},
@@ -47,7 +48,7 @@ export const transaction: NovesResponseData = {
4748
},
4849
token: {
4950
address: 'ETH',
50-
decimals: 18,
51+
decimals: EXPONENT,
5152
name: 'ETH',
5253
symbol: 'ETH',
5354
},
@@ -69,7 +70,7 @@ export const transaction: NovesResponseData = {
6970
transactionFee: {
7071
amount: '395521502109448',
7172
token: {
72-
decimals: 18,
73+
decimals: EXPONENT,
7374
symbol: 'ETH',
7475
},
7576
},

toolkit/utils/consts.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import BigNumber from 'bignumber.js';
22

3-
export const WEI = new BigNumber(10 ** 18);
3+
export const EXPONENT = 18;
4+
export const WEI = new BigNumber(10 ** EXPONENT);
45
export const GWEI = new BigNumber(10 ** 9);
56
export const WEI_IN_GWEI = WEI.dividedBy(GWEI);
67
export const ZERO = new BigNumber(0);

ui/address/contract/methods/form/ContractMethodFieldInput.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Field } from 'toolkit/chakra/field';
1010
import { Input } from 'toolkit/chakra/input';
1111
import { InputGroup } from 'toolkit/chakra/input-group';
1212
import { ClearButton } from 'toolkit/components/buttons/ClearButton';
13-
import { HOUR, SECOND } from 'toolkit/utils/consts';
13+
import { EXPONENT, HOUR, SECOND } from 'toolkit/utils/consts';
1414

1515
import ContractMethodAddressButton from './ContractMethodAddressButton';
1616
import ContractMethodFieldLabel from './ContractMethodFieldLabel';
@@ -34,7 +34,7 @@ interface Props {
3434
const ContractMethodFieldInput = ({ data, hideLabel, path: name, className, isDisabled, isOptional: isOptionalProp, level }: Props) => {
3535
const ref = React.useRef<HTMLInputElement>(null);
3636

37-
const [ intPower, setIntPower ] = React.useState<number>(18);
37+
const [ intPower, setIntPower ] = React.useState<number>(EXPONENT);
3838

3939
const isNativeCoin = data.fieldType === 'native_coin';
4040
const isOptional = isOptionalProp || isNativeCoin;

ui/block/BlockDetails.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ const BlockDetails = ({ query }: Props) => {
345345
</>
346346
) }
347347

348-
{ !rollupFeature.isEnabled && !totalReward.isEqualTo(ZERO) && !config.UI.views.block.hiddenFields?.total_reward && (
348+
{ !rollupFeature.isEnabled && !totalReward.isEqualTo(ZERO) && (
349349
<>
350350
<DetailedInfo.ItemLabel
351351
hint={

ui/block/BlockRewards.tsx

Lines changed: 6 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import { chakra, Text } from '@chakra-ui/react';
2-
import BigNumber from 'bignumber.js';
3-
import React, { useCallback, useMemo } from 'react';
2+
import React, { useCallback } from 'react';
43

5-
import useApiQuery from 'lib/api/useApiQuery';
64
import { currencyUnits } from 'lib/units';
75
import { Skeleton } from 'toolkit/chakra/skeleton';
86
import { Tooltip } from 'toolkit/chakra/tooltip';
97
import { Hint } from 'toolkit/components/Hint/Hint';
10-
import { WEI, ZERO } from 'toolkit/utils/consts';
118
import { space } from 'toolkit/utils/htmlEntities';
129

13-
import getBlockReward from '../../lib/block/getBlockReward';
1410
import RawDataSnippet from '../shared/RawDataSnippet';
1511
import type { BlockQuery } from './useBlockQuery';
12+
import { useKDABlockRewardsData } from './useKDABlockRewards';
1613

1714
interface Props {
1815
query: BlockQuery;
@@ -21,33 +18,6 @@ interface Props {
2118
type MouseEnterLeaveHandler = (event: React.MouseEvent<HTMLDivElement>) => void;
2219
type MouseEnterLeaveLabelHandler = (event: React.MouseEvent<HTMLSpanElement>) => void;
2320

24-
type TKDABlockRewardsData = {
25-
isLoading: boolean;
26-
loading: {
27-
queryIsLoading: boolean;
28-
withdrawalsIsLoading: boolean;
29-
};
30-
data: {
31-
blockData?: BlockQuery['data'];
32-
withdrawalsData?: { items: Array<{ amount?: string }> };
33-
};
34-
calculatedValues: {
35-
rewardAmount: BigNumber;
36-
rewardBaseFee: BigNumber;
37-
txFees: BigNumber;
38-
burntFees: BigNumber;
39-
hasRewardBaseFee: boolean;
40-
hasTxFees: boolean;
41-
hasBurntFees: boolean;
42-
} | null;
43-
formattedValues: {
44-
rewardAmount?: string;
45-
rewardBaseFee?: string;
46-
txFees?: string;
47-
burntFees?: string;
48-
};
49-
};
50-
5121
interface TKDABreakdownItemProps {
5222
isLoading: boolean;
5323
onMouseEnter?: MouseEnterLeaveHandler;
@@ -116,55 +86,7 @@ const BreakdownLabel = React.forwardRef<HTMLSpanElement, BreakdownLabelProps>(({
11686

11787
BreakdownLabel.displayName = 'BreakdownLabel';
11888

119-
export const KDABlockRewardsData = (query: BlockQuery): TKDABlockRewardsData => {
120-
const { data, isLoading: queryIsLoading } = query;
121-
122-
const { data: withdrawalsData, isLoading: withdrawalsIsLoading } = useApiQuery('general:block_withdrawals', {
123-
queryParams: { height_or_hash: `${ data?.height }` },
124-
});
125-
const { totalReward, burntFees, txFees } = data ? getBlockReward(data) : { totalReward: ZERO, burntFees: ZERO, txFees: ZERO };
126-
127-
const calculatedValues = useMemo(() => {
128-
if (!withdrawalsData?.items?.length) {
129-
return null;
130-
}
131-
132-
const [ reward ] = withdrawalsData.items;
133-
const rewardAmount = BigNumber(reward.amount ?? 0);
134-
const rewardBaseFee = BigNumber(rewardAmount.toNumber() - totalReward.toNumber() + burntFees.toNumber());
135-
136-
return {
137-
rewardAmount: rewardAmount.dividedBy(WEI),
138-
rewardBaseFee: rewardBaseFee.dividedBy(WEI),
139-
txFees: txFees.dividedBy(WEI),
140-
burntFees: burntFees.dividedBy(WEI),
141-
hasRewardBaseFee: !rewardBaseFee.isEqualTo(ZERO),
142-
hasTxFees: !txFees.isEqualTo(ZERO),
143-
hasBurntFees: !burntFees.isEqualTo(ZERO),
144-
};
145-
}, [ withdrawalsData, totalReward, burntFees, txFees ]);
146-
147-
return {
148-
isLoading: withdrawalsIsLoading || queryIsLoading,
149-
loading: {
150-
queryIsLoading,
151-
withdrawalsIsLoading,
152-
},
153-
data: {
154-
blockData: data,
155-
withdrawalsData,
156-
},
157-
calculatedValues,
158-
formattedValues: {
159-
rewardAmount: calculatedValues?.rewardAmount ? BigNumber(calculatedValues.rewardAmount).toFixed() : undefined,
160-
rewardBaseFee: calculatedValues?.rewardBaseFee ? BigNumber(calculatedValues.rewardBaseFee).toFixed() : undefined,
161-
txFees: calculatedValues?.txFees ? BigNumber(calculatedValues.txFees).toFixed() : undefined,
162-
burntFees: calculatedValues?.burntFees ? BigNumber(calculatedValues.burntFees).toFixed() : undefined,
163-
},
164-
};
165-
};
166-
167-
const KDABlockRewards = ({ query /* data, txFees, burntFees, totalReward */ }: Props) => {
89+
const KDABlockRewards = ({ query }: Props) => {
16890
const blockRewardValuesRef = React.useRef<HTMLDivElement>(null);
16991
const blockRewardLabelRef = React.useRef<HTMLSpanElement>(null);
17092
const txFeesValuesRef = React.useRef<HTMLDivElement>(null);
@@ -181,7 +103,8 @@ const KDABlockRewards = ({ query /* data, txFees, burntFees, totalReward */ }: P
181103
txFees,
182104
burntFees,
183105
},
184-
} = KDABlockRewardsData(query);
106+
} = useKDABlockRewardsData(query);
107+
185108
const {
186109
hasRewardBaseFee,
187110
hasTxFees,
@@ -260,7 +183,7 @@ const KDABlockRewards = ({ query /* data, txFees, burntFees, totalReward */ }: P
260183
<Text color="text.primary" fontSize="sm" display="inline" fontFamily="var(--global-font-body, var(--font-fallback))">
261184
<chakra.span whiteSpace="nowrap">
262185
<Hint label="PoW mining reward"/>
263-
Block reward
186+
Mining reward
264187
</chakra.span>
265188
</Text>
266189
</KDABreakdownItem>

ui/block/useKDABlockRewards.tsx

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import BigNumber from 'bignumber.js';
2+
import { useMemo } from 'react';
3+
4+
import useApiQuery from 'lib/api/useApiQuery';
5+
import { WEI, ZERO } from 'toolkit/utils/consts';
6+
7+
import getBlockReward from '../../lib/block/getBlockReward';
8+
import type { BlockQuery } from './useBlockQuery';
9+
10+
export type TKDABlockRewardsData = {
11+
isLoading: boolean;
12+
loading: {
13+
queryIsLoading: boolean;
14+
withdrawalsIsLoading: boolean;
15+
};
16+
data: {
17+
blockData?: BlockQuery['data'];
18+
withdrawalsData?: { items: Array<{ amount?: string }> };
19+
} | null;
20+
calculatedValues: {
21+
rewardAmount: BigNumber;
22+
rewardBaseFee: BigNumber;
23+
txFees: BigNumber;
24+
burntFees: BigNumber;
25+
hasRewardBaseFee: boolean;
26+
hasTxFees: boolean;
27+
hasBurntFees: boolean;
28+
} | null;
29+
formattedValues: {
30+
rewardAmount?: string;
31+
rewardBaseFee?: string;
32+
txFees?: string;
33+
burntFees?: string;
34+
};
35+
};
36+
37+
export const useKDABlockRewardsData = (query: BlockQuery): TKDABlockRewardsData => {
38+
const { data, isLoading: queryIsLoading } = query;
39+
const { data: withdrawalsData, isLoading: withdrawalsIsLoading } = useApiQuery('general:block_withdrawals', {
40+
queryParams: { height_or_hash: `${ data?.height }` },
41+
});
42+
const { totalReward, burntFees, txFees } = data ? getBlockReward(data) : { totalReward: ZERO, burntFees: ZERO, txFees: ZERO };
43+
44+
const calculatedValues = useMemo(() => {
45+
if (!withdrawalsData?.items?.length) {
46+
return null;
47+
}
48+
49+
const [ reward ] = withdrawalsData.items;
50+
const rewardAmount = BigNumber(reward.amount ?? 0);
51+
const rewardBaseFee = BigNumber(rewardAmount.toNumber() - totalReward.toNumber() + burntFees.toNumber());
52+
53+
return {
54+
rewardAmount: rewardAmount.dividedBy(WEI),
55+
rewardBaseFee: rewardBaseFee.dividedBy(WEI),
56+
txFees: txFees.dividedBy(WEI),
57+
burntFees: burntFees.dividedBy(WEI),
58+
hasRewardBaseFee: !rewardBaseFee.isEqualTo(ZERO),
59+
hasTxFees: !txFees.isEqualTo(ZERO),
60+
hasBurntFees: !burntFees.isEqualTo(ZERO),
61+
};
62+
}, [ withdrawalsData, totalReward, burntFees, txFees ]);
63+
64+
return {
65+
isLoading: withdrawalsIsLoading || queryIsLoading,
66+
loading: {
67+
queryIsLoading,
68+
withdrawalsIsLoading,
69+
},
70+
data: {
71+
blockData: data,
72+
withdrawalsData,
73+
},
74+
calculatedValues,
75+
formattedValues: {
76+
rewardAmount: calculatedValues?.rewardAmount ? BigNumber(calculatedValues.rewardAmount).toFixed() : undefined,
77+
rewardBaseFee: calculatedValues?.rewardBaseFee ? BigNumber(calculatedValues.rewardBaseFee).toFixed() : undefined,
78+
txFees: calculatedValues?.txFees ? BigNumber(calculatedValues.txFees).toFixed() : undefined,
79+
burntFees: calculatedValues?.burntFees ? BigNumber(calculatedValues.burntFees).toFixed() : undefined,
80+
},
81+
};
82+
};

0 commit comments

Comments
 (0)