Skip to content

Commit

Permalink
Add displayable amount
Browse files Browse the repository at this point in the history
  • Loading branch information
philogicae committed Feb 6, 2025
1 parent 84e6a80 commit 8e891e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/aleph/sdk/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from abc import ABC

from aleph.sdk.utils import displayable_amount


class QueryError(ABC, ValueError):
"""The result of an API query is inconsistent."""
Expand Down Expand Up @@ -73,8 +75,8 @@ class InsufficientFundsError(Exception):
available_funds: float

def __init__(self, required_funds: float, available_funds: float):
self.required_funds = required_funds
self.available_funds = available_funds
self.required_funds = displayable_amount(required_funds)
self.available_funds = displayable_amount(available_funds)
super().__init__(
f"Insufficient funds: required {required_funds}, available {available_funds}"
)
Expand Down
6 changes: 6 additions & 0 deletions src/aleph/sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import subprocess
from datetime import date, datetime, time
from decimal import Decimal
from enum import Enum
from pathlib import Path
from shutil import make_archive
Expand Down Expand Up @@ -418,6 +419,11 @@ def safe_getattr(obj, attr, default=None):
return obj


def displayable_amount(amount: float | Decimal | str) -> str:
"""Returns the amount as a string with no trailing zeros or decimals."""
return str(amount).rstrip("0").rstrip(".")


def make_instance_content(
rootfs: str,
rootfs_size: int,
Expand Down

0 comments on commit 8e891e1

Please sign in to comment.