Skip to content

Commit

Permalink
Add default logo
Browse files Browse the repository at this point in the history
Remove gnosis on display name field
  • Loading branch information
moisses89 committed Oct 18, 2023
1 parent eb2604a commit 981a417
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from gnosis.eth import EthereumClientProvider
from gnosis.safe.safe_deployments import safe_deployments

from config.settings.base import STATICFILES_DIRS
from safe_transaction_service.contracts.models import Contract


Expand All @@ -16,6 +17,8 @@ def generate_safe_contract_display_name(contract_name: str, version: str) -> str
:param version:
:return: display_name
"""
# Remove gnosis word
contract_name = contract_name.replace("Gnosis", "")
if "safe" not in contract_name.lower():
return f"Safe: {contract_name} {version}"
else:
Expand All @@ -36,7 +39,11 @@ def add_arguments(self, parser):
default=False,
)
parser.add_argument(
"--logo-path", type=str, help="Path of new logo", required=True
"--logo-path",
type=str,
help="Path of new logo",
required=False,
default=f"{STATICFILES_DIRS[0]}/safe/safe_contract_logo.png",
)

def handle(self, *args, **options):
Expand All @@ -48,10 +55,10 @@ def handle(self, *args, **options):
:return:
"""
safe_version = options["safe_version"]
force_update_contract_names = options["force_update_contract_names"]
logo_path = options["logo_path"]
ethereum_client = EthereumClientProvider()
chain_id = ethereum_client.get_chain_id()
force_update_contract_names = options["force_update_contract_names"]
logo_file = File(open(logo_path, "rb"))
if not safe_version:
versions = list(safe_deployments.keys())
Expand Down
8 changes: 2 additions & 6 deletions safe_transaction_service/contracts/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from gnosis.eth import EthereumClient

from config.settings.base import STATICFILES_DIRS
from safe_transaction_service.contracts.models import Contract
from safe_transaction_service.contracts.tests.factories import ContractFactory

Expand Down Expand Up @@ -37,13 +36,11 @@ def test_update_safe_contracts_logo(self, mock_chain_id):
previous_random_contract_logo = random_contract.logo.read()
multisend_address = "0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761"
multisend_contract = ContractFactory(
address=multisend_address, name="Custom multisend"
address=multisend_address, name="GnosisMultisend"
)
multisend_contract_logo = multisend_contract.logo.read()

call_command(
command, f"--logo-path={STATICFILES_DIRS[0]}/safe/logo.png", stdout=buf
)
call_command(command, stdout=buf)
current_multisend_contract = Contract.objects.get(address=multisend_address)
# Previous created contracts logo should be updated
self.assertNotEqual(
Expand Down Expand Up @@ -80,7 +77,6 @@ def test_update_safe_contracts_logo(self, mock_chain_id):
call_command(
command,
"--force-update-contract-names",
f"--logo-path={STATICFILES_DIRS[0]}/safe/logo.png",
stdout=buf,
)
contract = Contract.objects.get(address=multisend_address)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Sequence, Tuple

from django.conf import settings
from django.core.management import call_command
from django.core.management.base import BaseCommand
from django.db.models import Min

Expand Down Expand Up @@ -212,6 +213,9 @@ def handle(self, *args, **options):
self.stdout.write(
self.style.WARNING("Cannot detect a valid ethereum-network")
)
else:
# Initialize contracts
call_command("update_safe_contracts_logo")

def _setup_safe_master_copies(
self, safe_master_copies: Sequence[Tuple[str, int, str]]
Expand Down
2 changes: 2 additions & 0 deletions safe_transaction_service/history/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@

class TestCommands(TestCase):
@mock.patch.object(EthereumClient, "get_network", autospec=True)
@mock.patch.object(EthereumClient, "get_chain_id", autospec=True, return_value=1)
def _test_setup_service(
self,
ethereum_network: EthereumNetwork,
ethereum_client_chain_id: MagicMock,
ethereum_client_get_network_mock: MagicMock,
):
command = "setup_service"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 981a417

Please sign in to comment.