Skip to content

Commit f80e5db

Browse files
committed
add other way to display data
1 parent 7e6d22a commit f80e5db

7 files changed

Lines changed: 451 additions & 146 deletions

File tree

app/src/common/tx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ storage_t NV_CONST N_appdata_impl __attribute__((aligned(64)));
4444
#define N_appdata (*(NV_VOLATILE storage_t *)PIC(&N_appdata_impl))
4545
#endif
4646

47-
static parser_tx_t tx_obj;
48-
static parser_context_t ctx_parsed_tx;
47+
static parser_tx_t tx_obj = {0};
48+
static parser_context_t ctx_parsed_tx = {0};
4949

5050
void tx_initialize() {
5151
buffering_init(ram_buffer, sizeof(ram_buffer), (uint8_t *)N_appdata.buffer, sizeof(N_appdata.buffer));

app/src/parser_impl.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
#include "zxerror.h"
2222

2323
parser_error_t _read(parser_context_t *c, parser_tx_t *v) {
24-
UNUSED(c);
25-
24+
2625
CHECK_ERROR(merkle_proofs_read(c, v));
2726
CHECK_ERROR(unsigned_transaction_read(c, v));
2827

app/src/schema_display.c

Lines changed: 269 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,26 @@ parser_error_t schema_display_generic_by_index(parser_tx_t *txObj, uint32_t inde
580580
return parser_ok;
581581
}
582582

583+
parser_error_t add_navigate_up(parser_tx_t *txObj, uint8_t navigate_up_qty, uint16_t greater_than_indexes[],
584+
uint8_t greater_than_qty) {
585+
CHECK_INPUT(txObj);
586+
587+
for (uint8_t k = 0; k < navigate_up_qty; k++) {
588+
char local_title[100] = {0};
589+
uint16_t index_title_greater_than = greater_than_indexes[greater_than_qty - k - 1];
590+
MEMCPY(local_title, txObj->device_items.items[index_title_greater_than].title,
591+
strlen(txObj->device_items.items[index_title_greater_than].title));
592+
MEMCPY(txObj->device_items.items[txObj->device_items.qty].title, local_title, strlen(local_title));
593+
MEMCPY(txObj->device_items.items[txObj->device_items.qty].data, NAVIGATE_UP, strlen(NAVIGATE_UP));
594+
txObj->device_items.qty++;
595+
}
596+
return parser_ok;
597+
}
598+
583599
parser_error_t schema_create_device_items(parser_tx_t *txObj) {
584600
CHECK_INPUT(txObj);
585601

586-
uint8_t title_qty = 2;
602+
uint8_t title_qty = 1;
587603

588604
print_string("schema_create_device_items: ");
589605
print_u32("schema_create_device_items: ", txObj->ui_items.qty);
@@ -592,6 +608,10 @@ parser_error_t schema_create_device_items(parser_tx_t *txObj) {
592608
print_string(txObj->ui_items.items[i].data);
593609
}
594610

611+
uint8_t greater_than_qty = 0;
612+
uint16_t device_item_base = 0;
613+
bool use_navigate_up = false;
614+
uint16_t greater_than_indexes[MAX_ITEMS] = {0};
595615
for (uint32_t i = 0; i < txObj->ui_items.qty; i++) {
596616
if (txObj->device_items.qty > MAX_ITEMS - 1) {
597617
return parser_too_many_items;
@@ -613,23 +633,49 @@ parser_error_t schema_create_device_items(parser_tx_t *txObj) {
613633
MEMZERO(content_title, sizeof(content_title));
614634
CHECK_ERROR(create_item_title(j, j + title_qty, content_title, sizeof(content_title)));
615635
bool exists = false;
616-
for (uint16_t k = 0; k < txObj->device_items.qty; k++) {
636+
for (uint16_t k = device_item_base; k < txObj->device_items.qty; k++) {
617637
if (MEMCMP(txObj->device_items.items[k].title, content_title, strlen(content_title)) == 0) {
618638
exists = true;
619639
break;
620640
}
621641
}
622642
if (!exists && (j + title_qty < items_qty)) {
643+
if (greater_than_qty >= items_qty) {
644+
uint8_t navigate_up_qty = greater_than_qty - j;
645+
CHECK_ERROR(add_navigate_up(txObj, navigate_up_qty, greater_than_indexes, greater_than_qty));
646+
greater_than_qty -= navigate_up_qty;
647+
}
623648
MEMCPY(txObj->device_items.items[txObj->device_items.qty].title, content_title, strlen(content_title));
624649
MEMCPY(txObj->device_items.items[txObj->device_items.qty].data, PAGE_BREAK, strlen(PAGE_BREAK));
650+
use_navigate_up = true;
651+
greater_than_indexes[greater_than_qty] = txObj->device_items.qty;
652+
greater_than_qty++;
625653
txObj->device_items.qty++;
626654
}
627655
if (j + title_qty == items_qty) {
656+
if (greater_than_qty >= items_qty) {
657+
uint8_t navigate_up_qty = greater_than_qty - items_qty + 1;
658+
CHECK_ERROR(add_navigate_up(txObj, navigate_up_qty, greater_than_indexes, greater_than_qty));
659+
greater_than_qty -= navigate_up_qty;
660+
}
628661
MEMZERO(content_title, sizeof(content_title));
629662
CHECK_ERROR(create_item_title(j, items_qty, content_title, sizeof(content_title)));
630663
}
664+
if (greater_than_qty == 0 && use_navigate_up) {
665+
device_item_base = txObj->device_items.qty;
666+
use_navigate_up = false;
667+
}
631668
}
632669
} else {
670+
if (greater_than_qty > 0) {
671+
uint8_t navigate_up_qty = greater_than_qty - items_qty + 1;
672+
CHECK_ERROR(add_navigate_up(txObj, navigate_up_qty, greater_than_indexes, greater_than_qty));
673+
greater_than_qty -= navigate_up_qty;
674+
}
675+
if (greater_than_qty == 0 && use_navigate_up) {
676+
device_item_base = txObj->device_items.qty;
677+
use_navigate_up = false;
678+
}
633679
CHECK_ERROR(create_item_title(0, title_qty - 1, content_title, sizeof(content_title)));
634680
}
635681

@@ -639,6 +685,226 @@ parser_error_t schema_create_device_items(parser_tx_t *txObj) {
639685
txObj->device_items.qty++;
640686
}
641687

688+
print_string("\nSchema_create_device_items!!: ");
689+
for (uint8_t i = 0; i < txObj->device_items.qty; i++) {
690+
print_string(txObj->device_items.items[i].title);
691+
print_string(txObj->device_items.items[i].data);
692+
}
693+
694+
return parser_ok;
695+
}
696+
697+
parser_error_t schema_create_device_items_2(parser_tx_t *txObj) {
698+
CHECK_INPUT(txObj);
699+
700+
uint8_t title_qty = 1;
701+
702+
print_string("schema_create_device_items: ");
703+
print_u32("schema_create_device_items: ", txObj->ui_items.qty);
704+
for (uint32_t i = 0; i < txObj->ui_items.qty; i++) {
705+
print_string(txObj->ui_items.items[i].title);
706+
print_string(txObj->ui_items.items[i].data);
707+
}
708+
709+
uint8_t greater_than_qty = 0;
710+
uint16_t device_item_base = 0;
711+
bool use_navigate_up = false;
712+
uint16_t greater_than_indexes[MAX_ITEMS] = {0};
713+
for (uint32_t i = 0; i < txObj->ui_items.qty; i++) {
714+
if (txObj->device_items.qty > MAX_ITEMS - 1) {
715+
return parser_too_many_items;
716+
}
717+
718+
clear_item_title_buffer();
719+
init_item_title_buffer(txObj->ui_items.items[i].title);
720+
721+
uint8_t items_qty = 0;
722+
CHECK_ERROR(get_title_item_qty(&items_qty));
723+
if (items_qty == 0) {
724+
return parser_ui_item_title_empty;
725+
}
726+
print_u8("items_qty: ", items_qty);
727+
char content_title[100] = {0};
728+
char content_title_2[100] = {0};
729+
char* path_str = "\n[";
730+
if (items_qty > 1) {
731+
MEMZERO(content_title_2, sizeof(content_title_2));
732+
strncat(content_title_2, path_str, strlen(path_str));
733+
CHECK_ERROR(create_item_title(items_qty-1, items_qty, content_title, sizeof(content_title)));
734+
CHECK_ERROR(create_item_title(0, items_qty - 1, content_title_2 + strlen(path_str), sizeof(content_title_2) - strlen(path_str)));
735+
if (strlen(content_title) <= 1) {
736+
MEMZERO(content_title, sizeof(content_title));
737+
CHECK_ERROR(create_item_title(items_qty - 2, items_qty, content_title, sizeof(content_title)));
738+
strncat(content_title_2, path_str, strlen(path_str));
739+
CHECK_ERROR(create_item_title(0, items_qty - 2, content_title_2 + strlen(path_str), sizeof(content_title_2) - strlen(path_str)));
740+
}
741+
strncat(content_title_2, "]", 1);
742+
} else {
743+
CHECK_ERROR(create_item_title(items_qty-1, items_qty, content_title, sizeof(content_title)));
744+
MEMZERO(content_title_2, sizeof(content_title_2));
745+
}
746+
747+
char content_title_3[100] = {0};
748+
strncat(content_title_3, txObj->ui_items.items[i].data, strlen(txObj->ui_items.items[i].data));
749+
strncat(content_title_3, content_title_2, strlen(content_title_2));
750+
751+
MEMCPY(txObj->device_items.items[txObj->device_items.qty].title, content_title, strlen(content_title));
752+
MEMCPY(txObj->device_items.items[txObj->device_items.qty].data, content_title_3, strlen(content_title_3));
753+
txObj->device_items.qty++;
754+
}
755+
756+
print_string("\nSchema_create_device_items!!: ");
757+
for (uint8_t i = 0; i < txObj->device_items.qty; i++) {
758+
print_string(txObj->device_items.items[i].title);
759+
print_string(txObj->device_items.items[i].data);
760+
}
761+
762+
return parser_ok;
763+
}
764+
765+
parser_error_t test_schema_create_device_items() {
766+
parser_tx_t txObj = {0};
767+
768+
// uint8_t qty = 0;
769+
// char *title1 = "|deep1|deep2|value3|";
770+
// char *data1 = "10000";
771+
// MEMCPY(txObj.ui_items.items[qty].title, title1, strlen(title1));
772+
// MEMCPY(txObj.ui_items.items[qty].data, data1, strlen(data1));
773+
// qty++;
774+
775+
// char *title2 = "|deep1|deep2|deep3|deep4|deep5|value6|";
776+
// char *data2 = "20000";
777+
// MEMCPY(txObj.ui_items.items[qty].title, title2, strlen(title2));
778+
// MEMCPY(txObj.ui_items.items[qty].data, data2, strlen(data2));
779+
// qty++;
780+
781+
// char *title3 = "|deep1|deep2|deep3|deep4|value5|";
782+
// char *data3 = "30000";
783+
// MEMCPY(txObj.ui_items.items[qty].title, title3, strlen(title3));
784+
// MEMCPY(txObj.ui_items.items[qty].data, data3, strlen(data3));
785+
// qty++;
786+
787+
// char *title4 = "|value1|";
788+
// char *data4 = "40000";
789+
// MEMCPY(txObj.ui_items.items[qty].title, title4, strlen(title4));
790+
// MEMCPY(txObj.ui_items.items[qty].data, data4, strlen(data4));
791+
// qty++;
792+
793+
// char *title5 = "|deep1|deep2|deep3|deep4|deep5|value6|";
794+
// char *data5 = "20000";
795+
// MEMCPY(txObj.ui_items.items[qty].title, title5, strlen(title5));
796+
// MEMCPY(txObj.ui_items.items[qty].data, data5, strlen(data5));
797+
// qty++;
798+
799+
// char *title6 = "|value1|";
800+
// char *data6 = "60000";
801+
// MEMCPY(txObj.ui_items.items[qty].title, title6, strlen(title6));
802+
// MEMCPY(txObj.ui_items.items[qty].data, data6, strlen(data6));
803+
// qty++;
804+
805+
806+
807+
////////////////////////////////////////////////////////////////
808+
809+
810+
811+
// char *title1 = "|RegisterPaymaster|policy|default_payee_policy|Allow|max_fee|";
812+
// char *data1 = "10000";
813+
// MEMCPY(txObj.ui_items.items[qty].title, title1, strlen(title1));
814+
// MEMCPY(txObj.ui_items.items[qty].data, data1, strlen(data1));
815+
// qty++;
816+
817+
// char *title2 = "|RegisterPaymaster|policy|default_payee_policy|Allow|gas_limit|";
818+
// char *data2 = "None";
819+
// MEMCPY(txObj.ui_items.items[qty].title, title2, strlen(title2));
820+
// MEMCPY(txObj.ui_items.items[qty].data, data2, strlen(data2));
821+
// qty++;
822+
823+
// char *title3 = "|RegisterPaymaster|policy|default_payee_policy|Allow|max_gas_price|value|0|";
824+
// char *data3 = "2000";
825+
// MEMCPY(txObj.ui_items.items[qty].title, title3, strlen(title3));
826+
// MEMCPY(txObj.ui_items.items[qty].data, data3, strlen(data3));
827+
// qty++;
828+
829+
// char *title3_1 = "|RegisterPaymaster|policy|default_payee_policy|Allow|max_gas_price|value|1|";
830+
// char *data3_1 = "2000";
831+
// MEMCPY(txObj.ui_items.items[qty].title, title3_1, strlen(title3_1));
832+
// MEMCPY(txObj.ui_items.items[qty].data, data3_1, strlen(data3_1));
833+
// qty++;
834+
835+
// char *title4 = "|RegisterPaymaster|policy|default_payee_policy|Allow|transaction_limit|";
836+
// char *data4 = "50";
837+
// MEMCPY(txObj.ui_items.items[qty].title, title4, strlen(title4));
838+
// MEMCPY(txObj.ui_items.items[qty].data, data4, strlen(data4));
839+
// qty++;
840+
841+
// char *title5 = "|RegisterPaymaster|policy|payees|0|";
842+
// char *data5 = "sov1pv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skqm7ehv";
843+
// MEMCPY(txObj.ui_items.items[qty].title, title5, strlen(title5));
844+
// MEMCPY(txObj.ui_items.items[qty].data, data5, strlen(data5));
845+
// qty++;
846+
847+
// char *title6 = "|RegisterPaymaster|policy|payees|1|";
848+
// char *data6 = "Deny";
849+
// MEMCPY(txObj.ui_items.items[qty].title, title6, strlen(title6));
850+
// MEMCPY(txObj.ui_items.items[qty].data, data6, strlen(data6));
851+
// qty++;
852+
853+
// char *title8 = "|RegisterPaymaster|policy|authorized_sequencers|";
854+
// char *data8 = "All";
855+
// MEMCPY(txObj.ui_items.items[qty].title, title8, strlen(title8));
856+
// MEMCPY(txObj.ui_items.items[qty].data, data8, strlen(data8));
857+
// qty++;
858+
859+
// char *title9 = "|Max Fee|";
860+
// char *data9 = "100000000000";
861+
// MEMCPY(txObj.ui_items.items[qty].title, title9, strlen(title9));
862+
// MEMCPY(txObj.ui_items.items[qty].data, data9, strlen(data9));
863+
// qty++;
864+
865+
// char *title10 = "|Chain ID|";
866+
// char *data10 = "4321";
867+
// MEMCPY(txObj.ui_items.items[qty].title, title10, strlen(title10));
868+
// MEMCPY(txObj.ui_items.items[qty].data, data10, strlen(data10));
869+
// qty++;
870+
871+
////////////////////////////////////////////////////////////////
872+
873+
874+
uint8_t qty = 0;
875+
char *title1 = "|deep1|deep2|deep3|deep4|deep5|deep6|value7|";
876+
char *data1 = "10000";
877+
MEMCPY(txObj.ui_items.items[qty].title, title1, strlen(title1));
878+
MEMCPY(txObj.ui_items.items[qty].data, data1, strlen(data1));
879+
qty++;
880+
881+
char *title2 = "|deep1|deep2|deep3|deep4|value5|";
882+
char *data2 = "20000";
883+
MEMCPY(txObj.ui_items.items[qty].title, title2, strlen(title2));
884+
MEMCPY(txObj.ui_items.items[qty].data, data2, strlen(data2));
885+
qty++;
886+
887+
char *title4 = "|deep1|deep2|new_deep3|value4|";
888+
char *data4 = "40000";
889+
MEMCPY(txObj.ui_items.items[qty].title, title4, strlen(title4));
890+
MEMCPY(txObj.ui_items.items[qty].data, data4, strlen(data4));
891+
qty++;
892+
893+
char *title5 = "|deep1|deep2|new_deep3|value4_new|";
894+
char *data5 = "50000";
895+
MEMCPY(txObj.ui_items.items[qty].title, title5, strlen(title5));
896+
MEMCPY(txObj.ui_items.items[qty].data, data5, strlen(data5));
897+
qty++;
898+
899+
900+
char *title6 = "|deep1|deep2|value3|";
901+
char *data6 = "60000";
902+
MEMCPY(txObj.ui_items.items[qty].title, title6, strlen(title6));
903+
MEMCPY(txObj.ui_items.items[qty].data, data6, strlen(data6));
904+
qty++;
905+
906+
txObj.ui_items.qty = qty;
907+
CHECK_ERROR(schema_create_device_items_2(&txObj));
642908
return parser_ok;
643909
}
644910

@@ -658,6 +924,7 @@ parser_error_t schema_display(parser_tx_t *txObj, uint32_t start_index) {
658924
}
659925

660926
CHECK_ERROR(schema_create_device_items(txObj));
927+
// CHECK_ERROR(test_schema_create_device_items());
661928

662929
return parser_ok;
663930
}

app/src/txdefs/ui_txdef.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ extern "C" {
2121

2222
#include "common_txdef.h"
2323

24-
#define MAX_ITEMS 30
24+
#define MAX_ITEMS 32
2525
#define MAX_STRING_LENGTH 100
26+
#define MAX_TITLE_LENGTH 60
2627
#define U128_STR_MAX_LEN 40
2728
#define MAX_SEPARATOR_LENGTH 100
2829
#define SEPARATOR_TITLE_OPEN "|"
@@ -31,7 +32,7 @@ extern "C" {
3132
#define SEPARATOR_DATA_CLOSE "}"
3233
#define SEPARATOR_TITLE_DISPLAY "/"
3334
#define PAGE_BREAK ">"
34-
35+
#define NAVIGATE_UP "navigating back up"
3536
// Buffer to store item data for array or vector display
3637
typedef struct {
3738
bool initialized;

app/src/ui_item_manager.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ parser_error_t get_item_title(char *item_title, uint16_t item_title_len) {
7777
parser_error_t create_item_title(uint16_t index_start, uint16_t index_end, char *output, uint16_t output_len) {
7878
CHECK_INPUT(output);
7979

80-
MEMZERO(output, sizeof(output));
80+
MEMZERO(output, output_len);
8181
char content[100] = {0};
8282

8383
if (index_start >= index_end) {

0 commit comments

Comments
 (0)