diff --git a/src/handler/sign_psbt.c b/src/handler/sign_psbt.c index 154b0f82a..90d42f2b1 100644 --- a/src/handler/sign_psbt.c +++ b/src/handler/sign_psbt.c @@ -1378,19 +1378,11 @@ confirm_transaction(dispatcher_context_t *dc, sign_psbt_state_t *st) { } } else { // Show final user validation UI - if (st->outputs.n_external == 0) { - // All outputs are change; show the user it's a self transfer - if (!ui_validate_selftransfer(dc, COIN_COINID_SHORT, fee)) { - SEND_SW(dc, SW_DENY); - ui_post_processing_confirm_transaction(dc, false); - return false; - } - } else { - if (!ui_validate_transaction(dc, COIN_COINID_SHORT, fee)) { - SEND_SW(dc, SW_DENY); - ui_post_processing_confirm_transaction(dc, false); - return false; - } + bool is_self_transfer = st->outputs.n_external == 0; + if (!ui_validate_transaction(dc, COIN_COINID_SHORT, fee, is_self_transfer)) { + SEND_SW(dc, SW_DENY); + ui_post_processing_confirm_transaction(dc, false); + return false; } } diff --git a/src/ui/display.c b/src/ui/display.c index 63742c5d1..57db7a691 100644 --- a/src/ui/display.c +++ b/src/ui/display.c @@ -199,23 +199,15 @@ bool ui_validate_output(dispatcher_context_t *context, return io_ui_process(context, true); } -bool ui_validate_transaction(dispatcher_context_t *context, const char *coin_name, uint64_t fee) { +bool ui_validate_transaction(dispatcher_context_t *context, + const char *coin_name, + uint64_t fee, + bool is_self_transfer) { ui_validate_transaction_state_t *state = (ui_validate_transaction_state_t *) &g_ui_state; format_sats_amount(coin_name, fee, state->fee); - ui_accept_transaction_flow(); - - return io_ui_process(context, true); -} - -// Special case when all the outputs are change: show a "Self-transfer" screen in the flow -bool ui_validate_selftransfer(dispatcher_context_t *context, const char *coin_name, uint64_t fee) { - ui_validate_transaction_state_t *state = (ui_validate_transaction_state_t *) &g_ui_state; - - format_sats_amount(coin_name, fee, state->fee); - - ui_accept_selftransfer_flow(); + ui_accept_transaction_flow(is_self_transfer); return io_ui_process(context, true); } diff --git a/src/ui/display.h b/src/ui/display.h index 9026b4cfd..21eb450cc 100644 --- a/src/ui/display.h +++ b/src/ui/display.h @@ -132,9 +132,10 @@ bool ui_validate_output(dispatcher_context_t *context, const char *coin_name, uint64_t amount); -bool ui_validate_transaction(dispatcher_context_t *context, const char *coin_name, uint64_t fee); - -bool ui_validate_selftransfer(dispatcher_context_t *context, const char *coin_name, uint64_t fee); +bool ui_validate_transaction(dispatcher_context_t *context, + const char *coin_name, + uint64_t fee, + bool is_self_transfer); void set_ux_flow_response(bool approved); @@ -164,9 +165,7 @@ void ui_display_output_address_amount_flow(int index); void ui_display_output_address_amount_no_index_flow(int index); -void ui_accept_transaction_flow(void); - -void ui_accept_selftransfer_flow(void); +void ui_accept_transaction_flow(bool is_self_transfer); void ui_display_transaction_prompt(const int external_outputs_total_count); diff --git a/src/ui/display_bagl.c b/src/ui/display_bagl.c index 38486e2c4..5bbfd709c 100644 --- a/src/ui/display_bagl.c +++ b/src/ui/display_bagl.c @@ -466,12 +466,10 @@ void ui_display_output_address_amount_no_index_flow(int index) { ui_display_output_address_amount_flow(index); } -void ui_accept_transaction_flow(void) { - ux_flow_init(0, ux_accept_transaction_flow, NULL); -} - -void ui_accept_selftransfer_flow(void) { - ux_flow_init(0, ux_accept_selftransfer_flow, NULL); +void ui_accept_transaction_flow(bool is_self_transfer) { + ux_flow_init(0, + is_self_transfer ? ux_accept_selftransfer_flow : ux_accept_transaction_flow, + NULL); } #endif // HAVE_BAGL diff --git a/src/ui/display_nbgl.c b/src/ui/display_nbgl.c index 1a423c0f1..591dc4dd5 100644 --- a/src/ui/display_nbgl.c +++ b/src/ui/display_nbgl.c @@ -93,10 +93,10 @@ static void transaction_confirm_callback(int token, uint8_t index) { ux_flow_response(true); break; case BACK_TOKEN_TRANSACTION: - ui_accept_transaction_flow(); + ui_accept_transaction_flow(false); break; case BACK_TOKEN_SELFTRANSFER: - ui_accept_selftransfer_flow(); + ui_accept_transaction_flow(true); break; default: PRINTF("Unhandled token : %d", token); @@ -183,42 +183,20 @@ static void transaction_confirm(int token, uint8_t index) { } } -void ui_accept_transaction_flow(void) { - transactionContext.tagValuePair[0].item = "Fees"; - transactionContext.tagValuePair[0].value = g_ui_state.validate_transaction.fee; +void ui_accept_transaction_flow(bool is_self_transfer) { + if (!is_self_transfer) { + transactionContext.tagValuePair[0].item = "Fees"; + transactionContext.tagValuePair[0].value = g_ui_state.validate_transaction.fee; - transactionContext.tagValueList.nbPairs = 1; - - transactionContext.confirm = "Sign transaction\nto send Bitcoin?"; - transactionContext.confirmed_status = "TRANSACTION\nSIGNED"; - transactionContext.rejected_status = "Transaction rejected"; - - nbgl_pageNavigationInfo_t info = {.activePage = transactionContext.extOutputCount, - .nbPages = transactionContext.extOutputCount + 2, - .navType = NAV_WITH_TAP, - .progressIndicator = true, - .navWithTap.backButton = false, - .navWithTap.nextPageText = "Tap to continue", - .navWithTap.nextPageToken = CONFIRM_TOKEN, - .navWithTap.quitText = "Reject transaction", - .quitToken = CANCEL_TOKEN, - .tuneId = TUNE_TAP_CASUAL}; - - nbgl_pageContent_t content = {.type = TAG_VALUE_LIST, - .tagValueList.nbPairs = transactionContext.tagValueList.nbPairs, - .tagValueList.pairs = transactionContext.tagValuePair}; - - nbgl_pageDrawGenericContent(&transaction_confirm, &info, &content); - nbgl_refresh(); -} - -void ui_accept_selftransfer_flow(void) { - transactionContext.tagValuePair[0].item = "Amount"; - transactionContext.tagValuePair[0].value = "Self-transfer"; - transactionContext.tagValuePair[1].item = "Fees"; - transactionContext.tagValuePair[1].value = g_ui_state.validate_transaction.fee; + transactionContext.tagValueList.nbPairs = 1; + } else { + transactionContext.tagValuePair[0].item = "Amount"; + transactionContext.tagValuePair[0].value = "Self-transfer"; + transactionContext.tagValuePair[1].item = "Fees"; + transactionContext.tagValuePair[1].value = g_ui_state.validate_transaction.fee; - transactionContext.tagValueList.nbPairs = 2; + transactionContext.tagValueList.nbPairs = 2; + } transactionContext.confirm = "Sign transaction\nto send Bitcoin?"; transactionContext.confirmed_status = "TRANSACTION\nSIGNED";