Skip to content

Commit

Permalink
Port message review steps to 'nbgl_useCaseStreamingReview' in ui_sign…
Browse files Browse the repository at this point in the history
…_message.c
  • Loading branch information
cedelavergne-ledger committed Apr 23, 2024
1 parent 597451d commit 2e07df0
Show file tree
Hide file tree
Showing 45 changed files with 56 additions and 94 deletions.
150 changes: 56 additions & 94 deletions src_nbgl/ui_sign_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,121 +23,95 @@ 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 bool 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

stringsTmpTmpIdx = len - eip191MessageIdx;
eip191MessageIdx = len;
g_stax_shared_buffer[eip191MessageIdx] = '\0';

if (!reached && eip191MessageIdx < SHARED_BUFFER_SIZE) {
stringsTmpTmpIdx = 0;
question_switcher();

if (g_action != UI_191_ACTION_GO_TO_SIGN) {
return false;
}
} else if (reached || eip191MessageIdx == SHARED_BUFFER_SIZE) {
eip191MessageIdx = 0;
}
explicit_bzero(&pair, sizeof(pair));
explicit_bzero(&pairsList, sizeof(pairsList));

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);

stringsTmpTmpIdx = len - eip191MessageIdx;
eip191MessageIdx = len;
g_stax_shared_buffer[eip191MessageIdx] = '\0';

if (!reached && eip191MessageIdx < SHARED_BUFFER_SIZE) {
stringsTmpTmpIdx = 0;
question_switcher();
// return false;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
} 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;
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) {
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/ragger/snapshots/stax/test_personal_sign_metamask/00000.png
Binary file modified tests/ragger/snapshots/stax/test_personal_sign_metamask/00001.png
Binary file modified tests/ragger/snapshots/stax/test_personal_sign_metamask/00002.png
Binary file modified tests/ragger/snapshots/stax/test_personal_sign_non_ascii/00000.png
Binary file modified tests/ragger/snapshots/stax/test_personal_sign_non_ascii/00001.png
Binary file modified tests/ragger/snapshots/stax/test_personal_sign_non_ascii/00002.png
Binary file modified tests/ragger/snapshots/stax/test_personal_sign_opensea/00000.png
Binary file modified tests/ragger/snapshots/stax/test_personal_sign_opensea/00001.png
Binary file modified tests/ragger/snapshots/stax/test_personal_sign_opensea/00002.png
Binary file modified tests/ragger/snapshots/stax/test_personal_sign_opensea/00003.png
Binary file modified tests/ragger/snapshots/stax/test_personal_sign_reject/00000.png
Binary file modified tests/ragger/snapshots/stax/test_personal_sign_reject/00001.png
Binary file modified tests/ragger/snapshots/stax/test_personal_sign_reject/00002.png
Binary file modified tests/ragger/snapshots/stax/test_personal_sign_reject/00003.png

0 comments on commit 2e07df0

Please sign in to comment.