1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 17:38:39 +00:00

layout: fix VerifyMessage dialog (use nonproportional font for addresses)

This commit is contained in:
Pavol Rusnak 2018-09-06 14:37:42 +02:00
parent 988209ab7d
commit a3555b9c7c
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
4 changed files with 26 additions and 24 deletions

View File

@ -254,7 +254,7 @@ void fsm_msgVerifyMessage(VerifyMessage *msg)
if (!coin) return; if (!coin) return;
layoutProgressSwipe(_("Verifying"), 0); layoutProgressSwipe(_("Verifying"), 0);
if (msg->signature.size == 65 && cryptoMessageVerify(coin, msg->message.bytes, msg->message.size, msg->address, msg->signature.bytes) == 0) { if (msg->signature.size == 65 && cryptoMessageVerify(coin, msg->message.bytes, msg->message.size, msg->address, msg->signature.bytes) == 0) {
layoutVerifyAddress(msg->address); layoutVerifyAddress(coin, msg->address);
if (!protectButton(ButtonRequest_ButtonRequestType_ButtonRequest_Other, false)) { if (!protectButton(ButtonRequest_ButtonRequestType_ButtonRequest_Other, false)) {
fsm_sendFailure(Failure_FailureType_Failure_ActionCancelled, NULL); fsm_sendFailure(Failure_FailureType_Failure_ActionCancelled, NULL);
layoutHome(); layoutHome();

View File

@ -90,7 +90,7 @@ void fsm_msgEthereumVerifyMessage(EthereumVerifyMessage *msg)
char address[43] = { '0', 'x' }; char address[43] = { '0', 'x' };
ethereum_address_checksum(msg->address.bytes, address + 2, false, 0); ethereum_address_checksum(msg->address.bytes, address + 2, false, 0);
layoutVerifyAddress(address); layoutVerifyAddress(NULL, address);
if (!protectButton(ButtonRequest_ButtonRequestType_ButtonRequest_Other, false)) { if (!protectButton(ButtonRequest_ButtonRequestType_ButtonRequest_Other, false)) {
fsm_sendFailure(Failure_FailureType_Failure_ActionCancelled, NULL); fsm_sendFailure(Failure_FailureType_Failure_ActionCancelled, NULL);
layoutHome(); layoutHome();

View File

@ -244,43 +244,39 @@ void layoutHome(void)
system_millis_lock_start = timer_ms(); system_millis_lock_start = timer_ms();
} }
void layoutConfirmOutput(const CoinInfo *coin, const TxAck_TransactionType_TxOutputType *out) static void render_address_dialog(const CoinInfo *coin, const char *address, const char *line1, const char *line2, const char *extra_line)
{ {
char str_out[32 + 3]; if (coin && coin->cashaddr_prefix) {
bn_format_uint64(out->amount, NULL, coin->coin_shortcut, BITCOIN_DIVISIBILITY, 0, false, str_out, sizeof(str_out) - 3);
strlcat(str_out, " to", sizeof(str_out));
const char *addr = out->address;
if (coin->cashaddr_prefix) {
/* If this is a cashaddr address, remove the prefix from the /* If this is a cashaddr address, remove the prefix from the
* string presented to the user * string presented to the user
*/ */
int prefix_len = strlen(coin->cashaddr_prefix); int prefix_len = strlen(coin->cashaddr_prefix);
if (strncmp(addr, coin->cashaddr_prefix, prefix_len) == 0 if (strncmp(address, coin->cashaddr_prefix, prefix_len) == 0
&& addr[prefix_len] == ':') { && address[prefix_len] == ':') {
addr += prefix_len + 1; address += prefix_len + 1;
} }
} }
int addrlen = strlen(addr); int addrlen = strlen(address);
int numlines = addrlen <= 42 ? 2 : 3; int numlines = addrlen <= 42 ? 2 : 3;
int linelen = (addrlen - 1) / numlines + 1; int linelen = (addrlen - 1) / numlines + 1;
if (linelen > 21) { if (linelen > 21) {
linelen = 21; linelen = 21;
} }
const char **str = split_message((const uint8_t *)addr, addrlen, linelen); const char **str = split_message((const uint8_t *)address, addrlen, linelen);
layoutLast = layoutDialogSwipe; layoutLast = layoutDialogSwipe;
layoutSwipe(); layoutSwipe();
oledClear(); oledClear();
oledDrawBitmap(0, 0, &bmp_icon_question); oledDrawBitmap(0, 0, &bmp_icon_question);
oledDrawString(20, 0 * 9, _("Confirm sending"), FONT_STANDARD); oledDrawString(20, 0 * 9, line1, FONT_STANDARD);
oledDrawString(20, 1 * 9, str_out, FONT_STANDARD); oledDrawString(20, 1 * 9, line2, FONT_STANDARD);
int left = linelen > 18 ? 0 : 20; int left = linelen > 18 ? 0 : 20;
oledDrawString(left, 2 * 9, str[0], FONT_FIXED); oledDrawString(left, 2 * 9, str[0], FONT_FIXED);
oledDrawString(left, 3 * 9, str[1], FONT_FIXED); oledDrawString(left, 3 * 9, str[1], FONT_FIXED);
oledDrawString(left, 4 * 9, str[2], FONT_FIXED); oledDrawString(left, 4 * 9, str[2], FONT_FIXED);
oledDrawString(left, 5 * 9, str[3], FONT_FIXED); oledDrawString(left, 5 * 9, str[3], FONT_FIXED);
if (!str[3][0]) { if (!str[3][0]) {
if (out->address_n_count > 0) { if (extra_line) {
oledDrawString(0, 5*9, address_n_str(out->address_n, out->address_n_count), FONT_STANDARD); oledDrawString(0, 5 * 9, extra_line, FONT_STANDARD);
} else { } else {
oledHLine(OLED_HEIGHT - 13); oledHLine(OLED_HEIGHT - 13);
} }
@ -290,6 +286,16 @@ void layoutConfirmOutput(const CoinInfo *coin, const TxAck_TransactionType_TxOut
oledRefresh(); oledRefresh();
} }
void layoutConfirmOutput(const CoinInfo *coin, const TxAck_TransactionType_TxOutputType *out)
{
char str_out[32 + 3];
bn_format_uint64(out->amount, NULL, coin->coin_shortcut, BITCOIN_DIVISIBILITY, 0, false, str_out, sizeof(str_out) - 3);
strlcat(str_out, " to", sizeof(str_out));
const char *address = out->address;
const char *extra_line = (out->address_n_count > 0) ? address_n_str(out->address_n, out->address_n_count) : 0;
render_address_dialog(coin, address, _("Confirm sending"), str_out, extra_line);
}
void layoutConfirmOpReturn(const uint8_t *data, uint32_t size) void layoutConfirmOpReturn(const uint8_t *data, uint32_t size)
{ {
bool ascii_only = true; bool ascii_only = true;
@ -364,13 +370,9 @@ void layoutSignMessage(const uint8_t *msg, uint32_t len)
str[0], str[1], str[2], str[3], NULL, NULL); str[0], str[1], str[2], str[3], NULL, NULL);
} }
void layoutVerifyAddress(const char *address) void layoutVerifyAddress(const CoinInfo *coin, const char *address)
{ {
const char **str = split_message((const uint8_t *)address, strlen(address), 17); render_address_dialog(coin, address, _("Confirm address?"), _("Message signed by:"), 0);
layoutDialogSwipe(&bmp_icon_info, _("Cancel"), _("Confirm"),
_("Confirm address?"),
_("Message signed by:"),
str[0], str[1], str[2], NULL, NULL);
} }
void layoutVerifyMessage(const uint8_t *msg, uint32_t len) void layoutVerifyMessage(const uint8_t *msg, uint32_t len)

View File

@ -48,7 +48,7 @@ void layoutConfirmOpReturn(const uint8_t *data, uint32_t size);
void layoutConfirmTx(const CoinInfo *coin, uint64_t amount_out, uint64_t amount_fee); void layoutConfirmTx(const CoinInfo *coin, uint64_t amount_out, uint64_t amount_fee);
void layoutFeeOverThreshold(const CoinInfo *coin, uint64_t fee); void layoutFeeOverThreshold(const CoinInfo *coin, uint64_t fee);
void layoutSignMessage(const uint8_t *msg, uint32_t len); void layoutSignMessage(const uint8_t *msg, uint32_t len);
void layoutVerifyAddress(const char *address); void layoutVerifyAddress(const CoinInfo *coin, const char *address);
void layoutVerifyMessage(const uint8_t *msg, uint32_t len); void layoutVerifyMessage(const uint8_t *msg, uint32_t len);
void layoutCipherKeyValue(bool encrypt, const char *key); void layoutCipherKeyValue(bool encrypt, const char *key);
void layoutEncryptMessage(const uint8_t *msg, uint32_t len, bool signing); void layoutEncryptMessage(const uint8_t *msg, uint32_t len, bool signing);