From 6f5c1b8e3fbe57df6537121f30455acdc95e5e7c Mon Sep 17 00:00:00 2001 From: Brian Choromanski Date: Thu, 17 Oct 2024 02:43:27 -0400 Subject: [PATCH] [auth] Bugfix/auth icons with period (#3559) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Previously it would check if the substring that precedes the first `.` or `(` of the lowercase spaceless provider title was a valid icon. Now: 1. Checks if lowercase spaceless provider title is valid icon 2. If the title contains a `(` it checks if the preceding part of the title is a valid icon 3. If the title contains a `.` it checks if the preceding part of the title is a valid icon | Provider Title | Previous Check | Now Checks | | -------- | ------- | ----------| | Login.gov | `login` ❌| `login.gov` ✅ | | GOV.UK (Brian) | `gov` ❌| `gov.uk(brian)`❌ then `gov.uk` ✅ | | PayPal.com (Visa) | `paypal` ✅ | `paypal.com(visa)` ❌ then `paypal.com` ❌ then `paypal` ✅| | Amazon.com | `amazon` ✅ | `amazon.com` ❌ then `amazon` ✅| This PR resolves issue #3473 --- auth/lib/ui/utils/icon_utils.dart | 48 +++++++++++++++++-------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/auth/lib/ui/utils/icon_utils.dart b/auth/lib/ui/utils/icon_utils.dart index 535ec6f4ae..ffc41699a1 100644 --- a/auth/lib/ui/utils/icon_utils.dart +++ b/auth/lib/ui/utils/icon_utils.dart @@ -17,6 +17,7 @@ class IconUtils { final Map _customIcons = {}; // Map of icon-color to its luminance final Map _colorLuminance = {}; + final List _titleSplitCharacters = ['(', '.']; Future init() async { await _loadJson(); @@ -27,31 +28,36 @@ class IconUtils { String provider, { double width = 24, }) { - final title = _getProviderTitle(provider); - if (_customIcons.containsKey(title)) { - return _getSVGIcon( - "assets/custom-icons/icons/${_customIcons[title]!.slug ?? title}.svg", - title, - _customIcons[title]!.color, - width, - context, - ); - } else if (_simpleIcons.containsKey(title)) { - return _getSVGIcon( - "assets/simple-icons/icons/$title.svg", - title, - _simpleIcons[title], - width, - context, - ); - } else if (title.isNotEmpty) { + final providerTitle = _getProviderTitle(provider); + final List titlesList = [providerTitle]; + titlesList.addAll(_titleSplitCharacters.where((char) => providerTitle.contains(char)).map((char) => providerTitle.split(char)[0])); + for(final title in titlesList){ + if (_customIcons.containsKey(title)) { + return _getSVGIcon( + "assets/custom-icons/icons/${_customIcons[title]!.slug ?? title}.svg", + title, + _customIcons[title]!.color, + width, + context, + ); + } else if (_simpleIcons.containsKey(title)) { + return _getSVGIcon( + "assets/simple-icons/icons/$title.svg", + title, + _simpleIcons[title], + width, + context, + ); + } + } + if (providerTitle.isNotEmpty) { bool showLargeIcon = width > 24; return CircleAvatar( radius: width / 2, backgroundColor: getEnteColorScheme(context).avatarColors[ - title.hashCode % getEnteColorScheme(context).avatarColors.length], + providerTitle.hashCode % getEnteColorScheme(context).avatarColors.length], child: Text( - title.toUpperCase()[0], + providerTitle.toUpperCase()[0], // fixed color style: showLargeIcon ? getEnteTextTheme(context).h3Bold.copyWith(color: Colors.white) @@ -146,7 +152,7 @@ class IconUtils { } String _getProviderTitle(String provider) { - return provider.split(RegExp(r'[.(]'))[0].replaceAll(' ', '').toLowerCase(); + return provider.replaceAll(' ', '').toLowerCase(); } }