Home page rework
Now explicitly shows if the app has been launched through a plugin or clone thanks to the new NBGL use case
This commit is contained in:
committed by
Clement Bouvet
parent
e950372438
commit
462c39aa4b
@@ -64,7 +64,7 @@ void eth_plugin_prepare_query_contract_UI(ethQueryContractUI_t *queryContractUI,
|
||||
}
|
||||
|
||||
queryContractUI->screenIndex = screenIndex;
|
||||
strlcpy(queryContractUI->network_ticker, get_network_ticker(), MAX_TICKER_LEN);
|
||||
strlcpy(queryContractUI->network_ticker, get_tx_network_ticker(), MAX_TICKER_LEN);
|
||||
queryContractUI->title = title;
|
||||
queryContractUI->titleLength = titleLength;
|
||||
queryContractUI->msg = msg;
|
||||
|
||||
+16
-21
@@ -69,7 +69,9 @@ bolos_ux_params_t G_ux_params;
|
||||
|
||||
const internalStorage_t N_storage_real;
|
||||
|
||||
chain_config_t *chainConfig;
|
||||
const char *plugin_name = NULL;
|
||||
|
||||
chain_config_t *chainConfig = NULL;
|
||||
|
||||
void reset_app_context() {
|
||||
// PRINTF("!!RESET_APP_CONTEXT\n");
|
||||
@@ -929,14 +931,19 @@ void init_coin_config(chain_config_t *coin_config) {
|
||||
coin_config->kind = CHAIN_KIND;
|
||||
}
|
||||
|
||||
void coin_main(chain_config_t *coin_config) {
|
||||
void coin_main(libargs_t *args) {
|
||||
chain_config_t config;
|
||||
if (coin_config == NULL) {
|
||||
if (args) {
|
||||
if (args->chain_config != NULL) {
|
||||
chainConfig = args->chain_config;
|
||||
}
|
||||
plugin_name = args->plugin_name;
|
||||
}
|
||||
if (chainConfig == NULL) {
|
||||
init_coin_config(&config);
|
||||
chainConfig = &config;
|
||||
} else {
|
||||
chainConfig = coin_config;
|
||||
}
|
||||
|
||||
reset_app_context();
|
||||
tmpCtx.transactionContext.currentItemIndex = 0;
|
||||
|
||||
@@ -977,7 +984,6 @@ void coin_main(chain_config_t *coin_config) {
|
||||
USB_power(1);
|
||||
|
||||
ui_idle();
|
||||
|
||||
#ifdef HAVE_BLE
|
||||
BLE_power(0, NULL);
|
||||
BLE_power(1, "Nano X");
|
||||
@@ -1002,18 +1008,7 @@ void coin_main(chain_config_t *coin_config) {
|
||||
app_exit();
|
||||
}
|
||||
|
||||
struct libargs_s {
|
||||
unsigned int id;
|
||||
unsigned int command;
|
||||
chain_config_t *chain_config;
|
||||
union {
|
||||
check_address_parameters_t *check_address;
|
||||
create_transaction_parameters_t *create_transaction;
|
||||
get_printable_amount_parameters_t *get_printable_amount;
|
||||
};
|
||||
};
|
||||
|
||||
static void library_main_helper(struct libargs_s *args) {
|
||||
static void library_main_helper(libargs_t *args) {
|
||||
check_api_level(CX_COMPAT_APILEVEL);
|
||||
PRINTF("Inside a library \n");
|
||||
switch (args->command) {
|
||||
@@ -1041,7 +1036,7 @@ static void library_main_helper(struct libargs_s *args) {
|
||||
}
|
||||
}
|
||||
|
||||
void library_main(struct libargs_s *args) {
|
||||
void library_main(libargs_t *args) {
|
||||
chain_config_t coin_config;
|
||||
if (args->chain_config == NULL) {
|
||||
init_coin_config(&coin_config);
|
||||
@@ -1112,7 +1107,7 @@ __attribute__((section(".boot"))) int main(int arg0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct libargs_s *args = (struct libargs_s *) arg0;
|
||||
libargs_t *args = (libargs_t *) arg0;
|
||||
if (args->id != 0x100) {
|
||||
app_exit();
|
||||
return 0;
|
||||
@@ -1120,7 +1115,7 @@ __attribute__((section(".boot"))) int main(int arg0) {
|
||||
switch (args->command) {
|
||||
case RUN_APPLICATION:
|
||||
// called as ethereum from altcoin or plugin
|
||||
coin_main(args->chain_config);
|
||||
coin_main(args);
|
||||
break;
|
||||
default:
|
||||
// called as ethereum or altcoin library
|
||||
|
||||
@@ -226,6 +226,8 @@ extern bool quantumSet;
|
||||
extern uint32_t eth2WithdrawalIndex;
|
||||
#endif
|
||||
|
||||
extern const char *plugin_name;
|
||||
|
||||
void reset_app_context(void);
|
||||
const uint8_t *parseBip32(const uint8_t *dataBuffer, uint8_t *dataLength, bip32_path_t *bip32);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define _SWAP_LIB_CALLS_H_
|
||||
|
||||
#include "stdbool.h"
|
||||
#include "chainConfig.h"
|
||||
|
||||
#define RUN_APPLICATION 1
|
||||
|
||||
@@ -52,4 +53,16 @@ typedef struct create_transaction_parameters_s {
|
||||
const char* const destination_address_extra_id;
|
||||
} create_transaction_parameters_t;
|
||||
|
||||
typedef struct libargs_s {
|
||||
unsigned int id;
|
||||
unsigned int command;
|
||||
chain_config_t *chain_config;
|
||||
union {
|
||||
check_address_parameters_t *check_address;
|
||||
create_transaction_parameters_t *create_transaction;
|
||||
get_printable_amount_parameters_t *get_printable_amount;
|
||||
char *plugin_name;
|
||||
};
|
||||
} libargs_t;
|
||||
|
||||
#endif // _SWAP_LIB_CALLS_H_
|
||||
|
||||
@@ -224,7 +224,7 @@ void ux_approve_tx(bool fromPlugin) {
|
||||
ux_approval_tx_flow[step++] = &ux_approval_nonce_step;
|
||||
}
|
||||
|
||||
uint64_t chain_id = get_chain_id();
|
||||
uint64_t chain_id = get_tx_chain_id();
|
||||
if (chainConfig->chainId == ETHEREUM_MAINNET_CHAINID && chain_id != chainConfig->chainId) {
|
||||
ux_approval_tx_flow[step++] = &ux_approval_network_step;
|
||||
}
|
||||
@@ -235,4 +235,4 @@ void ux_approve_tx(bool fromPlugin) {
|
||||
ux_approval_tx_flow[step++] = FLOW_END_STEP;
|
||||
|
||||
ux_flow_init(0, ux_approval_tx_flow, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
+37
-7
@@ -7,6 +7,11 @@
|
||||
#include "shared_context.h"
|
||||
#include "utils.h"
|
||||
|
||||
typedef enum {
|
||||
APP,
|
||||
TX
|
||||
} e_net_type;
|
||||
|
||||
// Mappping of chain ids to networks.
|
||||
static const network_info_t NETWORK_MAPPING[] = {
|
||||
{.chain_id = 1, .name = "Ethereum", .ticker = "ETH"},
|
||||
@@ -63,7 +68,8 @@ static const network_info_t NETWORK_MAPPING[] = {
|
||||
{.chain_id = 288, .name = "Boba Network", .ticker = "ETH"},
|
||||
{.chain_id = 39797, .name = "Energi", .ticker = "NRG"}};
|
||||
|
||||
uint64_t get_chain_id(void) {
|
||||
|
||||
uint64_t get_tx_chain_id(void) {
|
||||
uint64_t chain_id = 0;
|
||||
|
||||
switch (txContext.txType) {
|
||||
@@ -82,8 +88,16 @@ uint64_t get_chain_id(void) {
|
||||
return chain_id;
|
||||
}
|
||||
|
||||
const network_info_t *get_network(void) {
|
||||
uint64_t chain_id = get_chain_id();
|
||||
uint64_t get_app_chain_id(void) {
|
||||
return chainConfig->chainId;
|
||||
}
|
||||
|
||||
static uint64_t get_chain_id(e_net_type type) {
|
||||
return (type == APP) ? get_app_chain_id() : get_tx_chain_id();
|
||||
}
|
||||
|
||||
static const network_info_t *get_network(e_net_type type) {
|
||||
uint64_t chain_id = get_chain_id(type);
|
||||
for (size_t i = 0; i < sizeof(NETWORK_MAPPING) / sizeof(*NETWORK_MAPPING); i++) {
|
||||
if (NETWORK_MAPPING[i].chain_id == chain_id) {
|
||||
return (const network_info_t *) PIC(&NETWORK_MAPPING[i]);
|
||||
@@ -92,8 +106,8 @@ const network_info_t *get_network(void) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *get_network_name(void) {
|
||||
const network_info_t *network = get_network();
|
||||
static const char *get_network_name(e_net_type type) {
|
||||
const network_info_t *network = get_network(type);
|
||||
if (network == NULL) {
|
||||
return NULL;
|
||||
} else {
|
||||
@@ -101,11 +115,27 @@ const char *get_network_name(void) {
|
||||
}
|
||||
}
|
||||
|
||||
const char *get_network_ticker(void) {
|
||||
const network_info_t *network = get_network();
|
||||
const char *get_app_network_name(void) {
|
||||
return get_network_name(APP);
|
||||
}
|
||||
|
||||
const char *get_tx_network_name(void) {
|
||||
return get_network_name(TX);
|
||||
}
|
||||
|
||||
static const char *get_network_ticker(e_net_type type) {
|
||||
const network_info_t *network = get_network(type);
|
||||
if (network == NULL) {
|
||||
return chainConfig->coinName;
|
||||
} else {
|
||||
return (char *) PIC(network->ticker);
|
||||
}
|
||||
}
|
||||
|
||||
const char *get_app_network_ticker(void) {
|
||||
return get_network_ticker(APP);
|
||||
}
|
||||
|
||||
const char *get_tx_network_ticker(void) {
|
||||
return get_network_ticker(TX);
|
||||
}
|
||||
|
||||
@@ -11,13 +11,16 @@ typedef struct network_info_s {
|
||||
uint64_t chain_id;
|
||||
} network_info_t;
|
||||
|
||||
// Returns the current chain id. Defaults to 0 if txType was not found.
|
||||
uint64_t get_chain_id(void);
|
||||
// Returns a pointer to the network struct, or NULL if there is none.
|
||||
const network_info_t *get_network(void);
|
||||
// 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);
|
||||
|
||||
// Returns a pointer to the network name, or NULL if there is none.
|
||||
const char *get_network_name(void);
|
||||
const char *get_tx_network_name(void);
|
||||
const char *get_app_network_name(void);
|
||||
|
||||
// Returns a pointer to the network ticker, or chainConfig->coinName if there is none.
|
||||
const char *get_network_ticker(void);
|
||||
const char *get_tx_network_ticker(void);
|
||||
const char *get_app_network_ticker(void);
|
||||
|
||||
#endif // _NETWORK_H_
|
||||
|
||||
@@ -214,7 +214,7 @@ static void computeFees(txInt256_t *BEgasPrice, txInt256_t *BEgasLimit, uint256_
|
||||
}
|
||||
|
||||
static void feesToString(uint256_t *rawFee, char *displayBuffer, uint32_t displayBufferSize) {
|
||||
const char *feeTicker = get_network_ticker();
|
||||
const char *feeTicker = get_tx_network_ticker();
|
||||
uint8_t tickerOffset = 0;
|
||||
uint32_t i;
|
||||
|
||||
@@ -273,10 +273,10 @@ void prepareFeeDisplay() {
|
||||
}
|
||||
|
||||
void prepareNetworkDisplay() {
|
||||
const char *name = get_network_name();
|
||||
const char *name = get_tx_network_name();
|
||||
if (name == NULL) {
|
||||
// No network name found so simply copy the chain ID as the network name.
|
||||
uint64_t chain_id = get_chain_id();
|
||||
uint64_t chain_id = get_tx_chain_id();
|
||||
u64_to_string(chain_id, strings.common.network_name, sizeof(strings.common.network_name));
|
||||
} else {
|
||||
// Network name found, simply copy it.
|
||||
@@ -308,13 +308,13 @@ static void get_public_key(uint8_t *out, uint8_t outLength) {
|
||||
void finalizeParsing(bool direct) {
|
||||
char displayBuffer[50];
|
||||
uint8_t decimals = WEI_TO_ETHER;
|
||||
const char *ticker = get_network_ticker();
|
||||
const char *ticker = get_tx_network_ticker();
|
||||
ethPluginFinalize_t pluginFinalize;
|
||||
bool genericUI = true;
|
||||
|
||||
// Verify the chain
|
||||
if (chainConfig->chainId != ETHEREUM_MAINNET_CHAINID) {
|
||||
uint64_t id = get_chain_id();
|
||||
uint64_t id = get_tx_chain_id();
|
||||
|
||||
if (chainConfig->chainId != id) {
|
||||
PRINTF("Invalid chainID %u expected %u\n", id, chainConfig->chainId);
|
||||
|
||||
@@ -213,10 +213,10 @@ void ux_approve_tx(bool fromPlugin) {
|
||||
tx_approval_context.fromPlugin = fromPlugin;
|
||||
tx_approval_context.displayNetwork = false;
|
||||
|
||||
uint64_t chain_id = get_chain_id();
|
||||
uint64_t chain_id = get_tx_chain_id();
|
||||
if (chainConfig->chainId == ETHEREUM_MAINNET_CHAINID && chain_id != chainConfig->chainId) {
|
||||
tx_approval_context.displayNetwork = true;
|
||||
}
|
||||
|
||||
buildFirstPage();
|
||||
}
|
||||
}
|
||||
|
||||
+39
-2
@@ -1,7 +1,9 @@
|
||||
#include "common_ui.h"
|
||||
#include "shared_context.h"
|
||||
#include "ui_nbgl.h"
|
||||
#include "nbgl_use_case.h"
|
||||
#include "glyphs.h"
|
||||
#include "network.h"
|
||||
|
||||
nbgl_page_t* pageContext;
|
||||
|
||||
@@ -19,5 +21,40 @@ void app_quit(void) {
|
||||
}
|
||||
|
||||
void ui_idle(void) {
|
||||
nbgl_useCaseHome(APPNAME, &ICONGLYPH, NULL, true, ui_menu_settings, app_quit);
|
||||
}
|
||||
if (plugin_name != NULL) { // plugin
|
||||
nbgl_useCasePlugInHome((char*)plugin_name,
|
||||
APPNAME,
|
||||
&C_stax_app_ethereum,
|
||||
NULL,
|
||||
NULL,
|
||||
true,
|
||||
ui_menu_settings,
|
||||
app_quit);
|
||||
} else {
|
||||
char *app_name = (char*) get_app_network_name();
|
||||
|
||||
switch (get_app_chain_id()) {
|
||||
// Standalone apps
|
||||
case 1: // Mainnet
|
||||
case 3: // Ropsten
|
||||
case 5: // Goerli
|
||||
nbgl_useCaseHome(app_name,
|
||||
&ICONGLYPH,
|
||||
NULL,
|
||||
true,
|
||||
ui_menu_settings,
|
||||
app_quit);
|
||||
break;
|
||||
// Clones
|
||||
default:
|
||||
nbgl_useCasePlugInHome(app_name ? app_name : "???",
|
||||
APPNAME,
|
||||
&C_stax_app_ethereum,
|
||||
NULL,
|
||||
NULL,
|
||||
true,
|
||||
ui_menu_settings,
|
||||
app_quit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user