diff --git a/src/common_ui.h b/src/common_ui.h index 97dabad..280b8f0 100644 --- a/src/common_ui.h +++ b/src/common_ui.h @@ -13,6 +13,7 @@ void ui_display_public_key(const uint64_t *chain_id); void ui_sign_712_v0(void); void ui_confirm_selector(void); void ui_confirm_parameter(void); +void app_quit(void); // EIP-191 void ui_191_start(void); diff --git a/src_nbgl/ui_settings.c b/src_nbgl/ui_settings.c index 9d3656c..455ef32 100644 --- a/src_nbgl/ui_settings.c +++ b/src_nbgl/ui_settings.c @@ -2,8 +2,11 @@ #include "ui_nbgl.h" #include "nbgl_use_case.h" -static const char* const infoTypes[] = {"Version", APPNAME " App"}; -static const char* const infoContents[] = {APPVERSION, "(c) " BUILD_YEAR " Ledger"}; +// settings info definition +#define SETTING_INFO_NB 2 + +// settings menu definition +#define SETTING_CONTENTS_NB 1 enum { BLIND_SIGNING_TOKEN = FIRST_USER_TOKEN, @@ -11,106 +14,69 @@ enum { NONCE_TOKEN, #ifdef HAVE_EIP712_FULL_SUPPORT EIP712_VERBOSE_TOKEN, -#endif // HAVE_EIP712_FULL_SUPPORT +#endif #ifdef HAVE_DOMAIN_NAME DOMAIN_NAME_VERBOSE_TOKEN -#endif // HAVE_DOMAIN_NAME +#endif }; -static nbgl_layoutSwitch_t switches[3]; - -static bool navCallback(uint8_t page, nbgl_pageContent_t* content) { - uint8_t index = 0; - - switch (page) { - case 0: - content->type = INFOS_LIST; - content->infosList.nbInfos = 2; - content->infosList.infoTypes = (const char**) infoTypes; - content->infosList.infoContents = (const char**) infoContents; - break; - - case 1: - switches[index++] = - (nbgl_layoutSwitch_t){.initState = N_storage.dataAllowed ? ON_STATE : OFF_STATE, - .text = "Blind signing", - .subText = "Enable transaction blind\nsigning", - .token = BLIND_SIGNING_TOKEN, - .tuneId = TUNE_TAP_CASUAL}; - switches[index++] = - (nbgl_layoutSwitch_t){.initState = N_storage.contractDetails ? ON_STATE : OFF_STATE, - .text = "Debug", - .subText = "Display contract data\ndetails", - .token = DEBUG_TOKEN, - .tuneId = TUNE_TAP_CASUAL}; - switches[index++] = - (nbgl_layoutSwitch_t){.initState = N_storage.displayNonce ? ON_STATE : OFF_STATE, - .text = "Nonce", - .subText = "Display account nonce\nin transaction", - .token = NONCE_TOKEN, - .tuneId = TUNE_TAP_CASUAL}; - - content->type = SWITCHES_LIST; - content->switchesList.nbSwitches = index; - content->switchesList.switches = (nbgl_layoutSwitch_t*) switches; - break; - - case 2: +enum { + BLIND_SIGNING_ID = 0, + DEBUG_ID, + NONCE_ID, #ifdef HAVE_EIP712_FULL_SUPPORT - switches[index++] = - (nbgl_layoutSwitch_t){.initState = N_storage.verbose_eip712 ? ON_STATE : OFF_STATE, - .text = "Verbose EIP712", - .subText = "Ignore filtering and\ndisplay raw content", - .token = EIP712_VERBOSE_TOKEN, - .tuneId = TUNE_TAP_CASUAL}; -#endif // HAVE_EIP712_FULL_SUPPORT + EIP712_VERBOSE_ID, +#endif #ifdef HAVE_DOMAIN_NAME - switches[index++] = (nbgl_layoutSwitch_t){ - .initState = N_storage.verbose_domain_name ? ON_STATE : OFF_STATE, - .text = "Verbose domains", - .subText = "Show resolved address", - .token = DOMAIN_NAME_VERBOSE_TOKEN, - .tuneId = TUNE_TAP_CASUAL}; -#endif // HAVE_DOMAIN_NAME + DOMAIN_NAME_VERBOSE_ID, +#endif + SETTINGS_SWITCHES_NB +}; - content->type = SWITCHES_LIST; - content->switchesList.nbSwitches = index; - content->switchesList.switches = (nbgl_layoutSwitch_t*) switches; - break; +static uint8_t initSettingPage; - default: - return false; - break; - } +// settings definition +static const char* const infoTypes[SETTING_INFO_NB] = {"Version", APPNAME " App"}; +static const char* const infoContents[SETTING_INFO_NB] = {APPVERSION, "(c) " BUILD_YEAR " Ledger"}; - return true; -} +static nbgl_contentInfoList_t infoList = {0}; +static nbgl_contentSwitch_t switches[SETTINGS_SWITCHES_NB] = {0}; +static nbgl_content_t contents[SETTING_CONTENTS_NB] = {0}; +static nbgl_genericContents_t settingContents = {0}; -static void controlsCallback(int token, uint8_t index) { - (void) index; +static void controlsCallback(int token, uint8_t index, int page) { + UNUSED(index); uint8_t value; + + initSettingPage = page; + switch (token) { case BLIND_SIGNING_TOKEN: value = (N_storage.dataAllowed ? 0 : 1); + switches[BLIND_SIGNING_ID].initState = (nbgl_state_t) value; nvm_write((void*) &N_storage.dataAllowed, (void*) &value, sizeof(uint8_t)); break; case DEBUG_TOKEN: value = (N_storage.contractDetails ? 0 : 1); + switches[DEBUG_ID].initState = (nbgl_state_t) value; nvm_write((void*) &N_storage.contractDetails, (void*) &value, sizeof(uint8_t)); break; case NONCE_TOKEN: value = (N_storage.displayNonce ? 0 : 1); + switches[NONCE_ID].initState = (nbgl_state_t) value; nvm_write((void*) &N_storage.displayNonce, (void*) &value, sizeof(uint8_t)); break; #ifdef HAVE_EIP712_FULL_SUPPORT case EIP712_VERBOSE_TOKEN: value = (N_storage.verbose_eip712 ? 0 : 1); + switches[EIP712_VERBOSE_ID].initState = (nbgl_state_t) value; nvm_write((void*) &N_storage.verbose_eip712, (void*) &value, sizeof(uint8_t)); break; #endif // HAVE_EIP712_FULL_SUPPORT #ifdef HAVE_DOMAIN_NAME case DOMAIN_NAME_VERBOSE_TOKEN: value = (N_storage.verbose_domain_name ? 0 : 1); + switches[DOMAIN_NAME_VERBOSE_ID].initState = (nbgl_state_t) value; nvm_write((void*) &N_storage.verbose_domain_name, (void*) &value, sizeof(uint8_t)); break; #endif // HAVE_DOMAIN_NAME @@ -118,15 +84,60 @@ static void controlsCallback(int token, uint8_t index) { } void ui_menu_settings(void) { - uint8_t nb_screens = 2; -#if defined(HAVE_EIP712_FULL_SUPPORT) || defined(HAVE_DOMAIN_NAME) - nb_screens += 1; -#endif - nbgl_useCaseSettings(APPNAME " settings", - 0, - nb_screens, - false, - ui_idle, - navCallback, - controlsCallback); + switches[BLIND_SIGNING_ID].initState = N_storage.dataAllowed ? ON_STATE : OFF_STATE; + switches[BLIND_SIGNING_ID].text = "Blind signing"; + switches[BLIND_SIGNING_ID].subText = "Enable transaction blind\nsigning"; + switches[BLIND_SIGNING_ID].token = BLIND_SIGNING_TOKEN; + switches[BLIND_SIGNING_ID].tuneId = TUNE_TAP_CASUAL; + + switches[DEBUG_ID].initState = N_storage.contractDetails ? ON_STATE : OFF_STATE; + switches[DEBUG_ID].text = "Debug"; + switches[DEBUG_ID].subText = "Display contract data\ndetails"; + switches[DEBUG_ID].token = DEBUG_TOKEN; + switches[DEBUG_ID].tuneId = TUNE_TAP_CASUAL; + + switches[NONCE_ID].initState = N_storage.displayNonce ? ON_STATE : OFF_STATE; + switches[NONCE_ID].text = "Nonce"; + switches[NONCE_ID].subText = "Display account nonce\nin transaction"; + switches[NONCE_ID].token = NONCE_TOKEN; + switches[NONCE_ID].tuneId = TUNE_TAP_CASUAL; + +#ifdef HAVE_EIP712_FULL_SUPPORT + switches[EIP712_VERBOSE_ID].initState = N_storage.verbose_eip712 ? ON_STATE : OFF_STATE; + switches[EIP712_VERBOSE_ID].text = "Verbose EIP712"; + switches[EIP712_VERBOSE_ID].subText = "Ignore filtering and\ndisplay raw content"; + switches[EIP712_VERBOSE_ID].token = EIP712_VERBOSE_TOKEN; + switches[EIP712_VERBOSE_ID].tuneId = TUNE_TAP_CASUAL; +#endif // HAVE_EIP712_FULL_SUPPORT + +#ifdef HAVE_DOMAIN_NAME + switches[DOMAIN_NAME_VERBOSE_ID].initState = + N_storage.verbose_domain_name ? ON_STATE : OFF_STATE; + switches[DOMAIN_NAME_VERBOSE_ID].text = "Verbose domains"; + switches[DOMAIN_NAME_VERBOSE_ID].subText = "Show resolved address"; + switches[DOMAIN_NAME_VERBOSE_ID].token = DOMAIN_NAME_VERBOSE_TOKEN; + switches[DOMAIN_NAME_VERBOSE_ID].tuneId = TUNE_TAP_CASUAL; +#endif // HAVE_DOMAIN_NAME + + contents[0].type = SWITCHES_LIST; + contents[0].content.switchesList.nbSwitches = SETTINGS_SWITCHES_NB; + contents[0].content.switchesList.switches = switches; + contents[0].contentActionCallback = controlsCallback; + + settingContents.callbackCallNeeded = false; + settingContents.contentsList = contents; + settingContents.nbContents = SETTING_CONTENTS_NB; + + infoList.nbInfos = SETTING_INFO_NB; + infoList.infoTypes = infoTypes; + infoList.infoContents = infoContents; + + nbgl_useCaseHomeAndSettings(APPNAME, + get_app_icon(true), + NULL, + initSettingPage, + &settingContents, + &infoList, + NULL, + app_quit); }