diff --git a/app/src/apdu_sign.c b/app/src/apdu_sign.c index 93eedba17..7989a19d1 100644 --- a/app/src/apdu_sign.c +++ b/app/src/apdu_sign.c @@ -39,6 +39,7 @@ #include "globals.h" #include "handle_swap.h" #include "keys.h" +#include "num_parser.h" #include "ui_stream.h" #include "parser/parser_state.h" @@ -95,6 +96,26 @@ tz_ui_stream_push_accept_reject(void) } #endif +void tz_ui_stream_push_summary(void) +{ + FUNC_ENTER(("void")); + + tz_parser_state *st = &global.keys.apdu.sign.u.clear.parser_state; + tz_operation_state *op = &global.keys.apdu.sign.u.clear.parser_state.operation; + char *value = st->buffers.num.decimal; + snprintf(value, 32, "%d", op->batch_index); + tz_ui_stream_push(TZ_UI_STREAM_CB_NOCB, "Number of Tx", value, + TZ_UI_LAYOUT_BN, TZ_UI_ICON_NONE); + // get total_amount + tz_mutez_to_string(value, op->total_amount); + tz_ui_stream_push(TZ_UI_STREAM_CB_NOCB, "Total amount", value, + TZ_UI_LAYOUT_BN, TZ_UI_ICON_NONE); + + tz_mutez_to_string(value, op->total_fee); + tz_ui_stream_push(TZ_UI_STREAM_CB_NOCB, "Total fee", value, + TZ_UI_LAYOUT_BN, TZ_UI_ICON_NONE); +} + static void sign_packet(void) { @@ -230,6 +251,7 @@ static void refill_blo_done(void) { tz_parser_state *st = &global.keys.apdu.sign.u.clear.parser_state; + tz_operation_state *op = &global.keys.apdu.sign.u.clear.parser_state.operation; TZ_PREAMBLE(("void")); TZ_ASSERT( @@ -247,7 +269,9 @@ refill_blo_done(void) TZ_CHECK(sign_packet()); TZ_SUCCEED(); } - + if(op->batch_index > 1) { + tz_ui_stream_push_summary(); + } #ifdef HAVE_BAGL tz_ui_stream_push_accept_reject(); #endif diff --git a/app/src/parser/num_parser.c b/app/src/parser/num_parser.c index 67f41decf..190832d21 100644 --- a/app/src/parser/num_parser.c +++ b/app/src/parser/num_parser.c @@ -97,3 +97,62 @@ tz_string_to_mutez(const char *str, uint64_t *res) return true; } + + +bool tz_mutez_to_string(char *str, uint64_t microtez) { + if (str == NULL) { + return false; + } + + uint64_t integer_part = microtez / 1000000; + uint64_t decimal_part = microtez % 1000000; + + // Convert integer part to string + size_t i = 0; + if (integer_part == 0) { + str[i++] = '0'; + } else { + uint64_t temp = integer_part; + size_t int_len = 0; + while (temp > 0) { + temp /= 10; + int_len++; + } + for (size_t j = int_len; j > 0; j--) { + str[i + j - 1] = '0' + (integer_part % 10); + integer_part /= 10; + } + i += int_len; + } + + // Add decimal point + str[i++] = '.'; + + // Convert decimal part to string + size_t decimal_start = i; + for (size_t j = 0; j < 6; j++) { + str[i++] = '0' + (decimal_part / 100000); + decimal_part = (decimal_part % 100000) * 10; + } + + // Remove trailing zeros from the decimal part + while (i > decimal_start && str[i - 1] == '0') { + i--; + } + + // Remove decimal point if no decimal part + if (i > decimal_start && str[i - 1] == '.') { + i--; + } + + // Append " XTZ" + const char *xtz = " XTZ"; + for (size_t j = 0; xtz[j] != '\0'; j++) { + str[i++] = xtz[j]; + } + + // Null-terminate the string + str[i] = '\0'; + + return true; +} \ No newline at end of file diff --git a/app/src/parser/num_parser.h b/app/src/parser/num_parser.h index 9944e5d29..d03129ad1 100644 --- a/app/src/parser/num_parser.h +++ b/app/src/parser/num_parser.h @@ -71,3 +71,12 @@ tz_parser_result tz_parse_nat_step(tz_num_parser_buffer *buffers, * @return bool: success */ bool tz_string_to_mutez(const char *in, uint64_t *out); + +/** + * @brief format a mutez number to a string + * + * @param str: output string buffer + * @param microtez: input number + * @return bool: success + */ +bool tz_mutez_to_string( char *str, uint64_t microtez); \ No newline at end of file diff --git a/tests/integration/nano/snapshots/nanos/test_nanos_regression_batched_ops/00035.png b/tests/integration/nano/snapshots/nanos/test_nanos_regression_batched_ops/00035.png index 7e0e23820..7ccea318a 100644 Binary files a/tests/integration/nano/snapshots/nanos/test_nanos_regression_batched_ops/00035.png and b/tests/integration/nano/snapshots/nanos/test_nanos_regression_batched_ops/00035.png differ diff --git a/tests/integration/nano/snapshots/nanos/test_nanos_regression_batched_ops/00036.png b/tests/integration/nano/snapshots/nanos/test_nanos_regression_batched_ops/00036.png new file mode 100644 index 000000000..47ff01bc7 Binary files /dev/null and b/tests/integration/nano/snapshots/nanos/test_nanos_regression_batched_ops/00036.png differ diff --git a/tests/integration/nano/snapshots/nanos/test_nanos_regression_batched_ops/00037.png b/tests/integration/nano/snapshots/nanos/test_nanos_regression_batched_ops/00037.png new file mode 100644 index 000000000..ecc74530b Binary files /dev/null and b/tests/integration/nano/snapshots/nanos/test_nanos_regression_batched_ops/00037.png differ diff --git a/tests/integration/nano/snapshots/nanos/test_nanos_regression_batched_ops/00038.png b/tests/integration/nano/snapshots/nanos/test_nanos_regression_batched_ops/00038.png new file mode 100644 index 000000000..7e0e23820 Binary files /dev/null and b/tests/integration/nano/snapshots/nanos/test_nanos_regression_batched_ops/00038.png differ diff --git a/tests/integration/nano/snapshots/nanos/test_sign_batch_operation/00020.png b/tests/integration/nano/snapshots/nanos/test_sign_batch_operation/00020.png index 7e0e23820..7ccea318a 100644 Binary files a/tests/integration/nano/snapshots/nanos/test_sign_batch_operation/00020.png and b/tests/integration/nano/snapshots/nanos/test_sign_batch_operation/00020.png differ diff --git a/tests/integration/nano/snapshots/nanos/test_sign_batch_operation/00021.png b/tests/integration/nano/snapshots/nanos/test_sign_batch_operation/00021.png new file mode 100644 index 000000000..78ae701eb Binary files /dev/null and b/tests/integration/nano/snapshots/nanos/test_sign_batch_operation/00021.png differ diff --git a/tests/integration/nano/snapshots/nanos/test_sign_batch_operation/00022.png b/tests/integration/nano/snapshots/nanos/test_sign_batch_operation/00022.png new file mode 100644 index 000000000..a35ed878f Binary files /dev/null and b/tests/integration/nano/snapshots/nanos/test_sign_batch_operation/00022.png differ diff --git a/tests/integration/nano/snapshots/nanos/test_sign_batch_operation/00023.png b/tests/integration/nano/snapshots/nanos/test_sign_batch_operation/00023.png new file mode 100644 index 000000000..7e0e23820 Binary files /dev/null and b/tests/integration/nano/snapshots/nanos/test_sign_batch_operation/00023.png differ diff --git a/tests/integration/nano/snapshots/nanosp/test_sign_batch_operation/00016.png b/tests/integration/nano/snapshots/nanosp/test_sign_batch_operation/00016.png index 471324463..f64c947a1 100644 Binary files a/tests/integration/nano/snapshots/nanosp/test_sign_batch_operation/00016.png and b/tests/integration/nano/snapshots/nanosp/test_sign_batch_operation/00016.png differ diff --git a/tests/integration/nano/snapshots/nanosp/test_sign_batch_operation/00017.png b/tests/integration/nano/snapshots/nanosp/test_sign_batch_operation/00017.png new file mode 100644 index 000000000..7a48ac86a Binary files /dev/null and b/tests/integration/nano/snapshots/nanosp/test_sign_batch_operation/00017.png differ diff --git a/tests/integration/nano/snapshots/nanosp/test_sign_batch_operation/00018.png b/tests/integration/nano/snapshots/nanosp/test_sign_batch_operation/00018.png new file mode 100644 index 000000000..fed8af3aa Binary files /dev/null and b/tests/integration/nano/snapshots/nanosp/test_sign_batch_operation/00018.png differ diff --git a/tests/integration/nano/snapshots/nanosp/test_sign_batch_operation/00019.png b/tests/integration/nano/snapshots/nanosp/test_sign_batch_operation/00019.png new file mode 100644 index 000000000..471324463 Binary files /dev/null and b/tests/integration/nano/snapshots/nanosp/test_sign_batch_operation/00019.png differ diff --git a/tests/integration/nano/snapshots/nanox/test_nanox_regression_batched_ops/00019.png b/tests/integration/nano/snapshots/nanox/test_nanox_regression_batched_ops/00019.png index 471324463..f64c947a1 100644 Binary files a/tests/integration/nano/snapshots/nanox/test_nanox_regression_batched_ops/00019.png and b/tests/integration/nano/snapshots/nanox/test_nanox_regression_batched_ops/00019.png differ diff --git a/tests/integration/nano/snapshots/nanox/test_nanox_regression_batched_ops/00020.png b/tests/integration/nano/snapshots/nanox/test_nanox_regression_batched_ops/00020.png new file mode 100644 index 000000000..0331d3651 Binary files /dev/null and b/tests/integration/nano/snapshots/nanox/test_nanox_regression_batched_ops/00020.png differ diff --git a/tests/integration/nano/snapshots/nanox/test_nanox_regression_batched_ops/00021.png b/tests/integration/nano/snapshots/nanox/test_nanox_regression_batched_ops/00021.png new file mode 100644 index 000000000..7fbe12b3c Binary files /dev/null and b/tests/integration/nano/snapshots/nanox/test_nanox_regression_batched_ops/00021.png differ diff --git a/tests/integration/nano/snapshots/nanox/test_nanox_regression_batched_ops/00022.png b/tests/integration/nano/snapshots/nanox/test_nanox_regression_batched_ops/00022.png new file mode 100644 index 000000000..471324463 Binary files /dev/null and b/tests/integration/nano/snapshots/nanox/test_nanox_regression_batched_ops/00022.png differ diff --git a/tests/integration/nano/snapshots/nanox/test_sign_batch_operation/00016.png b/tests/integration/nano/snapshots/nanox/test_sign_batch_operation/00016.png index 471324463..f64c947a1 100644 Binary files a/tests/integration/nano/snapshots/nanox/test_sign_batch_operation/00016.png and b/tests/integration/nano/snapshots/nanox/test_sign_batch_operation/00016.png differ diff --git a/tests/integration/nano/snapshots/nanox/test_sign_batch_operation/00017.png b/tests/integration/nano/snapshots/nanox/test_sign_batch_operation/00017.png new file mode 100644 index 000000000..7a48ac86a Binary files /dev/null and b/tests/integration/nano/snapshots/nanox/test_sign_batch_operation/00017.png differ diff --git a/tests/integration/nano/snapshots/nanox/test_sign_batch_operation/00018.png b/tests/integration/nano/snapshots/nanox/test_sign_batch_operation/00018.png new file mode 100644 index 000000000..fed8af3aa Binary files /dev/null and b/tests/integration/nano/snapshots/nanox/test_sign_batch_operation/00018.png differ diff --git a/tests/integration/nano/snapshots/nanox/test_sign_batch_operation/00019.png b/tests/integration/nano/snapshots/nanox/test_sign_batch_operation/00019.png new file mode 100644 index 000000000..471324463 Binary files /dev/null and b/tests/integration/nano/snapshots/nanox/test_sign_batch_operation/00019.png differ