@@ -3,15 +3,16 @@ import styled from "styled-components";
33import { formatUnits , formatEther } from "viem" ;
44import { useParams } from "react-router-dom" ;
55import { useCourtDetails , CourtDetailsQuery } from "queries/useCourtDetails" ;
6+ import { useCoinPrice } from "hooks/useCoinPrice" ;
67import StatDisplay , { IStatDisplay } from "components/StatDisplay" ;
7- import JurorIcon from "svgs/icons/user.svg" ;
88import BalanceIcon from "svgs/icons/law-balance.svg" ;
99import MinStake from "svgs/icons/min-stake.svg" ;
1010import { commify } from "utils/commify" ;
1111import VoteStake from "svgs/icons/vote-stake.svg" ;
1212import PNKIcon from "svgs/icons/pnk.svg" ;
1313import PNKRedistributedIcon from "svgs/icons/redistributed-pnk.svg" ;
1414import EthereumIcon from "svgs/icons/ethereum.svg" ;
15+ import { isUndefined } from "~src/utils" ;
1516
1617const StyledCard = styled . div `
1718 width: auto;
@@ -25,24 +26,29 @@ const StyledCard = styled.div`
2526
2627interface IStat {
2728 title : string ;
29+ coinId ?: number ;
2830 getText : ( data : CourtDetailsQuery [ "court" ] ) => string ;
29- getSubtext : ( data : CourtDetailsQuery [ "court" ] ) => string ;
31+ getSubtext : ( data : CourtDetailsQuery [ "court" ] , coinPrice ?: number ) => string ;
3032 color : IStatDisplay [ "color" ] ;
3133 icon : React . FC < React . SVGAttributes < SVGElement > > ;
3234}
3335
3436const stats : IStat [ ] = [
3537 {
3638 title : "Min Stake" ,
39+ coinId : 0 ,
3740 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 ( ) + "$" ,
3943 color : "purple" ,
4044 icon : MinStake ,
4145 } ,
4246 {
4347 title : "Vote Stake" ,
48+ coinId : 0 ,
4449 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 ( ) + "$" ,
4652 color : "purple" ,
4753 icon : VoteStake ,
4854 } ,
@@ -55,8 +61,10 @@ const stats: IStat[] = [
5561 } ,
5662 {
5763 title : "PNK Staked" ,
64+ coinId : 0 ,
5865 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 ( ) + "$" ,
6068 color : "purple" ,
6169 icon : PNKIcon ,
6270 } ,
@@ -76,15 +84,19 @@ const stats: IStat[] = [
7684 } ,
7785 {
7886 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 ( ) + "$" ,
8191 color : "blue" ,
8292 icon : EthereumIcon ,
8393 } ,
8494 {
8595 title : "PNK redistributed" ,
96+ coinId : 0 ,
8697 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 ( ) + "$" ,
88100 color : "purple" ,
89101 icon : PNKRedistributedIcon ,
90102 } ,
@@ -93,16 +105,20 @@ const stats: IStat[] = [
93105const Stats = ( ) => {
94106 const { id } = useParams ( ) ;
95107 const { data } = useCourtDetails ( id ) ;
108+ const { prices } = useCoinPrice ( [ "kleros" , "ethereum" ] ) ;
96109 return (
97110 < 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+ } ) }
106122 </ StyledCard >
107123 ) ;
108124} ;
0 commit comments