Merge pull request #606 from LedgerHQ/fix/apa/clone_home_page

Fix clones/plugins home page
This commit is contained in:
apaillier-ledger
2024-07-17 10:00:12 +02:00
committed by GitHub
4 changed files with 76 additions and 90 deletions

View File

@@ -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);

View File

@@ -1,6 +1,8 @@
#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
@@ -8,6 +10,9 @@
// 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,
@@ -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;
@@ -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;
@@ -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);
}

View File

@@ -1,64 +0,0 @@
#include "common_ui.h"
#include "shared_context.h"
#include "ui_nbgl.h"
#include "nbgl_use_case.h"
#include "glyphs.h"
#include "caller_api.h"
#include "network.h"
char g_stax_shared_buffer[SHARED_BUFFER_SIZE] = {0};
nbgl_page_t *pageContext;
#define FORMAT_PLUGIN "This app enables clear\nsigning transactions for\nthe %s dApp."
void releaseContext(void) {
if (pageContext != NULL) {
nbgl_pageRelease(pageContext);
pageContext = NULL;
}
}
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;
}
void ui_idle(void) {
const char *app_name = NULL;
const char *tagline = NULL;
if (caller_app) {
app_name = caller_app->name;
if (caller_app->type == CALLER_TYPE_PLUGIN) {
snprintf(g_stax_shared_buffer, sizeof(g_stax_shared_buffer), FORMAT_PLUGIN, app_name);
tagline = g_stax_shared_buffer;
}
} else { // Ethereum app
uint64_t mainnet_chain_id = ETHEREUM_MAINNET_CHAINID;
app_name = get_network_name_from_chain_id(&mainnet_chain_id);
}
nbgl_useCaseHome((char *) app_name,
get_app_icon(true),
tagline,
true,
ui_menu_settings,
app_quit);
}

View File

@@ -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_