Skip to content

Commit

Permalink
Merge pull request #93 from DefiLlama/patchMissingEndpoints
Browse files Browse the repository at this point in the history
Patch missing endpoints
  • Loading branch information
waynebruce0x committed Sep 20, 2024
2 parents 6f08e0c + 9721744 commit a9e207a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
11 changes: 8 additions & 3 deletions adapters/balance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ export async function latest(
timestampDeployed: number,
): Promise<number> {
if (!res) {
let r = await fetch(`https://api.llama.fi/emission/${adapter}`).then((r) =>
r.json(),
);
let r;
try {
r = await fetch(`https://api.llama.fi/emission/${adapter}`).then((r) =>
r.json(),
);
} catch {
return timestampDeployed;
}
if (!r.body) return timestampDeployed;
r = JSON.parse(r.body);
return r.metadata.incompleteSections == null ||
Expand Down
11 changes: 8 additions & 3 deletions adapters/supply/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ let res: number;

export async function latest(key: string, reference: number): Promise<number> {
if (!res) {
let r = await fetch(`https://api.llama.fi/emission/${key}`).then((r) =>
r.json(),
);
let r;
try {
r = await fetch(`https://api.llama.fi/emission/${key}`).then((r) =>
r.json(),
);
} catch {
return reference;
}
if (!r.body) return reference;
r = JSON.parse(r.body);
return r.metadata.incompleteSections == null ||
Expand Down
11 changes: 7 additions & 4 deletions utils/convertToChartData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,14 @@ async function appendMissingDataSections(
const incompleteSections = data.metadata.incompleteSections;
if (incompleteSections == null || incompleteSections.length == 0) return;

let res = await fetch(`https://api.llama.fi/emission/${protocol}`).then((r) =>
r.json(),
);
let res = [];
try {
res = await fetch(`https://api.llama.fi/emission/${protocol}`).then((r) =>
r.json(),
);
} catch {}
let body = res.body ? JSON.parse(res.body) : [];
res = body && body.length != 0 ? body.documentedData?.data ?? body.data : [];
res = body && body.length ? body.documentedData?.data ?? body.data : [];

if (nullsInApiData(res)) {
await sendMessage(
Expand Down

0 comments on commit a9e207a

Please sign in to comment.