@@ -45,6 +45,8 @@ query {
45
45
}
46
46
}) {
47
47
decodedDataJson
48
+ refUID
49
+ time
48
50
}
49
51
}
50
52
` ;
@@ -53,7 +55,21 @@ query {
53
55
query : query ,
54
56
} ) ;
55
57
56
- const attestations = result . data . attestations . map ( ( attestation : any ) => {
58
+ // Create a copy of the array and sort it by "time" in descending order
59
+ const sortedAttestations = [ ...result . data . attestations ] . sort ( ( a : any , b : any ) => b . time - a . time ) ;
60
+
61
+ // Filter to keep only the latest attestation for each "refUID"
62
+ const uniqueAttestations = new Map ( ) ;
63
+ for ( const attestation of sortedAttestations ) {
64
+ if ( ! uniqueAttestations . has ( attestation . refUID ) ) {
65
+ uniqueAttestations . set ( attestation . refUID , attestation ) ;
66
+ }
67
+ }
68
+
69
+ const filteredAttestations = Array . from ( uniqueAttestations . values ( ) ) ;
70
+
71
+ // Parse the decodedDataJson for each attestation
72
+ const attestations = filteredAttestations . map ( ( attestation : any ) => {
57
73
return JSON . parse ( attestation . decodedDataJson ) ;
58
74
} ) ;
59
75
@@ -87,22 +103,24 @@ async function fetchMetadataURL(refUid: string, client: ApolloClient<NormalizedC
87
103
decodedDataJson
88
104
}
89
105
}` ;
90
- try {
91
- const result = await client . query ( {
92
- query : query ,
93
- } ) ;
106
+ try {
107
+ const result = await client . query ( {
108
+ query : query ,
109
+ } ) ;
94
110
95
- const attestation = result . data . attestations [ 0 ] ; // Assuming you want the first attestation
96
- const parsedData = JSON . parse ( attestation . decodedDataJson ) ;
111
+ const sortedAttestations = [ ...result . data . attestations ] . sort ( ( a : any , b : any ) => b . time - a . time ) ;
97
112
98
- const projectRefUid = parsedData . find ( ( item : any ) => item . name === 'projectRefUID' ) ;
99
- const metadataURL = parsedData . find ( ( item : any ) => item . name === 'metadataUrl' ) ;
113
+ const attestation = sortedAttestations [ 0 ] ; // Assuming you want the first attestation
114
+ const parsedData = JSON . parse ( attestation . decodedDataJson ) ;
100
115
101
- return {
102
- metadataURL : metadataURL . value . value ,
103
- projectRefUid : projectRefUid . value . value
104
- } ;
105
- } catch ( error ) {
116
+ const projectRefUid = parsedData . find ( ( item : any ) => item . name === 'projectRefUID' ) ;
117
+ const metadataURL = parsedData . find ( ( item : any ) => item . name === 'metadataUrl' ) ;
118
+
119
+ return {
120
+ metadataURL : metadataURL . value . value ,
121
+ projectRefUid : projectRefUid . value . value
122
+ } ;
123
+ } catch ( error ) {
106
124
console . error ( "Error fetching data:" , error ) ;
107
125
return null ;
108
126
}
@@ -127,7 +145,7 @@ export async function fetchAndProcessData(client: ApolloClient<NormalizedCacheOb
127
145
} ;
128
146
} ) ) ;
129
147
130
- console . log ( "data" , arrObjectSomething )
148
+ console . log ( "data" , arrObjectSomething )
131
149
132
150
try {
133
151
const responses : any [ ] = [ ] ;
0 commit comments