diff --git a/.env.example b/.env.example index 37d6622..c20643d 100644 --- a/.env.example +++ b/.env.example @@ -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' diff --git a/netlify.toml b/netlify.toml index 915de96..b6ab15e 100644 --- a/netlify.toml +++ b/netlify.toml @@ -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" @@ -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' @@ -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' @@ -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' diff --git a/package.json b/package.json index a60902b..c976aad 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "eslintConfig": { "extends": "react-app" }, + "proxy": "https://gov-db.makerfoundation.com", "browserslist": { "production": [ ">0.2%", diff --git a/src/utils/makerdao.ts b/src/utils/makerdao.ts index e7b466b..492c012 100644 --- a/src/utils/makerdao.ts +++ b/src/utils/makerdao.ts @@ -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') @@ -177,13 +178,20 @@ export async function getPollsMetaData(polls: Array) { }), ) - 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)] diff --git a/src/utils/mkr-gov-db.ts b/src/utils/mkr-gov-db.ts new file mode 100644 index 0000000..1c4fafa --- /dev/null +++ b/src/utils/mkr-gov-db.ts @@ -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] +}