diff --git a/src/components/PollDetails/data.ts b/src/components/PollDetails/data.ts
index 189c8e6..14fbd3f 100644
--- a/src/components/PollDetails/data.ts
+++ b/src/components/PollDetails/data.ts
@@ -1,12 +1,6 @@
-import { request } from 'graphql-request'
import { BigNumber } from 'bignumber.js'
import { getPollVotersRegistries, getStakedByPoll, stakedByAddress, msToSeconds, getVotersSnapshots } from '../../utils'
-const GOVERNANCE_API_URI = process.env.REACT_APP_GRAPH_HTTP
-const MKR_API_URI = process.env.REACT_APP_MKR_GRAPH_HTTP
-
-const fetchQuery = (url, query, variables) => request(url, query, variables)
-
export const getPollVotersPerOption = poll => {
return poll.votes.reduce((acum, el) => {
const option = acum[el.option] || []
diff --git a/src/containers/Home/index.tsx b/src/containers/Home/index.tsx
index 4cac740..08f6a8f 100644
--- a/src/containers/Home/index.tsx
+++ b/src/containers/Home/index.tsx
@@ -1,7 +1,6 @@
import React, { useState, useEffect } from 'react'
import HomeDetail from '../../components/Home/HomeDetail'
-import { DEFAULT_FETCH_ROWS } from '../../constants'
import { FullLoading } from '../../components/common'
import { useQuery } from '@apollo/react-hooks'
import { GOVERNANCE_INFO_QUERY } from './queries'
@@ -11,28 +10,6 @@ import useAsyncMemo from '../../hooks/useAsyncMemo'
import useHomeData from '../../hooks/useHomeData'
import BigNumber from 'bignumber.js'
-const getHomeVariables = data => {
- const governance = data.governanceInfo
- return {
- voters: Number(governance.countProxies) + Number(governance.countAddresses) || DEFAULT_FETCH_ROWS,
- }
-}
-
-const getPages = gData => {
- if (!gData) {
- return {
- pollPages: 2,
- executivesPages: 2,
- }
- }
-
- const { governanceInfo } = gData
- return {
- pollPages: Math.ceil(Number(governanceInfo.countPolls) / 1000),
- executivesPages: Math.ceil(Number(governanceInfo.countSpells) / 1000),
- }
-}
-
const Error = () =>
ERROR: There was an error trying to fetch the data.
function MakerGovernanceInfo() {
@@ -65,7 +42,7 @@ function MakerGovernanceInfo() {
return
}
- if (error || gResult.error) {
+ if (error || gResult.error || mkrError) {
return
}
diff --git a/src/containers/VotingHistory/index.tsx b/src/containers/VotingHistory/index.tsx
index 6e1f64a..5c7235b 100644
--- a/src/containers/VotingHistory/index.tsx
+++ b/src/containers/VotingHistory/index.tsx
@@ -1,4 +1,4 @@
-import React, { useState, useEffect } from 'react'
+import React from 'react'
import { useQuery } from '@apollo/react-hooks'
import { PageTitle, FullLoading } from '../../components/common'
import { DEFAULT_FETCH_ROWS } from '../../constants'
diff --git a/src/hooks/queries.tsx b/src/hooks/queries.tsx
index d4f2208..4eef6b8 100644
--- a/src/hooks/queries.tsx
+++ b/src/hooks/queries.tsx
@@ -109,17 +109,25 @@ export const POLLS_FIRST_QUERY = gql`
`
const getPollsData = (pageIndex, pageSize, offset, ordering) => {
return `
- polls_${pageIndex}: polls(first: ${pageSize}, skip: ${offset}, ${ordering}, where: { id_not_in: [0,1,2,3,6,7,8,9,11] }) {
- ...pollsDetail
- }
+ polls_${pageIndex}: polls(first: ${pageSize}, skip: ${offset}, ${ordering}, where: { id_not_in: [0,1,2,3,6,7,8,9,11] }) {
+ ...pollsDetail
+ }
`
}
const getExecutivesData = (pageIndex, pageSize, offset, ordering) => {
return `
- executives_${pageIndex}: spells(first: ${pageSize}, skip: ${offset}, ${ordering}) {
- ...executivesDetailHome
- }
+ executives_${pageIndex}: spells(first: ${pageSize}, skip: ${offset}, ${ordering}) {
+ ...executivesDetailHome
+ }
+ `
+}
+
+const getVotersData = (pageIndex, pageSize, offset, ordering) => {
+ return `
+ voters_${pageIndex}: actions(where: { type: VOTER }, first: ${pageSize}, skip: ${offset}, ${ordering}) {
+ ...actionsDetail
+ }
`
}
@@ -143,27 +151,11 @@ const getHomeData = (pageIndex, pageSize, offset, ordering) => {
`
}
-export const HOME_DATA_QUERY2 = gql`
- query getHomeData2($voters: Int!) {
- ${getAllEvents(getPollsData, 'startDate')}
- ${getAllEvents(getExecutivesData)}
- voters: actions(where: { type: VOTER }, first: $voters) {
- ...actionsDetail
- }
- ${getAllEvents(getHomeData)}
- }
- ${pollsDetailFragment}
- ${executivesDetailFragment}
- ${actionsDetailFragment}
-`
-
-export const HOME_DATA_QUERY = ({ pollPages, executivesPages }) => gql`
- query getHomeData($voters: Int!) {
+export const HOME_DATA_QUERY = ({ pollPages, executivesPages, votersPages }) => gql`
+ query getHomeData {
${getAllEvents(getExecutivesData, 'timestamp', executivesPages)}
${getAllEvents(getPollsData, 'startDate', pollPages)}
- voters: actions(where: { type: VOTER }, first: $voters) {
- ...actionsDetail
- }
+ ${getAllEvents(getVotersData, 'timestamp', votersPages)}
${getAllEvents(getHomeData)}
}
${pollsDetailFragment}
diff --git a/src/hooks/useHomeData.tsx b/src/hooks/useHomeData.tsx
index 7659d96..ea43049 100644
--- a/src/hooks/useHomeData.tsx
+++ b/src/hooks/useHomeData.tsx
@@ -7,18 +7,12 @@ import { mergeEventPages } from '../utils'
const REACT_APP_HOME_DATA_TTL = Number(process.env.REACT_APP_HOME_DATA_TTL) || 5
-const getHomeVariables = data => {
- const governance = data.governanceInfo
- return {
- voters: Number(governance.countProxies) + Number(governance.countAddresses) || 1000,
- }
-}
-
const getPages = gData => {
if (!gData) {
return {
pollPages: 2,
executivesPages: 2,
+ votersPages: 1,
}
}
@@ -26,6 +20,7 @@ const getPages = gData => {
return {
pollPages: Math.ceil(Number(governanceInfo.countPolls) / 1000),
executivesPages: Math.ceil(Number(governanceInfo.countSpells) / 1000),
+ votersPages: Math.ceil((Number(governanceInfo.countProxies) + Number(governanceInfo.countAddresses)) / 1000),
}
}
@@ -34,7 +29,6 @@ export function useHomeData(governanceInfo: Maybe): any {
const [results, setResults] = useState>(null)
const [loading, setLoading] = useState(true)
const { data, error } = useQuery(HOME_DATA_QUERY(getPages(governanceInfo)), {
- variables: governanceInfo && getHomeVariables(governanceInfo),
skip: skipQuery,
})
diff --git a/src/types/generatedGQL.ts b/src/types/generatedGQL.ts
index 1e146ac..cb0c55b 100644
--- a/src/types/generatedGQL.ts
+++ b/src/types/generatedGQL.ts
@@ -1181,39 +1181,6 @@ export interface getHistoryDataVariables {
/* eslint-disable */
// This file was automatically generated and should not be edited.
-// ====================================================
-// GraphQL query operation: getHomeData2
-// ====================================================
-
-export interface getHomeData2_voters {
- __typename: 'Action'
- id: string
- /**
- * Action timestamp as seconds (time)
- */
- timestamp: any
- /**
- * Action value (arg)
- */
- wad: any | null
- /**
- * Action name (act)
- */
- type: ActionType
-}
-
-export interface getHomeData2 {
- voters: getHomeData2_voters[]
-}
-
-export interface getHomeData2Variables {
- voters: number
-}
-
-/* tslint:disable */
-/* eslint-disable */
-// This file was automatically generated and should not be edited.
-
// ====================================================
// GraphQL fragment: executivesDetailPage
// ====================================================
diff --git a/src/utils/index.tsx b/src/utils/index.tsx
index 95352af..421cc94 100644
--- a/src/utils/index.tsx
+++ b/src/utils/index.tsx
@@ -22,7 +22,6 @@ import {
differenceInMinutes,
differenceInHours,
differenceInDays,
- differenceInWeeks,
differenceInMonths,
differenceInYears,
addHours,
@@ -30,7 +29,7 @@ import {
isBefore,
} from 'date-fns'
import { LAST_YEAR, LAST_MONTH, LAST_WEEK, LAST_DAY } from '../constants'
-import store, { setCache, getCache } from './cache'
+import { setCache, getCache } from './cache'
export * from './mkr-registry'
@@ -181,7 +180,7 @@ export const getVotersSnapshots = async voters => {
const snapshotsCache = (await getCache('accounts-snapshots-cache')) || {}
const requiredVoters = voters.reduce((acc, voter) => {
- const { lastUpdate, data } = snapshotsCache[voter] || {}
+ const { lastUpdate } = snapshotsCache[voter] || {}
// Do not update for 1/2 hour
if (!lastUpdate || getUnixTime(addMinutes(fromUnixTime(lastUpdate), 30)) < endDate) {
return [...acc, { voter, endDate }]
@@ -488,7 +487,6 @@ export const getPollData = async (poll, balancesLookup) => {
// TODO - improve function naming (snapshots of acctual voting addresses)
export const getPollsBalances = async polls => {
- const now = new Date()
const allVoters = Array.from(
new Set(polls.flatMap(poll => poll.votes.reduce((voters, v) => [...voters, v.voter], []))),
)