Skip to content

Commit 0376de6

Browse files
author
Lucas Araujo
committed
[DDW-796] Fund phase logic
1 parent cd26d6a commit 0376de6

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

source/renderer/app/config/votingConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const VOTING_REGISTRATION_FEE_CALCULATION_AMOUNT = 1; // 1 ADA | unit: AD
88
export const VOTING_REGISTRATION_PIN_CODE_LENGTH = 4;
99
export const VOTING_REGISTRATION_MIN_TRANSACTION_CONFIRMATIONS = isDev ? 2 : 10;
1010
export const VOTING_REGISTRATION_TRANSACTION_POLLING_INTERVAL = 1000; // 1 second | unit: milliseconds
11-
export const VOTING_PHASE_CHECK_INTERVAL = 3000; // 3 seconds | unit: milliseconds
11+
export const VOTING_PHASE_CHECK_INTERVAL = 60000; // 60 seconds | unit: milliseconds
1212
export const VOTING_SNAPSHOT_DATE = new Date('Jan 6, 2022, 11:00 UTC');
1313
export const VOTING_CAST_START_DATE = new Date('Jan 13, 2022, 11:00 UTC');
1414
export const VOTING_CAST_END_DATE = new Date('Jan 27, 2022, 11:00 UTC');

source/renderer/app/stores/VotingStore.js

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import {
1111
import { formattedArrayBufferToHexString } from '../utils/formatters';
1212
import walletUtils from '../utils/walletUtils';
1313
import {
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

4652
export 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

Comments
 (0)