Skip to content

Commit

Permalink
use startDate and endDate for polls from mkr-gov api
Browse files Browse the repository at this point in the history
  • Loading branch information
ramirotw committed May 18, 2020
1 parent a825836 commit db516fa
Show file tree
Hide file tree
Showing 5 changed files with 40 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' # IN MINUTES
1 change: 1 addition & 0 deletions _redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/api/v1 https://gov-db.makerfoundation.com/api/v1
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 db516fa

Please sign in to comment.