From b02d8aa056a02776411183a9959e67e142ef054f Mon Sep 17 00:00:00 2001 From: Christophe Date: Fri, 7 Jun 2024 10:20:22 +0000 Subject: [PATCH] refactor: Move subgraph url to .env file --- .env.sample | 3 +++ .../[address]/PendingRetryables.tsx | 8 +++---- .../[address]/querySubgraph.ts | 21 +++++++++++++++---- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.env.sample b/.env.sample index b4a4d84..4a1908a 100644 --- a/.env.sample +++ b/.env.sample @@ -13,3 +13,6 @@ NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID= NEXT_PUBLIC_LOCAL_ETHEREUM_RPC_URL=http://localhost:8545 NEXT_PUBLIC_LOCAL_ARBITRUM_RPC_URL=http://localhost:8547 + +RETRYABLES_SUBGRAPH_URL= +BRIDGE_SUBGRAPH_URL= \ No newline at end of file diff --git a/src/app/retryables-tracker/[address]/PendingRetryables.tsx b/src/app/retryables-tracker/[address]/PendingRetryables.tsx index 1100254..81c29a4 100644 --- a/src/app/retryables-tracker/[address]/PendingRetryables.tsx +++ b/src/app/retryables-tracker/[address]/PendingRetryables.tsx @@ -1,6 +1,6 @@ import Link from 'next/link'; import { Retryable, Deposit, BridgeRetryable } from './types'; -import { querySubgraph, subgraphUrl } from './querySubgraph'; +import { querySubgraph, SubgraphQuery } from './querySubgraph'; async function fetchPendingRetryables( address?: string, @@ -21,7 +21,7 @@ async function fetchPendingRetryables( const result: { retryables: Retryable[] } = await querySubgraph( query, - subgraphUrl.Retryables, + SubgraphQuery.Retryables, ); const retryableCreationTxHashes = result.retryables.map( (retryable) => retryable.createdAtTxHash, @@ -40,7 +40,7 @@ async function fetchPendingRetryables( `; const { retryables }: { retryables: BridgeRetryable[] } = await querySubgraph( queryForCreation, - subgraphUrl.Bridge, + SubgraphQuery.Bridge, ); if (retryables.length === 0) { @@ -66,7 +66,7 @@ async function fetchPendingRetryables( const { deposits }: { deposits: Deposit[] } = await querySubgraph( queryForDeposits, - subgraphUrl.Bridge, + SubgraphQuery.Bridge, ); const depositsMap = deposits.reduce((acc, deposit) => { diff --git a/src/app/retryables-tracker/[address]/querySubgraph.ts b/src/app/retryables-tracker/[address]/querySubgraph.ts index 754b86d..63799f5 100644 --- a/src/app/retryables-tracker/[address]/querySubgraph.ts +++ b/src/app/retryables-tracker/[address]/querySubgraph.ts @@ -1,9 +1,22 @@ -export enum subgraphUrl { - Retryables = 'https://api.thegraph.com/subgraphs/name/gvladika/arbitrum-retryables', - Bridge = 'https://api.thegraph.com/subgraphs/name/gvladika/arb-bridge-eth-nitro', +const retryablesSubgraphUrl = process.env.RETRYABLES_SUBGRAPH_URL; +const bridgeSubgraphUrl = process.env.BRIDGE_SUBGRAPH_URL; + +if (!retryablesSubgraphUrl || !bridgeSubgraphUrl) { + throw new Error('Missing subgraph Urls'); +} + +export enum SubgraphQuery { + Retryables = 'retryables', + Bridge = 'bridge', } -export async function querySubgraph(query: string, url: subgraphUrl) { +const urls = { + [SubgraphQuery.Retryables]: retryablesSubgraphUrl, + [SubgraphQuery.Bridge]: bridgeSubgraphUrl, +}; + +export async function querySubgraph(query: string, type: SubgraphQuery) { + const url = urls[type]; const response = await fetch(url, { method: 'POST', headers: {