@@ -27,7 +27,7 @@ import {
27
27
PageTitle ,
28
28
PageSubTitle ,
29
29
} from '../common'
30
- import { getPollsData , getMKRSupply } from '../../utils/makerdao'
30
+ import { getPollsMetaData } from '../../utils/makerdao'
31
31
import { getModalContainer , getPollData , getPollsBalances } from '../../utils'
32
32
import {
33
33
getStakedMkrData ,
@@ -50,6 +50,7 @@ import {
50
50
//getActivenessBreakdown,
51
51
getMostVotedPolls ,
52
52
getRecentPolls ,
53
+ getMKRResponsiveness ,
53
54
} from './helpers'
54
55
import styled from 'styled-components'
55
56
import LinkableComponent from '../common/LinkableComponent'
@@ -72,6 +73,7 @@ const Loading = () => (
72
73
73
74
const getParticipation = ( data , mkrSupply ) => {
74
75
const totalMkr : BigNumber = data . reduce ( ( acc , value ) => acc . plus ( new BigNumber ( value . mkr ) ) , new BigNumber ( '0' ) )
76
+
75
77
return totalMkr
76
78
. times ( 100 )
77
79
. div ( mkrSupply )
@@ -89,71 +91,75 @@ type Props = {
89
91
}
90
92
91
93
function HomeDetail ( props : Props ) {
92
- const { data, gData, history, executivesResponsiveness } = props
94
+ const { data, gData, history } = props
93
95
const { governanceInfo } = gData
94
96
const [ isModalOpen , setModalOpen ] = useState ( false )
95
- const cachedDataPoll = lscache . get ( 'home-polls' ) || [ ]
96
- const cachedMkrSupply = lscache . get ( 'mkr-supply' ) || undefined
97
-
98
- const cachedDataTopVoters = lscache . get ( 'home-topVoters' ) || [ ]
99
- const cachedDataPollsResponsiveness = lscache . get ( 'polls-responsiveness' ) || [ ]
100
97
101
98
const [ isModalChart , setModalChart ] = useState ( false )
102
99
const [ chartFilters , setChartFilters ] = useState ( defaultFilters )
103
- const [ mkrSupply , setMkrSupply ] = useState < BigNumber | undefined > ( cachedMkrSupply )
104
- const [ pollsBalances , setBalances ] = useState < any > ( { } )
105
100
106
101
const [ modalData , setModalData ] = useState ( { type : '' , component : '' } )
107
- const [ topVoters , setTopVoters ] = useState < any [ ] > ( cachedDataTopVoters )
108
- const [ pollsResponsiveness , setPollsResponsiveness ] = useState < any [ ] > ( cachedDataPollsResponsiveness )
109
- // const [activenessBreakdown, setActivenessBreakdown ] = useState<any>([])
110
- // const [mkrActiveness, setMkrActiveness ] = useState<any>([])
102
+
103
+ const [ pollsResponsiveness , setPollsResponsiveness ] = useState < any [ ] > ( [ ] )
104
+ const [ topVoters , setTopVoters ] = useState < any [ ] > ( [ ] )
105
+ const [ polls , setPolls ] = useState < any [ ] > ( [ ] )
111
106
const [ mostVotedPolls , setMostVotedPolls ] = useState < any > ( [ ] )
112
- const [ stakedMkr , setStakedMkr ] = useState < any > ( [ ] )
113
107
const [ recentPolls , setRecentPolls ] = useState < any > ( [ ] )
114
108
115
- const [ polls , setPolls ] = useState < any [ ] > ( cachedDataPoll . length === 0 ? data . polls : cachedDataPoll )
116
-
117
109
const pollcolumns = expanded => Pollcolumns ( expanded )
118
- const votedPollcolumns = ( ) => VotedPollcolumns ( )
119
-
120
- useEffect ( ( ) => {
121
- if ( cachedDataPoll . length === 0 ) getPollsBalances ( polls ) . then ( balances => setBalances ( balances ) )
122
- if ( cachedDataPollsResponsiveness . length === 0 )
123
- getPollsMKRResponsiveness ( polls ) . then ( responsiveness => setPollsResponsiveness ( responsiveness ) )
124
- } , [ polls , cachedDataPoll . length , cachedDataPollsResponsiveness . length ] )
125
-
126
- useEffect ( ( ) => {
127
- if ( ! mkrSupply ) {
128
- getMKRSupply ( ) . then ( supply => setMkrSupply ( supply ) )
129
- }
130
- } , [ mkrSupply ] )
131
-
132
110
const executiveColumns = expanded => Executivecolumns ( expanded )
133
111
const topVotersColumns = ( ) => TopVotersColumns ( )
112
+ const votedPollcolumns = ( ) => VotedPollcolumns ( )
134
113
const uncastedExecutiveColumns = ( ) => UncastedExecutivecolumns ( )
135
- //const activenessBreakdownColumns = () => ActivenessBreakdownColumns()
136
114
137
- const executives = data . executives
115
+ useEffect ( ( ) => {
116
+ if ( data && data . polls . length && data . executives . length && data . mkrSupply ) {
117
+ getPollsBalances ( data . polls ) . then ( votersSnapshots => {
118
+ // TODO - improve function naming (snapshots of acctual voting addresses)
119
+ getPollsMetaData ( data . polls ) . then ( polls => {
120
+ Promise . all (
121
+ polls . map ( poll => {
122
+ return getPollData ( poll , votersSnapshots ) . then ( pollData => {
123
+ return { ...poll , participation : getParticipation ( pollData , data . mkrSupply ) }
124
+ } )
125
+ } ) ,
126
+ ) . then ( pollsWithPluralityAndParticipation => {
127
+ getPollsMKRResponsiveness ( polls ) . then ( responsiveness => {
128
+ // TODO - are all this state needed?
129
+ setPollsResponsiveness ( responsiveness )
130
+ setPolls ( pollsWithPluralityAndParticipation )
131
+ setTopVoters ( getTopVoters ( data . executives , pollsWithPluralityAndParticipation ) )
132
+ setMostVotedPolls ( getMostVotedPolls ( pollsWithPluralityAndParticipation ) )
133
+ setRecentPolls ( getRecentPolls ( pollsWithPluralityAndParticipation ) )
134
+ } )
135
+ } )
136
+ } )
137
+ } )
138
+ }
139
+ } , [ data ] )
138
140
141
+ //////////////////
142
+ const [ stakedMkr , setStakedMkr ] = useState < any > ( [ ] )
139
143
useEffect ( ( ) => {
140
144
setStakedMkr ( getStakedMkrData ( data , chartFilters . stakedMkr ) )
141
145
} , [ data , chartFilters . stakedMkr ] )
142
146
147
+ const giniData = useMemo ( ( ) => getGiniData ( [ ...data . free , ...data . lock ] , chartFilters . gini ) , [
148
+ data ,
149
+ chartFilters . gini ,
150
+ ] )
151
+
152
+ const cachedDataExecutivesResponsiveness = lscache . get ( 'executives-responsiveness' ) || [ ]
153
+ const [ executivesResponsiveness , setExecutivesResponsiveness ] = useState < any > ( cachedDataExecutivesResponsiveness )
143
154
useEffect ( ( ) => {
144
- if ( cachedDataTopVoters . length === 0 ) {
145
- setTopVoters ( getTopVoters ( executives , polls ) )
155
+ if ( data && data . executives && cachedDataExecutivesResponsiveness . length === 0 ) {
156
+ const responsiveness = getMKRResponsiveness ( data . executives )
157
+ lscache . set ( 'executives-responsiveness' , responsiveness , DEFAULT_CACHE_TTL )
158
+ setExecutivesResponsiveness ( responsiveness )
146
159
}
147
- } , [ executives , polls , cachedDataTopVoters . length ] )
160
+ } , [ data , cachedDataExecutivesResponsiveness . length ] )
148
161
149
- useEffect ( ( ) => {
150
- setMostVotedPolls ( getMostVotedPolls ( polls ) )
151
- setRecentPolls ( getRecentPolls ( polls ) )
152
- } , [ polls ] )
153
- useEffect ( ( ) => {
154
- //setActivenessBreakdown(getActivenessBreakdown(executives))
155
- //setMkrActiveness(getMKRActiveness(executives))
156
- } , [ executives ] )
162
+ /////////////////
157
163
158
164
const getPoll = row => {
159
165
if ( row . id ) history . push ( `/poll/${ row . id } ` )
@@ -163,8 +169,6 @@ function HomeDetail(props: Props) {
163
169
if ( row . id ) history . push ( `/executive/${ row . id } ` )
164
170
}
165
171
166
- // Data map for building this page
167
- const giniData = getGiniData ( [ ...data . free , ...data . lock ] , chartFilters . gini )
168
172
const homeMap = {
169
173
table : {
170
174
polls : {
@@ -315,7 +319,7 @@ function HomeDetail(props: Props) {
315
319
) ,
316
320
} ,
317
321
mkrDistributionPerExecutive : {
318
- data : getMkrDistributionPerExecutive ( executives , governanceInfo ? governanceInfo . hat : null ) ,
322
+ data : getMkrDistributionPerExecutive ( data . executives , governanceInfo ? governanceInfo . hat : null ) ,
319
323
component : props => (
320
324
< MkrDistributionPerExecutive
321
325
expanded
@@ -519,31 +523,6 @@ function HomeDetail(props: Props) {
519
523
setModalData ( data )
520
524
}
521
525
522
- useEffect ( ( ) => {
523
- if ( mkrSupply ) {
524
- getPollsData ( data . polls ) . then ( result => {
525
- const polls = result . filter ( Boolean )
526
- setPolls ( [ ...polls ] )
527
- Promise . all (
528
- polls . map ( poll => {
529
- return getPollData ( poll , pollsBalances ) . then ( data => {
530
- return { ...poll , participation : getParticipation ( data , mkrSupply ) }
531
- } )
532
- } ) ,
533
- ) . then ( pollsWithPluralityAndParticipation => {
534
- setPolls ( pollsWithPluralityAndParticipation )
535
- } )
536
- } )
537
- }
538
- } , [ data . polls , mkrSupply , pollsBalances ] )
539
-
540
- useEffect ( ( ) => {
541
- lscache . set ( 'mkr-supply' , mkrSupply , DEFAULT_CACHE_TTL )
542
- lscache . set ( 'home-polls' , polls , DEFAULT_CACHE_TTL )
543
- lscache . set ( 'home-topVoters' , topVoters , DEFAULT_CACHE_TTL )
544
- lscache . set ( 'polls-responsiveness' , pollsResponsiveness , DEFAULT_CACHE_TTL )
545
- } , [ mkrSupply , polls , topVoters , pollsResponsiveness ] )
546
-
547
526
return (
548
527
< >
549
528
< PageTitle > System Statistics</ PageTitle >
0 commit comments