Skip to content

Commit

Permalink
Merge pull request #606 from LedgerHQ/fix/apa/clone_home_page
Browse files Browse the repository at this point in the history
Fix clones/plugins home page
  • Loading branch information
apaillier-ledger authored Jul 17, 2024
2 parents 5aeda68 + 1ccdd9c commit 7db0099
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 90 deletions.
1 change: 0 additions & 1 deletion src/common_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ 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);
Expand Down
97 changes: 76 additions & 21 deletions src_nbgl/ui_settings.c → src_nbgl/ui_home.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#include "common_ui.h"
#include "ui_nbgl.h"
#include "nbgl_use_case.h"
#include "caller_api.h"
#include "network.h"

// settings info definition
#define SETTING_INFO_NB 2

// settings menu definition
#define SETTING_CONTENTS_NB 1

// Tagline format for plugins
#define FORMAT_PLUGIN "This app enables clear\nsigning transactions for\nthe %s dApp."

enum {
DEBUG_TOKEN = FIRST_USER_TOKEN,
NONCE_TOKEN,
Expand All @@ -31,52 +36,79 @@ enum {
SETTINGS_SWITCHES_NB
};

static uint8_t initSettingPage;

// settings definition
static const char* const infoTypes[SETTING_INFO_NB] = {"Version", "Developer"};
static const char* const infoContents[SETTING_INFO_NB] = {APPVERSION, "Ledger"};
static const char *const infoTypes[SETTING_INFO_NB] = {"Version", "Developer"};
static const char *const infoContents[SETTING_INFO_NB] = {APPVERSION, "Ledger"};

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, int page) {
UNUSED(index);
uint8_t value;
// Buffer used all throughout the NBGL code
char g_stax_shared_buffer[SHARED_BUFFER_SIZE] = {0};

initSettingPage = page;
static void setting_toggle_callback(int token, uint8_t index, int page) {
UNUSED(index);
UNUSED(page);
bool value;

switch (token) {
case DEBUG_TOKEN:
value = (N_storage.contractDetails ? 0 : 1);
value = !N_storage.contractDetails;
switches[DEBUG_ID].initState = (nbgl_state_t) value;
nvm_write((void*) &N_storage.contractDetails, (void*) &value, sizeof(uint8_t));
nvm_write((void *) &N_storage.contractDetails, (void *) &value, sizeof(uint8_t));
break;
case NONCE_TOKEN:
value = (N_storage.displayNonce ? 0 : 1);
value = !N_storage.displayNonce;
switches[NONCE_ID].initState = (nbgl_state_t) value;
nvm_write((void*) &N_storage.displayNonce, (void*) &value, sizeof(uint8_t));
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);
value = !N_storage.verbose_eip712;
switches[EIP712_VERBOSE_ID].initState = (nbgl_state_t) value;
nvm_write((void*) &N_storage.verbose_eip712, (void*) &value, sizeof(uint8_t));
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);
value = !N_storage.verbose_domain_name;
switches[DOMAIN_NAME_VERBOSE_ID].initState = (nbgl_state_t) value;
nvm_write((void*) &N_storage.verbose_domain_name, (void*) &value, sizeof(uint8_t));
nvm_write((void *) &N_storage.verbose_domain_name, (void *) &value, sizeof(uint8_t));
break;
#endif // HAVE_DOMAIN_NAME
}
}

void ui_menu_settings(void) {
static void app_quit(void) {
// exit app here
os_sched_exit(-1);
}

const nbgl_icon_details_t *get_app_icon(bool caller_icon) {
const nbgl_icon_details_t *icon = NULL;

if (caller_icon && caller_app) {
if (caller_app->icon) {
icon = caller_app->icon;
}
} else {
icon = &ICONGLYPH;
}
if (icon == NULL) {
PRINTF("%s(%s) returned NULL!\n", __func__, (caller_icon ? "true" : "false"));
}
return icon;
}

/**
* Prepare settings, app infos and call the HomeAndSettings use case
*
* @param[in] appname given app name
* @param[in] tagline given tagline (\ref NULL if default)
*/
static void prepare_and_display_home(const char *appname, const char *tagline) {
#ifdef HAVE_DOMAIN_NAME
switches[DOMAIN_NAME_VERBOSE_ID].initState =
N_storage.verbose_domain_name ? ON_STATE : OFF_STATE;
Expand Down Expand Up @@ -109,7 +141,7 @@ void ui_menu_settings(void) {
contents[0].type = SWITCHES_LIST;
contents[0].content.switchesList.nbSwitches = SETTINGS_SWITCHES_NB;
contents[0].content.switchesList.switches = switches;
contents[0].contentActionCallback = controlsCallback;
contents[0].contentActionCallback = setting_toggle_callback;

settingContents.callbackCallNeeded = false;
settingContents.contentsList = contents;
Expand All @@ -119,12 +151,35 @@ void ui_menu_settings(void) {
infoList.infoTypes = infoTypes;
infoList.infoContents = infoContents;

nbgl_useCaseHomeAndSettings(APPNAME,
nbgl_useCaseHomeAndSettings(appname,
get_app_icon(true),
NULL,
initSettingPage,
tagline,
INIT_HOME_PAGE,
&settingContents,
&infoList,
NULL,
app_quit);
}

/**
* Go to home screen
*
* This function prepares the app name & tagline depending on how the application was called
*/
void ui_idle(void) {
const char *appname = NULL;
const char *tagline = NULL;

if (caller_app) {
appname = caller_app->name;

if (caller_app->type == CALLER_TYPE_PLUGIN) {
snprintf(g_stax_shared_buffer, sizeof(g_stax_shared_buffer), FORMAT_PLUGIN, appname);
tagline = g_stax_shared_buffer;
}
} else { // Ethereum app
uint64_t mainnet_chain_id = ETHEREUM_MAINNET_CHAINID;
appname = get_network_name_from_chain_id(&mainnet_chain_id);
}
prepare_and_display_home(appname, tagline);
}
64 changes: 0 additions & 64 deletions src_nbgl/ui_idle.c

This file was deleted.

4 changes: 0 additions & 4 deletions src_nbgl/ui_nbgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ extern char g_stax_shared_buffer[SHARED_BUFFER_SIZE];

extern nbgl_page_t* pageContext;

void releaseContext(void);

const nbgl_icon_details_t* get_app_icon(bool caller_icon);

void ui_idle(void);
void ui_menu_settings(void);
void ui_menu_about(void);

#endif // _UI_NBGL_H_

0 comments on commit 7db0099

Please sign in to comment.