From 559e729188c294a0cb27f77405ae96dc565a1bca Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Fri, 24 Jun 2022 18:12:55 +0200 Subject: [PATCH] Better UI for verbose EIP-712, now shows the review struct screen even on inner structures --- src_features/signMessageEIP712/field_hash.c | 1 - src_features/signMessageEIP712/path.c | 18 +++++++++++ src_features/signMessageEIP712/path.h | 1 + src_features/signMessageEIP712/ui_logic.c | 36 +++++++++++++++------ src_features/signMessageEIP712/ui_logic.h | 2 ++ 5 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src_features/signMessageEIP712/field_hash.c b/src_features/signMessageEIP712/field_hash.c index bcd8985..20398d4 100644 --- a/src_features/signMessageEIP712/field_hash.c +++ b/src_features/signMessageEIP712/field_hash.c @@ -15,7 +15,6 @@ static s_field_hashing *fh = NULL; - bool field_hash_init(void) { if (fh == NULL) diff --git a/src_features/signMessageEIP712/path.c b/src_features/signMessageEIP712/path.c index 485bb97..2639589 100644 --- a/src_features/signMessageEIP712/path.c +++ b/src_features/signMessageEIP712/path.c @@ -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; diff --git a/src_features/signMessageEIP712/path.h b/src_features/signMessageEIP712/path.h index ec8413f..ef43a2c 100644 --- a/src_features/signMessageEIP712/path.h +++ b/src_features/signMessageEIP712/path.h @@ -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 diff --git a/src_features/signMessageEIP712/ui_logic.c b/src_features/signMessageEIP712/ui_logic.c index 8a5b772..a260e31 100644 --- a/src_features/signMessageEIP712/ui_logic.c +++ b/src_features/signMessageEIP712/ui_logic.c @@ -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 diff --git a/src_features/signMessageEIP712/ui_logic.h b/src_features/signMessageEIP712/ui_logic.h index 27a840a..81a2779 100644 --- a/src_features/signMessageEIP712/ui_logic.h +++ b/src_features/signMessageEIP712/ui_logic.h @@ -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