Merge pull request #440 from LedgerHQ/fix/apa/stax_ui_changes

Stax UI fixes
This commit is contained in:
apaillier-ledger
2023-07-18 14:19:16 +02:00
committed by GitHub
33 changed files with 307 additions and 204 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 556 B

After

Width:  |  Height:  |  Size: 569 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 309 B

After

Width:  |  Height:  |  Size: 301 B

View File

@@ -7,7 +7,7 @@
static const uint8_t EIP_712_MAGIC[] = {0x19, 0x01};
unsigned int ui_712_approve_cb() {
unsigned int ui_712_approve_cb(void) {
uint8_t privateKeyData[INT256_LENGTH];
uint8_t hash[INT256_LENGTH];
uint8_t signature[100];
@@ -75,7 +75,7 @@ unsigned int ui_712_approve_cb() {
return 0; // do not redraw the widget
}
unsigned int ui_712_reject_cb() {
unsigned int ui_712_reject_cb(void) {
reset_app_context();
G_io_apdu_buffer[0] = 0x69;
G_io_apdu_buffer[1] = 0x85;

View File

@@ -1,48 +0,0 @@
#include "ui_nbgl.h"
#include "ui_712_common.h"
#include "common_712.h"
static void (*g_resume_func)(void) = NULL;
void nbgl_712_review_approve(void) {
ui_712_approve_cb(NULL);
}
void nbgl_712_review_reject(void) {
ui_712_reject_cb(NULL);
}
void nbgl_712_confirm_rejection_cb(bool confirm) {
if (confirm) {
nbgl_useCaseStatus("Message signing\ncancelled", false, nbgl_712_review_reject);
} else {
(*g_resume_func)();
}
}
void nbgl_712_confirm_rejection(void) {
nbgl_useCaseChoice(&C_warning64px,
"Reject message?",
NULL,
"Yes, reject",
"Go back to message",
nbgl_712_confirm_rejection_cb);
}
void nbgl_712_review_choice(bool confirm) {
if (confirm) {
nbgl_useCaseStatus("MESSAGE\nSIGNED", true, nbgl_712_review_approve);
} else {
nbgl_712_confirm_rejection();
}
}
void nbgl_712_start(void (*resume_func)(void), const char *title) {
g_resume_func = resume_func;
nbgl_useCaseReviewStart(&C_Message_64px,
title,
NULL,
"Reject",
resume_func,
nbgl_712_confirm_rejection);
}

View File

@@ -1,13 +0,0 @@
#ifndef UI_712_COMMON_H_
#define UI_712_COMMON_H_
#include <stdbool.h>
void nbgl_712_approve(void);
void nbgl_712_reject(void);
void nbgl_712_confirm_rejection_cb(bool confirm);
void nbgl_712_confirm_rejection(void);
void nbgl_712_review_choice(bool confirm);
void nbgl_712_start(void (*resume_func)(void), const char *title);
#endif // UI_712_COMMON_H_

View File

@@ -1,12 +1,14 @@
#include <ctype.h>
#include <nbgl_page.h>
#include "shared_context.h"
#include "ui_callbacks.h"
#include "ui_nbgl.h"
#include "ethUtils.h"
#include "ui_signing.h"
#include "plugins.h"
#include "domain_name.h"
#define TEXT_TX "transaction"
// 1 more than actually displayed on screen, because of calculations in StaticReview
#define MAX_PLUGIN_ITEMS_PER_SCREEN 4
#define TAG_MAX_LEN 43
@@ -51,10 +53,10 @@ static void onConfirmAbandon(void) {
}
static void rejectTransactionQuestion(void) {
nbgl_useCaseConfirm("Reject transaction?",
nbgl_useCaseConfirm(REJECT_QUESTION(TEXT_TX),
NULL,
"Yes, reject",
"Go back to transaction",
REJECT_CONFIRM_BUTTON,
RESUME(TEXT_TX),
onConfirmAbandon);
}
@@ -159,7 +161,7 @@ static void reviewContinue(void) {
.centeredInfo.text3 = NULL,
.centeredInfo.style = LARGE_CASE_INFO,
.centeredInfo.offsetY = -32,
.footerText = "Reject transaction",
.footerText = REJECT(TEXT_TX),
.footerToken = REJECT_TOKEN,
.tapActionText = "Tap to continue",
.tapActionToken = START_REVIEW_TOKEN,
@@ -177,6 +179,22 @@ static void reviewContinue(void) {
}
}
static const nbgl_icon_details_t *get_tx_icon(void) {
const nbgl_icon_details_t *icon = NULL;
if (tx_approval_context.fromPlugin && (pluginType == EXTERNAL)) {
if (caller_app && caller_app->name) {
if ((strlen(strings.common.fullAddress) == strlen(caller_app->name)) &&
(strcmp(strings.common.fullAddress, caller_app->name) == 0)) {
icon = get_app_icon(true);
}
}
} else {
icon = get_app_icon(false);
}
return icon;
}
static void reviewContinueCommon(void) {
uint8_t nbPairs = 0;
@@ -210,33 +228,66 @@ static void reviewContinueCommon(void) {
useCaseTagValueList.nbPairs = nbPairs; ///< number of pairs in pairs array
useCaseTagValueList.smallCaseForValue = false;
useCaseTagValueList.wrapping = false;
infoLongPress.icon = get_app_icon(true);
infoLongPress.text = tx_approval_context.fromPlugin ? staxSharedBuffer : "Review transaction";
infoLongPress.longPressText = "Hold to sign";
nbgl_useCaseStaticReview(&useCaseTagValueList,
&infoLongPress,
"Reject transaction",
reviewChoice);
infoLongPress.icon = get_tx_icon();
infoLongPress.text = tx_approval_context.fromPlugin ? g_stax_shared_buffer : SIGN(TEXT_TX);
infoLongPress.longPressText = SIGN_BUTTON;
nbgl_useCaseStaticReview(&useCaseTagValueList, &infoLongPress, REJECT(TEXT_TX), reviewChoice);
}
// Replace "Review" by "Sign" and add questionmark
static void prepare_sign_text(void) {
uint8_t sign_length = strlen("Sign");
uint8_t review_length = strlen("Review");
memmove(g_stax_shared_buffer, "Sign", sign_length);
memmove(g_stax_shared_buffer + sign_length,
g_stax_shared_buffer + review_length,
strlen(g_stax_shared_buffer) - review_length + 1);
strlcat(g_stax_shared_buffer, "?", sizeof(g_stax_shared_buffer));
}
// Force operation to be lowercase
static void get_lowercase_operation(char *dst, size_t dst_len) {
const char *src = strings.common.fullAmount;
size_t idx;
for (idx = 0; (idx < dst_len - 1) && (src[idx] != '\0'); ++idx) {
dst[idx] = (char) tolower((int) src[idx]);
}
dst[idx] = '\0';
}
static void buildFirstPage(void) {
if (tx_approval_context.fromPlugin) {
char op_name[sizeof(strings.common.fullAmount)];
plugin_ui_get_id();
SPRINTF(staxSharedBuffer,
"Review %s\ntransaction:\n%s",
strings.common.fullAddress,
strings.common.fullAmount);
nbgl_useCaseReviewStart(get_app_icon(true),
staxSharedBuffer,
get_lowercase_operation(op_name, sizeof(op_name));
if (pluginType == EXTERNAL) {
snprintf(g_stax_shared_buffer,
sizeof(g_stax_shared_buffer),
"Review transaction\nto %s\non %s",
op_name,
strings.common.fullAddress);
} else {
snprintf(g_stax_shared_buffer,
sizeof(g_stax_shared_buffer),
"Review transaction\nto %s\n%s",
op_name,
strings.common.fullAddress);
}
nbgl_useCaseReviewStart(get_tx_icon(),
g_stax_shared_buffer,
NULL,
"Reject transaction",
REJECT(TEXT_TX),
reviewContinue,
rejectTransactionQuestion);
prepare_sign_text();
} else {
nbgl_useCaseReviewStart(get_app_icon(true),
"Review transaction",
nbgl_useCaseReviewStart(get_tx_icon(),
REVIEW(TEXT_TX),
NULL,
"Reject transaction",
REJECT(TEXT_TX),
reviewContinue,
rejectTransactionQuestion);
}

View File

@@ -1,4 +1,5 @@
#include "common_ui.h"
#include "ui_signing.h"
#include "ui_nbgl.h"
#include "network.h"
@@ -31,12 +32,12 @@ static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) {
content->tagValueList.nbPairs = 1;
content->tagValueList.pairs = (nbgl_layoutTagValue_t *) &pair;
} else if (page == 1) {
snprintf(staxSharedBuffer,
sizeof(staxSharedBuffer),
snprintf(g_stax_shared_buffer,
sizeof(g_stax_shared_buffer),
"Confirm %s",
(confirm_type == PARAMETER_CONFIRMATION) ? "parameter" : "selector");
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(true);
content->infoLongPress.text = staxSharedBuffer;
content->infoLongPress.text = g_stax_shared_buffer;
content->infoLongPress.longPressText = "Hold to confirm";
} else {
return false;
@@ -46,22 +47,27 @@ static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) {
}
static void reviewContinue(void) {
snprintf(staxSharedBuffer,
sizeof(staxSharedBuffer),
snprintf(g_stax_shared_buffer,
sizeof(g_stax_shared_buffer),
"Reject %s",
(confirm_type == PARAMETER_CONFIRMATION) ? "parameter" : "selector");
nbgl_useCaseRegularReview(0, 2, staxSharedBuffer, NULL, displayTransactionPage, reviewChoice);
nbgl_useCaseRegularReview(0,
2,
g_stax_shared_buffer,
NULL,
displayTransactionPage,
reviewChoice);
}
static void buildScreen(void) {
snprintf(staxSharedBuffer,
sizeof(staxSharedBuffer),
snprintf(g_stax_shared_buffer,
sizeof(g_stax_shared_buffer),
"Verify %s",
(confirm_type == PARAMETER_CONFIRMATION) ? "parameter" : "selector");
nbgl_useCaseReviewStart(get_app_icon(true),
staxSharedBuffer,
g_stax_shared_buffer,
NULL,
"Reject",
REJECT_BUTTON,
reviewContinue,
reviewReject);
}

View File

@@ -1,4 +1,5 @@
#include "common_ui.h"
#include "ui_signing.h"
#include "ui_nbgl.h"
#include "ui_callbacks.h"
#include "nbgl_use_case.h"
@@ -45,14 +46,14 @@ static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) {
}
static void reviewContinue(void) {
nbgl_useCaseRegularReview(0, 2, "Reject", NULL, displayTransactionPage, reviewChoice);
nbgl_useCaseRegularReview(0, 2, REJECT_BUTTON, NULL, displayTransactionPage, reviewChoice);
}
static void buildFirstPage(void) {
nbgl_useCaseReviewStart(get_app_icon(true),
review_string,
NULL,
"Reject",
REJECT_BUTTON,
reviewContinue,
reviewReject);
}

View File

@@ -5,7 +5,7 @@
#include "glyphs.h"
#include "network.h"
char staxSharedBuffer[SHARED_BUFFER_SIZE] = {0};
char g_stax_shared_buffer[SHARED_BUFFER_SIZE] = {0};
nbgl_page_t *pageContext;
#define FORMAT_PLUGIN "This app enables clear\nsigning transactions for\nthe %s dApp."
@@ -32,6 +32,9 @@ const nbgl_icon_details_t *get_app_icon(bool caller_icon) {
} else {
icon = &ICONGLYPH;
}
if (icon == NULL) {
PRINTF("%s(%s) returned NULL!\n", __func__, (caller_icon ? "true" : "false"));
}
return icon;
}
@@ -43,8 +46,8 @@ void ui_idle(void) {
app_name = caller_app->name;
if (caller_app->type == CALLER_TYPE_PLUGIN) {
snprintf(staxSharedBuffer, sizeof(staxSharedBuffer), FORMAT_PLUGIN, app_name);
tagline = staxSharedBuffer;
snprintf(g_stax_shared_buffer, sizeof(g_stax_shared_buffer), FORMAT_PLUGIN, app_name);
tagline = g_stax_shared_buffer;
}
} else { // Ethereum app
uint64_t mainnet_chain_id = ETHEREUM_MAINNET_CHAINID;

View File

@@ -0,0 +1,50 @@
#include "ui_nbgl.h"
#include "ui_signing.h"
#include "common_712.h"
#include "ui_message_signing.h"
#include "glyphs.h"
static void (*g_approved_func)(void) = NULL;
static void (*g_rejected_func)(void) = NULL;
static void ui_message_rejection_handler() {
nbgl_useCaseStatus("Message signing\ncancelled", false, g_rejected_func);
}
static void ui_message_confirm_rejection(void) {
nbgl_useCaseConfirm(REJECT_QUESTION(TEXT_MESSAGE),
NULL,
REJECT_CONFIRM_BUTTON,
RESUME(TEXT_MESSAGE),
ui_message_rejection_handler);
}
void ui_message_review_choice(bool confirm) {
if (confirm) {
nbgl_useCaseStatus("MESSAGE\nSIGNED", true, g_approved_func);
} else {
ui_message_confirm_rejection();
}
}
void ui_message_start(const char *title,
void (*start_func)(void),
void (*approved_func)(void),
void (*rejected_func)(void)) {
g_approved_func = approved_func;
g_rejected_func = rejected_func;
nbgl_useCaseReviewStart(&C_Message_64px,
title,
NULL,
REJECT_BUTTON,
start_func,
ui_message_confirm_rejection);
}
void ui_message_712_approved(void) {
ui_712_approve_cb();
}
void ui_message_712_rejected(void) {
ui_712_reject_cb();
}

View File

@@ -0,0 +1,20 @@
#ifndef UI_MESSAGE_SIGNING_H_
#define UI_MESSAGE_SIGNING_H_
#include <stdbool.h>
#define TEXT_MESSAGE "message"
#define TEXT_TYPED_MESSAGE "typed " TEXT_MESSAGE
#define TEXT_REVIEW_EIP712 REVIEW(TEXT_TYPED_MESSAGE)
#define TEXT_SIGN_EIP712 SIGN(TEXT_TYPED_MESSAGE)
void ui_message_review_choice(bool confirm);
void ui_message_start(const char *title,
void (*start_func)(void),
void (*approved_func)(void),
void (*rejected_func)(void));
void ui_message_712_approved(void);
void ui_message_712_rejected(void);
#endif // UI_MESSAGE_SIGNING_H_

View File

@@ -6,7 +6,7 @@
#include <shared_context.h>
#define SHARED_BUFFER_SIZE SHARED_CTX_FIELD_1_SIZE
extern char staxSharedBuffer[SHARED_BUFFER_SIZE];
extern char g_stax_shared_buffer[SHARED_BUFFER_SIZE];
extern nbgl_page_t* pageContext;

View File

@@ -24,6 +24,13 @@ static bool navCallback(uint8_t page, nbgl_pageContent_t* content) {
switch (page) {
case 0:
content->type = INFOS_LIST;
content->infosList.nbInfos = 2;
content->infosList.infoTypes = (const char**) infoTypes;
content->infosList.infoContents = (const char**) infoContents;
break;
case 1:
switches[index++] =
(nbgl_layoutSwitch_t){.initState = N_storage.dataAllowed ? ON_STATE : OFF_STATE,
.text = "Blind signing",
@@ -48,7 +55,7 @@ static bool navCallback(uint8_t page, nbgl_pageContent_t* content) {
content->switchesList.switches = (nbgl_layoutSwitch_t*) switches;
break;
case 1:
case 2:
switches[index++] =
(nbgl_layoutSwitch_t){.initState = N_storage.verbose_eip712 ? ON_STATE : OFF_STATE,
.text = "Verbose EIP712",
@@ -69,13 +76,6 @@ static bool navCallback(uint8_t page, nbgl_pageContent_t* content) {
content->switchesList.switches = (nbgl_layoutSwitch_t*) switches;
break;
case 2:
content->type = INFOS_LIST;
content->infosList.nbInfos = 2;
content->infosList.infoTypes = (const char**) infoTypes;
content->infosList.infoContents = (const char**) infoContents;
break;
default:
return false;
break;
@@ -116,5 +116,5 @@ static void controlsCallback(int token, uint8_t index) {
}
void ui_menu_settings(void) {
nbgl_useCaseSettings(APPNAME " settings", 0, 3, true, ui_idle, navCallback, controlsCallback);
nbgl_useCaseSettings(APPNAME " settings", 0, 3, false, ui_idle, navCallback, controlsCallback);
}

View File

@@ -6,15 +6,16 @@
#include "common_712.h"
#include "nbgl_use_case.h"
#include "network.h"
#include "ui_712_common.h"
#include "ui_message_signing.h"
#include "ui_signing.h"
static nbgl_layoutTagValue_t pair;
static bool display_sign_page(uint8_t page, nbgl_pageContent_t *content) {
(void) page;
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(true);
content->infoLongPress.text = "Sign typed message";
content->infoLongPress.longPressText = "Hold to sign";
content->infoLongPress.text = TEXT_SIGN_EIP712;
content->infoLongPress.longPressText = SIGN_BUTTON;
return true;
}
@@ -45,7 +46,8 @@ static bool display_review_page(uint8_t page, nbgl_pageContent_t *content) {
case 1:
switch (ui_712_next_field()) {
case EIP712_NO_MORE_FIELD:
return display_sign_page(page, content);
ui_712_switch_to_sign();
ret = true;
break;
case EIP712_FIELD_INCOMING:
case EIP712_FIELD_LATER:
@@ -62,18 +64,24 @@ static bool display_review_page(uint8_t page, nbgl_pageContent_t *content) {
}
static void handle_display(nbgl_navCallback_t cb) {
nbgl_useCaseRegularReview(0, 0, "Reject", NULL, cb, nbgl_712_review_choice);
nbgl_useCaseRegularReview(0, 0, REJECT_BUTTON, NULL, cb, ui_message_review_choice);
}
void ui_712_start(void) {
nbgl_712_start(&ui_712_switch_to_message, "Review typed message");
g_position = UI_SIGNING_POSITION_START;
ui_message_start(TEXT_REVIEW_EIP712,
&ui_712_switch_to_message,
&ui_message_712_approved,
&ui_message_712_rejected);
}
void ui_712_switch_to_message(void) {
g_position = UI_SIGNING_POSITION_REVIEW;
handle_display(display_review_page);
}
void ui_712_switch_to_sign(void) {
g_position = UI_SIGNING_POSITION_SIGN;
handle_display(display_sign_page);
}

View File

@@ -3,7 +3,8 @@
#include "common_712.h"
#include "network.h"
#include "ethUtils.h"
#include "ui_712_common.h"
#include "ui_message_signing.h"
#include "ui_signing.h"
static nbgl_layoutTagValue_t pairs[2];
@@ -32,9 +33,10 @@ static bool display_review_page(uint8_t page, nbgl_pageContent_t *content) {
content->tagValueList.nbMaxLinesForValue = 0;
content->tagValueList.pairs = (nbgl_layoutTagValue_t *) pairs;
} else if (page == 1) {
g_position = UI_SIGNING_POSITION_SIGN;
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(true);
content->infoLongPress.text = "Sign typed message";
content->infoLongPress.longPressText = "Hold to sign";
content->infoLongPress.text = TEXT_SIGN_EIP712;
content->infoLongPress.longPressText = SIGN_BUTTON;
} else {
return false;
}
@@ -42,10 +44,36 @@ static bool display_review_page(uint8_t page, nbgl_pageContent_t *content) {
return true;
}
static void display_review(void) {
uint8_t page;
switch (g_position) {
case UI_SIGNING_POSITION_REVIEW:
page = 0;
break;
case UI_SIGNING_POSITION_SIGN:
page = 1;
break;
default:
return; // should not happen
}
nbgl_useCaseRegularReview(page,
2,
REJECT_BUTTON,
NULL,
display_review_page,
ui_message_review_choice);
}
static void start_review(void) {
nbgl_useCaseRegularReview(0, 2, "Reject", NULL, display_review_page, nbgl_712_review_choice);
g_position = UI_SIGNING_POSITION_REVIEW;
display_review();
}
void ui_sign_712_v0(void) {
nbgl_712_start(&start_review, "Sign typed message");
g_position = UI_SIGNING_POSITION_START;
ui_message_start(TEXT_REVIEW_EIP712,
&start_review,
&ui_message_712_approved,
&ui_message_712_rejected);
}

View File

@@ -6,22 +6,24 @@
#include "glyphs.h"
#include "nbgl_use_case.h"
#include "common_ui.h"
#include "ui_message_signing.h"
#include "ui_signing.h"
#define TEXT_REVIEW_EIP191 REVIEW(TEXT_MESSAGE)
#define TEXT_SIGN_EIP191 SIGN(TEXT_MESSAGE)
typedef enum {
UI_191_NBGL_START_REVIEW_DISPLAYED = 0,
UI_191_NBGL_GO_TO_NEXT_CONTENT,
UI_191_NBGL_BACK_FROM_REJECT_CANCEL,
UI_191_NBGL_GO_TO_SIGN,
UI_191_NBGL_SIGN_DISPLAYED,
} e_ui_nbgl_191_state;
UI_191_ACTION_IDLE = 0,
UI_191_ACTION_ADVANCE_IN_MESSAGE,
UI_191_ACTION_GO_TO_SIGN
} e_ui_191_action;
static e_ui_191_action g_action;
static e_ui_nbgl_191_state state;
static e_ui_nbgl_191_state state_before_reject_cancel;
static bool skip_message;
static nbgl_layoutTagValue_t pair;
//
static uint32_t eip191MessageIdx = 0;
static uint32_t stringsTmpTmpIdx = 0;
@@ -37,25 +39,25 @@ static bool display_message(nbgl_pageContent_t *content) {
uint16_t len = 0;
bool reached;
if (state != UI_191_NBGL_BACK_FROM_REJECT_CANCEL) {
strncpy(staxSharedBuffer + eip191MessageIdx,
if (g_action == UI_191_ACTION_ADVANCE_IN_MESSAGE) {
strncpy(g_stax_shared_buffer + eip191MessageIdx,
strings.tmp.tmp + stringsTmpTmpIdx,
SHARED_BUFFER_SIZE - eip191MessageIdx);
reached = nbgl_getTextMaxLenInNbLines(BAGL_FONT_INTER_MEDIUM_32px,
(char *) staxSharedBuffer,
(char *) g_stax_shared_buffer,
SCREEN_WIDTH - (2 * BORDER_MARGIN),
9,
&len);
stringsTmpTmpIdx = len - eip191MessageIdx;
eip191MessageIdx = len;
staxSharedBuffer[eip191MessageIdx] = '\0';
g_stax_shared_buffer[eip191MessageIdx] = '\0';
if (!reached && eip191MessageIdx < SHARED_BUFFER_SIZE) {
stringsTmpTmpIdx = 0;
question_switcher();
if (state != UI_191_NBGL_GO_TO_SIGN) {
if (g_action != UI_191_ACTION_GO_TO_SIGN) {
return false;
}
} else if (reached || eip191MessageIdx == SHARED_BUFFER_SIZE) {
@@ -63,7 +65,7 @@ static bool display_message(nbgl_pageContent_t *content) {
}
}
pair.value = staxSharedBuffer;
pair.value = g_stax_shared_buffer;
pair.item = "Message";
content->type = TAG_VALUE_LIST;
content->tagValueList.nbPairs = 1;
@@ -72,13 +74,7 @@ static bool display_message(nbgl_pageContent_t *content) {
content->tagValueList.nbMaxLinesForValue = 9;
content->tagValueList.wrapping = false;
if (state == UI_191_NBGL_BACK_FROM_REJECT_CANCEL) {
// We come back from Reject screen.
// The previously displayed content must be redisplayed.
// Do not call question_switcher() to avoid replacing
// string.tmp.tmp content.
state = state_before_reject_cancel;
} else if (stringsTmpTmpIdx >= strlen(strings.tmp.tmp)) {
if ((g_action != UI_191_ACTION_IDLE) && (stringsTmpTmpIdx >= strlen(strings.tmp.tmp))) {
// Fetch the next content to display into strings.tmp.tmp buffer.
stringsTmpTmpIdx = 0;
question_switcher();
@@ -86,11 +82,17 @@ static bool display_message(nbgl_pageContent_t *content) {
return true;
}
static void display_sign(nbgl_pageContent_t *content) {
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = &C_Message_64px;
content->infoLongPress.text = "Sign Message?";
content->infoLongPress.longPressText = "Hold to sign";
state = UI_191_NBGL_SIGN_DISPLAYED;
static bool display_sign(nbgl_pageContent_t *content) {
bool ret = false;
if (g_position != UI_SIGNING_POSITION_SIGN) {
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = &C_Message_64px;
content->infoLongPress.text = TEXT_SIGN_EIP191;
content->infoLongPress.longPressText = SIGN_BUTTON;
g_position = UI_SIGNING_POSITION_SIGN;
ret = true;
}
return ret;
}
static bool nav_callback(uint8_t page, nbgl_pageContent_t *content) {
@@ -100,7 +102,7 @@ static bool nav_callback(uint8_t page, nbgl_pageContent_t *content) {
skip_message = true;
skip_rest_of_message();
}
if ((state != UI_191_NBGL_GO_TO_SIGN) && (state != UI_191_NBGL_SIGN_DISPLAYED)) {
if ((g_action != UI_191_ACTION_GO_TO_SIGN) && (g_position != UI_SIGNING_POSITION_SIGN)) {
if (skip_message) {
// do not refresh when this callback triggers after user validation
ret = false;
@@ -109,73 +111,37 @@ static bool nav_callback(uint8_t page, nbgl_pageContent_t *content) {
}
} else {
// the last page must contain a long press button
display_sign(content);
ret = display_sign(content);
}
return ret;
}
static void choice_callback(bool confirm) {
if (confirm) {
nbgl_useCaseStatus("MESSAGE\nSIGNED", true, sign_message);
sign_message();
}
}
static void continue_review(void) {
nbgl_useCaseForwardOnlyReview("Reject", NULL, nav_callback, choice_callback);
}
static void confirm_transaction_rejection_choice(bool confirm) {
if (confirm) {
reject_message();
} else {
// Go to previous screen accordingly
if (state == UI_191_NBGL_START_REVIEW_DISPLAYED) {
ui_191_start();
} else {
if (state != UI_191_NBGL_SIGN_DISPLAYED) {
state_before_reject_cancel = state;
state = UI_191_NBGL_BACK_FROM_REJECT_CANCEL;
}
continue_review();
}
}
}
static void confirm_transaction_rejection() {
nbgl_useCaseChoice(&C_warning64px,
"Reject message?",
NULL,
"Yes, Reject",
"Go back to message",
confirm_transaction_rejection_choice);
nbgl_useCaseForwardOnlyReview(REJECT_BUTTON, NULL, nav_callback, ui_message_review_choice);
}
void ui_191_start(void) {
state = UI_191_NBGL_START_REVIEW_DISPLAYED;
g_position = UI_SIGNING_POSITION_START;
skip_message = false;
eip191MessageIdx = 0;
stringsTmpTmpIdx = 0;
nbgl_useCaseReviewStart(&C_Message_64px,
"Review message",
NULL,
"Reject",
continue_review,
confirm_transaction_rejection);
ui_message_start(TEXT_REVIEW_EIP191, &ui_191_switch_to_message, &sign_message, &reject_message);
}
void ui_191_switch_to_message(void) {
g_position = UI_SIGNING_POSITION_REVIEW;
g_action = UI_191_ACTION_ADVANCE_IN_MESSAGE;
// No question mechanism on Stax:
// Message is already displayed
state = UI_191_NBGL_GO_TO_NEXT_CONTENT;
continue_review();
}
void ui_191_switch_to_sign(void) {
g_action = UI_191_ACTION_GO_TO_SIGN;
// Next nav_callback callback must display
// the hold to approve screen
state = UI_191_NBGL_GO_TO_SIGN;
if (skip_message) {
continue_review(); // to force screen refresh
}

3
src_nbgl/ui_signing.c Normal file
View File

@@ -0,0 +1,3 @@
#include "ui_signing.h"
e_ui_signing_position g_position;

21
src_nbgl/ui_signing.h Normal file
View File

@@ -0,0 +1,21 @@
#ifndef UI_SIGNING_H_
#define UI_SIGNING_H_
#define SIGN_BUTTON "Hold to sign"
#define REJECT_BUTTON "Reject"
#define SIGN(msg) "Sign " msg "?"
#define REVIEW(msg) "Review " msg
#define REJECT(msg) "Reject " msg
#define REJECT_QUESTION(msg) REJECT(msg) "?"
#define REJECT_CONFIRM_BUTTON "Yes, reject"
#define RESUME(msg) "Go back to " msg
typedef enum {
UI_SIGNING_POSITION_START = 0,
UI_SIGNING_POSITION_REVIEW,
UI_SIGNING_POSITION_SIGN
} e_ui_signing_position;
extern e_ui_signing_position g_position;
#endif // UI_SIGNING_H_

View File

@@ -1,4 +1,5 @@
#include "common_ui.h"
#include "ui_signing.h"
#include "ui_nbgl.h"
#include "ui_callbacks.h"
#include "nbgl_use_case.h"
@@ -39,7 +40,7 @@ static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) {
} else if (page == 1) {
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(false);
content->infoLongPress.text = "Review stark limit order";
content->infoLongPress.longPressText = "Hold to sign";
content->infoLongPress.longPressText = SIGN_BUTTON;
} else {
return false;
}
@@ -48,14 +49,14 @@ static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) {
}
static void reviewContinue(void) {
nbgl_useCaseRegularReview(0, 2, "Reject", NULL, displayTransactionPage, reviewChoice);
nbgl_useCaseRegularReview(0, 2, REJECT_BUTTON, NULL, displayTransactionPage, reviewChoice);
}
static void buildFirstPage(void) {
nbgl_useCaseReviewStart(get_app_icon(false),
"Review stark limit order",
NULL,
"Reject",
REJECT_BUTTON,
reviewContinue,
reviewReject);
}

View File

@@ -2,6 +2,7 @@
#include "shared_context.h"
#include "ui_callbacks.h"
#include "ui_nbgl.h"
#include "ui_signing.h"
#include "starkDisplayUtils.h"
#include "ethUtils.h"
#include "network.h"
@@ -84,7 +85,7 @@ static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) {
if (page == 2) {
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(false);
content->infoLongPress.text = "Review transaction";
content->infoLongPress.longPressText = "Hold to sign";
content->infoLongPress.longPressText = SIGN_BUTTON;
}
return false;
@@ -93,7 +94,7 @@ static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) {
static void reviewContinue(void) {
nbgl_useCaseRegularReview(0,
context.conditional ? 3 : 2,
"Reject",
REJECT_BUTTON,
NULL,
displayTransactionPage,
reviewChoice);
@@ -119,7 +120,7 @@ void ui_stark_transfer(bool selfTransfer, bool conditional) {
nbgl_useCaseReviewStart(get_app_icon(false),
"Review stark transaction",
subTitle,
"Reject",
REJECT_BUTTON,
reviewContinue,
reviewReject);
}

View File

@@ -1,5 +1,5 @@
#include "common_ui.h"
#include "ui_signing.h"
#include "ui_nbgl.h"
#include "ui_callbacks.h"
#include "nbgl_use_case.h"
@@ -42,7 +42,7 @@ static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) {
} else if (page == 1) {
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(false);
content->infoLongPress.text = "Unsafe Stark Sign";
content->infoLongPress.longPressText = "Hold to sign";
content->infoLongPress.longPressText = SIGN_BUTTON;
} else {
return false;
}
@@ -51,14 +51,14 @@ static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) {
}
static void reviewContinue(void) {
nbgl_useCaseRegularReview(0, 2, "Reject", NULL, displayTransactionPage, reviewChoice);
nbgl_useCaseRegularReview(0, 2, REJECT_BUTTON, NULL, displayTransactionPage, reviewChoice);
}
static void buildFirstPage(void) {
nbgl_useCaseReviewStart(get_app_icon(false),
"Unsafe Stark Sign",
NULL,
"Reject",
REJECT_BUTTON,
reviewContinue,
reviewReject);
}

View File

@@ -182,7 +182,11 @@ void erc20_plugin_call(int message, void *parameters) {
case ETH_PLUGIN_QUERY_CONTRACT_ID: {
ethQueryContractID_t *msg = (ethQueryContractID_t *) parameters;
#ifdef HAVE_NBGL
strlcpy(msg->name, "ERC20 token", msg->nameLength);
#else
strlcpy(msg->name, "Type", msg->nameLength);
#endif
strlcpy(msg->version, "Approve", msg->versionLength);
msg->result = ETH_PLUGIN_RESULT_OK;
} break;

View File

@@ -52,11 +52,12 @@ def settings_toggle(fw: Firmware, nav: Navigator, to_toggle: list[SettingID]):
moves += [NavInsID.BOTH_CLICK] # Back
else:
moves += [NavInsID.USE_CASE_HOME_SETTINGS]
moves += [NavInsID.USE_CASE_SETTINGS_NEXT]
for setting in settings:
setting_idx = settings.index(setting)
if (setting_idx > 0) and (setting_idx % settings_per_page) == 0:
moves += [NavInsID.USE_CASE_SETTINGS_NEXT]
if setting in to_toggle:
moves += [NavIns(NavInsID.TOUCH, get_setting_position(fw.device, setting))]
moves += [NavInsID.EXIT_HEADER_TAP]
moves += [NavInsID.USE_CASE_SETTINGS_MULTI_PAGE_EXIT]
nav.navigate(moves, screen_change_before_first_instruction=False)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB