1
1
import React from "react" ;
2
2
import styled from "styled-components" ;
3
3
import { useAccount } from "wagmi" ;
4
- import { formatEther } from "viem" ;
4
+ import { formatUnits } from "viem" ;
5
5
import { Card as _Card , Breadcrumb } from "@kleros/ui-components-library" ;
6
6
import WithHelpTooltip from "../WithHelpTooltip" ;
7
7
import { isUndefined } from "utils/index" ;
@@ -33,8 +33,6 @@ const tooltipMsg =
33
33
"The locked stake of incoherent jurors is redistributed as incentives for " +
34
34
"the coherent jurors." ;
35
35
36
- export const format = ( value : bigint | undefined ) : string => ( value !== undefined ? formatEther ( value ) : "0" ) ;
37
-
38
36
interface ICourtCard {
39
37
id : string ;
40
38
name : string ;
@@ -44,31 +42,30 @@ const CourtCard: React.FC<ICourtCard> = ({ id, name }) => {
44
42
const { address } = useAccount ( ) ;
45
43
const { data : jurorBalance } = useKlerosCoreGetJurorBalance ( {
46
44
enabled : ! isUndefined ( address ) ,
47
- args : [ address , id ] ,
45
+ args : [ address ! , BigInt ( id ) ] ,
48
46
watch : true ,
49
47
} ) ;
50
48
51
- const stake = format ( jurorBalance ?. [ 0 ] ) ;
52
- const lockedStake = format ( jurorBalance ?. [ 1 ] ) ;
49
+ const stake = jurorBalance ?. [ 0 ] ?? BigInt ( 0 ) ;
50
+ const lockedStake = jurorBalance ?. [ 1 ] ?? BigInt ( 0 ) ;
51
+ const formatedStake = formatUnits ( stake , 18 ) ;
52
+ const formatedLockedStake = formatUnits ( lockedStake , 18 ) ;
53
53
54
- return (
55
- stake !== "0" ||
56
- ( lockedStake !== "0" && (
57
- < Card >
58
- < StyledBreadcrumb items = { [ { text : name , value : 0 } ] } />
59
- < ValueContainer >
60
- < label > Stake: </ label >
61
- < small > { `${ stake } PNK` } </ small >
62
- </ ValueContainer >
63
- < ValueContainer >
64
- < WithHelpTooltip { ...{ place : "bottom" , tooltipMsg } } >
65
- < label > Locked Stake: </ label >
66
- </ WithHelpTooltip >
67
- < small > { `${ lockedStake } PNK` } </ small >
68
- </ ValueContainer >
69
- </ Card >
70
- ) )
71
- ) ;
54
+ return stake > 0 || lockedStake > 0 ? (
55
+ < Card >
56
+ < StyledBreadcrumb items = { [ { text : name , value : 0 } ] } />
57
+ < ValueContainer >
58
+ < label > Stake: </ label >
59
+ < small > { `${ formatedStake } PNK` } </ small >
60
+ </ ValueContainer >
61
+ < ValueContainer >
62
+ < WithHelpTooltip { ...{ place : "bottom" , tooltipMsg } } >
63
+ < label > Locked Stake: </ label >
64
+ </ WithHelpTooltip >
65
+ < small > { `${ formatedLockedStake } PNK` } </ small >
66
+ </ ValueContainer >
67
+ </ Card >
68
+ ) : null ;
72
69
} ;
73
70
74
71
export default CourtCard ;
0 commit comments