@@ -11,10 +11,10 @@ import {
1111import { formattedArrayBufferToHexString } from '../utils/formatters' ;
1212import walletUtils from '../utils/walletUtils' ;
1313import {
14- // VOTING_SNAPSHOT_DATE,
15- // VOTING_CAST_START_DATE,
16- // VOTING_CAST_END_DATE,
17- // VOTING_RESULTS_DATE,
14+ VOTING_SNAPSHOT_DATE ,
15+ VOTING_CAST_START_DATE ,
16+ VOTING_CAST_END_DATE ,
17+ VOTING_RESULTS_DATE ,
1818 VOTING_PHASE_CHECK_INTERVAL ,
1919 VOTING_REGISTRATION_TRANSACTION_POLLING_INTERVAL ,
2020 VOTING_REGISTRATION_MIN_TRANSACTION_CONFIRMATIONS ,
@@ -41,7 +41,13 @@ export type VotingDataType = {
4141 absoluteSlotNumber : number ,
4242} ;
4343
44- export type VotingPhase = 'Snapshot' | 'Voting' | 'Tallying' | 'Results' ;
44+ export type FundPhase = 'snapshot' | 'voting' | 'tallying' | 'results' ;
45+ export const FundPhases : EnumMap < string , FundPhase > = {
46+ SNAPSHOT : 'snapshot' ,
47+ VOTING : 'voting' ,
48+ TALLYING : 'tallying' ,
49+ RESULTS : 'results' ,
50+ } ;
4551
4652export default class VotingStore extends Store {
4753 @observable registrationStep : number = 1 ;
@@ -53,10 +59,10 @@ export default class VotingStore extends Store {
5359 @observable votingRegistrationKey : ?VotingRegistrationKeyType = null ;
5460 @observable qrCode : ?string = null ;
5561 @observable isConfirmationDialogOpen : boolean = false ;
56- @observable votingPhase : VotingPhase = 'Snapshot' ;
62+ @observable fundPhase : FundPhase = FundPhases . SNAPSHOT ;
5763
5864 transactionPollingInterval : ?IntervalID = null ;
59- votingPhaseInterval : ?IntervalID = null ;
65+ fundPhaseInterval : ?IntervalID = null ;
6066
6167 setup ( ) {
6268 const { voting : votingActions } = this . actions ;
@@ -71,7 +77,7 @@ export default class VotingStore extends Store {
7177 votingActions . resetRegistration . listen ( this . _resetRegistration ) ;
7278 votingActions . showConfirmationDialog . listen ( this . _showConfirmationDialog ) ;
7379 votingActions . closeConfirmationDialog . listen ( this . _closeConfirmationDialog ) ;
74- this . _initializeVotingPhaseInterval ( ) ;
80+ this . _initializeFundPhaseInterval ( ) ;
7581 }
7682
7783 // REQUESTS
@@ -130,9 +136,12 @@ export default class VotingStore extends Store {
130136 this . getWalletPublicKeyRequest . reset ( ) ;
131137 this . createVotingRegistrationTransactionRequest . reset ( ) ;
132138 this . signMetadataRequest . reset ( ) ;
133- if ( this . transactionPollingInterval )
139+ if ( this . transactionPollingInterval ) {
134140 clearInterval ( this . transactionPollingInterval ) ;
135- if ( this . votingPhaseInterval ) clearInterval ( this . votingPhaseInterval ) ;
141+ }
142+ if ( this . fundPhaseInterval ) {
143+ clearInterval ( this . fundPhaseInterval ) ;
144+ }
136145 } ;
137146
138147 @action _startTransactionPolling = ( ) => {
@@ -143,13 +152,13 @@ export default class VotingStore extends Store {
143152 } , VOTING_REGISTRATION_TRANSACTION_POLLING_INTERVAL ) ;
144153 } ;
145154
146- @action _initializeVotingPhaseInterval = ( ) => {
147- if ( this . votingPhaseInterval ) {
148- clearInterval ( this . votingPhaseInterval ) ;
155+ @action _initializeFundPhaseInterval = ( ) => {
156+ if ( this . fundPhaseInterval ) {
157+ clearInterval ( this . fundPhaseInterval ) ;
149158 }
150159
151- this . votingPhaseInterval = setInterval ( ( ) => {
152- this . _checkVotingPhase ( ) ;
160+ this . fundPhaseInterval = setInterval ( ( ) => {
161+ this . _checkFundPhase ( new Date ( ) ) ;
153162 } , VOTING_PHASE_CHECK_INTERVAL ) ;
154163 } ;
155164
@@ -439,8 +448,18 @@ export default class VotingStore extends Store {
439448 }
440449 } ;
441450
442- @action _checkVotingPhase = ( ) => {
443- this . votingPhase = 'Snapshot' ;
451+ @action _checkFundPhase = ( now : Date ) => {
452+ const phaseValidation = {
453+ [ FundPhases . SNAPSHOT ] : now < VOTING_CAST_START_DATE ,
454+ [ FundPhases . VOTING ] :
455+ now >= VOTING_CAST_START_DATE && now <= VOTING_CAST_END_DATE ,
456+ [ FundPhases . TALLYING ] :
457+ now > VOTING_CAST_END_DATE && now < VOTING_RESULTS_DATE ,
458+ [ FundPhases . RESULTS ] : now >= VOTING_RESULTS_DATE ,
459+ } ;
460+ this . fundPhase =
461+ Object . values ( FundPhases ) . find ( ( phase ) => phaseValidation [ phase ] ) ||
462+ FundPhases . SNAPSHOT ;
444463 } ;
445464
446465 _generateVotingRegistrationKey = async ( ) => {
0 commit comments