1
1
#include "common_ui.h"
2
2
#include "ui_nbgl.h"
3
3
#include "nbgl_use_case.h"
4
+ #include "caller_api.h"
5
+ #include "network.h"
4
6
5
7
// settings info definition
6
8
#define SETTING_INFO_NB 2
7
9
8
10
// settings menu definition
9
11
#define SETTING_CONTENTS_NB 1
10
12
13
+ // Tagline format for plugins
14
+ #define FORMAT_PLUGIN "This app enables clear\nsigning transactions for\nthe %s dApp."
15
+
11
16
enum {
12
17
DEBUG_TOKEN = FIRST_USER_TOKEN ,
13
18
NONCE_TOKEN ,
@@ -31,52 +36,79 @@ enum {
31
36
SETTINGS_SWITCHES_NB
32
37
};
33
38
34
- static uint8_t initSettingPage ;
35
-
36
39
// 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" };
39
42
40
43
static nbgl_contentInfoList_t infoList = {0 };
41
44
static nbgl_contentSwitch_t switches [SETTINGS_SWITCHES_NB ] = {0 };
42
45
static nbgl_content_t contents [SETTING_CONTENTS_NB ] = {0 };
43
46
static nbgl_genericContents_t settingContents = {0 };
44
47
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 };
48
50
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 ;
50
55
51
56
switch (token ) {
52
57
case DEBUG_TOKEN :
53
- value = ( N_storage .contractDetails ? 0 : 1 ) ;
58
+ value = ! N_storage .contractDetails ;
54
59
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 ));
56
61
break ;
57
62
case NONCE_TOKEN :
58
- value = ( N_storage .displayNonce ? 0 : 1 ) ;
63
+ value = ! N_storage .displayNonce ;
59
64
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 ));
61
66
break ;
62
67
#ifdef HAVE_EIP712_FULL_SUPPORT
63
68
case EIP712_VERBOSE_TOKEN :
64
- value = ( N_storage .verbose_eip712 ? 0 : 1 ) ;
69
+ value = ! N_storage .verbose_eip712 ;
65
70
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 ));
67
72
break ;
68
73
#endif // HAVE_EIP712_FULL_SUPPORT
69
74
#ifdef HAVE_DOMAIN_NAME
70
75
case DOMAIN_NAME_VERBOSE_TOKEN :
71
- value = ( N_storage .verbose_domain_name ? 0 : 1 ) ;
76
+ value = ! N_storage .verbose_domain_name ;
72
77
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 ));
74
79
break ;
75
80
#endif // HAVE_DOMAIN_NAME
76
81
}
77
82
}
78
83
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 ) {
80
112
#ifdef HAVE_DOMAIN_NAME
81
113
switches [DOMAIN_NAME_VERBOSE_ID ].initState =
82
114
N_storage .verbose_domain_name ? ON_STATE : OFF_STATE ;
@@ -109,7 +141,7 @@ void ui_menu_settings(void) {
109
141
contents [0 ].type = SWITCHES_LIST ;
110
142
contents [0 ].content .switchesList .nbSwitches = SETTINGS_SWITCHES_NB ;
111
143
contents [0 ].content .switchesList .switches = switches ;
112
- contents [0 ].contentActionCallback = controlsCallback ;
144
+ contents [0 ].contentActionCallback = setting_toggle_callback ;
113
145
114
146
settingContents .callbackCallNeeded = false;
115
147
settingContents .contentsList = contents ;
@@ -119,12 +151,35 @@ void ui_menu_settings(void) {
119
151
infoList .infoTypes = infoTypes ;
120
152
infoList .infoContents = infoContents ;
121
153
122
- nbgl_useCaseHomeAndSettings (APPNAME ,
154
+ nbgl_useCaseHomeAndSettings (appname ,
123
155
get_app_icon (true),
124
- NULL ,
125
- initSettingPage ,
156
+ tagline ,
157
+ INIT_HOME_PAGE ,
126
158
& settingContents ,
127
159
& infoList ,
128
160
NULL ,
129
161
app_quit );
130
162
}
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
+ }
0 commit comments