Skip to content

Commit f8c07b5

Browse files
feat: reviews link resolved against env (#2671)
1 parent 45fea24 commit f8c07b5

File tree

7 files changed

+136
-113
lines changed

7 files changed

+136
-113
lines changed

catalyst_voices/apps/voices/lib/common/constants/constants.dart

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,47 @@
11
import 'package:catalyst_cardano_serialization/catalyst_cardano_serialization.dart';
2+
import 'package:catalyst_voices/dependency/dependencies.dart';
3+
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
24

35
abstract class VoicesConstants {
6+
static const _docs = 'https://docs.projectcatalyst.io';
7+
static const _catalystApp = '$_docs/catalyst-tools/catalyst-app';
8+
49
/// External urls
5-
static const supportedWalletsUrl =
6-
'https://docs.projectcatalyst.io/current-fund/voter-registration/supported-wallets';
7-
static const tosUrl =
8-
'https://docs.projectcatalyst.io/current-fund/fund-basics/project-catalyst-terms-and-conditions';
10+
static const supportedWalletsUrl = '$_docs/current-fund/voter-registration/supported-wallets';
11+
static const tosUrl = '$_docs/current-fund/fund-basics/project-catalyst-terms-and-conditions';
912
static const privacyPolicyUrl =
10-
'https://docs.projectcatalyst.io/current-fund/fund-basics/project-catalyst-terms-and-conditions/catalyst-fc-privacy-policy';
13+
'$_docs/current-fund/fund-basics/project-catalyst-terms-and-conditions/catalyst-fc-privacy-policy';
1114
static const supportUrl = 'https://catalystiog.zendesk.com/hc/en-us/requests/new';
12-
static const docsUrl = 'https://docs.projectcatalyst.io/';
13-
static const beforeSubmissionUrl =
14-
'https://docs.projectcatalyst.io/catalyst-tools/catalyst-app/app-timeline#before-submission';
15-
static const afterSubmissionUrl =
16-
'https://docs.projectcatalyst.io/catalyst-tools/catalyst-app/stay-involved';
17-
static const becomeReviewerUrl = 'https://reviews.projectcatalyst.io/';
18-
static const votingRegistrationUrl =
19-
'https://docs.projectcatalyst.io/current-fund/voter-registration';
15+
static const docsUrl = '$_docs/';
16+
static const beforeSubmissionUrl = '$_catalystApp/app-timeline#before-submission';
17+
static const afterSubmissionUrl = '$_catalystApp/stay-involved';
18+
static const votingRegistrationUrl = '$_docs/current-fund/voter-registration';
2019
static const walletTroubleshootingUrl =
21-
'https://docs.projectcatalyst.io/catalyst-tools/catalyst-app/getting-started#wallet-connect-troubleshooting';
22-
static const mobileExperienceUrl =
23-
'https://docs.projectcatalyst.io/catalyst-tools/catalyst-app/mobile-experience';
24-
static const catalystKnowledgeBaseUrl =
25-
'https://docs.projectcatalyst.io/catalyst-tools/catalyst-app';
20+
'$_catalystApp/getting-started#wallet-connect-troubleshooting';
21+
static const mobileExperienceUrl = '$_catalystApp/mobile-experience';
22+
static const catalystKnowledgeBaseUrl = _catalystApp;
2623
static const proposalPublishingDocsUrl =
27-
'https://docs.projectcatalyst.io/catalyst-tools/catalyst-app/create-and-submit-proposals-in-workspace#proposal-publishing';
28-
static const getStartedUrl =
29-
'https://docs.projectcatalyst.io/catalyst-tools/catalyst-app/getting-started';
30-
static const setupBaseProfileUrl =
31-
'https://docs.projectcatalyst.io/catalyst-tools/catalyst-app/getting-started#setup-base-profile';
32-
static const createCatalystKeychainUrl =
33-
'https://docs.projectcatalyst.io/catalyst-tools/catalyst-app/getting-started#create-catalyst-keychain';
24+
'$_catalystApp/create-and-submit-proposals-in-workspace#proposal-publishing';
25+
static const getStartedUrl = '$_catalystApp/getting-started';
26+
static const setupBaseProfileUrl = '$_catalystApp/getting-started#setup-base-profile';
27+
static const createCatalystKeychainUrl = '$_catalystApp/getting-started#create-catalyst-keychain';
3428
static const officiallySupportedWalletsUrl =
35-
'https://docs.projectcatalyst.io/catalyst-tools/catalyst-app/getting-started#officially-supported-wallets';
36-
static const linkCardanoWalletUrl =
37-
'https://docs.projectcatalyst.io/catalyst-tools/catalyst-app/getting-started#link-cardano-wallet-and-roles';
38-
static const selectRolesUrl =
39-
'https://docs.projectcatalyst.io/catalyst-tools/catalyst-app/getting-started#select-roles';
29+
'$_catalystApp/getting-started#officially-supported-wallets';
30+
static const linkCardanoWalletUrl = '$_catalystApp/getting-started#link-cardano-wallet-and-roles';
31+
static const selectRolesUrl = '$_catalystApp/getting-started#select-roles';
4032
static const submitRegistrationTransactionUrl =
41-
'https://docs.projectcatalyst.io/catalyst-tools/catalyst-app/getting-started#submit-registration-transaction';
42-
static const restoreKeychainUrl =
43-
'https://docs.projectcatalyst.io/catalyst-tools/catalyst-app/restore-keychain';
44-
static const myAccountUrl =
45-
'https://docs.projectcatalyst.io/catalyst-tools/catalyst-app/my-account';
33+
'$_catalystApp/getting-started#submit-registration-transaction';
34+
static const restoreKeychainUrl = '$_catalystApp/restore-keychain';
35+
static const myAccountUrl = '$_catalystApp/my-account';
4636
static const insertNewImageDocsUrl =
47-
'https://docs.projectcatalyst.io/catalyst-tools/catalyst-app/create-and-submit-proposals-in-workspace/using-images';
37+
'$_catalystApp/create-and-submit-proposals-in-workspace/using-images';
4838
static const joinNewsletterUrl = 'https://mpc.projectcatalyst.io/newsletter-signup';
49-
static const unlockAccountUrl =
50-
'https://docs.projectcatalyst.io/catalyst-tools/catalyst-app/my-account#lock-unlock-account';
51-
static const confirmSeedPhraseUrl =
52-
'https://docs.projectcatalyst.io/catalyst-tools/catalyst-app/getting-started#confirm-seed-phrase';
39+
static const unlockAccountUrl = '$_catalystApp/my-account#lock-unlock-account';
40+
static const confirmSeedPhraseUrl = '$_catalystApp/getting-started#confirm-seed-phrase';
41+
42+
static String becomeReviewerUrl() {
43+
return Dependencies.instance.get<AppEnvironment>().type.reviews.toString();
44+
}
5345

5446
static String cardanoScanStakeAddressUrl(ShelleyAddress stakeAddress) {
5547
switch (stakeAddress.network) {

catalyst_voices/apps/voices/lib/pages/dev_tools/widgets/environment_card.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,14 @@ class _EnvironmentCard extends StatelessWidget {
3232
title: const Text('Environment'),
3333
children: [
3434
ValueText(name: const Text('Env'), value: Text(env?.type.name.capitalize() ?? '-')),
35-
ValueText(name: const Text('GatewayUrl'), value: Text(env?.type.gateway.toString() ?? '-')),
36-
ValueText(name: const Text('ReviewsUrl'), value: Text(env?.type.reviews.toString() ?? '-')),
35+
ValueText(
36+
name: const Text('GatewayUrl'),
37+
value: Text(env?.type.appGatewayApi.toString() ?? '-'),
38+
),
39+
ValueText(
40+
name: const Text('ReviewsUrl'),
41+
value: Text(env?.type.appReviewsApi.toString() ?? '-'),
42+
),
3743
],
3844
);
3945
}

catalyst_voices/apps/voices/lib/pages/discovery/sections/stay_involved.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ class StayInvolved extends StatelessWidget {
3939
}
4040
}
4141

42+
class _CopyCatalystIdTipText extends StatelessWidget {
43+
const _CopyCatalystIdTipText();
44+
45+
@override
46+
Widget build(BuildContext context) {
47+
return TipText(
48+
context.l10n.tipCopyCatalystIdForReviewTool,
49+
style: context.textTheme.bodyMedium?.copyWith(color: context.colors.textOnPrimaryLevel1),
50+
);
51+
}
52+
}
53+
4254
class _Header extends StatelessWidget {
4355
const _Header();
4456

@@ -65,7 +77,7 @@ class _ReviewerCard extends StatelessWidget {
6577
children: [
6678
_StayInvolvedActionButton(
6779
title: context.l10n.becomeReviewer,
68-
urlString: VoicesConstants.becomeReviewerUrl,
80+
urlString: VoicesConstants.becomeReviewerUrl(),
6981
trailing: VoicesAssets.icons.externalLink.buildIcon(),
7082
),
7183
const SizedBox(width: 24),
@@ -76,18 +88,6 @@ class _ReviewerCard extends StatelessWidget {
7688
}
7789
}
7890

79-
class _CopyCatalystIdTipText extends StatelessWidget {
80-
const _CopyCatalystIdTipText();
81-
82-
@override
83-
Widget build(BuildContext context) {
84-
return TipText(
85-
context.l10n.tipCopyCatalystIdForReviewTool,
86-
style: context.textTheme.bodyMedium?.copyWith(color: context.colors.textOnPrimaryLevel1),
87-
);
88-
}
89-
}
90-
9191
class _StayInvolvedActionButton extends StatelessWidget with LaunchUrlMixin {
9292
final String title;
9393
final String urlString;

catalyst_voices/apps/voices/lib/pages/spaces/drawer/opportunities_drawer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class _BecomeReviewerCard extends StatelessWidget with LaunchUrlMixin {
7070
const SizedBox(height: 20),
7171
_OpportunityActionButton(
7272
onTap: () async {
73-
await launchUri(VoicesConstants.becomeReviewerUrl.getUri());
73+
await launchUri(VoicesConstants.becomeReviewerUrl().getUri());
7474
},
7575
title: context.l10n.becomeReviewer,
7676
trailing: VoicesAssets.icons.externalLink.buildIcon(),

catalyst_voices/packages/internal/catalyst_voices_models/lib/src/config/app_environment.dart

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import 'package:equatable/equatable.dart';
33
import 'package:flutter/foundation.dart';
44

55
const _fallbackEnvType = kIsWeb ? AppEnvironmentType.relative : AppEnvironmentType.dev;
6+
const _projectCatalyst = 'projectcatalyst.io';
7+
final _envRegExp = RegExp(r'app\.([a-z]+)\.projectcatalyst\.io', caseSensitive: false);
68

79
final class AppEnvironment extends Equatable {
810
final AppEnvironmentType type;
@@ -48,6 +50,7 @@ final class AppEnvironment extends Equatable {
4850
List<Object?> get props => [type];
4951
}
5052

53+
/// See https://github.com/input-output-hk/catalyst-internal-docs/issues/178
5154
enum AppEnvironmentType {
5255
/// This type tells app to always talk to full, hardcoded dev backend
5356
/// url.
@@ -71,23 +74,57 @@ enum AppEnvironmentType {
7174
/// It useful when building app one time and it can be deployed anywhere.
7275
relative;
7376

74-
/// See https://github.com/input-output-hk/catalyst-internal-docs/issues/178
75-
Uri get baseUrl {
77+
Uri get app {
7678
return switch (this) {
77-
AppEnvironmentType.dev ||
78-
AppEnvironmentType.preprod =>
79-
Uri.https('app.$name.projectcatalyst.io'),
80-
AppEnvironmentType.prod => Uri.https('app.projectcatalyst.io'),
79+
AppEnvironmentType.dev || AppEnvironmentType.preprod => _getBaseUrl('app', envName: name),
80+
AppEnvironmentType.prod => _getBaseUrl('app'),
8181

8282
/// [AppEnvironmentType.relative] type does not now where its backends
8383
/// are hosted.
8484
AppEnvironmentType.relative => Uri(),
8585
};
8686
}
8787

88-
/// See https://github.com/input-output-hk/catalyst-internal-docs/issues/178
89-
Uri get gateway => baseUrl.replace(path: '/api/gateway');
88+
Uri get appGatewayApi => app.replace(path: '/api/gateway');
9089

91-
/// See https://github.com/input-output-hk/catalyst-internal-docs/issues/178
92-
Uri get reviews => baseUrl.replace(path: '/api/reviews');
90+
Uri get appReviewsApi => app.replace(path: '/api/reviews');
91+
92+
Uri get reviews {
93+
return switch (this) {
94+
AppEnvironmentType.dev || AppEnvironmentType.preprod => _getBaseUrl('reviews', envName: name),
95+
AppEnvironmentType.prod => _getBaseUrl('reviews'),
96+
AppEnvironmentType.relative => _getBaseUrl(
97+
'reviews',
98+
envName: tryUriBaseEnvName(from: Uri.base.toString()),
99+
),
100+
};
101+
}
102+
103+
Uri _getBaseUrl(
104+
String name, {
105+
String? envName,
106+
}) {
107+
final parts = [
108+
name,
109+
if (envName != null) envName,
110+
_projectCatalyst,
111+
];
112+
113+
final authority = parts.join('.');
114+
115+
return Uri.https(authority);
116+
}
117+
118+
@visibleForTesting
119+
static String? tryUriBaseEnvName({required String from}) {
120+
final match = _envRegExp.firstMatch(from);
121+
if (match != null && match.groupCount >= 1) {
122+
final value = match.group(1)!;
123+
if (AppEnvironmentType.values.any((element) => element.name == value)) {
124+
return value;
125+
}
126+
}
127+
128+
return null;
129+
}
93130
}

0 commit comments

Comments
 (0)