From 368a4001a7a007ae7cc88b5b2ab002ae0929be2d Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Thu, 21 Dec 2023 14:40:57 -0600 Subject: [PATCH] feat: default safe config --- ape_safe/__init__.py | 13 +++++++++++++ ape_safe/_cli/click_ext.py | 10 ++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ape_safe/__init__.py b/ape_safe/__init__.py index 2422253..4407700 100644 --- a/ape_safe/__init__.py +++ b/ape_safe/__init__.py @@ -1,9 +1,22 @@ +from typing import Optional + from ape import plugins +from ape.api import PluginConfig from .accounts import SafeAccount, SafeContainer from .multisend import MultiSend +class SafeConfig(PluginConfig): + default_safe: Optional[str] = None + """Alias of the default safe.""" + + +@plugins.register(plugins.Config) +def config_class(): + return SafeConfig + + @plugins.register(plugins.AccountPlugin) def account_types(): return SafeContainer, SafeAccount diff --git a/ape_safe/_cli/click_ext.py b/ape_safe/_cli/click_ext.py index e2f84b5..271bb68 100644 --- a/ape_safe/_cli/click_ext.py +++ b/ape_safe/_cli/click_ext.py @@ -1,7 +1,7 @@ from typing import NoReturn, Sequence, Union, cast import click -from ape import accounts +from ape import accounts, config from ape.cli import ApeCliContextObject, ape_cli_context from click import BadOptionUsage, MissingParameter @@ -29,8 +29,14 @@ def _safe_callback(ctx, param, value): # NOTE: For some reason, the Cli CTX object is not the SafeCliCtx yet at this point. safes = accounts.containers["safe"] if value is None: + # First, check config for a default. If one is there, + # we must use that. + safe_config = config.get_config("safe") + if alias := safe_config.default_safe: + return accounts.load(alias) + # If there is only 1 safe, just use that. - if len(safes) == 1: + elif len(safes) == 1: return next(safes.accounts) options = ", ".join(safes.aliases)