Files
app-ethereum/src/handle_get_printable_amount.c

48 lines
1.5 KiB
C
Raw Normal View History

2024-01-15 17:17:29 +01:00
#include <stdint.h>
#include <os.h>
#include "swap_utils.h"
2020-06-29 15:43:02 +02:00
#include "handle_get_printable_amount.h"
#include "shared_context.h"
2024-01-16 13:51:36 +01:00
#include "common_utils.h"
2020-06-29 15:43:02 +02:00
#include "uint256.h"
#include "string.h"
#include "network.h"
2020-06-29 15:43:02 +02:00
void handle_get_printable_amount(get_printable_amount_parameters_t* params,
chain_config_t* config) {
2020-06-29 15:43:02 +02:00
char ticker[MAX_TICKER_LEN];
uint8_t decimals;
uint64_t chain_id = 0;
2020-11-24 10:23:45 +01:00
memset(params->printable_amount, 0, sizeof(params->printable_amount));
2020-06-29 15:43:02 +02:00
if (params->amount_length > 32) {
PRINTF("Amount is too big, 32 bytes max but buffer has %u bytes", params->amount_length);
return;
2020-06-29 15:43:02 +02:00
}
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
2020-12-01 16:20:13 +01:00
if (params->is_fee) {
strlcpy(ticker, get_displayable_ticker(&chain_id, config), sizeof(ticker));
2020-06-29 15:43:02 +02:00
decimals = WEI_TO_ETHER;
}
if (!amountToString(params->amount,
params->amount_length,
decimals,
ticker,
params->printable_amount,
sizeof(params->printable_amount))) {
memset(params->printable_amount, 0, sizeof(params->printable_amount));
}
return;
2020-11-24 10:23:45 +01:00
}