@@ -8,26 +8,82 @@ import {
88 CommandItem ,
99 CommandList ,
1010} from "@/components/ui/command" ;
11- import { truncateEthereumAddress } from "@/lib/utils" ;
12- import { UserCircle2 } from "lucide-react" ;
1311import { useState } from "react" ;
1412import { FormattedUnits } from "../formatted-units" ;
1513import { HypercertState } from "@/hypercerts/fragments/hypercert-state.fragment" ;
16-
14+ import { getAddress , isAddress } from "viem" ;
15+ import { useGetUser } from "@/users/hooks" ;
16+ import { Skeleton } from "../ui/skeleton" ;
17+ import { UserIcon } from "../user-icon" ;
18+ import { ImageIcon } from "../user-icon/ImageIcon" ;
19+ import { SvgIcon } from "../user-icon/SvgIcon" ;
20+ import EthAddress from "../eth-address" ;
21+ import { UserName } from "../user-name" ;
22+ import { calculateBigIntPercentage } from "@/lib/calculateBigIntPercentage" ;
1723const MAX_FRACTIONS_DISPLAYED = 5 ;
1824
1925function Fraction ( {
2026 ownerAddress,
27+ totalUnits,
2128 units,
2229} : {
23- ownerAddress : string | null ;
24- units : unknown ;
30+ ownerAddress : string ;
31+ totalUnits : string | null | undefined ;
32+ units : string | null | undefined ;
2533} ) {
34+ const address = isAddress ( ownerAddress . trim ( ) )
35+ ? getAddress ( ownerAddress . trim ( ) )
36+ : undefined ;
37+
38+ const { data : userData , isFetching } = useGetUser ( {
39+ address : address ,
40+ } ) ;
41+
42+ const calculatedPercentage = calculateBigIntPercentage (
43+ units as string ,
44+ totalUnits as string ,
45+ ) ;
46+
47+ const roundedPercentage =
48+ calculatedPercentage ! < 1
49+ ? "<1"
50+ : Math . round ( calculatedPercentage ! ) . toString ( ) ;
51+
52+ if ( isFetching ) {
53+ return (
54+ < div className = "flex flex-row gap-2 items-center" >
55+ < Skeleton className = "h-8 w-8 rounded-full" />
56+ < Skeleton className = "h-8 w-32" />
57+ </ div >
58+ ) ;
59+ }
2660 return (
27- < div className = "flex flex-col w-full" >
28- { truncateEthereumAddress ( ownerAddress as `0x${string } `) } —{ " " }
29- < FormattedUnits > { units as string } </ FormattedUnits >
30- </ div >
61+ < >
62+ { userData ?. user ? (
63+ < div className = "flex flex-row gap-2" >
64+ { userData ?. user ?. avatar ? (
65+ < ImageIcon url = { userData . user . avatar } size = "tiny" />
66+ ) : (
67+ < SvgIcon size = "tiny" />
68+ ) }
69+ < div className = "flex justify-center items-start" >
70+ < UserName
71+ address = { userData . user . address }
72+ userName = { userData . user . display_name }
73+ />
74+ </ div >
75+ </ div >
76+ ) : (
77+ < div className = "flex flex-row items-center gap-2" >
78+ < UserIcon address = { address } size = "tiny" />
79+ < EthAddress address = { address } showEnsName = { true } />
80+ </ div >
81+ ) }
82+ < div className = "flex flex-row items-center gap-2" >
83+ — < FormattedUnits > { units as string } </ FormattedUnits >
84+ < span > { `(${ roundedPercentage } %)` } </ span >
85+ </ div >
86+ </ >
3187 ) ;
3288}
3389
@@ -77,10 +133,9 @@ export default function Fractions({
77133 key = { fraction . fraction_id }
78134 title = { fraction . owner_address || "" }
79135 >
80- < UserCircle2 className = "mr-2 h-4 w-4" />
81- < span className = "hidden" > { fraction . owner_address } </ span >
82136 < Fraction
83- ownerAddress = { fraction . owner_address }
137+ ownerAddress = { fraction . owner_address as string }
138+ totalUnits = { hypercert . units }
84139 units = { fraction . units }
85140 />
86141 </ CommandItem >
0 commit comments