Skip to content

Commit

Permalink
Merge pull request #410 from protofire/use-makerfoundation-graphql-api
Browse files Browse the repository at this point in the history
  • Loading branch information
leolower authored May 27, 2020
2 parents 5035c34 + 521914f commit bcde40c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
REACT_APP_GRAPH_NETWORK='Mainnet'
REACT_APP_GRAPH_HTTP='https://api.thegraph.com/subgraphs/name/protofire/makerdao-governance'
REACT_APP_MKR_GRAPH_HTTP='https://api.thegraph.com/subgraphs/name/protofire/mkr-registry'
REACT_APP_GOV_DB_HTTP='/api/v1'
REACT_APP_ETHERSCAN_API_KEY='XQ2QTEM7H4KX7AQTE9JWXD3HWTTZ46TTU9'
REACT_APP_LAST_CACHE_UPDATE='1587733935'
REACT_APP_HOME_DATA_TTL='5'
8 changes: 8 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
publish = "build/"
command = "npm run build"

[[redirects]]
from = "/api/v1"
to = "https://gov-db.makerfoundation.com/api/v1"
status = 200

[[redirects]]
from = "/*"
to = "/index.html"
Expand All @@ -11,6 +16,7 @@
REACT_APP_GRAPH_HTTP = "https://api.thegraph.com/subgraphs/name/protofire/makerdao-governance"
REACT_APP_GRAPH_WS = "wss://api.thegraph.com/subgraphs/name/protofire/makerdao-governance"
REACT_APP_MKR_GRAPH_HTTP='https://api.thegraph.com/subgraphs/name/protofire/mkr-registry'
REACT_APP_GOV_DB_HTTP='/api/v1'
REACT_APP_ETHERSCAN_API_KEY='XQ2QTEM7H4KX7AQTE9JWXD3HWTTZ46TTU9'
REACT_APP_LAST_CACHE_UPDATE='1587733935'
REACT_APP_HOME_DATA_TTL='5'
Expand All @@ -19,6 +25,7 @@
REACT_APP_GRAPH_HTTP = "https://api.thegraph.com/subgraphs/name/protofire/makerdao-governance"
REACT_APP_GRAPH_WS = "wss://api.thegraph.com/subgraphs/name/protofire/makerdao-governance"
REACT_APP_MKR_GRAPH_HTTP='https://api.thegraph.com/subgraphs/name/protofire/mkr-registry'
REACT_APP_GOV_DB_HTTP='/api/v1'
REACT_APP_ETHERSCAN_API_KEY='XQ2QTEM7H4KX7AQTE9JWXD3HWTTZ46TTU9'
REACT_APP_LAST_CACHE_UPDATE='1587733935'
REACT_APP_HOME_DATA_TTL='5'
Expand All @@ -27,6 +34,7 @@
REACT_APP_GRAPH_HTTP = "https://api.thegraph.com/subgraphs/name/protofire/makerdao-governance"
REACT_APP_GRAPH_WS = "wss://api.thegraph.com/subgraphs/name/protofire/makerdao-governance"
REACT_APP_MKR_GRAPH_HTTP='https://api.thegraph.com/subgraphs/name/protofire/mkr-registry'
REACT_APP_GOV_DB_HTTP='/api/v1'
REACT_APP_ETHERSCAN_API_KEY='XQ2QTEM7H4KX7AQTE9JWXD3HWTTZ46TTU9'
REACT_APP_LAST_CACHE_UPDATE='1587733935'
REACT_APP_HOME_DATA_TTL='5'
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"eslintConfig": {
"extends": "react-app"
},
"proxy": "https://gov-db.makerfoundation.com",
"browserslist": {
"production": [
">0.2%",
Expand Down
22 changes: 15 additions & 7 deletions src/utils/makerdao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import matter from 'gray-matter'
import BigNumber from 'bignumber.js'
import { getUnixTime } from 'date-fns'
import { setCache, getCache } from './cache'
import { getPollDates } from './mkr-gov-db'

const Hash = require('ipfs-only-hash')

Expand Down Expand Up @@ -177,13 +178,20 @@ export async function getPollsMetaData(polls: Array<any>) {
}),
)

const updatedCached = cached.map(cachedData => {
const newPollData = polls.find(p => p.id === cachedData.id)
return {
...cachedData,
...newPollData,
}
}) // need to update data coming from subgraph
const updatedCached = await Promise.all(
cached.map(async cachedData => {
const newPollData = polls.find(p => p.id === cachedData.id)
let pollDates
if (newPollData) {
pollDates = await getPollDates(newPollData.id)
}
return {
...cachedData,
...newPollData,
...pollDates,
}
}),
) // need to update data coming from subgraph

const allPolls = [...updatedCached, ...pollsToAdd.filter(Boolean)]

Expand Down
22 changes: 22 additions & 0 deletions src/utils/mkr-gov-db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { GraphQLClient } from 'graphql-request'

const MKR_GOV_DB_URI = process.env.REACT_APP_GOV_DB_HTTP || ''

const client = new GraphQLClient(MKR_GOV_DB_URI)

const POLL_QUERY = /* GraphQL */ `
query GetPoll($pollId: Int) {
activePolls(filter: { pollId: { equalTo: $pollId } }) {
nodes {
startDate
endDate
}
}
}
`

export async function getPollDates(pollId) {
const data = await client.request(POLL_QUERY, { pollId: Number(pollId) })

return data.activePolls.nodes[0]
}

0 comments on commit bcde40c

Please sign in to comment.