Additional verification
This commit is contained in:
parent
b05f889144
commit
028124e427
|
@ -512,15 +512,26 @@ class AssetAmount:
|
||||||
asset: Asset
|
asset: Asset
|
||||||
amount: Decimal
|
amount: Decimal
|
||||||
|
|
||||||
|
def __post_init__(self):
|
||||||
|
assert isinstance(self.asset, Asset), 'Incorrect value for self.asset'
|
||||||
|
assert isinstance(self.amount, Decimal), 'Incorrect value for self.amount'
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return self.human_readable_str()
|
return self.human_readable_str()
|
||||||
|
|
||||||
def human_readable_str(self) -> str:
|
def human_readable_str(self) -> str:
|
||||||
abs_amount = abs(self.amount)
|
abs_amount = abs(self.amount)
|
||||||
specificity = '2' if abs_amount >= THREE_DECIMALS_UNDER_THIS_AMOUNT else '3'
|
|
||||||
|
# Determine specificity
|
||||||
|
specificity = '3'
|
||||||
|
if abs_amount != abs_amount:
|
||||||
|
specificity = '0'
|
||||||
|
elif abs_amount >= THREE_DECIMALS_UNDER_THIS_AMOUNT:
|
||||||
|
specificity = '2'
|
||||||
|
|
||||||
prefix = ASSET_PREFIX.get(self.asset, '')
|
prefix = ASSET_PREFIX.get(self.asset, '')
|
||||||
return ('{sign}{prefix}{amount:.' + specificity + 'f} {name}').format(
|
return ('{sign}{prefix}{amount:.' + specificity + 'f} {name}').format(
|
||||||
sign='-' if self.amount < 0 else '',
|
sign='-' if (self.amount == self.amount and self.amount < 0) else '',
|
||||||
prefix=prefix,
|
prefix=prefix,
|
||||||
amount=abs_amount,
|
amount=abs_amount,
|
||||||
name=self.asset.raw_short_name(),
|
name=self.asset.raw_short_name(),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user