From fa2d304c8d479c2d76cd45c8863be411e67f4c41 Mon Sep 17 00:00:00 2001 From: dab246 Date: Wed, 10 Sep 2025 14:30:52 +0700 Subject: [PATCH] TF-3985 Prefer to use domain from platform rather than from email --- .../extensions/handle_paywall_extension.dart | 2 ++ .../domain/model/paywall_url_pattern.dart | 2 +- lib/main/routes/route_utils.dart | 16 ++++++++++ test/main/routes/route_utils_test.dart | 30 +++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/lib/features/mailbox_dashboard/presentation/extensions/handle_paywall_extension.dart b/lib/features/mailbox_dashboard/presentation/extensions/handle_paywall_extension.dart index 4657ddd82..e0f56a6a2 100644 --- a/lib/features/mailbox_dashboard/presentation/extensions/handle_paywall_extension.dart +++ b/lib/features/mailbox_dashboard/presentation/extensions/handle_paywall_extension.dart @@ -4,6 +4,7 @@ import 'package:tmail_ui_user/features/paywall/domain/model/paywall_url_pattern. import 'package:tmail_ui_user/features/paywall/domain/usecases/get_paywall_url_interactor.dart'; import 'package:tmail_ui_user/main/localizations/app_localizations.dart'; import 'package:tmail_ui_user/main/routes/route_navigation.dart'; +import 'package:tmail_ui_user/main/routes/route_utils.dart'; import 'package:tmail_ui_user/main/utils/app_utils.dart'; extension ValidateSaasPremiumAvailableExtension on MailboxDashBoardController { @@ -43,6 +44,7 @@ extension ValidateSaasPremiumAvailableExtension on MailboxDashBoardController { final qualifiedPaywall = paywallUrlPattern!.getQualifiedUrl( ownerEmail: ownEmailAddress.value, + domainName: RouteUtils.getRootDomain(), ); AppUtils.launchLink(qualifiedPaywall); diff --git a/lib/features/paywall/domain/model/paywall_url_pattern.dart b/lib/features/paywall/domain/model/paywall_url_pattern.dart index fcb7c2d1b..a237e5224 100644 --- a/lib/features/paywall/domain/model/paywall_url_pattern.dart +++ b/lib/features/paywall/domain/model/paywall_url_pattern.dart @@ -14,7 +14,7 @@ class PaywallUrlPattern with EquatableMixin { return PaywallUtils.buildPaywallUrlFromTemplate( template: pattern, localPart: mailAddress?.localPart, - domainName: mailAddress?.domain.domainName, + domainName: domainName ?? mailAddress?.domain.domainName, ); } diff --git a/lib/main/routes/route_utils.dart b/lib/main/routes/route_utils.dart index 554739f03..83e64565a 100644 --- a/lib/main/routes/route_utils.dart +++ b/lib/main/routes/route_utils.dart @@ -264,4 +264,20 @@ abstract class RouteUtils { static String generateMailtoLink(String mailAddress) { return '$baseOriginUrl/$mailtoPrefix/?uri=$mailtoPrefix:$mailAddress'; } + + static String? getRootDomain({String? hostname}) { + final host = hostname ?? html.window.location.hostname; + + if (host == null || host.isEmpty) { + return null; + } + + final parts = host.split('.'); + + if (parts.length >= 2) { + return '${parts[parts.length - 2]}.${parts.last}'; + } + + return host; + } } \ No newline at end of file diff --git a/test/main/routes/route_utils_test.dart b/test/main/routes/route_utils_test.dart index ee587d31f..78f55df2b 100644 --- a/test/main/routes/route_utils_test.dart +++ b/test/main/routes/route_utils_test.dart @@ -253,4 +253,34 @@ void main() { expect(result[RouteUtils.paramBody], equals(body)); }); }); + + group('getRootDomain', () { + test('should return null when hostname is empty', () { + expect(RouteUtils.getRootDomain(hostname: ''), isNull); + }); + + test('should return null when hostname is empty', () { + expect(RouteUtils.getRootDomain(hostname: ''), isNull); + }); + + test('should return root domain for simple domain', () { + expect(RouteUtils.getRootDomain(hostname: 'example.com'), 'example.com'); + }); + + test('should return root domain and remove subdomains', () { + expect(RouteUtils.getRootDomain(hostname: 'mail.dev.example.com'), 'example.com'); + }); + + test('should return root domain and remove www subdomain', () { + expect(RouteUtils.getRootDomain(hostname: 'www.google.com'), 'google.com'); + }); + + test('should return localhost as is', () { + expect(RouteUtils.getRootDomain(hostname: 'localhost'), 'localhost'); + }); + + test('should handle multi-level tld like co.uk (not fully accurate)', () { + expect(RouteUtils.getRootDomain(hostname: 'service.example.co.uk'), 'co.uk'); + }); + }); } \ No newline at end of file