Skip to content

Commit

Permalink
fix: latest data fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
wit03 committed Oct 14, 2024
1 parent 0a5cf40 commit 914cc2d
Show file tree
Hide file tree
Showing 2 changed files with 10,682 additions and 16 deletions.
10,650 changes: 10,649 additions & 1 deletion src/scripts/retropgf6-live-data/data/retropgf6-live-data/retropgf6-live-data.json

Large diffs are not rendered by default.

48 changes: 33 additions & 15 deletions src/scripts/retropgf6-live-data/retropgf6-live-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ query {
}
}) {
decodedDataJson
refUID
time
}
}
`;
Expand All @@ -53,7 +55,21 @@ query {
query: query,
});

const attestations = result.data.attestations.map((attestation: any) => {
// Create a copy of the array and sort it by "time" in descending order
const sortedAttestations = [...result.data.attestations].sort((a: any, b: any) => b.time - a.time);

// Filter to keep only the latest attestation for each "refUID"
const uniqueAttestations = new Map();
for (const attestation of sortedAttestations) {
if (!uniqueAttestations.has(attestation.refUID)) {
uniqueAttestations.set(attestation.refUID, attestation);
}
}

const filteredAttestations = Array.from(uniqueAttestations.values());

// Parse the decodedDataJson for each attestation
const attestations = filteredAttestations.map((attestation: any) => {
return JSON.parse(attestation.decodedDataJson);
});

Expand Down Expand Up @@ -87,22 +103,24 @@ async function fetchMetadataURL(refUid: string, client: ApolloClient<NormalizedC
decodedDataJson
}
}`;
try {
const result = await client.query({
query: query,
});
try {
const result = await client.query({
query: query,
});

const attestation = result.data.attestations[0]; // Assuming you want the first attestation
const parsedData = JSON.parse(attestation.decodedDataJson);
const sortedAttestations = [...result.data.attestations].sort((a: any, b: any) => b.time - a.time);

const projectRefUid = parsedData.find((item: any) => item.name === 'projectRefUID');
const metadataURL = parsedData.find((item: any) => item.name === 'metadataUrl');
const attestation = sortedAttestations[0]; // Assuming you want the first attestation
const parsedData = JSON.parse(attestation.decodedDataJson);

return {
metadataURL: metadataURL.value.value,
projectRefUid: projectRefUid.value.value
};
} catch (error) {
const projectRefUid = parsedData.find((item: any) => item.name === 'projectRefUID');
const metadataURL = parsedData.find((item: any) => item.name === 'metadataUrl');

return {
metadataURL: metadataURL.value.value,
projectRefUid: projectRefUid.value.value
};
} catch (error) {
console.error("Error fetching data:", error);
return null;
}
Expand All @@ -127,7 +145,7 @@ export async function fetchAndProcessData(client: ApolloClient<NormalizedCacheOb
};
}));

console.log("data", arrObjectSomething)
console.log("data", arrObjectSomething)

try {
const responses: any[] = [];
Expand Down

0 comments on commit 914cc2d

Please sign in to comment.