Skip to content

Commit

Permalink
Add generic operation
Browse files Browse the repository at this point in the history
  • Loading branch information
abenso committed Jul 26, 2024
1 parent a69b91d commit f06768b
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 36 deletions.
6 changes: 5 additions & 1 deletion app/ui/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ void view_initialize_init(viewfunc_initialize_t viewFuncInit) {

void view_review_show(review_type_e reviewKind) {
// Set > 0 to reply apdu message
view_review_show_impl((unsigned int)reviewKind);
view_review_show_impl((unsigned int)reviewKind, NULL, NULL);
}

void view_review_show_with_title(review_type_e reviewKind, const char *title, const char *validate) {
view_review_show_impl((unsigned int)reviewKind, title, validate);
}

void view_initialize_show(uint8_t item_idx, const char *statusString) {
Expand Down
62 changes: 31 additions & 31 deletions app/ui/view.h
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
/*******************************************************************************
* (c) 2018 - 2022 Zondax AG
* (c) 2016 Ledger
*
* 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) 2018 - 2022 Zondax AG
* (c) 2016 Ledger
*
* 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 <stdbool.h>
#include <stdint.h>

#include "coin.h"
#include "zxerror.h"

#if defined(LEDGER_SPECIFIC)
#include "bolos_target.h"
#if defined(BOLOS_SDK)
#include "os.h"
#include "cx.h"
#include "os.h"
#endif
#endif

Expand All @@ -43,7 +44,6 @@
#define MENU_MAIN_APP_LINE2 "DO NOT USE"
#endif


typedef struct {
uint8_t displayIdx;
char *outKey;
Expand All @@ -61,7 +61,7 @@ typedef struct {
uint8_t pageCount;
} paging_t;

#define MAX_DEPTH 10
#define MAX_DEPTH 10
typedef struct {
uint8_t level;
uint8_t trace[MAX_DEPTH];
Expand All @@ -70,10 +70,8 @@ typedef struct {

typedef zxerr_t (*viewfunc_getNumItems_t)(uint8_t *num_items);

typedef zxerr_t (*viewfunc_getItem_t)(int8_t displayIdx,
char *outKey, uint16_t outKeyLen,
char *outVal, uint16_t outValLen,
uint8_t pageIdx, uint8_t *pageCount);
typedef zxerr_t (*viewfunc_getItem_t)(int8_t displayIdx, char *outKey, uint16_t outKeyLen, char *outVal,
uint16_t outValLen, uint8_t pageIdx, uint8_t *pageCount);

typedef zxerr_t (*viewfunc_getInnerItem_t)(uint8_t depth_level, uint8_t *trace, ui_field_t *ui_field);

Expand All @@ -84,10 +82,12 @@ typedef void (*viewfunc_accept_t)();
typedef zxerr_t (*viewfunc_initialize_t)();

typedef enum {
REVIEW_UI = 0,
REVIEW_ADDRESS,
REVIEW_TXN,
REVIEW_MSG,
REVIEW_UI = 0,
REVIEW_ADDRESS,
// Used to review keys or params that needs user confirmation before send the response
REVIEW_GENERIC,
REVIEW_TXN,
REVIEW_MSG,
} review_type_e;

#ifdef APP_SECRET_MODE_ENABLED
Expand All @@ -111,12 +111,12 @@ void view_error_show();

void view_custom_error_show(const char *upper, const char *lower);

void view_review_init(viewfunc_getItem_t viewfuncGetItem,
viewfunc_getNumItems_t viewfuncGetNumItems,
void view_review_init(viewfunc_getItem_t viewfuncGetItem, viewfunc_getNumItems_t viewfuncGetNumItems,
viewfunc_accept_t viewfuncAccept);

void view_inspect_init(viewfunc_getInnerItem_t view_funcGetInnerItem,
viewfunc_getNumItems_t view_funcGetInnerNumItems,
viewfunc_canInspectItem_t view_funcCanInspectItem);
void view_inspect_init(viewfunc_getInnerItem_t view_funcGetInnerItem, viewfunc_getNumItems_t view_funcGetInnerNumItems,
viewfunc_canInspectItem_t view_funcCanInspectItem);

void view_review_show(review_type_e reviewKind);

void view_review_show_with_title(review_type_e reviewKind, const char *title, const char *validate);
5 changes: 4 additions & 1 deletion app/ui/view_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ static const char *shortcut_value = SHORTCUT_VALUE;
#define INTRO_PAGES 0
#endif

#undef NB_MAX_DISPLAYED_PAIRS_IN_REVIEW
#define NB_MAX_DISPLAYED_PAIRS_IN_REVIEW 5

typedef struct {
struct {
#if defined(TARGET_STAX) || defined(TARGET_FLEX)
Expand Down Expand Up @@ -163,7 +166,7 @@ void h_paging_init();

void h_inspect_init();

void view_review_show_impl(unsigned int requireReply);
void view_review_show_impl(unsigned int requireReply, const char *title, const char *validate);

void view_inspect_show_impl();

Expand Down
1 change: 1 addition & 0 deletions app/ui/view_nano.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ zxerr_t h_review_update_data() {
intro_value = PIC(review_addrvalue);
break;

case REVIEW_GENERIC:
case REVIEW_TXN:
default:
intro_value = PIC(review_txvalue);
Expand Down
39 changes: 38 additions & 1 deletion app/ui/view_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ zxerr_t account_enabled();
#endif

#define APPROVE_LABEL_NBGL "Sign transaction?"
#define APPROVE_LABEL_NBGL_GENERIC "Accept operation?"
#define CANCEL_LABEL "Cancel"
#define VERIFY_TITLE_LABEL_GENERIC "Verify operation"

static const char HOME_TEXT[] =
"This application enables\nsigning transactions on the\n" MENU_MAIN_APP_LINE1 " network";
Expand Down Expand Up @@ -112,6 +114,19 @@ static void reviewTransactionChoice(bool confirm) {
}
}

static void reviewGenericChoice(bool confirm) {
const char *msg = "Operation rejected";
bool isSuccess = false;

if (confirm) {
msg = "Operation approved";
isSuccess = true;
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_SIGNED, h_approve_internal);
}

nbgl_useCaseStatus(msg, isSuccess, confirm ? h_approve_internal : h_reject_internal);
}

static void confirm_setting(bool confirm) {
if (confirm && viewdata.viewfuncAccept != NULL) {
viewdata.viewfuncAccept();
Expand Down Expand Up @@ -426,7 +441,25 @@ static void config_useCaseReview(nbgl_operationType_t type) {
NULL, APPROVE_LABEL_NBGL, reviewTransactionChoice);
}

void view_review_show_impl(unsigned int requireReply) {
static void config_useCaseReviewLight(const char *title, const char *validate) {
if (viewdata.viewfuncGetNumItems == NULL) {
ZEMU_LOGF(50, "GetNumItems==NULL\n")
view_error_show();
return;
}

pairList.nbMaxLinesForValue = NB_MAX_LINES_IN_REVIEW;
pairList.nbPairs = get_pair_number();
pairList.pairs = NULL; // to indicate that callback should be used
pairList.callback = update_item_callback;
pairList.startIndex = 0;

nbgl_useCaseReviewLight(TYPE_OPERATION, &pairList, &C_icon_stax_64,
(title == NULL ? VERIFY_TITLE_LABEL_GENERIC : title), NULL,
(validate == NULL ? APPROVE_LABEL_NBGL_GENERIC : validate), reviewGenericChoice);
}

void view_review_show_impl(unsigned int requireReply, const char *title, const char *validate) {
review_type = (review_type_e)requireReply;

// Retrieve intro text for transaction
Expand All @@ -451,6 +484,10 @@ void view_review_show_impl(unsigned int requireReply) {
config_useCaseAddressReview();
break;
}
case REVIEW_GENERIC: {
config_useCaseReviewLight(title, validate);
break;
}
case REVIEW_TXN:
default:
config_useCaseReview(TYPE_TRANSACTION);
Expand Down
4 changes: 3 additions & 1 deletion app/ui/view_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,9 @@ void h_secret_click() {
}
#endif

void view_review_show_impl(unsigned int requireReply) {
void view_review_show_impl(unsigned int requireReply, const char *title, const char *validate) {
UNUSED(title);
UNUSED(validate);
zemu_log_stack("view_review_show_impl");
review_type = requireReply;

Expand Down
5 changes: 4 additions & 1 deletion app/ui/view_x.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,9 @@ void view_initialize_show_impl(__Z_UNUSED uint8_t item_idx, const char *statusSt
ux_flow_init(0, ux_menu_initialize, NULL);
}

void view_review_show_impl(unsigned int requireReply){
void view_review_show_impl(unsigned int requireReply, const char *title, const char *validate){
UNUSED(title);
UNUSED(validate);
review_type = requireReply;
h_paging_init();
h_paging_decrease();
Expand Down Expand Up @@ -412,6 +414,7 @@ void run_ux_review_flow(review_type_e reviewType, const ux_flow_step_t* const st
ux_review_flow[index++] = &ux_review_flow_4_review_title;
break;

case REVIEW_GENERIC:
case REVIEW_TXN:
default:
ux_review_flow[index++] = &ux_review_flow_1_review_title;
Expand Down

0 comments on commit f06768b

Please sign in to comment.