From a49cb95779c552749b5694a207a01298720b9b55 Mon Sep 17 00:00:00 2001 From: uncoolzero <107518216+uncoolzero@users.noreply.github.com> Date: Thu, 31 Aug 2023 15:34:29 -0300 Subject: [PATCH 1/2] Chart - Fixed handling of arrays longer than 100 --- .../components/Well/Activity/eventRender.tsx | 2 +- .../components/Well/Chart/ChartSection.tsx | 4 +-- .../src/queries/GetWellChartData.graphql | 4 +-- projects/dex-ui/src/wells/chartDataLoader.ts | 34 +++++++++++++++---- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/projects/dex-ui/src/components/Well/Activity/eventRender.tsx b/projects/dex-ui/src/components/Well/Activity/eventRender.tsx index a7fdaa64a5..28abcf6784 100644 --- a/projects/dex-ui/src/components/Well/Activity/eventRender.tsx +++ b/projects/dex-ui/src/components/Well/Activity/eventRender.tsx @@ -36,7 +36,7 @@ export const renderEvent = (event: WellEvent, well: Well, prices: (TokenValue | event = event as ShiftEvent; action = "Shift"; valueUSD = `$${event.toAmount.mul(tokenPrices[event.toToken.symbol] || 0).toHuman("short")}`; - description = `Swaped to ${event.toAmount.toHuman("short")} ${event.toToken.symbol}`; + description = `Swapped to ${event.toAmount.toHuman("short")} ${event.toToken.symbol}`; break; case EVENT_TYPE.ADD_LIQUIDITY: diff --git a/projects/dex-ui/src/components/Well/Chart/ChartSection.tsx b/projects/dex-ui/src/components/Well/Chart/ChartSection.tsx index 8b52491ed4..bb92eadd10 100644 --- a/projects/dex-ui/src/components/Well/Chart/ChartSection.tsx +++ b/projects/dex-ui/src/components/Well/Chart/ChartSection.tsx @@ -19,8 +19,8 @@ function timeToLocal(originalTime: number) { export const ChartSection: FC<{ well: Well }> = ({ well }) => { const [tab, setTab] = useState(0); const [showDropdown, setShowDropdown] = useState(false); - const [timePeriod, setTimePeriod] = useState("all"); - const [dropdownButtonText, setDropdownButtonText] = useState("ALL"); + const [timePeriod, setTimePeriod] = useState("week"); + const [dropdownButtonText, setDropdownButtonText] = useState("1 WEEK"); const { data: chartData, refetch, error, isLoading } = useWellChartData(well, timePeriod); diff --git a/projects/dex-ui/src/queries/GetWellChartData.graphql b/projects/dex-ui/src/queries/GetWellChartData.graphql index 79f9dcea43..0ac4d4f2f8 100644 --- a/projects/dex-ui/src/queries/GetWellChartData.graphql +++ b/projects/dex-ui/src/queries/GetWellChartData.graphql @@ -1,6 +1,6 @@ -query GetWellChartData($id: ID!, $lastUpdateTimestamp_gte: BigInt!) { +query GetWellChartData($id: ID!, $lastUpdateTimestamp_gte: BigInt!, $resultsToSkip: Int!) { well(id: $id) { - hourlySnapshots(orderBy: lastUpdateTimestamp, orderDirection: asc, where: { lastUpdateTimestamp_gte: $lastUpdateTimestamp_gte }) { + hourlySnapshots(first: 1000, skip: $resultsToSkip, orderBy: lastUpdateTimestamp, orderDirection: asc, where: { lastUpdateTimestamp_gte: $lastUpdateTimestamp_gte }) { lastUpdateTimestamp totalLiquidityUSD deltaVolumeUSD diff --git a/projects/dex-ui/src/wells/chartDataLoader.ts b/projects/dex-ui/src/wells/chartDataLoader.ts index c909874b45..3c24b6930a 100644 --- a/projects/dex-ui/src/wells/chartDataLoader.ts +++ b/projects/dex-ui/src/wells/chartDataLoader.ts @@ -13,15 +13,35 @@ const loadFromGraph = async (sdk: BeanstalkSDK, well: Well, timePeriod: string) const HISTORY_DAYS_AGO_BLOCK_TIMESTAMP = HISTORY_DAYS === 0 ? 0 : Math.floor(new Date(Date.now() - HISTORY_DAYS * 24 * 60 * 60 * 1000).getTime() / 1000); - const data = await fetchFromSubgraphRequest(GetWellChartDataDocument, { - id: well.address, - lastUpdateTimestamp_gte: HISTORY_DAYS_AGO_BLOCK_TIMESTAMP - }); + let results: any[] = []; + let goToNextPage: boolean = false; + let nextPage: number = 0; + let skipAmount: number = 0; - const results = await data(); + do { + const data = fetchFromSubgraphRequest(GetWellChartDataDocument, { + id: well.address, + lastUpdateTimestamp_gte: HISTORY_DAYS_AGO_BLOCK_TIMESTAMP, + resultsToSkip: skipAmount + }); - if (!results.well) return []; - return results.well.hourlySnapshots; + const fetchedData = await data(); + + if (fetchedData.well) { + results = results.concat(fetchedData.well.hourlySnapshots) + if (fetchedData.well.hourlySnapshots.length === 1000) { + goToNextPage = true; + nextPage++; + skipAmount = nextPage * 1000; + } else { + goToNextPage = false; + } + } + } + + while (goToNextPage === true); + + return results; }; export const loadChartData = async (sdk: BeanstalkSDK, well: Well, timePeriod: string): Promise => { From cee95dabb9b781c5bf6626da3500fdd19e6e6e89 Mon Sep 17 00:00:00 2001 From: uncoolzero <107518216+uncoolzero@users.noreply.github.com> Date: Thu, 31 Aug 2023 15:50:49 -0300 Subject: [PATCH 2/2] Missing else statement --- projects/dex-ui/src/wells/chartDataLoader.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/projects/dex-ui/src/wells/chartDataLoader.ts b/projects/dex-ui/src/wells/chartDataLoader.ts index 3c24b6930a..57b67c9c4a 100644 --- a/projects/dex-ui/src/wells/chartDataLoader.ts +++ b/projects/dex-ui/src/wells/chartDataLoader.ts @@ -36,7 +36,9 @@ const loadFromGraph = async (sdk: BeanstalkSDK, well: Well, timePeriod: string) } else { goToNextPage = false; } - } + } else { + goToNextPage = false; + } } while (goToNextPage === true);