Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

254 use usecasestreaming for stax #258

Merged
merged 4 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
75 changes: 36 additions & 39 deletions app/src/ui_stream_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
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. */

#ifdef HAVE_NBGL

#include <nbgl_use_case.h>
Expand All @@ -24,9 +23,10 @@
#include "globals.h"
#include "ui_stream.h"

bool tz_ui_nav_cb(uint8_t page, nbgl_pageContent_t *content);
bool tz_ui_nav_cb(void);
bool has_final_screen(void);
void tz_ui_stream_start(void);
void tz_transaction_choice(bool getMorePairs);

void drop_last_screen(void);
void push_str(const char *text, size_t len, char **out);
Expand Down Expand Up @@ -62,8 +62,7 @@ tz_reject(void)
}

global.step = ST_IDLE;
nbgl_useCaseStatus("Transaction rejected", false, ui_home_init);

nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, ui_home_init);
FUNC_LEAVE();
}

Expand Down Expand Up @@ -141,6 +140,7 @@ switch_to_blindsigning(__attribute__((unused)) const char *err_type,

TZ_POSTAMBLE;
}

void
expert_mode_splash(void)
{
Expand Down Expand Up @@ -195,7 +195,7 @@ tz_accept_ui(void)
global.keys.apdu.sign.step = SIGN_ST_WAIT_USER_INPUT;
s->cb(TZ_UI_STREAM_CB_ACCEPT);

nbgl_useCaseStatus("TRANSACTION\nSIGNED", true, ui_home_init);
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_SIGNED, ui_home_init);

FUNC_LEAVE();
}
Expand Down Expand Up @@ -223,7 +223,6 @@ tz_ui_continue(void)

if (!s->full) {
TZ_CHECK(s->cb(TZ_UI_STREAM_CB_REFILL));
PRINTF("[DEBUG] total=%d\n", s->total);
}

TZ_POSTAMBLE;
Expand All @@ -233,10 +232,13 @@ void
tz_ui_stream_cb(void)
{
FUNC_ENTER(("void"));
bool result = tz_ui_nav_cb();
if (result) {
tz_ui_stream_t *s = &global.stream;
tz_ui_stream_display_t *c = &s->current_screen;

nbgl_useCaseForwardOnlyReviewNoSkip("Reject transaction", NULL,
tz_ui_nav_cb, tz_choice_ui);

nbgl_useCaseReviewStreamingContinue(&c->list, tz_transaction_choice);
}
FUNC_LEAVE();
}

Expand Down Expand Up @@ -267,13 +269,28 @@ tz_ui_review_start(void)
FUNC_LEAVE();
}

void
tz_transaction_choice(bool getMorePairs)
{
FUNC_ENTER();
if (getMorePairs) {
// get more pairs
tz_ui_review_start();
} else {
tz_reject();
}

FUNC_LEAVE();
}

void
tz_ui_stream_init(void (*cb)(tz_ui_cb_type_t cb_type))
{
tz_ui_stream_t *s = &global.stream;

FUNC_ENTER(("cb=%p", cb));
memset(s, 0x0, sizeof(*s));
memset(global.error_code, '\0', sizeof(global.error_code));
s->cb = cb;
s->full = false;
s->last = 0;
Expand All @@ -282,10 +299,11 @@ tz_ui_stream_init(void (*cb)(tz_ui_cb_type_t cb_type))
s->pressed_right = false;

ui_strings_init();
nbgl_operationType_t op_type = TYPE_TRANSACTION;
nbgl_useCaseReviewStreamingStart(op_type, &C_tezos,
"Review request to sign operation", NULL,
tz_transaction_choice);

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

Expand Down Expand Up @@ -313,20 +331,16 @@ tz_ui_stream_close(void)
}

bool
tz_ui_nav_cb(uint8_t page, nbgl_pageContent_t *content)
tz_ui_nav_cb(void)
{
FUNC_ENTER(("page=%d, content=%p", page, content));
FUNC_ENTER(("void"));

tz_ui_stream_t *s = &global.stream;
tz_ui_stream_display_t *c = &s->current_screen;
bool result = true;
tz_parser_state *st = &global.keys.apdu.sign.u.clear.parser_state;

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

// Continue receiving data from the apdu until s->full is true.
while (((s->total < 0) || ((s->current == s->total) && !s->full))
&& (st->errno < TZ_ERR_INVALID_TAG)) {
PRINTF("tz_ui_nav_cb: Looping...\n");
Expand All @@ -343,11 +357,6 @@ tz_ui_nav_cb(uint8_t page, nbgl_pageContent_t *content)
s->total++;
}

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

if (global.step == ST_ERROR) {
global.step = ST_IDLE;
ui_home_init();
Expand All @@ -356,18 +365,9 @@ tz_ui_nav_cb(uint8_t page, nbgl_pageContent_t *content)
result = false;
} else if ((s->current == s->total) && s->full) {
PRINTF("[DEBUG] signing...\n");
content->type = INFO_LONG_PRESS;
content->infoLongPress.icon = &C_tezos;
content->infoLongPress.text = "Sign transaction?";
content->infoLongPress.longPressText = "Hold to sign";
} else if (page == LAST_PAGE_FOR_REVIEW) {
s->current = s->total;
result = false;

result = false;
nbgl_useCaseReviewStreamingFinish(SIGN("transaction"), tz_choice_ui);
} else if (s->total >= 0) {
PRINTF("[DEBUG] Display: curr=%d total=%d pr=%d\n", s->current,
s->total, s->pressed_right);

if (s->current < s->total) {
s->current++;
}
Expand Down Expand Up @@ -395,10 +395,7 @@ tz_ui_nav_cb(uint8_t page, nbgl_pageContent_t *content)
c->list.nbPairs = s->screens[bucket].nb_pairs;
c->list.smallCaseForValue = false;
c->list.wrapping = true;

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

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading