@@ -67,7 +67,9 @@ void eth_plugin_prepare_query_contract_UI(ethQueryContractUI_t *queryContractUI,
|
||||
|
||||
queryContractUI->screenIndex = screenIndex;
|
||||
chain_id = get_tx_chain_id();
|
||||
strlcpy(queryContractUI->network_ticker, get_displayable_ticker(&chain_id), MAX_TICKER_LEN);
|
||||
strlcpy(queryContractUI->network_ticker,
|
||||
get_displayable_ticker(&chain_id, chainConfig),
|
||||
sizeof(queryContractUI->network_ticker));
|
||||
queryContractUI->title = title;
|
||||
queryContractUI->titleLength = titleLength;
|
||||
queryContractUI->msg = msg;
|
||||
|
||||
@@ -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 the amount is a fee, its value is nominated in ETH even if we're doing an ERC20 swap
|
||||
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, the ticker should be the chain's native currency
|
||||
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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -136,11 +136,11 @@ uint64_t get_tx_chain_id(void) {
|
||||
return chain_id;
|
||||
}
|
||||
|
||||
const char *get_displayable_ticker(const uint64_t *chain_id) {
|
||||
const char *get_displayable_ticker(const uint64_t *chain_id, const chain_config_t *chain_cfg) {
|
||||
const char *ticker = get_network_ticker_from_chain_id(chain_id);
|
||||
|
||||
if (ticker == NULL) {
|
||||
ticker = chainConfig->coinName;
|
||||
ticker = chain_cfg->coinName;
|
||||
}
|
||||
return ticker;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "chainConfig.h"
|
||||
|
||||
#define UNSUPPORTED_CHAIN_ID_MSG(id) \
|
||||
do { \
|
||||
@@ -16,4 +17,4 @@ bool app_compatible_with_chain_id(const uint64_t *chain_id);
|
||||
|
||||
uint64_t get_tx_chain_id(void);
|
||||
|
||||
const char *get_displayable_ticker(const uint64_t *chain_id);
|
||||
const char *get_displayable_ticker(const uint64_t *chain_id, const chain_config_t *chain_cfg);
|
||||
|
||||
@@ -22,22 +22,38 @@
|
||||
#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;
|
||||
}
|
||||
ticker_len = config[offset++];
|
||||
if (ticker_len == 0 || ticker_len > MAX_TICKER_LEN - 2 || config_len - offset < ticker_len) {
|
||||
ticker_len = config[offset];
|
||||
offset += sizeof(ticker_len);
|
||||
if ((ticker_len == 0) || (ticker_len > (MAX_TICKER_LEN - 2)) ||
|
||||
((config_len - offset) < (ticker_len))) {
|
||||
return false;
|
||||
}
|
||||
memcpy(ticker, config + offset, ticker_len);
|
||||
offset += ticker_len;
|
||||
ticker[ticker_len] = '\0';
|
||||
|
||||
if (config_len - offset < 1) {
|
||||
if ((config_len - offset) < 1) {
|
||||
return false;
|
||||
}
|
||||
*decimals = config[offset];
|
||||
offset += sizeof(*decimals);
|
||||
|
||||
// the chain ID was adder later to the CAL swap subconfig
|
||||
// so it is optional for retro-compatibility (as it might not be present)
|
||||
if ((config_len - offset) >= sizeof(*chain_id)) {
|
||||
PRINTF("Chain ID from the swap subconfig = 0x%.*h\n", sizeof(*chain_id), &config[offset]);
|
||||
*chain_id = u64_from_BE(config + offset, sizeof(*chain_id));
|
||||
offset += sizeof(*chain_id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -19,4 +19,8 @@
|
||||
|
||||
#include <stdint.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);
|
||||
|
||||
@@ -200,7 +200,7 @@ static void address_to_string(uint8_t *in,
|
||||
|
||||
static void raw_fee_to_string(uint256_t *rawFee, char *displayBuffer, uint32_t displayBufferSize) {
|
||||
uint64_t chain_id = get_tx_chain_id();
|
||||
const char *feeTicker = get_displayable_ticker(&chain_id);
|
||||
const char *feeTicker = get_displayable_ticker(&chain_id, chainConfig);
|
||||
uint8_t tickerOffset = 0;
|
||||
uint32_t i;
|
||||
|
||||
@@ -323,7 +323,7 @@ __attribute__((noinline)) static void finalize_parsing_helper(bool direct, bool
|
||||
char displayBuffer[50];
|
||||
uint8_t decimals = WEI_TO_ETHER;
|
||||
uint64_t chain_id = get_tx_chain_id();
|
||||
const char *ticker = get_displayable_ticker(&chain_id);
|
||||
const char *ticker = get_displayable_ticker(&chain_id, chainConfig);
|
||||
ethPluginFinalize_t pluginFinalize;
|
||||
|
||||
*use_standard_UI = true;
|
||||
|
||||
Reference in New Issue
Block a user