Skip to content

Commit 7db0099

Browse files
Merge pull request #606 from LedgerHQ/fix/apa/clone_home_page
Fix clones/plugins home page
2 parents 5aeda68 + 1ccdd9c commit 7db0099

File tree

4 files changed

+76
-90
lines changed

4 files changed

+76
-90
lines changed

src/common_ui.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ void ui_display_public_key(const uint64_t *chain_id);
1313
void ui_sign_712_v0(void);
1414
void ui_confirm_selector(void);
1515
void ui_confirm_parameter(void);
16-
void app_quit(void);
1716

1817
// EIP-191
1918
void ui_191_start(void);

src_nbgl/ui_settings.c renamed to src_nbgl/ui_home.c

Lines changed: 76 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
#include "common_ui.h"
22
#include "ui_nbgl.h"
33
#include "nbgl_use_case.h"
4+
#include "caller_api.h"
5+
#include "network.h"
46

57
// settings info definition
68
#define SETTING_INFO_NB 2
79

810
// settings menu definition
911
#define SETTING_CONTENTS_NB 1
1012

13+
// Tagline format for plugins
14+
#define FORMAT_PLUGIN "This app enables clear\nsigning transactions for\nthe %s dApp."
15+
1116
enum {
1217
DEBUG_TOKEN = FIRST_USER_TOKEN,
1318
NONCE_TOKEN,
@@ -31,52 +36,79 @@ enum {
3136
SETTINGS_SWITCHES_NB
3237
};
3338

34-
static uint8_t initSettingPage;
35-
3639
// settings definition
37-
static const char* const infoTypes[SETTING_INFO_NB] = {"Version", "Developer"};
38-
static const char* const infoContents[SETTING_INFO_NB] = {APPVERSION, "Ledger"};
40+
static const char *const infoTypes[SETTING_INFO_NB] = {"Version", "Developer"};
41+
static const char *const infoContents[SETTING_INFO_NB] = {APPVERSION, "Ledger"};
3942

4043
static nbgl_contentInfoList_t infoList = {0};
4144
static nbgl_contentSwitch_t switches[SETTINGS_SWITCHES_NB] = {0};
4245
static nbgl_content_t contents[SETTING_CONTENTS_NB] = {0};
4346
static nbgl_genericContents_t settingContents = {0};
4447

45-
static void controlsCallback(int token, uint8_t index, int page) {
46-
UNUSED(index);
47-
uint8_t value;
48+
// Buffer used all throughout the NBGL code
49+
char g_stax_shared_buffer[SHARED_BUFFER_SIZE] = {0};
4850

49-
initSettingPage = page;
51+
static void setting_toggle_callback(int token, uint8_t index, int page) {
52+
UNUSED(index);
53+
UNUSED(page);
54+
bool value;
5055

5156
switch (token) {
5257
case DEBUG_TOKEN:
53-
value = (N_storage.contractDetails ? 0 : 1);
58+
value = !N_storage.contractDetails;
5459
switches[DEBUG_ID].initState = (nbgl_state_t) value;
55-
nvm_write((void*) &N_storage.contractDetails, (void*) &value, sizeof(uint8_t));
60+
nvm_write((void *) &N_storage.contractDetails, (void *) &value, sizeof(uint8_t));
5661
break;
5762
case NONCE_TOKEN:
58-
value = (N_storage.displayNonce ? 0 : 1);
63+
value = !N_storage.displayNonce;
5964
switches[NONCE_ID].initState = (nbgl_state_t) value;
60-
nvm_write((void*) &N_storage.displayNonce, (void*) &value, sizeof(uint8_t));
65+
nvm_write((void *) &N_storage.displayNonce, (void *) &value, sizeof(uint8_t));
6166
break;
6267
#ifdef HAVE_EIP712_FULL_SUPPORT
6368
case EIP712_VERBOSE_TOKEN:
64-
value = (N_storage.verbose_eip712 ? 0 : 1);
69+
value = !N_storage.verbose_eip712;
6570
switches[EIP712_VERBOSE_ID].initState = (nbgl_state_t) value;
66-
nvm_write((void*) &N_storage.verbose_eip712, (void*) &value, sizeof(uint8_t));
71+
nvm_write((void *) &N_storage.verbose_eip712, (void *) &value, sizeof(uint8_t));
6772
break;
6873
#endif // HAVE_EIP712_FULL_SUPPORT
6974
#ifdef HAVE_DOMAIN_NAME
7075
case DOMAIN_NAME_VERBOSE_TOKEN:
71-
value = (N_storage.verbose_domain_name ? 0 : 1);
76+
value = !N_storage.verbose_domain_name;
7277
switches[DOMAIN_NAME_VERBOSE_ID].initState = (nbgl_state_t) value;
73-
nvm_write((void*) &N_storage.verbose_domain_name, (void*) &value, sizeof(uint8_t));
78+
nvm_write((void *) &N_storage.verbose_domain_name, (void *) &value, sizeof(uint8_t));
7479
break;
7580
#endif // HAVE_DOMAIN_NAME
7681
}
7782
}
7883

79-
void ui_menu_settings(void) {
84+
static void app_quit(void) {
85+
// exit app here
86+
os_sched_exit(-1);
87+
}
88+
89+
const nbgl_icon_details_t *get_app_icon(bool caller_icon) {
90+
const nbgl_icon_details_t *icon = NULL;
91+
92+
if (caller_icon && caller_app) {
93+
if (caller_app->icon) {
94+
icon = caller_app->icon;
95+
}
96+
} else {
97+
icon = &ICONGLYPH;
98+
}
99+
if (icon == NULL) {
100+
PRINTF("%s(%s) returned NULL!\n", __func__, (caller_icon ? "true" : "false"));
101+
}
102+
return icon;
103+
}
104+
105+
/**
106+
* Prepare settings, app infos and call the HomeAndSettings use case
107+
*
108+
* @param[in] appname given app name
109+
* @param[in] tagline given tagline (\ref NULL if default)
110+
*/
111+
static void prepare_and_display_home(const char *appname, const char *tagline) {
80112
#ifdef HAVE_DOMAIN_NAME
81113
switches[DOMAIN_NAME_VERBOSE_ID].initState =
82114
N_storage.verbose_domain_name ? ON_STATE : OFF_STATE;
@@ -109,7 +141,7 @@ void ui_menu_settings(void) {
109141
contents[0].type = SWITCHES_LIST;
110142
contents[0].content.switchesList.nbSwitches = SETTINGS_SWITCHES_NB;
111143
contents[0].content.switchesList.switches = switches;
112-
contents[0].contentActionCallback = controlsCallback;
144+
contents[0].contentActionCallback = setting_toggle_callback;
113145

114146
settingContents.callbackCallNeeded = false;
115147
settingContents.contentsList = contents;
@@ -119,12 +151,35 @@ void ui_menu_settings(void) {
119151
infoList.infoTypes = infoTypes;
120152
infoList.infoContents = infoContents;
121153

122-
nbgl_useCaseHomeAndSettings(APPNAME,
154+
nbgl_useCaseHomeAndSettings(appname,
123155
get_app_icon(true),
124-
NULL,
125-
initSettingPage,
156+
tagline,
157+
INIT_HOME_PAGE,
126158
&settingContents,
127159
&infoList,
128160
NULL,
129161
app_quit);
130162
}
163+
164+
/**
165+
* Go to home screen
166+
*
167+
* This function prepares the app name & tagline depending on how the application was called
168+
*/
169+
void ui_idle(void) {
170+
const char *appname = NULL;
171+
const char *tagline = NULL;
172+
173+
if (caller_app) {
174+
appname = caller_app->name;
175+
176+
if (caller_app->type == CALLER_TYPE_PLUGIN) {
177+
snprintf(g_stax_shared_buffer, sizeof(g_stax_shared_buffer), FORMAT_PLUGIN, appname);
178+
tagline = g_stax_shared_buffer;
179+
}
180+
} else { // Ethereum app
181+
uint64_t mainnet_chain_id = ETHEREUM_MAINNET_CHAINID;
182+
appname = get_network_name_from_chain_id(&mainnet_chain_id);
183+
}
184+
prepare_and_display_home(appname, tagline);
185+
}

src_nbgl/ui_idle.c

Lines changed: 0 additions & 64 deletions
This file was deleted.

src_nbgl/ui_nbgl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ extern char g_stax_shared_buffer[SHARED_BUFFER_SIZE];
1010

1111
extern nbgl_page_t* pageContext;
1212

13-
void releaseContext(void);
14-
1513
const nbgl_icon_details_t* get_app_icon(bool caller_icon);
1614

1715
void ui_idle(void);
18-
void ui_menu_settings(void);
19-
void ui_menu_about(void);
2016

2117
#endif // _UI_NBGL_H_

0 commit comments

Comments
 (0)