Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
waynebruce0x committed Oct 4, 2023
2 parents a766914 + af0b0a3 commit 2ad9068
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions utils/convertToChartData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
IncompleteSection,
ApiChartData,
} from "../types/adapters";
import { PromisePool } from "@supercharge/promise-pool";
import fetch from "node-fetch";
import {
RESOLUTION_SECONDS,
Expand Down Expand Up @@ -385,36 +384,14 @@ function discreet(raw: RawResult, config: ChartConfig): ChartData {
return { timestamps, unlocked, apiData, isContinuous: false };
}

export async function mapToServerData(testData: ChartSection[], token: string) {
const allTimestamps = [
...new Set(
testData
.map((s: ChartSection) => {
return s.data.timestamps;
})
.flat(),
),
];
const prices: Record<string, number> = {};

await PromisePool.withConcurrency(20)
.for(allTimestamps)
.process(async (ts: any) => {
const res = await fetch(
`https://coins.llama.fi/prices/historical/${ts}/${token}`,
)
.then((r: any) => r.json())
.catch(() => null);
const price = res ? res?.coins[token]?.price : 0;
prices[ts] = price;
});

export function mapToServerData(testData: ChartSection[]) {
const serverData: any[] = testData.map((s: ChartSection) => {
const label = s.section;

const data = s.data.timestamps.map((timestamp: number, i: number) => ({
timestamp,
unlocked: s.data.unlocked[i],
price: prices[timestamp] ?? 0,
}));

return { label, data };
Expand Down

0 comments on commit 2ad9068

Please sign in to comment.