From dbd346c58e03a1012471836bc514ab25e1809f85 Mon Sep 17 00:00:00 2001 From: Clement Bouvet Date: Thu, 8 Dec 2022 16:11:35 +0100 Subject: [PATCH] pass clone icon to eth --- Makefile | 1 + src/chainConfig.h | 7 +++++++ src/main.c | 8 ++++++++ src_common/network.c | 11 +++++++++++ src_common/network.h | 4 +++- src_nbgl/ui_idle.c | 33 ++++++++++++++++----------------- 6 files changed, 46 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 3b23b1d7..62079b5b 100644 --- a/Makefile +++ b/Makefile @@ -69,6 +69,7 @@ ICONNAME=icons/nanos_app_$(CHAIN).gif else ifeq ($(TARGET_NAME),TARGET_FATSTACKS) ICONNAME=icons/stax_app_$(CHAIN).gif DEFINES += ICONGLYPH=C_stax_app_$(CHAIN)_64px +DEFINES += ICONBITMAP=C_stax_app_$(CHAIN)_64px_bitmap DEFINES += ICONGLYPH_SMALL=C_stax_app_$(CHAIN) GLYPH_FILES += icons/stax_app_$(CHAIN)_64px.gif GLYPH_FILES += icons/stax_app_$(CHAIN).gif diff --git a/src/chainConfig.h b/src/chainConfig.h index fd09ed24..1b87b35c 100644 --- a/src/chainConfig.h +++ b/src/chainConfig.h @@ -76,10 +76,17 @@ typedef enum chain_kind_e { CHAIN_KIND_ID4GOOD } chain_kind_t; +#ifdef HAVE_NBGL +#include "ui_nbgl.h" +#endif // HAVE_NBGL + typedef struct chain_config_s { char coinName[10]; // ticker uint64_t chainId; chain_kind_t kind; +#ifdef HAVE_NBGL + nbgl_icon_details_t coinIconDetails; +#endif // HAVE_NBGL } chain_config_t; #define ETHEREUM_MAINNET_CHAINID 1 diff --git a/src/main.c b/src/main.c index d669192b..b620914d 100644 --- a/src/main.c +++ b/src/main.c @@ -1068,6 +1068,13 @@ __attribute__((section(".boot"))) int main(int arg0) { unsigned int libcall_params[5]; chain_config_t local_chainConfig; init_coin_config(&local_chainConfig); +#ifdef HAVE_NBGL + uint8_t coinIcon[sizeof(ICONBITMAP)]; + memcpy(coinIcon, &ICONBITMAP, sizeof(ICONBITMAP)); + memcpy(&local_chainConfig.coinIconDetails, &ICONGLYPH, sizeof(ICONGLYPH)); + local_chainConfig.coinIconDetails.bitmap = coinIcon; +#endif // HAVE_NBGL + PRINTF("Hello from Eth-clone\n"); check_api_level(CX_COMPAT_APILEVEL); // delegate to Ethereum app/lib @@ -1076,6 +1083,7 @@ __attribute__((section(".boot"))) int main(int arg0) { libcall_params[2] = RUN_APPLICATION; libcall_params[3] = (unsigned int) &local_chainConfig; libcall_params[4] = 0; + if (arg0) { // call as a library libcall_params[2] = ((unsigned int *) arg0)[1]; diff --git a/src_common/network.c b/src_common/network.c index 936bef89..5e114519 100644 --- a/src_common/network.c +++ b/src_common/network.c @@ -92,6 +92,17 @@ uint64_t get_app_chain_id(void) { return chainConfig->chainId; } +#ifdef HAVE_NBGL +#include "glyphs.h" +const nbgl_icon_details_t* get_app_chain_icon(void) { + if (chainConfig->coinIconDetails.bitmap) { + return &chainConfig->coinIconDetails; // if called from a clone, the bitmap is correct + } else { + return &ICONGLYPH; // else, jsu return the ETH icon + } +} +#endif // HAVE_NBGL + static uint64_t get_chain_id(e_net_type type) { return (type == APP) ? get_app_chain_id() : get_tx_chain_id(); } diff --git a/src_common/network.h b/src_common/network.h index 22876564..7ed9ffa0 100644 --- a/src_common/network.h +++ b/src_common/network.h @@ -14,7 +14,9 @@ typedef struct network_info_s { // Returns the chain ID. Defaults to 0 if txType was not found (For TX). uint64_t get_tx_chain_id(void); uint64_t get_app_chain_id(void); - +#ifdef HAVE_NBGL +const nbgl_icon_details_t* get_app_chain_icon(void); +#endif // HAVE_NBGL // Returns a pointer to the network name, or NULL if there is none. const char *get_tx_network_name(void); const char *get_app_network_name(void); diff --git a/src_nbgl/ui_idle.c b/src_nbgl/ui_idle.c index fb382979..bd1416fa 100644 --- a/src_nbgl/ui_idle.c +++ b/src_nbgl/ui_idle.c @@ -22,14 +22,14 @@ void app_quit(void) { void ui_idle(void) { if (plugin_name != NULL) { // plugin - nbgl_useCasePlugInHome((char*)plugin_name, - APPNAME, - &ICONGLYPH_SMALL, - NULL, - NULL, - true, - ui_menu_settings, - app_quit); + nbgl_useCasePlugInHome((char*)plugin_name, + APPNAME, + &ICONGLYPH_SMALL, + NULL, + NULL, + true, + ui_menu_settings, + app_quit); } else { char *app_name = (char*) get_app_network_name(); @@ -39,7 +39,7 @@ void ui_idle(void) { case 3: // Ropsten case 5: // Goerli nbgl_useCaseHome(app_name, - &ICONGLYPH, + get_app_chain_icon(), NULL, true, ui_menu_settings, @@ -47,14 +47,13 @@ void ui_idle(void) { break; // Clones default: - nbgl_useCasePlugInHome(app_name ? app_name : "???", - APPNAME, - &ICONGLYPH_SMALL, - NULL, - NULL, - true, - ui_menu_settings, - app_quit); + nbgl_useCaseHome(app_name, + get_app_chain_icon(), + NULL, + true, + ui_menu_settings, + app_quit); + break; } } }