Skip to content

Commit 8e891e1

Browse files
committed
Add displayable amount
1 parent 84e6a80 commit 8e891e1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/aleph/sdk/exceptions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from abc import ABC
22

3+
from aleph.sdk.utils import displayable_amount
4+
35

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

7577
def __init__(self, required_funds: float, available_funds: float):
76-
self.required_funds = required_funds
77-
self.available_funds = available_funds
78+
self.required_funds = displayable_amount(required_funds)
79+
self.available_funds = displayable_amount(available_funds)
7880
super().__init__(
7981
f"Insufficient funds: required {required_funds}, available {available_funds}"
8082
)

src/aleph/sdk/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import subprocess
1010
from datetime import date, datetime, time
11+
from decimal import Decimal
1112
from enum import Enum
1213
from pathlib import Path
1314
from shutil import make_archive
@@ -418,6 +419,11 @@ def safe_getattr(obj, attr, default=None):
418419
return obj
419420

420421

422+
def displayable_amount(amount: float | Decimal | str) -> str:
423+
"""Returns the amount as a string with no trailing zeros or decimals."""
424+
return str(amount).rstrip("0").rstrip(".")
425+
426+
421427
def make_instance_content(
422428
rootfs: str,
423429
rootfs_size: int,

0 commit comments

Comments
 (0)