Skip to content

Commit

Permalink
Merge pull request #105 from trilitech/emturner@review-wait-for-tap
Browse files Browse the repository at this point in the history
Stax: review operation splash screen must wait for tap to advance
  • Loading branch information
emturner authored Oct 31, 2023
2 parents ce88421 + 9133501 commit 4d514c4
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 69 deletions.
12 changes: 1 addition & 11 deletions app/src/apdu_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ static void handle_data_apdu_blind(command_t *);
#define PKT_IS_LAST(_cmd) ((_cmd)->p1 & P1_LAST_MARKER)
#define PKT_IS_FIRST(_cmd) (((_cmd)->p1 & ~P1_LAST_MARKER) == 0)

#define TZ_UI_STREAM_CB_CANCEL 0xf0

#define APDU_SIGN_ASSERT(_cond) TZ_ASSERT(EXC_UNEXPECTED_SIGN_STATE, (_cond))
#define APDU_SIGN_ASSERT_STEP(x) \
APDU_SIGN_ASSERT(global.apdu.sign.step == (x))
Expand Down Expand Up @@ -175,18 +173,10 @@ refill_error(void)
{
tz_parser_state *st = &global.apdu.sign.u.clear.parser_state;
TZ_PREAMBLE(("void"));
#ifdef HAVE_BAGL

tz_ui_stream_push(TZ_UI_STREAM_CB_CANCEL, "Parsing error",
tz_parser_result_name(st->errno), TZ_UI_ICON_CROSS);
#elif HAVE_NBGL
send_cancel();
global.step = ST_IDLE;
char error_message[50] = "Parsing error\n";
strlcat(error_message, tz_parser_result_name(st->errno),
sizeof(error_message));
nbgl_useCaseStatus(error_message, false, ui_home_init);
#endif

tz_ui_stream_close();
TZ_POSTAMBLE;
}
Expand Down
11 changes: 8 additions & 3 deletions app/src/ui_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ pred(void)
}
FUNC_LEAVE();
}
#endif // HAVE_BAGL

static void
succ(void)
Expand All @@ -237,7 +238,6 @@ succ(void)
}
FUNC_LEAVE();
}
#endif // HAVE_BAGL

// View

Expand Down Expand Up @@ -382,8 +382,9 @@ change_screen_left(void)
redisplay();
FUNC_LEAVE();
}
#endif // HAVE_BAGL

static void
void
change_screen_right(void)
{
tz_ui_stream_t *s = &global.stream;
Expand All @@ -393,18 +394,22 @@ change_screen_right(void)
if (s->current == s->total) {
if (!s->full)
s->cb(TZ_UI_STREAM_CB_REFILL);
#ifdef HAVE_BAGL
if (global.step == ST_ERROR) {
global.step = ST_IDLE;
ui_home_init();
return;
}
#endif
}
// go back to the data screen
succ();

#ifdef HAVE_BAGL
redisplay();
#endif
FUNC_LEAVE();
}
#endif // HAVE_BAGL

void
tz_ui_stream_start(void)
Expand Down
2 changes: 2 additions & 0 deletions app/src/ui_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ typedef uint8_t tz_ui_cb_type_t;
#define TZ_UI_STREAM_CB_NOCB 0x00
#define TZ_UI_STREAM_CB_REFILL 0xef
#define TZ_UI_STREAM_CB_MAINMASK 0xf0
#define TZ_UI_STREAM_CB_CANCEL 0xfd
#define TZ_UI_STREAM_CB_REJECT 0xfe
#define TZ_UI_STREAM_CB_ACCEPT 0xff

Expand Down Expand Up @@ -122,6 +123,7 @@ typedef struct {
#ifdef HAVE_NBGL
tz_ui_stream_display_t current_screen;
char verify_address[TZ_BASE58CHECK_BUFFER_SIZE(20, 3)];
nbgl_callback_t stream_cb;
#endif // HAVE_NBGL
} tz_ui_stream_t;

Expand Down
84 changes: 67 additions & 17 deletions app/src/ui_stream_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,32 @@
#include <ux.h>

#include "globals.h"
#include "ui_stream.h"

void change_screen_right(void);
bool tz_ui_nav_cb(uint8_t, nbgl_pageContent_t *);

void
tz_cancel_ui(void)
{
tz_ui_stream_t *s = &global.stream;
char error_message[50] = "";

FUNC_ENTER(("void"));

size_t bucket = s->current % TZ_UI_STREAM_HISTORY_SCREENS;
STRLCPY(error_message, s->screens[bucket].title);
strlcat(error_message, "\n", sizeof(error_message));
strlcat(error_message, s->screens[bucket].body[0], sizeof(error_message));

s->cb(TZ_UI_STREAM_CB_CANCEL);

global.step = ST_IDLE;
nbgl_useCaseStatus(error_message, false, ui_home_init);

FUNC_LEAVE();
}

void
tz_reject_ui(void)
{
Expand Down Expand Up @@ -88,16 +111,41 @@ tz_ui_continue(void)
}

void
tz_ui_stream(void)
tz_ui_stream_cb(void)
{
FUNC_ENTER(("void"));

nbgl_useCaseForwardOnlyReview("Reject", NULL, tz_ui_nav_cb, tz_choice_ui);

FUNC_LEAVE();
}

void
tz_ui_stream(void)
{
tz_ui_stream_t *s = &global.stream;
FUNC_ENTER(("void"));

if (s->stream_cb)
s->stream_cb();

FUNC_LEAVE();
return;
}

void
tz_ui_review_start()
{
tz_ui_stream_t *s = &global.stream;

FUNC_ENTER(("void"));

s->stream_cb = &tz_ui_stream_cb;
tz_ui_stream();

FUNC_LEAVE();
}

void
tz_ui_stream_init(void (*cb)(uint8_t))
{
Expand All @@ -107,11 +155,11 @@ tz_ui_stream_init(void (*cb)(uint8_t))
memset(s, 0x0, sizeof(*s));
s->cb = cb;
s->full = false;
s->current = 0;
s->current = -1;
s->total = -1;

nbgl_useCaseReviewStart(&C_tezos, "Review request to sign operation",
NULL, "Reject request", tz_ui_stream,
NULL, "Reject request", tz_ui_review_start,
tz_reject_ui);

FUNC_LEAVE();
Expand All @@ -128,7 +176,6 @@ tz_ui_current_screen(__attribute__((unused)) uint8_t pairIndex)
PRINTF("[DEBUG] pressed_right=%d\n", s->pressed_right);

if (s->current < s->total && s->pressed_right) {
s->current++;
s->pressed_right = false;
}

Expand Down Expand Up @@ -179,11 +226,9 @@ tz_ui_nav_cb(uint8_t page, nbgl_pageContent_t *content)
return false;
}

if (page > 0 && !s->pressed_right) {
s->pressed_right = true;
}
change_screen_right();

PRINTF("pressed_right=%d, current=%d, total=%d, full=%d\n",
PRINTF("[DEBUG]: pressed_right=%d, current=%d, total=%d, full=%d\n",
s->pressed_right, s->current, s->total, s->full);

if (page == LAST_PAGE_FOR_REVIEW) {
Expand All @@ -192,24 +237,29 @@ tz_ui_nav_cb(uint8_t page, nbgl_pageContent_t *content)
global.apdu.sign.u.clear.skip_to_sign = true;
tz_ui_continue();
}
if ((s->current == s->total) && !s->full) {
tz_ui_continue();
}

bool result = true;
if (global.step == ST_ERROR) {
// TODO: this is handled by change_screen_right except we disable it
// to use it here. We should make ui_stream fully compatible with
// exception.h
global.step = ST_IDLE;
ui_home_init();
return false;
result = false;
} else if (global.step != ST_CLEAR_SIGN && global.step != ST_BLIND_SIGN) {
return false;
} else if (s->full) {
result = false;
} else if (tz_ui_stream_get_type() == TZ_UI_STREAM_CB_CANCEL) {
// We hit an error in the parsing workflow...
tz_cancel_ui();
result = false;
} else if ((s->current == s->total) && s->full) {
content->type = INFO_LONG_PRESS;
content->infoLongPress.icon = &C_tezos;
content->infoLongPress.text = "Sign";
content->infoLongPress.longPressText = "Sign";
} else if (page == LAST_PAGE_FOR_REVIEW) {
nbgl_useCaseSpinner("Loading operation");
return false;
result = false;
} else {
c->list.pairs = NULL;
c->list.callback = tz_ui_current_screen;
Expand All @@ -220,11 +270,11 @@ tz_ui_nav_cb(uint8_t page, nbgl_pageContent_t *content)

content->type = TAG_VALUE_LIST;
content->tagValueList = c->list;
result = true;
}

FUNC_LEAVE();

return true;
return result;
}

#endif
Loading

0 comments on commit 4d514c4

Please sign in to comment.