From 6efd5840312e88fb209fc620c04128ad6af44140 Mon Sep 17 00:00:00 2001 From: Ramiro Vazquez Date: Tue, 14 Apr 2020 19:46:56 -0300 Subject: [PATCH 1/5] update spell metadata for Executive list --- src/containers/Executive/index.tsx | 4 ++-- src/utils/makerdao.ts | 33 ++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/containers/Executive/index.tsx b/src/containers/Executive/index.tsx index b13bb3b..d7692eb 100644 --- a/src/containers/Executive/index.tsx +++ b/src/containers/Executive/index.tsx @@ -44,10 +44,10 @@ function ExecutiveInfo(props) { useEffect(() => { if (excutivesData.data && excutivesData.data.spells) { getMakerDaoData() - .then(({ executiveVotes }) => { + .then(({ spellsInfo }) => { setData( excutivesData.data.spells.map(spell => { - const proposal = executiveVotes.find(prop => { + const proposal = spellsInfo.find(prop => { return prop.source.toLowerCase() === spell.id.toLowerCase() }) return { diff --git a/src/utils/makerdao.ts b/src/utils/makerdao.ts index 2ef130d..dd1e509 100644 --- a/src/utils/makerdao.ts +++ b/src/utils/makerdao.ts @@ -5,7 +5,8 @@ const Hash = require('ipfs-only-hash') const network = 'mainnet' const prod = 'https://cms-gov.makerfoundation.com' -const path = 'content/governance-dashboard' +const topicsPath = 'content/governance-dashboard' +const spellsPath = 'content/all-spells' const rawUri = 'https://raw.githubusercontent.com/makerdao/community/master/governance/polls' const POLLING_EMITTER = '0xF9be8F0945acDdeeDaA64DFCA5Fe9629D0CF8E5D' // mainnet @@ -13,9 +14,9 @@ const POLLING_EMITTER = '0xF9be8F0945acDdeeDaA64DFCA5Fe9629D0CF8E5D' // mainnet const MKR_SUPPLY_API = 'https://api.etherscan.io/api' const PRECISION = new BigNumber('10').exponentiatedBy(18) -const check = async res => { +const check = async (res, resource) => { if (!res.ok) { - throw new Error(`unable to fetch topics: ${res.status} - ${await res.text()}`) + throw new Error(`unable to fetch ${resource}: ${res.status} - ${await res.text()}`) } } @@ -39,14 +40,18 @@ export const promiseRetry = ({ times = 3, fn, delay = 500, args = [] }) => { ) } -const fetchNetwork = async (url, network = 'mainnet') => { +const fetchNetwork = async (url, resource, path, network = 'mainnet') => { const res = await fetch(`${url}/${path}?network=${network}`) - await check(res) + await check(res, resource) return await res.json() } const fetchTopics = async network => { - return fetchNetwork(prod, network) + return fetchNetwork(prod, 'topics', topicsPath, network) +} + +const fetchSpells = async network => { + return fetchNetwork(prod, 'spells', spellsPath, network) } function extractProposals(topics, network) { @@ -100,10 +105,22 @@ export async function getMakerDaoData() { delay: 1, }) + const allSpells = await promiseRetry({ + fn: fetchSpells, + times: 4, + delay: 1, + }) + const executiveVotes = extractProposals(topics, network) const historicalPolls = formatHistoricalPolls(topics) + const spellsInfo = allSpells.map(({ source, title, proposal_blurb, about }) => ({ + source, + title, + proposal_blurb, + about, + })) - return { executiveVotes, historicalPolls } + return { executiveVotes, historicalPolls, spellsInfo } } // Polls data @@ -111,7 +128,7 @@ const fetchPollFromUrl = async url => { let customUri = url if (url.includes('github.com')) customUri = `${rawUri}/${url.substring(url.lastIndexOf('/') + 1)}` const res = await fetch(customUri) - await check(res) + await check(res, 'topics') const contentType = res.headers.get('content-type') if (!contentType) return null if (contentType.indexOf('application/json') !== -1) { From 96248bcdc36db84215a27c597a2eec0c39884ac5 Mon Sep 17 00:00:00 2001 From: Ramiro Vazquez Date: Tue, 14 Apr 2020 19:59:29 -0300 Subject: [PATCH 2/5] update Vote and VoteHistory --- src/containers/Vote/index.tsx | 4 ++-- src/containers/VoterHistory/index.tsx | 4 ++-- src/utils/makerdao.ts | 32 +++++++++++++-------------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/containers/Vote/index.tsx b/src/containers/Vote/index.tsx index 86dc530..52d3064 100644 --- a/src/containers/Vote/index.tsx +++ b/src/containers/Vote/index.tsx @@ -34,8 +34,8 @@ function VoteInfo(props: Props) { useEffect(() => { getMakerDaoData() - .then(({ executiveVotes }) => { - const vote = executiveVotes.find(el => { + .then(({ spellsInfo }) => { + const vote = spellsInfo.find(el => { return el.source.toLowerCase() === voteId.toLowerCase() }) setMakerData(vote) diff --git a/src/containers/VoterHistory/index.tsx b/src/containers/VoterHistory/index.tsx index af3930e..a4a6057 100644 --- a/src/containers/VoterHistory/index.tsx +++ b/src/containers/VoterHistory/index.tsx @@ -123,10 +123,10 @@ function VoterHistory(props: Props) { useEffect(() => { if (historyData.data && historyData.data.executives) { getMakerDaoData() - .then(({ executiveVotes }) => { + .then(({ spellsInfo }) => { setExecutives(exs => exs.map(spell => { - const proposal = executiveVotes.find(prop => prop.source.toLowerCase() === spell.id.toLowerCase()) + const proposal = spellsInfo.find(prop => prop.source.toLowerCase() === spell.id.toLowerCase()) return { ...spell, ...proposal, diff --git a/src/utils/makerdao.ts b/src/utils/makerdao.ts index dd1e509..c8abeb5 100644 --- a/src/utils/makerdao.ts +++ b/src/utils/makerdao.ts @@ -54,20 +54,20 @@ const fetchSpells = async network => { return fetchNetwork(prod, 'spells', spellsPath, network) } -function extractProposals(topics, network) { - const executiveTopics = topics.filter(t => t.govVote === false) - return executiveTopics.reduce((acc, topic) => { - const proposals = topic.proposals.map(({ source, ...otherProps }) => ({ - ...otherProps, - source: source.startsWith('{') ? JSON.parse(source)[network] : source, - active: topic.active, - govVote: topic.govVote, - topicKey: topic.key, - topicTitle: topic.topic, - })) - return acc.concat(proposals) - }, []) -} +// function extractProposals(topics, network) { +// const executiveTopics = topics.filter(t => t.govVote === false) +// return executiveTopics.reduce((acc, topic) => { +// const proposals = topic.proposals.map(({ source, ...otherProps }) => ({ +// ...otherProps, +// source: source.startsWith('{') ? JSON.parse(source)[network] : source, +// active: topic.active, +// govVote: topic.govVote, +// topicKey: topic.key, +// topicTitle: topic.topic, +// })) +// return acc.concat(proposals) +// }, []) +// } export const formatHistoricalPolls = topics => { const govTopics = topics.filter(t => t.govVote === true) @@ -111,7 +111,7 @@ export async function getMakerDaoData() { delay: 1, }) - const executiveVotes = extractProposals(topics, network) + //const executiveVotes = extractProposals(topics, network) const historicalPolls = formatHistoricalPolls(topics) const spellsInfo = allSpells.map(({ source, title, proposal_blurb, about }) => ({ source, @@ -120,7 +120,7 @@ export async function getMakerDaoData() { about, })) - return { executiveVotes, historicalPolls, spellsInfo } + return { /*executiveVotes,*/ historicalPolls, spellsInfo } } // Polls data From d515816ec3b7d1f261671b674aa88af55cd13891 Mon Sep 17 00:00:00 2001 From: Ramiro Vazquez Date: Wed, 15 Apr 2020 09:46:03 -0300 Subject: [PATCH 3/5] comment out unused variable --- src/utils/makerdao.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/makerdao.ts b/src/utils/makerdao.ts index c8abeb5..4920809 100644 --- a/src/utils/makerdao.ts +++ b/src/utils/makerdao.ts @@ -3,7 +3,7 @@ import BigNumber from 'bignumber.js' import { getUnixTime } from 'date-fns' const Hash = require('ipfs-only-hash') -const network = 'mainnet' +// const network = 'mainnet' const prod = 'https://cms-gov.makerfoundation.com' const topicsPath = 'content/governance-dashboard' const spellsPath = 'content/all-spells' From 3cf7b777632b13417f54de0311837bdeef748ec9 Mon Sep 17 00:00:00 2001 From: Ramiro Vazquez Date: Wed, 15 Apr 2020 10:40:41 -0300 Subject: [PATCH 4/5] remove commented code --- src/utils/makerdao.ts | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/utils/makerdao.ts b/src/utils/makerdao.ts index 4920809..2ff754c 100644 --- a/src/utils/makerdao.ts +++ b/src/utils/makerdao.ts @@ -3,7 +3,6 @@ import BigNumber from 'bignumber.js' import { getUnixTime } from 'date-fns' const Hash = require('ipfs-only-hash') -// const network = 'mainnet' const prod = 'https://cms-gov.makerfoundation.com' const topicsPath = 'content/governance-dashboard' const spellsPath = 'content/all-spells' @@ -54,21 +53,6 @@ const fetchSpells = async network => { return fetchNetwork(prod, 'spells', spellsPath, network) } -// function extractProposals(topics, network) { -// const executiveTopics = topics.filter(t => t.govVote === false) -// return executiveTopics.reduce((acc, topic) => { -// const proposals = topic.proposals.map(({ source, ...otherProps }) => ({ -// ...otherProps, -// source: source.startsWith('{') ? JSON.parse(source)[network] : source, -// active: topic.active, -// govVote: topic.govVote, -// topicKey: topic.key, -// topicTitle: topic.topic, -// })) -// return acc.concat(proposals) -// }, []) -// } - export const formatHistoricalPolls = topics => { const govTopics = topics.filter(t => t.govVote === true) const allPolls = govTopics.reduce((result, { end_timestamp, date, topic_blurb, topic, key, proposals }) => { @@ -120,7 +104,7 @@ export async function getMakerDaoData() { about, })) - return { /*executiveVotes,*/ historicalPolls, spellsInfo } + return { historicalPolls, spellsInfo } } // Polls data From ffd8ca80e7b9967ba864307ef9632f97e246612d Mon Sep 17 00:00:00 2001 From: Ramiro Vazquez Date: Wed, 22 Apr 2020 18:13:07 -0300 Subject: [PATCH 5/5] remove historicalPolls reference --- src/utils/makerdao.ts | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/utils/makerdao.ts b/src/utils/makerdao.ts index 2ff754c..90e724f 100644 --- a/src/utils/makerdao.ts +++ b/src/utils/makerdao.ts @@ -4,7 +4,6 @@ import { getUnixTime } from 'date-fns' const Hash = require('ipfs-only-hash') const prod = 'https://cms-gov.makerfoundation.com' -const topicsPath = 'content/governance-dashboard' const spellsPath = 'content/all-spells' const rawUri = 'https://raw.githubusercontent.com/makerdao/community/master/governance/polls' @@ -45,10 +44,6 @@ const fetchNetwork = async (url, resource, path, network = 'mainnet') => { return await res.json() } -const fetchTopics = async network => { - return fetchNetwork(prod, 'topics', topicsPath, network) -} - const fetchSpells = async network => { return fetchNetwork(prod, 'spells', spellsPath, network) } @@ -83,20 +78,12 @@ export const formatHistoricalPolls = topics => { } export async function getMakerDaoData() { - const topics = await promiseRetry({ - fn: fetchTopics, - times: 4, - delay: 1, - }) - const allSpells = await promiseRetry({ fn: fetchSpells, times: 4, delay: 1, }) - //const executiveVotes = extractProposals(topics, network) - const historicalPolls = formatHistoricalPolls(topics) const spellsInfo = allSpells.map(({ source, title, proposal_blurb, about }) => ({ source, title, @@ -104,7 +91,7 @@ export async function getMakerDaoData() { about, })) - return { historicalPolls, spellsInfo } + return { spellsInfo } } // Polls data