16
16
#include "typed_data.h"
17
17
#include "commands_712.h"
18
18
#include "common_ui.h"
19
+ #include "domain_name.h"
19
20
20
21
static t_ui_context * ui_ctx = NULL ;
21
22
@@ -184,6 +185,46 @@ static void ui_712_format_str(const uint8_t *const data, uint8_t length) {
184
185
}
185
186
}
186
187
188
+ /**
189
+ * Find a substitute token ticker for a given address
190
+ *
191
+ * @param[in] addr the given address
192
+ * @return the ticker name if found, \ref NULL otherwise
193
+ */
194
+ static const char * get_address_token_ticker (const uint8_t * addr ) {
195
+ tokenDefinition_t * token ;
196
+
197
+ // Loop over the received token informations
198
+ for (uint8_t token_idx = 0 ; token_idx < MAX_ITEMS ; ++ token_idx ) {
199
+ if (tmpCtx .transactionContext .tokenSet [token_idx ] == 1 ) {
200
+ token = & tmpCtx .transactionContext .extraInfo [token_idx ].token ;
201
+ if (memcmp (token -> address , addr , ADDRESS_LENGTH ) == 0 ) {
202
+ return token -> ticker ;
203
+ }
204
+ }
205
+ }
206
+ return NULL ;
207
+ }
208
+
209
+ /**
210
+ * Find a substitute (token ticker or domain name) for a given address
211
+ *
212
+ * @param[in] addr the given address
213
+ * @return the substitute if found, \ref NULL otherwise
214
+ */
215
+ static const char * get_address_substitute (const uint8_t * addr ) {
216
+ const char * str = NULL ;
217
+
218
+ str = get_address_token_ticker (addr );
219
+ if (str == NULL ) {
220
+ if (has_domain_name (& eip712_context -> chain_id , addr )) {
221
+ // No handling of the verbose domains setting
222
+ str = g_domain_name ;
223
+ }
224
+ }
225
+ return str ;
226
+ }
227
+
187
228
/**
188
229
* Format a given data as a string representation of an address
189
230
*
@@ -196,13 +237,20 @@ static bool ui_712_format_addr(const uint8_t *const data, uint8_t length) {
196
237
apdu_response_code = APDU_RESPONSE_INVALID_DATA ;
197
238
return false;
198
239
}
240
+
199
241
if (ui_712_field_shown ()) {
200
- if (!getEthDisplayableAddress ((uint8_t * ) data ,
201
- strings .tmp .tmp ,
202
- sizeof (strings .tmp .tmp ),
203
- & global_sha3 ,
204
- chainConfig -> chainId )) {
205
- THROW (APDU_RESPONSE_ERROR_NO_INFO );
242
+ const char * sub ;
243
+
244
+ if (!N_storage .verbose_eip712 && ((sub = get_address_substitute (data )) != NULL )) {
245
+ ui_712_set_value (sub , strlen (sub ));
246
+ } else {
247
+ if (!getEthDisplayableAddress ((uint8_t * ) data ,
248
+ strings .tmp .tmp ,
249
+ sizeof (strings .tmp .tmp ),
250
+ & global_sha3 ,
251
+ chainConfig -> chainId )) {
252
+ THROW (APDU_RESPONSE_ERROR_NO_INFO );
253
+ }
206
254
}
207
255
}
208
256
return true;
0 commit comments