From 3dd8215fd48239447cec59c9baca68095a138710 Mon Sep 17 00:00:00 2001 From: tyler17 Date: Fri, 12 Jul 2024 11:32:35 -0700 Subject: [PATCH] cleanup and fix date conversion --- .../helpers/formatDelegationHistoryChart.ts | 2 +- modules/gql/gqlRequest.ts | 26 +++---------------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/modules/delegates/helpers/formatDelegationHistoryChart.ts b/modules/delegates/helpers/formatDelegationHistoryChart.ts index 841d98e38..a322588c0 100644 --- a/modules/delegates/helpers/formatDelegationHistoryChart.ts +++ b/modules/delegates/helpers/formatDelegationHistoryChart.ts @@ -18,7 +18,7 @@ export const formatDelegationHistoryChart = ( ): MKRWeightHisory[] => { // We need to fill all the data for the interval // If we get last month, we need to add all the missing days - const start = formatIsoDateConversion(lockEvents[0].blockTimestamp); + const start = formatIsoDateConversion(new Date(Number(lockEvents[0].blockTimestamp) * 1000).toISOString()); const years = differenceInCalendarYears(Date.now(), new Date(lockEvents[0].blockTimestamp)); diff --git a/modules/gql/gqlRequest.ts b/modules/gql/gqlRequest.ts index 9cc1e899c..8632e80ad 100644 --- a/modules/gql/gqlRequest.ts +++ b/modules/gql/gqlRequest.ts @@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later */ -import { request, Variables, RequestDocument, GraphQLClient } from 'graphql-request'; +import { request, Variables, RequestDocument } from 'graphql-request'; import logger from 'lib/logger'; import { backoffRetry } from 'lib/utils'; import { ApiError } from 'modules/app/api/ApiError'; @@ -36,39 +36,21 @@ export const gqlRequest = async ({ url = CHAIN_INFO[id].spockUrl; } if (!url) { - return Promise.reject(new ApiError(`Missing spock url in configuration for chainId: ${id}`)); + return Promise.reject(new ApiError(`Missing ${useSubgraph ? 'subgraph' : 'spock'} url in configuration for chainId: ${id}`)); } - //const contentLength = JSON.stringify({ query, variables }).length.toString(); - const client = - // useSubgraph ? new GraphQLClient(url, { - // headers: () => ({ - // 'Host': 'localhost:3000', - // 'Origin': 'http://localhost:3000', - // 'Content-Type': 'application/json', - // 'Content-Length': contentLength, - // }) - // }) : - new GraphQLClient(url); - console.log('url', url); - console.log('client', client); - // Determine the environment - const isBrowser = typeof window !== 'undefined'; - console.log(`Running on the ${isBrowser ? 'frontend' : 'backend'}`); const resp = await backoffRetry( 3, - () => client.request(query, variables), + () => request(url, query, variables), 500, (message: string) => { logger.debug(`GQL Request: ${message}. --- ${query}`); } ); - - console.log('resp', resp); return resp; } catch (e) { const status = e.response ? e.response.status : 500; - const errorMessage = status === 403 ? e.message : e.message; //'Rate limited on gov polling' : e.message; + const errorMessage = e.message; const message = `Error on GraphQL query, Chain ID: ${chainId}, query: ${query}, message: ${errorMessage}`; throw new ApiError(message, status, 'Error fetching gov polling data'); }