Skip to content

Commit

Permalink
fix: token flag for cluster pay (#171)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
dtdang and fubuloubu authored Nov 25, 2024
1 parent e949e04 commit 92674ef
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions silverback/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import click
import yaml # type: ignore[import-untyped]
from ape import Contract, convert
from ape.cli import (
AccountAliasPromptChoice,
ConnectedProviderCommand,
Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 92674ef

Please sign in to comment.