Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
nbgl_use_case_nanos.c
Go to the documentation of this file.
1
5
6#ifdef NBGL_USE_CASE
7#ifndef HAVE_SE_TOUCH
8/*********************
9 * INCLUDES
10 *********************/
11#include <string.h>
12#include <stdio.h>
13#include "nbgl_debug.h"
14#include "nbgl_use_case.h"
15#include "nbgl_step_internal.h"
16#include "glyphs.h"
17#include "os_pic.h"
18#include "os_print.h"
19#include "os_helpers.h"
20#include "ux.h"
21
22/*********************
23 * DEFINES
24 *********************/
25
26/**********************
27 * TYPEDEFS
28 **********************/
29
30typedef struct ReviewContext_s {
31 nbgl_choiceCallback_t onChoice;
32 const nbgl_contentTagValueList_t *tagValueList;
33 const nbgl_icon_details_t *icon;
34 const char *reviewTitle;
35 const char *reviewSubTitle;
36 const char *finishTitle;
37 const char *address; // for address confirmation review
38 nbgl_callback_t skipCallback; // callback provided by used
39 uint8_t nbDataSets; // number of sets of data received by StreamingContinue
40 bool skipDisplay; // if set to true, means that we are displaying the skip page
41 uint8_t dataDirection; // used to know whether the skip page is reached from back or forward
42 uint8_t currentTagValueIndex;
43 // (16 bits because a list of 255 elements has 256 extension pages, including the back one)
44 uint16_t currentExtensionPage;
45 uint16_t nbExtensionPages;
46 const nbgl_contentValueExt_t *extension;
47 nbgl_step_t extensionStepCtx;
48 const char *aliasValue; // displayed value of the alias pair, used as heading of its details
49
50} ReviewContext_t;
51
52typedef struct ChoiceContext_s {
53 const nbgl_icon_details_t *icon;
54 const char *title;
55 const char *message;
56 const char *subMessage;
57 const char *confirmText;
58 const char *cancelText;
59 nbgl_choiceCallback_t onChoice;
60 const nbgl_genericDetails_t *details;
61} ChoiceContext_t;
62
63typedef struct ConfirmContext_s {
64 const char *message;
65 const char *subMessage;
66 const char *confirmText;
67 const char *cancelText;
68 nbgl_callback_t onConfirm;
69 nbgl_step_t currentStep;
70} ConfirmContext_t;
71
72typedef struct ContentContext_s {
73 const char *title; // For CHOICES_LIST /BARS_LIST
74 nbgl_genericContents_t genericContents;
75 const char *rejectText;
76 nbgl_layoutTouchCallback_t controlsCallback;
77 nbgl_navCallback_t navCallback;
78 nbgl_callback_t quitCallback;
79} ContentContext_t;
80
81typedef struct HomeContext_s {
82 const char *appName;
83 const nbgl_icon_details_t *appIcon;
84 const char *tagline;
85 const nbgl_genericContents_t *settingContents;
86 const nbgl_contentInfoList_t *infosList;
87 const nbgl_homeAction_t *homeAction;
88 nbgl_callback_t quitCallback;
89} HomeContext_t;
90
91typedef struct ActionContext_s {
92 nbgl_callback_t actionCallback;
93} ActionContext_t;
94
95#ifdef NBGL_KEYPAD
96typedef struct KeypadContext_s {
97 uint8_t pinEntry[KEYPAD_MAX_DIGITS + 1]; // +1 for the NUL terminator
98 uint8_t pinLen;
99 uint8_t pinMinDigits;
100 uint8_t pinMaxDigits;
101 nbgl_layout_t *layoutCtx;
102 bool hidden;
103 uint8_t keypadIndex;
104 nbgl_pinValidCallback_t validatePin;
105 nbgl_callback_t backCallback;
106} KeypadContext_t;
107#endif
108
109#ifdef NBGL_KEYBOARD
110typedef struct KeyboardContext_s {
111 nbgl_layoutKeyboardContent_t content;
112 char *entryBuffer;
113 uint16_t entryMaxLen;
114 nbgl_layout_t *layoutCtx;
115 uint8_t keyboardIndex;
116 uint8_t textIndex;
117 nbgl_callback_t actionCallback;
118 nbgl_callback_t backCallback;
119 nbgl_keyboardButtonsCallback_t getSuggestButtons;
120 nbgl_layoutTouchCallback_t onButtonCallback;
121} KeyboardContext_t;
122#endif
123
124typedef enum {
125 NONE_USE_CASE,
126 SPINNER_USE_CASE,
127 REVIEW_USE_CASE,
128 GENERIC_REVIEW_USE_CASE,
129 ADDRESS_REVIEW_USE_CASE,
130 STREAMING_START_REVIEW_USE_CASE,
131 STREAMING_CONTINUE_REVIEW_USE_CASE,
132 STREAMING_FINISH_REVIEW_USE_CASE,
133 CHOICE_USE_CASE,
134 STATUS_USE_CASE,
135 CONFIRM_USE_CASE,
136 KEYPAD_USE_CASE,
137 KEYBOARD_USE_CASE,
138 HOME_USE_CASE,
139 INFO_USE_CASE,
140 SETTINGS_USE_CASE,
141 GENERIC_SETTINGS,
142 CONTENT_USE_CASE,
143 ACTION_USE_CASE
144} ContextType_t;
145
146typedef struct UseCaseContext_s {
147 ContextType_t type;
148 nbgl_operationType_t operationType;
149 uint8_t nbPages;
150 uint8_t currentPage;
151 uint8_t firstPairPage;
152 bool forceAction;
154 stepCallback;
155 union {
156 ReviewContext_t review;
157 ChoiceContext_t choice;
158 ConfirmContext_t confirm;
159 HomeContext_t home;
160 ContentContext_t content;
161#ifdef NBGL_KEYPAD
162 KeypadContext_t keypad;
163#endif
164#ifdef NBGL_KEYBOARD
165 KeyboardContext_t keyboard;
166#endif
167 ActionContext_t action;
168 };
169} UseCaseContext_t;
170
171typedef struct PageContent_s {
172 bool isSwitch;
173 const char *text;
174 const char *subText;
175 const nbgl_icon_details_t *icon;
176 const nbgl_contentValueExt_t *extension;
177 nbgl_state_t state;
178 bool isCenteredInfo;
179 bool isAction;
180 bool bottomIcon;
183 uint8_t nbMaxLinesForSubText;
184} PageContent_t;
185
186typedef struct ReviewWithWarningContext_s {
187 ContextType_t type;
188 nbgl_operationType_t operationType;
189 const nbgl_contentTagValueList_t *tagValueList;
190 const nbgl_icon_details_t *icon;
191 const char *reviewTitle;
192 const char *reviewSubTitle;
193 const char *finishTitle;
194 const nbgl_warning_t *warning;
195 nbgl_choiceCallback_t choiceCallback;
196 uint8_t securityReportLevel; // level 1 is the first level of menus
197 bool isIntro; // set to true during intro (before actual review)
198 uint8_t warningPage;
199 uint8_t nbWarningPages;
200 uint8_t firstWarningPage;
201 uint8_t barDetailIdx; // index of the bar whose detail is displayed
202} ReviewWithWarningContext_t;
203
204typedef enum {
205 NO_FORCED_TYPE = 0,
206 FORCE_BUTTON,
207 FORCE_CENTERED_INFO
208} ForcedType_t;
209
210/**********************
211 * STATIC VARIABLES
212 **********************/
213static UseCaseContext_t context;
214
215static ReviewWithWarningContext_t reviewWithWarnCtx;
216// configuration of warning when using @ref nbgl_useCaseReviewBlindSigning()
217static const nbgl_warning_t blindSigningWarning = {.predefinedSet = (1 << BLIND_SIGNING_WARN)};
218
219// local copy of a caller's warning, used when it has to be normalized (see normalizeWarning())
220static nbgl_warning_t normalizedWarning;
221
222// Operation type for streaming (because the one in 'context' is reset at each streaming API call)
223nbgl_operationType_t streamingOpType;
224
225/**********************
226 * STATIC FUNCTIONS
227 **********************/
228static void displayReviewPage(nbgl_stepPosition_t pos);
229static void displayStreamingReviewPage(nbgl_stepPosition_t pos);
230static void displayHomePage(nbgl_stepPosition_t pos);
231static void displayInfoPage(nbgl_stepPosition_t pos);
232static void displaySettingsPage(nbgl_stepPosition_t pos, bool toogle_state);
233static void displayChoicePage(nbgl_stepPosition_t pos);
234static void displayConfirm(nbgl_stepPosition_t pos);
235static void displayContent(nbgl_stepPosition_t pos, bool toogle_state);
236static void displaySpinner(const char *text);
237
238static void startUseCaseHome(void);
239static void startUseCaseInfo(void);
240static void startUseCaseSettings(void);
241static void startUseCaseSettingsAtPage(uint8_t initSettingPage);
242static void startUseCaseContent(void);
243
244static void statusTickerCallback(void);
245
246static void displayExtensionStep(nbgl_stepPosition_t pos);
247static void displayWarningStep(void);
248
249// Risk and threat warnings are only rendered alongside the blind signing warning
250static bool isWarningSupported(const nbgl_warning_t *warning)
251{
252 return ((warning->predefinedSet
254 == 0)
255 || ((warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) != 0);
256}
257
258// Helper to check that all pairs of a tag/value list retrieved with a callback have an index
259// fitting in uint8_t (from startIndex to startIndex + nbPairs - 1). The list must not be NULL.
260static bool isTagValueListValid(const nbgl_contentTagValueList_t *tagValueList)
261{
262 return (tagValueList->pairs != NULL)
263 || (((uint16_t) tagValueList->startIndex + tagValueList->nbPairs) <= (UINT8_MAX + 1));
264}
265
266static bool checkTagValueList(const nbgl_contentTagValueList_t *tagValueList, bool checkAliases);
267
268// Helper to check that the details of a pair displayed as an alias can be displayed in full:
269// the list of an INFO_LIST_ALIAS or TAG_VALUE_LIST_ALIAS alias must exist and must not be empty,
270// and the one of a TAG_VALUE_LIST_ALIAS alias using a callback must be provided with all its pairs.
271// Otherwise opening the alias would crash, or display empty details, preventing to verify the
272// actual value. (pairs of an alias list are not checked for aliases, since their details are not
273// reachable)
274static bool isAliasDetailsComplete(const nbgl_contentTagValue_t *pair)
275{
276 const nbgl_contentValueExt_t *extension;
277
278 // the extension is in an union with valueIcon, only relevant for an alias
279 if (!pair->aliasValue || (pair->extension == NULL)) {
280 return true;
281 }
282 extension = PIC(pair->extension);
283 if (extension->aliasType == INFO_LIST_ALIAS) {
284 const nbgl_contentInfoList_t *infoList = PIC(extension->infolist);
285 return (infoList != NULL) && (infoList->nbInfos > 0);
286 }
287 if (extension->aliasType == TAG_VALUE_LIST_ALIAS) {
288 const nbgl_contentTagValueList_t *aliasList = PIC(extension->tagValuelist);
289 return (aliasList != NULL) && (aliasList->nbPairs > 0)
290 && checkTagValueList(aliasList, false);
291 }
292 return true;
293}
294
295// Helper to check that a non NULL tag/value list is valid and that its callback, if any, provides
296// all pairs. If checkAliases is true, the details of every pair displayed as an alias are checked
297// too (see isAliasDetailsComplete()). An empty list is complete, since no pair is retrieved from
298// it.
299static bool checkTagValueList(const nbgl_contentTagValueList_t *tagValueList, bool checkAliases)
300{
301 if (tagValueList->nbPairs == 0) {
302 return true;
303 }
304 if (tagValueList->pairs == NULL) {
305 if ((tagValueList->callback == NULL) || !isTagValueListValid(tagValueList)) {
306 return false;
307 }
308 }
309 else if (!checkAliases) {
310 return true;
311 }
312 for (uint8_t i = 0; i < tagValueList->nbPairs; i++) {
313 const nbgl_contentTagValue_t *pair;
314
315 if (tagValueList->pairs != NULL) {
316 pair = PIC(&tagValueList->pairs[i]);
317 }
318 else {
319 pair = PIC(tagValueList->callback(tagValueList->startIndex + i));
320 }
321 if ((pair == NULL) || (checkAliases && !isAliasDetailsComplete(pair))) {
322 return false;
323 }
324 }
325 return true;
326}
327
328// Helper to check that a tag/value list is valid, that its callback, if any, provides all pairs,
329// and that the details of all its aliases can be displayed in full.
330// The list must not be NULL. An empty list is complete, since no pair is retrieved from it.
331static bool isTagValueListComplete(const nbgl_contentTagValueList_t *tagValueList)
332{
333 return checkTagValueList(tagValueList, true);
334}
335
336// Helper to check that the tag/value list of a content, if any, is complete
337static bool isContentComplete(const nbgl_content_t *content)
338{
339 if (content->type == TAG_VALUE_LIST) {
340 return isTagValueListComplete(&content->content.tagValueList);
341 }
342 if (content->type == TAG_VALUE_CONFIRM) {
343 return isTagValueListComplete(&content->content.tagValueConfirm.tagValueList);
344 }
345 return true;
346}
347
348// Simple helper to get the number of elements inside a nbgl_content_t
349static uint16_t getContentNbElement(const nbgl_content_t *content)
350{
351 switch (content->type) {
352 case CENTERED_INFO:
353 return 1;
354 case INFO_BUTTON:
355 return 1;
356 case TAG_VALUE_LIST:
357 // an invalid list is reported as overflowing, to be rejected by callers
358 if (!isTagValueListValid(&content->content.tagValueList)) {
359 return UINT8_MAX + 1;
360 }
361 return content->content.tagValueList.nbPairs;
363 // an invalid list is reported as overflowing, to be rejected by callers
364 if (!isTagValueListValid(&content->content.tagValueConfirm.tagValueList)) {
365 return UINT8_MAX + 1;
366 }
367 // last element is for Confirm page
368 return (uint16_t) content->content.tagValueConfirm.tagValueList.nbPairs + 1;
369 case SWITCHES_LIST:
370 return content->content.switchesList.nbSwitches;
371 case INFOS_LIST:
372 return content->content.infosList.nbInfos;
373 case CHOICES_LIST:
374 return content->content.choicesList.nbChoices;
375 case BARS_LIST:
376 return content->content.barsList.nbBars;
377 default:
378 return 0;
379 }
380}
381
382// Helper to retrieve the content inside a nbgl_genericContents_t using
383// either the contentsList or using the contentGetterCallback
384static const nbgl_content_t *getContentAtIdx(const nbgl_genericContents_t *genericContents,
385 uint8_t contentIdx,
386 nbgl_content_t *content)
387{
388 nbgl_pageContent_t pageContent = {0};
389 if (contentIdx >= genericContents->nbContents) {
390 LOG_DEBUG(USE_CASE_LOGGER, "No content available at %d\n", contentIdx);
391 return NULL;
392 }
393
394 if (genericContents->callbackCallNeeded) {
395 if (content == NULL) {
396 LOG_DEBUG(USE_CASE_LOGGER, "Invalid content variable\n");
397 return NULL;
398 }
399 // Retrieve content through callback, but first memset the content.
400 memset(content, 0, sizeof(nbgl_content_t));
401 if (context.content.navCallback) {
402 if (context.content.navCallback(contentIdx, &pageContent) == true) {
403 // Copy the Page Content to the Content variable
404 content->type = pageContent.type;
405 switch (content->type) {
406 case CENTERED_INFO:
407 content->content.centeredInfo = pageContent.centeredInfo;
408 break;
409 case INFO_BUTTON:
410 content->content.infoButton = pageContent.infoButton;
411 break;
412 case TAG_VALUE_LIST:
413 content->content.tagValueList = pageContent.tagValueList;
414 break;
416 content->content.tagValueConfirm = pageContent.tagValueConfirm;
417 break;
418 case SWITCHES_LIST:
419 content->content.switchesList = pageContent.switchesList;
420 break;
421 case INFOS_LIST:
422 content->content.infosList = pageContent.infosList;
423 break;
424 case CHOICES_LIST:
425 content->content.choicesList = pageContent.choicesList;
426 break;
427 case BARS_LIST:
428 content->content.barsList = pageContent.barsList;
429 break;
430 default:
431 LOG_DEBUG(USE_CASE_LOGGER, "Invalid content type\n");
432 return NULL;
433 }
434 }
435 else {
436 LOG_DEBUG(USE_CASE_LOGGER, "Error getting page content\n");
437 return NULL;
438 }
439 }
440 else {
441 genericContents->contentGetterCallback(contentIdx, content);
442 }
443 return content;
444 }
445 else {
446 // Retrieve content through list
447 return PIC(&genericContents->contentsList[contentIdx]);
448 }
449}
450
451// Helper to retrieve the content inside a nbgl_genericContents_t using
452// either the contentsList or using the contentGetterCallback
453static const nbgl_content_t *getContentElemAtIdx(uint8_t elemIdx,
454 uint8_t *elemContentIdx,
455 nbgl_content_t *content)
456{
457 const nbgl_genericContents_t *genericContents = NULL;
458 const nbgl_content_t *p_content = NULL;
459 uint16_t nbPages = 0;
460 uint16_t elemNbPages = 0;
461
462 switch (context.type) {
463 case SETTINGS_USE_CASE:
464 case HOME_USE_CASE:
465 case GENERIC_SETTINGS:
466 genericContents = context.home.settingContents;
467 break;
468 case CONTENT_USE_CASE:
469 case GENERIC_REVIEW_USE_CASE:
470 genericContents = &context.content.genericContents;
471 break;
472 default:
473 return NULL;
474 }
475 for (unsigned int i = 0; i < genericContents->nbContents; i++) {
476 p_content = getContentAtIdx(genericContents, i, content);
477 elemNbPages = getContentNbElement(p_content);
478 if (nbPages + elemNbPages > elemIdx) {
479 *elemContentIdx = context.currentPage - nbPages;
480 break;
481 }
482 nbPages += elemNbPages;
483 }
484
485 return p_content;
486}
487
488static const char *getChoiceName(uint8_t choiceIndex)
489{
490 uint8_t elemIdx;
491 uint8_t nbValues;
492 const nbgl_content_t *p_content = NULL;
493 nbgl_content_t content = {0};
494 nbgl_contentRadioChoice_t *contentChoices = NULL;
495 nbgl_contentBarsList_t *contentBars = NULL;
496 char **names = NULL;
497
498 p_content = getContentElemAtIdx(context.currentPage, &elemIdx, &content);
499 if (p_content == NULL) {
501 "getChoiceName(): p_content is NULL for page %d\n",
502 context.currentPage);
503 return NULL;
504 }
505 switch (p_content->type) {
506 case CHOICES_LIST:
507 contentChoices = (nbgl_contentRadioChoice_t *) PIC(&p_content->content.choicesList);
508 names = (char **) PIC(contentChoices->names);
509 nbValues = contentChoices->nbChoices;
510 break;
511 case BARS_LIST:
512 contentBars = ((nbgl_contentBarsList_t *) PIC(&p_content->content.barsList));
513 names = (char **) PIC(contentBars->barTexts);
514 nbValues = contentBars->nbBars;
515 break;
516 default:
517 // Not supported as vertical MenuList
518 return NULL;
519 }
520 if (choiceIndex >= nbValues) {
521 // Last item is always "Back" button
522 return "Back";
523 }
524 return (const char *) PIC(names[choiceIndex]);
525}
526
527static void onChoiceSelected(uint8_t choiceIndex)
528{
529 uint8_t elemIdx;
530 uint8_t token = 255;
531 const nbgl_content_t *p_content = NULL;
532 nbgl_content_t content = {0};
533 nbgl_contentRadioChoice_t *contentChoices = NULL;
534 nbgl_contentBarsList_t *contentBars = NULL;
535
536 p_content = getContentElemAtIdx(context.currentPage, &elemIdx, &content);
537 if (p_content == NULL) {
539 "onChoiceSelected(): p_content is NULL for page %d\n",
540 context.currentPage);
541 return;
542 }
543 switch (p_content->type) {
544 case CHOICES_LIST:
545 contentChoices = (nbgl_contentRadioChoice_t *) PIC(&p_content->content.choicesList);
546 if (choiceIndex < contentChoices->nbChoices) {
547 token = contentChoices->token;
548 }
549 break;
550 case BARS_LIST:
551 contentBars = ((nbgl_contentBarsList_t *) PIC(&p_content->content.barsList));
552 if (choiceIndex < contentBars->nbBars) {
553 token = ((const uint8_t *) PIC(contentBars->tokens))[choiceIndex];
554 }
555 break;
556 default:
557 // Not supported as vertical MenuList
558 break;
559 }
560 if (token != 255) {
561 // Prefer the per-content action callback (used by settings/content
562 // flows). Forward both the choice index and the absolute page so the
563 // app can react identically to the horizontal flow.
564 if (p_content->contentActionCallback != NULL) {
565 nbgl_contentActionCallback_t actionCallback = PIC(p_content->contentActionCallback);
566 actionCallback(token, choiceIndex, context.currentPage);
567 return;
568 }
569 if (context.content.controlsCallback != NULL) {
570 context.content.controlsCallback(token, choiceIndex);
571 return;
572 }
573 }
574 // Back entry (the extra item appended by drawStep at index nbChoices) or
575 // unknown selection: mirror the horizontal-flow Back behaviour in
576 // displaySettingsPage so SETTINGS_USE_CASE / GENERIC_SETTINGS / content
577 // callers all exit consistently.
578 if ((context.type == GENERIC_SETTINGS) && (context.home.quitCallback != NULL)) {
579 context.home.quitCallback();
580 return;
581 }
582 if (context.type == SETTINGS_USE_CASE) {
583 startUseCaseHome();
584 return;
585 }
586 if (context.content.quitCallback != NULL) {
587 context.content.quitCallback();
588 }
589}
590
591static void getPairData(const nbgl_contentTagValueList_t *tagValueList,
592 uint8_t index,
593 const char **item,
594 const char **value,
595 const nbgl_contentValueExt_t **extension,
596 const nbgl_icon_details_t **icon,
597 bool *isCenteredInfo,
598 uint8_t *nbMaxLinesForValue)
599{
600 static nbgl_contentTagValue_t emptyPair;
601 const nbgl_contentTagValue_t *pair;
602
603 if (tagValueList->pairs != NULL) {
604 pair = PIC(&tagValueList->pairs[index]);
605 }
606 else {
607 // index is relative to the first pair to get with callback
608 pair = PIC(tagValueList->callback(tagValueList->startIndex + index));
609 if (pair == NULL) {
610 // an empty pair is used if the callback doesn't provide one
611 LOG_WARN(USE_CASE_LOGGER, "getPairData(): no pair for index %d\n", index);
612 memset(&emptyPair, 0, sizeof(emptyPair));
613 emptyPair.item = "";
614 emptyPair.value = "";
615 pair = &emptyPair;
616 }
617 }
618 *item = pair->item;
619 *value = pair->value;
620 if (pair->aliasValue) {
621 *extension = pair->extension;
622 }
623 else if (pair->centeredInfo) {
624 *isCenteredInfo = true;
625 *icon = pair->valueIcon;
626 }
627 else {
628 *extension = NULL;
629 }
630 if (nbMaxLinesForValue != NULL) {
631 // not used if the pair is drawn as a centered info (see drawStep())
632 *nbMaxLinesForValue = pair->nbMaxLinesForValue;
633 }
634}
635
636static void onReviewAccept(void)
637{
638 if (context.review.onChoice) {
639 context.review.onChoice(true);
640 }
641}
642
643static void onReviewReject(void)
644{
645 if (context.review.onChoice) {
646 context.review.onChoice(false);
647 }
648}
649
650static void onChoiceAccept(void)
651{
652 if (context.choice.onChoice) {
653 context.choice.onChoice(true);
654 }
655}
656
657static void onChoiceReject(void)
658{
659 if (context.choice.onChoice) {
660 context.choice.onChoice(false);
661 }
662}
663
664static void onConfirmAccept(void)
665{
666 if (context.confirm.currentStep) {
667 nbgl_stepRelease(context.confirm.currentStep);
668 }
669 if (context.confirm.onConfirm) {
670 context.confirm.onConfirm();
671 }
672}
673
674static void onConfirmReject(void)
675{
676 if (context.confirm.currentStep) {
677 nbgl_stepRelease(context.confirm.currentStep);
679 nbgl_refresh();
680 }
681}
682
683static void onSwitchAction(void)
684{
685 const nbgl_contentSwitch_t *contentSwitch = NULL;
686 const nbgl_content_t *p_content = NULL;
687 nbgl_content_t content = {0};
688 uint8_t elemIdx;
689
690 p_content = getContentElemAtIdx(context.currentPage, &elemIdx, &content);
691 if ((p_content == NULL) || (p_content->type != SWITCHES_LIST)) {
693 "onSwitchAction(): p_content is NULL or not a switches list for page %d\n",
694 context.currentPage);
695 return;
696 }
697 contentSwitch
698 = &((const nbgl_contentSwitch_t *) PIC(p_content->content.switchesList.switches))[elemIdx];
699 switch (context.type) {
700 case SETTINGS_USE_CASE:
701 case HOME_USE_CASE:
702 case GENERIC_SETTINGS:
703 displaySettingsPage(FORWARD_DIRECTION, true);
704 break;
705 case CONTENT_USE_CASE:
706 case GENERIC_REVIEW_USE_CASE:
707 displayContent(FORWARD_DIRECTION, true);
708 break;
709 default:
710 break;
711 }
712 if (p_content->contentActionCallback != NULL) {
713 nbgl_contentActionCallback_t actionCallback = PIC(p_content->contentActionCallback);
714 actionCallback(contentSwitch->token,
715 (contentSwitch->initState == ON_STATE) ? OFF_STATE : ON_STATE,
716 context.currentPage);
717 }
718 else if (context.content.controlsCallback != NULL) {
719 context.content.controlsCallback(contentSwitch->token, 0);
720 }
721}
722
723// nbMaxLinesForSubTxt: if > 0, subTxt is truncated to this number of lines, in a single page
724static void drawStep(nbgl_stepPosition_t pos,
725 const nbgl_icon_details_t *icon,
726 const char *txt,
727 const char *subTxt,
728 uint8_t nbMaxLinesForSubTxt,
729 nbgl_stepButtonCallback_t onActionCallback,
730 bool modal,
731 ForcedType_t forcedType,
732 bool bottomIcon)
733{
734 uint8_t elemIdx;
735 nbgl_step_t newStep = NULL;
736 const nbgl_content_t *p_content = NULL;
737 nbgl_content_t content = {0};
738 nbgl_contentRadioChoice_t *contentChoices = NULL;
739 nbgl_contentBarsList_t *contentBars = NULL;
740 nbgl_screenTickerConfiguration_t *p_ticker = NULL;
741 nbgl_layoutMenuList_t list = {0};
742 nbgl_screenTickerConfiguration_t ticker = {.tickerCallback = PIC(statusTickerCallback),
743 .tickerIntervale = 0, // not periodic
744 .tickerValue = STATUS_SCREEN_DURATION};
745
746 pos |= GET_POS_OF_STEP(context.currentPage, context.nbPages);
747 // if we are in streaming+skip case, enable going backward even for first tag/value of the set
748 // (except the first set) because the set starts with a "skip" page
749 if ((context.type == STREAMING_CONTINUE_REVIEW_USE_CASE)
750 && (context.review.skipCallback != NULL) && (context.review.nbDataSets > 1)) {
751 pos |= LAST_STEP;
752 }
753 if ((context.type == STATUS_USE_CASE) || (context.type == SPINNER_USE_CASE)) {
754 p_ticker = &ticker;
755 }
756 if ((context.type == CONFIRM_USE_CASE) && (context.confirm.currentStep != NULL)) {
757 nbgl_stepRelease(context.confirm.currentStep);
758 }
759
760 if (txt == NULL) {
761 p_content = getContentElemAtIdx(context.currentPage, &elemIdx, &content);
762 if (p_content) {
763 switch (p_content->type) {
764 case CHOICES_LIST:
765 contentChoices
766 = ((nbgl_contentRadioChoice_t *) PIC(&p_content->content.choicesList));
767 list.nbChoices = contentChoices->nbChoices + 1; // For Back button
768 list.selectedChoice = contentChoices->initChoice;
769 list.callback = getChoiceName;
770 newStep = nbgl_stepDrawMenuList(onChoiceSelected, p_ticker, &list, modal);
771 break;
772 case BARS_LIST:
773 contentBars = ((nbgl_contentBarsList_t *) PIC(&p_content->content.barsList));
774 list.nbChoices = contentBars->nbBars + 1; // For Back button
775 list.selectedChoice = 0;
776 list.callback = getChoiceName;
777 newStep = nbgl_stepDrawMenuList(onChoiceSelected, p_ticker, &list, modal);
778 break;
779 default:
780 // Not supported as vertical MenuList
781 break;
782 }
783 }
784 }
785 else if ((icon == NULL) && (forcedType != FORCE_CENTERED_INFO)) {
787 if (subTxt != NULL) {
788 style = (forcedType == FORCE_BUTTON) ? BUTTON_INFO : BOLD_TEXT1_INFO;
789 }
790 else {
791 style = REGULAR_INFO;
792 }
793 newStep = stepDrawText(
794 pos, onActionCallback, p_ticker, txt, subTxt, style, modal, nbMaxLinesForSubTxt);
795 }
796 else {
797 nbgl_layoutCenteredInfo_t info = {0};
798 info.icon = icon;
799 info.text1 = txt;
800 info.text2 = subTxt;
801 info.bottomIcon = bottomIcon;
802 if ((subTxt != NULL) || (context.stepCallback != NULL) || context.forceAction) {
803 info.style = BOLD_TEXT1_INFO;
804 }
805 else {
806 info.style = REGULAR_INFO;
807 }
808 newStep = nbgl_stepDrawCenteredInfo(pos, onActionCallback, p_ticker, &info, modal);
809 }
810 if (context.type == CONFIRM_USE_CASE) {
811 context.confirm.currentStep = newStep;
812 }
813}
814
815static void drawSwitchStep(nbgl_stepPosition_t pos,
816 const char *title,
817 const char *description,
818 bool state,
819 nbgl_stepButtonCallback_t onActionCallback,
820 bool modal)
821{
822 nbgl_layoutSwitch_t switchInfo = {0};
823
824 pos |= GET_POS_OF_STEP(context.currentPage, context.nbPages);
825 switchInfo.initState = state;
826 switchInfo.text = title;
827 switchInfo.subText = description;
828 nbgl_stepDrawSwitch(pos, onActionCallback, NULL, &switchInfo, modal);
829}
830
831static bool buttonGenericCallback(nbgl_buttonEvent_t event, nbgl_stepPosition_t *pos)
832{
833 uint8_t elemIdx;
834 uint8_t token = 0;
835 uint8_t index = 0;
836 const nbgl_content_t *p_content = NULL;
837 nbgl_content_t content = {0};
838
839 if (event == BUTTON_LEFT_PRESSED) {
840 if (context.currentPage > 0) {
841 context.currentPage--;
842 }
843 // in streaming+skip case, it is allowed to go backward at the first tag/value, except for
844 // the first set
845 else if ((context.type != STREAMING_CONTINUE_REVIEW_USE_CASE)
846 || (context.review.skipCallback == NULL) || (context.review.nbDataSets == 1)) {
847 // Drop the event
848 return false;
849 }
851 }
852 else if (event == BUTTON_RIGHT_PRESSED) {
853 if (context.currentPage < (int) (context.nbPages - 1)) {
854 context.currentPage++;
855 }
856 else {
857 // Drop the event
858 return false;
859 }
861 }
862 else {
863 if (event == BUTTON_BOTH_PRESSED) {
864 if (context.stepCallback != NULL) {
865 context.stepCallback();
866 }
867 else if ((context.type == CONTENT_USE_CASE) || (context.type == SETTINGS_USE_CASE)
868 || (context.type == GENERIC_SETTINGS)
869 || (context.type == GENERIC_REVIEW_USE_CASE)) {
870 p_content = getContentElemAtIdx(context.currentPage, &elemIdx, &content);
871 if (p_content != NULL) {
872 switch (p_content->type) {
873 case CENTERED_INFO:
874 // No associated callback
875 return false;
876 case INFO_BUTTON:
877 token = p_content->content.infoButton.buttonToken;
878 break;
879 case SWITCHES_LIST:
880 token = p_content->content.switchesList.switches->token;
881 break;
882 case BARS_LIST:
883 if (elemIdx >= p_content->content.barsList.nbBars) {
884 return false;
885 }
886 token = ((const uint8_t *) PIC(
887 p_content->content.barsList.tokens))[elemIdx];
888 index = elemIdx;
889 break;
890 case CHOICES_LIST:
891 token = p_content->content.choicesList.token;
892 index = elemIdx;
893 break;
894 case TAG_VALUE_LIST:
895 return false;
897 if (elemIdx < p_content->content.tagValueConfirm.tagValueList.nbPairs) {
898 return false;
899 }
900 token = p_content->content.tagValueConfirm.confirmationToken;
901 break;
902 default:
903 break;
904 }
905
906 bool used_action_callback
907 = (p_content != NULL) && (p_content->contentActionCallback != NULL);
908 ContextType_t prev_type = context.type;
909 if (used_action_callback) {
910 nbgl_contentActionCallback_t actionCallback
912 actionCallback(token, index, context.currentPage);
913 }
914 else if (context.content.controlsCallback != NULL) {
915 context.content.controlsCallback(token, index);
916 }
917 // If the callback swapped the use case (e.g. by entering
918 // a new screen via display_home_page / nbgl_useCaseXxx),
919 // the global context has already been reset — leave it
920 // alone, do not try to redraw the previous layout.
921 if (context.type != prev_type) {
922 return false;
923 }
924 // After a CHOICES_LIST or BARS_LIST selection that went
925 // through the per-content action callback (settings-style
926 // flows), request a redraw of the current page so any
927 // visual side effect of the pick (e.g. the selectionIcon
928 // moving below the new initChoice) becomes visible.
929 // The controlsCallback path (navigable content, generic
930 // review, ...) is excluded because such callbacks
931 // commonly route to a brand-new use case (review,
932 // warning, ...) that owns the screen without resetting
933 // context.type — forcing a redraw there would clobber it.
934 if (used_action_callback
935 && ((p_content->type == CHOICES_LIST) || (p_content->type == BARS_LIST))) {
937 return true;
938 }
939 }
940 }
941 }
942 return false;
943 }
944 return true;
945}
946
947static void reviewCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
948{
949 UNUSED(stepCtx);
951
952 if (!buttonGenericCallback(event, &pos)) {
953 return;
954 }
955 else {
956 // memorize last direction
957 context.review.dataDirection = pos;
958 }
959 displayReviewPage(pos);
960}
961
962// this is the callback used when button action on the "skip" page
963static void buttonSkipCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
964{
965 UNUSED(stepCtx);
967
968 if (event == BUTTON_LEFT_PRESSED) {
969 // only decrement page if we are going backward but coming from forward (back & forth)
970 if ((context.review.dataDirection == FORWARD_DIRECTION)
971 && (context.currentPage > context.firstPairPage)) {
972 context.currentPage--;
973 }
975 }
976 else if (event == BUTTON_RIGHT_PRESSED) {
977 // only increment page if we are going forward but coming from backward (back & forth)
978 if ((context.review.dataDirection == BACKWARD_DIRECTION)
979 && (context.currentPage < (int) (context.nbPages - 1))
980 && (context.currentPage > context.firstPairPage)) {
981 context.currentPage++;
982 }
984 }
985 else if (event == BUTTON_BOTH_PRESSED) {
986 // the first tag/value page is at page 0 only in streaming case
987 if (context.firstPairPage == 0) {
988 // in streaming, we have to call the provided callback
989 context.review.skipCallback();
990 }
991 else {
992 // if not in streaming, go directly to the "approve" page
993 context.currentPage = context.nbPages - 2;
994 displayReviewPage(FORWARD_DIRECTION);
995 }
996 return;
997 }
998 else {
999 return;
1000 }
1001 // the first tag/value page is at page 0 only in streaming case
1002 if (context.firstPairPage == 0) {
1003 displayStreamingReviewPage(pos);
1004 }
1005 else {
1006 displayReviewPage(pos);
1007 }
1008}
1009
1010// this is the callback used when buttons in "Action" use case are pressed
1011static void useCaseActionCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
1012{
1013 UNUSED(stepCtx);
1014
1015 if (event == BUTTON_BOTH_PRESSED) {
1016 context.action.actionCallback();
1017 }
1018}
1019
1020static void streamingReviewCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
1021{
1023 UNUSED(stepCtx);
1024
1025 if (!buttonGenericCallback(event, &pos)) {
1026 return;
1027 }
1028 else {
1029 // memorize last direction
1030 context.review.dataDirection = pos;
1031 }
1032
1033 displayStreamingReviewPage(pos);
1034}
1035
1036static void settingsCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
1037{
1038 UNUSED(stepCtx);
1040
1041 if (!buttonGenericCallback(event, &pos)) {
1042 return;
1043 }
1044
1045 displaySettingsPage(pos, false);
1046}
1047
1048static void infoCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
1049{
1050 UNUSED(stepCtx);
1052
1053 if (!buttonGenericCallback(event, &pos)) {
1054 return;
1055 }
1056
1057 displayInfoPage(pos);
1058}
1059
1060static void homeCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
1061{
1062 UNUSED(stepCtx);
1064
1065 if (!buttonGenericCallback(event, &pos)) {
1066 return;
1067 }
1068
1069 displayHomePage(pos);
1070}
1071
1072static void genericChoiceCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
1073{
1074 UNUSED(stepCtx);
1076
1077 if (!buttonGenericCallback(event, &pos)) {
1078 return;
1079 }
1080
1081 displayChoicePage(pos);
1082}
1083
1084static void genericConfirmCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
1085{
1086 UNUSED(stepCtx);
1088
1089 if (!buttonGenericCallback(event, &pos)) {
1090 return;
1091 }
1092
1093 displayConfirm(pos);
1094}
1095
1096static void statusButtonCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
1097{
1098 UNUSED(stepCtx);
1099 // any button press should dismiss the status screen
1100 if ((event == BUTTON_BOTH_PRESSED) || (event == BUTTON_LEFT_PRESSED)
1101 || (event == BUTTON_RIGHT_PRESSED)) {
1102 if (context.stepCallback != NULL) {
1103 context.stepCallback();
1104 }
1105 }
1106}
1107
1108static void contentCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
1109{
1110 UNUSED(stepCtx);
1112
1113 if (!buttonGenericCallback(event, &pos)) {
1114 return;
1115 }
1116
1117 displayContent(pos, false);
1118}
1119
1120// callback used for timeout
1121static void statusTickerCallback(void)
1122{
1123 if (context.stepCallback != NULL) {
1124 context.stepCallback();
1125 }
1126}
1127
1128// this is the callback used when navigating in extension pages
1129static void extensionNavigate(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
1130{
1132 UNUSED(stepCtx);
1133
1134 if (event == BUTTON_LEFT_PRESSED) {
1135 // only decrement page if we are not at the first page
1136 if (context.review.currentExtensionPage > 0) {
1137 context.review.currentExtensionPage--;
1138 }
1140 }
1141 else if (event == BUTTON_RIGHT_PRESSED) {
1142 // only increment page if not at last page
1143 if (context.review.currentExtensionPage < (context.review.nbExtensionPages - 1)) {
1144 context.review.currentExtensionPage++;
1145 }
1147 }
1148 else if (event == BUTTON_BOTH_PRESSED) {
1149 // if at last page, leave modal context
1150 if (context.review.currentExtensionPage == (context.review.nbExtensionPages - 1)) {
1151 nbgl_stepRelease(context.review.extensionStepCtx);
1153 nbgl_refresh();
1154 }
1155 return;
1156 }
1157 else {
1158 return;
1159 }
1160 displayExtensionStep(pos);
1161}
1162
1163// function used to display the extension pages
1164static void displayExtensionStep(nbgl_stepPosition_t pos)
1165{
1166 nbgl_layoutCenteredInfo_t info = {0};
1167 const nbgl_contentTagValueList_t *tagValueList = NULL;
1168 const nbgl_contentInfoList_t *infoList = NULL;
1169 const char *text = NULL;
1170 const char *subText = NULL;
1171 uint8_t nbMaxLines = 0;
1172
1173 if (context.review.extensionStepCtx != NULL) {
1174 nbgl_stepRelease(context.review.extensionStepCtx);
1175 context.review.extensionStepCtx = NULL;
1176 }
1177 if (context.review.currentExtensionPage < (context.review.nbExtensionPages - 1)) {
1178 // title is only documented for QR Code aliases, so for ENS and Address Book aliases,
1179 // fall back to the displayed alias value (as on touchscreen devices) if not provided
1180 const char *aliasHeading = (context.review.extension->title != NULL)
1181 ? context.review.extension->title
1182 : context.review.aliasValue;
1183
1184 if (context.review.currentExtensionPage == 0) {
1185 pos |= FIRST_STEP;
1186 }
1187 else {
1189 }
1190
1191 switch (context.review.extension->aliasType) {
1192 case ENS_ALIAS:
1193 text = aliasHeading;
1194 subText = context.review.extension->fullValue;
1195 break;
1196 case ADDRESS_BOOK_ALIAS: {
1197 bool has_scope = (context.review.extension->aliasSubName != NULL);
1198 bool has_tn = (context.review.extension->explanation != NULL);
1199 uint8_t page = (uint8_t) context.review.currentExtensionPage;
1200 if (page == 0) {
1201 text = aliasHeading;
1202 subText = has_scope ? context.review.extension->aliasSubName
1203 : context.review.extension->fullValue;
1204 }
1205 else if (has_scope && page == 1) {
1206 text = aliasHeading;
1207 subText = context.review.extension->fullValue;
1208 }
1209 else if (has_tn) {
1210 text = context.review.extension->explanation;
1211 }
1212 break;
1213 }
1214 case INFO_LIST_ALIAS:
1215 infoList = context.review.extension->infolist;
1216 text = PIC(infoList->infoTypes[context.review.currentExtensionPage]);
1217 subText = PIC(infoList->infoContents[context.review.currentExtensionPage]);
1218 break;
1219 case TAG_VALUE_LIST_ALIAS: {
1220 // the pair may be retrieved with the callback of the list (when pairs is NULL)
1221 const nbgl_contentValueExt_t *pairExtension;
1222 const nbgl_icon_details_t *pairIcon;
1223 bool pairIsCenteredInfo = false;
1224
1225 tagValueList = context.review.extension->tagValuelist;
1226 // these values are tag/value pairs, so their max number of lines applies
1227 getPairData(tagValueList,
1228 (uint8_t) context.review.currentExtensionPage,
1229 &text,
1230 &subText,
1231 &pairExtension,
1232 &pairIcon,
1233 &pairIsCenteredInfo,
1234 &nbMaxLines);
1235 text = PIC(text);
1236 subText = PIC(subText);
1237 break;
1238 }
1239 default:
1240 break;
1241 }
1242 if (text != NULL) {
1243 context.review.extensionStepCtx = stepDrawText(
1244 pos, extensionNavigate, NULL, text, subText, BOLD_TEXT1_INFO, true, nbMaxLines);
1245 }
1246 }
1247 else if (context.review.currentExtensionPage == (context.review.nbExtensionPages - 1)) {
1248 // draw the back page
1249 info.icon = &C_icon_back_x;
1250 info.text1 = "Back";
1251 info.style = BOLD_TEXT1_INFO;
1252 pos |= LAST_STEP;
1253 context.review.extensionStepCtx
1254 = nbgl_stepDrawCenteredInfo(pos, extensionNavigate, NULL, &info, true);
1255 }
1256 nbgl_refresh();
1257}
1258
1259static void displayAliasFullValue(void)
1260{
1261 const char *text = NULL;
1262 const char *subText = NULL;
1263 const nbgl_icon_details_t *icon;
1264 bool isCenteredInfo;
1265
1266 getPairData(context.review.tagValueList,
1267 context.review.currentTagValueIndex,
1268 &text,
1269 &subText,
1270 &context.review.extension,
1271 &icon,
1272 &isCenteredInfo,
1273 NULL);
1274 if (context.review.extension == NULL) {
1275 // probably an error
1277 "displayAliasFullValue: extension nor found for pair %d\n",
1278 context.review.currentTagValueIndex);
1279 return;
1280 }
1281 context.review.currentExtensionPage = 0;
1282 context.review.extensionStepCtx = NULL;
1283 context.review.aliasValue = (subText != NULL) ? PIC(subText) : "";
1284 // create a modal flow to display this extension
1285 switch (context.review.extension->aliasType) {
1286 case ENS_ALIAS:
1287 context.review.nbExtensionPages = 2;
1288 break;
1289 case ADDRESS_BOOK_ALIAS:
1290 context.review.nbExtensionPages
1291 = 2 + ((context.review.extension->aliasSubName != NULL) ? 1 : 0)
1292 + ((context.review.extension->explanation != NULL) ? 1 : 0);
1293 break;
1294 case INFO_LIST_ALIAS:
1295 case TAG_VALUE_LIST_ALIAS: {
1296 // such details are rejected when starting the review (see isAliasDetailsComplete()),
1297 // but nothing must be drawn from them anyway
1298 uint8_t nbElements = 0;
1299 if (context.review.extension->aliasType == INFO_LIST_ALIAS) {
1300 const nbgl_contentInfoList_t *infoList = PIC(context.review.extension->infolist);
1301 nbElements = (infoList != NULL) ? infoList->nbInfos : 0;
1302 }
1303 else {
1304 const nbgl_contentTagValueList_t *aliasList
1305 = PIC(context.review.extension->tagValuelist);
1306 nbElements = (aliasList != NULL) ? aliasList->nbPairs : 0;
1307 }
1308 if (nbElements == 0) {
1309 LOG_WARN(USE_CASE_LOGGER, "displayAliasFullValue: no details to display\n");
1310 return;
1311 }
1312 // 1 page per element + 1 back page
1313 context.review.nbExtensionPages = (uint16_t) nbElements + 1;
1314 break;
1315 }
1316 default:
1318 "displayAliasFullValue: unsupported alias type %d\n",
1319 context.review.extension->aliasType);
1320 return;
1321 }
1322 displayExtensionStep(FORWARD_DIRECTION);
1323}
1324
1325static void getLastPageInfo(bool approve, const nbgl_icon_details_t **icon, const char **text)
1326{
1327 if (approve) {
1328 // Approve page
1329 *icon = &C_icon_validate_14;
1330 if (context.operationType & ADDRESS_BOOK_OPERATION) {
1331 if ((context.type == REVIEW_USE_CASE) && (context.review.finishTitle != NULL)) {
1332 *text = context.review.finishTitle;
1333 }
1334 else {
1335 *text = "Confirm contact details";
1336 }
1337 }
1338 else if (context.type == ADDRESS_REVIEW_USE_CASE) {
1339 *text = "Confirm";
1340 }
1341 else {
1342 // if finish title is provided, use it
1343 if (context.review.finishTitle != NULL) {
1344 *text = context.review.finishTitle;
1345 }
1346 else {
1347 switch (context.operationType & REAL_TYPE_MASK) {
1348 case TYPE_TRANSACTION:
1349 if (context.operationType & RISKY_OPERATION) {
1350 *text = "Accept risk and sign transaction";
1351 }
1352 else {
1353 *text = "Sign transaction";
1354 }
1355 break;
1356 case TYPE_MESSAGE:
1357 if (context.operationType & RISKY_OPERATION) {
1358 *text = "Accept risk and sign message";
1359 }
1360 else {
1361 *text = "Sign message";
1362 }
1363 break;
1364 default:
1365 if (context.operationType & RISKY_OPERATION) {
1366 *text = "Accept risk and sign operation";
1367 }
1368 else {
1369 *text = "Sign operation";
1370 }
1371 break;
1372 }
1373 }
1374 }
1375 context.stepCallback = onReviewAccept;
1376 }
1377 else {
1378 // Reject page
1379 *icon = &C_icon_crossmark;
1380 if ((context.type == ADDRESS_REVIEW_USE_CASE)
1381 || (context.operationType & ADDRESS_BOOK_OPERATION)) {
1382 *text = "Cancel";
1383 }
1384 else if ((context.operationType & REAL_TYPE_MASK) == TYPE_TRANSACTION) {
1385 *text = "Reject transaction";
1386 }
1387 else if ((context.operationType & REAL_TYPE_MASK) == TYPE_MESSAGE) {
1388 *text = "Reject message";
1389 }
1390 else {
1391 *text = "Reject operation";
1392 }
1393 context.stepCallback = onReviewReject;
1394 }
1395}
1396
1397// function used to display the current page in review
1398static void displayReviewPage(nbgl_stepPosition_t pos)
1399{
1400 uint8_t reviewPages = 0;
1401 uint8_t finalPages = 0;
1402 uint8_t pairIndex = 0;
1403 const char *text = NULL;
1404 const char *subText = NULL;
1405 const nbgl_icon_details_t *icon = NULL;
1406 uint8_t currentIndex = 0;
1407 uint8_t titleIndex = 255;
1408 uint8_t subIndex = 255;
1409 uint8_t approveIndex = 255;
1410 uint8_t rejectIndex = 255;
1411 const nbgl_contentValueExt_t *extension = NULL;
1412 ForcedType_t forcedType = NO_FORCED_TYPE;
1413 uint8_t nbMaxLines = 0;
1414
1415 context.stepCallback = NULL;
1416
1417 // Determine the 1st page to display tag/values
1418 // Title page to display
1419 titleIndex = currentIndex++;
1420 reviewPages++;
1421 if (context.review.reviewSubTitle) {
1422 // subtitle page to display
1423 subIndex = currentIndex++;
1424 reviewPages++;
1425 }
1426 approveIndex = context.nbPages - 2;
1427 rejectIndex = context.nbPages - 1;
1428 finalPages = approveIndex;
1429
1430 // Determine which page to display
1431 if (context.currentPage >= finalPages) {
1432 if (context.currentPage == approveIndex) {
1433 // Approve page
1434 getLastPageInfo(true, &icon, &text);
1435 }
1436 else if (context.currentPage == rejectIndex) {
1437 // Reject page
1438 getLastPageInfo(false, &icon, &text);
1439 }
1440 }
1441 else if (context.currentPage < reviewPages) {
1442 if (context.currentPage == titleIndex) {
1443 // Title page
1444 icon = context.review.icon;
1445 text = context.review.reviewTitle;
1446 }
1447 else if (context.currentPage == subIndex) {
1448 // SubTitle page
1449 text = context.review.reviewSubTitle;
1450 }
1451 }
1452 else if ((context.review.address != NULL) && (context.currentPage == reviewPages)) {
1453 // address confirmation and 2nd page
1454 text = "Address";
1455 subText = context.review.address;
1456 }
1457 else {
1458 // if there is a skip, and we are not already displaying the "skip" page
1459 // and we are not at the first tag/value of the first set of data (except if going
1460 // backward) then display the "skip" page
1461 if ((context.operationType & SKIPPABLE_OPERATION) && (context.review.skipDisplay == false)
1462 && ((context.currentPage > reviewPages)
1463 || (context.review.dataDirection == BACKWARD_DIRECTION))) {
1465 nbgl_layoutCenteredInfo_t info = {0};
1466 if ((context.review.nbDataSets == 1) || (context.currentPage > 0)) {
1467 directions |= LAST_STEP;
1468 }
1469 info.icon = &C_Information_circle_14px;
1470 info.text1 = "Press right button to continue message or \bpress both to skip\b";
1471 nbgl_stepDrawCenteredInfo(directions, buttonSkipCallback, NULL, &info, false);
1472 nbgl_refresh();
1473 context.review.skipDisplay = true;
1474 context.firstPairPage = reviewPages;
1475 return;
1476 }
1477 context.review.skipDisplay = false;
1478 bool isCenteredInfo = false;
1479 pairIndex = context.currentPage - reviewPages;
1480 if (context.review.address != NULL) {
1481 pairIndex--;
1482 }
1483 getPairData(context.review.tagValueList,
1484 pairIndex,
1485 &text,
1486 &subText,
1487 &extension,
1488 &icon,
1489 &isCenteredInfo,
1490 &nbMaxLines);
1491 if (extension != NULL) {
1492 context.stepCallback = displayAliasFullValue;
1493 context.review.currentTagValueIndex = pairIndex;
1494 forcedType = FORCE_BUTTON;
1495 }
1496 else {
1497 if (isCenteredInfo) {
1498 forcedType = FORCE_CENTERED_INFO;
1499 }
1500 }
1501 }
1502
1503 drawStep(pos, icon, text, subText, nbMaxLines, reviewCallback, false, forcedType, false);
1504 nbgl_refresh();
1505}
1506
1507// function used to display the current page in review
1508static void displayStreamingReviewPage(nbgl_stepPosition_t pos)
1509{
1510 const char *text = NULL;
1511 const char *subText = NULL;
1512 const nbgl_icon_details_t *icon = NULL;
1513 uint8_t reviewPages = 0;
1514 uint8_t titleIndex = 255;
1515 uint8_t subIndex = 255;
1516 const nbgl_contentValueExt_t *extension = NULL;
1517 ForcedType_t forcedType = NO_FORCED_TYPE;
1518 uint8_t nbMaxLines = 0;
1519
1520 context.stepCallback = NULL;
1521 switch (context.type) {
1522 case STREAMING_START_REVIEW_USE_CASE:
1523 // Title page to display
1524 titleIndex = reviewPages++;
1525 if (context.review.reviewSubTitle) {
1526 // subtitle page to display
1527 subIndex = reviewPages++;
1528 }
1529 // Determine which page to display
1530 if (context.currentPage >= reviewPages) {
1531 onReviewAccept();
1532 return;
1533 }
1534 // header page(s)
1535 if (context.currentPage == titleIndex) {
1536 // title page
1537 icon = context.review.icon;
1538 text = context.review.reviewTitle;
1539 }
1540 else if (context.currentPage == subIndex) {
1541 // subtitle page
1542 text = context.review.reviewSubTitle;
1543 }
1544 break;
1545
1546 case STREAMING_CONTINUE_REVIEW_USE_CASE:
1547 if (context.currentPage >= context.review.tagValueList->nbPairs) {
1548 onReviewAccept();
1549 return;
1550 }
1551 // if there is a skip, and we are not already displaying the "skip" page
1552 // and we are not at the first tag/value of the first set of data (except if going
1553 // backward) then display the "skip" page
1554 if ((context.review.skipCallback != NULL) && (context.review.skipDisplay == false)
1555 && ((context.review.nbDataSets > 1) || (context.currentPage > 0)
1556 || (context.review.dataDirection == BACKWARD_DIRECTION))) {
1558 nbgl_layoutCenteredInfo_t info = {0};
1559 if ((context.review.nbDataSets == 1) || (context.currentPage > 0)) {
1560 directions |= LAST_STEP;
1561 }
1562 info.icon = &C_Information_circle_14px;
1563 info.text1 = "Press right button to continue message or \bpress both to skip\b";
1564 nbgl_stepDrawCenteredInfo(directions, buttonSkipCallback, NULL, &info, false);
1565 nbgl_refresh();
1566 context.review.skipDisplay = true;
1567 return;
1568 }
1569 context.review.skipDisplay = false;
1570 bool isCenteredInfo = false;
1571 getPairData(context.review.tagValueList,
1572 context.currentPage,
1573 &text,
1574 &subText,
1575 &extension,
1576 &icon,
1577 &isCenteredInfo,
1578 &nbMaxLines);
1579 if (extension != NULL) {
1580 // allow the user to review the full value behind the alias, as in non-streaming
1581 // review
1582 context.stepCallback = displayAliasFullValue;
1583 context.review.currentTagValueIndex = context.currentPage;
1584 forcedType = FORCE_BUTTON;
1585 }
1586 else {
1587 if (isCenteredInfo) {
1588 forcedType = FORCE_CENTERED_INFO;
1589 }
1590 }
1591 break;
1592
1593 case STREAMING_FINISH_REVIEW_USE_CASE:
1594 default:
1595 if (context.currentPage == 0) {
1596 // accept page
1597 getLastPageInfo(true, &icon, &text);
1598 }
1599 else {
1600 // reject page
1601 getLastPageInfo(false, &icon, &text);
1602 }
1603 break;
1604 }
1605
1606 drawStep(
1607 pos, icon, text, subText, nbMaxLines, streamingReviewCallback, false, forcedType, false);
1608 nbgl_refresh();
1609}
1610
1611// function used to display the current page in info
1612static void displayInfoPage(nbgl_stepPosition_t pos)
1613{
1614 const char *text = NULL;
1615 const char *subText = NULL;
1616 const nbgl_icon_details_t *icon = NULL;
1617
1618 context.stepCallback = NULL;
1619
1620 if (context.currentPage < (context.nbPages - 1)) {
1621 text = PIC(
1622 ((const char *const *) PIC(context.home.infosList->infoTypes))[context.currentPage]);
1623 subText = PIC(
1624 ((const char *const *) PIC(context.home.infosList->infoContents))[context.currentPage]);
1625 }
1626 else {
1627 icon = &C_icon_back_x;
1628 text = "Back";
1629 context.stepCallback = startUseCaseHome;
1630 }
1631
1632 drawStep(pos, icon, text, subText, 0, infoCallback, false, FORCE_CENTERED_INFO, false);
1633 nbgl_refresh();
1634}
1635
1636// function used to get the current page content
1637static void getContentPage(bool toogle_state, PageContent_t *contentPage)
1638{
1639 uint8_t elemIdx = 0;
1640 const nbgl_content_t *p_content = NULL;
1641 nbgl_content_t content = {0};
1642 nbgl_contentSwitch_t *contentSwitch = NULL;
1643 nbgl_contentRadioChoice_t *contentChoices = NULL;
1644 char **names = NULL;
1645 nbgl_contentBarsList_t *contentBars = NULL;
1646 char **texts = NULL;
1647 p_content = getContentElemAtIdx(context.currentPage, &elemIdx, &content);
1648 if (p_content == NULL) {
1650 "getContentPage(): p_content is NULL for page %d\n",
1651 context.currentPage);
1652 return;
1653 }
1654 switch (p_content->type) {
1655 case CENTERED_INFO:
1656 contentPage->text = PIC(p_content->content.centeredInfo.text1);
1657 contentPage->subText = PIC(p_content->content.centeredInfo.text2);
1658 contentPage->icon = PIC(p_content->content.centeredInfo.icon);
1659 contentPage->bottomIcon = p_content->content.centeredInfo.bottomIcon;
1660 break;
1661 case INFO_BUTTON:
1662 contentPage->icon = PIC(p_content->content.infoButton.icon);
1663 contentPage->text = PIC(p_content->content.infoButton.text);
1664 contentPage->subText = PIC(p_content->content.infoButton.buttonText);
1665 contentPage->bottomIcon = p_content->content.infoButton.bottomIcon;
1666 break;
1667 case TAG_VALUE_LIST:
1668 getPairData(&p_content->content.tagValueList,
1669 elemIdx,
1670 &contentPage->text,
1671 &contentPage->subText,
1672 &contentPage->extension,
1673 &contentPage->icon,
1674 &contentPage->isCenteredInfo,
1675 &contentPage->nbMaxLinesForSubText);
1676 break;
1677 case TAG_VALUE_CONFIRM:
1678 if (elemIdx < p_content->content.tagValueConfirm.tagValueList.nbPairs) {
1679 getPairData(&p_content->content.tagValueConfirm.tagValueList,
1680 elemIdx,
1681 &contentPage->text,
1682 &contentPage->subText,
1683 &contentPage->extension,
1684 &contentPage->icon,
1685 &contentPage->isCenteredInfo,
1686 &contentPage->nbMaxLinesForSubText);
1687 }
1688 else {
1689 contentPage->text = p_content->content.tagValueConfirm.confirmationText;
1690 contentPage->icon = &C_icon_validate_14;
1691 contentPage->isAction = true;
1692 }
1693 break;
1694 case SWITCHES_LIST:
1695 contentPage->isSwitch = true;
1696 contentSwitch = &(
1697 (nbgl_contentSwitch_t *) PIC(p_content->content.switchesList.switches))[elemIdx];
1698 contentPage->text = contentSwitch->text;
1699 contentPage->state = contentSwitch->initState;
1700 if (toogle_state) {
1701 contentPage->state = (contentPage->state == ON_STATE) ? OFF_STATE : ON_STATE;
1702 }
1703 context.stepCallback = onSwitchAction;
1704 contentPage->subText = contentSwitch->subText;
1705 break;
1706 case INFOS_LIST:
1707 contentPage->text
1708 = ((const char *const *) PIC(p_content->content.infosList.infoTypes))[elemIdx];
1709 contentPage->subText
1710 = ((const char *const *) PIC(p_content->content.infosList.infoContents))[elemIdx];
1711 break;
1712 case CHOICES_LIST:
1713 contentChoices = (nbgl_contentRadioChoice_t *) PIC(&p_content->content.choicesList);
1714 // When the content opts into the vertical layout, leave
1715 // contentPage->text NULL so drawStep falls through to the menu-list
1716 // rendering (all choices visible, with a radio button on
1717 // initChoice). Default is the horizontal one-page-per-choice flow.
1718 if (contentChoices->vertical) {
1719 break;
1720 }
1721 names = (char **) PIC(contentChoices->names);
1722 // The caller-provided per-content title wins over the contextual
1723 // fallback (app name / use case title).
1724 if (contentChoices->title != NULL) {
1725 contentPage->text = PIC(contentChoices->title);
1726 contentPage->subText = (const char *) PIC(names[elemIdx]);
1727 }
1728 else if ((context.type == CONTENT_USE_CASE) && (context.content.title != NULL)) {
1729 contentPage->text = PIC(context.content.title);
1730 contentPage->subText = (const char *) PIC(names[elemIdx]);
1731 }
1732 else if (((context.type == GENERIC_SETTINGS) || (context.type == SETTINGS_USE_CASE))
1733 && (context.home.appName != NULL)) {
1734 // Both nbgl_useCaseGenericSettings (GENERIC_SETTINGS) and
1735 // nbgl_useCaseHomeAndSettings -> Settings (SETTINGS_USE_CASE)
1736 // populate context.home.appName, so use it as the page title
1737 // for the latter too -- otherwise a horizontally-paged
1738 // CHOICES_LIST would render the choice name only with no
1739 // contextual header at all.
1740 contentPage->text = PIC(context.home.appName);
1741 contentPage->subText = (const char *) PIC(names[elemIdx]);
1742 }
1743 else {
1744 contentPage->text = (const char *) PIC(names[elemIdx]);
1745 }
1746 // Mark the currently-selected choice with the caller-provided icon
1747 // placed at the bottom of the screen (see contentCenteredInfo
1748 // bottomIcon handling in nbgl_layoutAddCenteredInfo). Skipped when
1749 // the caller did not opt in.
1750 if ((contentChoices->selectionIcon != NULL)
1751 && (elemIdx == contentChoices->initChoice)) {
1752 contentPage->icon = PIC(contentChoices->selectionIcon);
1753 contentPage->bottomIcon = true;
1754 }
1755 break;
1756 case BARS_LIST:
1757 contentBars = (nbgl_contentBarsList_t *) PIC(&p_content->content.barsList);
1758 if (contentBars->vertical) {
1759 break; // see CHOICES_LIST comment above
1760 }
1761 texts = (char **) PIC(contentBars->barTexts);
1762 // Same precedence as CHOICES_LIST: caller-provided title overrides
1763 // the contextual fallback.
1764 if (contentBars->title != NULL) {
1765 contentPage->text = PIC(contentBars->title);
1766 contentPage->subText = PIC(texts[elemIdx]);
1767 }
1768 else if ((context.type == CONTENT_USE_CASE) && (context.content.title != NULL)) {
1769 contentPage->text = PIC(context.content.title);
1770 contentPage->subText = PIC(texts[elemIdx]);
1771 }
1772 else if ((context.type == GENERIC_SETTINGS) && (context.home.appName != NULL)) {
1773 contentPage->text = PIC(context.home.appName);
1774 contentPage->subText = PIC(texts[elemIdx]);
1775 }
1776 else {
1777 contentPage->text = PIC(texts[elemIdx]);
1778 }
1779 // Sub-menu indicator: always pinned at the bottom of every bar's
1780 // page. Mirrors the hardcoded PUSH_ICON ('>') that Stax/Flex draw
1781 // on the right of touchable bars (see nbgl_page.c). On Nano the
1782 // right button is reserved for navigation, so we pick a downward
1783 // chevron and place it at the screen bottom via the centeredInfo
1784 // bottomIcon path.
1785 contentPage->icon = &C_icon_down;
1786 contentPage->bottomIcon = true;
1787 break;
1788 default:
1789 break;
1790 }
1791}
1792
1793// function used to display the current page in settings
1794static void displaySettingsPage(nbgl_stepPosition_t pos, bool toogle_state)
1795{
1796 PageContent_t contentPage = {0};
1797
1798 context.stepCallback = NULL;
1799
1800 if (context.currentPage < (context.nbPages - 1)) {
1801 getContentPage(toogle_state, &contentPage);
1802 }
1803 else { // last page is for quit
1804 contentPage.icon = &C_icon_back_x;
1805 contentPage.text = "Back";
1806 if (context.type == GENERIC_SETTINGS) {
1807 context.stepCallback = context.home.quitCallback;
1808 }
1809 else {
1810 context.stepCallback = startUseCaseHome;
1811 }
1812 }
1813
1814 if (contentPage.isSwitch) {
1815 drawSwitchStep(
1816 pos, contentPage.text, contentPage.subText, contentPage.state, settingsCallback, false);
1817 }
1818 else {
1819 drawStep(pos,
1820 contentPage.icon,
1821 contentPage.text,
1822 contentPage.subText,
1823 contentPage.nbMaxLinesForSubText,
1824 settingsCallback,
1825 false,
1826 NO_FORCED_TYPE,
1827 contentPage.bottomIcon);
1828 }
1829
1830 nbgl_refresh();
1831}
1832
1833static void startUseCaseHome(void)
1834{
1835 switch (context.type) {
1836 case SETTINGS_USE_CASE:
1837 // Settings page index
1838 context.currentPage = 1;
1839 if (context.home.homeAction) {
1840 // Action page is before Settings page
1841 context.currentPage++;
1842 }
1843 break;
1844 case INFO_USE_CASE:
1845 // Info page index
1846 context.currentPage = 1;
1847 if (context.home.homeAction) {
1848 // Action page is before Settings and Info pages
1849 context.currentPage++;
1850 }
1851 if (context.home.settingContents) {
1852 // Settings page is before Info pages
1853 context.currentPage++;
1854 }
1855 break;
1856 default:
1857 // Home page index
1858 context.currentPage = 0;
1859 break;
1860 }
1861
1862 context.type = HOME_USE_CASE;
1863 context.nbPages = 2; // Home + Quit
1864 if (context.home.settingContents) {
1865 context.nbPages++;
1866 }
1867 if (context.home.infosList) {
1868 context.nbPages++;
1869 }
1870 if (context.home.homeAction) {
1871 context.nbPages++;
1872 }
1873 displayHomePage(FORWARD_DIRECTION);
1874}
1875
1876static void startUseCaseInfo(void)
1877{
1878 context.type = INFO_USE_CASE;
1879 context.nbPages = context.home.infosList->nbInfos + 1; // For back screen
1880 context.currentPage = 0;
1881
1882 displayInfoPage(FORWARD_DIRECTION);
1883}
1884
1885static void startUseCaseSettingsAtPage(uint8_t initSettingPage)
1886{
1887 nbgl_content_t content = {0};
1888 const nbgl_content_t *p_content = NULL;
1889
1890 // if not coming from GENERIC_SETTINGS, force to SETTINGS_USE_CASE
1891 if (context.type != GENERIC_SETTINGS) {
1892 context.type = SETTINGS_USE_CASE;
1893 }
1894
1895 uint16_t nbPages = 1; // For back screen
1896 for (unsigned int i = 0; i < context.home.settingContents->nbContents; i++) {
1897 p_content = getContentAtIdx(context.home.settingContents, i, &content);
1898 nbPages += getContentNbElement(p_content);
1899 if (nbPages > UINT8_MAX) {
1900 if (context.type == SETTINGS_USE_CASE) {
1901 startUseCaseHome();
1902 }
1903 else if (context.home.quitCallback != NULL) {
1904 context.home.quitCallback();
1905 }
1906 return;
1907 }
1908 }
1909 context.nbPages = (uint8_t) nbPages;
1910 context.currentPage = initSettingPage;
1911
1912 displaySettingsPage(FORWARD_DIRECTION, false);
1913}
1914
1915static void startUseCaseSettings(void)
1916{
1917 startUseCaseSettingsAtPage(0);
1918}
1919
1920static void startUseCaseContent(void)
1921{
1922 uint8_t contentIdx = 0;
1923 const nbgl_content_t *p_content = NULL;
1924 nbgl_content_t content = {0};
1925
1926 uint16_t nbPages = 1; // Quit
1927
1928 for (contentIdx = 0; contentIdx < context.content.genericContents.nbContents; contentIdx++) {
1929 p_content = getContentAtIdx(&context.content.genericContents, contentIdx, &content);
1930 nbPages += getContentNbElement(p_content);
1931 if ((nbPages > UINT8_MAX) || !isContentComplete(p_content)) {
1932 if (context.content.quitCallback != NULL) {
1933 context.content.quitCallback();
1934 }
1935 return;
1936 }
1937 }
1938 context.nbPages = (uint8_t) nbPages;
1939
1940 // Ensure currentPage is valid
1941 if (context.currentPage >= context.nbPages) {
1942 return;
1943 }
1944
1945 displayContent(FORWARD_DIRECTION, false);
1946}
1947
1948// function used to display the current page in home
1949static void displayHomePage(nbgl_stepPosition_t pos)
1950{
1951 const char *text = NULL;
1952 const char *subText = NULL;
1953 const nbgl_icon_details_t *icon = NULL;
1954 uint8_t currentIndex = 0;
1955 uint8_t homeIndex = 255;
1956 uint8_t actionIndex = 255;
1957 uint8_t settingsIndex = 255;
1958 uint8_t infoIndex = 255;
1959
1960 context.stepCallback = NULL;
1961
1962 // Determine which pages are present
1963 homeIndex = currentIndex++;
1964 if (context.home.homeAction) {
1965 actionIndex = currentIndex++;
1966 }
1967 if (context.home.settingContents) {
1968 settingsIndex = currentIndex++;
1969 }
1970 if (context.home.infosList) {
1971 infoIndex = currentIndex++;
1972 }
1973
1974 if (context.currentPage == homeIndex) {
1975 // Home page
1976 icon = context.home.appIcon;
1977 if (context.home.tagline != NULL) {
1978 text = context.home.tagline;
1979 }
1980 else {
1981 text = context.home.appName;
1982 subText = "app is ready";
1983 }
1984 }
1985 else if (context.currentPage == actionIndex) {
1986 // Action page
1987 icon = context.home.homeAction->icon;
1988 text = PIC(context.home.homeAction->text);
1989 context.stepCallback = context.home.homeAction->callback;
1990 }
1991 else if (context.currentPage == settingsIndex) {
1992 // Settings page
1993 icon = &C_icon_coggle;
1994 text = "App settings";
1995 context.stepCallback = startUseCaseSettings;
1996 }
1997 else if (context.currentPage == infoIndex) {
1998 // About page
1999 icon = &C_Information_circle_14px;
2000 text = "App info";
2001 context.stepCallback = startUseCaseInfo;
2002 }
2003 else {
2004 icon = &C_Quit_14px;
2005 text = "Quit app";
2006 context.stepCallback = context.home.quitCallback;
2007 }
2008
2009 drawStep(pos, icon, text, subText, 0, homeCallback, false, NO_FORCED_TYPE, false);
2010 nbgl_refresh();
2011}
2012
2013// An intro page of a choice flow displays the header text and, below it, at most one other
2014// element, as a step cannot hold more. Those elements take one page each, in this order:
2015// 1. the icon, if any
2016// 2. the message, when the advanced flow uses the title as header text
2017// 3. the subMessage, if any
2018// The header text is the title of the advanced flow, or the message of the basic one, in which
2019// case only the subMessage is left below it.
2020
2021// Number of pages displayed before the (optional) detail pages and the confirm/cancel ones.
2022static uint8_t getChoiceNbIntroPages(void)
2023{
2024 uint8_t nbPages = 0;
2025
2026 // no intro at all without a header text
2027 if ((context.choice.title == NULL) && (context.choice.message == NULL)) {
2028 return 0;
2029 }
2030 if (context.choice.icon != NULL) {
2031 nbPages++;
2032 }
2033 if ((context.choice.title != NULL) && (context.choice.message != NULL)) {
2034 nbPages++;
2035 }
2036 if (context.choice.subMessage != NULL) {
2037 nbPages++;
2038 }
2039 // the header text still needs a page of its own when nothing goes below it
2040 return (nbPages > 0) ? nbPages : 1;
2041}
2042
2043// Text to display under the header text on the given (0-based) intro page, NULL if this page
2044// displays the icon instead, or if nothing is left to display below the header.
2045static const char *getChoiceIntroSubText(uint8_t page)
2046{
2047 // Page holding the element being examined. The elements are walked in display order and each
2048 // one that is given takes a page, pushing the following ones one page further: when elemPage
2049 // reaches the requested page, the element examined at that point is the one to display.
2050 uint8_t elemPage = 0;
2051
2052 if (context.choice.icon != NULL) {
2053 if (page == elemPage) {
2054 // the icon takes the whole page next to the header text
2055 return NULL;
2056 }
2057 elemPage++;
2058 }
2059 if ((context.choice.title != NULL) && (context.choice.message != NULL)) {
2060 // in the advanced flow the header text is the title, so the message goes below it
2061 if (page == elemPage) {
2062 return context.choice.message;
2063 }
2064 elemPage++;
2065 }
2066 // the subMessage closes the intro, on the last page
2067 return (page == elemPage) ? context.choice.subMessage : NULL;
2068}
2069
2070// function used to display the current page in choice
2071static void displayChoicePage(nbgl_stepPosition_t pos)
2072{
2073 const char *text = NULL;
2074 const char *subText = NULL;
2075 const nbgl_icon_details_t *icon = NULL;
2076 // acceptPage = number of intro pages, see getChoiceNbIntroPages()
2077 uint8_t acceptPage = getChoiceNbIntroPages();
2078 // nbDetailPages = number of BAR_LIST bar pages shown before confirm/cancel (0 if none)
2079 // Page order: intro(s) | bar pages | confirm | cancel
2080 uint8_t nbDetailPages = 0;
2081
2082 if ((context.choice.details != NULL) && (context.choice.details->type == BAR_LIST_WARNING)) {
2083 nbDetailPages = context.choice.details->barList.nbBars;
2084 }
2085 context.stepCallback = NULL;
2086
2087 if (context.currentPage < acceptPage) {
2088 // the header text is repeated on every intro page, the icon (if any) is on the first one
2089 // and each remaining text gets a page of its own, see getChoiceIntroSubText()
2090 text = (context.choice.title != NULL) ? context.choice.title : context.choice.message;
2091 if (context.currentPage == 0) {
2092 icon = context.choice.icon;
2093 }
2094 subText = getChoiceIntroSubText(context.currentPage);
2095 }
2096 else if (context.currentPage < (acceptPage + nbDetailPages)) {
2097 // BAR_LIST detail pages, shown before confirm/cancel (one page per bar)
2098 uint8_t idx = context.currentPage - acceptPage;
2099 text = (context.choice.details->barList.texts != NULL)
2100 ? context.choice.details->barList.texts[idx]
2101 : NULL;
2102 subText = (context.choice.details->barList.subTexts != NULL)
2103 ? context.choice.details->barList.subTexts[idx]
2104 : NULL;
2105 }
2106 else if (context.currentPage == (acceptPage + nbDetailPages)) { // confirm page
2107 icon = &C_icon_validate_14;
2108 text = context.choice.confirmText;
2109 context.stepCallback = onChoiceAccept;
2110 }
2111 else { // cancel page (last page)
2112 icon = &C_icon_crossmark;
2113 text = context.choice.cancelText;
2114 context.stepCallback = onChoiceReject;
2115 }
2116 // other detail types (non-BAR_LIST) are not navigated on Nano
2117
2118 drawStep(pos, icon, text, subText, 0, genericChoiceCallback, false, NO_FORCED_TYPE, false);
2119 nbgl_refresh();
2120}
2121
2122// function used to display the Confirm page
2123static void displayConfirm(nbgl_stepPosition_t pos)
2124{
2125 const char *text = NULL;
2126 const char *subText = NULL;
2127 const nbgl_icon_details_t *icon = NULL;
2128
2129 context.stepCallback = NULL;
2130 switch (context.currentPage) {
2131 case 0:
2132 // title page
2133 text = context.confirm.message;
2134 subText = context.confirm.subMessage;
2135 break;
2136 case 1:
2137 // confirm page
2138 icon = &C_icon_validate_14;
2139 text = context.confirm.confirmText;
2140 context.stepCallback = onConfirmAccept;
2141 break;
2142 case 2:
2143 // cancel page
2144 icon = &C_icon_crossmark;
2145 text = context.confirm.cancelText;
2146 context.stepCallback = onConfirmReject;
2147 break;
2148 }
2149
2150 drawStep(pos, icon, text, subText, 0, genericConfirmCallback, true, NO_FORCED_TYPE, false);
2151 nbgl_refresh();
2152}
2153
2154// function used to display the current navigable content
2155static void displayContent(nbgl_stepPosition_t pos, bool toogle_state)
2156{
2157 PageContent_t contentPage = {0};
2158 ForcedType_t forcedType = NO_FORCED_TYPE;
2159
2160 context.stepCallback = NULL;
2161
2162 if (context.currentPage < (context.nbPages - 1)) {
2163 getContentPage(toogle_state, &contentPage);
2164 if (contentPage.isCenteredInfo) {
2165 forcedType = FORCE_CENTERED_INFO;
2166 }
2167 context.forceAction = contentPage.isAction;
2168 }
2169 else { // last page is for quit
2170 if (context.content.rejectText) {
2171 contentPage.text = context.content.rejectText;
2172 }
2173 else {
2174 contentPage.text = "Back";
2175 }
2176 if (context.type == GENERIC_REVIEW_USE_CASE) {
2177 contentPage.icon = &C_icon_crossmark;
2178 }
2179 else {
2180 contentPage.icon = &C_icon_back_x;
2181 }
2182 context.stepCallback = context.content.quitCallback;
2183 }
2184
2185 if (contentPage.isSwitch) {
2186 drawSwitchStep(
2187 pos, contentPage.text, contentPage.subText, contentPage.state, contentCallback, false);
2188 }
2189 else {
2190 drawStep(pos,
2191 contentPage.icon,
2192 contentPage.text,
2193 contentPage.subText,
2194 contentPage.nbMaxLinesForSubText,
2195 contentCallback,
2196 false,
2197 forcedType,
2198 contentPage.bottomIcon);
2199 }
2200 context.forceAction = false;
2201 nbgl_refresh();
2202}
2203
2204static void displaySpinner(const char *text)
2205{
2206 drawStep(SINGLE_STEP, &C_icon_processing, text, NULL, 0, NULL, false, NO_FORCED_TYPE, false);
2207 nbgl_refresh();
2208}
2209
2210// function to factorize code for all simple reviews
2211static void useCaseReview(ContextType_t type,
2212 nbgl_operationType_t operationType,
2213 const nbgl_contentTagValueList_t *tagValueList,
2214 const nbgl_icon_details_t *icon,
2215 const char *reviewTitle,
2216 const char *reviewSubTitle,
2217 const char *finishTitle,
2218 nbgl_choiceCallback_t choiceCallback)
2219{
2220 memset(&context, 0, sizeof(UseCaseContext_t));
2221 context.type = type;
2222 context.operationType = operationType;
2223 context.review.tagValueList = tagValueList;
2224 context.review.reviewTitle = reviewTitle;
2225 context.review.reviewSubTitle = reviewSubTitle;
2226 context.review.finishTitle = finishTitle;
2227 context.review.icon = icon;
2228 context.review.onChoice = choiceCallback;
2229 context.currentPage = 0;
2230 if (tagValueList == NULL) {
2231 onReviewReject();
2232 return;
2233 }
2234 // 1 page for title and 2 pages at the end for accept/reject
2235 uint16_t nbPages = (uint16_t) tagValueList->nbPairs + 3;
2236 if (reviewSubTitle) {
2237 nbPages++; // 1 page for subtitle page
2238 }
2239 if ((nbPages <= UINT8_MAX) && isTagValueListComplete(tagValueList)) {
2240 context.nbPages = (uint8_t) nbPages;
2241 displayReviewPage(FORWARD_DIRECTION);
2242 }
2243 else {
2244 onReviewReject();
2245 }
2246}
2247
2248#ifdef NBGL_KEYPAD
2249static void setPinCodeText(void)
2250{
2251 bool enableValidate = false;
2252 bool enableBackspace = true;
2253
2254 // pin can be validated when min digits is entered
2255 enableValidate = (context.keypad.pinLen >= context.keypad.pinMinDigits);
2256 // backspace is disabled when no digit is entered and back vallback is not provided
2257 enableBackspace = (context.keypad.pinLen > 0) || (context.keypad.backCallback != NULL);
2258 nbgl_layoutUpdateKeypadContent(context.keypad.layoutCtx,
2259 context.keypad.hidden,
2260 context.keypad.pinLen,
2261 (const char *) context.keypad.pinEntry);
2263 context.keypad.layoutCtx, context.keypad.keypadIndex, enableValidate, enableBackspace);
2264 nbgl_layoutDraw(context.keypad.layoutCtx);
2265 nbgl_refresh();
2266}
2267
2268// called when a key is touched on the keypad
2269static void keypadCallback(char touchedKey)
2270{
2271 switch (touchedKey) {
2272 case BACKSPACE_KEY:
2273 if (context.keypad.pinLen > 0) {
2274 context.keypad.pinLen--;
2275 context.keypad.pinEntry[context.keypad.pinLen] = 0;
2276 }
2277 else if (context.keypad.backCallback != NULL) {
2278 context.keypad.backCallback();
2279 break;
2280 }
2281 setPinCodeText();
2282 break;
2283
2284 case VALIDATE_KEY:
2285 context.keypad.validatePin(context.keypad.pinEntry, context.keypad.pinLen);
2286 break;
2287
2288 default:
2289 if ((touchedKey >= 0x30) && (touchedKey < 0x40)) {
2290 if (context.keypad.pinLen < context.keypad.pinMaxDigits) {
2291 context.keypad.pinEntry[context.keypad.pinLen] = touchedKey;
2292 context.keypad.pinLen++;
2293 }
2294 setPinCodeText();
2295 }
2296 break;
2297 }
2298}
2299#endif // NBGL_KEYPAD
2300
2301#ifdef NBGL_KEYBOARD
2302// Saved keyboard context for suggestion selection
2303// (needed because switching to CONTENT_USE_CASE overwrites the union context)
2304static struct {
2305 const char **buttons;
2306 int firstButtonToken;
2307 uint8_t nbUsedButtons;
2308 nbgl_layoutTouchCallback_t onButtonCallback;
2309 nbgl_callback_t backCallback;
2310 char title[KEYBOARD_MAX_TITLE];
2311} savedKeyboardContext;
2312
2313// Navigation callback to fill the suggestion choices page
2314static bool suggestionNavCallback(uint8_t page, nbgl_pageContent_t *content)
2315{
2316 UNUSED(page);
2317 content->type = CHOICES_LIST;
2318 content->choicesList.names = savedKeyboardContext.buttons;
2319 content->choicesList.token = savedKeyboardContext.firstButtonToken;
2320 content->choicesList.initChoice = 0;
2321 content->choicesList.nbChoices = savedKeyboardContext.nbUsedButtons;
2322 return true;
2323}
2324
2325// Display suggestion selection page
2326static void displaySuggestionSelection(void)
2327{
2328 // Save keyboard context before it gets overwritten
2329 savedKeyboardContext.buttons = context.keyboard.content.suggestionButtons.buttons;
2330 savedKeyboardContext.firstButtonToken
2331 = context.keyboard.content.suggestionButtons.firstButtonToken;
2332 savedKeyboardContext.nbUsedButtons = context.keyboard.content.suggestionButtons.nbUsedButtons;
2333 savedKeyboardContext.onButtonCallback = context.keyboard.onButtonCallback;
2334 savedKeyboardContext.backCallback = context.keyboard.backCallback;
2335
2336 // Release the keyboard layout
2337 nbgl_layoutRelease(context.keyboard.layoutCtx);
2338 context.keyboard.layoutCtx = NULL;
2339
2340 snprintf(savedKeyboardContext.title,
2341 sizeof(savedKeyboardContext.title),
2342 "Select word #%d",
2343 context.keyboard.content.number);
2344 nbgl_useCaseNavigableContent(savedKeyboardContext.title,
2345 0,
2346 1,
2347 savedKeyboardContext.backCallback,
2348 suggestionNavCallback,
2349 savedKeyboardContext.onButtonCallback);
2350}
2351
2352// called when a key is touched on the keyboard
2353static void keyboardCallback(char touchedKey)
2354{
2355 uint32_t mask = 0;
2356 size_t textLen = strlen(context.keyboard.entryBuffer);
2357 PRINTF("[keyboardCallback] touchedKey: '%c'\n", touchedKey);
2358 if (touchedKey == BACKSPACE_KEY) {
2359 if (textLen == 0) {
2360 // Used to exit the keyboard when backspace is pressed on an empty entry
2361 context.keyboard.backCallback();
2362 return;
2363 }
2364 context.keyboard.entryBuffer[--textLen] = '\0';
2365 }
2366 else if (touchedKey == VALIDATE_KEY) {
2367 context.keyboard.actionCallback();
2368 return;
2369 }
2370 else if (textLen < context.keyboard.entryMaxLen) {
2371 // the key mask is only a UI hint, so the buffer bound is enforced here: entryBuffer holds
2372 // at most entryMaxLen characters plus the NUL terminator
2373 context.keyboard.entryBuffer[textLen] = touchedKey;
2374 context.keyboard.entryBuffer[++textLen] = '\0';
2375 }
2376 // Set the keyMask to disable some keys
2377 if (context.keyboard.content.type == KEYBOARD_WITH_SUGGESTIONS) {
2378 // if suggestions are displayed, we update them at each key press
2379 context.keyboard.getSuggestButtons(&context.keyboard.content, &mask);
2380 const nbgl_layoutSuggestionButtons_t *suggestions
2381 = &context.keyboard.content.suggestionButtons;
2382 // On Nano, when all the matching candidates can be displayed, switch to a selection page
2383 // instead of continuing with keyboard entry. When the caller provides the real number of
2384 // candidates (nbCandidates != 0), rely on it: this lets a fully-typed word that is also
2385 // the prefix of other words (e.g. "can") be selected even though the displayed buttons are
2386 // capped at NB_MAX_SUGGESTION_BUTTONS. Otherwise fall back to the legacy heuristic based on
2387 // the number of displayed buttons.
2388 bool allCandidatesFit;
2389 if (suggestions->nbCandidates != 0) {
2390 allCandidatesFit = (suggestions->nbCandidates <= NB_MAX_SUGGESTION_BUTTONS);
2391 }
2392 else {
2393 allCandidatesFit = (suggestions->nbUsedButtons < NB_MAX_SUGGESTION_BUTTONS);
2394 }
2395 if ((suggestions->nbUsedButtons > 0) && allCandidatesFit) {
2396 displaySuggestionSelection();
2397 return; // Don't update keyboard, we're in suggestion mode
2398 }
2399 }
2400 if (textLen >= context.keyboard.entryMaxLen) {
2401 // entry length can't be greater, so whatever the suggestions, we mask every characters
2402 mask = -1;
2403 }
2404 nbgl_layoutUpdateKeyboard(context.keyboard.layoutCtx, context.keyboard.keyboardIndex, mask);
2405 nbgl_layoutUpdateEnteredText(
2406 context.keyboard.layoutCtx, context.keyboard.textIndex, context.keyboard.entryBuffer);
2407 nbgl_refresh();
2408}
2409#endif
2410
2411// this is the function called to start the actual review, from the initial warning pages
2412static void launchReviewAfterWarning(void)
2413{
2414 if (reviewWithWarnCtx.type == REVIEW_USE_CASE) {
2415 useCaseReview(reviewWithWarnCtx.type,
2416 reviewWithWarnCtx.operationType,
2417 reviewWithWarnCtx.tagValueList,
2418 reviewWithWarnCtx.icon,
2419 reviewWithWarnCtx.reviewTitle,
2420 reviewWithWarnCtx.reviewSubTitle,
2421 reviewWithWarnCtx.finishTitle,
2422 reviewWithWarnCtx.choiceCallback);
2423 }
2424 else if (reviewWithWarnCtx.type == STREAMING_START_REVIEW_USE_CASE) {
2425 displayStreamingReviewPage(FORWARD_DIRECTION);
2426 }
2427}
2428
2429// callback used when navigating in a bar detail sub-page
2430static void barDetailNavigate(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
2431{
2432 UNUSED(stepCtx);
2433 if (event == BUTTON_LEFT_PRESSED) {
2434 displayWarningStep();
2435 }
2436}
2437
2438// display a bar detail sub-page (CENTERED_INFO_WARNING type)
2439static void displayBarDetailStep(void)
2440{
2441 const nbgl_genericDetails_t *detail
2442 = &reviewWithWarnCtx.warning->introDetails->barList.details[reviewWithWarnCtx.barDetailIdx];
2443
2444 if (detail->type == CENTERED_INFO_WARNING) {
2445 nbgl_layoutCenteredInfo_t info = {0};
2446 info.icon = detail->centeredInfo.icon;
2447 info.text1 = detail->centeredInfo.title;
2448 info.text2 = detail->centeredInfo.description;
2449 info.style = BOLD_TEXT1_INFO;
2450 // LAST_STEP: only left arrow shown, pressing LEFT goes back via barDetailNavigate
2452 LAST_STEP | BACKWARD_DIRECTION, barDetailNavigate, NULL, &info, false);
2453 nbgl_refresh();
2454 }
2455}
2456
2457// this is the callback used when navigating in warning pages
2458static void warningNavigate(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
2459{
2460 UNUSED(stepCtx);
2461 uint8_t barIdx = 0;
2462
2463 if (event == BUTTON_LEFT_PRESSED) {
2464 // only decrement page if we are not at the first page
2465 if (reviewWithWarnCtx.warningPage > 0) {
2466 reviewWithWarnCtx.warningPage--;
2467 }
2468 }
2469 else if (event == BUTTON_RIGHT_PRESSED) {
2470 // only increment page if not at last page
2471 if (reviewWithWarnCtx.warningPage < (reviewWithWarnCtx.nbWarningPages - 1)) {
2472 reviewWithWarnCtx.warningPage++;
2473 }
2474 else if ((reviewWithWarnCtx.warning->predefinedSet == 0)
2475 && (reviewWithWarnCtx.warning->info != NULL)) {
2476 launchReviewAfterWarning();
2477 return;
2478 }
2479 }
2480 else if ((event == BUTTON_BOTH_PRESSED)
2481 && (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN))) {
2482 // if at first page, double press leads to start of review
2483 if (reviewWithWarnCtx.warningPage == reviewWithWarnCtx.firstWarningPage) {
2484 launchReviewAfterWarning();
2485 }
2486 // if at last page, reject operation
2487 else if (reviewWithWarnCtx.warningPage == (reviewWithWarnCtx.nbWarningPages - 1)) {
2488 reviewWithWarnCtx.choiceCallback(false);
2489 }
2490 return;
2491 }
2492 else if ((event == BUTTON_BOTH_PRESSED) && (reviewWithWarnCtx.warning->introDetails != NULL)
2493 && (reviewWithWarnCtx.warning->introDetails->type == BAR_LIST_WARNING)
2494 && (reviewWithWarnCtx.warningPage > reviewWithWarnCtx.firstWarningPage)) {
2495 // enter the detail sub-page for the current bar (if it has one)
2496 barIdx = reviewWithWarnCtx.warningPage - reviewWithWarnCtx.firstWarningPage - 1;
2497 if ((reviewWithWarnCtx.warning->introDetails->barList.details != NULL)
2498 && (reviewWithWarnCtx.warning->introDetails->barList.details[barIdx].type
2499 != NO_TYPE_WARNING)) {
2500 reviewWithWarnCtx.barDetailIdx = barIdx;
2501 displayBarDetailStep();
2502 }
2503 return;
2504 }
2505 else {
2506 return;
2507 }
2508 displayWarningStep();
2509}
2510
2511// function used to display the initial warning pages when starting a "review with warning"
2512static void displayWarningStep(void)
2513{
2514 nbgl_layoutCenteredInfo_t info = {0};
2516 uint8_t barIdx = 0;
2517 if ((reviewWithWarnCtx.warning->prelude) && (reviewWithWarnCtx.warningPage == 0)) {
2518 // for prelude, only draw text as a single step
2520 warningNavigate,
2521 NULL,
2522 reviewWithWarnCtx.warning->prelude->title,
2523 reviewWithWarnCtx.warning->prelude->description,
2524 REGULAR_INFO,
2525 false);
2526 nbgl_refresh();
2527 return;
2528 }
2529 else if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
2530 if (reviewWithWarnCtx.warningPage == reviewWithWarnCtx.firstWarningPage) {
2531 // draw the main warning page
2532 info.icon = &C_icon_warning;
2533 info.text1 = "Blind signing ahead";
2534 info.text2 = "To accept risk, press both buttons";
2535 pos = (reviewWithWarnCtx.firstWarningPage == 0) ? FIRST_STEP
2538 }
2539 else if (reviewWithWarnCtx.warningPage == (reviewWithWarnCtx.nbWarningPages - 1)) {
2540 getLastPageInfo(false, &info.icon, &info.text1);
2542 }
2543 }
2544 else if ((reviewWithWarnCtx.warning->predefinedSet == 0)
2545 && (reviewWithWarnCtx.warning->info != NULL)) {
2546 if (reviewWithWarnCtx.warningPage == reviewWithWarnCtx.firstWarningPage) {
2547 info.icon = reviewWithWarnCtx.warning->info->icon;
2548 info.text1 = reviewWithWarnCtx.warning->info->title;
2549 info.text2 = reviewWithWarnCtx.warning->info->description;
2550 pos = (reviewWithWarnCtx.firstWarningPage == 0) ? FIRST_STEP
2553 }
2554 else if ((reviewWithWarnCtx.warning->introDetails != NULL)
2555 && (reviewWithWarnCtx.warning->introDetails->type == BAR_LIST_WARNING)) {
2556 // intermediate or last bar page
2557 barIdx = reviewWithWarnCtx.warningPage - reviewWithWarnCtx.firstWarningPage - 1;
2558 if (reviewWithWarnCtx.warning->introDetails->barList.icons) {
2559 info.icon = reviewWithWarnCtx.warning->introDetails->barList.icons[barIdx];
2560 }
2561 info.text1 = reviewWithWarnCtx.warning->introDetails->barList.texts[barIdx];
2562 if (reviewWithWarnCtx.warning->introDetails->barList.subTexts) {
2563 info.text2 = reviewWithWarnCtx.warning->introDetails->barList.subTexts[barIdx];
2564 }
2566 }
2567 else if (reviewWithWarnCtx.warningPage == (reviewWithWarnCtx.nbWarningPages - 1)) {
2568 if ((reviewWithWarnCtx.warning->introDetails != NULL)
2569 && (reviewWithWarnCtx.warning->introDetails->type == CENTERED_INFO_WARNING)) {
2570 info.icon = reviewWithWarnCtx.warning->introDetails->centeredInfo.icon;
2571 info.text1 = reviewWithWarnCtx.warning->introDetails->centeredInfo.title;
2572 info.text2 = reviewWithWarnCtx.warning->introDetails->centeredInfo.description;
2574 }
2575 else {
2576 // not supported
2577 return;
2578 }
2579 }
2580 }
2581 else {
2582 // not supported
2583 return;
2584 }
2585 info.style = BOLD_TEXT1_INFO;
2586 nbgl_stepDrawCenteredInfo(pos, warningNavigate, NULL, &info, false);
2587 nbgl_refresh();
2588}
2589
2590// function used to display the initial warning page when starting a "review with warning"
2591static void displayInitialWarning(void)
2592{
2593 // draw the main warning page
2594 reviewWithWarnCtx.warningPage = 0;
2595 if ((reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN))
2596 || ((reviewWithWarnCtx.warning->introDetails)
2597 && (reviewWithWarnCtx.warning->introDetails->type == CENTERED_INFO_WARNING))) {
2598 reviewWithWarnCtx.nbWarningPages = 2;
2599 }
2600 else if ((reviewWithWarnCtx.warning->introDetails)
2601 && (reviewWithWarnCtx.warning->introDetails->type == BAR_LIST_WARNING)) {
2602 reviewWithWarnCtx.nbWarningPages
2603 = reviewWithWarnCtx.warning->introDetails->barList.nbBars + 1;
2604 }
2605 else {
2606 // if no intro details and not Blind Signing warning, only one page
2607 reviewWithWarnCtx.nbWarningPages = 1;
2608 }
2609
2610 reviewWithWarnCtx.firstWarningPage = 0;
2611 displayWarningStep();
2612}
2613
2614// function used to display the prelude page when starting a "review with warning"
2615static void displayPrelude(void)
2616{
2617 // draw the main warning page
2618 reviewWithWarnCtx.warningPage = 0;
2619 if ((reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN))
2620 || ((reviewWithWarnCtx.warning->introDetails)
2621 && (reviewWithWarnCtx.warning->introDetails->type == CENTERED_INFO_WARNING))) {
2622 reviewWithWarnCtx.nbWarningPages = 3;
2623 }
2624 else {
2625 // if no intro details and not Blind Signing warning, only 2 pages
2626 reviewWithWarnCtx.nbWarningPages = 2;
2627 }
2628 reviewWithWarnCtx.firstWarningPage = 1;
2629 displayWarningStep();
2630}
2631
2632// Gated signing is a stricter flavor of blind signing: it must go through the whole blind signing
2633// warning flow (initial warning page with explicit risk acceptance, security report, tip-box...).
2634// If the caller only set GATED_SIGNING_WARN, use a local copy with BLIND_SIGNING_WARN also set,
2635// so that no warning page or report entry is silently skipped.
2636static const nbgl_warning_t *normalizeWarning(const nbgl_warning_t *warning)
2637{
2638 if ((warning == NULL) || ((warning->predefinedSet & (1 << GATED_SIGNING_WARN)) == 0)
2639 || (warning->predefinedSet & (1 << BLIND_SIGNING_WARN))) {
2640 return warning;
2641 }
2642 memcpy(&normalizedWarning, warning, sizeof(normalizedWarning));
2643 normalizedWarning.predefinedSet |= (1 << BLIND_SIGNING_WARN);
2644 return &normalizedWarning;
2645}
2646
2647/**********************
2648 * GLOBAL FUNCTIONS
2649 **********************/
2650
2662uint8_t nbgl_useCaseGetNbTagValuesInPage(uint8_t nbPairs,
2663 const nbgl_contentTagValueList_t *tagValueList,
2664 uint8_t startIndex,
2665 bool *requireSpecificDisplay)
2666{
2667 UNUSED(nbPairs);
2668 UNUSED(tagValueList);
2669 UNUSED(startIndex);
2670 *requireSpecificDisplay = true;
2671 return 1;
2672}
2673
2682uint8_t nbgl_useCaseGetNbChoicesInPage(uint8_t nbChoices,
2683 const nbgl_contentRadioChoice_t *choicesList,
2684 uint8_t startIndex,
2685 bool withNav)
2686{
2687 UNUSED(nbChoices);
2688 UNUSED(choicesList);
2689 UNUSED(startIndex);
2690 UNUSED(withNav);
2691 return 1;
2692}
2693
2707void nbgl_useCaseNavigableContent(const char *title,
2708 uint8_t initPage,
2709 uint8_t nbPages,
2710 nbgl_callback_t quitCallback,
2711 nbgl_navCallback_t navCallback,
2712 nbgl_layoutTouchCallback_t controlsCallback)
2713{
2714 memset(&context, 0, sizeof(UseCaseContext_t));
2715 context.type = CONTENT_USE_CASE;
2716 context.currentPage = initPage;
2717 context.content.title = title;
2718 context.content.quitCallback = quitCallback;
2719 context.content.navCallback = navCallback;
2720 context.content.controlsCallback = controlsCallback;
2721 context.content.genericContents.callbackCallNeeded = true;
2722 context.content.genericContents.nbContents = nbPages;
2723
2724 startUseCaseContent();
2725}
2726
2741void nbgl_useCaseHomeAndSettings(const char *appName,
2742 const nbgl_icon_details_t *appIcon,
2743 const char *tagline,
2744 const uint8_t initSettingPage,
2745 const nbgl_genericContents_t *settingContents,
2746 const nbgl_contentInfoList_t *infosList,
2747 const nbgl_homeAction_t *action,
2748 nbgl_callback_t quitCallback)
2749{
2750 memset(&context, 0, sizeof(UseCaseContext_t));
2751 context.home.appName = appName;
2752 context.home.appIcon = appIcon;
2753 context.home.tagline = tagline;
2754 context.home.settingContents = PIC(settingContents);
2755 context.home.infosList = PIC(infosList);
2756 context.home.homeAction = action;
2757 context.home.quitCallback = quitCallback;
2758
2759 if ((initSettingPage != INIT_HOME_PAGE) && (settingContents != NULL)) {
2760 startUseCaseSettingsAtPage(initSettingPage);
2761 }
2762 else {
2763 startUseCaseHome();
2764 }
2765}
2766
2777bool nbgl_useCaseShowInfoAndSettings(uint8_t initPage)
2778{
2779 if (context.type != HOME_USE_CASE) {
2780 return false;
2781 }
2782 if (context.home.settingContents != NULL) {
2783 startUseCaseSettingsAtPage(initPage);
2784 }
2785 else if (context.home.infosList != NULL) {
2786 startUseCaseInfo();
2787 }
2788 else {
2789 return false;
2790 }
2791 return true;
2792}
2793
2806void nbgl_useCaseGenericSettings(const char *appName,
2807 uint8_t initPage,
2808 const nbgl_genericContents_t *settingContents,
2809 const nbgl_contentInfoList_t *infosList,
2810 nbgl_callback_t quitCallback)
2811{
2812 memset(&context, 0, sizeof(UseCaseContext_t));
2813 context.type = GENERIC_SETTINGS;
2814 context.home.appName = appName;
2815 context.home.settingContents = PIC(settingContents);
2816 context.home.infosList = PIC(infosList);
2817 context.home.quitCallback = quitCallback;
2818
2819 startUseCaseSettingsAtPage(initPage);
2820}
2821
2833void nbgl_useCaseGenericConfiguration(const char *title,
2834 uint8_t initPage,
2835 const nbgl_genericContents_t *contents,
2836 nbgl_callback_t quitCallback)
2837{
2838 nbgl_useCaseGenericSettings(title, initPage, contents, NULL, quitCallback);
2839}
2840
2855void nbgl_useCaseReview(nbgl_operationType_t operationType,
2856 const nbgl_contentTagValueList_t *tagValueList,
2857 const nbgl_icon_details_t *icon,
2858 const char *reviewTitle,
2859 const char *reviewSubTitle,
2860 const char *finishTitle,
2861 nbgl_choiceCallback_t choiceCallback)
2862{
2863 useCaseReview(REVIEW_USE_CASE,
2864 operationType,
2865 tagValueList,
2866 icon,
2867 reviewTitle,
2868 reviewSubTitle,
2869 finishTitle,
2870 choiceCallback);
2871}
2872
2896 const nbgl_contentTagValueList_t *tagValueList,
2897 const nbgl_icon_details_t *icon,
2898 const char *reviewTitle,
2899 const char *reviewSubTitle,
2900 const char *finishTitle,
2901 const nbgl_tipBox_t *tipBox,
2902 const nbgl_warning_t *warning,
2903 nbgl_choiceCallback_t choiceCallback)
2904{
2905 UNUSED(tipBox);
2906 ContextType_t type = REVIEW_USE_CASE;
2907
2908 // if no warning at all, it's a simple review
2909 if ((warning == NULL)
2910 || ((warning->predefinedSet == 0) && (warning->info == NULL)
2911 && (warning->reviewDetails == NULL) && (warning->prelude == NULL))) {
2912 useCaseReview(type,
2913 operationType,
2914 tagValueList,
2915 icon,
2916 reviewTitle,
2917 reviewSubTitle,
2918 finishTitle,
2919 choiceCallback);
2920 return;
2921 }
2922 if (warning->predefinedSet == (1 << W3C_NO_THREAT_WARN)) {
2923 operationType |= NO_THREAT_OPERATION;
2924 }
2925 else if (warning->predefinedSet != 0) {
2926 operationType |= RISKY_OPERATION;
2927 }
2928
2929 memset(&reviewWithWarnCtx, 0, sizeof(reviewWithWarnCtx));
2930 reviewWithWarnCtx.type = type;
2931 reviewWithWarnCtx.operationType = operationType;
2932 reviewWithWarnCtx.tagValueList = tagValueList;
2933 reviewWithWarnCtx.icon = icon;
2934 reviewWithWarnCtx.reviewTitle = reviewTitle;
2935 reviewWithWarnCtx.reviewSubTitle = reviewSubTitle;
2936 reviewWithWarnCtx.finishTitle = finishTitle;
2937 reviewWithWarnCtx.warning = normalizeWarning(warning);
2938 reviewWithWarnCtx.choiceCallback = choiceCallback;
2939
2940 if (!isWarningSupported(reviewWithWarnCtx.warning)) {
2941 choiceCallback(false);
2942 return;
2943 }
2944 // if the warning contains a prelude, display it first
2945 if (reviewWithWarnCtx.warning->prelude) {
2946 displayPrelude();
2947 }
2948 // display the initial warning only of a risk/threat or blind signing or prelude
2949 else if (HAS_INITIAL_WARNING(reviewWithWarnCtx.warning)) {
2950 displayInitialWarning();
2951 }
2952 else {
2953 useCaseReview(type,
2954 operationType,
2955 tagValueList,
2956 icon,
2957 reviewTitle,
2958 reviewSubTitle,
2959 finishTitle,
2960 choiceCallback);
2961 }
2962}
2963
2984 const nbgl_contentTagValueList_t *tagValueList,
2985 const nbgl_icon_details_t *icon,
2986 const char *reviewTitle,
2987 const char *reviewSubTitle,
2988 const char *finishTitle,
2989 const nbgl_tipBox_t *dummy,
2990 nbgl_choiceCallback_t choiceCallback)
2991{
2992 nbgl_useCaseAdvancedReview(operationType,
2993 tagValueList,
2994 icon,
2995 reviewTitle,
2996 reviewSubTitle,
2997 finishTitle,
2998 dummy,
2999 &blindSigningWarning,
3000 choiceCallback);
3001}
3002
3018 const nbgl_contentTagValueList_t *tagValueList,
3019 const nbgl_icon_details_t *icon,
3020 const char *reviewTitle,
3021 const char *reviewSubTitle,
3022 const char *finishTitle,
3023 nbgl_choiceCallback_t choiceCallback)
3024{
3025 nbgl_useCaseReview(operationType,
3026 tagValueList,
3027 icon,
3028 reviewTitle,
3029 reviewSubTitle,
3030 finishTitle,
3031 choiceCallback);
3032}
3033
3050void nbgl_useCaseAddressReview(const char *address,
3051 const nbgl_contentTagValueList_t *additionalTagValueList,
3052 const nbgl_icon_details_t *icon,
3053 const char *reviewTitle,
3054 const char *reviewSubTitle,
3055 nbgl_choiceCallback_t choiceCallback)
3056{
3057 memset(&context, 0, sizeof(UseCaseContext_t));
3058 context.type = ADDRESS_REVIEW_USE_CASE;
3059 context.review.address = address;
3060 context.review.reviewTitle = reviewTitle;
3061 context.review.reviewSubTitle = reviewSubTitle;
3062 context.review.icon = icon;
3063 context.review.onChoice = choiceCallback;
3064 context.currentPage = 0;
3065 // + 4 because 1 page for title, 1 for address and 2 pages at the end for approve/reject
3066 // + 1 if sub Title
3067 uint16_t nbPages = reviewSubTitle ? 5 : 4;
3068 if (additionalTagValueList) {
3069 context.review.tagValueList = PIC(additionalTagValueList);
3070 nbPages += additionalTagValueList->nbPairs;
3071 if (!isTagValueListComplete(additionalTagValueList)) {
3072 nbPages = UINT8_MAX + 1;
3073 }
3074 }
3075
3076 if (nbPages <= UINT8_MAX) {
3077 context.nbPages = (uint8_t) nbPages;
3078 displayReviewPage(FORWARD_DIRECTION);
3079 }
3080 else {
3081 onReviewReject();
3082 }
3083}
3084
3094 const char *rejectText,
3095 nbgl_callback_t rejectCallback)
3096{
3097 memset(&context, 0, sizeof(UseCaseContext_t));
3098 context.type = GENERIC_REVIEW_USE_CASE;
3099 context.content.rejectText = rejectText;
3100 context.content.quitCallback = rejectCallback;
3101 context.content.genericContents.nbContents = contents->nbContents;
3102 context.content.genericContents.callbackCallNeeded = contents->callbackCallNeeded;
3103 if (contents->callbackCallNeeded) {
3104 context.content.genericContents.contentGetterCallback = contents->contentGetterCallback;
3105 }
3106 else {
3107 context.content.genericContents.contentsList = PIC(contents->contentsList);
3108 }
3109
3110 startUseCaseContent();
3111}
3112
3121void nbgl_useCaseStatus(const char *message, bool isSuccess, nbgl_callback_t quitCallback)
3122{
3123 UNUSED(isSuccess);
3124 memset(&context, 0, sizeof(UseCaseContext_t));
3125 context.type = STATUS_USE_CASE;
3126 context.stepCallback = quitCallback;
3127 context.currentPage = 0;
3128 context.nbPages = 1;
3129
3131 NULL,
3132 message,
3133 NULL,
3134 0,
3135 statusButtonCallback,
3136 false,
3137 NO_FORCED_TYPE,
3138 false);
3139}
3140
3148 nbgl_callback_t quitCallback)
3149{
3150 const char *msg;
3151 bool isSuccess;
3152 switch (reviewStatusType) {
3154 msg = "Operation signed";
3155 isSuccess = true;
3156 break;
3158 msg = "Operation rejected";
3159 isSuccess = false;
3160 break;
3162 msg = "Transaction signed";
3163 isSuccess = true;
3164 break;
3166 msg = "Transaction rejected";
3167 isSuccess = false;
3168 break;
3170 msg = "Message signed";
3171 isSuccess = true;
3172 break;
3174 msg = "Message rejected";
3175 isSuccess = false;
3176 break;
3178 msg = "Address verified";
3179 isSuccess = true;
3180 break;
3182 msg = "Address verification cancelled";
3183 isSuccess = false;
3184 break;
3185 default:
3186 return;
3187 }
3188 nbgl_useCaseStatus(msg, isSuccess, quitCallback);
3189}
3190
3204 const nbgl_icon_details_t *icon,
3205 const char *reviewTitle,
3206 const char *reviewSubTitle,
3207 nbgl_choiceCallback_t choiceCallback)
3208{
3209 // memorize streaming operation type for future API calls
3210 streamingOpType = operationType;
3211
3212 memset(&context, 0, sizeof(UseCaseContext_t));
3213 context.type = STREAMING_START_REVIEW_USE_CASE;
3214 context.operationType = operationType;
3215 context.review.reviewTitle = reviewTitle;
3216 context.review.reviewSubTitle = reviewSubTitle;
3217 context.review.icon = icon;
3218 context.review.onChoice = choiceCallback;
3219 context.currentPage = 0;
3220 context.nbPages = reviewSubTitle ? 3 : 2; // Start page(s) + trick for review continue
3221
3222 displayStreamingReviewPage(FORWARD_DIRECTION);
3223}
3224
3239 const nbgl_icon_details_t *icon,
3240 const char *reviewTitle,
3241 const char *reviewSubTitle,
3242 nbgl_choiceCallback_t choiceCallback)
3243{
3245 operationType, icon, reviewTitle, reviewSubTitle, &blindSigningWarning, choiceCallback);
3246}
3247
3264 const nbgl_icon_details_t *icon,
3265 const char *reviewTitle,
3266 const char *reviewSubTitle,
3267 const nbgl_warning_t *warning,
3268 nbgl_choiceCallback_t choiceCallback)
3269{
3270 memset(&context, 0, sizeof(UseCaseContext_t));
3271 context.type = STREAMING_START_REVIEW_USE_CASE;
3272 context.operationType = operationType;
3273 context.review.reviewTitle = reviewTitle;
3274 context.review.reviewSubTitle = reviewSubTitle;
3275 context.review.icon = icon;
3276 context.review.onChoice = choiceCallback;
3277 context.currentPage = 0;
3278 context.nbPages = reviewSubTitle ? 3 : 2; // Start page(s) + trick for review continue
3279
3280 // memorize streaming operation type for future API calls
3281 streamingOpType = operationType;
3282
3283 // if no warning at all, it's a simple review
3284 if ((warning == NULL)
3285 || ((warning->predefinedSet == 0) && (warning->info == NULL)
3286 && (warning->reviewDetails == NULL) && (warning->prelude == NULL))) {
3287 displayStreamingReviewPage(FORWARD_DIRECTION);
3288 return;
3289 }
3290 if (warning->predefinedSet == (1 << W3C_NO_THREAT_WARN)) {
3291 operationType |= NO_THREAT_OPERATION;
3292 }
3293 else if (warning->predefinedSet != 0) {
3294 operationType |= RISKY_OPERATION;
3295 }
3296 memset(&reviewWithWarnCtx, 0, sizeof(reviewWithWarnCtx));
3297
3298 reviewWithWarnCtx.type = context.type;
3299 reviewWithWarnCtx.operationType = operationType;
3300 reviewWithWarnCtx.icon = icon;
3301 reviewWithWarnCtx.reviewTitle = reviewTitle;
3302 reviewWithWarnCtx.reviewSubTitle = reviewSubTitle;
3303 reviewWithWarnCtx.choiceCallback = choiceCallback;
3304 reviewWithWarnCtx.warning = normalizeWarning(warning);
3305
3306 if (!isWarningSupported(reviewWithWarnCtx.warning)) {
3307 choiceCallback(false);
3308 return;
3309 }
3310 // if the warning contains a prelude, display it first
3311 if (reviewWithWarnCtx.warning->prelude) {
3312 displayPrelude();
3313 }
3314 // display the initial warning only of a risk/threat or blind signing or prelude
3315 else if (HAS_INITIAL_WARNING(reviewWithWarnCtx.warning)) {
3316 displayInitialWarning();
3317 }
3318 else {
3319 displayStreamingReviewPage(FORWARD_DIRECTION);
3320 }
3321}
3322
3337 nbgl_choiceCallback_t choiceCallback,
3338 nbgl_callback_t skipCallback)
3339{
3340 uint8_t curNbDataSets = context.review.nbDataSets;
3341
3342 memset(&context, 0, sizeof(UseCaseContext_t));
3343 context.type = STREAMING_CONTINUE_REVIEW_USE_CASE;
3344 context.operationType = streamingOpType;
3345 context.review.tagValueList = tagValueList;
3346 context.review.onChoice = choiceCallback;
3347 context.currentPage = 0;
3348 context.review.skipCallback = skipCallback;
3349 context.review.nbDataSets = curNbDataSets + 1;
3350
3351 if (tagValueList == NULL) {
3352 onReviewReject();
3353 return;
3354 }
3355 uint16_t nbPages = (uint16_t) tagValueList->nbPairs + 1; // data + trick for review continue
3356 if ((nbPages <= UINT8_MAX) && isTagValueListComplete(tagValueList)) {
3357 context.nbPages = (uint8_t) nbPages;
3358 displayStreamingReviewPage(FORWARD_DIRECTION);
3359 }
3360 else {
3361 onReviewReject();
3362 }
3363}
3364
3376 nbgl_choiceCallback_t choiceCallback)
3377{
3378 nbgl_useCaseReviewStreamingContinueExt(tagValueList, choiceCallback, NULL);
3379}
3380
3381void nbgl_useCaseReviewStreamingFinish(const char *finishTitle,
3382 nbgl_choiceCallback_t choiceCallback)
3383{
3384 memset(&context, 0, sizeof(UseCaseContext_t));
3385 context.type = STREAMING_FINISH_REVIEW_USE_CASE;
3386 context.operationType = streamingOpType;
3387 context.review.onChoice = choiceCallback;
3388 context.review.finishTitle = finishTitle;
3389 context.currentPage = 0;
3390 context.nbPages = 2; // 2 pages at the end for accept/reject
3391
3392 displayStreamingReviewPage(FORWARD_DIRECTION);
3393}
3394
3400void nbgl_useCaseSpinner(const char *text)
3401{
3402 memset(&context, 0, sizeof(UseCaseContext_t));
3403 context.type = SPINNER_USE_CASE;
3404 context.currentPage = 0;
3405 context.nbPages = 1;
3406
3407 displaySpinner(text);
3408}
3409
3423 const char *message,
3424 const char *subMessage,
3425 const char *confirmText,
3426 const char *cancelText,
3427 nbgl_choiceCallback_t callback)
3428{
3430 icon, message, subMessage, confirmText, cancelText, NULL, callback);
3431}
3432
3433// Common implementation of the choice flows. title is NULL for the basic ones, in which case
3434// message and subMessage share the same page.
3435static void startChoice(const nbgl_icon_details_t *icon,
3436 const char *title,
3437 const char *message,
3438 const char *subMessage,
3439 const char *confirmText,
3440 const char *cancelText,
3441 nbgl_genericDetails_t *details,
3442 nbgl_choiceCallback_t callback)
3443{
3444 memset(&context, 0, sizeof(UseCaseContext_t));
3445 context.type = CHOICE_USE_CASE;
3446 context.choice.icon = icon;
3447 context.choice.title = title;
3448 context.choice.message = message;
3449 context.choice.subMessage = subMessage;
3450 context.choice.confirmText = confirmText;
3451 context.choice.cancelText = cancelText;
3452 context.choice.onChoice = callback;
3453 context.choice.details = details;
3454 context.currentPage = 0;
3455 uint16_t nbPages = 2 + getChoiceNbIntroPages(); // 2 pages for confirm/cancel
3456 if (details != NULL) {
3457 // only the first level of details and BAR_LIST type are supported
3458 if (details->type == BAR_LIST_WARNING) {
3459 nbPages += details->barList.nbBars;
3460 }
3461 }
3462
3463 if (nbPages <= UINT8_MAX) {
3464 context.nbPages = (uint8_t) nbPages;
3465 displayChoicePage(FORWARD_DIRECTION);
3466 }
3467 else {
3468 onChoiceReject();
3469 }
3470}
3471
3487 const char *message,
3488 const char *subMessage,
3489 const char *confirmText,
3490 const char *cancelText,
3491 nbgl_genericDetails_t *details,
3492 nbgl_choiceCallback_t callback)
3493{
3494 startChoice(icon, NULL, message, subMessage, confirmText, cancelText, details, callback);
3495}
3496
3497// On Nano, the three texts of the advanced variant are spread over one page each, the title
3498// being kept as the first line of all of them. headerIcon is ignored (no top-right button).
3500 const nbgl_icon_details_t *headerIcon,
3501 const char *title,
3502 const char *message,
3503 const char *subMessage,
3504 const char *confirmText,
3505 const char *cancelText,
3506 nbgl_genericDetails_t *details,
3507 nbgl_choiceCallback_t callback)
3508{
3509 UNUSED(headerIcon);
3510 startChoice(centerIcon, title, message, subMessage, confirmText, cancelText, details, callback);
3511}
3512
3526void nbgl_useCaseConfirm(const char *message,
3527 const char *subMessage,
3528 const char *confirmText,
3529 const char *cancelText,
3530 nbgl_callback_t callback)
3531{
3532 memset(&context, 0, sizeof(UseCaseContext_t));
3533 context.type = CONFIRM_USE_CASE;
3534 context.confirm.message = message;
3535 context.confirm.subMessage = subMessage;
3536 context.confirm.confirmText = confirmText;
3537 context.confirm.cancelText = cancelText;
3538 context.confirm.onConfirm = callback;
3539 context.currentPage = 0;
3540 context.nbPages = 1 + 2; // 2 pages at the end for confirm/cancel
3541
3542 displayConfirm(FORWARD_DIRECTION);
3543}
3544
3555 const char *message,
3556 const char *actionText,
3557 nbgl_callback_t callback)
3558{
3559 nbgl_layoutCenteredInfo_t centeredInfo = {0};
3560
3561 UNUSED(actionText);
3562
3563 // memorize callback in context
3564 memset(&context, 0, sizeof(UseCaseContext_t));
3565 context.type = ACTION_USE_CASE;
3566 context.action.actionCallback = callback;
3567
3568 centeredInfo.icon = icon;
3569 centeredInfo.text1 = message;
3570 centeredInfo.style = BOLD_TEXT1_INFO;
3571 nbgl_stepDrawCenteredInfo(0, useCaseActionCallback, NULL, &centeredInfo, false);
3572}
3573
3574#ifdef NBGL_KEYPAD
3593void nbgl_useCaseKeypad(const char *title,
3594 uint8_t minDigits,
3595 uint8_t maxDigits,
3596 bool shuffled,
3597 bool hidden,
3598 nbgl_pinValidCallback_t validatePinCallback,
3599 nbgl_callback_t backCallback)
3600{
3601 nbgl_layoutDescription_t layoutDescription = {0};
3602 int status = -1;
3603
3604 if ((minDigits > KEYPAD_MAX_DIGITS) || (maxDigits > KEYPAD_MAX_DIGITS)) {
3606 "nbgl_useCaseKeypad(): digits out of range (%d/%d > %d)\n",
3607 minDigits,
3608 maxDigits,
3610 return;
3611 }
3612
3613 // reset the context
3614 memset(&context, 0, sizeof(UseCaseContext_t));
3615 context.type = KEYPAD_USE_CASE;
3616 context.currentPage = 0;
3617 context.nbPages = 1;
3618 context.keypad.validatePin = validatePinCallback;
3619 context.keypad.backCallback = backCallback;
3620 context.keypad.pinMinDigits = minDigits;
3621 context.keypad.pinMaxDigits = maxDigits;
3622 context.keypad.hidden = hidden;
3623 context.keypad.layoutCtx = nbgl_layoutGet(&layoutDescription);
3624
3625 // add keypad
3626 status = nbgl_layoutAddKeypad(context.keypad.layoutCtx, keypadCallback, title, shuffled);
3627 if (status < 0) {
3628 LOG_WARN(
3629 USE_CASE_LOGGER, "nbgl_useCaseKeypad(): layout setup failed (status=%d)\n", status);
3630 return;
3631 }
3632 context.keypad.keypadIndex = status;
3633 // add digits
3634 status = nbgl_layoutAddKeypadContent(context.keypad.layoutCtx, hidden, maxDigits, "");
3635 if (status < 0) {
3636 LOG_WARN(
3637 USE_CASE_LOGGER, "nbgl_useCaseKeypad(): layout setup failed (status=%d)\n", status);
3638 return;
3639 }
3640
3641 nbgl_layoutDraw(context.keypad.layoutCtx);
3642 if (context.keypad.backCallback != NULL) {
3643 // force backspace to be visible at first digit, to be used as quit
3644 nbgl_layoutUpdateKeypad(context.keypad.layoutCtx, context.keypad.keypadIndex, false, true);
3645 }
3646 nbgl_refresh();
3647}
3648#endif // NBGL_KEYPAD
3649
3650#ifdef NBGL_KEYBOARD
3675void nbgl_useCaseKeyboard(const nbgl_keyboardParams_t *params, nbgl_callback_t backCallback)
3676{
3677 // clang-format off
3678 nbgl_layoutDescription_t layoutDescription = {0};
3679 nbgl_layoutCenteredInfo_t centeredInfo = {.text1 = params->title,
3680 .onTop = true};
3681 nbgl_layoutNavigation_t navInfo = {.direction = HORIZONTAL_NAV,
3682 .indication = LEFT_ARROW | RIGHT_ARROW};
3683 nbgl_layoutKbd_t kbdInfo = {.callback = &keyboardCallback,
3684 .mode = params->mode,
3685 .lettersOnly = params->lettersOnly};
3686 int status = -1;
3687 // clang-format on
3688
3689 // the buffer must at least hold one character and its NUL terminator
3690 if ((params->entryBuffer == NULL) || (params->entryMaxLen == 0)) {
3691 LOG_WARN(USE_CASE_LOGGER, "nbgl_useCaseKeyboard(): invalid entry buffer\n");
3692 return;
3693 }
3694
3695 // reset the keypad context
3696 memset(&context, 0, sizeof(UseCaseContext_t));
3697 context.type = KEYBOARD_USE_CASE;
3698 context.currentPage = 0;
3699 context.nbPages = 1;
3700 context.keyboard.entryBuffer = PIC(params->entryBuffer);
3701 context.keyboard.entryMaxLen = params->entryMaxLen;
3702 context.keyboard.entryBuffer[0] = '\0';
3703
3704 context.keyboard.content.type = params->type;
3705
3706 // memorize context
3707 context.keyboard.backCallback = PIC(backCallback);
3708
3709 switch (params->type) {
3711 context.keyboard.actionCallback = PIC(params->confirmationParams.onButtonCallback);
3712 break;
3714 // No need for 'Validate' or 'Case switch' buttons
3715 kbdInfo.keyMask = (1 << VALIDATE_INDEX) | (1 << SHIFT_KEY_INDEX);
3716 context.keyboard.getSuggestButtons
3718 context.keyboard.onButtonCallback = PIC(params->suggestionParams.onButtonCallback);
3719 context.keyboard.content.suggestionButtons = (nbgl_layoutSuggestionButtons_t){
3720 .buttons = PIC(params->suggestionParams.buttons),
3721 .firstButtonToken = params->suggestionParams.firstButtonToken,
3722 };
3723 break;
3724 default:
3725 return;
3726 }
3727
3728 // get a layout
3729 context.keyboard.layoutCtx = nbgl_layoutGet(&layoutDescription);
3730
3731 // add description
3732 nbgl_layoutAddCenteredInfo(context.keyboard.layoutCtx, &centeredInfo);
3733
3734 // Add keyboard
3735 status = nbgl_layoutAddKeyboard(context.keyboard.layoutCtx, &kbdInfo);
3736 if (status < 0) {
3737 LOG_WARN(
3738 USE_CASE_LOGGER, "nbgl_useCaseKeyboard(): layout setup failed (status=%d)\n", status);
3739 return;
3740 }
3741 context.keyboard.keyboardIndex = status;
3742
3743 // add empty entered text
3744 status = nbgl_layoutAddEnteredText(context.keyboard.layoutCtx, "", true);
3745 if (status < 0) {
3746 LOG_WARN(
3747 USE_CASE_LOGGER, "nbgl_useCaseKeyboard(): layout setup failed (status=%d)\n", status);
3748 return;
3749 }
3750 context.keyboard.textIndex = status;
3751
3752 nbgl_layoutAddNavigation(context.keyboard.layoutCtx, &navInfo);
3753
3754 nbgl_layoutDraw(context.keyboard.layoutCtx);
3755 nbgl_refresh();
3756}
3757#endif // NBGL_KEYBOARD
3758
3759#endif // HAVE_SE_TOUCH
3760#endif // NBGL_USE_CASE
nbgl_contentCenteredInfoStyle_t
possible styles for Centered Info Area
struct nbgl_contentTagValueList_s nbgl_contentTagValueList_t
This structure contains a list of [tag,value] pairs.
@ CHOICES_LIST
list of choices through radio buttons
@ CENTERED_INFO
a centered info
@ SWITCHES_LIST
list of switches with descriptions
@ INFOS_LIST
list of infos with titles
@ TAG_VALUE_CONFIRM
tag/value pairs and a black button/footer to confirm/cancel.
@ TAG_VALUE_LIST
list of tag/value pairs
@ BARS_LIST
list of touchable bars (with > on the right to go to sub-pages)
@ INFO_BUTTON
a centered info and a simple black button
@ INFO_LIST_ALIAS
alias is list of infos
@ TAG_VALUE_LIST_ALIAS
@ ENS_ALIAS
alias comes from ENS
@ ADDRESS_BOOK_ALIAS
alias comes from Address Book
void(* nbgl_contentActionCallback_t)(int token, uint8_t index, int page)
prototype of function to be called when an action on a content object occurs
struct nbgl_contentInfoList_s nbgl_contentInfoList_t
This structure contains data to build a INFOS_LIST content.
debug traces management
#define LOG_WARN(__logger,...)
Definition nbgl_debug.h:89
@ USE_CASE_LOGGER
Definition nbgl_debug.h:37
#define LOG_DEBUG(__logger,...)
Definition nbgl_debug.h:88
void(* nbgl_stepCallback_t)(void)
prototype of function to be called when a step is using a callback on "double-key" action
Definition nbgl_flow.h:40
struct nbgl_pageContent_s nbgl_pageContent_t
This structure contains data to build a page in multi-pages mode (nbgl_pageDrawGenericContent).
int nbgl_layoutUpdateKeyboard(nbgl_layout_t *layout, uint8_t index, uint32_t keyMask, bool updateCasing, keyboardCase_t casing)
Updates an existing keyboard on bottom of the screen, with the given configuration.
int nbgl_layoutAddKeyboard(nbgl_layout_t *layout, const nbgl_layoutKbd_t *kbdInfo)
Creates a keyboard on bottom of the screen, with the given configuration.
@ HORIZONTAL_NAV
'<' and '>' are displayed, to navigate between pages and steps
@ LEFT_ARROW
left arrow is used
@ RIGHT_ARROW
right arrow is used
int nbgl_layoutUpdateKeypad(nbgl_layout_t *layout, uint8_t index, bool enableValidate, bool enableBackspace, bool enableDigits)
Updates an existing keypad on bottom of the screen, with the given configuration.
int nbgl_layoutAddCenteredInfo(nbgl_layout_t *layout, const nbgl_layoutCenteredInfo_t *info)
Creates an area on the center of the main panel, with a possible icon/image, a possible text in black...
nbgl_contentSwitch_t nbgl_layoutSwitch_t
Deprecated, kept for retro compatibility.
int nbgl_layoutDraw(nbgl_layout_t *layout)
Applies given layout. The screen will be redrawn.
void * nbgl_layout_t
type shared externally
int nbgl_layoutAddKeypadContent(nbgl_layout_t *layout, const char *title, bool hidden, uint8_t nbDigits, const char *text)
Adds an area with a title and a placeholder for hidden digits on top of a keypad, to represent the en...
int nbgl_layoutUpdateKeypadContent(nbgl_layout_t *layout, bool hidden, uint8_t nbActiveDigits, const char *text)
Updates an existing set of hidden digits, with the given configuration.
nbgl_layout_t * nbgl_layoutGet(const nbgl_layoutDescription_t *description)
returns a layout of the given type. The layout is reset
struct nbgl_layoutDescription_s nbgl_layoutDescription_t
Structure containing all information when creating a layout. This structure must be passed as argumen...
int nbgl_layoutRelease(nbgl_layout_t *layout)
Release the layout obtained with nbgl_layoutGet().
int nbgl_layoutAddKeypad(nbgl_layout_t *layout, keyboardCallback_t callback, bool shuffled)
Adds a keypad on bottom of the screen, with the associated callback.
nbgl_contentCenteredInfo_t nbgl_layoutCenteredInfo_t
Deprecated, kept for retro compatibility.
void(* nbgl_layoutTouchCallback_t)(int token, uint8_t index)
prototype of function to be called when an object is touched
@ KEYBOARD_WITH_BUTTON
text entry area + confirmation button
@ KEYBOARD_WITH_SUGGESTIONS
text entry area + suggestion buttons
#define SHIFT_KEY_INDEX
Definition nbgl_obj.h:45
void nbgl_refresh(void)
#define KEYPAD_MAX_DIGITS
Definition nbgl_obj.h:76
nbgl_buttonEvent_t
Definition nbgl_obj.h:196
@ BUTTON_BOTH_PRESSED
Sent when both buttons are released.
Definition nbgl_obj.h:203
@ BUTTON_LEFT_PRESSED
Sent when Left button is released.
Definition nbgl_obj.h:197
@ BUTTON_RIGHT_PRESSED
Send when Right button is released.
Definition nbgl_obj.h:198
#define BACKSPACE_KEY
Definition nbgl_obj.h:30
#define VALIDATE_KEY
Definition nbgl_obj.h:31
struct PACKED__ nbgl_screenTickerConfiguration_s nbgl_screenTickerConfiguration_t
struct to configure a screen layer
void nbgl_screenRedraw(void)
void(* nbgl_stepButtonCallback_t)(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
prototype of function to be called when buttons are touched on a screen
Definition nbgl_step.h:59
#define GET_POS_OF_STEP(_step, _nb_steps)
Definition nbgl_step.h:32
nbgl_step_t nbgl_stepDrawSwitch(nbgl_stepPosition_t pos, nbgl_stepButtonCallback_t onActionCallback, nbgl_screenTickerConfiguration_t *ticker, nbgl_layoutSwitch_t *switchInfo, bool modal)
void * nbgl_step_t
type shared externally
Definition nbgl_step.h:46
uint8_t nbgl_stepPosition_t
this type is a bitfield containing:
Definition nbgl_step.h:90
@ NEITHER_FIRST_NOR_LAST_STEP
neither first nor last in a multiple steps flow
Definition nbgl_step.h:69
@ SINGLE_STEP
single step flow
Definition nbgl_step.h:66
@ LAST_STEP
last in a multiple steps flow
Definition nbgl_step.h:68
@ FIRST_STEP
first in a multiple steps flow
Definition nbgl_step.h:67
nbgl_step_t nbgl_stepDrawMenuList(nbgl_stepMenuListCallback_t onActionCallback, nbgl_screenTickerConfiguration_t *ticker, nbgl_layoutMenuList_t *list, bool modal)
#define ACTION_ON_ANY_BUTTON
When action callback applies only on both button press.
Definition nbgl_step.h:77
int nbgl_stepRelease(nbgl_step_t step)
#define FORWARD_DIRECTION
When the flow is navigated from last to first step.
Definition nbgl_step.h:73
nbgl_step_t nbgl_stepDrawText(nbgl_stepPosition_t pos, nbgl_stepButtonCallback_t onActionCallback, nbgl_screenTickerConfiguration_t *ticker, const char *text, const char *subText, nbgl_contentCenteredInfoStyle_t style, bool modal)
nbgl_step_t nbgl_stepDrawCenteredInfo(nbgl_stepPosition_t pos, nbgl_stepButtonCallback_t onActionCallback, nbgl_screenTickerConfiguration_t *ticker, nbgl_layoutCenteredInfo_t *info, bool modal)
#define BACKWARD_DIRECTION
When action callback applies on any button press.
Definition nbgl_step.h:75
Internal functions of NBGL step layer.
nbgl_step_t stepDrawText(nbgl_stepPosition_t pos, nbgl_stepButtonCallback_t onActionCallback, nbgl_screenTickerConfiguration_t *ticker, const char *text, const char *subText, nbgl_contentCenteredInfoStyle_t style, bool modal, uint8_t nbMaxLinesForSubText)
nbgl_state_t
to represent a boolean state.
Definition nbgl_types.h:212
@ ON_STATE
Definition nbgl_types.h:214
@ OFF_STATE
Definition nbgl_types.h:213
struct PACKED__ nbgl_icon_details_s nbgl_icon_details_t
Represents all information about an icon.
API of the Advanced BOLOS Graphical Library, for typical application use-cases.
@ NO_TYPE_WARNING
Invalid type (to use for bars leading to nothing).
@ CENTERED_INFO_WARNING
Centered info.
@ BAR_LIST_WARNING
list of touchable bars, to display sub-pages
void(* nbgl_callback_t)(void)
prototype of generic callback function
#define SKIPPABLE_OPERATION
This is to use in nbgl_operationType_t when the operation is skippable. This is used to add a Skip bu...
void nbgl_useCaseGenericSettings(const char *appName, uint8_t initPage, const nbgl_genericContents_t *settingContents, const nbgl_contentInfoList_t *infosList, nbgl_callback_t quitCallback)
uint32_t nbgl_operationType_t
This mask is used to describe the type of operation to review with additional options It is a mask of...
void nbgl_useCaseReview(nbgl_operationType_t operationType, const nbgl_contentTagValueList_t *tagValueList, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, const char *finishTitle, nbgl_choiceCallback_t choiceCallback)
struct nbgl_genericDetails_s nbgl_genericDetails_t
The necessary parameters to build the page(s) displayed when the top-right button is touched in intro...
void nbgl_useCaseAction(const nbgl_icon_details_t *icon, const char *message, const char *actionText, nbgl_callback_t callback)
uint8_t nbgl_useCaseGetNbTagValuesInPage(uint8_t nbPairs, const nbgl_contentTagValueList_t *tagValueList, uint8_t startIndex, bool *requireSpecificDisplay)
void(* nbgl_pinValidCallback_t)(const uint8_t *pin, uint8_t pinLen)
prototype of pin validation callback function
void nbgl_useCaseReviewStreamingStart(nbgl_operationType_t operationType, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, nbgl_choiceCallback_t choiceCallback)
void nbgl_useCaseHomeAndSettings(const char *appName, const nbgl_icon_details_t *appIcon, const char *tagline, const uint8_t initSettingPage, const nbgl_genericContents_t *settingContents, const nbgl_contentInfoList_t *infosList, const nbgl_homeAction_t *action, nbgl_callback_t quitCallback)
#define RISKY_OPERATION
This is to use in nbgl_operationType_t when the operation is concerned by an internal warning....
void(* nbgl_choiceCallback_t)(bool confirm)
prototype of choice callback function
void nbgl_useCaseNavigableContent(const char *title, uint8_t initPage, uint8_t nbPages, nbgl_callback_t quitCallback, nbgl_navCallback_t navCallback, nbgl_layoutTouchCallback_t controlsCallback)
void nbgl_useCaseReviewStreamingFinish(const char *finishTitle, nbgl_choiceCallback_t choiceCallback)
#define NO_THREAT_OPERATION
This is to use in nbgl_operationType_t when the operation is concerned by an internal information....
void nbgl_useCaseChoiceWithDetails(const nbgl_icon_details_t *icon, const char *message, const char *subMessage, const char *confirmText, const char *cancelText, nbgl_warningDetails_t *details, nbgl_choiceCallback_t callback)
void nbgl_useCaseAdvancedChoiceWithDetails(const nbgl_icon_details_t *centerIcon, const nbgl_icon_details_t *headerIcon, const char *title, const char *message, const char *subMessage, const char *confirmText, const char *cancelText, nbgl_warningDetails_t *details, nbgl_choiceCallback_t callback)
void nbgl_useCaseSpinner(const char *text)
void nbgl_useCaseConfirm(const char *message, const char *subMessage, const char *confirmText, const char *rejectText, nbgl_callback_t callback)
bool nbgl_useCaseShowInfoAndSettings(uint8_t initPage)
void nbgl_useCaseStatus(const char *message, bool isSuccess, nbgl_callback_t quitCallback)
@ W3C_THREAT_DETECTED_WARN
Web3 Checks: Threat detected (see reportRisk field).
@ BLIND_SIGNING_WARN
Blind signing.
@ GATED_SIGNING_WARN
Gated signing.
@ W3C_NO_THREAT_WARN
Web3 Checks: No Threat detected.
@ W3C_RISK_DETECTED_WARN
Web3 Checks: Risk detected (see reportRisk field).
void nbgl_useCaseGenericConfiguration(const char *title, uint8_t initPage, const nbgl_genericContents_t *contents, nbgl_callback_t quitCallback)
#define INIT_HOME_PAGE
Value to pass to nbgl_useCaseHomeAndSettings() initSettingPage parameter to initialize the use case o...
void nbgl_useCaseKeypad(const char *title, uint8_t minDigits, uint8_t maxDigits, bool shuffled, bool hidden, nbgl_pinValidCallback_t validatePinCallback, nbgl_callback_t backCallback)
void nbgl_useCaseReviewStreamingContinueExt(const nbgl_contentTagValueList_t *tagValueList, nbgl_choiceCallback_t choiceCallback, nbgl_callback_t skipCallback)
void nbgl_useCaseReviewBlindSigning(nbgl_operationType_t operationType, const nbgl_contentTagValueList_t *tagValueList, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, const char *finishTitle, const nbgl_tipBox_t *tipBox, nbgl_choiceCallback_t choiceCallback)
void nbgl_useCaseChoice(const nbgl_icon_details_t *icon, const char *message, const char *subMessage, const char *confirmText, const char *rejectString, nbgl_choiceCallback_t callback)
void nbgl_useCaseGenericReview(const nbgl_genericContents_t *contents, const char *rejectText, nbgl_callback_t rejectCallback)
#define STATUS_SCREEN_DURATION
void nbgl_useCaseKeyboard(const nbgl_keyboardParams_t *params, nbgl_callback_t backCallback)
void nbgl_useCaseReviewStreamingBlindSigningStart(nbgl_operationType_t operationType, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, nbgl_choiceCallback_t choiceCallback)
void nbgl_useCaseReviewStreamingContinue(const nbgl_contentTagValueList_t *tagValueList, nbgl_choiceCallback_t choiceCallback)
void nbgl_useCaseReviewLight(nbgl_operationType_t operationType, const nbgl_contentTagValueList_t *tagValueList, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, const char *finishTitle, nbgl_choiceCallback_t choiceCallback)
uint8_t nbgl_useCaseGetNbChoicesInPage(uint8_t nbChoices, const nbgl_contentRadioChoice_t *choicesList, uint8_t startIndex, bool withNav)
void(* nbgl_keyboardButtonsCallback_t)(nbgl_layoutKeyboardContent_t *content, uint32_t *mask)
prototype of keyboard buttons callback function
#define REAL_TYPE_MASK
Mask to apply on nbgl_operationType_t to extract the base nbgl_opType_t. Bits 0-3 are reserved for th...
void nbgl_useCaseReviewStatus(nbgl_reviewStatusType_t reviewStatusType, nbgl_callback_t quitCallback)
#define ADDRESS_BOOK_OPERATION
This is to use in nbgl_operationType_t when the operation is related to "AddressBook" to adapt wordin...
nbgl_reviewStatusType_t
The different types of review status.
@ STATUS_TYPE_TRANSACTION_REJECTED
@ STATUS_TYPE_ADDRESS_REJECTED
@ STATUS_TYPE_TRANSACTION_SIGNED
@ STATUS_TYPE_OPERATION_REJECTED
@ STATUS_TYPE_OPERATION_SIGNED
@ STATUS_TYPE_ADDRESS_VERIFIED
@ STATUS_TYPE_MESSAGE_SIGNED
@ STATUS_TYPE_MESSAGE_REJECTED
bool(* nbgl_navCallback_t)(uint8_t page, nbgl_pageContent_t *content)
prototype of navigation callback function
#define HAS_INITIAL_WARNING(_warning)
void nbgl_useCaseAddressReview(const char *address, const nbgl_contentTagValueList_t *additionalTagValueList, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, nbgl_choiceCallback_t choiceCallback)
@ TYPE_MESSAGE
@ TYPE_TRANSACTION
For operations transferring a coin or taken from an account to another.
void nbgl_useCaseAdvancedReviewStreamingStart(nbgl_operationType_t operationType, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, const nbgl_warning_t *warning, nbgl_choiceCallback_t choiceCallback)
void nbgl_useCaseAdvancedReview(nbgl_operationType_t operationType, const nbgl_contentTagValueList_t *tagValueList, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, const char *finishTitle, const nbgl_tipBox_t *tipBox, const nbgl_warning_t *warning, nbgl_choiceCallback_t choiceCallback)
This structure contains data to build a BARS_LIST content.
const uint8_t * tokens
array of tokens, one for each bar (nbBars items)
const char *const * barTexts
array of texts for each bar (nbBars items, in black/bold)
uint8_t nbBars
number of elements in barTexts and tokens array
const nbgl_icon_details_t * icon
the icon (can be null)
const char * title
title in black large (can be null)
const char * description
description in black small regular case (can be null)
const char * text2
second text (can be null)
const char * text1
first text (can be null)
nbgl_contentCenteredInfoStyle_t style
style to apply to this info
const nbgl_icon_details_t * icon
a buffer containing the 1BPP icon
const char * buttonText
text of the long press button
const nbgl_icon_details_t * icon
a buffer containing the 1BPP icon
const char * text
centered text in large case
const char *const * infoContents
array of contents of infos (in black)
const char *const * infoTypes
array of types of infos (in black/bold)
uint8_t nbInfos
number of elements in infoTypes and infoContents array
This structure contains a list of names to build a list of radio buttons (on the right part of screen...
uint8_t token
the token that will be used as argument of the callback
uint8_t initChoice
index of the current choice
const char *const * names
array of strings giving the choices (nbChoices)
uint8_t nbChoices
number of choices
This structure contains info to build a switch (on the right) with a description (on the left),...
const char * text
main text for the switch
uint8_t token
the token that will be used as argument of the callback (unused on Nano)
nbgl_state_t initState
initial state of the switch
const char * subText
description under main text (NULL terminated, single line, may be null)
const char * confirmationText
text of the confirmation button, if NULL "It matches" is used
uint8_t confirmationToken
the token used as argument of the onActionCallback
nbgl_contentTagValueList_t tagValueList
list of tag/value pairs
const nbgl_contentTagValue_t * pairs
array of [tag,value] pairs (nbPairs items). If NULL, callback is used instead
nbgl_contentTagValueCallback_t callback
function to call to retrieve a given pair
This structure contains a [tag,value] pair and possible extensions.
const nbgl_contentValueExt_t * extension
if not NULL, gives additional info on value field
const nbgl_icon_details_t * valueIcon
const char * value
string giving the value name
const char * item
string giving the tag name
uint8_t centeredInfo
if set to 1, the tag will be displayed as a centered info
This structure contains additions to a tag/value pair, to be able to build a screen to display these ...
nbgl_contentValueAliasType_t aliasType
type of alias
const struct nbgl_contentTagValueList_s * tagValuelist
if aliasType is TAG_VALUE_LIST_ALIAS
const struct nbgl_contentInfoList_s * infolist
if aliasType is INFO_LIST_ALIAS
This structure contains data to build a content.
nbgl_content_u content
nbgl_contentActionCallback_t contentActionCallback
callback to be called when an action on an object occurs
nbgl_contentType_t type
type of page content in the content union
uint8_t nbBars
number of touchable bars
uint8_t nbContents
number of contents
const nbgl_content_t * contentsList
array of nbgl_content_t (nbContents items).
nbgl_contentCallback_t contentGetterCallback
function to call to retrieve a given content
nbgl_genericBarList_t barList
touchable bars list, if type == BAR_LIST_WARNING
nbgl_genericDetailsType_t type
type of content in the page, determining what to use in the following union
nbgl_contentCenter_t centeredInfo
centered info, if type == CENTERED_INFO_WARNING
Structure describing the action button in Home Screen.
nbgl_callback_t onButtonCallback
callback to call when the button is pressed
nbgl_keyboardButtonsCallback_t updateButtonsCallback
callback to call when a key is pressed to update suggestions
nbgl_layoutTouchCallback_t onButtonCallback
callback to call when one of the buttons is pressed
const char ** buttons
array of strings for buttons (last ones can be NULL)
int firstButtonToken
first token used for buttons, provided in onButtonCallback
Structure containing all parameters for keyboard use case.
keyboardMode_t mode
keyboard mode to start with
nbgl_kbdSuggestParams_t suggestionParams
nbgl_kbdButtonParams_t confirmationParams
used if type is KEYBOARD_WITH_SUGGESTIONS
bool lettersOnly
if true, only display letter keys and Backspace
nbgl_layoutKeyboardContentType_t type
type of content
const char * title
centered title explaining the screen
char * entryBuffer
already entered text
This structure contains info to build a keyboard with nbgl_layoutAddKeyboard().
This structure contains a list of names to build a menu list on Nanos, with for each item a descripti...
nbgl_menuListCallback_t callback
function to call to retrieve a menu list item text
uint8_t nbChoices
total number of choices in the menu list
uint8_t selectedChoice
index of the selected choice (centered, in bold)
This structure contains info to build a navigation bar at the bottom of the screen.
This structure contains info to build suggestion buttons.
uint8_t nbUsedButtons
the number of actually used (displayed) buttons
nbgl_contentRadioChoice_t choicesList
CHOICES_LIST type
Definition nbgl_flow.h:69
nbgl_contentSwitchesList_t switchesList
SWITCHES_LIST type
Definition nbgl_flow.h:67
nbgl_contentBarsList_t barsList
BARS_LIST type
Definition nbgl_flow.h:70
nbgl_contentInfoButton_t infoButton
INFO_BUTTON type
Definition nbgl_flow.h:64
nbgl_contentInfoList_t infosList
INFOS_LIST type
Definition nbgl_flow.h:68
nbgl_contentTagValueList_t tagValueList
TAG_VALUE_LIST type
Definition nbgl_flow.h:65
nbgl_contentType_t type
type of page content in the following union
Definition nbgl_flow.h:61
nbgl_contentCenteredInfo_t centeredInfo
CENTERED_INFO type
Definition nbgl_flow.h:63
nbgl_contentTagValueConfirm_t tagValueConfirm
TAG_VALUE_CONFIRM type
Definition nbgl_flow.h:66
uint8_t nbSwitches
number of elements in switches and tokens array
const nbgl_contentSwitch_t * switches
array of switches (nbSwitches items)
The necessary parameters to build a tip-box in first review page and the modal if this tip box is tou...
The necessary parameters to build a warning page preceding a review. One can either use predefinedSet...
const nbgl_preludeDetails_t * prelude
if not null, means that the review can start by a prelude
const nbgl_warningDetails_t * reviewDetails
uint32_t predefinedSet
const nbgl_contentCenter_t * info
parameters to build the intro warning page, if not using pre-defined
nbgl_contentInfoList_t infosList
INFOS_LIST type
nbgl_contentTagValueConfirm_t tagValueConfirm
TAG_VALUE_CONFIRM type
nbgl_contentTagValueList_t tagValueList
TAG_VALUE_LIST type
nbgl_contentCenteredInfo_t centeredInfo
CENTERED_INFO type
nbgl_contentBarsList_t barsList
BARS_LIST type
nbgl_contentSwitchesList_t switchesList
SWITCHES_LIST type
nbgl_contentInfoButton_t infoButton
INFO_BUTTON type
nbgl_contentRadioChoice_t choicesList
CHOICES_LIST type
static nbgl_touchStatePosition_t pos
Definition ux.c:56