Repository: LedgerHQ/app-ethereum (language: python)

Issue:
Remove need to add space manually for tickers



Discussion / hints:

Fix patch:
diff --git a/src/eth_plugin_handler.c b/src/eth_plugin_handler.c
index 22ffbe8f2..3aa6883ef 100644
--- a/src/eth_plugin_handler.c
+++ b/src/eth_plugin_handler.c
@@ -63,12 +63,8 @@ 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);
-
     queryContractUI->screenIndex = screenIndex;
-    strlcpy(queryContractUI->network_ticker,
-            get_network_ticker(),
-            sizeof(queryContractUI->network_ticker));
+    strlcpy(queryContractUI->network_ticker, get_network_ticker(), MAX_TICKER_LEN);
     queryContractUI->title = title;
     queryContractUI->titleLength = titleLength;
     queryContractUI->msg = msg;
diff --git a/src/eth_plugin_interface.h b/src/eth_plugin_interface.h
index 48c6e6708..5bf54992a 100644
--- a/src/eth_plugin_interface.h
+++ b/src/eth_plugin_interface.h
@@ -13,7 +13,8 @@ typedef enum {
     ETH_PLUGIN_INTERFACE_VERSION_2 = 2,
     ETH_PLUGIN_INTERFACE_VERSION_3 = 3,
     ETH_PLUGIN_INTERFACE_VERSION_4 = 4,
-    ETH_PLUGIN_INTERFACE_VERSION_LATEST = 5,
+    ETH_PLUGIN_INTERFACE_VERSION_5 = 5,
+    ETH_PLUGIN_INTERFACE_VERSION_LATEST = 6
 } eth_plugin_interface_version_t;
 
 typedef enum {
diff --git a/src/handle_get_printable_amount.c b/src/handle_get_printable_amount.c
index 13acc2841..715c85d10 100644
--- a/src/handle_get_printable_amount.c
+++ b/src/handle_get_printable_amount.c
@@ -20,8 +20,7 @@ int handle_get_printable_amount(get_printable_amount_parameters_t* params, chain
     if (params->is_fee) {
         uint8_t ticker_len = strnlen(config->coinName, sizeof(config->coinName));
         memcpy(ticker, config->coinName, ticker_len);
-        ticker[ticker_len] = ' ';
-        ticker[ticker_len + 1] = '\0';
+        ticker[ticker_len] = '\0';
         decimals = WEI_TO_ETHER;
     } else {
         // If the amount is *not* a fee, decimals and ticker are built from the given config
diff --git a/src/main.c b/src/main.c
index 5ca0a3461..261ff1851 100644
--- a/src/main.c
+++ b/src/main.c
@@ -918,7 +918,7 @@ void app_exit() {
 
 void init_coin_config(chain_config_t *coin_config) {
     memset(coin_config, 0, sizeof(chain_config_t));
-    strcpy(coin_config->coinName, CHAINID_COINNAME " ");
+    strcpy(coin_config->coinName, CHAINID_COINNAME);
     coin_config->chainId = CHAIN_ID;
     coin_config->kind = CHAIN_KIND;
 }
diff --git a/src/tokens.h b/src/tokens.h
index 0a10125f1..e4e096c25 100644
--- a/src/tokens.h
+++ b/src/tokens.h
@@ -21,7 +21,7 @@
 #include <stdint.h>
 #include "ethUstream.h"
 
-#define MAX_TICKER_LEN 12  // 10 characters + ' ' + '\0'
+#define MAX_TICKER_LEN 11  // 10 characters + '\0'
 #define MAX_ITEMS      2
 
 typedef struct tokenDefinition_t {
diff --git a/src/utils.c b/src/utils.c
index be03f10c9..2c553b4a8 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -132,6 +132,9 @@ void amountToString(const uint8_t *amount,
     uint8_t ticker_len = strnlen(ticker, MAX_TICKER_LEN);
 
     memcpy(out_buffer, ticker, MIN(out_buffer_size, ticker_len));
+    if (ticker_len > 0) {
+        out_buffer[ticker_len++] = ' ';
+    }
 
     if (adjustDecimals(tmp_buffer,
                        amount_len,
@@ -155,8 +158,7 @@ bool parse_swap_config(const uint8_t *config, uint8_t config_len, char *ticker,
     }
     memcpy(ticker, config + offset, ticker_len);
     offset += ticker_len;
-    ticker[ticker_len] = ' ';
-    ticker[ticker_len + 1] = '\0';
+    ticker[ticker_len] = '\0';
 
     if (config_len - offset < 1) {
         return false;
diff --git a/src_common/network.c b/src_common/network.c
index a41277448..9d55ec286 100644
--- a/src_common/network.c
+++ b/src_common/network.c
@@ -8,60 +8,60 @@
 #include "utils.h"
 
 // Mappping of chain ids to networks.
-const network_info_t NETWORK_MAPPING[] = {
-    {.chain_id = 1, .name = "Ethereum", .ticker = "ETH "},
-    {.chain_id = 3, .name = "Ropsten", .ticker = "ETH "},
-    {.chain_id = 4, .name = "Rinkeby", .ticker = "ETH "},
-    {.chain_id = 5, .name = "Goerli", .ticker = "ETH "},
-    {.chain_id = 10, .name = "Optimism", .ticker = "ETH "},
-    {.chain_id = 42, .name = "Kovan", .ticker = "ETH "},
-    {.chain_id = 56, .name = "BSC", .ticker = "BNB "},
-    {.chain_id = 100, .name = "xDai", .ticker = "xDAI "},
-    {.chain_id = 137, .name = "Polygon", .ticker = "MATIC "},
-    {.chain_id = 250, .name = "Fantom", .ticker = "FTM "},
-    {.chain_id = 42161, .name = "Arbitrum", .ticker = "AETH "},
-    {.chain_id = 42220, .name = "Celo", .ticker = "CELO "},
-    {.chain_id = 43114, .name = "Avalanche", .ticker = "AVAX "},
-    {.chain_id = 44787, .name = "Celo Alfajores", .ticker = "aCELO "},
-    {.chain_id = 62320, .name = "Celo Baklava", .ticker = "bCELO "},
-    {.chain_id = 11297108109, .name = "Palm Network", .ticker = "PALM "},
-    {.chain_id = 1818, .name = "Cube", .ticker = "CUBE "},
-    {.chain_id = 336, .name = "Shiden", .ticker = "SDN "},
-    {.chain_id = 592, .name = "Astar", .ticker = "ASTR "},
-    {.chain_id = 50, .name = "XDC", .ticker = "XDC "},
-    {.chain_id = 82, .name = "Meter", .ticker = "MTR "},
-    {.chain_id = 62621, .name = "Multivac", .ticker = "MTV "},
-    {.chain_id = 20531812, .name = "Tecra", .ticker = "TCR "},
-    {.chain_id = 20531811, .name = "TecraTestnet", .ticker = "TCR "},
-    {.chain_id = 51, .name = "Apothemnetwork", .ticker = "XDC "},
-    {.chain_id = 199, .name = "BTTC", .ticker = "BTT "},
-    {.chain_id = 1030, .name = "Conflux", .ticker = "CFX "},
-    {.chain_id = 61, .name = "Ethereum Classic", .ticker = "ETC "},
-    {.chain_id = 246, .name = "EnergyWebChain", .ticker = "EWC "},
-    {.chain_id = 14, .name = "Flare", .ticker = "FLR "},
-    {.chain_id = 16, .name = "Flare Coston", .ticker = "FLR "},
-    {.chain_id = 24, .name = "KardiaChain", .ticker = "KAI "},
-    {.chain_id = 1284, .name = "Moonbeam", .ticker = "GLMR "},
-    {.chain_id = 1285, .name = "Moonriver", .ticker = "MOVR "},
-    {.chain_id = 66, .name = "OKXChain", .ticker = "OKT "},
-    {.chain_id = 99, .name = "POA", .ticker = "POA "},
-    {.chain_id = 7341, .name = "Shyft", .ticker = "SHFT "},
-    {.chain_id = 19, .name = "Songbird", .ticker = "SGB "},
-    {.chain_id = 73799, .name = "Volta", .ticker = "VOLTA "},
-    {.chain_id = 25, .name = "Cronos", .ticker = "CRO "},
-    {.chain_id = 534354, .name = "Scroll (Pre-Alpha)", .ticker = "SCR "},
-    {.chain_id = 534353, .name = "Scroll (Goerli)", .ticker = "SCR "},
-    {.chain_id = 534352, .name = "Scroll", .ticker = "SCR "},
-    {.chain_id = 321, .name = "KCC", .ticker = "KCS "},
-    {.chain_id = 30, .name = "Rootstock", .ticker = "RBTC "},
-    {.chain_id = 9001, .name = "Evmos", .ticker = "EVMOS "},
-    {.chain_id = 1088, .name = "Metis Andromeda", .ticker = "METIS "},
-    {.chain_id = 2222, .name = "Kava EVM", .ticker = "KAVA "},
-    {.chain_id = 8217, .name = "Klaytn Cypress", .ticker = "KLAY "},
-    {.chain_id = 57, .name = "Syscoin", .ticker = "SYS "},
-    {.chain_id = 106, .name = "Velas EVM", .ticker = "VLX "},
-    {.chain_id = 288, .name = "Boba Network", .ticker = "ETH "},
-    {.chain_id = 39797, .name = "Energi", .ticker = "NRG "}};
+static const network_info_t NETWORK_MAPPING[] = {
+    {.chain_id = 1, .name = "Ethereum", .ticker = "ETH"},
+    {.chain_id = 3, .name = "Ropsten", .ticker = "ETH"},
+    {.chain_id = 4, .name = "Rinkeby", .ticker = "ETH"},
+    {.chain_id = 5, .name = "Goerli", .ticker = "ETH"},
+    {.chain_id = 10, .name = "Optimism", .ticker = "ETH"},
+    {.chain_id = 42, .name = "Kovan", .ticker = "ETH"},
+    {.chain_id = 56, .name = "BSC", .ticker = "BNB"},
+    {.chain_id = 100, .name = "xDai", .ticker = "xDAI"},
+    {.chain_id = 137, .name = "Polygon", .ticker = "MATIC"},
+    {.chain_id = 250, .name = "Fantom", .ticker = "FTM"},
+    {.chain_id = 42161, .name = "Arbitrum", .ticker = "AETH"},
+    {.chain_id = 42220, .name = "Celo", .ticker = "CELO"},
+    {.chain_id = 43114, .name = "Avalanche", .ticker = "AVAX"},
+    {.chain_id = 44787, .name = "Celo Alfajores", .ticker = "aCELO"},
+    {.chain_id = 62320, .name = "Celo Baklava", .ticker = "bCELO"},
+    {.chain_id = 11297108109, .name = "Palm Network", .ticker = "PALM"},
+    {.chain_id = 1818, .name = "Cube", .ticker = "CUBE"},
+    {.chain_id = 336, .name = "Shiden", .ticker = "SDN"},
+    {.chain_id = 592, .name = "Astar", .ticker = "ASTR"},
+    {.chain_id = 50, .name = "XDC", .ticker = "XDC"},
+    {.chain_id = 82, .name = "Meter", .ticker = "MTR"},
+    {.chain_id = 62621, .name = "Multivac", .ticker = "MTV"},
+    {.chain_id = 20531812, .name = "Tecra", .ticker = "TCR"},
+    {.chain_id = 20531811, .name = "TecraTestnet", .ticker = "TCR"},
+    {.chain_id = 51, .name = "Apothemnetwork", .ticker = "XDC"},
+    {.chain_id = 199, .name = "BTTC", .ticker = "BTT"},
+    {.chain_id = 1030, .name = "Conflux", .ticker = "CFX"},
+    {.chain_id = 61, .name = "Ethereum Classic", .ticker = "ETC"},
+    {.chain_id = 246, .name = "EnergyWebChain", .ticker = "EWC"},
+    {.chain_id = 14, .name = "Flare", .ticker = "FLR"},
+    {.chain_id = 16, .name = "Flare Coston", .ticker = "FLR"},
+    {.chain_id = 24, .name = "KardiaChain", .ticker = "KAI"},
+    {.chain_id = 1284, .name = "Moonbeam", .ticker = "GLMR"},
+    {.chain_id = 1285, .name = "Moonriver", .ticker = "MOVR"},
+    {.chain_id = 66, .name = "OKXChain", .ticker = "OKT"},
+    {.chain_id = 99, .name = "POA", .ticker = "POA"},
+    {.chain_id = 7341, .name = "Shyft", .ticker = "SHFT"},
+    {.chain_id = 19, .name = "Songbird", .ticker = "SGB"},
+    {.chain_id = 73799, .name = "Volta", .ticker = "VOLTA"},
+    {.chain_id = 25, .name = "Cronos", .ticker = "CRO"},
+    {.chain_id = 534354, .name = "Scroll (Pre-Alpha)", .ticker = "SCR"},
+    {.chain_id = 534353, .name = "Scroll (Goerli)", .ticker = "SCR"},
+    {.chain_id = 534352, .name = "Scroll", .ticker = "SCR"},
+    {.chain_id = 321, .name = "KCC", .ticker = "KCS"},
+    {.chain_id = 30, .name = "Rootstock", .ticker = "RBTC"},
+    {.chain_id = 9001, .name = "Evmos", .ticker = "EVMOS"},
+    {.chain_id = 1088, .name = "Metis Andromeda", .ticker = "METIS"},
+    {.chain_id = 2222, .name = "Kava EVM", .ticker = "KAVA"},
+    {.chain_id = 8217, .name = "Klaytn Cypress", .ticker = "KLAY"},
+    {.chain_id = 57, .name = "Syscoin", .ticker = "SYS"},
+    {.chain_id = 106, .name = "Velas EVM", .ticker = "VLX"},
+    {.chain_id = 288, .name = "Boba Network", .ticker = "ETH"},
+    {.chain_id = 39797, .name = "Energi", .ticker = "NRG"}};
 
 uint64_t get_chain_id(void) {
     uint64_t chain_id = 0;
diff --git a/src_common/network.h b/src_common/network.h
index ade31523e..b9ce7f31a 100644
--- a/src_common/network.h
+++ b/src_common/network.h
@@ -5,8 +5,6 @@
 #include "tokens.h"
 #include "shared_context.h"
 
-#define MAX_NETWORK_TICKER_LEN 8
-
 typedef struct network_info_s {
     const char *name;
     const char *ticker;
diff --git a/src_features/provideErc20TokenInformation/cmd_provideTokenInfo.c b/src_features/provideErc20TokenInformation/cmd_provideTokenInfo.c
index 134096646..496c54ada 100644
--- a/src_features/provideErc20TokenInformation/cmd_provideTokenInfo.c
+++ b/src_features/provideErc20TokenInformation/cmd_provideTokenInfo.c
@@ -42,8 +42,7 @@ void handleProvideErc20TokenInformation(uint8_t p1,
     }
     cx_hash((cx_hash_t *) &sha256, 0, workBuffer + offset, tickerLength, NULL, 0);
     memmove(token->ticker, workBuffer + offset, tickerLength);
-    token->ticker[tickerLength] = ' ';
-    token->ticker[tickerLength + 1] = '\0';
+    token->ticker[tickerLength] = '\0';
     offset += tickerLength;
     dataLength -= tickerLength;
 
@@ -136,8 +135,7 @@ void handleProvideErc20TokenInformation(uint8_t p1,
     }
     cx_hash_sha256(workBuffer + offset, tickerLength + 20 + 4 + 4, hash, 32);
     memmove(token->ticker, workBuffer + offset, tickerLength);
-    token->ticker[tickerLength] = ' ';
-    token->ticker[tickerLength + 1] = '\0';
+    token->ticker[tickerLength] = '\0';
     offset += tickerLength;
     dataLength -= tickerLength;
     memmove(token->address, workBuffer + offset, 20);
diff --git a/src_features/signTx/logic_signTx.c b/src_features/signTx/logic_signTx.c
index 1c4164677..c22214c5a 100644
--- a/src_features/signTx/logic_signTx.c
+++ b/src_features/signTx/logic_signTx.c
@@ -240,6 +240,7 @@ static void feesToString(uint256_t *rawFee, char *displayBuffer, uint32_t displa
         displayBuffer[tickerOffset] = feeTicker[tickerOffset];
         tickerOffset++;
     }
+    if ((uint32_t) tickerOffset < displayBufferSize) displayBuffer[tickerOffset++] = ' ';
     while (G_io_apdu_buffer[i]) {
         if ((uint32_t) (tickerOffset) + i >= displayBufferSize) {
             break;
diff --git a/src_plugins/starkware/starkware_plugin.c b/src_plugins/starkware/starkware_plugin.c
index 3937adaaa..634ea4e53 100644
--- a/src_plugins/starkware/starkware_plugin.c
+++ b/src_plugins/starkware/starkware_plugin.c
@@ -326,10 +326,11 @@ void starkware_print_amount(uint8_t *amountData,
     }
     tostring256(&amount, 10, (char *) (G_io_apdu_buffer + 100), 100);
     strlcpy(destination, ticker, destinationLength);
+    strlcat(destination, " ", destinationLength);
     adjustDecimals((char *) (G_io_apdu_buffer + 100),
                    strlen((char *) (G_io_apdu_buffer + 100)),
-                   destination + strlen(ticker),
-                   destinationLength - strlen(ticker),
+                   destination + strlen(ticker) + 1,
+                   destinationLength - strlen(ticker) - 1,
                    decimals);
 }
 


Test patch:
diff --git a/tests/zemu/snapshots/nanos_approve_dai_tokens/00002.png b/tests/zemu/snapshots/nanos_approve_dai_tokens/00002.png
index d514de0dd..8afcc0115 100644
Binary files a/tests/zemu/snapshots/nanos_approve_dai_tokens/00002.png and b/tests/zemu/snapshots/nanos_approve_dai_tokens/00002.png differ
diff --git a/tests/zemu/snapshots/nanox_approve_dai_tokens/00002.png b/tests/zemu/snapshots/nanox_approve_dai_tokens/00002.png
index f42c8d158..1bf7f2e0b 100644
Binary files a/tests/zemu/snapshots/nanox_approve_dai_tokens/00002.png and b/tests/zemu/snapshots/nanox_approve_dai_tokens/00002.png differ