Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
925f7fdd
Commit
925f7fdd
authored
Oct 11, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
migrate block details to big-number-js
parent
5421b86e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
31 deletions
+36
-31
getBlockReward.ts
lib/block/getBlockReward.ts
+6
-11
consts.ts
lib/consts.ts
+1
-0
BlockDetails.tsx
ui/block/BlockDetails.tsx
+29
-20
No files found.
lib/block/getBlockReward.ts
View file @
925f7fdd
import
{
utils
}
from
'
ether
s
'
;
import
BigNumber
from
'
bignumber.j
s
'
;
import
type
{
Block
}
from
'
types/api/block
'
;
import
type
{
Block
}
from
'
types/api/block
'
;
export
default
function
getBlockReward
(
block
:
Block
)
{
export
default
function
getBlockReward
(
block
:
Block
)
{
const
txFees
=
utils
.
parseUnits
(
block
.
tx_fees
||
'
0
'
,
'
wei
'
);
const
txFees
=
BigNumber
(
block
.
tx_fees
||
0
);
const
burntFees
=
utils
.
parseUnits
(
String
(
block
.
burnt_fees
||
'
0
'
),
'
wei
'
);
const
burntFees
=
BigNumber
(
block
.
burnt_fees
||
0
);
const
totalReward
=
utils
.
parseUnits
(
const
minerReward
=
block
.
rewards
?.
find
(({
type
})
=>
type
===
'
Miner Reward
'
||
type
===
'
Validator Reward
'
)?.
reward
;
String
(
const
totalReward
=
BigNumber
(
minerReward
||
0
);
block
.
rewards
?.
find
(({
type
})
=>
type
===
'
Miner Reward
'
||
type
===
'
Validator Reward
'
)?.
reward
||
const
staticReward
=
totalReward
.
minus
(
txFees
).
plus
(
burntFees
);
'
0
'
,
),
'
wei
'
,
);
const
staticReward
=
totalReward
.
sub
(
txFees
).
add
(
burntFees
);
return
{
return
{
totalReward
,
totalReward
,
...
...
lib/consts.ts
View file @
925f7fdd
...
@@ -3,3 +3,4 @@ import BigNumber from 'bignumber.js';
...
@@ -3,3 +3,4 @@ import BigNumber from 'bignumber.js';
export
const
WEI
=
new
BigNumber
(
10
**
18
);
export
const
WEI
=
new
BigNumber
(
10
**
18
);
export
const
GWEI
=
new
BigNumber
(
10
**
9
);
export
const
GWEI
=
new
BigNumber
(
10
**
9
);
export
const
WEI_IN_GWEI
=
WEI
.
dividedBy
(
GWEI
);
export
const
WEI_IN_GWEI
=
WEI
.
dividedBy
(
GWEI
);
export
const
ZERO
=
new
BigNumber
(
0
);
ui/block/BlockDetails.tsx
View file @
925f7fdd
import
{
Grid
,
GridItem
,
Text
,
Icon
,
Link
,
Box
,
Tooltip
,
Alert
}
from
'
@chakra-ui/react
'
;
import
{
Grid
,
GridItem
,
Text
,
Icon
,
Link
,
Box
,
Tooltip
,
Alert
}
from
'
@chakra-ui/react
'
;
import
{
useQuery
}
from
'
@tanstack/react-query
'
;
import
{
useQuery
}
from
'
@tanstack/react-query
'
;
import
{
utils
,
constants
}
from
'
ether
s
'
;
import
BigNumber
from
'
bignumber.j
s
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
{
scroller
,
Element
}
from
'
react-scroll
'
;
import
{
scroller
,
Element
}
from
'
react-scroll
'
;
...
@@ -10,6 +10,7 @@ import type { Block } from 'types/api/block';
...
@@ -10,6 +10,7 @@ import type { Block } from 'types/api/block';
import
clockIcon
from
'
icons/clock.svg
'
;
import
clockIcon
from
'
icons/clock.svg
'
;
import
flameIcon
from
'
icons/flame.svg
'
;
import
flameIcon
from
'
icons/flame.svg
'
;
import
getBlockReward
from
'
lib/block/getBlockReward
'
;
import
getBlockReward
from
'
lib/block/getBlockReward
'
;
import
{
WEI
,
WEI_IN_GWEI
,
ZERO
}
from
'
lib/consts
'
;
import
dayjs
from
'
lib/date/dayjs
'
;
import
dayjs
from
'
lib/date/dayjs
'
;
import
type
{
ErrorType
}
from
'
lib/hooks/useFetch
'
;
import
type
{
ErrorType
}
from
'
lib/hooks/useFetch
'
;
import
useFetch
from
'
lib/hooks/useFetch
'
;
import
useFetch
from
'
lib/hooks/useFetch
'
;
...
@@ -119,7 +120,7 @@ const BlockDetails = () => {
...
@@ -119,7 +120,7 @@ const BlockDetails = () => {
{
/* api doesn't return the block processing time yet */
}
{
/* api doesn't return the block processing time yet */
}
{
/* <Text>{ dayjs.duration(block.minedIn, 'second').humanize(true) }</Text> */
}
{
/* <Text>{ dayjs.duration(block.minedIn, 'second').humanize(true) }</Text> */
}
</
DetailsInfoItem
>
</
DetailsInfoItem
>
{
!
totalReward
.
eq
(
constants
.
Zero
)
&&
(
{
!
totalReward
.
isEqualTo
(
ZERO
)
&&
(
<
DetailsInfoItem
<
DetailsInfoItem
title=
"Block reward"
title=
"Block reward"
hint=
{
hint=
{
...
@@ -128,25 +129,25 @@ const BlockDetails = () => {
...
@@ -128,25 +129,25 @@ const BlockDetails = () => {
}
}
columnGap=
{
1
}
columnGap=
{
1
}
>
>
<
Text
>
{
utils
.
formatUnits
(
totalReward
)
}
{
network
?.
currency
}
</
Text
>
<
Text
>
{
totalReward
.
dividedBy
(
WEI
).
toFixed
(
)
}
{
network
?.
currency
}
</
Text
>
{
(
!
txFees
.
eq
(
constants
.
Zero
)
||
!
burntFees
.
eq
(
constants
.
Zero
))
&&
(
{
(
!
txFees
.
isEqualTo
(
ZERO
)
||
!
burntFees
.
isEqualTo
(
ZERO
))
&&
(
<
Text
variant=
"secondary"
whiteSpace=
"break-spaces"
>
(
<
Text
variant=
"secondary"
whiteSpace=
"break-spaces"
>
(
<
Tooltip
label=
"Static block reward"
>
<
Tooltip
label=
"Static block reward"
>
<
span
>
{
utils
.
formatUnits
(
staticReward
)
}
</
span
>
<
span
>
{
staticReward
.
dividedBy
(
WEI
).
toFixed
(
)
}
</
span
>
</
Tooltip
>
</
Tooltip
>
{
!
txFees
.
eq
(
constants
.
Zero
)
&&
(
{
!
txFees
.
isEqualTo
(
ZERO
)
&&
(
<>
<>
{
space
}
+
{
space
}
{
space
}
+
{
space
}
<
Tooltip
label=
"Txn fees"
>
<
Tooltip
label=
"Txn fees"
>
<
span
>
{
utils
.
formatUnits
(
txFees
)
}
</
span
>
<
span
>
{
txFees
.
dividedBy
(
WEI
).
toFixed
(
)
}
</
span
>
</
Tooltip
>
</
Tooltip
>
</>
</>
)
}
)
}
{
!
burntFees
.
eq
(
constants
.
Zero
)
&&
(
{
!
burntFees
.
isEqualTo
(
ZERO
)
&&
(
<>
<>
{
space
}
-
{
space
}
{
space
}
-
{
space
}
<
Tooltip
label=
"Burnt fees"
>
<
Tooltip
label=
"Burnt fees"
>
<
span
>
{
utils
.
formatUnits
(
burntFees
)
}
</
span
>
<
span
>
{
burntFees
.
dividedBy
(
WEI
).
toFixed
(
)
}
</
span
>
</
Tooltip
>
</
Tooltip
>
</>
</>
)
}
)
}
...
@@ -161,12 +162,12 @@ const BlockDetails = () => {
...
@@ -161,12 +162,12 @@ const BlockDetails = () => {
title=
"Gas used"
title=
"Gas used"
hint=
"The total gas amount used in the block and its percentage of gas filled in the block."
hint=
"The total gas amount used in the block and its percentage of gas filled in the block."
>
>
<
Text
>
{
utils
.
commify
(
data
.
gas_used
)
}
</
Text
>
<
Text
>
{
BigNumber
(
data
.
gas_used
).
toFormat
(
)
}
</
Text
>
<
Utilization
<
Utilization
ml=
{
4
}
ml=
{
4
}
mr=
{
5
}
mr=
{
5
}
colorScheme=
"gray"
colorScheme=
"gray"
value=
{
utils
.
parseUnits
(
data
.
gas_used
).
mul
(
10
_000
).
div
(
utils
.
parseUnits
(
data
.
gas_limit
)).
toNumber
()
/
10
_000
}
value=
{
BigNumber
(
data
.
gas_used
).
dividedBy
(
BigNumber
(
data
.
gas_limit
)).
toNumber
()
}
/>
/>
<
GasUsedToTargetRatio
value=
{
data
.
gas_target_percentage
||
undefined
}
/>
<
GasUsedToTargetRatio
value=
{
data
.
gas_target_percentage
||
undefined
}
/>
</
DetailsInfoItem
>
</
DetailsInfoItem
>
...
@@ -174,16 +175,16 @@ const BlockDetails = () => {
...
@@ -174,16 +175,16 @@ const BlockDetails = () => {
title=
"Gas limit"
title=
"Gas limit"
hint=
"Total gas limit provided by all transactions in the block."
hint=
"Total gas limit provided by all transactions in the block."
>
>
<
Text
>
{
utils
.
commify
(
data
.
gas_limit
)
}
</
Text
>
<
Text
>
{
BigNumber
(
data
.
gas_limit
).
toFormat
(
)
}
</
Text
>
</
DetailsInfoItem
>
</
DetailsInfoItem
>
{
data
.
base_fee_per_gas
&&
(
{
data
.
base_fee_per_gas
&&
(
<
DetailsInfoItem
<
DetailsInfoItem
title=
"Base fee per gas"
title=
"Base fee per gas"
hint=
"Minimum fee required per unit of gas. Fee adjusts based on network congestion."
hint=
"Minimum fee required per unit of gas. Fee adjusts based on network congestion."
>
>
<
Text
>
{
utils
.
formatUnits
(
utils
.
parseUnits
(
String
(
data
.
base_fee_per_gas
),
'
wei
'
)
)
}
{
network
?.
currency
}
</
Text
>
<
Text
>
{
BigNumber
(
data
.
base_fee_per_gas
).
dividedBy
(
WEI
).
toFixed
(
)
}
{
network
?.
currency
}
</
Text
>
<
Text
variant=
"secondary"
whiteSpace=
"pre"
>
<
Text
variant=
"secondary"
whiteSpace=
"pre"
>
{
space
}
(
{
utils
.
formatUnits
(
utils
.
parseUnits
(
String
(
data
.
base_fee_per_gas
),
'
wei
'
),
'
gwei
'
)
}
Gwei)
{
space
}
(
{
BigNumber
(
data
.
base_fee_per_gas
).
dividedBy
(
WEI_IN_GWEI
).
toFixed
(
)
}
Gwei)
</
Text
>
</
Text
>
</
DetailsInfoItem
>
</
DetailsInfoItem
>
)
}
)
}
...
@@ -195,18 +196,26 @@ const BlockDetails = () => {
...
@@ -195,18 +196,26 @@ const BlockDetails = () => {
}
}
>
>
<
Icon
as=
{
flameIcon
}
boxSize=
{
5
}
color=
"gray.500"
/>
<
Icon
as=
{
flameIcon
}
boxSize=
{
5
}
color=
"gray.500"
/>
<
Text
ml=
{
1
}
>
{
utils
.
formatUnits
(
burntFees
)
}
{
network
?.
currency
}
</
Text
>
<
Text
ml=
{
1
}
>
{
burntFees
.
dividedBy
(
WEI
).
toFixed
(
)
}
{
network
?.
currency
}
</
Text
>
{
!
txFees
.
eq
(
constants
.
Zero
)
&&
(
{
!
txFees
.
isEqualTo
(
ZERO
)
&&
(
<
Tooltip
label=
"Burnt fees / Txn fees * 100%"
>
<
Tooltip
label=
"Burnt fees / Txn fees * 100%"
>
<
Box
>
<
Box
>
<
Utilization
<
Utilization
ml=
{
4
}
ml=
{
4
}
value=
{
burntFees
.
mul
(
10
_000
).
div
(
txFees
).
toNumber
()
/
10
_000
}
value=
{
burntFees
.
dividedBy
(
txFees
).
toNumber
()
}
/>
/>
</
Box
>
</
Box
>
</
Tooltip
>
</
Tooltip
>
)
}
)
}
</
DetailsInfoItem
>
</
DetailsInfoItem
>
{
data
.
priority_fee
&&
(
<
DetailsInfoItem
title=
"Priority fee / Tip"
hint=
"User-defined tips sent to validator for transaction priority/inclusion."
>
{
BigNumber
(
data
.
priority_fee
).
dividedBy
(
WEI
).
toFixed
()
}
{
network
?.
currency
}
</
DetailsInfoItem
>
)
}
{
/* api doesn't support extra data yet */
}
{
/* api doesn't support extra data yet */
}
{
/* <DetailsInfoItem
{
/* <DetailsInfoItem
title="Extra data"
title="Extra data"
...
@@ -241,13 +250,13 @@ const BlockDetails = () => {
...
@@ -241,13 +250,13 @@ const BlockDetails = () => {
title=
"Difficulty"
title=
"Difficulty"
hint=
"Block difficulty for miner, used to calibrate block generation time."
hint=
"Block difficulty for miner, used to calibrate block generation time."
>
>
{
utils
.
commify
(
data
.
difficulty
)
}
{
BigNumber
(
data
.
difficulty
).
toFormat
(
)
}
</
DetailsInfoItem
>
</
DetailsInfoItem
>
<
DetailsInfoItem
<
DetailsInfoItem
title=
"Total difficulty"
title=
"Total difficulty"
hint=
"Total difficulty of the chain until this block."
hint=
"Total difficulty of the chain until this block."
>
>
{
utils
.
commify
(
data
.
total_difficulty
)
}
{
BigNumber
(
data
.
total_difficulty
).
toFormat
(
)
}
</
DetailsInfoItem
>
</
DetailsInfoItem
>
{
sectionGap
}
{
sectionGap
}
...
@@ -293,7 +302,7 @@ const BlockDetails = () => {
...
@@ -293,7 +302,7 @@ const BlockDetails = () => {
title=
{
type
}
title=
{
type
}
hint=
"Amount of distributed reward. Miners receive a static block reward + Tx fees + uncle fees."
hint=
"Amount of distributed reward. Miners receive a static block reward + Tx fees + uncle fees."
>
>
{
utils
.
formatUnits
(
utils
.
parseUnits
(
String
(
reward
),
'
wei
'
)
)
}
{
network
?.
currency
}
{
BigNumber
(
reward
).
dividedBy
(
WEI
).
toFixed
(
)
}
{
network
?.
currency
}
</
DetailsInfoItem
>
</
DetailsInfoItem
>
))
}
))
}
</>
</>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment