diff --git a/app/src/globals.c b/app/src/globals.c index 5e8056d08..4663ddd46 100644 --- a/app/src/globals.c +++ b/app/src/globals.c @@ -47,10 +47,17 @@ toggle_expert_mode(void) } void -toggle_blindsign_status(void) +set_blindsign_status(blindsign_state_t status) { settings_t tmp; memcpy(&tmp, (void *)&N_settings, sizeof(tmp)); - tmp.blindsign_status = (tmp.blindsign_status + 1) % 3; + tmp.blindsign_status = status; nvm_write((void *)&N_settings, (void *)&tmp, sizeof(N_settings)); } + +void +toggle_blindsign_status(void) +{ + blindsign_state_t status = (N_settings.blindsign_status + 1) % 3; + set_blindsign_status(status); +} diff --git a/app/src/globals.h b/app/src/globals.h index 5483e228e..f5cb40ee8 100644 --- a/app/src/globals.h +++ b/app/src/globals.h @@ -43,17 +43,6 @@ #include "utils.h" #include "parser/parser_state.h" -/** - * @brief Zeros out all application-specific globals and SDK-specific - * UI/exchange buffers. - */ -void init_globals(void); - -/// Toggles the persisted expert_mode setting -void toggle_expert_mode(void); - -/// toggles the blindsign setting between "For large tx", "ON", "OFF". -void toggle_blindsign_status(void); #define MAX_APDU_SIZE 235 #define MAX_SIGNATURE_SIZE 100 @@ -149,3 +138,19 @@ extern unsigned int app_stack_canary; // From SDK * */ extern unsigned char G_io_seproxyhal_spi_buffer[IO_SEPROXYHAL_BUFFER_SIZE_B]; + +/** + * @brief Zeros out all application-specific globals and SDK-specific + * UI/exchange buffers. + */ +void init_globals(void); + +/// Toggles the persisted expert_mode setting +void toggle_expert_mode(void); + +/// Toggles the persisted blindsign setting between "For large tx", "ON", +/// "OFF". +void toggle_blindsign_status(void); + +/// set the blindsign setting between "For large tx", "ON", "OFF". +void set_blindsign_status(blindsign_state_t status); diff --git a/app/src/ui_home.c b/app/src/ui_home.c index 544cf58d5..b118c86cb 100644 --- a/app/src/ui_home.c +++ b/app/src/ui_home.c @@ -63,7 +63,7 @@ void ui_home_init(void) { FUNC_ENTER(("void")); - tz_ui_home_redisplay(); + tz_ui_home_redisplay(INIT_HOME_PAGE); FUNC_LEAVE(); } #endif // HAVE_NBGL diff --git a/app/src/ui_home_nbgl.c b/app/src/ui_home_nbgl.c index cf718b653..1c41ece2d 100644 --- a/app/src/ui_home_nbgl.c +++ b/app/src/ui_home_nbgl.c @@ -28,79 +28,115 @@ #include "globals.h" #include "nbgl_use_case.h" -void tz_ui_home_redisplay(void); +static void controls_callback(int token, + __attribute__((unused)) uint8_t index, + __attribute__((unused)) int page); +void tz_ui_home_redisplay(uint8_t page); // ----------------------------------------------------------- // --------------------- SETTINGS MENU ----------------------- // ----------------------------------------------------------- -#define SETTING_INFO_NB 2 +#define SETTING_INFO_NB 2 +#define SETTINGS_SWITCHES_NB 1 +#define SETTINGS_RADIO_NB 3 static const char *const infoTypes[] = {"Version", "Developer"}; static const char *const infoContents[] = {APPVERSION, "Trilitech Kanvas Limited et al."}; enum { EXPERT_MODE_TOKEN = FIRST_USER_TOKEN, + BLINDSIGN_MODE_TOKEN }; enum { EXPERT_MODE_TOKEN_ID = 0, - SETTINGS_SWITCHES_NB + BLINDSIGN_MODE_TOKEN_ID, + SETTINGS_CONTENTS_NB +}; +enum { + EXPERT_MODE_PAGE = 0, + BLINDSIGN_PAGE = 1 }; -static nbgl_layoutSwitch_t switches[SETTINGS_SWITCHES_NB] = {0}; - +static nbgl_contentSwitch_t expert_mode_switch = {0}; static const nbgl_contentInfoList_t infoList = {.nbInfos = SETTING_INFO_NB, .infoTypes = infoTypes, .infoContents = infoContents}; +static const char *const blindsign_choices_text[] + = {"Blindsign For Large Tx", "Blindsigning ON", "Blindsigning OFF"}; + +static void +get_contents(uint8_t index, nbgl_content_t *content) +{ + FUNC_ENTER(("Index: %d", index)); + if (index == EXPERT_MODE_TOKEN_ID) { + content->content.switchesList.nbSwitches = SETTINGS_SWITCHES_NB; + content->content.switchesList.switches = &expert_mode_switch; + content->type = SWITCHES_LIST; + content->contentActionCallback = controls_callback; + } else { + content->content.choicesList.nbChoices = SETTINGS_RADIO_NB; + content->content.choicesList.names = blindsign_choices_text; + content->content.choicesList.token = BLINDSIGN_MODE_TOKEN; + content->content.choicesList.initChoice = N_settings.blindsign_status; + content->type = CHOICES_LIST; + content->contentActionCallback = controls_callback; + } + FUNC_LEAVE(); +} + static void controls_callback(int token, __attribute__((unused)) uint8_t index, __attribute__((unused)) int page) { + FUNC_ENTER(("Token : %d, Index: %d, Page: %d", token, index, page)); uint8_t switch_value; if (token == EXPERT_MODE_TOKEN) { switch_value = !N_settings.expert_mode; toggle_expert_mode(); - switches[EXPERT_MODE_TOKEN_ID].initState - = (nbgl_state_t)(switch_value); + expert_mode_switch.initState = (nbgl_state_t)(switch_value); } + if (token == BLINDSIGN_MODE_TOKEN) { + blindsign_state_t blindsign_status = (blindsign_state_t)(index % 3); + set_blindsign_status(blindsign_status); + tz_ui_home_redisplay(BLINDSIGN_PAGE); + } + FUNC_LEAVE(); } -#define SETTINGS_CONTENTS_NB 1 -static const nbgl_content_t contentsList[SETTINGS_CONTENTS_NB] = { - {.content.switchesList.nbSwitches = SETTINGS_SWITCHES_NB, - .content.switchesList.switches = switches, - .type = SWITCHES_LIST, - .contentActionCallback = controls_callback} -}; - -static const nbgl_genericContents_t tezos_settingContents - = {.callbackCallNeeded = false, - .contentsList = contentsList, - .nbContents = SETTINGS_CONTENTS_NB}; -; - #define HOME_TEXT "This app enables signing transactions on the Tezos Network" + void initSettings(void) { - switches[EXPERT_MODE_TOKEN_ID].initState - = (nbgl_state_t)(N_settings.expert_mode); - switches[EXPERT_MODE_TOKEN_ID].text = "Expert mode"; - switches[EXPERT_MODE_TOKEN_ID].subText = "Enable expert mode signing"; - switches[EXPERT_MODE_TOKEN_ID].token = EXPERT_MODE_TOKEN; - switches[EXPERT_MODE_TOKEN_ID].tuneId = TUNE_TAP_CASUAL; + expert_mode_switch.initState = (nbgl_state_t)(N_settings.expert_mode); + expert_mode_switch.text = "Expert mode"; + expert_mode_switch.subText = "Enable expert mode signing"; + expert_mode_switch.token = EXPERT_MODE_TOKEN; + expert_mode_switch.tuneId = TUNE_TAP_CASUAL; } void -tz_ui_home_redisplay(void) +tz_ui_home_redisplay(uint8_t page) { FUNC_ENTER(("void")); initSettings(); + static nbgl_genericContents_t tezos_settingContents = {0}; + tezos_settingContents.callbackCallNeeded = false; + tezos_settingContents.nbContents = SETTINGS_CONTENTS_NB; + + static nbgl_content_t contents[SETTINGS_CONTENTS_NB] = {0}; + get_contents(EXPERT_MODE_TOKEN_ID, &contents[EXPERT_MODE_TOKEN_ID]); + get_contents(BLINDSIGN_MODE_TOKEN_ID, &contents[BLINDSIGN_MODE_TOKEN_ID]); + + tezos_settingContents.contentsList = contents; + + PRINTF("Entered settings and initialized\n"); - nbgl_useCaseHomeAndSettings("Tezos Wallet", &C_tezos, HOME_TEXT, - INIT_HOME_PAGE, &tezos_settingContents, - &infoList, NULL, app_exit); + nbgl_useCaseHomeAndSettings("Tezos Wallet", &C_tezos, HOME_TEXT, page, + &tezos_settingContents, &infoList, NULL, + app_exit); FUNC_LEAVE(); } diff --git a/app/src/ui_home_nbgl.h b/app/src/ui_home_nbgl.h index cd9eaeb5d..b57104761 100644 --- a/app/src/ui_home_nbgl.h +++ b/app/src/ui_home_nbgl.h @@ -22,6 +22,6 @@ #ifdef HAVE_NBGL -void tz_ui_home_redisplay(void); +void tz_ui_home_redisplay(uint8_t page); #endif diff --git a/tests/integration/touch/snapshots/flex/test_basic/settings_BlindsigningStatus-Large_Tx_only.png b/tests/integration/touch/snapshots/flex/test_basic/settings_BlindsigningStatus-Large_Tx_only.png new file mode 100644 index 000000000..96d653922 Binary files /dev/null and b/tests/integration/touch/snapshots/flex/test_basic/settings_BlindsigningStatus-Large_Tx_only.png differ diff --git a/tests/integration/touch/snapshots/flex/test_basic/settings_BlindsigningStatus-OFF.png b/tests/integration/touch/snapshots/flex/test_basic/settings_BlindsigningStatus-OFF.png new file mode 100644 index 000000000..2836c2288 Binary files /dev/null and b/tests/integration/touch/snapshots/flex/test_basic/settings_BlindsigningStatus-OFF.png differ diff --git a/tests/integration/touch/snapshots/flex/test_basic/settings_BlindsigningStatus-ON.png b/tests/integration/touch/snapshots/flex/test_basic/settings_BlindsigningStatus-ON.png new file mode 100644 index 000000000..f95ae2b2b Binary files /dev/null and b/tests/integration/touch/snapshots/flex/test_basic/settings_BlindsigningStatus-ON.png differ diff --git a/tests/integration/touch/snapshots/stax/test_basic/settings_BlindsigningStatus-Large_Tx_only.png b/tests/integration/touch/snapshots/stax/test_basic/settings_BlindsigningStatus-Large_Tx_only.png new file mode 100644 index 000000000..596390634 Binary files /dev/null and b/tests/integration/touch/snapshots/stax/test_basic/settings_BlindsigningStatus-Large_Tx_only.png differ diff --git a/tests/integration/touch/snapshots/stax/test_basic/settings_BlindsigningStatus-OFF.png b/tests/integration/touch/snapshots/stax/test_basic/settings_BlindsigningStatus-OFF.png new file mode 100644 index 000000000..a25587e19 Binary files /dev/null and b/tests/integration/touch/snapshots/stax/test_basic/settings_BlindsigningStatus-OFF.png differ diff --git a/tests/integration/touch/snapshots/stax/test_basic/settings_BlindsigningStatus-ON.png b/tests/integration/touch/snapshots/stax/test_basic/settings_BlindsigningStatus-ON.png new file mode 100644 index 000000000..107c31ed6 Binary files /dev/null and b/tests/integration/touch/snapshots/stax/test_basic/settings_BlindsigningStatus-ON.png differ diff --git a/tests/integration/touch/test_basic.py b/tests/integration/touch/test_basic.py index ea4c2a373..1e5095dfc 100755 --- a/tests/integration/touch/test_basic.py +++ b/tests/integration/touch/test_basic.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from utils import tezos_app +from utils import tezos_app, BlindsigningStatus if __name__ == "__main__": app = tezos_app(__file__) @@ -22,14 +22,20 @@ app.assert_home() app.welcome.settings() - app.assert_settings() + app.assert_expert_mode() app.settings.toggle_expert_mode() - app.assert_settings(expert_mode=True) + app.assert_expert_mode(expert_mode=True) app.settings.toggle_expert_mode() - app.assert_settings() + app.assert_expert_mode() + app.settings.next() + app.assert_blindsigning_status(blindsignStatus=BlindsigningStatus.Large_Tx_only) + app.settings.set_blindigning(2) + app.assert_blindsigning_status(blindsignStatus=BlindsigningStatus.ON) + app.settings.set_blindigning(3) + app.assert_blindsigning_status(blindsignStatus=BlindsigningStatus.OFF) app.settings.next() app.assert_info() diff --git a/tests/integration/touch/utils.py b/tests/integration/touch/utils.py index 169d71017..74e9591d7 100644 --- a/tests/integration/touch/utils.py +++ b/tests/integration/touch/utils.py @@ -15,6 +15,7 @@ import os import time +from enum import Enum from pathlib import Path from typing import Generator, List @@ -136,15 +137,21 @@ def toggle_expert_mode(self): """Toggle the expert_mode switch.""" self._toggle_list.choose(1) - def toggle_blindsigning(self): - """Toggle the blindsigning switch.""" - self._toggle_list.choose(2) + def set_blindigning(self, value: int): + if value not in [1, 2, 3]: + raise ValueError("Value must be 1, 2 or 3") + self._toggle_list.choose(value) def exit(self) -> None: """Exits settings.""" self.multi_page_exit() +class BlindsigningStatus(Enum): + Large_Tx_only = 1 + ON = 2 + OFF = 3 + class TezosAppScreen(metaclass=MetaScreen): use_case_welcome = UseCaseHomeExt use_case_settings = UseCaseSettings @@ -244,16 +251,16 @@ def assert_home(self): def assert_info(self): self.assert_screen("info", True) - def assert_settings(self, - blindsigning = False, - expert_mode = False): - suffix="" - if blindsigning: - suffix += "_blindsigning" + def assert_expert_mode(self, expert_mode=False): + suffix = "" if expert_mode: - suffix += "_expert" - if suffix != "": - suffix += "_on" + suffix += "_expert_on" + self.assert_screen("settings" + suffix) + + def assert_blindsigning_status( + self, blindsignStatus=BlindsigningStatus.Large_Tx_only + ): + suffix = "_" + str(blindsignStatus).replace(".", "-") self.assert_screen("settings" + suffix) def quit(self):