New EIP-712 verbose in-app setting + small refactoring & naming unification

This commit is contained in:
Alexandre Paillier
2022-06-21 11:44:15 +02:00
parent b1f2e933c0
commit 8dcb4bc74f
2 changed files with 80 additions and 32 deletions

View File

@@ -27,6 +27,9 @@ typedef struct internalStorage_t {
unsigned char dataAllowed;
unsigned char contractDetails;
unsigned char displayNonce;
#ifdef HAVE_EIP712_FULL_SUPPORT
bool verbose_eip712;
#endif // HAVE_EIP712_FULL_SUPPORT
uint8_t initialized;
} internalStorage_t;

View File

@@ -5,6 +5,9 @@ void display_settings(const ux_flow_step_t* const start_step);
void switch_settings_blind_signing(void);
void switch_settings_display_data(void);
void switch_settings_display_nonce(void);
#ifdef HAVE_EIP712_FULL_SUPPORT
void switch_settings_verbose_eip712(void);
#endif // HAVE_EIP712_FULL_SUPPORT
//////////////////////////////////////////////////////////////////////
// clang-format off
@@ -52,7 +55,7 @@ UX_FLOW(ux_idle_flow,
// clang-format off
UX_STEP_CB(
ux_settings_flow_1_step,
ux_settings_flow_blind_signing_step,
bnnn_paging,
switch_settings_blind_signing(),
{
@@ -61,62 +64,76 @@ UX_STEP_CB(
});
UX_STEP_CB(
ux_settings_flow_2_step,
ux_settings_flow_display_data_step,
bnnn_paging,
switch_settings_display_data(),
{
.title = "Debug data",
.text = strings.common.fullAddress + 12
.text = strings.common.fullAddress + 9
});
UX_STEP_CB(
ux_settings_flow_3_step,
ux_settings_flow_display_nonce_step,
bnnn_paging,
switch_settings_display_nonce(),
{
.title = "Account nonce",
.text = strings.common.fullAddress + 26
.text = strings.common.fullAddress + 18
});
#else
UX_STEP_CB(
ux_settings_flow_1_step,
ux_settings_flow_blind_signing_step,
bnnn,
switch_settings_blind_signing(),
{
"Blind signing",
"Enable transaction",
"Transaction",
"blind signing",
strings.common.fullAddress,
});
UX_STEP_CB(
ux_settings_flow_2_step,
ux_settings_flow_display_data_step,
bnnn,
switch_settings_display_data(),
{
"Debug data",
"Display contract data",
"Show contract data",
"details",
strings.common.fullAddress + 12
strings.common.fullAddress + 9
});
UX_STEP_CB(
ux_settings_flow_3_step,
ux_settings_flow_display_nonce_step,
bnnn,
switch_settings_display_nonce(),
{
"Nonce",
"Display account nonce",
"Show account nonce",
"in transactions",
strings.common.fullAddress + 26
strings.common.fullAddress + 18
});
#endif
#ifdef HAVE_EIP712_FULL_SUPPORT
UX_STEP_CB(
ux_settings_flow_4_step,
ux_settings_flow_verbose_eip712_step,
bnnn,
switch_settings_verbose_eip712(),
{
"Verbose EIP-712",
"Ignore filtering &",
"display raw content",
strings.common.fullAddress + 27
});
#endif // HAVE_EIP712_FULL_SUPPORT
UX_STEP_CB(
ux_settings_flow_back_step,
pb,
ui_idle(),
{
@@ -126,40 +143,68 @@ UX_STEP_CB(
// clang-format on
UX_FLOW(ux_settings_flow,
&ux_settings_flow_1_step,
&ux_settings_flow_2_step,
&ux_settings_flow_3_step,
&ux_settings_flow_4_step);
&ux_settings_flow_blind_signing_step,
&ux_settings_flow_display_data_step,
&ux_settings_flow_display_nonce_step,
#ifdef HAVE_EIP712_FULL_SUPPORT
&ux_settings_flow_verbose_eip712_step,
#endif // HAVE_EIP712_FULL_SUPPORT
&ux_settings_flow_back_step);
void display_settings(const ux_flow_step_t* const start_step) {
strlcpy(strings.common.fullAddress, (N_storage.dataAllowed ? "Enabled" : "NOT Enabled"), 12);
strlcpy(strings.common.fullAddress + 12,
(N_storage.contractDetails ? "Displayed" : "NOT Displayed"),
26 - 12);
strlcpy(strings.common.fullAddress + 26,
(N_storage.displayNonce ? "Displayed" : "NOT Displayed"),
sizeof(strings.common.fullAddress) - 26);
const char *const values[] = {
"Enabled",
"Disabled"
};
bool settings[] = {
N_storage.dataAllowed,
N_storage.contractDetails,
N_storage.displayNonce,
#ifdef HAVE_EIP712_FULL_SUPPORT
N_storage.verbose_eip712
#endif // HAVE_EIP712_FULL_SUPPORT
};
uint8_t offset = 0;
uint8_t increment = MAX(strlen(values[0]), strlen(values[1])) + 1;
for (unsigned int i = 0; i < (sizeof(settings) / sizeof(settings[0])); ++i)
{
strlcpy(strings.common.fullAddress + offset,
(settings[i] ? values[0] : values[1]),
sizeof(strings.common.fullAddress) - offset);
offset += increment;
}
ux_flow_init(0, ux_settings_flow, start_step);
}
void switch_settings_blind_signing() {
void switch_settings_blind_signing(void) {
uint8_t value = (N_storage.dataAllowed ? 0 : 1);
nvm_write((void*) &N_storage.dataAllowed, (void*) &value, sizeof(uint8_t));
display_settings(&ux_settings_flow_1_step);
display_settings(&ux_settings_flow_blind_signing_step);
}
void switch_settings_display_data() {
void switch_settings_display_data(void) {
uint8_t value = (N_storage.contractDetails ? 0 : 1);
nvm_write((void*) &N_storage.contractDetails, (void*) &value, sizeof(uint8_t));
display_settings(&ux_settings_flow_2_step);
display_settings(&ux_settings_flow_display_data_step);
}
void switch_settings_display_nonce() {
void switch_settings_display_nonce(void) {
uint8_t value = (N_storage.displayNonce ? 0 : 1);
nvm_write((void*) &N_storage.displayNonce, (void*) &value, sizeof(uint8_t));
display_settings(&ux_settings_flow_3_step);
display_settings(&ux_settings_flow_display_nonce_step);
}
#ifdef HAVE_EIP712_FULL_SUPPORT
void switch_settings_verbose_eip712(void)
{
bool value = !N_storage.verbose_eip712;
nvm_write((void*) &N_storage.verbose_eip712, (void*) &value, sizeof(value));
display_settings(&ux_settings_flow_verbose_eip712_step);
}
#endif // HAVE_EIP712_FULL_SUPPORT
//////////////////////////////////////////////////////////////////////
// clang-format off
#if defined(TARGET_NANOS)
@@ -184,4 +229,4 @@ UX_STEP_CB(
#endif
// clang-format on
UX_FLOW(ux_warning_contract_data_flow, &ux_warning_contract_data_step);
UX_FLOW(ux_warning_contract_data_flow, &ux_warning_contract_data_step);