mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
core+legacy: fix display of non-divisible OMNI amounts
This commit is contained in:
parent
5684983b3c
commit
c288514a4f
@ -2,7 +2,12 @@ from ustruct import unpack
|
||||
|
||||
from trezor.utils import format_amount
|
||||
|
||||
currencies = {1: "OMNI", 2: "tOMNI", 3: "MAID", 31: "USDT"}
|
||||
currencies = {
|
||||
1: ("OMNI", True),
|
||||
2: ("tOMNI", True),
|
||||
3: ("MAID", False),
|
||||
31: ("USDT", True),
|
||||
}
|
||||
|
||||
|
||||
def is_valid(data: bytes) -> bool:
|
||||
@ -15,9 +20,10 @@ def parse(data: bytes) -> bool:
|
||||
tx_version, tx_type = unpack(">HH", data[4:8])
|
||||
if tx_version == 0 and tx_type == 0 and len(data) == 20: # OMNI simple send
|
||||
currency, amount = unpack(">IQ", data[8:20])
|
||||
suffix, divisible = currencies.get(currency, ("UNKN", False))
|
||||
return "Simple send of %s %s" % (
|
||||
format_amount(amount, 8),
|
||||
currencies.get(currency, "UNKN"),
|
||||
format_amount(amount, 8 if divisible else 0),
|
||||
suffix,
|
||||
)
|
||||
else:
|
||||
# unknown OMNI transaction
|
||||
|
@ -361,25 +361,30 @@ void layoutConfirmOmni(const uint8_t *data, uint32_t size) {
|
||||
desc = _("Simple send of ");
|
||||
REVERSE32(*(const uint32_t *)(data + 8), currency);
|
||||
const char *suffix = " UNKN";
|
||||
bool divisible = false;
|
||||
switch (currency) {
|
||||
case 1:
|
||||
suffix = " OMNI";
|
||||
divisible = true;
|
||||
break;
|
||||
case 2:
|
||||
suffix = " tOMNI";
|
||||
divisible = true;
|
||||
break;
|
||||
case 3:
|
||||
suffix = " MAID";
|
||||
divisible = false;
|
||||
break;
|
||||
case 31:
|
||||
suffix = " USDT";
|
||||
divisible = true;
|
||||
break;
|
||||
}
|
||||
uint64_t amount_be, amount;
|
||||
memcpy(&amount_be, data + 12, sizeof(uint64_t));
|
||||
REVERSE64(amount_be, amount);
|
||||
bn_format_uint64(amount, NULL, suffix, BITCOIN_DIVISIBILITY, 0, false,
|
||||
str_out, sizeof(str_out));
|
||||
bn_format_uint64(amount, NULL, suffix, divisible ? BITCOIN_DIVISIBILITY : 0,
|
||||
0, false, str_out, sizeof(str_out));
|
||||
} else {
|
||||
desc = _("Unknown transaction");
|
||||
str_out[0] = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user