Skip to content

Fix: Estimated cost based on TX and not hardcoded value #359

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
19 changes: 11 additions & 8 deletions src/aleph_client/commands/instance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,17 +782,20 @@ async def delete(
fetched_settings = await fetch_settings()
community_wallet_timestamp = fetched_settings.get("community_wallet_timestamp")
community_wallet_address = fetched_settings.get("community_wallet_address")
try: # Safety check to ensure account can transact
account.can_transact()
except Exception as e:
echo(e)
raise typer.Exit(code=1) from e

echo("Deleting the flows...")
flow_crn_percent = Decimal("0.8") if community_wallet_timestamp < creation_time else Decimal("1")
flow_com_percent = Decimal("1") - flow_crn_percent
flow_hash_crn = await account.manage_flow(
payment.receiver, Decimal(price.required_tokens) * flow_crn_percent, FlowUpdate.REDUCE
)
try:
flow_hash_crn = await account.manage_flow(
payment.receiver, Decimal(price.required_tokens) * flow_crn_percent, FlowUpdate.REDUCE
)
except InsufficientFundsError as e:
echo(f"Error missing token type: {e.token_type}")
echo(f"Required : {e.required_funds}")
echo(f"Available : {e.available_funds}")
raise typer.Exit(code=1) from e

if flow_hash_crn:
echo(f"CRN flow has been deleted successfully (Tx: {flow_hash_crn})")
if flow_com_percent > Decimal("0"):
Expand Down
6 changes: 2 additions & 4 deletions src/aleph_client/commands/instance/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@
"/api/v0/aggregates/0xFba561a84A537fCaa567bb7A2257e7142701ae2A.json?keys=settings"
)

crn_list_link = (
f"{sanitize_url(settings.CRN_URL_FOR_PROGRAMS)}"
"/vm/bec08b08bb9f9685880f3aeb9c1533951ad56abef2a39c97f5a93683bdaa5e30/crns.json"
)
crn_list_vm = "bec08b08bb9f9685880f3aeb9c1533951ad56abef2a39c97f5a93683bdaa5e30"
crn_list_link = f"{settings.VM_URL_PATH.format(hash=crn_list_vm).rstrip('/')}/crns.json"

PATH_ABOUT_EXECUTIONS_LIST = "/about/executions/list"

Expand Down
17 changes: 13 additions & 4 deletions src/aleph_client/commands/pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,10 @@ def display_table_for(
row.append(internet_cell)
table.add_row(*row)

tier_data[tier_id] = SelectedTier(
tier=tier_id,
# Convert tier_id to int to ensure consistent typing
tier_id_int = int(tier_id)
tier_data[tier_id_int] = SelectedTier(
tier=tier_id_int,
compute_units=current_units,
vcpus=unit_vcpus * current_units,
memory=unit_memory * current_units,
Expand Down Expand Up @@ -302,9 +304,16 @@ def display_table_for(
)

if selector and pricing_entity not in [PricingEntity.STORAGE, PricingEntity.WEB3_HOSTING]:
# Make sure tier_data has at least one element before proceeding
if not tier_data:
typer.echo(f"No valid tiers found for {pricing_entity.value}")
raise typer.Exit(1)

if not auto_selected:
tier_id = validated_prompt("Select a tier by index", lambda tier_id: tier_id in tier_data)
return next(iter(tier_data.values())) if auto_selected else tier_data[tier_id]
tier_id = validated_prompt("Select a tier by index", lambda tier_id: int(tier_id) in tier_data)
# Convert tier_id to integer since we store it as integer keys in tier_data
return tier_data[int(tier_id)]
return next(iter(tier_data.values()))

return None

Expand Down
Loading
Loading