Skip to content

Commit

Permalink
[touch] use useCaseHomeAndSettings for home and settings display
Browse files Browse the repository at this point in the history
Instead of useCaseHome and nbgl_useCaseSettings
  • Loading branch information
spalmer25 committed Jul 25, 2024
1 parent 3c6a05e commit 70cf539
Show file tree
Hide file tree
Showing 117 changed files with 130 additions and 80 deletions.
158 changes: 82 additions & 76 deletions src/ui_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@

#include "nbgl_use_case.h"

// -----------------------------------------------------------
// -------------------------- INFO ---------------------------
// -----------------------------------------------------------

typedef enum {
CHAIN_IDX = 0,
PKH_IDX,
Expand All @@ -54,36 +58,20 @@ static const char* const infoTypes[INFO_NB] =
static const char* infoContents[INFO_NB];
static char infoContentsBridge[INFO_NB][MAX_LENGTH];

enum {
HWM_ENABLED_TOKEN = FIRST_USER_TOKEN
};
enum {
HWM_ENABLED_TOKEN_ID = 0,
SETTINGS_SWITCHES_NB
};

static nbgl_layoutSwitch_t switches[SETTINGS_SWITCHES_NB] = {0};
static const nbgl_contentInfoList_t infoList = {.nbInfos = INFO_NB,
.infoTypes = infoTypes,
.infoContents = infoContents};

/**
* @brief Callback to fill the settings page content
*
* @param page: page of the settings
* @param content: content to fill
* @return bool: if the page is not out of bounds
* @brief Initializes info values
*/
static bool navigation_cb_baking(uint8_t page, nbgl_pageContent_t* content) {
if (page > 2u) {
return false;
}

static void initInfo(void) {
tz_exc exc = SW_OK;

for (tz_infoIndex_t idx = 0; idx < INFO_NB; idx++) {
infoContents[idx] = infoContentsBridge[idx];
}

const bool hwm_disabled = g_hwm.hwm_disabled;

TZ_ASSERT(chain_id_to_string_with_aliases(infoContentsBridge[CHAIN_IDX],
MAX_LENGTH,
&g_hwm.main_chain_id) >= 0,
Expand All @@ -110,78 +98,96 @@ static bool navigation_cb_baking(uint8_t page, nbgl_pageContent_t* content) {
TZ_ASSERT(copy_string(infoContentsBridge[COPYRIGHT_IDX], MAX_LENGTH, "(c) 2023 Ledger") >= 0,
EXC_WRONG_LENGTH);

switch (page) {
case 0:
switches[HWM_ENABLED_TOKEN_ID].initState = (nbgl_state_t) (!hwm_disabled);
switches[HWM_ENABLED_TOKEN_ID].text = "High Watermark";
switches[HWM_ENABLED_TOKEN_ID].subText = "Track high watermark\n in Ledger";
switches[HWM_ENABLED_TOKEN_ID].token = HWM_ENABLED_TOKEN;
switches[HWM_ENABLED_TOKEN_ID].tuneId = TUNE_TAP_CASUAL;
content->type = SWITCHES_LIST;
content->switchesList.nbSwitches = SETTINGS_SWITCHES_NB;
content->switchesList.switches = (nbgl_layoutSwitch_t*) switches;
break;
case 1:
content->type = INFOS_LIST;
// Only the 3 first info are displayed on the first page
// will be removed in the next commit
content->infosList.nbInfos = 3;
content->infosList.infoTypes = infoTypes;
content->infosList.infoContents = (const char* const*) infoContents;
break;
case 2:
content->type = INFOS_LIST;
// Only the 3 last info are displayed on the third page
// will be removed in the next commit
content->infosList.nbInfos = 3; // INFO_NB - 3
// + 3 because information for page 2 starts at infoTypes[3]
// will be removed in the next commit
content->infosList.infoTypes = infoTypes + 3;
content->infosList.infoContents = (const char* const*) infoContents + 3;
break;
default:
return false;
}
return true;
end:
TZ_EXC_PRINT(exc);
return true;
}

static void controls_callback(int token, uint8_t index) {
// -----------------------------------------------------------
// ------------------------ SETTINGS -------------------------
// -----------------------------------------------------------

typedef enum {
HWM_ENABLED_TOKEN = FIRST_USER_TOKEN,
NEXT_TOKEN
} tz_settingsToken_t;

// -------------------- SWITCHES SETTINGS --------------------

typedef enum {
HWM_ENABLED_IDX = 0,
SETTINGS_SWITCHES_NB
} tz_settingsSwitchesIndex_t;

static nbgl_contentSwitch_t settingsSwitches[SETTINGS_SWITCHES_NB] = {0};

/**
* @brief Initializes switches settings values
*/
static void initSettingsSwitches(void) {
nbgl_contentSwitch_t* hwmSwitch = &settingsSwitches[HWM_ENABLED_IDX];
hwmSwitch->text = "High Watermark";
hwmSwitch->subText = "Track high watermark\n in Ledger";
hwmSwitch->initState = (nbgl_state_t) (!g_hwm.hwm_disabled);
hwmSwitch->token = HWM_ENABLED_TOKEN;
}

/**
* @brief Callback to controle switches impact
*
* @param token: token of the switch toggled
* @param index: settings index
* @param page: page index
*/
static void settingsSwitchesToggleCallback(tz_settingsToken_t token, uint8_t index, int page) {
UNUSED(index);
UNUSED(page);
if (token == HWM_ENABLED_TOKEN) {
toggle_hwm();
}
}

#define TOTAL_SETTINGS_PAGE (3)
#define INIT_SETTINGS_PAGE (0)
#define DISABLE_SUB_SETTINGS false
#define SETTINGS_SWITCHES_CONTENTS \
{ \
.type = SWITCHES_LIST, \
.content.switchesList = {.switches = settingsSwitches, \
.nbSwitches = SETTINGS_SWITCHES_NB}, \
.contentActionCallback = (nbgl_contentActionCallback_t) settingsSwitchesToggleCallback \
}

// ---------------------- ALL SETTINGS -----------------------

typedef enum {
SWITCHES_IDX = 0,
SETTINGS_PAGE_NB
} tz_settingsIndex_t;

static const nbgl_content_t settingsContentsList[SETTINGS_PAGE_NB] = {SETTINGS_SWITCHES_CONTENTS};

static const nbgl_genericContents_t settingsContents = {.callbackCallNeeded = false,
.contentsList = settingsContentsList,
.nbContents = SETTINGS_PAGE_NB};

/**
* @brief Draws settings pages
*
* @brief Initializes settings values
*/
static void ui_menu_about_baking(void) {
nbgl_useCaseSettings("Tezos baking",
INIT_SETTINGS_PAGE,
TOTAL_SETTINGS_PAGE,
DISABLE_SUB_SETTINGS,
ui_initial_screen,
navigation_cb_baking,
controls_callback);
static void initSettings(void) {
initSettingsSwitches();
}

#define SETTINGS_BUTTON_ENABLED (true)
// -----------------------------------------------------------

void ui_initial_screen(void) {
nbgl_useCaseHome("Tezos Baking",
&C_tezos,
NULL,
SETTINGS_BUTTON_ENABLED,
ui_menu_about_baking,
app_exit);
initSettings();
initInfo();

nbgl_useCaseHomeAndSettings("Tezos Baking",
&C_tezos,
NULL,
INIT_HOME_PAGE,
&settingsContents,
&infoList,
NULL,
app_exit);
}

#endif // HAVE_NBGL
Binary file modified test/snapshots/flex/description.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/snapshots/flex/hwm_status_disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/snapshots/flex/hwm_status_enabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed test/snapshots/flex/test_review_home/app_context.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/snapshots/stax/description.png
Binary file modified test/snapshots/stax/hwm_status_disabled.png
Binary file modified test/snapshots/stax/hwm_status_enabled.png
Binary file modified test/snapshots/stax/test_review_home/app_context.png
44 changes: 40 additions & 4 deletions test/test_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,31 @@ def test_review_home(account: Optional[Account],
tezos_navigator.assert_screen(TouchFixedScreen.SETTINGS_HMW_ENABLED)
tezos_navigator.settings.next()
backend.wait_for_screen_change()
tezos_navigator.assert_screen("app_context", snap_path)
if tezos_navigator.firmware == Firmware.STAX:
# chain_id + pkh + hwm
tezos_navigator.assert_screen("app_context", snap_path)
elif tezos_navigator.firmware == Firmware.FLEX:
# chain_id + pkh
tezos_navigator.assert_screen("app_context_1", snap_path)
tezos_navigator.settings.next()
backend.wait_for_screen_change()
# hwm + version
tezos_navigator.assert_screen("app_context_2", snap_path)
tezos_navigator.settings.next()
backend.wait_for_screen_change()
tezos_navigator.assert_screen(TouchFixedScreen.SETTINGS_DESCRIPTION)
tezos_navigator.settings.previous()
backend.wait_for_screen_change()
tezos_navigator.assert_screen("app_context", snap_path)
if tezos_navigator.firmware == Firmware.STAX:
# chain_id + pkh + hwm
tezos_navigator.assert_screen("app_context", snap_path)
elif tezos_navigator.firmware == Firmware.FLEX:
# hwm + version
tezos_navigator.assert_screen("app_context_2", snap_path)
tezos_navigator.settings.previous()
backend.wait_for_screen_change()
# chain_id + pkh
tezos_navigator.assert_screen("app_context_1", snap_path)
tezos_navigator.settings.previous()
backend.wait_for_screen_change()
tezos_navigator.assert_screen(TouchFixedScreen.SETTINGS_HMW_ENABLED)
Expand All @@ -179,13 +197,31 @@ def test_review_home(account: Optional[Account],
tezos_navigator.assert_screen(TouchFixedScreen.SETTINGS_HMW_DISABLED)
tezos_navigator.settings.next()
backend.wait_for_screen_change()
tezos_navigator.assert_screen("app_context", snap_path)
if tezos_navigator.firmware == Firmware.STAX:
# chain_id + pkh + hwm
tezos_navigator.assert_screen("app_context", snap_path)
elif tezos_navigator.firmware == Firmware.FLEX:
# chain_id + pkh
tezos_navigator.assert_screen("app_context_1", snap_path)
tezos_navigator.settings.next()
backend.wait_for_screen_change()
# hwm + version
tezos_navigator.assert_screen("app_context_2", snap_path)
tezos_navigator.settings.next()
backend.wait_for_screen_change()
tezos_navigator.assert_screen(TouchFixedScreen.SETTINGS_DESCRIPTION)
tezos_navigator.settings.previous()
backend.wait_for_screen_change()
tezos_navigator.assert_screen("app_context", snap_path)
if tezos_navigator.firmware == Firmware.STAX:
# chain_id + pkh + hwm
tezos_navigator.assert_screen("app_context", snap_path)
elif tezos_navigator.firmware == Firmware.FLEX:
# hwm + version
tezos_navigator.assert_screen("app_context_2", snap_path)
tezos_navigator.settings.previous()
backend.wait_for_screen_change()
# chain_id + pkh
tezos_navigator.assert_screen("app_context_1", snap_path)
tezos_navigator.settings.previous()
backend.wait_for_screen_change()
tezos_navigator.assert_screen(TouchFixedScreen.SETTINGS_HMW_DISABLED)
Expand Down
8 changes: 8 additions & 0 deletions test/utils/navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ def goto_home_public_key(self) -> Generator[None, None, None]:
self.settings.next()
self.backend.wait_for_screen_change()

# Stax: chain_id + pkh + hwm
# Flex: chain_id + pkh
yield

if self.firmware.is_nano:
Expand Down Expand Up @@ -345,7 +347,13 @@ def goto_home_hwm(self) -> Generator[None, None, None]:
# hwm_status
self.settings.next()
self.backend.wait_for_screen_change()
if self.firmware == Firmware.FLEX:
# chain_id + pkh
self.settings.next()
self.backend.wait_for_screen_change()

# Stax: chain_id + pkh + hwm
# Flex: hwm + version
yield

if self.firmware.is_nano:
Expand Down

0 comments on commit 70cf539

Please sign in to comment.