diff --git a/src/handle_get_printable_amount.c b/src/handle_get_printable_amount.c index a2e3338004..af5951852e 100644 --- a/src/handle_get_printable_amount.c +++ b/src/handle_get_printable_amount.c @@ -7,32 +7,32 @@ #include "common_utils.h" #include "uint256.h" #include "string.h" +#include "network.h" void handle_get_printable_amount(get_printable_amount_parameters_t* params, chain_config_t* config) { - uint8_t decimals; char ticker[MAX_TICKER_LEN]; + uint8_t decimals; + uint64_t chain_id = 0; + memset(params->printable_amount, 0, sizeof(params->printable_amount)); if (params->amount_length > 32) { PRINTF("Amount is too big, 32 bytes max but buffer has %u bytes", params->amount_length); return; } + if (!parse_swap_config(params->coin_configuration, + params->coin_configuration_length, + ticker, + &decimals, + &chain_id)) { + PRINTF("Error while parsing config\n"); + return; + } // If the amount is a fee, its value is nominated in ETH even if we're doing an ERC20 swap if (params->is_fee) { - uint8_t ticker_len = strnlen(config->coinName, sizeof(config->coinName)); - memcpy(ticker, config->coinName, ticker_len); - ticker[ticker_len] = '\0'; + strlcpy(ticker, get_displayable_ticker(&chain_id, config), sizeof(ticker)); decimals = WEI_TO_ETHER; - } else { - // If the amount is *not* a fee, decimals and ticker are built from the given config - if (!parse_swap_config(params->coin_configuration, - params->coin_configuration_length, - ticker, - &decimals)) { - PRINTF("Error while parsing config\n"); - return; - } } if (!amountToString(params->amount, diff --git a/src/handle_swap_sign_transaction.c b/src/handle_swap_sign_transaction.c index 3b8be8342e..f0ca62178d 100644 --- a/src/handle_swap_sign_transaction.c +++ b/src/handle_swap_sign_transaction.c @@ -5,6 +5,7 @@ #include "handle_swap_sign_transaction.h" #include "shared_context.h" #include "common_utils.h" +#include "network.h" #ifdef HAVE_NBGL #include "nbgl_use_case.h" #endif // HAVE_NBGL @@ -27,12 +28,15 @@ bool copy_transaction_parameters(create_transaction_parameters_t* sign_transacti return false; } - uint8_t decimals; char ticker[MAX_TICKER_LEN]; + uint8_t decimals; + uint64_t chain_id = 0; + if (!parse_swap_config(sign_transaction_params->coin_configuration, sign_transaction_params->coin_configuration_length, ticker, - &decimals)) { + &decimals, + &chain_id)) { PRINTF("Error while parsing config\n"); return false; } @@ -46,7 +50,7 @@ bool copy_transaction_parameters(create_transaction_parameters_t* sign_transacti } // If the amount is a fee, its value is nominated in ETH even if we're doing an ERC20 swap - strlcpy(ticker, config->coinName, MAX_TICKER_LEN); + strlcpy(ticker, get_displayable_ticker(&chain_id, config), sizeof(ticker)); decimals = WEI_TO_ETHER; if (!amountToString(sign_transaction_params->fee_amount, sign_transaction_params->fee_amount_length, diff --git a/src/swap_utils.c b/src/swap_utils.c index 2fa4a5a565..a0002da187 100644 --- a/src/swap_utils.c +++ b/src/swap_utils.c @@ -22,8 +22,13 @@ #include "asset_info.h" #include "swap_utils.h" -bool parse_swap_config(const uint8_t *config, uint8_t config_len, char *ticker, uint8_t *decimals) { +bool parse_swap_config(const uint8_t *config, + uint8_t config_len, + char *ticker, + uint8_t *decimals, + uint64_t *chain_id) { uint8_t ticker_len, offset = 0; + if (config_len == 0) { return false; } @@ -38,6 +43,11 @@ bool parse_swap_config(const uint8_t *config, uint8_t config_len, char *ticker, if (config_len - offset < 1) { return false; } - *decimals = config[offset]; + *decimals = config[offset++]; + // optional for retro-compatibility + if ((config_len - offset) >= sizeof(*chain_id)) { + *chain_id = u64_from_BE(config + offset, sizeof(*chain_id)); + offset += sizeof(*chain_id); + } return true; } diff --git a/src/swap_utils.h b/src/swap_utils.h index 00af3d3427..76ca90e56a 100644 --- a/src/swap_utils.h +++ b/src/swap_utils.h @@ -19,4 +19,8 @@ #include -bool parse_swap_config(const uint8_t* config, uint8_t config_len, char* ticker, uint8_t* decimals); +bool parse_swap_config(const uint8_t* config, + uint8_t config_len, + char* ticker, + uint8_t* decimals, + uint64_t* chain_id);