From 12fb8c6a3ae7721d9d610aa2f6bf334d8ee7b818 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Fri, 7 Apr 2023 11:30:40 +0200 Subject: [PATCH] Merged confirm_parameter & confirm_selector UI code --- ...eter.c => ui_confirm_parameter_selector.c} | 35 +++++++++--- src_nbgl/ui_confirm_selector.c | 56 ------------------- 2 files changed, 28 insertions(+), 63 deletions(-) rename src_nbgl/{ui_confirm_parameter.c => ui_confirm_parameter_selector.c} (50%) delete mode 100644 src_nbgl/ui_confirm_selector.c diff --git a/src_nbgl/ui_confirm_parameter.c b/src_nbgl/ui_confirm_parameter_selector.c similarity index 50% rename from src_nbgl/ui_confirm_parameter.c rename to src_nbgl/ui_confirm_parameter_selector.c index bebe5ae..43f93fc 100644 --- a/src_nbgl/ui_confirm_parameter.c +++ b/src_nbgl/ui_confirm_parameter_selector.c @@ -2,7 +2,10 @@ #include "ui_nbgl.h" #include "network.h" -static nbgl_layoutTagValue_t tlv; +typedef enum { PARAMETER_CONFIRMATION, SELECTOR_CONFIRMATION } e_confirmation_type; + +static nbgl_layoutTagValue_t pair; +static e_confirmation_type confirm_type; static void reviewReject(void) { io_seproxyhal_touch_data_cancel(NULL); @@ -22,14 +25,18 @@ static void reviewChoice(bool confirm) { static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) { if (page == 0) { - tlv.item = "Parameter"; - tlv.value = strings.tmp.tmp; + pair.item = (confirm_type == PARAMETER_CONFIRMATION) ? "Parameter" : "Selector"; + pair.value = strings.tmp.tmp; content->type = TAG_VALUE_LIST; content->tagValueList.nbPairs = 1; - content->tagValueList.pairs = (nbgl_layoutTagValue_t *) &tlv; + content->tagValueList.pairs = (nbgl_layoutTagValue_t *) &pair; } else if (page == 1) { + snprintf(staxSharedBuffer, + sizeof(staxSharedBuffer), + "Confirm %s", + (confirm_type == PARAMETER_CONFIRMATION) ? "parameter" : "selector"); content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(true); - content->infoLongPress.text = "Confirm parameter"; + content->infoLongPress.text = staxSharedBuffer; content->infoLongPress.longPressText = "Hold to confirm"; } else { return false; @@ -39,12 +46,20 @@ static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) { } static void reviewContinue(void) { - nbgl_useCaseRegularReview(0, 2, "Reject parameter", NULL, displayTransactionPage, reviewChoice); + snprintf(staxSharedBuffer, + sizeof(staxSharedBuffer), + "Reject %s", + (confirm_type == PARAMETER_CONFIRMATION) ? "parameter" : "selector"); + nbgl_useCaseRegularReview(0, 2, staxSharedBuffer, NULL, displayTransactionPage, reviewChoice); } static void buildScreen(void) { + snprintf(staxSharedBuffer, + sizeof(staxSharedBuffer), + "Verify %s", + (confirm_type == PARAMETER_CONFIRMATION) ? "parameter" : "selector"); nbgl_useCaseReviewStart(get_app_icon(true), - "Verify parameter", + staxSharedBuffer, NULL, "Reject", reviewContinue, @@ -52,5 +67,11 @@ static void buildScreen(void) { } void ui_confirm_parameter(void) { + confirm_type = PARAMETER_CONFIRMATION; + buildScreen(); +} + +void ui_confirm_selector(void) { + confirm_type = SELECTOR_CONFIRMATION; buildScreen(); } diff --git a/src_nbgl/ui_confirm_selector.c b/src_nbgl/ui_confirm_selector.c deleted file mode 100644 index c268d28..0000000 --- a/src_nbgl/ui_confirm_selector.c +++ /dev/null @@ -1,56 +0,0 @@ -#include "common_ui.h" -#include "ui_nbgl.h" -#include "network.h" - -static nbgl_layoutTagValue_t tlv; - -static void reviewReject(void) { - io_seproxyhal_touch_data_cancel(NULL); -} - -static void confirmTransation(void) { - io_seproxyhal_touch_data_ok(NULL); -} - -static void reviewChoice(bool confirm) { - if (confirm) { - confirmTransation(); - } else { - reviewReject(); - } -} - -static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) { - if (page == 0) { - tlv.item = "Parameter"; - tlv.value = strings.tmp.tmp; - content->type = TAG_VALUE_LIST; - content->tagValueList.nbPairs = 1; - content->tagValueList.pairs = (nbgl_layoutTagValue_t *) &tlv; - } else if (page == 1) { - content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(true); - content->infoLongPress.text = "Confirm selector"; - content->infoLongPress.longPressText = "Hold to confirm"; - } else { - return false; - } - // valid page so return true - return true; -} - -static void reviewContinue(void) { - nbgl_useCaseRegularReview(0, 2, "Reject selector", NULL, displayTransactionPage, reviewChoice); -} - -static void buildScreen(void) { - nbgl_useCaseReviewStart(get_app_icon(true), - "Verify selector", - NULL, - "Reject", - reviewContinue, - reviewReject); -} - -void ui_confirm_selector(void) { - buildScreen(); -}