18
18
#include "commands_712.h"
19
19
#include "common_ui.h"
20
20
#include "uint_common.h"
21
+ #include "filtering.h"
21
22
22
23
#define AMOUNT_JOIN_FLAG_TOKEN (1 << 0)
23
24
#define AMOUNT_JOIN_FLAG_VALUE (1 << 1)
@@ -56,6 +57,8 @@ typedef struct {
56
57
uint8_t field_flags ;
57
58
uint8_t structs_to_review ;
58
59
s_amount_context amount ;
60
+ uint8_t filters_received ;
61
+ uint32_t filters_crc [MAX_FILTERS ];
59
62
#ifdef SCREEN_SIZE_WALLET
60
63
char ui_pairs_buffer [(SHARED_CTX_FIELD_1_SIZE + SHARED_CTX_FIELD_2_SIZE ) * 2 ];
61
64
#endif
@@ -617,12 +620,8 @@ void ui_712_end_sign(void) {
617
620
*/
618
621
bool ui_712_init (void ) {
619
622
if ((ui_ctx = MEM_ALLOC_AND_ALIGN_TYPE (* ui_ctx ))) {
620
- ui_ctx -> shown = false;
621
- ui_ctx -> end_reached = false;
623
+ explicit_bzero (ui_ctx , sizeof (* ui_ctx ));
622
624
ui_ctx -> filtering_mode = EIP712_FILTERING_BASIC ;
623
- explicit_bzero (& ui_ctx -> amount , sizeof (ui_ctx -> amount ));
624
- explicit_bzero (strings .tmp .tmp , sizeof (strings .tmp .tmp ));
625
- explicit_bzero (strings .tmp .tmp2 , sizeof (strings .tmp .tmp2 ));
626
625
} else {
627
626
apdu_response_code = APDU_RESPONSE_INSUFFICIENT_MEMORY ;
628
627
}
@@ -717,7 +716,7 @@ void ui_712_set_filters_count(uint8_t count) {
717
716
* @return number of filters
718
717
*/
719
718
uint8_t ui_712_remaining_filters (void ) {
720
- return ui_ctx -> filters_to_process ;
719
+ return ui_ctx -> filters_to_process - ui_ctx -> filters_received ;
721
720
}
722
721
723
722
/**
@@ -739,20 +738,16 @@ void ui_712_queue_struct_to_review(void) {
739
738
}
740
739
741
740
/**
742
- * Notify of a filter change from a path advance
741
+ * Increment the filters counter
743
742
*
744
- * This function figures out by itself if there is anything to do
745
- */
746
- void ui_712_notify_filter_change (void ) {
747
- if (path_get_root_type () == ROOT_MESSAGE ) {
748
- if (ui_ctx -> filtering_mode == EIP712_FILTERING_FULL ) {
749
- if (ui_ctx -> filters_to_process > 0 ) {
750
- if (ui_ctx -> field_flags & UI_712_FIELD_SHOWN ) {
751
- ui_ctx -> filters_to_process -= 1 ;
752
- }
753
- }
754
- }
743
+ * @return if the counter could be incremented
744
+ */
745
+ bool ui_712_filters_counter_incr (void ) {
746
+ if (ui_ctx -> filters_received > ui_ctx -> filters_to_process ) {
747
+ return false;
755
748
}
749
+ ui_ctx -> filters_received += 1 ;
750
+ return true;
756
751
}
757
752
758
753
void ui_712_token_join_prepare_addr_check (uint8_t index ) {
@@ -789,6 +784,26 @@ bool ui_712_show_raw_key(const void *field_ptr) {
789
784
return true;
790
785
}
791
786
787
+ /**
788
+ * Push a new filter path
789
+ *
790
+ * @return if the path was pushed or not (in case it was already present)
791
+ */
792
+ bool ui_712_push_new_filter_path (void ) {
793
+ uint32_t path_crc = get_path_crc ();
794
+
795
+ // check if already present
796
+ for (int i = 0 ; i < ui_ctx -> filters_received ; ++ i ) {
797
+ if (ui_ctx -> filters_crc [i ] == path_crc ) {
798
+ PRINTF ("EIP-712 path CRC (%x) already found at index %u!\n" , path_crc , i );
799
+ return false;
800
+ }
801
+ }
802
+ PRINTF ("Pushing new EIP-712 path CRC (%x) at index %u\n" , path_crc , ui_ctx -> filters_received );
803
+ ui_ctx -> filters_crc [ui_ctx -> filters_received ] = path_crc ;
804
+ return true;
805
+ }
806
+
792
807
#ifdef SCREEN_SIZE_WALLET
793
808
/*
794
809
* Get UI pairs buffer
0 commit comments