Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B2CA-1813: High Fees warning screen #80

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions src/signTx_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/uiScreens_bagl.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "state.h"
#include "uiHelpers.h"
#include "menu.h"
#include "signTx_ui.h"

static const int INS_NONE = -1;

Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/uiScreens_bagl.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,6 @@ void ui_displayInputScreen(
ui_callback_fn_t callback
);

void fee_high_cb(void);

#endif // H_CARDANO_APP_UI_SCREENS_BAGL
48 changes: 46 additions & 2 deletions src/ui_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Loading