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
|
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:
|
def is_valid(data: bytes) -> bool:
|
||||||
@ -15,9 +20,10 @@ def parse(data: bytes) -> bool:
|
|||||||
tx_version, tx_type = unpack(">HH", data[4:8])
|
tx_version, tx_type = unpack(">HH", data[4:8])
|
||||||
if tx_version == 0 and tx_type == 0 and len(data) == 20: # OMNI simple send
|
if tx_version == 0 and tx_type == 0 and len(data) == 20: # OMNI simple send
|
||||||
currency, amount = unpack(">IQ", data[8:20])
|
currency, amount = unpack(">IQ", data[8:20])
|
||||||
|
suffix, divisible = currencies.get(currency, ("UNKN", False))
|
||||||
return "Simple send of %s %s" % (
|
return "Simple send of %s %s" % (
|
||||||
format_amount(amount, 8),
|
format_amount(amount, 8 if divisible else 0),
|
||||||
currencies.get(currency, "UNKN"),
|
suffix,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# unknown OMNI transaction
|
# unknown OMNI transaction
|
||||||
|
@ -361,25 +361,30 @@ void layoutConfirmOmni(const uint8_t *data, uint32_t size) {
|
|||||||
desc = _("Simple send of ");
|
desc = _("Simple send of ");
|
||||||
REVERSE32(*(const uint32_t *)(data + 8), currency);
|
REVERSE32(*(const uint32_t *)(data + 8), currency);
|
||||||
const char *suffix = " UNKN";
|
const char *suffix = " UNKN";
|
||||||
|
bool divisible = false;
|
||||||
switch (currency) {
|
switch (currency) {
|
||||||
case 1:
|
case 1:
|
||||||
suffix = " OMNI";
|
suffix = " OMNI";
|
||||||
|
divisible = true;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
suffix = " tOMNI";
|
suffix = " tOMNI";
|
||||||
|
divisible = true;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
suffix = " MAID";
|
suffix = " MAID";
|
||||||
|
divisible = false;
|
||||||
break;
|
break;
|
||||||
case 31:
|
case 31:
|
||||||
suffix = " USDT";
|
suffix = " USDT";
|
||||||
|
divisible = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
uint64_t amount_be, amount;
|
uint64_t amount_be, amount;
|
||||||
memcpy(&amount_be, data + 12, sizeof(uint64_t));
|
memcpy(&amount_be, data + 12, sizeof(uint64_t));
|
||||||
REVERSE64(amount_be, amount);
|
REVERSE64(amount_be, amount);
|
||||||
bn_format_uint64(amount, NULL, suffix, BITCOIN_DIVISIBILITY, 0, false,
|
bn_format_uint64(amount, NULL, suffix, divisible ? BITCOIN_DIVISIBILITY : 0,
|
||||||
str_out, sizeof(str_out));
|
0, false, str_out, sizeof(str_out));
|
||||||
} else {
|
} else {
|
||||||
desc = _("Unknown transaction");
|
desc = _("Unknown transaction");
|
||||||
str_out[0] = 0;
|
str_out[0] = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user