Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
cedelavergne-ledger committed Sep 30, 2024
1 parent f92954a commit 1a6fdf3
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 65 deletions.
65 changes: 0 additions & 65 deletions src/signTx_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,71 +298,6 @@ void signTx_handleInput_ui_runStep()

#define MAX_FEES 5000000 // 5 ADA threshold

#ifdef HAVE_BAGL
static void fee_high_cb(void) {
ui_displayAdaAmountScreen("Transaction fee", BODY_CTX->stageData.fee, signTx_handleFee_ui_runStep);
}
#elif defined(HAVE_NBGL)

enum {
TOKEN_HIGH_FEES_NEXT = FIRST_USER_TOKEN,
TOKEN_HIGH_FEES_REJECT,
};

static void cancellation_status_callback(void)
{
respond_with_user_reject();
ui_idle_flow();
nbgl_reset_transaction_full_context();
}

static void display_cancel_status(void)
{
nbgl_useCaseStatus("Transaction\nrejected", false, cancellation_status_callback);
}

static 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;
}
}

static 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_BAGL

void signTx_handleFee_ui_runStep()
{
TRACE("UI step %d", ctx->ui_step);
Expand Down
14 changes: 14 additions & 0 deletions src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@

#include "io.h"
#include "uiHelpers.h"
#ifdef HAVE_NBGL
#include "nbgl_use_case.h"
#include "nbgl_layout.h"
#include "nbgl_page.h"
#include "os_io_seproxyhal.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 +36,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
44 changes: 44 additions & 0 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 @@ -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

0 comments on commit 1a6fdf3

Please sign in to comment.