From c50943e4ca26488ffd853f0d1774a680ef617ffa Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Fri, 24 May 2024 13:39:04 +0200 Subject: [PATCH] Port EIP712 to the new NBGL streaming use case Fixes the Flex navigation issue --- src_nbgl/ui_message_signing.c | 12 ++++- src_nbgl/ui_message_signing.h | 4 +- src_nbgl/ui_sign_712.c | 87 +++++++++++++++-------------------- src_nbgl/ui_sign_712_v0.c | 10 +--- 4 files changed, 49 insertions(+), 64 deletions(-) diff --git a/src_nbgl/ui_message_signing.c b/src_nbgl/ui_message_signing.c index 40544df..1e1e589 100644 --- a/src_nbgl/ui_message_signing.c +++ b/src_nbgl/ui_message_signing.c @@ -41,10 +41,18 @@ void ui_message_start(const char *title, ui_message_confirm_rejection); } -void ui_message_712_approved(void) { +static void ui_message_712_approved(void) { ui_712_approve(); } -void ui_message_712_rejected(void) { +static void ui_message_712_rejected(void) { ui_712_reject(); } + +void ui_typed_message_review_choice(bool confirm) { + if (confirm) { + nbgl_useCaseReviewStatus(STATUS_TYPE_MESSAGE_SIGNED, ui_message_712_approved); + } else { + nbgl_useCaseReviewStatus(STATUS_TYPE_MESSAGE_REJECTED, ui_message_712_rejected); + } +} diff --git a/src_nbgl/ui_message_signing.h b/src_nbgl/ui_message_signing.h index 6b04374..0791851 100644 --- a/src_nbgl/ui_message_signing.h +++ b/src_nbgl/ui_message_signing.h @@ -14,8 +14,6 @@ void ui_message_start(const char *title, void (*start_func)(void), void (*approved_func)(void), void (*rejected_func)(void)); - -void ui_message_712_approved(void); -void ui_message_712_rejected(void); +void ui_typed_message_review_choice(bool confirm); #endif // UI_MESSAGE_SIGNING_H_ diff --git a/src_nbgl/ui_sign_712.c b/src_nbgl/ui_sign_712.c index de82582..8dc8096 100644 --- a/src_nbgl/ui_sign_712.c +++ b/src_nbgl/ui_sign_712.c @@ -1,80 +1,67 @@ #ifdef HAVE_EIP712_FULL_SUPPORT +#include // explicit_bzero #include "common_ui.h" #include "ui_nbgl.h" #include "ui_logic.h" #include "common_712.h" #include "nbgl_use_case.h" -#include "network.h" #include "ui_message_signing.h" -#include "ui_signing.h" static nbgl_contentTagValue_t pair; +static nbgl_contentTagValueList_t pairs_list; -static bool display_sign_page(uint8_t page, nbgl_pageContent_t *content) { - (void) page; - content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(true); - content->infoLongPress.text = TEXT_SIGN_EIP712; - content->infoLongPress.longPressText = SIGN_BUTTON; - return true; +static void message_progress(bool confirm) { + if (confirm) { + if (ui_712_next_field() == EIP712_NO_MORE_FIELD) { + ui_712_switch_to_sign(); + } + } else { + ui_typed_message_review_choice(false); + } } -static bool display_review_page(uint8_t page, nbgl_pageContent_t *content) { - bool ret; +static void message_update(bool confirm) { uint16_t len; - switch (page) { - case 0: - // limit the value to one page - nbgl_getTextMaxLenInNbLines(LARGE_MEDIUM_FONT, - strings.tmp.tmp, - SCREEN_WIDTH - (2 * BORDER_MARGIN), - NB_MAX_LINES_IN_REVIEW, - &len, - false); - strings.tmp.tmp[len] = '\0'; + if (confirm) { + explicit_bzero(&pair, sizeof(pair)); + explicit_bzero(&pairs_list, sizeof(pairs_list)); - pair.item = strings.tmp.tmp2; - pair.value = strings.tmp.tmp; - content->type = TAG_VALUE_LIST; - content->tagValueList.nbPairs = 1; - content->tagValueList.pairs = &pair; - content->tagValueList.wrapping = false; - ret = true; - break; + // limit the value to one page + nbgl_getTextMaxLenInNbLines(LARGE_MEDIUM_FONT, + strings.tmp.tmp, + SCREEN_WIDTH - (2 * BORDER_MARGIN), + NB_MAX_LINES_IN_REVIEW, + &len, + false); + strings.tmp.tmp[len] = '\0'; - case 1: - if (ui_712_next_field() == EIP712_NO_MORE_FIELD) { - ui_712_switch_to_sign(); - } - __attribute__((fallthrough)); - default: - ret = false; - break; + pair.item = strings.tmp.tmp2; + pair.value = strings.tmp.tmp; + pairs_list.nbPairs = 1; + pairs_list.pairs = &pair; + pairs_list.wrapping = false; + nbgl_useCaseReviewStreamingContinue(&pairs_list, message_progress); + } else { + ui_typed_message_review_choice(false); } - return ret; -} - -static void handle_display(nbgl_navCallback_t cb) { - nbgl_useCaseRegularReview(0, 0, REJECT_BUTTON, NULL, cb, ui_message_review_choice); } void ui_712_start(void) { - g_position = UI_SIGNING_POSITION_START; - ui_message_start(TEXT_REVIEW_EIP712, - &ui_712_switch_to_message, - &ui_message_712_approved, - &ui_message_712_rejected); + nbgl_useCaseReviewStreamingStart(TYPE_MESSAGE, + &C_Review_64px, + TEXT_REVIEW_EIP712, + NULL, + message_update); } void ui_712_switch_to_message(void) { - g_position = UI_SIGNING_POSITION_REVIEW; - handle_display(display_review_page); + message_update(true); } void ui_712_switch_to_sign(void) { - g_position = UI_SIGNING_POSITION_SIGN; - handle_display(display_sign_page); + nbgl_useCaseReviewStreamingFinish(TEXT_SIGN_EIP712, ui_typed_message_review_choice); } #endif // HAVE_EIP712_FULL_SUPPORT diff --git a/src_nbgl/ui_sign_712_v0.c b/src_nbgl/ui_sign_712_v0.c index ba09d4a..a3a39b7 100644 --- a/src_nbgl/ui_sign_712_v0.c +++ b/src_nbgl/ui_sign_712_v0.c @@ -8,14 +8,6 @@ static nbgl_contentTagValue_t pairs[2]; static nbgl_contentTagValueList_t pairs_list; -static void message_review_choice(bool confirm) { - if (confirm) { - nbgl_useCaseReviewStatus(STATUS_TYPE_MESSAGE_SIGNED, ui_message_712_approved); - } else { - nbgl_useCaseReviewStatus(STATUS_TYPE_MESSAGE_REJECTED, ui_message_712_rejected); - } -} - static char *format_hash(const uint8_t *hash, char *buffer, size_t buffer_size, size_t offset) { array_bytes_string(buffer + offset, buffer_size - offset, hash, KECCAK256_HASH_BYTESIZE); return buffer + offset; @@ -46,5 +38,5 @@ void ui_sign_712_v0(void) { TEXT_REVIEW_EIP712, NULL, TEXT_SIGN_EIP712, - message_review_choice); + ui_typed_message_review_choice); }