Skip to content

Commit

Permalink
add global flag for blinsign required
Browse files Browse the repository at this point in the history
  • Loading branch information
chcmedeiros committed Nov 27, 2024
1 parent a2d4cca commit 5ebe5b2
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 33 deletions.
6 changes: 3 additions & 3 deletions app/ui/view_nano.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ uint8_t getIntroPages() {
}
#endif
#ifdef APP_BLINDSIGN_MODE_ENABLED
if (!app_mode_blindsign() || review_type != REVIEW_TXN) {
if (!app_mode_blindsign() || !app_mode_blindsign_required()) {
return 0;
}
#endif
Expand Down Expand Up @@ -183,7 +183,7 @@ zxerr_t h_review_update_data() {
snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, "Ok");
} else {
#if defined(APP_BLINDSIGN_MODE_ENABLED)
if (app_mode_blindsign() && review_type == REVIEW_TXN) {
if (app_mode_blindsign() && app_mode_blindsign_required()) {
snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, "%s %s", APPROVE_LABEL_1, APPROVE_LABEL_2);
} else {
snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, "%s", APPROVE_LABEL);
Expand Down Expand Up @@ -248,7 +248,7 @@ zxerr_t h_review_update_data() {
intro_key = PIC(shortcut_key);
intro_value = PIC(shortcut_value);
#elif defined(APP_BLINDSIGN_MODE_ENABLED)
if (app_mode_blindsign() && review_type == REVIEW_TXN) {
if (app_mode_blindsign() && app_mode_blindsign_required()) {
switch (viewdata.itemIdx) {
case 0:
intro_key = PIC(review_skip_key);
Expand Down
24 changes: 12 additions & 12 deletions app/ui/view_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,8 @@ void view_custom_error_show(const char *upper, const char *lower) {
}

void view_blindsign_error_show() {
nbgl_useCaseChoice(&C_Warning_64px,
"This message cannot\nbe clear-signed",
"Enable blind-signing in\nthe settings to sign\nthis transaction.",
"Exit", "", confirm_error);
nbgl_useCaseChoice(&C_Warning_64px, "This message cannot\nbe clear-signed",
"Enable blind-signing in\nthe settings to sign\nthis transaction.", "Exit", "", confirm_error);
}

void view_error_show_impl() {
Expand Down Expand Up @@ -306,7 +304,7 @@ static void settings_screen_callback(uint8_t index, nbgl_content_t *content) {
switches[ACCOUNT_MODE].subText = "";
switches[ACCOUNT_MODE].tuneId = TUNE_TAP_CASUAL;
switches[ACCOUNT_MODE].token = ACCOUNT_MODE_TOKEN;
}
}
#endif

#ifdef APP_SECRET_MODE_ENABLED
Expand Down Expand Up @@ -347,7 +345,8 @@ void view_idle_show_impl(__Z_UNUSED uint8_t item_idx, const char *statusString)
infoList.infoContents = INFO_VALUES_PAGE;
infoList.infoTypes = INFO_KEYS_PAGE;

nbgl_useCaseHomeAndSettings(MENU_MAIN_APP_LINE1, &C_icon_stax_64, home_text, INIT_HOME_PAGE, &settingContents, &infoList, NULL, app_quit);
nbgl_useCaseHomeAndSettings(MENU_MAIN_APP_LINE1, &C_icon_stax_64, home_text, INIT_HOME_PAGE, &settingContents,
&infoList, NULL, app_quit);
}

void view_message_impl(const char *title, const char *message) {
Expand Down Expand Up @@ -441,14 +440,15 @@ static void config_useCaseReview(nbgl_operationType_t type) {
pairList.pairs = NULL; // to indicate that callback should be used
pairList.callback = update_item_callback;
pairList.startIndex = 0;
if (app_mode_blindsign()) {
nbgl_useCaseReviewBlindSigning(type, &pairList, &C_icon_stax_64, (intro_message == NULL ? "Review transaction" : intro_message), NULL,
"Accept risk and sign transaction ?", NULL, reviewTransactionChoice);
if (app_mode_blindsign() && app_mode_blindsign_required()) {
nbgl_useCaseReviewBlindSigning(type, &pairList, &C_icon_stax_64,
(intro_message == NULL ? "Review transaction" : intro_message), NULL,
"Accept risk and sign transaction ?", NULL, reviewTransactionChoice);
} else {
nbgl_useCaseReview(type, &pairList, &C_icon_stax_64, (intro_message == NULL ? "Review transaction" : intro_message),
NULL, APPROVE_LABEL_NBGL, reviewTransactionChoice);
nbgl_useCaseReview(type, &pairList, &C_icon_stax_64,
(intro_message == NULL ? "Review transaction" : intro_message), NULL, APPROVE_LABEL_NBGL,
reviewTransactionChoice);
}

}

static void config_useCaseReviewLight(const char *title, const char *validate) {
Expand Down
4 changes: 2 additions & 2 deletions app/ui/view_x.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ void run_ux_review_flow(review_type_e reviewType, const ux_flow_step_t *const st
case REVIEW_TXN:
default:
#ifdef APP_BLINDSIGN_MODE_ENABLED
if (app_mode_blindsign()) {
if (app_mode_blindsign() && app_mode_blindsign_required()) {
ux_review_flow[index++] = &ux_approval_blind_signing_warning_step;
ux_review_flow[index++] = &ux_approval_blind_signing_message_step;
}
Expand All @@ -550,7 +550,7 @@ void run_ux_review_flow(review_type_e reviewType, const ux_flow_step_t *const st
ux_review_flow[index++] = &ux_review_flow_6_step;
} else {
#ifdef APP_BLINDSIGN_MODE_ENABLED
if (app_mode_blindsign() && reviewType == REVIEW_TXN) {
if (app_mode_blindsign() && app_mode_blindsign_required()) {
ux_review_flow[index++] = &ux_review_flow_3_step_blindsign;
} else {
ux_review_flow[index++] = &ux_review_flow_3_step;
Expand Down
35 changes: 19 additions & 16 deletions include/app_mode.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/*******************************************************************************
* (c) 2016 Ledger
* (c) 2018 Zondax GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
* (c) 2016 Ledger
* (c) 2018 Zondax GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
#pragma once
#include "zxmacros.h"
#include "stdbool.h"
#include "zxmacros.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -44,6 +44,9 @@ bool app_mode_blindsign();

void app_mode_set_blindsign(uint8_t val);

bool app_mode_blindsign_required();

void app_mode_set_blindsign_required(uint8_t val);
#ifdef __cplusplus
}
#endif
19 changes: 19 additions & 0 deletions src/app_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ typedef struct {
uint8_t expert;
uint8_t account;
uint8_t blindsign;
uint8_t blindsign_required;
} app_mode_persistent_t;

typedef struct {
Expand Down Expand Up @@ -52,6 +53,7 @@ void app_mode_set_expert(uint8_t val) {
mode.expert = val;
mode.account = N_appmode.account;
mode.blindsign = N_appmode.blindsign;
mode.blindsign_required = N_appmode.blindsign_required;
MEMCPY_NV((void *)PIC(&N_appmode_impl), (void *)&mode, sizeof(app_mode_persistent_t));
}

Expand All @@ -60,6 +62,7 @@ void app_mode_set_account(uint8_t val) {
mode.expert = N_appmode.expert;
mode.account = val;
mode.blindsign = N_appmode.blindsign;
mode.blindsign_required = N_appmode.blindsign_required;
MEMCPY_NV((void *)PIC(&N_appmode_impl), (void *)&mode, sizeof(app_mode_persistent_t));
}

Expand All @@ -70,9 +73,20 @@ void app_mode_set_blindsign(uint8_t val) {
mode.expert = N_appmode.expert;
mode.account = N_appmode.account;
mode.blindsign = val;
mode.blindsign_required = N_appmode.blindsign_required;
MEMCPY_NV((void *)PIC(&N_appmode_impl), (void *)&mode, sizeof(app_mode_persistent_t));
}

bool app_mode_blindsign_required() { return N_appmode.blindsign_required; }

void app_mode_set_blindsign_required(uint8_t val) {
app_mode_persistent_t mode;
mode.expert = N_appmode.expert;
mode.account = N_appmode.account;
mode.blindsign = N_appmode.blindsign;
mode.blindsign_required = val;
MEMCPY_NV((void *)PIC(&N_appmode_impl), (void *)&mode, sizeof(app_mode_persistent_t));
}
#else
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
Expand All @@ -85,6 +99,7 @@ void app_mode_reset() {
app_mode.expert = 0;
app_mode.account = 0;
app_mode.blindsign = 0;
app_mode.blindsign_required = 0;
app_mode_temporary.secret = 0;
app_mode_temporary.shortcut = 0;
}
Expand All @@ -101,6 +116,10 @@ bool app_mode_blindsign() { return app_mode.blindsign; }

void app_mode_set_blindsign(uint8_t val) { app_mode.blindsign = val; }

bool app_mode_blindsign_required() { return app_mode.blindsign_required; }

void app_mode_set_blindsign_required(uint8_t val) { app_mode.blindsign_required = val; }

//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 5ebe5b2

Please sign in to comment.