Skip to content

Commit

Permalink
cleanup and fix date conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler17 committed Jul 12, 2024
1 parent a064e3a commit 3dd8215
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
2 changes: 1 addition & 1 deletion modules/delegates/helpers/formatDelegationHistoryChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
26 changes: 4 additions & 22 deletions modules/gql/gqlRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -36,39 +36,21 @@ export const gqlRequest = async <TQuery = any>({
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');
}
Expand Down

0 comments on commit 3dd8215

Please sign in to comment.