Skip to content

Commit af9cb39

Browse files
Merge pull request #1012 from LedgerHQ/feat/clickable_gcs_fields_of_unknown_token
Clickable GCS fields of unknown token
2 parents 32f1e9f + 301bcd0 commit af9cb39

41 files changed

Lines changed: 51 additions & 12 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/features/generic_tx_parser/gtp_param_token.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ bool format_param_token(const s_param_token *param, const char *name) {
7272
buf_shrink_expand(collec.value[i].ptr, collec.value[i].length, addr, sizeof(addr));
7373
if (match_native(addr, param)) {
7474
ticker = get_displayable_ticker(&chain_id, g_chain_config, true);
75-
} else if ((token_info = get_matching_token_info(&chain_id, addr))) {
75+
} else {
76+
if ((token_info = get_matching_token_info_or_dummy(&chain_id, addr)) == NULL) {
77+
ret = false;
78+
break;
79+
}
7680
ticker = token_info->ticker;
7781
}
7882
if (ticker == NULL) {

src/features/generic_tx_parser/gtp_param_token_amount.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,11 @@ static bool process_token_amount(const s_param_token_amount *param,
109109
ticker = get_displayable_ticker(&chain_id, g_chain_config, true);
110110
decimals = WEI_TO_ETHER;
111111
} else {
112-
if ((token_info = get_matching_token_info(&chain_id, addr_buf)) != NULL) {
113-
ticker = token_info->ticker;
114-
decimals = token_info->decimals;
112+
if ((token_info = get_matching_token_info_or_dummy(&chain_id, addr_buf)) == NULL) {
113+
return false;
115114
}
115+
ticker = token_info->ticker;
116+
decimals = token_info->decimals;
116117
}
117118
}
118119

src/features/provide_erc20_token_information/token_info.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "lists.h"
33
#include "app_mem_utils.h"
44
#include "token_info.h"
5+
#include "network.h"
56

67
typedef struct {
78
flist_node_t _list;
@@ -59,3 +60,24 @@ const s_token_info *get_matching_token_info(const uint64_t *chain_id, const uint
5960
}
6061
return NULL;
6162
}
63+
64+
const s_token_info *get_matching_token_info_or_dummy(const uint64_t *chain_id,
65+
const uint8_t *address) {
66+
const s_token_info *info_ptr;
67+
s_token_info info;
68+
69+
if ((chain_id == NULL) || (address == NULL)) {
70+
return NULL;
71+
}
72+
if ((info_ptr = get_matching_token_info(chain_id, address)) != NULL) {
73+
return info_ptr;
74+
}
75+
info.chain_id = *chain_id;
76+
memcpy(info.address, address, ADDRESS_LENGTH);
77+
strlcpy(info.ticker, g_unknown_ticker, sizeof(info.ticker));
78+
info.decimals = 0;
79+
if (set_token_info(&info) == -1) {
80+
return NULL;
81+
}
82+
return get_matching_token_info(chain_id, address);
83+
}

src/features/provide_erc20_token_information/token_info.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ typedef struct {
1515
int set_token_info(const s_token_info *info);
1616
void clear_token_infos(void);
1717
const s_token_info *get_matching_token_info(const uint64_t *chain_id, const uint8_t *address);
18+
const s_token_info *get_matching_token_info_or_dummy(const uint64_t *chain_id,
19+
const uint8_t *address);
3.07 KB
3.74 KB
4.39 KB
3.19 KB
2.05 KB
3.11 KB

0 commit comments

Comments
 (0)