From 9022933d6b94623f8198e5883dd12be7ae8f3f96 Mon Sep 17 00:00:00 2001 From: Charles-Edouard de la Vergne Date: Fri, 27 Sep 2024 16:28:35 +0200 Subject: [PATCH] Add warning screen for High fees --- Makefile | 2 +- src/signTx_ui.c | 16 +++++++++++---- src/ui.h | 11 ++++++++++ src/uiScreens_bagl.c | 6 ++++++ src/uiScreens_bagl.h | 2 ++ src/ui_nbgl.c | 48 ++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 78 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index ca028f74..23240a86 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ APPNAME = "Cardano ADA" # Application version APPVERSION_M = 7 APPVERSION_N = 1 -APPVERSION_P = 3 +APPVERSION_P = 4 APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)" # Application source files diff --git a/src/signTx_ui.c b/src/signTx_ui.c index 41b1c13d..765e27b8 100644 --- a/src/signTx_ui.c +++ b/src/signTx_ui.c @@ -293,6 +293,8 @@ void signTx_handleInput_ui_runStep() // ============================== FEE ============================== +#define MAX_FEES 5000000 // 5 ADA threshold + void signTx_handleFee_ui_runStep() { TRACE("UI step %d", ctx->ui_step); @@ -304,11 +306,17 @@ void signTx_handleFee_ui_runStep() UI_STEP(HANDLE_FEE_STEP_DISPLAY) { #ifdef HAVE_BAGL - ui_displayAdaAmountScreen("Transaction fee", BODY_CTX->stageData.fee, this_fn); + if (BODY_CTX->stageData.fee > (uint64_t)MAX_FEES) { + ui_displayPaginatedText("Warning: Fees are", "above 5 ADA", fee_high_cb); + } else { + fee_high_cb(); + } #elif defined(HAVE_NBGL) - char adaAmountStr[50] = {0}; - ui_getAdaAmountScreen(adaAmountStr, SIZEOF(adaAmountStr), BODY_CTX->stageData.fee); - fill_and_display_if_required("Fees", adaAmountStr, this_fn, respond_with_user_reject); + if (BODY_CTX->stageData.fee > (uint64_t)MAX_FEES) { + display_warning_fee(); + } else { + fee_high_cb(TOKEN_HIGH_FEES_NEXT, 0); + } #endif // HAVE_BAGL } UI_STEP(HANDLE_FEE_STEP_RESPOND) { diff --git a/src/ui.h b/src/ui.h index 0a78cf6e..2b9d9761 100644 --- a/src/ui.h +++ b/src/ui.h @@ -3,8 +3,17 @@ #include "io.h" #include "uiHelpers.h" +#ifdef HAVE_NBGL +#include "nbgl_use_case.h" +#endif #ifdef HAVE_NBGL +enum { + TOKEN_HIGH_FEES_NEXT = FIRST_USER_TOKEN, + TOKEN_HIGH_FEES_REJECT, +}; + + typedef void (*callback_t)(void); void set_light_confirmation(bool needed); @@ -24,6 +33,8 @@ void ui_idle_flow(void); void display_cancel_message(void); void display_error(void); void nbgl_reset_transaction_full_context(void); +void display_warning_fee(void); +void fee_high_cb(int token, uint8_t index); #endif #ifdef HAVE_BAGL diff --git a/src/uiScreens_bagl.c b/src/uiScreens_bagl.c index 1a5a0c52..cc750e6b 100644 --- a/src/uiScreens_bagl.c +++ b/src/uiScreens_bagl.c @@ -10,6 +10,7 @@ #include "state.h" #include "uiHelpers.h" #include "menu.h" +#include "signTx_ui.h" static const int INS_NONE = -1; @@ -906,4 +907,9 @@ void ui_displayInputScreen( callback ); } + +void fee_high_cb(void) { + ui_displayAdaAmountScreen("Transaction fee", BODY_CTX->stageData.fee, signTx_handleFee_ui_runStep); +} + #endif // HAVE_BAGL diff --git a/src/uiScreens_bagl.h b/src/uiScreens_bagl.h index f0d78339..dc790ee5 100644 --- a/src/uiScreens_bagl.h +++ b/src/uiScreens_bagl.h @@ -177,4 +177,6 @@ void ui_displayInputScreen( ui_callback_fn_t callback ); +void fee_high_cb(void); + #endif // H_CARDANO_APP_UI_SCREENS_BAGL diff --git a/src/ui_nbgl.c b/src/ui_nbgl.c index 5a18fb3a..aa35e7af 100644 --- a/src/ui_nbgl.c +++ b/src/ui_nbgl.c @@ -20,6 +20,7 @@ #include "ui.h" #include "uiHelpers.h" #include "uiScreens_nbgl.h" +#include "signTx_ui.h" #define MAX_LINE_PER_PAGE_COUNT NB_MAX_LINES_IN_REVIEW #define MAX_TAG_TITLE_LINE_LENGTH 30 @@ -334,7 +335,7 @@ static void _display_warning(void) { TRACE("_warning"); - nbgl_useCaseReviewStart(&C_warning64px, "WARNING", + nbgl_useCaseReviewStart(&C_Warning_64px, "WARNING", uiContext.pageText[0], "Reject if not sure", ui_callback, &display_cancel); #ifdef HEADLESS @@ -356,7 +357,7 @@ static void _display_choice(void) { TRACE("_choice"); - nbgl_useCaseChoice(&C_round_warning_64px, uiContext.pageText[0], + nbgl_useCaseChoice(&C_Important_Circle_64px, uiContext.pageText[0], uiContext.pageText[1], "Allow", "Don't Allow", display_choice_callback); #ifdef HEADLESS @@ -602,4 +603,47 @@ void display_status(const char* text) { nbgl_useCaseStatus(text, true, ui_idle_flow); } + + +void fee_high_cb(int token, uint8_t index) { + UNUSED(index); + char adaAmountStr[50] = {0}; + + switch (token) { + case TOKEN_HIGH_FEES_NEXT: + ui_getAdaAmountScreen(adaAmountStr, SIZEOF(adaAmountStr), BODY_CTX->stageData.fee); + fill_and_display_if_required("Fees", adaAmountStr, signTx_handleFee_ui_runStep, respond_with_user_reject); + break; + case TOKEN_HIGH_FEES_REJECT: + nbgl_useCaseConfirm("Reject transaction?", NULL, "Yes, reject", + "Go back to transaction", display_cancel_status); + break; + default: + break; + } +} + +void display_warning_fee(void) { + nbgl_pageInfoDescription_t info = {0}; + + info.footerText = "Reject"; + info.footerToken = TOKEN_HIGH_FEES_REJECT; + info.isSwipeable = true; + info.tapActionToken = TOKEN_HIGH_FEES_NEXT; + info.topRightStyle = NO_BUTTON_STYLE; + info.tuneId = TUNE_LOOK_AT_ME; + + info.centeredInfo.icon = &C_Important_Circle_64px; + info.centeredInfo.text1 = "Fee are above\n5 ADA"; + info.centeredInfo.text3 = "Swipe to review"; + info.centeredInfo.style = LARGE_CASE_GRAY_INFO; + + nbgl_pageDrawInfo(fee_high_cb, NULL, &info); + + #ifdef HEADLESS + nbgl_refresh(); + fee_high_cb(TOKEN_HIGH_FEES_NEXT, 0); + #endif +} + #endif // HAVE_NBGL