@@ -3,15 +3,16 @@ import styled from "styled-components";
3
3
import { formatUnits , formatEther } from "viem" ;
4
4
import { useParams } from "react-router-dom" ;
5
5
import { useCourtDetails , CourtDetailsQuery } from "queries/useCourtDetails" ;
6
+ import { useCoinPrice } from "hooks/useCoinPrice" ;
6
7
import StatDisplay , { IStatDisplay } from "components/StatDisplay" ;
7
- import JurorIcon from "svgs/icons/user.svg" ;
8
8
import BalanceIcon from "svgs/icons/law-balance.svg" ;
9
9
import MinStake from "svgs/icons/min-stake.svg" ;
10
10
import { commify } from "utils/commify" ;
11
11
import VoteStake from "svgs/icons/vote-stake.svg" ;
12
12
import PNKIcon from "svgs/icons/pnk.svg" ;
13
13
import PNKRedistributedIcon from "svgs/icons/redistributed-pnk.svg" ;
14
14
import EthereumIcon from "svgs/icons/ethereum.svg" ;
15
+ import { isUndefined } from "~src/utils" ;
15
16
16
17
const StyledCard = styled . div `
17
18
width: auto;
@@ -25,24 +26,29 @@ const StyledCard = styled.div`
25
26
26
27
interface IStat {
27
28
title : string ;
29
+ coinId ?: number ;
28
30
getText : ( data : CourtDetailsQuery [ "court" ] ) => string ;
29
- getSubtext : ( data : CourtDetailsQuery [ "court" ] ) => string ;
31
+ getSubtext : ( data : CourtDetailsQuery [ "court" ] , coinPrice ?: number ) => string ;
30
32
color : IStatDisplay [ "color" ] ;
31
33
icon : React . FC < React . SVGAttributes < SVGElement > > ;
32
34
}
33
35
34
36
const stats : IStat [ ] = [
35
37
{
36
38
title : "Min Stake" ,
39
+ coinId : 0 ,
37
40
getText : ( data ) => commify ( formatUnits ( data ?. minStake , 18 ) ) ,
38
- getSubtext : ( data ) => ( parseInt ( formatUnits ( data ?. minStake , 18 ) ) * 0.029 ) . toFixed ( 2 ) . toString ( ) + "$" ,
41
+ getSubtext : ( data , coinPrice ) =>
42
+ ( parseInt ( formatUnits ( data ?. minStake , 18 ) ) * ( coinPrice ?? 0 ) ) . toFixed ( 2 ) . toString ( ) + "$" ,
39
43
color : "purple" ,
40
44
icon : MinStake ,
41
45
} ,
42
46
{
43
47
title : "Vote Stake" ,
48
+ coinId : 0 ,
44
49
getText : ( data ) => commify ( formatUnits ( data ?. minStake , 18 ) ) ,
45
- getSubtext : ( data ) => ( parseInt ( formatUnits ( data ?. minStake , 18 ) ) * 0.029 ) . toFixed ( 2 ) . toString ( ) + "$" ,
50
+ getSubtext : ( data , coinPrice ) =>
51
+ ( parseInt ( formatUnits ( data ?. minStake , 18 ) ) * ( coinPrice ?? 0 ) ) . toFixed ( 2 ) . toString ( ) + "$" ,
46
52
color : "purple" ,
47
53
icon : VoteStake ,
48
54
} ,
@@ -55,8 +61,10 @@ const stats: IStat[] = [
55
61
} ,
56
62
{
57
63
title : "PNK Staked" ,
64
+ coinId : 0 ,
58
65
getText : ( data ) => commify ( formatUnits ( data ?. stake , 18 ) ) ,
59
- getSubtext : ( data ) => ( parseInt ( formatUnits ( data ?. stake , 18 ) ) * 0.029 ) . toFixed ( 2 ) . toString ( ) + "$" ,
66
+ getSubtext : ( data , coinPrice ) =>
67
+ ( parseInt ( formatUnits ( data ?. stake , 18 ) ) * ( coinPrice ?? 0 ) ) . toFixed ( 2 ) . toString ( ) + "$" ,
60
68
color : "purple" ,
61
69
icon : PNKIcon ,
62
70
} ,
@@ -76,15 +84,19 @@ const stats: IStat[] = [
76
84
} ,
77
85
{
78
86
title : "ETH paid to Jurors" ,
79
- getText : ( data ) => commify ( formatEther ( data ?. paidETH ) ) ,
80
- getSubtext : ( data ) => ( parseInt ( formatUnits ( data ?. paidETH , 18 ) ) * 1600 ) . toFixed ( 2 ) . toString ( ) + "$" ,
87
+ coinId : 1 ,
88
+ getText : ( data ) => commify ( formatEther ( BigInt ( data ?. paidETH ) ) ) ,
89
+ getSubtext : ( data , coinPrice ) =>
90
+ ( Number ( formatUnits ( data ?. paidETH , 18 ) ) * ( coinPrice ?? 0 ) ) . toFixed ( 2 ) . toString ( ) + "$" ,
81
91
color : "blue" ,
82
92
icon : EthereumIcon ,
83
93
} ,
84
94
{
85
95
title : "PNK redistributed" ,
96
+ coinId : 0 ,
86
97
getText : ( data ) => commify ( formatUnits ( data ?. paidPNK , 18 ) ) ,
87
- getSubtext : ( data ) => ( parseInt ( formatUnits ( data ?. paidPNK , 18 ) ) * 0.029 ) . toFixed ( 2 ) . toString ( ) + "$" ,
98
+ getSubtext : ( data , coinPrice ) =>
99
+ ( parseInt ( formatUnits ( data ?. paidPNK , 18 ) ) * ( coinPrice ?? 0 ) ) . toFixed ( 2 ) . toString ( ) + "$" ,
88
100
color : "purple" ,
89
101
icon : PNKRedistributedIcon ,
90
102
} ,
@@ -93,16 +105,20 @@ const stats: IStat[] = [
93
105
const Stats = ( ) => {
94
106
const { id } = useParams ( ) ;
95
107
const { data } = useCourtDetails ( id ) ;
108
+ const { prices } = useCoinPrice ( [ "kleros" , "ethereum" ] ) ;
96
109
return (
97
110
< StyledCard >
98
- { stats . map ( ( { title, getText, getSubtext, color, icon } , i ) => (
99
- < StatDisplay
100
- key = { i }
101
- { ...{ title, color, icon } }
102
- text = { data ? getText ( data . court ) : "Fetching..." }
103
- subtext = { data ? getSubtext ( data . court ) : "Fetching..." }
104
- />
105
- ) ) }
111
+ { stats . map ( ( { title, coinId, getText, getSubtext, color, icon } , i ) => {
112
+ const coinPrice = prices && ! isUndefined ( coinId ) ? prices [ coinId ] : undefined ;
113
+ return (
114
+ < StatDisplay
115
+ key = { i }
116
+ { ...{ title, color, icon } }
117
+ text = { data ? getText ( data . court ) : "Fetching..." }
118
+ subtext = { data ? getSubtext ( data . court , coinPrice ) : "Fetching..." }
119
+ />
120
+ ) ;
121
+ } ) }
106
122
</ StyledCard >
107
123
) ;
108
124
} ;
0 commit comments