Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: token flag for cluster pay #171

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 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,19 @@ def create_payment_stream(
sm = platform.get_stream_manager(network.chain_id)
product = configuration.get_product_code(account.address, cluster.id)

accepted_tokens = platform.get_accepted_tokens(network.chain_id)
if token:
try:
convert(token, AddressType)
token_symbol = Contract(token).symbol()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could do something like check if it's an address, and then do this without a try...except

Copy link
Contributor Author

@dtdang dtdang Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried checking for an address without a try...except but even using convert will need one. The first method will check if it an address by association if the Contract(token) gives a value error but the new push checks using convert and will give a ConversionError. Both do the same thing but the second is more descriptive.

token = accepted_tokens.get(token_symbol)
except ConversionError:
token = accepted_tokens.get(token)

if token is None:
raise click.UsageError(f"Token not found in accepted tokens: {accepted_tokens}.")

if not token:
accepted_tokens = platform.get_accepted_tokens(network.chain_id)
token = accepted_tokens.get(
click.prompt(
"Select one of the following tokens to fund your stream with",
Expand Down
Loading