33 lines
1.2 KiB
C
33 lines
1.2 KiB
C
#include "handle_get_printable_amount.h"
|
|
#include "shared_context.h"
|
|
#include "ethUtils.h"
|
|
#include "utils.h"
|
|
#include "uint256.h"
|
|
#include "string.h"
|
|
#include <stdint.h>
|
|
|
|
|
|
void handle_get_printable_amount( get_printable_amount_parameters_t* params, chain_config_t *config) {
|
|
uint8_t decimals;
|
|
char ticker[MAX_TICKER_LEN];
|
|
os_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);
|
|
os_lib_end();
|
|
}
|
|
if(!parse_swap_config(params->coin_configuration, params->coin_configuration_length, ticker, &decimals)){
|
|
PRINTF("Error while parsing config\n");
|
|
os_lib_end();
|
|
}
|
|
|
|
// 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] = ' ';
|
|
ticker[ticker_len+1] = '\0';
|
|
decimals = WEI_TO_ETHER;
|
|
}
|
|
|
|
amountToString(params->amount, params->amount_length, decimals, ticker, params->printable_amount, sizeof(params->printable_amount));
|
|
} |