Skip to content

Commit

Permalink
feat: give an alert when enabling hash signing in settings. (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat authored Jul 10, 2024
1 parent a989c37 commit 25a6b52
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
40 changes: 34 additions & 6 deletions src/ui/nbgl_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ static const nbgl_contentInfoList_t info_list = {
.infoContents = INFO_CONTENTS,
};

static uint8_t init_setting_page;
static void review_warning_choice(bool confirm);
static void controls_callback(int token, uint8_t index, int page);

// settings menu definition
Expand All @@ -68,16 +70,42 @@ static const nbgl_genericContents_t setting_contents = {.callbackCallNeeded = fa
.contentsList = contents,
.nbContents = SETTING_CONTENTS_NB};

// callback for setting warning choice
static void review_warning_choice(bool confirm) {
if (confirm) {
switches[SWITCH_HASH_SET_ID].initState = ON_STATE;
// store the new setting value in NVM
SETTING_TOGGLE(S_HASH_SIGNING_ENABLED);
}

// Reset setting menu to the right page
nbgl_useCaseHomeAndSettings(APPNAME,
&C_icon_stellar_64px,
NULL,
init_setting_page,
&setting_contents,
&info_list,
NULL,
app_quit);
}

static void controls_callback(int token, uint8_t index, int page) {
UNUSED(index);
UNUSED(page);
init_setting_page = page;

if (token == SWITCH_HASH_SET_TOKEN) {
// toggle the switch value
switches[SWITCH_HASH_SET_ID].initState =
(!HAS_SETTING(S_HASH_SIGNING_ENABLED)) ? ON_STATE : OFF_STATE;
// store the new setting value in NVM
SETTING_TOGGLE(S_HASH_SIGNING_ENABLED);
if (HAS_SETTING(S_HASH_SIGNING_ENABLED)) {
switches[SWITCH_HASH_SET_ID].initState = OFF_STATE;
SETTING_TOGGLE(S_HASH_SIGNING_ENABLED);
} else {
// Display the warning message and ask the user to confirm
nbgl_useCaseChoice(&C_Warning_64px,
"Enable Hash Signing",
"Are you sure to\nallow hash signing?",
"I understand, confirm",
"Cancel",
review_warning_choice);
}
} else if (token == SWITCH_SEQUENCE_SET_TOKEN) {
// toggle the switch value
switches[SWITCH_SEQUENCE_SET_ID].initState =
Expand Down
2 changes: 2 additions & 0 deletions tests_zemu/tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ describe("hash signing", () => {
const settingNav = new TouchNavigation([
ButtonKind.InfoButton,
ButtonKind.ToggleSettingButton1,
ButtonKind.ConfirmYesButton,
]);
await sim.navigate(".", `${dev.prefix.toLowerCase()}-hash-signing-approve`, settingNav.schedule, true, true);
} else {
Expand Down Expand Up @@ -152,6 +153,7 @@ describe("hash signing", () => {
const settingNav = new TouchNavigation([
ButtonKind.InfoButton,
ButtonKind.ToggleSettingButton1,
ButtonKind.ConfirmYesButton,
]);
await sim.navigate(".", `${dev.prefix.toLowerCase()}-hash-signing-reject`, settingNav.schedule, true, false);
} else {
Expand Down

0 comments on commit 25a6b52

Please sign in to comment.