Trusted name UI implementation
This commit is contained in:
+71
-33
@@ -7,13 +7,16 @@
|
||||
#define DISABLED_STR "Disabled"
|
||||
#define BUF_INCREMENT (MAX(strlen(ENABLED_STR), strlen(DISABLED_STR)) + 1)
|
||||
|
||||
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);
|
||||
static void display_settings(const ux_flow_step_t* const start_step);
|
||||
static void switch_settings_blind_signing(void);
|
||||
static void switch_settings_display_data(void);
|
||||
static void switch_settings_display_nonce(void);
|
||||
#ifdef HAVE_EIP712_FULL_SUPPORT
|
||||
void switch_settings_verbose_eip712(void);
|
||||
static void switch_settings_verbose_eip712(void);
|
||||
#endif // HAVE_EIP712_FULL_SUPPORT
|
||||
#ifdef HAVE_TRUSTED_NAME
|
||||
static void switch_settings_verbose_trusted_name(void);
|
||||
#endif // HAVE_TRUSTED_NAME
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// clang-format off
|
||||
@@ -75,7 +78,7 @@ UX_STEP_CB(
|
||||
"Transaction",
|
||||
"blind signing",
|
||||
#endif
|
||||
strings.common.fullAddress
|
||||
strings.common.fullAmount
|
||||
});
|
||||
|
||||
UX_STEP_CB(
|
||||
@@ -95,7 +98,7 @@ UX_STEP_CB(
|
||||
"Show contract data",
|
||||
"details",
|
||||
#endif
|
||||
strings.common.fullAddress + BUF_INCREMENT
|
||||
strings.common.fullAmount + BUF_INCREMENT
|
||||
});
|
||||
|
||||
UX_STEP_CB(
|
||||
@@ -115,9 +118,31 @@ UX_STEP_CB(
|
||||
"Show account nonce",
|
||||
"in transactions",
|
||||
#endif
|
||||
strings.common.fullAddress + (BUF_INCREMENT * 2)
|
||||
strings.common.fullAmount + (BUF_INCREMENT * 2)
|
||||
});
|
||||
|
||||
#ifdef HAVE_TRUSTED_NAME
|
||||
UX_STEP_CB(
|
||||
ux_settings_flow_verbose_trusted_name_step,
|
||||
#ifdef TARGET_NANOS
|
||||
bnnn_paging,
|
||||
#else
|
||||
bnnn,
|
||||
#endif
|
||||
switch_settings_verbose_trusted_name(),
|
||||
{
|
||||
#ifdef TARGET_NANOS
|
||||
.title = "Verbose ENS",
|
||||
.text =
|
||||
#else
|
||||
"Verbose ENS",
|
||||
"Show addresses",
|
||||
"alongside domains",
|
||||
#endif
|
||||
strings.common.fullAmount + (BUF_INCREMENT * 3)
|
||||
});
|
||||
#endif // HAVE_TRUSTED_NAME
|
||||
|
||||
#ifdef HAVE_EIP712_FULL_SUPPORT
|
||||
UX_STEP_CB(
|
||||
ux_settings_flow_verbose_eip712_step,
|
||||
@@ -127,7 +152,7 @@ UX_STEP_CB(
|
||||
"Verbose EIP-712",
|
||||
"Ignore filtering &",
|
||||
"display raw content",
|
||||
strings.common.fullAddress + (BUF_INCREMENT * 3)
|
||||
strings.common.fullAmount + (BUF_INCREMENT * 4)
|
||||
});
|
||||
#endif // HAVE_EIP712_FULL_SUPPORT
|
||||
|
||||
@@ -146,54 +171,67 @@ UX_FLOW(ux_settings_flow,
|
||||
&ux_settings_flow_blind_signing_step,
|
||||
&ux_settings_flow_display_data_step,
|
||||
&ux_settings_flow_display_nonce_step,
|
||||
#ifdef HAVE_TRUSTED_NAME
|
||||
&ux_settings_flow_verbose_trusted_name_step,
|
||||
#endif // HAVE_TRUSTED_NAME
|
||||
#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) {
|
||||
bool settings[] = {N_storage.dataAllowed,
|
||||
N_storage.contractDetails,
|
||||
N_storage.displayNonce,
|
||||
static void display_settings(const ux_flow_step_t* const start_step) {
|
||||
bool settings[] = {
|
||||
N_storage.dataAllowed,
|
||||
N_storage.contractDetails,
|
||||
N_storage.displayNonce,
|
||||
#ifdef HAVE_TRUSTED_NAME
|
||||
N_storage.verbose_trusted_name,
|
||||
#endif // HAVE_TRUSTED_NAME
|
||||
#ifdef HAVE_EIP712_FULL_SUPPORT
|
||||
N_storage.verbose_eip712
|
||||
N_storage.verbose_eip712,
|
||||
#endif // HAVE_EIP712_FULL_SUPPORT
|
||||
};
|
||||
uint8_t offset = 0;
|
||||
|
||||
for (unsigned int i = 0; i < ARRAY_SIZE(settings); ++i) {
|
||||
strlcpy(strings.common.fullAddress + offset,
|
||||
(settings[i] ? ENABLED_STR : DISABLED_STR),
|
||||
sizeof(strings.common.fullAddress) - offset);
|
||||
if ((sizeof(strings.common.fullAmount) - offset) >= BUF_INCREMENT) {
|
||||
strlcpy(strings.common.fullAmount + offset,
|
||||
(settings[i] ? ENABLED_STR : DISABLED_STR),
|
||||
BUF_INCREMENT);
|
||||
}
|
||||
offset += BUF_INCREMENT;
|
||||
}
|
||||
|
||||
ux_flow_init(0, ux_settings_flow, start_step);
|
||||
}
|
||||
|
||||
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_blind_signing_step);
|
||||
static void toggle_setting(volatile bool* setting, const ux_flow_step_t* ui_step) {
|
||||
bool value = !*setting;
|
||||
nvm_write((void*) setting, (void*) &value, sizeof(value));
|
||||
display_settings(ui_step);
|
||||
}
|
||||
|
||||
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_display_data_step);
|
||||
static void switch_settings_blind_signing(void) {
|
||||
toggle_setting(&N_storage.dataAllowed, &ux_settings_flow_blind_signing_step);
|
||||
}
|
||||
|
||||
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_display_nonce_step);
|
||||
static void switch_settings_display_data(void) {
|
||||
toggle_setting(&N_storage.contractDetails, &ux_settings_flow_display_data_step);
|
||||
}
|
||||
|
||||
static void switch_settings_display_nonce(void) {
|
||||
toggle_setting(&N_storage.displayNonce, &ux_settings_flow_display_nonce_step);
|
||||
}
|
||||
|
||||
#ifdef HAVE_TRUSTED_NAME
|
||||
static void switch_settings_verbose_trusted_name(void) {
|
||||
toggle_setting(&N_storage.verbose_trusted_name, &ux_settings_flow_verbose_trusted_name_step);
|
||||
}
|
||||
#endif // HAVE_TRUSTED_NAME
|
||||
|
||||
#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);
|
||||
static void switch_settings_verbose_eip712(void) {
|
||||
toggle_setting(&N_storage.verbose_eip712, &ux_settings_flow_verbose_eip712_step);
|
||||
}
|
||||
#endif // HAVE_EIP712_FULL_SUPPORT
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "ui_plugin.h"
|
||||
#include "common_ui.h"
|
||||
#include "plugins.h"
|
||||
#include "trusted_name.h"
|
||||
|
||||
// clang-format off
|
||||
UX_STEP_NOCB(
|
||||
@@ -199,6 +200,7 @@ UX_STEP_NOCB(ux_approval_blind_signing_warning_step,
|
||||
// clang-format on
|
||||
|
||||
const ux_flow_step_t *ux_approval_tx_flow[15];
|
||||
extern const ux_flow_step_t ux_trusted_name_step;
|
||||
|
||||
void ux_approve_tx(bool fromPlugin) {
|
||||
int step = 0;
|
||||
@@ -217,7 +219,19 @@ void ux_approve_tx(bool fromPlugin) {
|
||||
} else {
|
||||
// We're in a regular transaction, just show the amount and the address
|
||||
ux_approval_tx_flow[step++] = &ux_approval_amount_step;
|
||||
ux_approval_tx_flow[step++] = &ux_approval_address_step;
|
||||
#ifdef HAVE_TRUSTED_NAME
|
||||
uint64_t chain_id = get_chain_id();
|
||||
if (verify_trusted_name(&chain_id, tmpContent.txContent.destination)) {
|
||||
ux_approval_tx_flow[step++] = &ux_trusted_name_step;
|
||||
if (N_storage.verbose_trusted_name) {
|
||||
ux_approval_tx_flow[step++] = &ux_approval_address_step;
|
||||
}
|
||||
} else {
|
||||
#endif // HAVE_TRUSTED_NAME
|
||||
ux_approval_tx_flow[step++] = &ux_approval_address_step;
|
||||
#ifdef HAVE_TRUSTED_NAME
|
||||
}
|
||||
#endif // HAVE_TRUSTED_NAME
|
||||
}
|
||||
|
||||
if (N_storage.displayNonce) {
|
||||
@@ -235,4 +249,4 @@ void ux_approve_tx(bool fromPlugin) {
|
||||
ux_approval_tx_flow[step++] = FLOW_END_STEP;
|
||||
|
||||
ux_flow_init(0, ux_approval_tx_flow, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifdef HAVE_TRUSTED_NAME
|
||||
|
||||
#include "ux.h"
|
||||
#include "trusted_name.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// clang-format off
|
||||
UX_STEP_NOCB(
|
||||
ux_trusted_name_step,
|
||||
bnnn_paging,
|
||||
{
|
||||
.title = "Domain",
|
||||
.text = trusted_name
|
||||
});
|
||||
// clang-format on
|
||||
|
||||
#endif // HAVE_TRUSTED_NAME
|
||||
Reference in New Issue
Block a user