Better UI for verbose EIP-712, now shows the review struct screen even on inner structures

This commit is contained in:
Alexandre Paillier
2022-06-24 18:12:55 +02:00
parent 032d74e301
commit 559e729188
5 changed files with 47 additions and 11 deletions

View File

@@ -15,7 +15,6 @@
static s_field_hashing *fh = NULL;
bool field_hash_init(void)
{
if (fh == NULL)

View File

@@ -10,6 +10,7 @@
#include "shared_context.h"
#include "ethUtils.h"
#include "mem_utils.h"
#include "ui_logic.h"
static s_path *path_struct = NULL;
@@ -78,6 +79,22 @@ static inline const void *get_field_from_path(uint8_t *const fields_count)
return get_nth_field_from_path(fields_count, path_struct->depth_count);
}
const void *path_get_nth_struct_to_last(uint8_t n)
{
const char *typename;
uint8_t typename_len;
const void *field_ptr;
const void *struct_ptr = NULL;
field_ptr = get_nth_field_from_path(NULL, path_struct->depth_count - n);
if (field_ptr != NULL)
{
typename = get_struct_field_typename(field_ptr, &typename_len);
struct_ptr = get_structn(eip712_context->structs_array, typename, typename_len);
}
return struct_ptr;
}
/**
* Get the element the path is pointing to. (public facing)
*
@@ -306,6 +323,7 @@ static bool path_update(void)
// deallocate it
mem_dealloc(KECCAK256_HASH_BYTESIZE);
ui_712_queue_struct_to_review();
path_depth_list_push();
}
return true;

View File

@@ -39,6 +39,7 @@ void path_deinit(void);
bool path_new_array_depth(uint8_t size);
e_root_type path_get_root_type(void);
const void *path_get_root(void);
const void *path_get_nth_struct_to_last(uint8_t n);
#endif // HAVE_EIP712_FULL_SUPPORT

View File

@@ -130,24 +130,32 @@ void ui_712_next_field(void)
{
return;
}
if (!ui_ctx->end_reached)
if (ui_ctx->structs_to_review > 0)
{
// reply to previous APDU
G_io_apdu_buffer[0] = 0x90;
G_io_apdu_buffer[1] = 0x00;
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2);
ui_712_review_struct(path_get_nth_struct_to_last(ui_ctx->structs_to_review));
ui_ctx->structs_to_review -= 1;
}
else
{
if (ui_ctx->pos == UI_712_POS_REVIEW)
if (!ui_ctx->end_reached)
{
ux_flow_next();
ui_ctx->pos = UI_712_POS_END;
// reply to previous APDU
G_io_apdu_buffer[0] = 0x90;
G_io_apdu_buffer[1] = 0x00;
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2);
}
else
{
ux_flow_prev();
ui_ctx->pos = UI_712_POS_REVIEW;
if (ui_ctx->pos == UI_712_POS_REVIEW)
{
ux_flow_next();
ui_ctx->pos = UI_712_POS_END;
}
else
{
ux_flow_prev();
ui_ctx->pos = UI_712_POS_REVIEW;
}
}
}
}
@@ -415,4 +423,12 @@ void ui_712_field_flags_reset(void)
ui_ctx->field_flags = 0;
}
void ui_712_queue_struct_to_review(void)
{
if (N_storage.verbose_eip712)
{
ui_ctx->structs_to_review += 1;
}
}
#endif // HAVE_EIP712_FULL_SUPPORT

View File

@@ -28,6 +28,7 @@ typedef struct
e_ui_position pos;
uint8_t filtering_mode;
uint8_t field_flags;
uint8_t structs_to_review;
} t_ui_context;
bool ui_712_init(void);
@@ -47,6 +48,7 @@ void ui_712_field_flags_reset(void);
void ui_712_finalize_field(void);
void ui_712_set_filtering_mode(e_eip712_filtering_mode mode);
e_eip712_filtering_mode ui_712_get_filtering_mode(void);
void ui_712_queue_struct_to_review(void);
#endif // HAVE_EIP712_FULL_SUPPORT