-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from onchainification/feat/subgraph-query-ui-test
feat: use subgraph to pre-populate gauge options for the safe user in ui
- Loading branch information
Showing
8 changed files
with
160 additions
and
48 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// in future this `type` may contain more data pieces | ||
interface IChainDetails { | ||
[key: number]: { | ||
subgraphGauges: string; | ||
}; | ||
} | ||
|
||
export const chainDetails: IChainDetails = { | ||
10: { | ||
subgraphGauges: | ||
"https://api.studio.thegraph.com/proxy/50162/smartgarden-optimism-gauges/version/latest", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { useAccount, useNetwork } from "wagmi"; | ||
|
||
import { request } from "graphql-request"; | ||
|
||
import { chainDetails } from "../helpers/chainDetails"; | ||
import { GET_GAUGE_POSITIONS } from "./graphql/gaugePositions"; | ||
|
||
export interface IGaugePositions { | ||
id: string; | ||
pool_name: string; | ||
} | ||
|
||
async function getUserGaugePositions( | ||
safeAddress: string | undefined, | ||
chainId: number | undefined, | ||
) { | ||
try { | ||
if (!safeAddress) throw new Error("No Safe Account"); | ||
if (!chainId) throw new Error("Missing Chain ID"); | ||
if (!chainDetails[chainId].subgraphGauges) | ||
throw new Error("No Gauge subgraph url available"); | ||
const queryVars = { | ||
safeAddr: `${safeAddress}`, | ||
}; | ||
const positions = ( | ||
await request( | ||
chainDetails[chainId].subgraphGauges, | ||
GET_GAUGE_POSITIONS, | ||
queryVars, | ||
) | ||
).gaugePositions; | ||
const gaugeResults: IGaugePositions[] = []; | ||
positions.forEach((position: any) => { | ||
gaugeResults.push({ | ||
id: position.gauge.id, | ||
pool_name: position.gauge.pool_name, | ||
}); | ||
}); | ||
return gaugeResults; | ||
} catch (error) { | ||
console.error(error); | ||
return null; | ||
} | ||
} | ||
|
||
export default function useGetUserGaugePositions() { | ||
const { address } = useAccount(); | ||
const { chain } = useNetwork(); | ||
return useQuery(["userGaugePositions", address?.toLowerCase()], () => | ||
getUserGaugePositions(address?.toLowerCase(), chain?.id), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,4 @@ query UserGaugePositions { | |
pool_name | ||
} | ||
} | ||
} | ||
} |