Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion apps/inheritance_app/inheritance_auth_wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
#include "bip39.h"
#include "card_fetch_data.h"
#include "card_pair.h"
#include "constant_texts.h"
#include "core_error.h"
#include "inheritance/core.pb.h"
#include "inheritance_api.h"
#include "inheritance_priv.h"
#include "reconstruct_wallet_flow.h"
#include "status_api.h"
#include "ui_core_confirm.h"
#include "ui_delay.h"
/*****************************************************************************
* EXTERN VARIABLES
Expand Down Expand Up @@ -148,6 +150,49 @@ static bool auth_wallet_get_signature();
* STATIC FUNCTIONS
*****************************************************************************/

static bool check_which_request(const inheritance_query_t *query,
pb_size_t which_request) {
if (which_request != query->encrypt.which_request) {
inheritance_send_error(ERROR_COMMON_ERROR_CORRUPT_DATA_TAG,
ERROR_DATA_FLOW_INVALID_REQUEST);
return false;
}

return true;
}

STATIC bool auth_wallet_handle_inititate_query(inheritance_query_t *query) {
char wallet_name[NAME_SIZE] = "";
char msg[100] = "";

if (!check_which_request(query,
INHERITANCE_AUTH_WALLET_REQUEST_INITIATE_TAG)) {
return false;
}
if (get_wallet_name_by_id(query->auth_wallet.initiate.wallet_id,
(uint8_t *)wallet_name,
NULL)) {
snprintf(msg,
sizeof(msg),
ui_text_inheritance_wallet_auth_flow_confirmation,
wallet_name);

} else {
snprintf(msg,
sizeof(msg),
"%s",
ui_text_inheritance_wallet_auth_flow_confirmation_generic);
}

if (!core_confirmation(msg, inheritance_send_error)) {
return false;
}

// TODO: update flow status here

return true;
}

static bool verify_auth_wallet_inputs() {
if (auth->data.challenge_size == 0 ||
auth->data.challenge_size < CHALLENGE_SIZE_MIN ||
Expand Down Expand Up @@ -349,7 +394,8 @@ void inheritance_auth_wallet(inheritance_query_t *query) {
auth->do_wallet_based = query->auth_wallet.initiate.do_wallet_based;

set_app_flow_status(INHERITANCE_AUTH_WALLET_STATUS_INIT);
if (verify_auth_wallet_inputs() && auth_wallet_get_entropy() &&
if (verify_auth_wallet_inputs() &&
auth_wallet_handle_inititate_query(query) && auth_wallet_get_entropy() &&
auth_wallet_get_pairs() && auth_wallet_get_signature() && send_result()) {
delay_scr_init(ui_text_inheritance_wallet_auth_success, DELAY_TIME);
}
Expand Down
26 changes: 16 additions & 10 deletions apps/inheritance_app/inheritance_decrypt_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,23 @@ STATIC bool inheritance_handle_initiate_query(inheritance_query_t *query) {

if (!check_which_request(
query, INHERITANCE_DECRYPT_DATA_WITH_PIN_REQUEST_INITIATE_TAG) ||
!validate_request_data(&query->decrypt) ||
!get_wallet_name_by_id(query->decrypt.initiate.wallet_id,
(uint8_t *)wallet_name,
inheritance_send_error)) {
!validate_request_data(&query->decrypt)) {
return false;
}

snprintf(msg,
sizeof(msg),
ui_text_inheritance_decryption_flow_confirmation,
wallet_name);
if (get_wallet_name_by_id(
query->decrypt.initiate.wallet_id, (uint8_t *)wallet_name, NULL)) {
snprintf(msg,
sizeof(msg),
ui_text_inheritance_decryption_flow_confirmation,
wallet_name);

} else {
snprintf(msg,
sizeof(msg),
"%s",
ui_text_inheritance_decryption_flow_confirmation_generic);
}

if (!core_confirmation(msg, inheritance_send_error)) {
return false;
Expand Down Expand Up @@ -321,9 +327,9 @@ static bool show_data(void) {

if (tag == INHERITANCE_ONLY_SHOW_ON_DEVICE) {
if (!core_scroll_page(
UI_TEXT_VERIFY_MESSAGE,
UI_TEXT_PIN, ///< TODO: Figure out a way to make this generic
(const char *)&decryption_context->data[i]
.plain_data[3], ///> sizeof (tag) + sizeof (length) = 3
.plain_data[3], ///< sizeof (tag) + sizeof (length) = 3
inheritance_send_error)) {
return false;
}
Expand Down
7 changes: 4 additions & 3 deletions apps/inheritance_app/inheritance_encrypt_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,10 @@ STATIC bool inheritance_encryption_get_user_verification(void) {
&encryption_context->request_pointer->plain_data[i];

if (data->has_is_verified_on_device && data->is_verified_on_device) {
if (!core_scroll_page(UI_TEXT_VERIFY_MESSAGE,
(const char *)&data->message.bytes,
inheritance_send_error)) {
if (!core_scroll_non_sticky_heading_page(
UI_TEXT_VERIFY_MESSAGE,
(const char *)&data->message.bytes,
inheritance_send_error)) {
return false;
}
}
Expand Down
13 changes: 13 additions & 0 deletions common/core/ui_core_confirm.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "error.pb.h"
#include "events.h"
#include "ui_screens.h"
#include "ui_scroll_page.h"

/*****************************************************************************
* EXTERN VARIABLES
Expand Down Expand Up @@ -135,3 +136,15 @@ bool core_scroll_page(const char *title,
ui_scrollable_page(title, body, MENU_SCROLL_HORIZONTAL, false);
return wait_for_event(reject_cb);
}

// TODO: merge with above function
bool core_scroll_non_sticky_heading_page(const char *title,
const char *body,
ui_core_rejection_cb *reject_cb) {
scrollable_page_options_t options = {
.is_heading_sticky = false,
.are_cancel_accept_btn_visible = false,
.page_orientation = MENU_SCROLL_HORIZONTAL};
ui_scrollable_page_with_options(title, body, options);
return wait_for_event(reject_cb);
}
6 changes: 6 additions & 0 deletions common/core/ui_core_confirm.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,10 @@ bool core_scroll_page(const char *title,
const char *body,
ui_core_rejection_cb *reject_cb);

/**
* @brief Copy of above function, to be merged eventually.
*/
bool core_scroll_non_sticky_heading_page(const char *title,
const char *body,
ui_core_rejection_cb *reject_cb);
#endif
129 changes: 113 additions & 16 deletions common/interfaces/user_interface/ui_scroll_page.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
*/
#include "ui_scroll_page.h"

#include <stdint.h>

#include "stdlib.h"
#include "ui_events_priv.h"
#ifdef DEV_BUILD
Expand Down Expand Up @@ -238,6 +240,31 @@ static void page_update_buttons(void) {
return;
}

static void page_update_header(void) {
if (!gp_scrollabe_page_data->bool_only_first_page_header_visible) {
return;
}

ASSERT((NULL != gp_scrollabe_page_data) && (NULL != gp_scrollabe_page_lvgl));

bool is_heading_hidden = gp_scrollabe_page_data->curr_page_num != 1;

lv_coord_t scroll_page_height = 48;
lv_align_t scroll_page_aligment = LV_ALIGN_IN_TOP_MID;

if (!is_heading_hidden) {
scroll_page_height = 32;
scroll_page_aligment = LV_ALIGN_CENTER;
}

lv_obj_set_size(
gp_scrollabe_page_lvgl->p_ui_page_lvgl, 128, scroll_page_height);
lv_obj_align(
gp_scrollabe_page_lvgl->p_ui_page_lvgl, NULL, scroll_page_aligment, 0, 0);
lv_obj_set_hidden(gp_scrollabe_page_lvgl->p_ui_header_lvgl,
is_heading_hidden);
}

static void page_update_footnote(void) {
ASSERT((NULL != gp_scrollabe_page_data) && (NULL != gp_scrollabe_page_lvgl));

Expand All @@ -264,7 +291,6 @@ static void page_update_icons(void) {
page_update_arrows();
page_update_buttons();
page_update_footnote();

return;
}

Expand Down Expand Up @@ -400,10 +426,17 @@ static void page_arrow_handler(lv_obj_t *pLvglArrowObject,
LV_ALIGN_IN_TOP_MID,
0,
0);
page_update_header();
page_update_icons();
}
} else if (LV_KEY_LEFT == keyPressed) {
if (true == page_decrement()) {
/***
* We have to update header before calculating scroll distance
* other wise the current page height is decrease instead of previous
* page height
*/
page_update_header();
lv_label_set_style(gp_scrollabe_page_lvgl->p_ui_left_arrow_lvgl,
LV_LABEL_STYLE_MAIN,
&(gp_scrollabe_page_lvgl->ui_arrow_pressed_style));
Expand Down Expand Up @@ -443,8 +476,8 @@ static void page_arrow_handler(lv_obj_t *pLvglArrowObject,
}

case LV_EVENT_DELETE: {
/* Destruct object and data variables in case the object is being deleted
* directly using lv_obj_clean() */
/* Destruct object and data variables in case the object is being
* deleted directly using lv_obj_clean() */
ui_scrollable_destructor();
break;
}
Expand Down Expand Up @@ -514,9 +547,10 @@ static void ui_scrollable_page_create(void) {
* Create a label on page gp_scrollabe_page_lvgl->p_ui_page_lvgl which
* contains the body holding the actual text Size of the label is
* lv_page_get_fit_width(gp_scrollabe_page_lvgl->p_ui_page_lvgl) - 16,
* lv_page_get_fit_height(gp_scrollabe_page_lvgl->p_ui_page_lvgl) Text will be
* broken into multiple lines, but only 2 or 3 lines (32 pixels/ 48 pixels)
* are available on the page. So this creates a scrollable label on the page.
* lv_page_get_fit_height(gp_scrollabe_page_lvgl->p_ui_page_lvgl) Text will
* be broken into multiple lines, but only 2 or 3 lines (32 pixels/ 48
* pixels) are available on the page. So this creates a scrollable label on
* the page.
*/
gp_scrollabe_page_lvgl->p_ui_body_lvgl =
lv_label_create(gp_scrollabe_page_lvgl->p_ui_page_lvgl, NULL);
Expand Down Expand Up @@ -557,7 +591,8 @@ static void ui_scrollable_page_create(void) {

// Pad with \n if there are 2 rows of text and pad with \n\n if there are 3
// rows of text
if (32 == scroll_page_height) {
if (32 == scroll_page_height &&
!gp_scrollabe_page_data->bool_only_first_page_header_visible) {
lv_label_set_text(paddingLabel, "\n");
} else {
lv_label_set_text(paddingLabel, "\n\n");
Expand All @@ -581,9 +616,10 @@ static void ui_scrollable_page_create(void) {
lv_group_focus_obj(gp_scrollabe_page_lvgl->p_ui_body_lvgl);

/**
* Create a labels on current screen to hold the left and right arrows icons.
* These icons will be placed on the left and right side of the screen.
* These icons will be visible conditionally (if there is anything to scroll)
* Create a labels on current screen to hold the left and right arrows
* icons. These icons will be placed on the left and right side of the
* screen. These icons will be visible conditionally (if there is anything
* to scroll)
*/
/* TODO: Handle vertical scrolling input by processing page_orientation
* argument */
Expand Down Expand Up @@ -612,8 +648,8 @@ static void ui_scrollable_page_create(void) {
lv_style_copy(&(gp_scrollabe_page_lvgl->ui_arrow_released_style),
&lv_style_plain);

/* gp_scrollabe_page_lvgl->ui_arrow_pressed_style: This style will be drawn on
* the arrow if scrolling icon is pressed */
/* gp_scrollabe_page_lvgl->ui_arrow_pressed_style: This style will be drawn
* on the arrow if scrolling icon is pressed */
lv_style_copy(&(gp_scrollabe_page_lvgl->ui_arrow_pressed_style),
&lv_style_plain);
(gp_scrollabe_page_lvgl->ui_arrow_pressed_style).body.main_color =
Expand All @@ -627,9 +663,9 @@ static void ui_scrollable_page_create(void) {

/**
* Calculate the number of pages/max number of times full scrolling can take
* place Total number of scrolls = Total height of content on page / Height of
* page We have already padded the content on page with label paddingLabel and
* therefore we do not need to consider padding here
* place Total number of scrolls = Total height of content on page / Height
* of page We have already padded the content on page with label
* paddingLabel and therefore we do not need to consider padding here
*/
int16_t totalPageHeight =
(int16_t)lv_page_get_scrl_height(gp_scrollabe_page_lvgl->p_ui_page_lvgl);
Expand All @@ -639,6 +675,25 @@ static void ui_scrollable_page_create(void) {
gp_scrollabe_page_data->curr_page_num = 1;
gp_scrollabe_page_data->total_page_num = totalPageHeight / currPageHeight;

/**
* Recalculate the total pages if heading is only visible on the first page
*/
if (gp_scrollabe_page_data->bool_only_first_page_header_visible) {
gp_scrollabe_page_data->total_page_num = 1;
int16_t first_page_height = currPageHeight;

gp_scrollabe_page_data->curr_page_num = 2;
page_update_header();

int16_t curr_page_height =
(int16_t)lv_obj_get_height(gp_scrollabe_page_lvgl->p_ui_page_lvgl);
gp_scrollabe_page_data->total_page_num +=
(totalPageHeight - first_page_height) / curr_page_height;

gp_scrollabe_page_data->curr_page_num = 1;
page_update_header();
}

/**
* Create buttons on the screen for cancellation and confirmation.
* These buttons will be visible conditionally (if the current page is the
Expand Down Expand Up @@ -669,7 +724,8 @@ static void ui_scrollable_page_create(void) {
lv_label_create(lv_scr_act(), NULL);
}

/* Update all icons: Left/right arrows, Accept/Cancel buttons and Footnote */
/* Update all icons: Left/right arrows, Accept/Cancel buttons and Footnote
*/
page_update_icons();

return;
Expand Down Expand Up @@ -714,3 +770,44 @@ void ui_scrollable_page(const char *p_page_ui_heading,

return;
}

void ui_scrollable_page_with_options(const char *p_page_ui_heading,
const char *p_page_ui_body,
scrollable_page_options_t options) {
if (NULL == p_page_ui_body) {
return;
}

lv_obj_clean(lv_scr_act());

gp_scrollabe_page_data =
(scrolling_page_data_t *)malloc(sizeof(scrolling_page_data_t));
ASSERT(NULL != gp_scrollabe_page_data);

gp_scrollabe_page_data->p_ui_heading = p_page_ui_heading;
gp_scrollabe_page_data->p_ui_body = p_page_ui_body;
gp_scrollabe_page_data->bool_accept_cancel_visible =
options.are_cancel_accept_btn_visible;
gp_scrollabe_page_data->bool_only_first_page_header_visible =
!options.is_heading_sticky;

/* Below fields will be overwritten below, when page settings are being
* applied */
gp_scrollabe_page_data->total_page_num = 1;
gp_scrollabe_page_data->curr_page_num = 1;
gp_scrollabe_page_data->bool_left_arrow_hidden = true;
gp_scrollabe_page_data->bool_right_arrow_hidden = true;
gp_scrollabe_page_data->bool_accept_cancel_hidden = false;

ui_scrollable_page_create();

#ifdef DEV_BUILD
ekp_enqueue(LV_KEY_UP, DEFAULT_DELAY);
for (int i = 0; i < gp_scrollabe_page_data->total_page_num; i++)
ekp_enqueue(LV_KEY_RIGHT, DEFAULT_DELAY);
// ekp_enqueue(LV_KEY_DOWN,DEFAULT_DELAY);
ekp_enqueue(LV_KEY_ENTER, DEFAULT_DELAY);
#endif

return;
}
Loading
Loading