Skip to content

Commit

Permalink
feat: create separate dict for gql queries to export easier/mantain
Browse files Browse the repository at this point in the history
  • Loading branch information
petrovska-petro committed Aug 23, 2023
1 parent 9249a30 commit be555d9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
14 changes: 14 additions & 0 deletions src/queries/graphql/gaugePositions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { gql } from "graphql-request";

export const GET_GAUGE_POSITIONS = gql`
query UserGaugePositions($safeAddr: String!) {
gaugePositions(where: { user: $safeAddr, balance_gt: "0" }) {
gauge {
id
protocol
pool
pool_name
}
}
}
`;
29 changes: 10 additions & 19 deletions src/queries/useGetUserGaugePositions.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useQuery } from "@tanstack/react-query";
import { useAccount, useNetwork } from "wagmi";

import { request, gql } from "graphql-request";
import { request } from "graphql-request";

import { chainDetails } from "../helpers/chainDetails";
import { GET_GAUGE_POSITIONS } from "./graphql/gaugePositions";

export interface IGaugePositions {
id: string;
Expand All @@ -19,25 +20,15 @@ async function getUserGaugePositions(
if (!chainId) throw new Error("Missing Chain ID");
if (!chainDetails[chainId].subgraphGauges)
throw new Error("No Gauge subgraph url available");
const querySafeAddr = gql`
query UserGaugePositions {
gaugePositions(
where: {
user: "${safeAddress}"
balance_gt: "0"
}
) {
gauge {
id
protocol
pool
pool_name
}
}
}
`;
const queryVars = {
safeAddr: `${safeAddress}`,
};
const positions = (
await request(chainDetails[chainId].subgraphGauges, querySafeAddr)
await request(
chainDetails[chainId].subgraphGauges,
GET_GAUGE_POSITIONS,
queryVars,
)
).gaugePositions;
const gaugeResults: IGaugePositions[] = [];
positions.forEach((position: any) => {
Expand Down

0 comments on commit be555d9

Please sign in to comment.