1
- import { Badge } from "@/components/ui/badge"
2
1
import {
3
- Card ,
4
- CardContent ,
5
- CardDescription ,
6
- CardFooter ,
7
- CardHeader ,
8
- CardTitle ,
9
- } from "@/components/ui/card"
10
- import { useGetAttestations } from "@/lib/eas/get-attestations"
11
- import { Address , Hex } from "viem"
12
- import { useChainId } from "wagmi"
13
- import { asAttestationMeta , AttestationMeta } from "./attestations"
14
- import { useMemo } from "react"
15
- import { Skeleton } from "@/components/ui/skeleton"
16
- import { Label } from "@radix-ui/ react-label"
17
- import { Separator } from "@/components/ui/separator"
18
- import { getShortHex } from "@/utils/hex"
19
- import { format } from "date-fns"
20
- import { mainnet } from "viem/chains"
21
- import { SchemaBadge } from "./SchemaBadge"
2
+ Card ,
3
+ CardContent ,
4
+ CardDescription ,
5
+ CardFooter ,
6
+ CardHeader ,
7
+ CardTitle ,
8
+ } from "@/components/ui/card" ;
9
+ import { Separator } from "@/components/ui/separator" ;
10
+ import { Skeleton } from "@/components/ui/skeleton" ;
11
+ import { useGetAttestations } from "@/lib/eas/get-attestations" ;
12
+ import { getShortHex } from "@/utils/hex" ;
13
+ import { Label } from "@radix-ui/ react-label" ;
14
+ import { format } from "date-fns" ;
15
+ import { useMemo } from "react" ;
16
+ import { Address , Hex } from "viem" ;
17
+ import { mainnet } from "viem/chains" ;
18
+ import { useChainId } from "wagmi" ;
19
+ import { SchemaBadge } from "./SchemaBadge" ;
20
+ import { AttestationMeta , asAttestationMeta } from "./attestations" ;
22
21
23
- // TODO indicate network
24
- const AttestationCardContent = ( { attestation } : { attestation : AttestationMeta } ) => {
25
- const { from , to , schemaId , schemaName , schemaIndex } = attestation ;
26
- if ( ! attestation ) {
27
- return < Skeleton className = "w-[100px] h-[20px] rounded-full" />
28
- }
29
- return (
30
- < CardContent >
31
- < div className = "flex w-full items-center gap-2" >
32
- < div className = "grid flex-1 auto-rows-min gap-0.5" >
33
- < div className = "text-xs text-muted-foreground" > Schema ID </ div >
34
- < div className = "flex items-center gap-1 text-2xl font-bold tabular-nums leading-none " >
35
- < SchemaBadge chainId = { mainnet . id } schemaId = { schemaId } schemaIndex = { schemaIndex } / >
36
- < div className = "flex flex-col " >
37
- < div className = "text-sm font-normal text-muted-foreground" >
38
- < span className = "text-sm font-normal" >
39
- { schemaName }
40
- </ span >
41
- </ div >
42
- < span className = "text-sm font-normal text-muted-foreground " >
43
- { getShortHex ( schemaId as Hex ) }
44
- </ span >
45
- </ div >
46
- </ div >
47
- </ div >
48
- < Separator orientation = "vertical" className = "mx-2 h-10 w-px" / >
49
- < div className = "grid flex-1 auto-rows-min gap-0.5" >
50
- < div className = "text-xs text-muted-foreground" > From </ div >
51
- < div className = "flex items-baseline gap-1 text-2xl font-bold tabular-nums leading-none" >
52
- < span className = "text-sm font-normal" >
53
- { from }
54
- </ span >
55
- </ div >
56
- < div className = "text-xs text-muted-foreground" > To </ div >
57
- < div className = "flex items-baseline gap-1 text-2xl font-bold tabular-nums leading-none" >
58
- < span className = "text-sm font-normal" >
59
- { to }
60
- </ span >
61
- </ div >
62
- </ div >
63
- </ div >
22
+ // TODO indicate network
23
+ const AttestationCardContent = ( {
24
+ attestation,
25
+ } : { attestation : AttestationMeta } ) => {
26
+ const { from , to , schemaId , schemaName , schemaIndex } = attestation ;
27
+ if ( ! attestation ) {
28
+ return < Skeleton className = "w-[100px] h-[20px] rounded-full" /> ;
29
+ }
30
+ return (
31
+ < CardContent >
32
+ < div className = "flex w-full items-center gap-2" >
33
+ < div className = "grid flex-1 auto-rows-min gap-0.5 " >
34
+ < div className = "text-xs text-muted-foreground" > Schema ID </ div >
35
+ < div className = "flex items-center gap-1 text-2xl font-bold tabular-nums leading-none " >
36
+ < SchemaBadge
37
+ chainId = { mainnet . id }
38
+ schemaId = { schemaId }
39
+ schemaIndex = { schemaIndex }
40
+ / >
41
+ < div className = "flex flex-col " >
42
+ < div className = "text-sm font-normal text-muted-foreground" >
43
+ < span className = "text-sm font-normal" > { schemaName } </ span >
44
+ </ div >
45
+ < span className = "text-sm font-normal text-muted-foreground" >
46
+ { getShortHex ( schemaId as Hex ) }
47
+ </ span >
48
+ </ div >
49
+ </ div >
50
+ </ div >
51
+ < Separator orientation = "vertical" className = "mx-2 h-10 w-px" / >
52
+ < div className = "grid flex-1 auto-rows-min gap-0.5" >
53
+ < div className = "text-xs text-muted-foreground" > From </ div >
54
+ < div className = "flex items-baseline gap-1 text-2xl font-bold tabular-nums leading-none" >
55
+ < span className = "text-sm font-normal" > { from } </ span >
56
+ </ div >
57
+ < div className = "text-xs text-muted-foreground" > To </ div >
58
+ < div className = "flex items-baseline gap-1 text-2xl font-bold tabular-nums leading-none" >
59
+ < span className = "text-sm font-normal" > { to } </ span >
60
+ </ div >
61
+ </ div >
62
+ </ div >
64
63
65
- < Label > </ Label >
66
- </ CardContent >
67
- )
68
- }
64
+ < Label > </ Label >
65
+ </ CardContent >
66
+ ) ;
67
+ } ;
69
68
70
69
// some key fields from https://easscan.org/offchain/attestation/view/0x49dff46654fe740241026c1a717ace9ec439abe26124cd925b0ba1df296433c5
71
70
export const AttestationCard = ( {
72
- attesterAddress
71
+ attesterAddress,
73
72
} : {
74
- attesterAddress : Address
73
+ attesterAddress : Address ;
75
74
} ) => {
75
+ const chainId = useChainId ( ) ;
76
+ const { data, isSuccess } = useGetAttestations ( {
77
+ chainId,
78
+ address : attesterAddress ,
79
+ } ) ;
76
80
77
- const chainId = useChainId ( ) ;
78
- const { data, isSuccess } = useGetAttestations ( {
79
- chainId,
80
- address : attesterAddress
81
- } ) ;
81
+ const attestation = useMemo ( ( ) => {
82
+ if ( ! data ) {
83
+ return null ;
84
+ }
85
+ return asAttestationMeta ( data ?. data ?. attestations ?. [ 0 ] ) ;
86
+ } , [ isSuccess ] ) ;
87
+ // 1. onchain vs offchain
82
88
89
+ // 2. grid
83
90
84
- const attestation = useMemo ( ( ) => {
85
- if ( ! data ) {
86
- return null ;
87
- }
88
- return asAttestationMeta ( data ?. data ?. attestations ?. [ 0 ] ) ;
89
- } , [ isSuccess ] ) ;
90
- // 1. onchain vs offchain
91
+ return (
92
+ < Card >
93
+ { attestation ? (
94
+ < CardHeader >
95
+ < CardTitle > Attestation</ CardTitle >
96
+ < CardDescription >
97
+ < div className = "flex flex-col" >
98
+ < div className = "flex items-baseline " >
99
+ < span className = "text-xs font-normal" > UID:</ span >
100
+ </ div >
91
101
92
- // 2. grid
102
+ < div className = "text-xs text-muted-foreground" >
103
+ { attestation . id }
104
+ </ div >
105
+ </ div >
93
106
94
- return (
95
-
96
- < Card >
97
- {
98
- attestation ? (
99
- < CardHeader >
100
- < CardTitle > Attestation</ CardTitle >
101
- < CardDescription >
102
- < div className = "flex flex-col" >
103
-
104
- < div className = "flex items-baseline " >
105
- < span className = "text-xs font-normal" >
106
- UID:
107
- </ span >
108
- </ div >
109
-
110
- < div className = "text-xs text-muted-foreground" > { attestation . id } </ div >
111
-
112
- </ div >
113
-
114
- < div className = "flex flex-col" >
115
- < span className = "text-xs font-normal" >
116
- TIMESTAMPS:
117
- </ span >
118
- </ div >
119
- < div className = "text-xs text-muted-foreground" >
120
- Created: { format ( new Date ( attestation . time * 1000 ) , 'yyyy/MM/dd HH:MM:ss' ) }
121
- </ div >
122
-
123
- </ CardDescription >
124
- </ CardHeader >
125
- ) : < Skeleton className = "w-[100px] h-[20px] rounded-full" />
126
- }
127
- < CardContent >
128
- {
129
- attestation && (
130
- < AttestationCardContent attestation = { attestation } />
131
- )
132
- }
133
- </ CardContent >
134
- < CardFooter >
135
- </ CardFooter >
136
- </ Card >
137
- )
138
-
139
- }
107
+ < div className = "flex flex-col" >
108
+ < span className = "text-xs font-normal" > TIMESTAMPS:</ span >
109
+ </ div >
110
+ < div className = "text-xs text-muted-foreground" >
111
+ Created:{ " " }
112
+ { format ( new Date ( attestation . time * 1000 ) , "yyyy/MM/dd HH:MM:ss" ) }
113
+ </ div >
114
+ </ CardDescription >
115
+ </ CardHeader >
116
+ ) : (
117
+ < Skeleton className = "w-[100px] h-[20px] rounded-full" />
118
+ ) }
119
+ < CardContent >
120
+ { attestation && < AttestationCardContent attestation = { attestation } /> }
121
+ </ CardContent >
122
+ < CardFooter > </ CardFooter >
123
+ </ Card >
124
+ ) ;
125
+ } ;
0 commit comments