forked from aragon/conviction-funding-pilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
29 deletions.
There are no files selected for viewing
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useEffect, useState } from 'react' | ||
import gql from 'graphql-tag' | ||
import { GraphQLWrapper } from '@aragon/connect-thegraph' | ||
import * as Sentry from '@sentry/browser' | ||
|
||
const UNISWAP_URL = 'https://api.thegraph.com/subgraphs/name/lutter/uniswap-v2' | ||
const DAI_ANT_PAIR_ID = '0x7286656f87b60e7560ef0a0e53cfa41f450ef993' | ||
|
||
const UNISWAP_PAIR_QUERY = gql` | ||
query { | ||
pair(id: "${DAI_ANT_PAIR_ID}") { | ||
token0Price | ||
} | ||
} | ||
` | ||
|
||
export function useUniswapAntPrice() { | ||
const [antPrice, setAntPrice] = useState('0') | ||
const wrapper = new GraphQLWrapper(UNISWAP_URL) | ||
|
||
useEffect(() => { | ||
let cancelled = false | ||
async function getData() { | ||
try { | ||
const results = await wrapper.performQuery(UNISWAP_PAIR_QUERY) | ||
|
||
const { pair } = results.data | ||
if (!cancelled) { | ||
setAntPrice(pair.token0Price) | ||
} | ||
} catch (err) { | ||
Sentry.captureException(err) | ||
} | ||
} | ||
|
||
getData() | ||
|
||
return () => (cancelled = true) | ||
}) | ||
|
||
return antPrice | ||
} |