Skip to content

Commit

Permalink
use case
Browse files Browse the repository at this point in the history
  • Loading branch information
spalmer25 committed Jul 18, 2024
1 parent f7c2c91 commit 4e0faa8
Show file tree
Hide file tree
Showing 423 changed files with 82 additions and 70 deletions.
152 changes: 82 additions & 70 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,72 +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;
content->infosList.nbInfos = 3;
content->infosList.infoTypes = infoTypes;
content->infosList.infoContents = (const char* const*) infoContents;
break;
case 2:
content->type = INFOS_LIST;
content->infosList.nbInfos = 3;
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
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.
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.
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.
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/flex/test_deauthorize/app_context/app_context.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.
Binary file modified test/snapshots/flex/test_deauthorize/app_context/hwm_status.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.
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.
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/test_review_home/app_context.png
Binary file modified test/snapshots/flex/test_review_home/description.png
Binary file modified test/snapshots/flex/test_review_home/hwm_status.png
Binary file modified test/snapshots/flex/test_review_home/hwm_status_off.png
Binary file modified test/snapshots/flex/test_review_home/hwm_status_on.png
Binary file modified test/snapshots/stax/test_deauthorize/app_context/app_context.png
Binary file modified test/snapshots/stax/test_deauthorize/app_context/description.png
Binary file modified test/snapshots/stax/test_deauthorize/app_context/hwm_status.png
Binary file modified test/snapshots/stax/test_reset_app_context/00001.png
Binary file modified test/snapshots/stax/test_review_home/app_context.png
Binary file modified test/snapshots/stax/test_review_home/description.png
Binary file modified test/snapshots/stax/test_review_home/hwm_status.png
Binary file modified test/snapshots/stax/test_review_home/hwm_status_off.png
Binary file modified test/snapshots/stax/test_review_home/hwm_status_on.png
Loading

0 comments on commit 4e0faa8

Please sign in to comment.