Now displays the field values
Show ints as uints for now
This commit is contained in:
@@ -57,6 +57,7 @@ bool field_hash(const uint8_t *data,
|
||||
if (IS_DYN(field_type))
|
||||
{
|
||||
cx_keccak_init(&global_sha3, 256); // init hash
|
||||
ui_712_new_field(field_ptr, data, data_length);
|
||||
}
|
||||
}
|
||||
fh->remaining_size -= data_length;
|
||||
@@ -113,6 +114,7 @@ bool field_hash(const uint8_t *data,
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ui_712_new_field(field_ptr, data, data_length);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -146,7 +148,6 @@ bool field_hash(const uint8_t *data,
|
||||
// deallocate it
|
||||
mem_dealloc(len);
|
||||
|
||||
ui_712_new_field(field_ptr, data, data_length);
|
||||
path_advance();
|
||||
fh->state = FHS_IDLE;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include "ui_flow_712.h"
|
||||
#include "shared_context.h"
|
||||
#include "eip712.h" // get_struct_name
|
||||
#include "ethUtils.h" // getEthDisplayableAddress
|
||||
#include "utils.h" // uint256_to_decimal
|
||||
|
||||
static t_ui_context *ui_ctx = NULL;
|
||||
|
||||
@@ -75,15 +77,62 @@ void ui_712_new_field(const void *const field_ptr, const uint8_t *const data,
|
||||
const char *key;
|
||||
uint8_t key_len;
|
||||
|
||||
// Key
|
||||
if ((key = get_struct_field_keyname(field_ptr, &key_len)) != NULL)
|
||||
{
|
||||
strncpy(strings.tmp.tmp2, key, MIN(key_len, sizeof(strings.tmp.tmp2) - 1));
|
||||
strings.tmp.tmp2[key_len] = '\0';
|
||||
}
|
||||
// TODO: Encode data as string based on data type
|
||||
(void)data;
|
||||
(void)length;
|
||||
strcpy(strings.tmp.tmp, "Field value");
|
||||
|
||||
// Value
|
||||
strings.tmp.tmp[0] = '\0'; // empty string
|
||||
switch (struct_field_type(field_ptr))
|
||||
{
|
||||
case TYPE_SOL_STRING:
|
||||
strncat(strings.tmp.tmp, (char*)data, sizeof(strings.tmp.tmp) - 1);
|
||||
if (length > (sizeof(strings.tmp.tmp) - 1))
|
||||
{
|
||||
strings.tmp.tmp[sizeof(strings.tmp.tmp) - 1 - 3] = '\0';
|
||||
strcat(strings.tmp.tmp, "...");
|
||||
}
|
||||
else
|
||||
{
|
||||
strings.tmp.tmp[length] = '\0';
|
||||
}
|
||||
break;
|
||||
case TYPE_SOL_ADDRESS:
|
||||
getEthDisplayableAddress((uint8_t*)data,
|
||||
strings.tmp.tmp,
|
||||
sizeof(strings.tmp.tmp),
|
||||
&global_sha3,
|
||||
chainConfig->chainId);
|
||||
break;
|
||||
case TYPE_SOL_BOOL:
|
||||
strcpy(strings.tmp.tmp, (*data == false) ? "false" : "true");
|
||||
break;
|
||||
case TYPE_SOL_BYTES_FIX:
|
||||
case TYPE_SOL_BYTES_DYN:
|
||||
snprintf(strings.tmp.tmp,
|
||||
sizeof(strings.tmp.tmp),
|
||||
"0x%.*H",
|
||||
length,
|
||||
data);
|
||||
// +2 for the "0x"
|
||||
// x2 for each byte value is represented by 2 ASCII characters
|
||||
if ((2 + (length * 2)) > (sizeof(strings.tmp.tmp) - 1))
|
||||
{
|
||||
strings.tmp.tmp[sizeof(strings.tmp.tmp) - 1 - 3] = '\0';
|
||||
strcat(strings.tmp.tmp, "...");
|
||||
}
|
||||
break;
|
||||
// TODO: signed integers should be handled differently
|
||||
case TYPE_SOL_INT:
|
||||
case TYPE_SOL_UINT:
|
||||
uint256_to_decimal(data, length, strings.tmp.tmp, sizeof(strings.tmp.tmp));
|
||||
break;
|
||||
default:
|
||||
PRINTF("Unhandled type\n");
|
||||
}
|
||||
ux_flow_prev();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user