Verified Commit ce36557e authored by Jakob Moser's avatar Jakob Moser
Browse files

Implement formatter for colored balances

parent fc94e18e
Loading
Loading
Loading
Loading
+10 −0
Changes for poolpay/admin/money.py: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -9,6 +9,16 @@ def format_euros(cents: int) -> str:
    return format_currency(Decimal(cents) / 100, "EUR", locale="de_DE")


def format_balance(cents: int) -> Text:
    balance = Text(format_euros(cents))
    # TODO Find out why the following behavior occurs and if it is a bug:
    # Interestingly enough, setting style= directly to the same value in the Text constructor causes the
    # balance dialog to use the HTML styles (where the red and green are quite dark), while the data table
    # uses nicer 'theme' colors. With stylize, the theme colors are consistently used.
    balance.stylize("green" if cents > 0 else "red" if cents < 0 else "")

    return balance


def to_decimal_if_numeric(thing: str | Text) -> str | Decimal:
    str_value = thing.plain if isinstance(thing, Text) else thing