Skip to content

Commit 43b2b5e

Browse files
danielmainMarcin Mazurek
andauthored
[DDW-1186] Shows 'To be defined' if date of the next fund is in the past (#3105)
* [DDW-1216] Use new Catalyst API * [DDW-1216] Add changelog entry * [DDW-1186] Now showing 'To be defined' if date of the next fund coming from API is in the past * [DDW-1186] Changed JP translation * [DDW-1186] Apply the latest requirements on showing "To be defined" * [DDW-1186] Implement Catalyst testing utilities * [DDW-1186] Fix handling of URL override for Catalyst * [DDW-1186] Implement time machine for Catalyst voting testing * [DDW-1186] Fix time machine --------- Co-authored-by: Marcin Mazurek <[email protected]>
1 parent 2990883 commit 43b2b5e

File tree

15 files changed

+111
-17
lines changed

15 files changed

+111
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Features
66

7+
- Show "To be defined" if date of the next Catalyst fund is in the past ([PR 3105](https://github.com/input-output-hk/daedalus/pull/3105))
78
- Switched to the new Catalyst API ([PR 3129](https://github.com/input-output-hk/daedalus/pull/3129))
89

910
### Fixes

source/common/types/environment.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export type Environment = {
3535
isBlankScreenFixActive: boolean;
3636
keepLocalClusterRunning: boolean;
3737
analyticsFeatureEnabled: boolean;
38+
catalystApiUrlOverride?: string;
39+
votingVisibleOverride: boolean;
3840
};
3941
// constants
4042
export const PRODUCTION = 'production';

source/main/environment.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ export const environment: Environment = Object.assign(
112112
keepLocalClusterRunning,
113113
hasMetHardwareRequirements,
114114
analyticsFeatureEnabled,
115+
catalystApiUrlOverride: process.env.CATALYST_API_URL_OVERRIDE,
116+
votingVisibleOverride: process.env.VOTING_VISIBLE_OVERRIDE === 'true',
115117
},
116118
process.env
117119
);

source/renderer/app/api/voting/requests/getCatalystFund.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ import { externalRequest } from '../../utils/externalRequest';
22
import { CATALYST_API_URL } from '../../../config/urlsConfig';
33
import { GetCatalystFundResponse } from '../types';
44

5-
export const getCatalystFund = (): Promise<GetCatalystFundResponse> =>
6-
externalRequest({
7-
hostname: CATALYST_API_URL,
5+
export const getCatalystFund = (): Promise<GetCatalystFundResponse> => {
6+
const urlOverride: URL | undefined = environment.catalystApiUrlOverride
7+
? new URL(environment.catalystApiUrlOverride)
8+
: undefined;
9+
10+
return externalRequest({
11+
hostname: urlOverride ? urlOverride.hostname : CATALYST_API_URL,
812
path: '/api/v0/fund',
913
method: 'GET',
10-
protocol: 'https',
14+
port: urlOverride ? Number(urlOverride.port) : undefined,
15+
protocol: urlOverride ? urlOverride.protocol.replace(':', '') : 'https',
1116
});
17+
};

source/renderer/app/components/voting/voting-info/RegisterToVote.messages.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ export const messages = defineMessages({
2727
defaultMessage: '!!!Register to vote',
2828
description: 'Button Label for voting registration steps',
2929
},
30+
toBeDefined: {
31+
id: 'voting.resultsPhase.toBeDefined',
32+
defaultMessage: '!!!To be defined',
33+
description:
34+
'Text to show when Catalyst API is returning a past date value',
35+
},
3036
});

source/renderer/app/components/voting/voting-info/RegisterToVote.tsx

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useState } from 'react';
22
import { injectIntl } from 'react-intl';
3+
import moment from 'moment';
34
import { Button } from 'react-polymorph/lib/components/Button';
45
import { Checkbox } from 'react-polymorph/lib/components/Checkbox';
56
import {
@@ -13,6 +14,7 @@ import { messages as votingMessages } from './VotingInfo.messages';
1314
import styles from './RegisterToVote.scss';
1415
import votingStyles from './VotingInfo.scss';
1516
import type { CatalystFund } from '../../../api/voting/types';
17+
import { logger } from '../../../utils/logging';
1618

1719
type Props = {
1820
currentLocale: Locale;
@@ -23,6 +25,17 @@ type Props = {
2325
onRegisterToVoteClick: (...args: Array<any>) => any;
2426
};
2527

28+
const isFutureDate = (date: Date): boolean => {
29+
try {
30+
return moment().diff(date) < 0;
31+
} catch (error) {
32+
logger.error('Voting::NextFund::Invalid date', {
33+
error,
34+
});
35+
}
36+
return false;
37+
};
38+
2639
function RegisterToVote({
2740
currentLocale,
2841
currentDateFormat,
@@ -34,17 +47,19 @@ function RegisterToVote({
3447
const [step1, setStep1] = useState(false);
3548
const [step2, setStep2] = useState(false);
3649
const canRegister = step1 && step2;
37-
const snapshotDate = formattedDateTime(
38-
fundInfo.next.registrationSnapshotTime,
39-
{
40-
currentLocale,
41-
...mapToLongDateTimeFormat({
50+
const nextSnapshotDateTime = fundInfo.next.registrationSnapshotTime;
51+
52+
const snapshotDate = isFutureDate(nextSnapshotDateTime)
53+
? formattedDateTime(nextSnapshotDateTime, {
4254
currentLocale,
43-
currentDateFormat,
44-
currentTimeFormat,
45-
}),
46-
}
47-
);
55+
...mapToLongDateTimeFormat({
56+
currentLocale,
57+
currentDateFormat,
58+
currentTimeFormat,
59+
}),
60+
})
61+
: intl.formatMessage(messages.toBeDefined);
62+
4863
return (
4964
<div className={styles.root}>
5065
<span className={styles.title}>

source/renderer/app/config/urlsConfig.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ export const ALLOWED_EXTERNAL_HOSTNAMES = [
2525
TESTNET_NEWS_HASH_URL,
2626
STAGING_NEWS_HASH_URL,
2727
coingeckoConfig.hostname,
28-
CATALYST_API_URL,
28+
environment.catalystApiUrlOverride
29+
? new URL(environment.catalystApiUrlOverride).hostname
30+
: CATALYST_API_URL,
2931
];

source/renderer/app/containers/voting/VotingRegistrationPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from 'react';
2-
import { observer, inject } from 'mobx-react';
2+
import { inject, observer } from 'mobx-react';
33
import Layout from '../MainLayout';
44
import { VOTING_REGISTRATION_MIN_WALLET_FUNDS } from '../../config/votingConfig';
55
import VerticalFlexContainer from '../../components/layout/VerticalFlexContainer';

source/renderer/app/i18n/locales/defaultMessages.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4475,6 +4475,11 @@
44754475
"defaultMessage": "!!!Register to vote",
44764476
"description": "Button Label for voting registration steps",
44774477
"id": "voting.registerToVote.registerToVoteButtonLabel"
4478+
},
4479+
{
4480+
"defaultMessage": "!!!To be defined",
4481+
"description": "Text to show when Catalyst API is returning a past date value",
4482+
"id": "voting.resultsPhase.toBeDefined"
44784483
}
44794484
],
44804485
"path": "source/renderer/app/components/voting/voting-info/RegisterToVote.messages.ts"

source/renderer/app/i18n/locales/en-US.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@
731731
"voting.registerToVote.step2CheckBoxLabel": "Ensure that you register and hold the necessary 500 ADA at the time of the snapshot.",
732732
"voting.registerToVote.stepsTitle": "Follow these steps to vote:",
733733
"voting.resultsPhase.endDateLabel": "End of voting:",
734+
"voting.resultsPhase.toBeDefined": "To be defined",
734735
"voting.resultsPhase.viewResultsLinkLabel": "View results",
735736
"voting.resultsPhase.viewResultsLinkURL": "https://cardano.ideascale.com/a/pages/results",
736737
"voting.snapshotPhase.snapshotDateLabel": "Snapshot date:",

0 commit comments

Comments
 (0)