@@ -8,26 +8,82 @@ import {
8
8
CommandItem ,
9
9
CommandList ,
10
10
} from "@/components/ui/command" ;
11
- import { truncateEthereumAddress } from "@/lib/utils" ;
12
- import { UserCircle2 } from "lucide-react" ;
13
11
import { useState } from "react" ;
14
12
import { FormattedUnits } from "../formatted-units" ;
15
13
import { 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" ;
17
23
const MAX_FRACTIONS_DISPLAYED = 5 ;
18
24
19
25
function Fraction ( {
20
26
ownerAddress,
27
+ totalUnits,
21
28
units,
22
29
} : {
23
- ownerAddress : string | null ;
24
- units : unknown ;
30
+ ownerAddress : string ;
31
+ totalUnits : string | null | undefined ;
32
+ units : string | null | undefined ;
25
33
} ) {
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
+ }
26
60
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
+ </ >
31
87
) ;
32
88
}
33
89
@@ -77,10 +133,9 @@ export default function Fractions({
77
133
key = { fraction . fraction_id }
78
134
title = { fraction . owner_address || "" }
79
135
>
80
- < UserCircle2 className = "mr-2 h-4 w-4" />
81
- < span className = "hidden" > { fraction . owner_address } </ span >
82
136
< Fraction
83
- ownerAddress = { fraction . owner_address }
137
+ ownerAddress = { fraction . owner_address as string }
138
+ totalUnits = { hypercert . units }
84
139
units = { fraction . units }
85
140
/>
86
141
</ CommandItem >
0 commit comments