Can now read a chain ID from the swap sub coin config

This commit is contained in:
Alexandre Paillier
2024-02-08 15:10:59 +01:00
parent c84794b257
commit 62d8b327d6
4 changed files with 46 additions and 22 deletions

View File

@@ -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,