|
7 | 7 | #include "common_utils.h" |
8 | 8 | #include "uint256.h" |
9 | 9 | #include "string.h" |
| 10 | +#include "network.h" |
10 | 11 |
|
11 | 12 | void handle_get_printable_amount(get_printable_amount_parameters_t* params, |
12 | 13 | chain_config_t* config) { |
13 | | - uint8_t decimals; |
14 | 14 | char ticker[MAX_TICKER_LEN]; |
| 15 | + uint8_t decimals; |
| 16 | + uint64_t chain_id = 0; |
| 17 | + |
15 | 18 | memset(params->printable_amount, 0, sizeof(params->printable_amount)); |
16 | 19 | if (params->amount_length > 32) { |
17 | 20 | PRINTF("Amount is too big, 32 bytes max but buffer has %u bytes", params->amount_length); |
18 | 21 | return; |
19 | 22 | } |
20 | 23 |
|
21 | | - // If the amount is a fee, its value is nominated in ETH even if we're doing an ERC20 swap |
| 24 | + if (!parse_swap_config(params->coin_configuration, |
| 25 | + params->coin_configuration_length, |
| 26 | + ticker, |
| 27 | + &decimals, |
| 28 | + &chain_id)) { |
| 29 | + PRINTF("Error while parsing config\n"); |
| 30 | + return; |
| 31 | + } |
| 32 | + // If the amount is a fee, the ticker should be the chain's native currency |
22 | 33 | if (params->is_fee) { |
23 | | - uint8_t ticker_len = strnlen(config->coinName, sizeof(config->coinName)); |
24 | | - memcpy(ticker, config->coinName, ticker_len); |
25 | | - ticker[ticker_len] = '\0'; |
| 34 | + strlcpy(ticker, get_displayable_ticker(&chain_id, config), sizeof(ticker)); |
26 | 35 | decimals = WEI_TO_ETHER; |
27 | | - } else { |
28 | | - // If the amount is *not* a fee, decimals and ticker are built from the given config |
29 | | - if (!parse_swap_config(params->coin_configuration, |
30 | | - params->coin_configuration_length, |
31 | | - ticker, |
32 | | - &decimals)) { |
33 | | - PRINTF("Error while parsing config\n"); |
34 | | - return; |
35 | | - } |
36 | 36 | } |
37 | 37 |
|
38 | 38 | if (!amountToString(params->amount, |
|
0 commit comments