From 92674ef5b2e254473d8e5dd38f37982c9114aee9 Mon Sep 17 00:00:00 2001 From: Dalena Date: Mon, 25 Nov 2024 09:31:51 -0600 Subject: [PATCH] fix: token flag for cluster pay (#171) * fix: token flag for cluster pay * fix: check token symbol in list * fix: use convert to check for address * fix: accepted tokens * fix: add finally * refactor: use else case, not opposite if --------- Co-authored-by: El De-dog-lo <3859395+fubuloubu@users.noreply.github.com> --- silverback/_cli.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/silverback/_cli.py b/silverback/_cli.py index 043ff5e6..d5b14aa1 100644 --- a/silverback/_cli.py +++ b/silverback/_cli.py @@ -6,6 +6,7 @@ import click import yaml # type: ignore[import-untyped] +from ape import Contract, convert from ape.cli import ( AccountAliasPromptChoice, ConnectedProviderCommand, @@ -14,8 +15,9 @@ ape_cli_context, network_option, ) -from ape.exceptions import Abort, ApeException +from ape.exceptions import Abort, ApeException, ConversionError from ape.logging import LogLevel +from ape.types import AddressType from silverback._click_ext import ( SectionedHelpGroup, @@ -546,8 +548,20 @@ def create_payment_stream( sm = platform.get_stream_manager(network.chain_id) product = configuration.get_product_code(account.address, cluster.id) - if not token: - accepted_tokens = platform.get_accepted_tokens(network.chain_id) + accepted_tokens = platform.get_accepted_tokens(network.chain_id) + if token: + try: + convert(token, AddressType) + token_symbol = Contract(token).symbol() + except ConversionError: + token_symbol = token + finally: + token = accepted_tokens.get(token_symbol) + + if token is None: + raise click.UsageError(f"Token not found in accepted tokens: {accepted_tokens}.") + + else: token = accepted_tokens.get( click.prompt( "Select one of the following tokens to fund your stream with",