Skip to content

Commit

Permalink
Add feature
Browse files Browse the repository at this point in the history
  • Loading branch information
cedelavergne-ledger committed Feb 12, 2025
1 parent 4ddea20 commit 86cc0bc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
35 changes: 22 additions & 13 deletions src_features/provideTxSimu/cmd_getTxSimulation.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#endif
#include "network.h"
#include "common_ui.h"
#include "ui_nbgl.h"

#define TYPE_TX_SIMULATION 0x09
#define STRUCT_VERSION 0x01
Expand Down Expand Up @@ -82,6 +83,8 @@ typedef struct {

// Global structure to store the tx simultion parameters
tx_simulation_t TX_SIMULATION = {0};
// Global flag to send Opt-In result
bool g_opt_in_return;

// Macros to check the field length
#define CHECK_FIELD_LENGTH(tag, len, expected) \
Expand Down Expand Up @@ -529,27 +532,33 @@ static void opt_in_cb(bool confirm) {
// Set the Web3 Check flag
nvm_write((void *) &N_storage.w3c_enable, (void *) &confirm, sizeof(confirm));
}
G_io_apdu_buffer[0] = confirm;
io_seproxyhal_send_status(APDU_RESPONSE_OK, 1, true, true);
if (g_opt_in_return) {
// return current state
G_io_apdu_buffer[0] = confirm;
io_seproxyhal_send_status(APDU_RESPONSE_OK, 1, true, true);
} else {
// return to the settings
ui_settings();
}
}

/**
* @brief Opt-In Web3 Checks setting.
* @brief Handle Tx Simulation Opt-In.
*
* @param[in] p_warning Warning structure for NBGL review flows
* @param[in] checkTxHash flag to check the TX_HASH
* @param[in] checkFromAddr flag to check the FROM address
* @param[in] with_return flag to return the current state
*/
static void handle_opt_in(void) {
void handleTxSimulationOptIn(bool with_return) {
if (N_storage.w3c_opt_in) {
// Web3 Checks already Opt-In
PRINTF("Web3 Checks already enabled!\n");
// return current state
G_io_apdu_buffer[0] = N_storage.w3c_enable;
io_seproxyhal_send_status(APDU_RESPONSE_OK, 1, true, true);
PRINTF("Web3 Checks already Opt-in!\n");
if (with_return) {
// return current state
G_io_apdu_buffer[0] = N_storage.w3c_enable;
io_seproxyhal_send_status(APDU_RESPONSE_OK, 1, true, true);
}
return;
}
// nbgl_useCaseChoice(&INFO_I_ICON,
g_opt_in_return = with_return;
nbgl_useCaseChoice(&C_review_info_button,
"Enable transaction Check?",
"Get real-time warnings about "
Expand Down Expand Up @@ -584,7 +593,7 @@ uint16_t handleTxSimulation(uint8_t p1, const uint8_t *data, uint8_t length, uns
break;
case 0x01:
// TX Simulation Opt-In
handle_opt_in();
handleTxSimulationOptIn(true);
*flags |= IO_ASYNCH_REPLY;
sw = APDU_NO_RESPONSE;
break;
Expand Down
2 changes: 1 addition & 1 deletion src_features/provideTxSimu/cmd_getTxSimulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ typedef struct tx_simu_s {
extern tx_simulation_t TX_SIMULATION;

uint16_t handleTxSimulation(uint8_t p1, const uint8_t *data, uint8_t length, unsigned int *flags);
void optInTxSimu(void);
void handleTxSimulationOptIn(bool with_return);
void clearTxSimulation(void);
bool checkTxSimulationParams(bool checkTxHash, bool checkFromAddr);
void setTxSimuWarning(nbgl_warning_t *p_warning, bool checkTxHash, bool checkFromAddr);
Expand Down
2 changes: 2 additions & 0 deletions src_nbgl/ui_home.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "nbgl_use_case.h"
#include "caller_api.h"
#include "network.h"
#include "cmd_getTxSimulation.h"

// Global Warning struct for NBGL review flows
nbgl_warning_t warning;
Expand Down Expand Up @@ -65,6 +66,7 @@ static void setting_toggle_callback(int token, uint8_t index, int page) {
switch (token) {
#ifdef HAVE_WEB3_CHECKS
case WEB3_CHECK_TOKEN:
handleTxSimulationOptIn(false);
value = !N_storage.w3c_enable;
switches[WEB3_CHECK_ID].initState = (nbgl_state_t) value;
nvm_write((void *) &N_storage.w3c_enable, (void *) &value, sizeof(value));
Expand Down

0 comments on commit 86cc0bc

Please sign in to comment.