Repository: safe-global/safe-config-service

Issue:
Restrict chain theme colours to RRGGBB
For improved compatibility between the data stored in the config service and the clients that will consume the `theme` payload (web, iOS, Android), we should remove the Alpha channel support from the color formats of `theme`.


Discussion:

Resolving patch:
diff --git a/src/chains/migrations/0006_change_color_default_help_text.py b/src/chains/migrations/0006_change_color_default_help_text.py
new file mode 100644
--- /dev/null
+++ b/src/chains/migrations/0006_change_color_default_help_text.py
@@ -0,0 +1,44 @@
+# Generated by Django 3.2.4 on 2021-07-01 08:46
+
+import re
+
+import django.core.validators
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("chains", "0005_chain_relevance"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="chain",
+            name="theme_background_color",
+            field=models.CharField(
+                default="#000000",
+                help_text="Please use the following format: <em>#RRGGBB</em>.",
+                max_length=9,
+                validators=[
+                    django.core.validators.RegexValidator(
+                        re.compile("^#[0-9a-fA-F]{6}$"), "Invalid hex color", "invalid"
+                    )
+                ],
+            ),
+        ),
+        migrations.AlterField(
+            model_name="chain",
+            name="theme_text_color",
+            field=models.CharField(
+                default="#ffffff",
+                help_text="Please use the following format: <em>#RRGGBB</em>.",
+                max_length=9,
+                validators=[
+                    django.core.validators.RegexValidator(
+                        re.compile("^#[0-9a-fA-F]{6}$"), "Invalid hex color", "invalid"
+                    )
+                ],
+            ),
+        ),
+    ]
diff --git a/src/chains/models.py b/src/chains/models.py
--- a/src/chains/models.py
+++ b/src/chains/models.py
@@ -4,7 +4,7 @@
 from django.core.validators import RegexValidator
 from django.db import models
 
-HEX_ARGB_REGEX = re.compile("^#(?:[0-9a-fA-F]{3,4}){1,2}$")
+HEX_ARGB_REGEX = re.compile("^#[0-9a-fA-F]{6}$")
 
 color_validator = RegexValidator(HEX_ARGB_REGEX, "Invalid hex color", "invalid")
 
@@ -22,10 +22,16 @@ class Chain(models.Model):
     currency_decimals = models.IntegerField(default=18)
     transaction_service_url = models.URLField(null=True)
     theme_text_color = models.CharField(
-        validators=[color_validator], max_length=9, default="#fff"
+        validators=[color_validator],
+        max_length=9,
+        default="#ffffff",
+        help_text="Please use the following format: <em>#RRGGBB</em>.",
     )
     theme_background_color = models.CharField(
-        validators=[color_validator], max_length=9, default="#000"
+        validators=[color_validator],
+        max_length=9,
+        default="#000000",
+        help_text="Please use the following format: <em>#RRGGBB</em>.",
     )
     gas_price_oracle_url = models.URLField(blank=True, null=True)
     gas_price_oracle_parameter = models.CharField(blank=True, null=True, max_length=255)


Test patch:
diff --git a/src/chains/tests/test_models.py b/src/chains/tests/test_models.py
--- a/src/chains/tests/test_models.py
+++ b/src/chains/tests/test_models.py
@@ -57,7 +57,18 @@ class ChainColorValidationTestCase(TransactionTestCase):
     faker = Faker()
 
     def test_invalid_text_colors(self):
-        param_list = ["aaa", "bbb", "#fffffffff", "zzz", "010", "", "a word", "#hhh"]
+        param_list = [
+            "aaa",
+            "bbb",
+            "#fffffffff",
+            "zzz",
+            "010",
+            "",
+            "a word",
+            "#hhh",
+            "#fff",
+            "#ffffffff",
+        ]
         for invalid_color in param_list:
             with self.subTest(msg=f"Invalid color {invalid_color} should throw"):
                 with self.assertRaises(
@@ -71,7 +82,7 @@ def test_invalid_text_colors(self):
                     chain.full_clean()
 
     def test_valid_text_colors(self):
-        param_list = ["#000", "#fff", "#00000000", "#ffffffff"] + [
+        param_list = ["#000000", "#ffffff"] + [
             self.faker.hex_color() for _ in range(20)
         ]
         for valid_color in param_list: