Skip to content

Commit a0056e7

Browse files
committed
feat: added a function to convert chain formatted values to human readable in Token class
1 parent 28f1854 commit a0056e7

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

pyinjective/core/token.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ def convert_value_from_extended_decimal_format(value: Decimal) -> Decimal:
2525

2626
def chain_formatted_value(self, human_readable_value: Decimal) -> Decimal:
2727
return human_readable_value * Decimal(f"1e{self.decimals}")
28+
29+
def human_readable_value(self, chain_formatted_value: Decimal) -> Decimal:
30+
return chain_formatted_value / Decimal(f"1e{self.decimals}")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "injective-py"
3-
version = "1.11.0-rc5"
3+
version = "1.11.0-rc6"
44
description = "Injective Python SDK, with Exchange API Client"
55
authors = ["Injective Labs <contact@injectivelabs.org>"]
66
license = "Apache-2.0"

tests/core/test_token.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@ def test_chain_formatted_value(self, inj_token):
1111
expected_value = value * Decimal(f"1e{inj_token.decimals}")
1212

1313
assert chain_formatted_value == expected_value
14+
15+
def test_human_readable_value(self, inj_token):
16+
value = Decimal("1345600000000000000")
17+
18+
human_readable_value = inj_token.human_readable_value(chain_formatted_value=value)
19+
expected_value = value / Decimal(f"1e{inj_token.decimals}")
20+
21+
assert human_readable_value == expected_value

0 commit comments

Comments
 (0)