Merged confirm_parameter & confirm_selector UI code

This commit is contained in:
Alexandre Paillier
2023-04-07 11:30:40 +02:00
parent e0bb1225fe
commit 12fb8c6a3a
2 changed files with 28 additions and 63 deletions

View File

@@ -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();
}

View File

@@ -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();
}