Skip to content

Commit

Permalink
feat: default safe config
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Dec 21, 2023
1 parent 252208e commit 368a400
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 13 additions & 0 deletions ape_safe/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 8 additions & 2 deletions ape_safe/_cli/click_ext.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 368a400

Please sign in to comment.