Skip to content

Commit

Permalink
refactor: Move subgraph url to .env file
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstph-dvx committed Jun 7, 2024
1 parent 84b4773 commit b02d8aa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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=
8 changes: 4 additions & 4 deletions src/app/retryables-tracker/[address]/PendingRetryables.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand All @@ -40,7 +40,7 @@ async function fetchPendingRetryables(
`;
const { retryables }: { retryables: BridgeRetryable[] } = await querySubgraph(
queryForCreation,
subgraphUrl.Bridge,
SubgraphQuery.Bridge,
);

if (retryables.length === 0) {
Expand All @@ -66,7 +66,7 @@ async function fetchPendingRetryables(

const { deposits }: { deposits: Deposit[] } = await querySubgraph(
queryForDeposits,
subgraphUrl.Bridge,
SubgraphQuery.Bridge,
);

const depositsMap = deposits.reduce((acc, deposit) => {
Expand Down
21 changes: 17 additions & 4 deletions src/app/retryables-tracker/[address]/querySubgraph.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down

0 comments on commit b02d8aa

Please sign in to comment.