Skip to content

Commit

Permalink
Add summary page for batch transactions. Show total number of transac…
Browse files Browse the repository at this point in the history
…tions, total amount and total fee.
  • Loading branch information
ajinkyaraj-23 committed Aug 23, 2024
1 parent 5cdebc5 commit 1eea4cd
Show file tree
Hide file tree
Showing 23 changed files with 93 additions and 1 deletion.
26 changes: 25 additions & 1 deletion app/src/apdu_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down
59 changes: 59 additions & 0 deletions app/src/parser/num_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
9 changes: 9 additions & 0 deletions app/src/parser/num_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1eea4cd

Please sign in to comment.