Skip to content

Commit

Permalink
Merge pull request #638 from LedgerHQ/cev/B2CA-1776_notification-order
Browse files Browse the repository at this point in the history
B2CA-1776: Change Confirm/Cancel notifications order
  • Loading branch information
cedelavergne-ledger committed Sep 12, 2024
2 parents 4d18bf6 + 8775a20 commit 74df8c0
Show file tree
Hide file tree
Showing 20 changed files with 118 additions and 80 deletions.
3 changes: 3 additions & 0 deletions src/plugins.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "eth_plugin_handler.h"
#include "ui_callbacks.h"
#include "common_ui.h"

void plugin_ui_get_id(void) {
ethQueryContractID_t pluginQueryContractID;
Expand All @@ -11,6 +12,7 @@ void plugin_ui_get_id(void) {
// Query the original contract for ID if it's not an internal alias
if (!eth_plugin_call(ETH_PLUGIN_QUERY_CONTRACT_ID, (void *) &pluginQueryContractID)) {
PRINTF("Plugin query contract ID call failed\n");
ui_idle();
io_seproxyhal_touch_tx_cancel();
}
}
Expand All @@ -28,6 +30,7 @@ void plugin_ui_get_item_internal(char *title_buffer,
msg_buffer_size);
if (!eth_plugin_call(ETH_PLUGIN_QUERY_CONTRACT_UI, (void *) &pluginQueryContractUI)) {
PRINTF("Plugin query contract UI call failed\n");
ui_idle();
io_seproxyhal_touch_tx_cancel();
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/ui_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ unsigned int io_seproxyhal_touch_data_cancel(void);
unsigned int io_seproxyhal_touch_eth2_address_ok(void);
unsigned int io_seproxyhal_touch_privacy_ok(void);
unsigned int io_seproxyhal_touch_privacy_cancel(void);
unsigned int address_cancel_cb(void);
unsigned int tx_ok_cb(void);
unsigned int tx_cancel_cb(void);

uint16_t io_seproxyhal_send_status(uint16_t sw, uint32_t tx, bool reset, bool idle);
15 changes: 15 additions & 0 deletions src_bagl/common_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,19 @@ void ui_confirm_parameter(void) {
ux_flow_init(0, ux_confirm_parameter_flow, NULL);
}

unsigned int address_cancel_cb(void) {
ui_idle();
return io_seproxyhal_touch_address_cancel();
}

unsigned int tx_ok_cb(void) {
ui_idle();
return io_seproxyhal_touch_tx_ok();
}

unsigned int tx_cancel_cb(void) {
ui_idle();
return io_seproxyhal_touch_tx_cancel();
}

#endif // HAVE_BAGL
4 changes: 2 additions & 2 deletions src_bagl/ui_flow_erc20_approval.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ UX_STEP_NOCB(
UX_STEP_CB(
ux_approval_allowance_6_step,
pbb,
io_seproxyhal_touch_tx_ok(),
tx_ok_cb(),
{
&C_icon_validate_14,
"Accept",
Expand All @@ -55,7 +55,7 @@ UX_STEP_CB(
UX_STEP_CB(
ux_approval_allowance_7_step,
pb,
io_seproxyhal_touch_tx_cancel(),
tx_cancel_cb(),
{
&C_icon_crossmark,
"Reject",
Expand Down
2 changes: 1 addition & 1 deletion src_bagl/ui_flow_getEth2PublicKey.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ UX_STEP_CB(
UX_STEP_CB(
ux_display_public_eth2_flow_4_step,
pb,
io_seproxyhal_touch_address_cancel(),
address_cancel_cb(),
{
&C_icon_crossmark,
"Reject",
Expand Down
10 changes: 8 additions & 2 deletions src_bagl/ui_flow_getPublicKey.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#include "shared_context.h"
#include "ui_callbacks.h"
#include "common_ui.h"

static unsigned int address_ok_cb(void) {
ui_idle();
return io_seproxyhal_touch_address_ok();
}

// clang-format off
UX_STEP_NOCB(
Expand All @@ -20,15 +26,15 @@ UX_STEP_NOCB(
UX_STEP_CB(
ux_display_public_flow_3_step,
pb,
io_seproxyhal_touch_address_ok(),
address_ok_cb(),
{
&C_icon_validate_14,
"Approve",
});
UX_STEP_CB(
ux_display_public_flow_4_step,
pb,
io_seproxyhal_touch_address_cancel(),
address_cancel_cb(),
{
&C_icon_crossmark,
"Reject",
Expand Down
14 changes: 12 additions & 2 deletions src_bagl/ui_flow_signMessage.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ static void dummy_post_cb(void) {
}
}

static unsigned int signMessage_ok_cb(void) {
ui_idle();
return io_seproxyhal_touch_signMessage_ok();
}

static unsigned int signMessage_cancel_cb(void) {
ui_idle();
return io_seproxyhal_touch_signMessage_cancel();
}

// clang-format off
UX_STEP_NOCB(
ux_191_step_review,
Expand Down Expand Up @@ -79,7 +89,7 @@ UX_STEP_INIT(
UX_STEP_CB(
ux_191_step_sign,
pbb,
io_seproxyhal_touch_signMessage_ok(),
signMessage_ok_cb(),
{
&C_icon_validate_14,
"Sign",
Expand All @@ -88,7 +98,7 @@ UX_STEP_CB(
UX_STEP_CB(
ux_191_step_cancel,
pbb,
io_seproxyhal_touch_signMessage_cancel(),
signMessage_cancel_cb(),
{
&C_icon_crossmark,
"Cancel",
Expand Down
15 changes: 13 additions & 2 deletions src_bagl/ui_flow_signMessage712.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "ui_logic.h"
#include "shared_context.h" // strings
#include "common_ui.h"

enum { UI_712_POS_REVIEW, UI_712_POS_END };
static uint8_t ui_pos;
Expand All @@ -28,6 +29,16 @@ static void dummy_cb(void) {
}
}

static unsigned int _approve_cb(void) {
ui_idle();
return ui_712_approve();
}

static unsigned int _reject_cb(void) {
ui_idle();
return ui_712_reject();
}

// clang-format off
UX_STEP_NOCB(
ux_712_step_review,
Expand Down Expand Up @@ -56,15 +67,15 @@ UX_STEP_INIT(
UX_STEP_CB(
ux_712_step_approve,
pb,
ui_712_approve(),
_approve_cb(),
{
&C_icon_validate_14,
"Approve",
});
UX_STEP_CB(
ux_712_step_reject,
pb,
ui_712_reject(),
_reject_cb(),
{
&C_icon_crossmark,
"Reject",
Expand Down
15 changes: 13 additions & 2 deletions src_bagl/ui_flow_signMessage712_v0.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ui_callbacks.h"
#include "common_712.h"
#include "uint_common.h"
#include "common_ui.h"

void prepare_domain_hash_v0() {
array_bytes_string(strings.tmp.tmp,
Expand All @@ -17,6 +18,16 @@ void prepare_message_hash_v0() {
KECCAK256_HASH_BYTESIZE);
}

static unsigned int _approve_cb(void) {
ui_idle();
return ui_712_approve_cb();
}

static unsigned int _reject_cb(void) {
ui_idle();
return ui_712_reject_cb();
}

// clang-format off
UX_STEP_NOCB(
ux_sign_712_v0_flow_1_step,
Expand Down Expand Up @@ -45,7 +56,7 @@ UX_STEP_NOCB_INIT(
UX_STEP_CB(
ux_sign_712_v0_flow_4_step,
pbb,
ui_712_approve_cb(),
_approve_cb(),
{
&C_icon_validate_14,
"Sign",
Expand All @@ -54,7 +65,7 @@ UX_STEP_CB(
UX_STEP_CB(
ux_sign_712_v0_flow_5_step,
pbb,
ui_712_reject_cb(),
_reject_cb(),
{
&C_icon_crossmark,
"Cancel",
Expand Down
24 changes: 17 additions & 7 deletions src_bagl/ui_flow_signTx.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
#include "domain_name.h"
#include "ui_domain_name.h"

static unsigned int data_ok_cb(void) {
ui_idle();
return io_seproxyhal_touch_data_ok();
}

static unsigned int data_cancel_cb(void) {
ui_idle();
return io_seproxyhal_touch_data_cancel();
}

// clang-format off
UX_STEP_NOCB(
ux_confirm_selector_flow_1_step,
Expand All @@ -31,15 +41,15 @@ UX_STEP_NOCB(
UX_STEP_CB(
ux_confirm_selector_flow_3_step,
pb,
io_seproxyhal_touch_data_ok(),
data_ok_cb(),
{
&C_icon_validate_14,
"Approve",
});
UX_STEP_CB(
ux_confirm_selector_flow_4_step,
pb,
io_seproxyhal_touch_data_cancel(),
data_cancel_cb(),
{
&C_icon_crossmark,
"Reject",
Expand Down Expand Up @@ -72,15 +82,15 @@ UX_STEP_NOCB(
UX_STEP_CB(
ux_confirm_parameter_flow_3_step,
pb,
io_seproxyhal_touch_data_ok(),
data_ok_cb(),
{
&C_icon_validate_14,
"Approve",
});
UX_STEP_CB(
ux_confirm_parameter_flow_4_step,
pb,
io_seproxyhal_touch_data_cancel(),
data_cancel_cb(),
{
&C_icon_crossmark,
"Reject",
Expand Down Expand Up @@ -176,7 +186,7 @@ UX_STEP_NOCB(
UX_STEP_CB(
ux_approval_accept_step,
pbb,
io_seproxyhal_touch_tx_ok(),
tx_ok_cb(),
{
&C_icon_validate_14,
"Accept",
Expand All @@ -185,7 +195,7 @@ UX_STEP_CB(
UX_STEP_CB(
ux_approval_accept_blind_step,
pbb,
io_seproxyhal_touch_tx_ok(),
tx_ok_cb(),
{
&C_icon_validate_14,
"Accept risk",
Expand All @@ -194,7 +204,7 @@ UX_STEP_CB(
UX_STEP_CB(
ux_approval_reject_step,
pb,
io_seproxyhal_touch_tx_cancel(),
tx_cancel_cb(),
{
&C_icon_crossmark,
"Reject",
Expand Down
4 changes: 2 additions & 2 deletions src_features/getPublicKey/ui_common_getPublicKey.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

unsigned int io_seproxyhal_touch_address_ok(void) {
uint32_t tx = set_result_get_publicKey();
return io_seproxyhal_send_status(APDU_RESPONSE_OK, tx, true, true);
return io_seproxyhal_send_status(APDU_RESPONSE_OK, tx, true, false);
}

unsigned int io_seproxyhal_touch_address_cancel(void) {
return io_seproxyhal_send_status(APDU_RESPONSE_CONDITION_NOT_SATISFIED, 0, true, true);
return io_seproxyhal_send_status(APDU_RESPONSE_CONDITION_NOT_SATISFIED, 0, true, false);
}
4 changes: 2 additions & 2 deletions src_features/signMessage/ui_common_signMessage.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ unsigned int io_seproxyhal_touch_signMessage_ok(void) {
if (info & CX_ECCINFO_xGTn) {
G_io_apdu_buffer[0] += 2;
}
return io_seproxyhal_send_status(APDU_RESPONSE_OK, 65, true, true);
return io_seproxyhal_send_status(APDU_RESPONSE_OK, 65, true, false);
}

unsigned int io_seproxyhal_touch_signMessage_cancel(void) {
return io_seproxyhal_send_status(APDU_RESPONSE_CONDITION_NOT_SATISFIED, 0, true, true);
return io_seproxyhal_send_status(APDU_RESPONSE_CONDITION_NOT_SATISFIED, 0, true, false);
}
4 changes: 2 additions & 2 deletions src_features/signMessageEIP712_common/common_712.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ unsigned int ui_712_approve_cb(void) {
if (info & CX_ECCINFO_xGTn) {
G_io_apdu_buffer[0] += 2;
}
return io_seproxyhal_send_status(APDU_RESPONSE_OK, 65, true, true);
return io_seproxyhal_send_status(APDU_RESPONSE_OK, 65, true, false);
}

unsigned int ui_712_reject_cb(void) {
return io_seproxyhal_send_status(APDU_RESPONSE_CONDITION_NOT_SATISFIED, 0, true, true);
return io_seproxyhal_send_status(APDU_RESPONSE_CONDITION_NOT_SATISFIED, 0, true, false);
}
1 change: 1 addition & 0 deletions src_features/signTx/logic_signTx.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ uint16_t finalizeParsing(void) {
// If called from swap, the user has already validated a standard transaction
// And we have already checked the fields of this transaction above
if (G_called_from_swap && g_use_standard_ui) {
ui_idle();
io_seproxyhal_touch_tx_ok();
} else {
// If blind-signing detected, start the warning flow beforehand
Expand Down
4 changes: 1 addition & 3 deletions src_features/signTx/ui_common_signTx.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,11 @@ uint32_t io_seproxyhal_touch_tx_ok(void) {
}
}
reset_app_context();
// Display back the original UX
ui_idle();
return 0; // do not redraw the widget
}

unsigned int io_seproxyhal_touch_tx_cancel(void) {
return io_seproxyhal_send_status(APDU_RESPONSE_CONDITION_NOT_SATISFIED, 0, true, true);
return io_seproxyhal_send_status(APDU_RESPONSE_CONDITION_NOT_SATISFIED, 0, true, false);
}

unsigned int io_seproxyhal_touch_data_ok(void) {
Expand Down
18 changes: 6 additions & 12 deletions src_nbgl/ui_approve_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,15 @@ struct tx_approval_context_t {

static struct tx_approval_context_t tx_approval_context;

static void reviewReject(void) {
io_seproxyhal_touch_tx_cancel();
memset(&tx_approval_context, 0, sizeof(tx_approval_context));
}

static void confirmTransation(void) {
io_seproxyhal_touch_tx_ok();
memset(&tx_approval_context, 0, sizeof(tx_approval_context));
}

static void reviewChoice(bool confirm) {
if (confirm) {
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_SIGNED, confirmTransation);
io_seproxyhal_touch_tx_ok();
memset(&tx_approval_context, 0, sizeof(tx_approval_context));
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_SIGNED, ui_idle);
} else {
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, reviewReject);
io_seproxyhal_touch_tx_cancel();
memset(&tx_approval_context, 0, sizeof(tx_approval_context));
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, ui_idle);
}
}

Expand Down
Loading

0 comments on commit 74df8c0

Please sign in to comment.