Skip to content

Commit

Permalink
Chart - Fixed handling of arrays longer than 100
Browse files Browse the repository at this point in the history
  • Loading branch information
uncoolzero committed Aug 31, 2023
1 parent 7e90103 commit a49cb95
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions projects/dex-ui/src/components/Well/Chart/ChartSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions projects/dex-ui/src/queries/GetWellChartData.graphql
Original file line number Diff line number Diff line change
@@ -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
Expand Down
34 changes: 27 additions & 7 deletions projects/dex-ui/src/wells/chartDataLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> => {
Expand Down

0 comments on commit a49cb95

Please sign in to comment.