Skip to content

Commit 821590e

Browse files
authored
Add intent on the last screen (#206)
* add intent in sign screen * bump version
1 parent 6ad0a46 commit 821590e

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

app/ui/view_nbgl.c

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const char *intro_message = NULL;
5353
const char *intro_submessage = NULL;
5454
char intro_msg_buf[MAX_CHARS_PER_VALUE1_LINE];
5555
char intro_submsg_buf[MAX_CHARS_SUBMSG_LINE];
56+
char approval_label_buf[MAX_CHARS_SUBMSG_LINE];
5657

5758
#define REVIEW_STANDALONE_SIZE 22
5859
#define REVIEW_MESSAGE_SIZE 18
@@ -470,13 +471,13 @@ static void config_useCaseReview(nbgl_operationType_t type) {
470471

471472
if (app_mode_blindsign_required()) {
472473
nbgl_useCaseReviewBlindSigning(type, &pairList, &C_icon_stax_64,
473-
(intro_message == NULL ? "Review transaction" : intro_message),
474-
(intro_submessage == NULL ? NULL : intro_submessage),
474+
(intro_message == NULL ? "Review transaction" : intro_message), intro_submessage,
475475
"Accept risk and sign transaction ?", NULL, reviewTransactionChoice);
476476
} else {
477-
nbgl_useCaseReview(
478-
type, &pairList, &C_icon_stax_64, (intro_message == NULL ? "Review transaction" : intro_message),
479-
(intro_submessage == NULL ? NULL : intro_submessage), APPROVE_LABEL_NBGL, reviewTransactionChoice);
477+
nbgl_useCaseReview(type, &pairList, &C_icon_stax_64,
478+
(intro_message == NULL ? "Review transaction" : intro_message), intro_submessage,
479+
(approval_label_buf[0] != '\0' ? approval_label_buf : APPROVE_LABEL_NBGL),
480+
reviewTransactionChoice);
480481
}
481482
}
482483

@@ -497,9 +498,9 @@ static void config_useCaseMessageReview() {
497498
(intro_message == NULL ? "Review Message" : intro_message), NULL,
498499
"Accept risk and sign message ?", NULL, reviewMessageChoice);
499500
} else {
500-
nbgl_useCaseReview(TYPE_MESSAGE, &pairList, &C_Review_64px,
501-
(intro_message == NULL ? "Review Message" : intro_message), NULL, APPROVE_LABEL_NBGL_MSG,
502-
reviewMessageChoice);
501+
nbgl_useCaseReview(
502+
TYPE_MESSAGE, &pairList, &C_Review_64px, (intro_message == NULL ? "Review Message" : intro_message), NULL,
503+
(approval_label_buf[0] != '\0' ? approval_label_buf : APPROVE_LABEL_NBGL_MSG), reviewMessageChoice);
503504
}
504505
}
505506

@@ -528,6 +529,7 @@ void view_review_show_impl(unsigned int requireReply, const char *title, const c
528529
intro_submessage = NULL;
529530
intro_msg_buf[0] = '\0';
530531
intro_submsg_buf[0] = '\0';
532+
approval_label_buf[0] = '\0';
531533
viewdata.key = viewdata.keys[0];
532534
viewdata.value = viewdata.values[0];
533535
// Retrieve intro text for transaction
@@ -574,6 +576,7 @@ void view_review_show_with_intent_impl(unsigned int requireReply, const char *in
574576
intro_submessage = NULL;
575577
intro_msg_buf[0] = '\0';
576578
intro_submsg_buf[0] = '\0';
579+
approval_label_buf[0] = '\0';
577580
viewdata.key = viewdata.keys[0];
578581
viewdata.value = viewdata.values[0];
579582

@@ -583,8 +586,14 @@ void view_review_show_with_intent_impl(unsigned int requireReply, const char *in
583586
const char *review_text = (review_type == REVIEW_MSG) ? "Review message" : "Review transaction";
584587
int ret = snprintf(intro_msg_buf, sizeof(intro_msg_buf), "%s to %s", review_text, intent);
585588

589+
// Check for snprintf error
590+
if (ret < 0) {
591+
// Handle encoding error - use a default message
592+
strncpy(intro_msg_buf, review_text, sizeof(intro_msg_buf) - 1);
593+
intro_msg_buf[sizeof(intro_msg_buf) - 1] = '\0';
594+
}
586595
// Check if truncation occurred and add ellipsis if needed
587-
if (ret >= (int)sizeof(intro_msg_buf)) {
596+
else if ((size_t)ret >= sizeof(intro_msg_buf)) {
588597
const size_t buf_len = sizeof(intro_msg_buf);
589598
if (buf_len >= 4) {
590599
intro_msg_buf[buf_len - 4] = '.';
@@ -595,6 +604,31 @@ void view_review_show_with_intent_impl(unsigned int requireReply, const char *in
595604
}
596605
intro_message = intro_msg_buf;
597606
intro_submessage = NULL; // No second line for NBGL
607+
608+
// Format the approval label with intent for the final approval screen
609+
const char *sign_text = (review_type == REVIEW_MSG) ? "Sign message" : "Sign transaction";
610+
ret = snprintf(approval_label_buf, sizeof(approval_label_buf), "%s to %s?", sign_text, intent);
611+
612+
// Check for snprintf error
613+
if (ret < 0) {
614+
// Handle encoding error - use a default message
615+
strncpy(approval_label_buf, sign_text, sizeof(approval_label_buf) - 1);
616+
approval_label_buf[sizeof(approval_label_buf) - 1] = '\0';
617+
}
618+
// Check if truncation occurred and add ellipsis if needed
619+
else if ((size_t)ret >= sizeof(approval_label_buf)) {
620+
const size_t buf_len = sizeof(approval_label_buf);
621+
if (buf_len >= 4) {
622+
approval_label_buf[buf_len - 4] = '.';
623+
approval_label_buf[buf_len - 3] = '.';
624+
approval_label_buf[buf_len - 2] = '.';
625+
approval_label_buf[buf_len - 1] = '\0';
626+
}
627+
}
628+
} else {
629+
// Use default labels if no intent
630+
snprintf(approval_label_buf, sizeof(approval_label_buf), "%s",
631+
(review_type == REVIEW_MSG) ? APPROVE_LABEL_NBGL_MSG : APPROVE_LABEL_NBGL);
598632
}
599633

600634
h_paging_init();

include/zxversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717

1818
#define ZXLIB_MAJOR 36
1919
#define ZXLIB_MINOR 0
20-
#define ZXLIB_PATCH 2
20+
#define ZXLIB_PATCH 3

0 commit comments

Comments
 (0)