Now displays the proper network name for clones on the home page

This commit is contained in:
Alexandre Paillier
2022-12-02 11:33:26 +01:00
parent f71b341b8d
commit 856785f83d
6 changed files with 64 additions and 24 deletions
+2 -2
View File
@@ -63,11 +63,11 @@ void eth_plugin_prepare_query_contract_UI(ethQueryContractUI_t *queryContractUI,
queryContractUI->item2 = &tmpCtx.transactionContext.extraInfo[0];
}
strlcpy(queryContractUI->network_ticker, get_network_ticker(), MAX_TICKER_LEN);
strlcpy(queryContractUI->network_ticker, get_tx_network_ticker(), MAX_TICKER_LEN);
queryContractUI->screenIndex = screenIndex;
strlcpy(queryContractUI->network_ticker,
get_network_ticker(),
get_tx_network_ticker(),
sizeof(queryContractUI->network_ticker));
queryContractUI->title = title;
queryContractUI->titleLength = titleLength;
+37 -7
View File
@@ -7,6 +7,11 @@
#include "shared_context.h"
#include "utils.h"
typedef enum {
APP,
TX
} e_net_type;
// Mappping of chain ids to networks.
const network_info_t NETWORK_MAPPING[] = {
{.chain_id = 1, .name = "Ethereum", .ticker = "ETH "},
@@ -54,7 +59,8 @@ const network_info_t NETWORK_MAPPING[] = {
{.chain_id = 534352, .name = "Scroll", .ticker = "SCR "},
{.chain_id = 321, .name = "KCC", .ticker = "KCS "}};
uint64_t get_chain_id(void) {
uint64_t get_tx_chain_id(void) {
uint64_t chain_id = 0;
switch (txContext.txType) {
@@ -73,8 +79,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]);
@@ -83,8 +97,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 {
@@ -92,11 +106,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);
}
+9 -6
View File
@@ -13,13 +13,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_
+5 -5
View File
@@ -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;
@@ -272,10 +272,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.
@@ -307,13 +307,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);
+2 -2
View File
@@ -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();
}
}
+9 -2
View File
@@ -2,6 +2,7 @@
#include "ui_nbgl.h"
#include "nbgl_use_case.h"
#include "glyphs.h"
#include "network.h"
nbgl_page_t* pageContext;
@@ -19,5 +20,11 @@ void app_quit(void) {
}
void ui_idle(void) {
nbgl_useCaseHome(APPNAME, &ICONGLYPH, NULL, true, ui_menu_settings, app_quit);
}
char *app_name = (char*)get_app_network_name();
// In case a new clone is ran with an older ethereum app (unknown chain ID)
if (app_name == NULL) {
app_name = APPNAME;
}
nbgl_useCaseHome(app_name, &ICONGLYPH, NULL, true, ui_menu_settings, app_quit);
}