diff --git a/src_nbgl/ui_sign_message.c b/src_nbgl/ui_sign_message.c index 50ec1411..be5b1e3e 100644 --- a/src_nbgl/ui_sign_message.c +++ b/src_nbgl/ui_sign_message.c @@ -9,20 +9,8 @@ #include "ui_message_signing.h" #include "ui_signing.h" -#define TEXT_REVIEW_EIP191 REVIEW(TEXT_MESSAGE) -#define TEXT_SIGN_EIP191 SIGN(TEXT_MESSAGE) - -typedef enum { - UI_191_ACTION_IDLE = 0, - UI_191_ACTION_ADVANCE_IN_MESSAGE, - UI_191_ACTION_GO_TO_SIGN -} e_ui_191_action; - -static e_ui_191_action g_action; - -static bool skip_message; - static nbgl_layoutTagValue_t pair; +static nbgl_layoutTagValueList_t pairsList; static uint32_t eip191MessageIdx = 0; static uint32_t stringsTmpTmpIdx = 0; @@ -35,121 +23,93 @@ static void sign_message(void) { io_seproxyhal_touch_signMessage_ok(); } -static bool display_message(nbgl_pageContent_t *content) { +static void messageReviewChoice_cb(bool confirm) { + if (confirm) { + nbgl_useCaseStatus("MESSAGE\nSIGNED", true, sign_message); + } else { + nbgl_useCaseStatus("Message signing\ncancelled", false, reject_message); + } +} + +static void setTagValuePairs(void) { uint16_t len = 0; bool reached; - if (g_action == UI_191_ACTION_ADVANCE_IN_MESSAGE) { - strncpy(g_stax_shared_buffer + eip191MessageIdx, - strings.tmp.tmp + stringsTmpTmpIdx, - SHARED_BUFFER_SIZE - eip191MessageIdx); - reached = nbgl_getTextMaxLenInNbLines(LARGE_MEDIUM_FONT, - (char *) g_stax_shared_buffer, - SCREEN_WIDTH - (2 * BORDER_MARGIN), - NB_MAX_LINES_IN_REVIEW, -#if (API_LEVEL == 0 || API_LEVEL >= 14) - &len, - false); -#else - &len); -#endif + explicit_bzero(&pair, sizeof(pair)); + explicit_bzero(&pairsList, sizeof(pairsList)); - stringsTmpTmpIdx = len - eip191MessageIdx; - eip191MessageIdx = len; - g_stax_shared_buffer[eip191MessageIdx] = '\0'; + strncpy(g_stax_shared_buffer + eip191MessageIdx, + strings.tmp.tmp + stringsTmpTmpIdx, + SHARED_BUFFER_SIZE - eip191MessageIdx); + reached = nbgl_getTextMaxLenInNbLines(LARGE_MEDIUM_FONT, + (char *) g_stax_shared_buffer, + SCREEN_WIDTH - (2 * BORDER_MARGIN), + NB_MAX_LINES_IN_REVIEW, + &len, + false); - if (!reached && eip191MessageIdx < SHARED_BUFFER_SIZE) { - stringsTmpTmpIdx = 0; - question_switcher(); + stringsTmpTmpIdx = len - eip191MessageIdx; + eip191MessageIdx = len; + g_stax_shared_buffer[eip191MessageIdx] = '\0'; - if (g_action != UI_191_ACTION_GO_TO_SIGN) { - return false; - } - } else if (reached || eip191MessageIdx == SHARED_BUFFER_SIZE) { - eip191MessageIdx = 0; - } + if (!reached && eip191MessageIdx < SHARED_BUFFER_SIZE) { + stringsTmpTmpIdx = 0; + question_switcher(); + } else if (reached || eip191MessageIdx == SHARED_BUFFER_SIZE) { + eip191MessageIdx = 0; } pair.value = g_stax_shared_buffer; pair.item = "Message"; - content->type = TAG_VALUE_LIST; - content->tagValueList.nbPairs = 1; - content->tagValueList.pairs = &pair; - content->tagValueList.smallCaseForValue = false; - content->tagValueList.nbMaxLinesForValue = NB_MAX_LINES_IN_REVIEW; - content->tagValueList.wrapping = false; - if ((g_action != UI_191_ACTION_IDLE) && (stringsTmpTmpIdx >= strlen(strings.tmp.tmp))) { + pairsList.nbPairs = 1; + pairsList.pairs = &pair; + pairsList.smallCaseForValue = false; + pairsList.nbMaxLinesForValue = NB_MAX_LINES_IN_REVIEW; + pairsList.wrapping = false; + + if (stringsTmpTmpIdx >= strlen(strings.tmp.tmp)) { // Fetch the next content to display into strings.tmp.tmp buffer. stringsTmpTmpIdx = 0; question_switcher(); } - return true; } -static bool display_sign(nbgl_pageContent_t *content) { - bool ret = false; - - if (g_position != UI_SIGNING_POSITION_SIGN) { - content->type = INFO_LONG_PRESS, content->infoLongPress.icon = &C_Review_64px; - content->infoLongPress.text = TEXT_SIGN_EIP191; - content->infoLongPress.longPressText = SIGN_BUTTON; - g_position = UI_SIGNING_POSITION_SIGN; - ret = true; - } - return ret; -} - -static bool nav_callback(uint8_t page, nbgl_pageContent_t *content) { - bool ret = true; - - if (page == LAST_PAGE_FOR_REVIEW) { // was skipped - skip_message = true; - skip_rest_of_message(); - } - if ((g_action != UI_191_ACTION_GO_TO_SIGN) && (g_position != UI_SIGNING_POSITION_SIGN)) { - if (skip_message) { - // do not refresh when this callback triggers after user validation - ret = false; +static void more_data_cb(bool confirm) { + if (confirm) { + if (g_position != UI_SIGNING_POSITION_SIGN) { + setTagValuePairs(); + nbgl_useCaseReviewStreamingContinue(&pairsList, more_data_cb); } else { - ret = display_message(content); + // the last page must contain a long press button + nbgl_useCaseReviewStreamingFinish(SIGN(TEXT_MESSAGE), messageReviewChoice_cb); } } else { - // the last page must contain a long press button - ret = display_sign(content); + reject_message(); } - return ret; -} - -static void continue_review(void) { - nbgl_useCaseForwardOnlyReview(REJECT_BUTTON, NULL, nav_callback, ui_message_review_choice); } void ui_191_start(void) { g_position = UI_SIGNING_POSITION_START; - - skip_message = false; eip191MessageIdx = 0; stringsTmpTmpIdx = 0; - ui_message_start(TEXT_REVIEW_EIP191, &ui_191_switch_to_message, &sign_message, &reject_message); + nbgl_useCaseReviewStreamingStart(TYPE_MESSAGE, + &C_Review_64px, + REVIEW(TEXT_MESSAGE), + NULL, + more_data_cb); } void ui_191_switch_to_message(void) { g_position = UI_SIGNING_POSITION_REVIEW; - g_action = UI_191_ACTION_ADVANCE_IN_MESSAGE; // No question mechanism on Stax: // Message is already displayed - continue_review(); + more_data_cb(true); } void ui_191_switch_to_sign(void) { - g_action = UI_191_ACTION_GO_TO_SIGN; - // Next nav_callback callback must display - // the hold to approve screen - if (skip_message) { - continue_review(); // to force screen refresh - } + g_position = UI_SIGNING_POSITION_SIGN; } void ui_191_switch_to_question(void) { diff --git a/tests/ragger/snapshots/flex/test_personal_sign_metamask/00000.png b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00000.png new file mode 100644 index 00000000..a59c316d Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00000.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_metamask/00001.png b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00001.png new file mode 100644 index 00000000..c43b553e Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00001.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_metamask/00002.png b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00002.png new file mode 100644 index 00000000..7a6f3ac5 Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00002.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_metamask/00003.png b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00003.png new file mode 100644 index 00000000..d9fe8e8f Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00003.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_metamask/00004.png b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00004.png new file mode 100644 index 00000000..dabe7afe Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00004.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_metamask/00005.png b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00005.png new file mode 100644 index 00000000..2b40ba7b Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00005.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_metamask/00006.png b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00006.png new file mode 100644 index 00000000..c02d7d44 Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00006.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_metamask/00007.png b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00007.png new file mode 100644 index 00000000..2b40ba7b Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00007.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_metamask/00008.png b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00008.png new file mode 100644 index 00000000..c02d7d44 Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00008.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_metamask/00009.png b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00009.png new file mode 100644 index 00000000..2b40ba7b Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00009.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_metamask/00010.png b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00010.png new file mode 100644 index 00000000..c02d7d44 Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00010.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_metamask/00011.png b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00011.png new file mode 100644 index 00000000..2b40ba7b Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00011.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_metamask/00012.png b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00012.png new file mode 100644 index 00000000..c02d7d44 Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_metamask/00012.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_non_ascii/00000.png b/tests/ragger/snapshots/flex/test_personal_sign_non_ascii/00000.png new file mode 100644 index 00000000..a59c316d Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_non_ascii/00000.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_non_ascii/00001.png b/tests/ragger/snapshots/flex/test_personal_sign_non_ascii/00001.png new file mode 100644 index 00000000..a644418e Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_non_ascii/00001.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_non_ascii/00002.png b/tests/ragger/snapshots/flex/test_personal_sign_non_ascii/00002.png new file mode 100644 index 00000000..7a6f3ac5 Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_non_ascii/00002.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_non_ascii/00003.png b/tests/ragger/snapshots/flex/test_personal_sign_non_ascii/00003.png new file mode 100644 index 00000000..d9fe8e8f Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_non_ascii/00003.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_non_ascii/00004.png b/tests/ragger/snapshots/flex/test_personal_sign_non_ascii/00004.png new file mode 100644 index 00000000..dabe7afe Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_non_ascii/00004.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_opensea/00000.png b/tests/ragger/snapshots/flex/test_personal_sign_opensea/00000.png new file mode 100644 index 00000000..a59c316d Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_opensea/00000.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_opensea/00001.png b/tests/ragger/snapshots/flex/test_personal_sign_opensea/00001.png new file mode 100644 index 00000000..e550655a Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_opensea/00001.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_opensea/00002.png b/tests/ragger/snapshots/flex/test_personal_sign_opensea/00002.png new file mode 100644 index 00000000..bc6387e9 Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_opensea/00002.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_opensea/00003.png b/tests/ragger/snapshots/flex/test_personal_sign_opensea/00003.png new file mode 100644 index 00000000..7a6f3ac5 Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_opensea/00003.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_opensea/00004.png b/tests/ragger/snapshots/flex/test_personal_sign_opensea/00004.png new file mode 100644 index 00000000..d9fe8e8f Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_opensea/00004.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_opensea/00005.png b/tests/ragger/snapshots/flex/test_personal_sign_opensea/00005.png new file mode 100644 index 00000000..dabe7afe Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_opensea/00005.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_reject/00000.png b/tests/ragger/snapshots/flex/test_personal_sign_reject/00000.png new file mode 100644 index 00000000..a59c316d Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_reject/00000.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_reject/00001.png b/tests/ragger/snapshots/flex/test_personal_sign_reject/00001.png new file mode 100644 index 00000000..e1bf2053 Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_reject/00001.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_reject/00002.png b/tests/ragger/snapshots/flex/test_personal_sign_reject/00002.png new file mode 100644 index 00000000..7a6f3ac5 Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_reject/00002.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_reject/00003.png b/tests/ragger/snapshots/flex/test_personal_sign_reject/00003.png new file mode 100644 index 00000000..0a6b1953 Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_reject/00003.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_reject/00004.png b/tests/ragger/snapshots/flex/test_personal_sign_reject/00004.png new file mode 100644 index 00000000..77540e3f Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_reject/00004.png differ diff --git a/tests/ragger/snapshots/flex/test_personal_sign_reject/00005.png b/tests/ragger/snapshots/flex/test_personal_sign_reject/00005.png new file mode 100644 index 00000000..dabe7afe Binary files /dev/null and b/tests/ragger/snapshots/flex/test_personal_sign_reject/00005.png differ diff --git a/tests/ragger/snapshots/stax/test_personal_sign_metamask/00000.png b/tests/ragger/snapshots/stax/test_personal_sign_metamask/00000.png index f7398110..aa60a577 100644 Binary files a/tests/ragger/snapshots/stax/test_personal_sign_metamask/00000.png and b/tests/ragger/snapshots/stax/test_personal_sign_metamask/00000.png differ diff --git a/tests/ragger/snapshots/stax/test_personal_sign_metamask/00001.png b/tests/ragger/snapshots/stax/test_personal_sign_metamask/00001.png index e964717d..65d4e7ef 100644 Binary files a/tests/ragger/snapshots/stax/test_personal_sign_metamask/00001.png and b/tests/ragger/snapshots/stax/test_personal_sign_metamask/00001.png differ diff --git a/tests/ragger/snapshots/stax/test_personal_sign_metamask/00002.png b/tests/ragger/snapshots/stax/test_personal_sign_metamask/00002.png index 83a0d80f..3a6ae099 100644 Binary files a/tests/ragger/snapshots/stax/test_personal_sign_metamask/00002.png and b/tests/ragger/snapshots/stax/test_personal_sign_metamask/00002.png differ diff --git a/tests/ragger/snapshots/stax/test_personal_sign_non_ascii/00000.png b/tests/ragger/snapshots/stax/test_personal_sign_non_ascii/00000.png index f7398110..aa60a577 100644 Binary files a/tests/ragger/snapshots/stax/test_personal_sign_non_ascii/00000.png and b/tests/ragger/snapshots/stax/test_personal_sign_non_ascii/00000.png differ diff --git a/tests/ragger/snapshots/stax/test_personal_sign_non_ascii/00001.png b/tests/ragger/snapshots/stax/test_personal_sign_non_ascii/00001.png index f5806b23..67e9b779 100644 Binary files a/tests/ragger/snapshots/stax/test_personal_sign_non_ascii/00001.png and b/tests/ragger/snapshots/stax/test_personal_sign_non_ascii/00001.png differ diff --git a/tests/ragger/snapshots/stax/test_personal_sign_non_ascii/00002.png b/tests/ragger/snapshots/stax/test_personal_sign_non_ascii/00002.png index 83a0d80f..3a6ae099 100644 Binary files a/tests/ragger/snapshots/stax/test_personal_sign_non_ascii/00002.png and b/tests/ragger/snapshots/stax/test_personal_sign_non_ascii/00002.png differ diff --git a/tests/ragger/snapshots/stax/test_personal_sign_opensea/00000.png b/tests/ragger/snapshots/stax/test_personal_sign_opensea/00000.png index f7398110..aa60a577 100644 Binary files a/tests/ragger/snapshots/stax/test_personal_sign_opensea/00000.png and b/tests/ragger/snapshots/stax/test_personal_sign_opensea/00000.png differ diff --git a/tests/ragger/snapshots/stax/test_personal_sign_opensea/00001.png b/tests/ragger/snapshots/stax/test_personal_sign_opensea/00001.png index a499291e..ddfdab7e 100644 Binary files a/tests/ragger/snapshots/stax/test_personal_sign_opensea/00001.png and b/tests/ragger/snapshots/stax/test_personal_sign_opensea/00001.png differ diff --git a/tests/ragger/snapshots/stax/test_personal_sign_opensea/00002.png b/tests/ragger/snapshots/stax/test_personal_sign_opensea/00002.png index bbf0532c..8ad20534 100644 Binary files a/tests/ragger/snapshots/stax/test_personal_sign_opensea/00002.png and b/tests/ragger/snapshots/stax/test_personal_sign_opensea/00002.png differ diff --git a/tests/ragger/snapshots/stax/test_personal_sign_opensea/00003.png b/tests/ragger/snapshots/stax/test_personal_sign_opensea/00003.png index 83a0d80f..3a6ae099 100644 Binary files a/tests/ragger/snapshots/stax/test_personal_sign_opensea/00003.png and b/tests/ragger/snapshots/stax/test_personal_sign_opensea/00003.png differ diff --git a/tests/ragger/snapshots/stax/test_personal_sign_reject/00000.png b/tests/ragger/snapshots/stax/test_personal_sign_reject/00000.png index f7398110..aa60a577 100644 Binary files a/tests/ragger/snapshots/stax/test_personal_sign_reject/00000.png and b/tests/ragger/snapshots/stax/test_personal_sign_reject/00000.png differ diff --git a/tests/ragger/snapshots/stax/test_personal_sign_reject/00001.png b/tests/ragger/snapshots/stax/test_personal_sign_reject/00001.png index 2f80635a..f6715214 100644 Binary files a/tests/ragger/snapshots/stax/test_personal_sign_reject/00001.png and b/tests/ragger/snapshots/stax/test_personal_sign_reject/00001.png differ diff --git a/tests/ragger/snapshots/stax/test_personal_sign_reject/00002.png b/tests/ragger/snapshots/stax/test_personal_sign_reject/00002.png index 83a0d80f..3a6ae099 100644 Binary files a/tests/ragger/snapshots/stax/test_personal_sign_reject/00002.png and b/tests/ragger/snapshots/stax/test_personal_sign_reject/00002.png differ diff --git a/tests/ragger/snapshots/stax/test_personal_sign_reject/00003.png b/tests/ragger/snapshots/stax/test_personal_sign_reject/00003.png index d4cf6afb..56afa4b2 100644 Binary files a/tests/ragger/snapshots/stax/test_personal_sign_reject/00003.png and b/tests/ragger/snapshots/stax/test_personal_sign_reject/00003.png differ