Now has a separate struct for caller app name & icon

- New home screen wording
- Removed duplicate RUN_APPLICATION macro
This commit is contained in:
Alexandre Paillier
2023-03-20 10:27:19 +01:00
parent 0414a043c8
commit 8361e349b7
19 changed files with 103 additions and 93 deletions

View File

@@ -77,17 +77,10 @@ typedef enum chain_kind_e {
CHAIN_KIND_OASYS
} chain_kind_t;
#ifdef HAVE_NBGL
#include "nbgl_types.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

View File

@@ -7,7 +7,6 @@
#define SELECTOR_SIZE 4
#define PARAMETER_LENGTH 32
#define RUN_APPLICATION 1
void copy_address(uint8_t* dst, const uint8_t* parameter, uint8_t dst_size);

View File

@@ -69,7 +69,7 @@ bolos_ux_params_t G_ux_params;
const internalStorage_t N_storage_real;
const char *plugin_name = NULL;
caller_app_t *caller_app = NULL;
chain_config_t *chainConfig = NULL;
void reset_app_context() {
@@ -957,7 +957,13 @@ void coin_main(libargs_t *args) {
if (args->chain_config != NULL) {
chainConfig = args->chain_config;
}
plugin_name = args->plugin_name;
if ((caller_app = args->caller_app) != NULL) {
if (chainConfig != NULL) {
caller_app->type = CALLER_TYPE_CLONE;
} else {
caller_app->type = CALLER_TYPE_PLUGIN;
}
}
}
if (chainConfig == NULL) {
init_coin_config(&config);
@@ -1097,12 +1103,6 @@ __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);
@@ -1111,7 +1111,21 @@ __attribute__((section(".boot"))) int main(int arg0) {
libcall_params[1] = 0x100;
libcall_params[2] = RUN_APPLICATION;
libcall_params[3] = (unsigned int) &local_chainConfig;
libcall_params[4] = 0;
#ifdef HAVE_NBGL
const char app_name[] = APPNAME;
caller_app_t capp;
nbgl_icon_details_t icon_details;
uint8_t bitmap[sizeof(ICONBITMAP)];
memcpy(&icon_details, &ICONGLYPH, sizeof(ICONGLYPH));
memcpy(&bitmap, &ICONBITMAP, sizeof(bitmap));
icon_details.bitmap = (const uint8_t *) bitmap;
capp.name = app_name;
capp.icon = &icon_details;
libcall_params[4] = (unsigned int) &capp;
#else
libcall_params[4] = NULL;
#endif // HAVE_NBGL
if (arg0) {
// call as a library

View File

@@ -7,6 +7,9 @@
#include "tokens.h"
#include "chainConfig.h"
#include "nft.h"
#ifdef HAVE_NBGL
#include "nbgl_types.h"
#endif
#define MAX_BIP32_PATH 10
@@ -221,6 +224,16 @@ typedef enum {
extern pluginType_t pluginType;
typedef enum { CALLER_TYPE_CLONE, CALLER_TYPE_PLUGIN } e_caller_type;
typedef struct caller_app_t {
const char *name;
#ifdef HAVE_NBGL
const nbgl_icon_details_t *icon;
#endif
char type; // does not have to be set by the caller app
} caller_app_t;
extern uint8_t appState;
#ifdef HAVE_STARKWARE
extern bool quantumSet;
@@ -229,7 +242,7 @@ extern bool quantumSet;
extern uint32_t eth2WithdrawalIndex;
#endif
extern const char *plugin_name;
extern caller_app_t *caller_app;
void reset_app_context(void);
const uint8_t *parseBip32(const uint8_t *dataBuffer, uint8_t *dataLength, bip32_path_t *bip32);

View File

@@ -3,6 +3,7 @@
#include "stdbool.h"
#include "chainConfig.h"
#include "shared_context.h"
#define RUN_APPLICATION 1
@@ -61,7 +62,7 @@ typedef struct libargs_s {
check_address_parameters_t* check_address;
create_transaction_parameters_t* create_transaction;
get_printable_amount_parameters_t* get_printable_amount;
char* plugin_name;
caller_app_t* caller_app;
};
} libargs_t;

View File

@@ -136,14 +136,3 @@ const char *get_app_network_ticker(void) {
const char *get_tx_network_ticker(void) {
return get_network_ticker(TX);
}
#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

View File

@@ -14,9 +14,6 @@ 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);

View File

@@ -188,7 +188,7 @@ static void reviewContinueCommon(void) {
useCaseTagValueList.nbPairs = nbPairs; ///< number of pairs in pairs array
useCaseTagValueList.smallCaseForValue = false;
useCaseTagValueList.wrapping = false;
infoLongPress.icon = get_app_chain_icon();
infoLongPress.icon = get_app_icon(true);
infoLongPress.text = tx_approval_context.fromPlugin ? transaction_type : "Review transaction";
infoLongPress.longPressText = "Hold to sign";
nbgl_useCaseStaticReview(&useCaseTagValueList,
@@ -204,14 +204,14 @@ static void buildFirstPage(void) {
"Review %s\ntransaction:\n%s",
strings.common.fullAddress,
strings.common.fullAmount);
nbgl_useCaseReviewStart(get_app_chain_icon(),
nbgl_useCaseReviewStart(get_app_icon(true),
transaction_type,
NULL,
"Reject transaction",
reviewContinue,
rejectTransactionQuestion);
} else {
nbgl_useCaseReviewStart(get_app_chain_icon(),
nbgl_useCaseReviewStart(get_app_icon(true),
"Review transaction",
NULL,
"Reject transaction",

View File

@@ -28,7 +28,7 @@ static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) {
content->tagValueList.nbPairs = 1;
content->tagValueList.pairs = (nbgl_layoutTagValue_t *) &tlv;
} else if (page == 1) {
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_chain_icon();
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(true);
content->infoLongPress.text = "Confirm parameter";
content->infoLongPress.longPressText = "Hold to confirm";
} else {
@@ -43,7 +43,7 @@ static void reviewContinue(void) {
}
static void buildScreen(void) {
nbgl_useCaseReviewStart(get_app_chain_icon(),
nbgl_useCaseReviewStart(get_app_icon(true),
"Verify parameter",
NULL,
"Reject",

View File

@@ -28,7 +28,7 @@ static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) {
content->tagValueList.nbPairs = 1;
content->tagValueList.pairs = (nbgl_layoutTagValue_t *) &tlv;
} else if (page == 1) {
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_chain_icon();
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(true);
content->infoLongPress.text = "Confirm selector";
content->infoLongPress.longPressText = "Hold to confirm";
} else {
@@ -43,7 +43,7 @@ static void reviewContinue(void) {
}
static void buildScreen(void) {
nbgl_useCaseReviewStart(get_app_chain_icon(),
nbgl_useCaseReviewStart(get_app_icon(true),
"Verify selector",
NULL,
"Reject",

View File

@@ -34,7 +34,7 @@ static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) {
content->tagValueList.nbPairs = 2;
content->tagValueList.pairs = (nbgl_layoutTagValue_t *) tlv;
} else if (page == 1) {
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_chain_icon();
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(true);
content->infoLongPress.text = review_string;
content->infoLongPress.longPressText = "Hold to approve";
} else {
@@ -49,7 +49,7 @@ static void reviewContinue(void) {
}
static void buildFirstPage(void) {
nbgl_useCaseReviewStart(get_app_chain_icon(),
nbgl_useCaseReviewStart(get_app_icon(true),
review_string,
NULL,
"Reject",

View File

@@ -5,9 +5,10 @@
#include "glyphs.h"
#include "network.h"
uint8_t staxSharedBuffer[SHARED_BUFFER_SIZE] = {0};
char staxSharedBuffer[SHARED_BUFFER_SIZE] = {0};
nbgl_page_t *pageContext;
nbgl_page_t* pageContext;
#define FORMAT_PLUGIN "This app enables clear\nsigning transactions for\nthe %s dApp."
void releaseContext(void) {
if (pageContext != NULL) {
@@ -15,47 +16,44 @@ void releaseContext(void) {
pageContext = NULL;
}
}
enum { BACK_TOKEN = 0, INFO_TOKEN, NEXT_TOKEN, CANCEL_TOKEN, QUIT_INFO_TOKEN, QUIT_APP_TOKEN };
void app_quit(void) {
// exit app here
os_sched_exit(-1);
}
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);
} else {
char* app_name = (char*) get_app_network_name();
const nbgl_icon_details_t *get_app_icon(bool caller_icon) {
const nbgl_icon_details_t *icon = NULL;
switch (get_app_chain_id()) {
// Standalone apps
case 1: // Mainnet
case 3: // Ropsten
case 5: // Goerli
nbgl_useCaseHome(app_name,
get_app_chain_icon(),
NULL,
true,
ui_menu_settings,
app_quit);
break;
// Clones
default:
nbgl_useCaseHome(app_name,
get_app_chain_icon(),
NULL,
true,
ui_menu_settings,
app_quit);
break;
if (caller_icon && caller_app) {
if (caller_app->icon) {
icon = caller_app->icon;
}
} else {
icon = &ICONGLYPH;
}
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(staxSharedBuffer, sizeof(staxSharedBuffer), FORMAT_PLUGIN, app_name);
tagline = staxSharedBuffer;
}
} else { // Ethereum app
app_name = get_app_network_name();
}
nbgl_useCaseHome((char *) app_name,
get_app_icon(true),
tagline,
true,
ui_menu_settings,
app_quit);
}

View File

@@ -6,14 +6,16 @@
#include <shared_context.h>
#define SHARED_BUFFER_SIZE SHARED_CTX_FIELD_1_SIZE
extern uint8_t staxSharedBuffer[SHARED_BUFFER_SIZE];
extern char staxSharedBuffer[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_
#endif // _UI_NBGL_H_

View File

@@ -25,7 +25,7 @@ static void reviewChoice(bool confirm) {
}
static bool displaySignPage(uint8_t page, nbgl_pageContent_t *content) {
(void) page;
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_chain_icon();
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(true);
content->infoLongPress.text = "Sign typed message";
content->infoLongPress.longPressText = "Hold to sign";
return true;

View File

@@ -39,7 +39,7 @@ static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) {
content->tagValueList.nbPairs = 2;
content->tagValueList.pairs = (nbgl_layoutTagValue_t *) tlv;
} else if (page == 1) {
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_chain_icon();
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(true);
content->infoLongPress.text = "Sign typed message";
content->infoLongPress.longPressText = "Hold to sign";
} else {

View File

@@ -37,7 +37,7 @@ static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) {
content->tagValueList.nbPairs = 3;
content->tagValueList.pairs = (nbgl_layoutTagValue_t *) tlv;
} else if (page == 1) {
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_chain_icon();
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(false);
content->infoLongPress.text = "Review stark limit order";
content->infoLongPress.longPressText = "Hold to sign";
} else {
@@ -52,7 +52,7 @@ static void reviewContinue(void) {
}
static void buildFirstPage(void) {
nbgl_useCaseReviewStart(get_app_chain_icon(),
nbgl_useCaseReviewStart(get_app_icon(false),
"Review stark limit order",
NULL,
"Reject",
@@ -64,4 +64,4 @@ void ui_stark_limit_order(void) {
buildFirstPage();
}
#endif
#endif

View File

@@ -82,7 +82,7 @@ static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) {
}
}
if (page == 2) {
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_chain_icon();
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(false);
content->infoLongPress.text = "Review transaction";
content->infoLongPress.longPressText = "Hold to sign";
}
@@ -116,7 +116,7 @@ void ui_stark_transfer(bool selfTransfer, bool conditional) {
subTitle = "Transfer";
}
}
nbgl_useCaseReviewStart(get_app_chain_icon(),
nbgl_useCaseReviewStart(get_app_icon(false),
"Review stark transaction",
subTitle,
"Reject",

View File

@@ -40,7 +40,7 @@ static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) {
content->tagValueList.nbPairs = 2;
content->tagValueList.pairs = (nbgl_layoutTagValue_t *) tlv;
} else if (page == 1) {
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_chain_icon();
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(false);
content->infoLongPress.text = "Unsafe Stark Sign";
content->infoLongPress.longPressText = "Hold to sign";
} else {
@@ -55,7 +55,7 @@ static void reviewContinue(void) {
}
static void buildFirstPage(void) {
nbgl_useCaseReviewStart(get_app_chain_icon(),
nbgl_useCaseReviewStart(get_app_icon(false),
"Unsafe Stark Sign",
NULL,
"Reject",
@@ -67,4 +67,4 @@ void ui_stark_unsafe_sign(void) {
buildFirstPage();
}
#endif // HAVE_STARKWARE
#endif // HAVE_STARKWARE

View File

@@ -82,10 +82,13 @@ def extract_from_c_files(sources, nodes_to_extract):
def merge_headers(sources, nodes_to_extract):
includes = [
'#include <stdbool.h>',
'#include <string.h>',
'#include "os.h"',
'#include "cx.h"',
'#include <stdbool.h>',
'#include <string.h>'
'#ifdef HAVE_NBGL',
'#include "nbgl_types.h"',
'#endif'
]
body = extract_from_headers(sources, nodes_to_extract)
@@ -156,11 +159,12 @@ if __name__ == "__main__":
"src/shared_context.h",
"src/eth_plugin_internal.h",
"src/nft.h",
"src/swap_lib_calls.h"
]
nodes_to_extract = {
"#define": ["MAX_TICKER_LEN", "ADDRESS_LENGTH", "INT256_LENGTH", "WEI_TO_ETHER", "SELECTOR_SIZE", "PARAMETER_LENGTH", "RUN_APPLICATION", "COLLECTION_NAME_MAX_LEN"],
"typedef enum": [],
"typedef struct": ["tokenDefinition_t", "txInt256_t", "txContent_t", "nftInfo_t"],
"typedef struct": ["tokenDefinition_t", "txInt256_t", "txContent_t", "nftInfo_t", "caller_app_t"],
"typedef union": ["extraInfo_t"],
"__attribute__((no_instrument_function)) inline": ["int allzeroes"],
"const": ["HEXDIGITS"],