Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
nbgl_use_case.c
Go to the documentation of this file.
1
6#ifdef NBGL_USE_CASE
7#ifdef 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 "glyphs.h"
16#include "os_io_seph_ux.h"
17#include "os_pic.h"
18#include "os_print.h"
19#include "os_helpers.h"
20
21/*********************
22 * DEFINES
23 *********************/
24
25/* Defines for definition and usage of genericContextPagesInfo */
26#define PAGE_NB_ELEMENTS_BITS 3
27#define GET_PAGE_NB_ELEMENTS(pageData) ((pageData) &0x07)
28#define SET_PAGE_NB_ELEMENTS(nbElements) ((nbElements) &0x07)
29
30#define PAGE_FLAG_BITS 1
31#define GET_PAGE_FLAG(pageData) (((pageData) &0x08) >> 3)
32#define SET_PAGE_FLAG(flag) (((flag) &0x01) << 3)
33
34#define PAGE_DATA_BITS (PAGE_NB_ELEMENTS_BITS + PAGE_FLAG_BITS)
35#define PAGES_PER_UINT8 (8 / PAGE_DATA_BITS)
36#define SET_PAGE_DATA(pageIdx, pageData) \
37 (pagesData[pageIdx / PAGES_PER_UINT8] = pageData \
38 << ((pageIdx % PAGES_PER_UINT8) * PAGE_DATA_BITS))
39
40#define MAX_PAGE_NB 256
41#define MAX_MODAL_PAGE_NB 32
42
43/* Alias to clarify usage of genericContext hasStartingContent and hasFinishingContent feature */
44#define STARTING_CONTENT localContentsList[0]
45#define FINISHING_CONTENT localContentsList[1]
46
47/* max number of lines for address under QR Code */
48#define QRCODE_NB_MAX_LINES 3
49/* max number of char for reduced QR Code address */
50#define QRCODE_REDUCED_ADDR_LEN 128
51
52/* maximum number of pairs in a page of address confirm */
53#define ADDR_VERIF_NB_PAIRS 3
54
55// macros to ease access to shared contexts
56#define sharedContext genericContext.sharedCtx
57#define keypadContext sharedContext.keypad
58#define keyboardContext sharedContext.keyboard
59#define reviewWithWarnCtx sharedContext.reviewWithWarning
60#define choiceWithDetailsCtx sharedContext.choiceWithDetails
61
62/* max length of the string displaying the description of the Web3 Checks report */
63#define W3C_DESCRIPTION_MAX_LEN 128
64
65/**********************
66 * TYPEDEFS
67 **********************/
68enum {
69 BACK_TOKEN = 0,
70 NEXT_TOKEN,
71 QUIT_TOKEN,
72 NAV_TOKEN,
73 MODAL_NAV_TOKEN,
74 SKIP_TOKEN,
75 CONTINUE_TOKEN,
76 ADDRESS_QRCODE_BUTTON_TOKEN,
77 ACTION_BUTTON_TOKEN,
78 CHOICE_TOKEN,
79 DETAILS_BUTTON_TOKEN,
80 CONFIRM_TOKEN,
81 REJECT_TOKEN,
82 VALUE_ALIAS_TOKEN,
83 INFO_ALIAS_TOKEN,
84 INFOS_TIP_BOX_TOKEN,
85 BLIND_WARNING_TOKEN,
86 WARNING_BUTTON_TOKEN,
87 CHOICE_DETAILS_TOKEN,
88 TIP_BOX_TOKEN,
89 QUIT_TIPBOX_MODAL_TOKEN,
90 WARNING_CHOICE_TOKEN,
91 DISMISS_QR_TOKEN,
92 DISMISS_WARNING_TOKEN,
93 DISMISS_DETAILS_TOKEN,
94 PRELUDE_CHOICE_TOKEN,
95 KEYBOARD_BUTTON_TOKEN,
96 KEYBOARD_CROSS_TOKEN,
97 FIRST_WARN_BAR_TOKEN,
98 LAST_WARN_BAR_TOKEN = (FIRST_WARN_BAR_TOKEN + NB_WARNING_TYPES - 1),
99};
100CCASSERT(NBGL_TOKENS, LAST_WARN_BAR_TOKEN + 1 < FIRST_USER_TOKEN);
101
102typedef enum {
103 REVIEW_NAV = 0,
104 SETTINGS_NAV,
105 GENERIC_NAV,
106 STREAMING_NAV
107} NavType_t;
108
109typedef struct DetailsContext_s {
110 uint8_t nbPages;
111 uint8_t currentPage;
112 uint8_t currentPairIdx;
113 bool wrapping;
114 const char *tag;
115 const char *value;
116 const char *nextPageStart;
117} DetailsContext_t;
118
119typedef struct AddressConfirmationContext_s {
120 nbgl_layoutTagValue_t tagValuePairs[ADDR_VERIF_NB_PAIRS];
121 nbgl_layout_t *modalLayout;
122 uint8_t nbPairs;
123} AddressConfirmationContext_t;
124
125#ifdef NBGL_KEYPAD
126typedef struct KeypadContext_s {
127 uint8_t pinEntry[KEYPAD_MAX_DIGITS];
128 uint8_t pinLen;
129 uint8_t pinMinDigits;
130 uint8_t pinMaxDigits;
131 nbgl_layout_t *layoutCtx;
132 bool hidden;
133 nbgl_pinValidCallback_t onValidatePin;
134} KeypadContext_t;
135#endif
136
137#ifdef NBGL_KEYBOARD
138typedef struct KeyboardContext_s {
139 nbgl_layoutKeyboardContent_t keyboardContent;
140 char *entryBuffer;
141 uint8_t entryMaxLen;
142 int keyboardIndex;
143 keyboardCase_t casing;
144 nbgl_layout_t *layoutCtx;
145 nbgl_keyboardButtonsCallback_t getSuggestionButtons;
146} KeyboardContext_t;
147#endif
148
149typedef struct ReviewWithWarningContext_s {
150 bool isStreaming;
151 nbgl_operationType_t operationType;
152 const nbgl_contentTagValueList_t *tagValueList;
153 const nbgl_icon_details_t *icon;
154 const char *reviewTitle;
155 const char *reviewSubTitle;
156 const char *finishTitle;
157 const nbgl_warning_t *warning;
158 nbgl_choiceCallback_t choiceCallback;
159 nbgl_layout_t *layoutCtx;
160 nbgl_layout_t *modalLayout;
161 uint8_t securityReportLevel; // level 1 is the first level of menus
162 bool isIntro; // set to true during intro (before actual review)
163} ReviewWithWarningContext_t;
164
165typedef struct ChoiceWithDetailsContext_s {
166 const nbgl_genericDetails_t *details;
167 nbgl_layout_t *layoutCtx;
168 nbgl_layout_t *modalLayout;
169 uint8_t level; // level 1 is the first level of menus
170} ChoiceWithDetailsContext_t;
171
172typedef enum {
173 SHARE_CTX_KEYPAD,
174 SHARE_CTX_REVIEW_WITH_WARNING,
175 SHARE_CTX_CHOICE_WITH_DETAILS,
176} SharedContextUsage_t;
177
178// this union is intended to save RAM for context storage
179// indeed, these 3 contexts cannot happen simultaneously
180typedef struct {
181 union {
182#ifdef NBGL_KEYPAD
183 KeypadContext_t keypad;
184#endif
185#ifdef NBGL_KEYBOARD
186 KeyboardContext_t keyboard;
187#endif
188 ReviewWithWarningContext_t reviewWithWarning;
189 ChoiceWithDetailsContext_t choiceWithDetails;
190 };
191 SharedContextUsage_t usage;
192} SharedContext_t;
193
194typedef enum {
195 USE_CASE_GENERIC = 0,
196 USE_CASE_SPINNER
197} GenericContextType_t;
198
199typedef struct {
200 GenericContextType_t type; // type of Generic context usage
201 uint8_t spinnerPosition;
202 nbgl_genericContents_t genericContents;
203 int8_t currentContentIdx;
204 uint8_t currentContentElementNb;
205 uint8_t currentElementIdx;
206 bool hasStartingContent;
207 bool hasFinishingContent;
208 const char *detailsItem;
209 const char *detailsvalue;
210 bool detailsWrapping;
211 bool validWarningCtx; // set to true if the WarningContext is valid
213 *currentPairs; // to be used to retrieve the pairs with value alias
215 currentCallback; // to be used to retrieve the pairs with value alias
216 nbgl_layout_t modalLayout;
217 nbgl_layout_t backgroundLayout;
218 const nbgl_contentInfoList_t *currentInfos;
219 const nbgl_contentTagValueList_t *currentTagValues;
220 nbgl_tipBox_t tipBox;
221 SharedContext_t sharedCtx; // multi-purpose context shared for non-concurrent usages
222} GenericContext_t;
223
224typedef struct {
225 const char *appName;
226 const nbgl_icon_details_t *appIcon;
227 const char *tagline;
228 const nbgl_genericContents_t *settingContents;
229 const nbgl_contentInfoList_t *infosList;
230 nbgl_homeAction_t homeAction;
231 nbgl_callback_t quitCallback;
232} nbgl_homeAndSettingsContext_t;
233
234typedef struct {
235 nbgl_operationType_t operationType;
236 nbgl_choiceCallback_t choiceCallback;
237} nbgl_reviewContext_t;
238
239typedef struct {
240 nbgl_operationType_t operationType;
241 nbgl_choiceCallback_t choiceCallback;
242 nbgl_callback_t skipCallback;
243 const nbgl_icon_details_t *icon;
244 uint8_t stepPageNb;
245} nbgl_reviewStreamingContext_t;
246
247typedef union {
248 nbgl_homeAndSettingsContext_t homeAndSettings;
249 nbgl_reviewContext_t review;
250 nbgl_reviewStreamingContext_t reviewStreaming;
251} nbgl_BundleNavContext_t;
252
253typedef struct {
254 const nbgl_icon_details_t *icon;
255 const char *text;
256 const char *subText;
257} SecurityReportItem_t;
258
259/**********************
260 * STATIC VARIABLES
261 **********************/
262
263// char buffers to build some strings
264static char tmpString[W3C_DESCRIPTION_MAX_LEN];
265
266// multi-purposes callbacks
267static nbgl_callback_t onQuit;
268static nbgl_callback_t onContinue;
269static nbgl_callback_t onAction;
270static nbgl_navCallback_t onNav;
271static nbgl_layoutTouchCallback_t onControls;
272static nbgl_contentActionCallback_t onContentAction;
273static nbgl_choiceCallback_t onChoice;
274static nbgl_callback_t onModalConfirm;
275
276// contexts for background and modal pages
277static nbgl_page_t *pageContext;
278static nbgl_page_t *modalPageContext;
279
280// context for pages
281static const char *pageTitle;
282
283// context for tip-box
284#define activeTipBox genericContext.tipBox
285
286// context for navigation use case
287static nbgl_pageNavigationInfo_t navInfo;
288static bool forwardNavOnly;
289static NavType_t navType;
290
291static DetailsContext_t detailsContext;
292
293// context for address review
294static AddressConfirmationContext_t addressConfirmationContext;
295
296// contexts for generic navigation
297static GenericContext_t genericContext;
298static nbgl_content_t
299 localContentsList[3]; // 3 needed for nbgl_useCaseReview (starting page / tags / final page)
300static uint8_t genericContextPagesInfo[MAX_PAGE_NB / PAGES_PER_UINT8];
301static uint8_t modalContextPagesInfo[MAX_MODAL_PAGE_NB / PAGES_PER_UINT8];
302
303// contexts for bundle navigation
304static nbgl_BundleNavContext_t bundleNavContext;
305
306// indexed by nbgl_contentType_t
307static const uint8_t nbMaxElementsPerContentType[] = {
308 1, // CENTERED_INFO
309 1, // EXTENDED_CENTER
310 1, // INFO_LONG_PRESS
311 1, // INFO_BUTTON
312 1, // TAG_VALUE_LIST (computed dynamically)
313 1, // TAG_VALUE_DETAILS
314 1, // TAG_VALUE_CONFIRM
315 3, // SWITCHES_LIST (computed dynamically)
316 3, // INFOS_LIST (computed dynamically)
317 5, // CHOICES_LIST (computed dynamically)
318 5, // BARS_LIST (computed dynamically)
319};
320
321// clang-format off
322static const SecurityReportItem_t securityReportItems[NB_WARNING_TYPES] = {
324 .icon = &WARNING_ICON,
325 .text = "Blind signing required",
326 .subText = "This transaction's details are not fully verifiable. If "
327 "you sign, you could lose all your assets."
328 },
329 [W3C_ISSUE_WARN] = {
330 .icon = &WARNING_ICON,
331 .text = "Transaction Check unavailable",
332 .subText = NULL
333 },
335 .icon = &WARNING_ICON,
336 .text = "Risk detected",
337 .subText = "This transaction was scanned as risky by Web3 Checks."
338 },
340 .icon = &WARNING_ICON,
341 .text = "Critical threat",
342 .subText = "This transaction was scanned as malicious by Web3 Checks."
343 },
345 .icon = NULL,
346 .text = "No threat detected",
347 .subText = "Transaction Check didn't find any threat, but always "
348 "review transaction details carefully."
349 }
350};
351// clang-format on
352
353// configuration of warning when using @ref nbgl_useCaseReviewBlindSigning()
354static const nbgl_warning_t blindSigningWarning = {.predefinedSet = (1 << BLIND_SIGNING_WARN)};
355
356#ifdef NBGL_QRCODE
357/* buffer to store reduced address under QR Code */
358static char reducedAddress[QRCODE_REDUCED_ADDR_LEN];
359#endif // NBGL_QRCODE
360
361/**********************
362 * STATIC FUNCTIONS
363 **********************/
364static void displayReviewPage(uint8_t page, bool forceFullRefresh);
365static void displayDetailsPage(uint8_t page, bool forceFullRefresh);
366static void displayTagValueListModalPage(uint8_t pageIdx, bool forceFullRefresh);
367static void displayFullValuePage(const char *backText,
368 const char *aliasText,
369 const nbgl_contentValueExt_t *extension);
370static void displayInfosListModal(const char *modalTitle,
371 const nbgl_contentInfoList_t *infos,
372 bool fromReview);
373static void displayTagValueListModal(const nbgl_contentTagValueList_t *tagValues);
374static void displaySettingsPage(uint8_t page, bool forceFullRefresh);
375static void displayGenericContextPage(uint8_t pageIdx, bool forceFullRefresh);
376static void pageCallback(int token, uint8_t index);
377#ifdef NBGL_QRCODE
378static void displayAddressQRCode(void);
379#endif // NBGL_QRCODE
380static void modalLayoutTouchCallback(int token, uint8_t index);
381static void displaySkipWarning(void);
382
383static void bundleNavStartHome(void);
384static void bundleNavStartSettingsAtPage(uint8_t initSettingPage);
385static void bundleNavStartSettings(void);
386
387static void bundleNavReviewStreamingChoice(bool confirm);
388static nbgl_layout_t *displayModalDetails(const nbgl_warningDetails_t *details, uint8_t token);
389static void displaySecurityReport(uint32_t set);
390static void displayCustomizedSecurityReport(const nbgl_warningDetails_t *details);
391static void displayInitialWarning(void);
392static void useCaseReview(nbgl_operationType_t operationType,
393 const nbgl_contentTagValueList_t *tagValueList,
394 const nbgl_icon_details_t *icon,
395 const char *reviewTitle,
396 const char *reviewSubTitle,
397 const char *finishTitle,
398 const nbgl_tipBox_t *tipBox,
399 nbgl_choiceCallback_t choiceCallback,
400 bool isLight,
401 bool playNotifSound);
402static void useCaseReviewStreamingStart(nbgl_operationType_t operationType,
403 const nbgl_icon_details_t *icon,
404 const char *reviewTitle,
405 const char *reviewSubTitle,
406 nbgl_choiceCallback_t choiceCallback,
407 bool playNotifSound);
408static void useCaseHomeExt(const char *appName,
409 const nbgl_icon_details_t *appIcon,
410 const char *tagline,
411 bool withSettings,
412 nbgl_homeAction_t *homeAction,
413 nbgl_callback_t topRightCallback,
414 nbgl_callback_t quitCallback);
415static void displayDetails(const char *tag, const char *value, bool wrapping);
416
417static void reset_callbacks_and_context(void)
418{
419 onQuit = NULL;
420 onContinue = NULL;
421 onAction = NULL;
422 onNav = NULL;
423 onControls = NULL;
424 onContentAction = NULL;
425 onChoice = NULL;
426 memset(&genericContext, 0, sizeof(genericContext));
427}
428
429// Helper to set genericContext page info
430static void genericContextSetPageInfo(uint8_t pageIdx, uint8_t nbElements, bool flag)
431{
432 uint8_t pageData = SET_PAGE_NB_ELEMENTS(nbElements) + SET_PAGE_FLAG(flag);
433
434 genericContextPagesInfo[pageIdx / PAGES_PER_UINT8]
435 &= ~(0x0F << ((pageIdx % PAGES_PER_UINT8) * PAGE_DATA_BITS));
436 genericContextPagesInfo[pageIdx / PAGES_PER_UINT8]
437 |= pageData << ((pageIdx % PAGES_PER_UINT8) * PAGE_DATA_BITS);
438}
439
440// Helper to get genericContext page info
441static void genericContextGetPageInfo(uint8_t pageIdx, uint8_t *nbElements, bool *flag)
442{
443 uint8_t pageData = genericContextPagesInfo[pageIdx / PAGES_PER_UINT8]
444 >> ((pageIdx % PAGES_PER_UINT8) * PAGE_DATA_BITS);
445 if (nbElements != NULL) {
446 *nbElements = GET_PAGE_NB_ELEMENTS(pageData);
447 }
448 if (flag != NULL) {
449 *flag = GET_PAGE_FLAG(pageData);
450 }
451}
452
453// Helper to set modalContext page info
454static void modalContextSetPageInfo(uint8_t pageIdx, uint8_t nbElements)
455{
456 uint8_t pageData = SET_PAGE_NB_ELEMENTS(nbElements);
457
458 modalContextPagesInfo[pageIdx / PAGES_PER_UINT8]
459 &= ~(0x0F << ((pageIdx % PAGES_PER_UINT8) * PAGE_DATA_BITS));
460 modalContextPagesInfo[pageIdx / PAGES_PER_UINT8]
461 |= pageData << ((pageIdx % PAGES_PER_UINT8) * PAGE_DATA_BITS);
462}
463
464// Helper to get modalContext page info
465static void modalContextGetPageInfo(uint8_t pageIdx, uint8_t *nbElements)
466{
467 uint8_t pageData = modalContextPagesInfo[pageIdx / PAGES_PER_UINT8]
468 >> ((pageIdx % PAGES_PER_UINT8) * PAGE_DATA_BITS);
469 if (nbElements != NULL) {
470 *nbElements = GET_PAGE_NB_ELEMENTS(pageData);
471 }
472}
473
474// Simple helper to get the number of elements inside a nbgl_content_t
475static uint8_t getContentNbElement(const nbgl_content_t *content)
476{
477 switch (content->type) {
478 case TAG_VALUE_LIST:
479 return content->content.tagValueList.nbPairs;
482 case SWITCHES_LIST:
483 return content->content.switchesList.nbSwitches;
484 case INFOS_LIST:
485 return content->content.infosList.nbInfos;
486 case CHOICES_LIST:
487 return content->content.choicesList.nbChoices;
488 case BARS_LIST:
489 return content->content.barsList.nbBars;
490 default:
491 return 1;
492 }
493}
494
495// Helper to retrieve the content inside a nbgl_genericContents_t using
496// either the contentsList or using the contentGetterCallback
497static const nbgl_content_t *getContentAtIdx(const nbgl_genericContents_t *genericContents,
498 int8_t contentIdx,
499 nbgl_content_t *content)
500{
501 if (contentIdx < 0 || contentIdx >= genericContents->nbContents) {
502 LOG_DEBUG(USE_CASE_LOGGER, "No content available at %d\n", contentIdx);
503 return NULL;
504 }
505
506 if (genericContents->callbackCallNeeded) {
507 // Retrieve content through callback, but first memset the content.
508 memset(content, 0, sizeof(nbgl_content_t));
509 genericContents->contentGetterCallback(contentIdx, content);
510 return content;
511 }
512 else {
513 // Retrieve content through list
514 return PIC(&genericContents->contentsList[contentIdx]);
515 }
516}
517
518static void prepareNavInfo(bool isReview, uint8_t nbPages, const char *rejectText)
519{
520 memset(&navInfo, 0, sizeof(navInfo));
521
522 navInfo.nbPages = nbPages;
523 navInfo.tuneId = TUNE_TAP_CASUAL;
524 navInfo.progressIndicator = false;
525 navInfo.navType = NAV_WITH_BUTTONS;
526
527 if (isReview == false) {
528 navInfo.navWithButtons.navToken = NAV_TOKEN;
529 navInfo.navWithButtons.backButton = true;
530 }
531 else {
532 navInfo.quitToken = REJECT_TOKEN;
533 navInfo.navWithButtons.quitText = rejectText;
534 navInfo.navWithButtons.navToken = NAV_TOKEN;
536 = ((navType == STREAMING_NAV) && (nbPages < 2)) ? false : true;
537 navInfo.navWithButtons.visiblePageIndicator = (navType != STREAMING_NAV);
538 }
539}
540
541static void prepareReviewFirstPage(nbgl_contentCenter_t *contentCenter,
542 const nbgl_icon_details_t *icon,
543 const char *reviewTitle,
544 const char *reviewSubTitle)
545{
546 contentCenter->icon = icon;
547 contentCenter->title = reviewTitle;
548 contentCenter->description = reviewSubTitle;
549 contentCenter->subText = "Swipe to review";
550 contentCenter->smallTitle = NULL;
551 contentCenter->iconHug = 0;
552 contentCenter->padding = false;
553 contentCenter->illustrType = ICON_ILLUSTRATION;
554}
555
556static const char *getFinishTitle(nbgl_operationType_t operationType, const char *finishTitle)
557{
558 if (finishTitle != NULL) {
559 return finishTitle;
560 }
561 switch (operationType & REAL_TYPE_MASK) {
562 case TYPE_TRANSACTION:
563 return "Sign transaction";
564 case TYPE_MESSAGE:
565 return "Sign message";
566 default:
567 return "Sign operation";
568 }
569}
570
571static void prepareReviewLastPage(nbgl_operationType_t operationType,
572 nbgl_contentInfoLongPress_t *infoLongPress,
573 const nbgl_icon_details_t *icon,
574 const char *finishTitle)
575{
576 infoLongPress->text = getFinishTitle(operationType, finishTitle);
577 infoLongPress->icon = icon;
578 infoLongPress->longPressText = "Hold to sign";
579 infoLongPress->longPressToken = CONFIRM_TOKEN;
580}
581
582static void prepareReviewLightLastPage(nbgl_operationType_t operationType,
583 nbgl_contentInfoButton_t *infoButton,
584 const nbgl_icon_details_t *icon,
585 const char *finishTitle)
586{
587 infoButton->text = getFinishTitle(operationType, finishTitle);
588 infoButton->icon = icon;
589 if (operationType & ADDRESS_BOOK_OPERATION) {
590 infoButton->buttonText = "Confirm";
591 }
592 else {
593 infoButton->buttonText = "Approve";
594 }
595 infoButton->buttonToken = CONFIRM_TOKEN;
596}
597
598static const char *getRejectReviewText(nbgl_operationType_t operationType)
599{
600 if (operationType & ADDRESS_BOOK_OPERATION) {
601 return "Cancel";
602 }
603 return "Reject";
604}
605
606// function called when navigating (or exiting) modal details pages
607// or when skip choice is displayed
608static void pageModalCallback(int token, uint8_t index)
609{
610 LOG_DEBUG(USE_CASE_LOGGER, "pageModalCallback, token = %d, index = %d\n", token, index);
611
612 if (token == INFOS_TIP_BOX_TOKEN) {
613 // the icon next to info type alias has been touched
614 displayFullValuePage(activeTipBox.infos.infoTypes[index],
615 activeTipBox.infos.infoContents[index],
616 &activeTipBox.infos.infoExtensions[index]);
617 return;
618 }
619 else if (token == INFO_ALIAS_TOKEN) {
620 // the icon next to info type alias has been touched, but coming from review
621 displayFullValuePage(genericContext.currentInfos->infoTypes[index],
622 genericContext.currentInfos->infoContents[index],
623 &genericContext.currentInfos->infoExtensions[index]);
624 return;
625 }
626 nbgl_pageRelease(modalPageContext);
627 modalPageContext = NULL;
628 if (token == NAV_TOKEN) {
629 if (index == EXIT_PAGE) {
630 // redraw the background layer
632 nbgl_refresh();
633 }
634 else {
635 displayDetailsPage(index, false);
636 }
637 }
638 if (token == MODAL_NAV_TOKEN) {
639 if (index == EXIT_PAGE) {
640 // redraw the background layer
642 nbgl_refresh();
643 }
644 else {
645 displayTagValueListModalPage(index, false);
646 }
647 }
648 else if (token == QUIT_TOKEN) {
649 // redraw the background layer
651 nbgl_refresh();
652 }
653 else if (token == QUIT_TIPBOX_MODAL_TOKEN) {
654 // if in "warning context", go back to security report
655 if (reviewWithWarnCtx.securityReportLevel == 2) {
656 reviewWithWarnCtx.securityReportLevel = 1;
657 displaySecurityReport(reviewWithWarnCtx.warning->predefinedSet);
658 }
659 else {
660 // redraw the background layer
662 nbgl_refresh();
663 }
664 }
665 else if (token == SKIP_TOKEN) {
666 if (index == 0) {
667 // display the last forward only review page, whatever it is
668 displayGenericContextPage(LAST_PAGE_FOR_REVIEW, true);
669 }
670 else {
671 // display background, which should be the page where skip has been touched
673 nbgl_refresh();
674 }
675 }
676 else if (token == CHOICE_TOKEN) {
677 if (index == 0) {
678 if (onModalConfirm != NULL) {
679 onModalConfirm();
680 onModalConfirm = NULL;
681 }
682 }
683 else {
684 // display background, which should be the page where skip has been touched
686 nbgl_refresh();
687 }
688 }
689}
690
691// generic callback for all pages except modal
692static void pageCallback(int token, uint8_t index)
693{
694 LOG_DEBUG(USE_CASE_LOGGER, "pageCallback, token = %d, index = %d\n", token, index);
695 if (token == QUIT_TOKEN) {
696 if (onQuit != NULL) {
697 onQuit();
698 }
699 }
700 else if (token == CONTINUE_TOKEN) {
701 if (onContinue != NULL) {
702 onContinue();
703 }
704 }
705 else if (token == CHOICE_TOKEN) {
706 if (onChoice != NULL) {
707 onChoice((index == 0) ? true : false);
708 }
709 }
710 else if (token == ACTION_BUTTON_TOKEN) {
711 if ((index == 0) && (onAction != NULL)) {
712 onAction();
713 }
714 else if ((index == 1) && (onQuit != NULL)) {
715 onQuit();
716 }
717 }
718#ifdef NBGL_QRCODE
719 else if (token == ADDRESS_QRCODE_BUTTON_TOKEN) {
720 displayAddressQRCode();
721 }
722#endif // NBGL_QRCODE
723 else if (token == CONFIRM_TOKEN) {
724 if (onChoice != NULL) {
725 onChoice(true);
726 }
727 }
728 else if (token == REJECT_TOKEN) {
729 if (onChoice != NULL) {
730 onChoice(false);
731 }
732 }
733 else if (token == DETAILS_BUTTON_TOKEN) {
734 displayDetails(genericContext.detailsItem,
735 genericContext.detailsvalue,
736 genericContext.detailsWrapping);
737 }
738 else if (token == NAV_TOKEN) {
739 if (index == EXIT_PAGE) {
740 if (onQuit != NULL) {
741 onQuit();
742 }
743 }
744 else {
745 if (navType == GENERIC_NAV || navType == STREAMING_NAV) {
746 displayGenericContextPage(index, false);
747 }
748 else if (navType == REVIEW_NAV) {
749 displayReviewPage(index, false);
750 }
751 else {
752 displaySettingsPage(index, false);
753 }
754 }
755 }
756 else if (token == NEXT_TOKEN) {
757 if (onNav != NULL) {
758 displayReviewPage(navInfo.activePage + 1, false);
759 }
760 else {
761 displayGenericContextPage(navInfo.activePage + 1, false);
762 }
763 }
764 else if (token == BACK_TOKEN) {
765 if (onNav != NULL) {
766 displayReviewPage(navInfo.activePage - 1, true);
767 }
768 else {
769 displayGenericContextPage(navInfo.activePage - 1, false);
770 }
771 }
772 else if (token == SKIP_TOKEN) {
773 // display a modal warning to confirm skip
774 displaySkipWarning();
775 }
776 else if (token == VALUE_ALIAS_TOKEN) {
777 // the icon next to value alias has been touched
778 const nbgl_contentTagValue_t *pair;
779 if (genericContext.currentPairs != NULL) {
780 pair = &genericContext.currentPairs[genericContext.currentElementIdx + index];
781 }
782 else {
783 pair = genericContext.currentCallback(genericContext.currentElementIdx + index);
784 }
785 displayFullValuePage(pair->item, pair->value, pair->extension);
786 }
787 else if (token == BLIND_WARNING_TOKEN) {
788 reviewWithWarnCtx.isIntro = false;
789 reviewWithWarnCtx.warning = NULL;
790 displaySecurityReport(1 << BLIND_SIGNING_WARN);
791 }
792 else if (token == WARNING_BUTTON_TOKEN) {
793 // top-right button, display the security modal
794 reviewWithWarnCtx.securityReportLevel = 1;
795 // if preset is used
796 if (reviewWithWarnCtx.warning->predefinedSet) {
797 displaySecurityReport(reviewWithWarnCtx.warning->predefinedSet);
798 }
799 else {
800 // use customized warning
801 if (reviewWithWarnCtx.isIntro) {
802 displayCustomizedSecurityReport(reviewWithWarnCtx.warning->introDetails);
803 }
804 else {
805 displayCustomizedSecurityReport(reviewWithWarnCtx.warning->reviewDetails);
806 }
807 }
808 }
809 else if (token == TIP_BOX_TOKEN) {
810 // if warning context is valid and if W3C directly display same as top-right
811 if (genericContext.validWarningCtx && (reviewWithWarnCtx.warning->predefinedSet != 0)) {
812 reviewWithWarnCtx.securityReportLevel = 1;
813 displaySecurityReport(reviewWithWarnCtx.warning->predefinedSet);
814 }
815 else {
816 displayInfosListModal(activeTipBox.modalTitle, &activeTipBox.infos, false);
817 }
818 }
819 else { // probably a control provided by caller
820 if (onContentAction != NULL) {
821 onContentAction(token, index, navInfo.activePage);
822 }
823 if (onControls != NULL) {
824 onControls(token, index);
825 }
826 }
827}
828
829// callback used for confirmation
830static void tickerCallback(void)
831{
832 nbgl_pageRelease(pageContext);
833 if (onQuit != NULL) {
834 onQuit();
835 }
836}
837
838// function used to display the current page in review
839static void displaySettingsPage(uint8_t page, bool forceFullRefresh)
840{
841 nbgl_pageContent_t content = {0};
842
843 if ((onNav == NULL) || (onNav(page, &content) == false)) {
844 return;
845 }
846
847 // override some fields
848 content.title = pageTitle;
849 content.isTouchableTitle = true;
850 content.titleToken = QUIT_TOKEN;
851 content.tuneId = TUNE_TAP_CASUAL;
852
853 navInfo.activePage = page;
854 pageContext = nbgl_pageDrawGenericContent(&pageCallback, &navInfo, &content);
855
856 if (forceFullRefresh) {
858 }
859 else {
861 }
862}
863
864// function used to display the current page in review
865static void displayReviewPage(uint8_t page, bool forceFullRefresh)
866{
867 nbgl_pageContent_t content = {0};
868
869 // ensure the page is valid
870 if ((navInfo.nbPages != 0) && (page >= (navInfo.nbPages))) {
871 return;
872 }
873 navInfo.activePage = page;
874 if ((onNav == NULL) || (onNav(navInfo.activePage, &content) == false)) {
875 return;
876 }
877
878 // override some fields
879 content.title = NULL;
880 content.isTouchableTitle = false;
881 content.tuneId = TUNE_TAP_CASUAL;
882
883 if (content.type == INFO_LONG_PRESS) { // last page
884 // for forward only review without known length...
885 // if we don't do that we cannot remove the '>' in the navigation bar at the last page
886 navInfo.nbPages = navInfo.activePage + 1;
887 content.infoLongPress.longPressToken = CONFIRM_TOKEN;
888 if (forwardNavOnly) {
889 // remove the "Skip" button
890 navInfo.skipText = NULL;
891 }
892 }
893
894 // override smallCaseForValue for tag/value types to false
895 if (content.type == TAG_VALUE_DETAILS) {
897 // the maximum displayable number of lines for value is NB_MAX_LINES_IN_REVIEW (without More
898 // button)
901 }
902 else if (content.type == TAG_VALUE_LIST) {
903 content.tagValueList.smallCaseForValue = false;
904 }
905 else if (content.type == TAG_VALUE_CONFIRM) {
907 // use confirm token for black button
908 content.tagValueConfirm.confirmationToken = CONFIRM_TOKEN;
909 }
910
911 pageContext = nbgl_pageDrawGenericContent(&pageCallback, &navInfo, &content);
912
913 if (forceFullRefresh) {
915 }
916 else {
918 }
919}
920
921// Helper that does the computing of which nbgl_content_t and which element in the content should be
922// displayed for the next generic context navigation page
923static const nbgl_content_t *genericContextComputeNextPageParams(uint8_t pageIdx,
924 nbgl_content_t *content,
925 uint8_t *p_nbElementsInNextPage,
926 bool *p_flag)
927{
928 int8_t nextContentIdx = genericContext.currentContentIdx;
929 int16_t nextElementIdx = genericContext.currentElementIdx;
930 uint8_t nbElementsInNextPage;
931
932 // Retrieve info on the next page
933 genericContextGetPageInfo(pageIdx, &nbElementsInNextPage, p_flag);
934 *p_nbElementsInNextPage = nbElementsInNextPage;
935
936 // Handle forward navigation:
937 // add to current index the number of pairs of the currently active page
938 if (pageIdx > navInfo.activePage) {
939 uint8_t nbElementsInCurrentPage;
940
941 genericContextGetPageInfo(navInfo.activePage, &nbElementsInCurrentPage, NULL);
942 nextElementIdx += nbElementsInCurrentPage;
943
944 // Handle case where the content to be displayed is in the next content
945 // In such case start at element index 0.
946 // If currentContentElementNb == 0, means not initialized, so skip
947 if ((nextElementIdx >= genericContext.currentContentElementNb)
948 && (genericContext.currentContentElementNb > 0)) {
949 nextContentIdx += 1;
950 nextElementIdx = 0;
951 }
952 }
953
954 // Handle backward navigation:
955 // add to current index the number of pairs of the currently active page
956 if (pageIdx < navInfo.activePage) {
957 // Backward navigation: remove to current index the number of pairs of the current page
958 nextElementIdx -= nbElementsInNextPage;
959
960 // Handle case where the content to be displayed is in the previous content
961 // In such case set a negative number as element index so that it is handled
962 // later once the previous content is accessible so that its elements number
963 // can be retrieved.
964 if (nextElementIdx < 0) {
965 nextContentIdx -= 1;
966 nextElementIdx = -nbElementsInNextPage;
967 }
968 }
969
970 const nbgl_content_t *p_content;
971 // Retrieve next content
972 if ((nextContentIdx == -1) && (genericContext.hasStartingContent)) {
973 p_content = &STARTING_CONTENT;
974 }
975 else if ((nextContentIdx == genericContext.genericContents.nbContents)
976 && (genericContext.hasFinishingContent)) {
977 p_content = &FINISHING_CONTENT;
978 }
979 else {
980 p_content = getContentAtIdx(&genericContext.genericContents, nextContentIdx, content);
981
982 if (p_content == NULL) {
983 LOG_DEBUG(USE_CASE_LOGGER, "Fail to retrieve content\n");
984 return NULL;
985 }
986 }
987
988 // Handle cases where we are going to display data from a new content:
989 // - navigation to a previous or to the next content
990 // - First page display (genericContext.currentContentElementNb == 0)
991 //
992 // In such case we need to:
993 // - Update genericContext.currentContentIdx
994 // - Update genericContext.currentContentElementNb
995 // - Update onContentAction callback
996 // - Update nextElementIdx in case it was previously not calculable
997 if ((nextContentIdx != genericContext.currentContentIdx)
998 || (genericContext.currentContentElementNb == 0)) {
999 genericContext.currentContentIdx = nextContentIdx;
1000 genericContext.currentContentElementNb = getContentNbElement(p_content);
1001 onContentAction = PIC(p_content->contentActionCallback);
1002 if (nextElementIdx < 0) {
1003 nextElementIdx = genericContext.currentContentElementNb + nextElementIdx;
1004 }
1005 }
1006
1007 // Sanity check
1008 if ((nextElementIdx < 0) || (nextElementIdx >= genericContext.currentContentElementNb)) {
1010 "Invalid element index %d / %d\n",
1011 nextElementIdx,
1012 genericContext.currentContentElementNb);
1013 return NULL;
1014 }
1015
1016 // Update genericContext elements
1017 genericContext.currentElementIdx = nextElementIdx;
1018 navInfo.activePage = pageIdx;
1019
1020 return p_content;
1021}
1022
1023// Helper that generates a nbgl_pageContent_t to be displayed for the next generic context
1024// navigation page
1025static bool genericContextPreparePageContent(const nbgl_content_t *p_content,
1026 uint8_t nbElementsInPage,
1027 bool flag,
1028 nbgl_pageContent_t *pageContent)
1029{
1030 uint8_t nextElementIdx = genericContext.currentElementIdx;
1031
1032 pageContent->title = pageTitle;
1033 pageContent->isTouchableTitle = false;
1034 pageContent->titleToken = QUIT_TOKEN;
1035 pageContent->tuneId = TUNE_TAP_CASUAL;
1036
1037 pageContent->type = p_content->type;
1038 switch (pageContent->type) {
1039 case CENTERED_INFO:
1040 memcpy(&pageContent->centeredInfo,
1041 &p_content->content.centeredInfo,
1042 sizeof(pageContent->centeredInfo));
1043 break;
1044 case EXTENDED_CENTER:
1045 memcpy(&pageContent->extendedCenter,
1046 &p_content->content.extendedCenter,
1047 sizeof(pageContent->extendedCenter));
1048 break;
1049 case INFO_LONG_PRESS:
1050 memcpy(&pageContent->infoLongPress,
1051 &p_content->content.infoLongPress,
1052 sizeof(pageContent->infoLongPress));
1053 break;
1054
1055 case INFO_BUTTON:
1056 memcpy(&pageContent->infoButton,
1057 &p_content->content.infoButton,
1058 sizeof(pageContent->infoButton));
1059 break;
1060
1061 case TAG_VALUE_LIST: {
1062 nbgl_contentTagValueList_t *p_tagValueList = &pageContent->tagValueList;
1063
1064 // memorize pairs (or callback) for usage when alias is used
1065 genericContext.currentPairs = p_content->content.tagValueList.pairs;
1066 genericContext.currentCallback = p_content->content.tagValueList.callback;
1067
1068 if (flag) {
1069 // Flag can be set if the pair is too long to fit or because it needs
1070 // to be displayed as centered info.
1071
1072 // First retrieve the pair
1073 const nbgl_layoutTagValue_t *pair;
1074
1075 if (p_content->content.tagValueList.pairs != NULL) {
1076 pair = PIC(&p_content->content.tagValueList.pairs[nextElementIdx]);
1077 }
1078 else {
1079 pair = PIC(p_content->content.tagValueList.callback(nextElementIdx));
1080 }
1081
1082 if (pair->centeredInfo) {
1083 pageContent->type = EXTENDED_CENTER;
1084 prepareReviewFirstPage(&pageContent->extendedCenter.contentCenter,
1085 pair->valueIcon,
1086 pair->item,
1087 pair->value);
1088
1089 // Skip population of nbgl_contentTagValueList_t structure
1090 p_tagValueList = NULL;
1091 }
1092 else {
1093 // if the pair is too long to fit, we use a TAG_VALUE_DETAILS content
1094 pageContent->type = TAG_VALUE_DETAILS;
1095 pageContent->tagValueDetails.detailsButtonText = "More";
1096 pageContent->tagValueDetails.detailsButtonIcon = NULL;
1097 pageContent->tagValueDetails.detailsButtonToken = DETAILS_BUTTON_TOKEN;
1098
1099 p_tagValueList = &pageContent->tagValueDetails.tagValueList;
1100
1101 // Backup pair info for easy data access upon click on button
1102 genericContext.detailsItem = pair->item;
1103 genericContext.detailsvalue = pair->value;
1104 genericContext.detailsWrapping = p_content->content.tagValueList.wrapping;
1105 }
1106 }
1107
1108 if (p_tagValueList != NULL) {
1109 p_tagValueList->nbPairs = nbElementsInPage;
1110 p_tagValueList->token = p_content->content.tagValueList.token;
1111 if (p_content->content.tagValueList.pairs != NULL) {
1112 p_tagValueList->pairs
1113 = PIC(&p_content->content.tagValueList.pairs[nextElementIdx]);
1114 // parse pairs to check if any contains an alias for value
1115 for (uint8_t i = 0; i < nbElementsInPage; i++) {
1116 if (p_tagValueList->pairs[i].aliasValue) {
1117 p_tagValueList->token = VALUE_ALIAS_TOKEN;
1118 break;
1119 }
1120 }
1121 }
1122 else {
1123 p_tagValueList->pairs = NULL;
1124 p_tagValueList->callback = p_content->content.tagValueList.callback;
1125 p_tagValueList->startIndex = nextElementIdx;
1126 // parse pairs to check if any contains an alias for value
1127 for (uint8_t i = 0; i < nbElementsInPage; i++) {
1128 const nbgl_layoutTagValue_t *pair
1129 = PIC(p_content->content.tagValueList.callback(nextElementIdx + i));
1130 if (pair->aliasValue) {
1131 p_tagValueList->token = VALUE_ALIAS_TOKEN;
1132 break;
1133 }
1134 }
1135 }
1136 p_tagValueList->smallCaseForValue = false;
1138 p_tagValueList->hideEndOfLastLine = true;
1139 p_tagValueList->wrapping = p_content->content.tagValueList.wrapping;
1140 }
1141
1142 break;
1143 }
1144 case TAG_VALUE_CONFIRM: {
1145 nbgl_contentTagValueList_t *p_tagValueList;
1146 // only display a TAG_VALUE_CONFIRM if we are at the last page
1147 if ((nextElementIdx + nbElementsInPage)
1149 memcpy(&pageContent->tagValueConfirm,
1150 &p_content->content.tagValueConfirm,
1151 sizeof(pageContent->tagValueConfirm));
1152 p_tagValueList = &pageContent->tagValueConfirm.tagValueList;
1153 }
1154 else {
1155 // else display it as a TAG_VALUE_LIST: preserve list-level
1156 // settings (nbMaxLinesForValue, wrapping, smallCaseForValue,
1157 // hideEndOfLastLine, token...) so intermediate pages render
1158 // identically to the last page
1159 pageContent->type = TAG_VALUE_LIST;
1160 pageContent->tagValueList = p_content->content.tagValueConfirm.tagValueList;
1161 p_tagValueList = &pageContent->tagValueList;
1162 }
1163 p_tagValueList->nbPairs = nbElementsInPage;
1164 p_tagValueList->pairs
1165 = PIC(&p_content->content.tagValueConfirm.tagValueList.pairs[nextElementIdx]);
1166 // parse pairs to check if any contains an alias for value
1167 for (uint8_t i = 0; i < nbElementsInPage; i++) {
1168 if (p_tagValueList->pairs[i].aliasValue) {
1169 p_tagValueList->token = VALUE_ALIAS_TOKEN;
1170 break;
1171 }
1172 }
1173 // memorize pairs (or callback) for usage when alias is used
1174 genericContext.currentPairs = p_tagValueList->pairs;
1175 genericContext.currentCallback = p_tagValueList->callback;
1176 break;
1177 }
1178 case SWITCHES_LIST:
1179 pageContent->switchesList.nbSwitches = nbElementsInPage;
1180 pageContent->switchesList.switches
1181 = PIC(&p_content->content.switchesList.switches[nextElementIdx]);
1182 break;
1183 case INFOS_LIST:
1184 pageContent->infosList.nbInfos = nbElementsInPage;
1185 pageContent->infosList.infoTypes
1186 = PIC(&p_content->content.infosList.infoTypes[nextElementIdx]);
1187 pageContent->infosList.infoContents
1188 = PIC(&p_content->content.infosList.infoContents[nextElementIdx]);
1189 break;
1190 case CHOICES_LIST:
1191 memcpy(&pageContent->choicesList,
1192 &p_content->content.choicesList,
1193 sizeof(pageContent->choicesList));
1194 pageContent->choicesList.nbChoices = nbElementsInPage;
1195 pageContent->choicesList.names
1196 = PIC(&p_content->content.choicesList.names[nextElementIdx]);
1197 if ((p_content->content.choicesList.initChoice >= nextElementIdx)
1198 && (p_content->content.choicesList.initChoice
1199 < nextElementIdx + nbElementsInPage)) {
1200 pageContent->choicesList.initChoice
1201 = p_content->content.choicesList.initChoice - nextElementIdx;
1202 }
1203 else {
1204 pageContent->choicesList.initChoice = nbElementsInPage;
1205 }
1206 break;
1207 case BARS_LIST:
1208 pageContent->barsList.nbBars = nbElementsInPage;
1209 pageContent->barsList.barTexts
1210 = PIC(&p_content->content.barsList.barTexts[nextElementIdx]);
1211 pageContent->barsList.tokens = PIC(&p_content->content.barsList.tokens[nextElementIdx]);
1212 pageContent->barsList.tuneId = p_content->content.barsList.tuneId;
1213 break;
1214 default:
1215 LOG_DEBUG(USE_CASE_LOGGER, "Unsupported type %d\n", pageContent->type);
1216 return false;
1217 }
1218
1219 bool isFirstOrLastPage
1220 = ((p_content->type == CENTERED_INFO) || (p_content->type == EXTENDED_CENTER))
1221 || (p_content->type == INFO_LONG_PRESS);
1222 nbgl_operationType_t operationType
1223 = (navType == STREAMING_NAV)
1224 ? bundleNavContext.reviewStreaming.operationType
1225 : ((navType == GENERIC_NAV) ? bundleNavContext.review.operationType : 0);
1226
1227 // if first or last page of review and blind/risky operation, add the warning top-right button
1228 if (isFirstOrLastPage
1229 && (operationType & (BLIND_OPERATION | RISKY_OPERATION | NO_THREAT_OPERATION))) {
1230 // if issue is only Web3Checks "no threat", use privacy icon
1231 if ((operationType & NO_THREAT_OPERATION)
1232 && !(reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN))) {
1233 pageContent->topRightIcon = &PRIVACY_ICON;
1234 }
1235 else {
1236 pageContent->topRightIcon = &WARNING_ICON;
1237 }
1238
1239 pageContent->topRightToken
1240 = (operationType & BLIND_OPERATION) ? BLIND_WARNING_TOKEN : WARNING_BUTTON_TOKEN;
1241 }
1242
1243 return true;
1244}
1245
1246// function used to display the current page in generic context navigation mode
1247static void displayGenericContextPage(uint8_t pageIdx, bool forceFullRefresh)
1248{
1249 // Retrieve next page parameters
1250 nbgl_content_t content;
1251 uint8_t nbElementsInPage;
1252 bool flag;
1253 const nbgl_content_t *p_content = NULL;
1254
1255 if (navType == STREAMING_NAV) {
1256 if (pageIdx == LAST_PAGE_FOR_REVIEW) {
1257 if (bundleNavContext.reviewStreaming.skipCallback != NULL) {
1258 bundleNavContext.reviewStreaming.skipCallback();
1259 }
1260 return;
1261 }
1262 else if (pageIdx >= bundleNavContext.reviewStreaming.stepPageNb) {
1263 bundleNavReviewStreamingChoice(true);
1264 return;
1265 }
1266 }
1267 else {
1268 // if coming from Skip modal, let's say we are at the last page
1269 if (pageIdx == LAST_PAGE_FOR_REVIEW) {
1270 pageIdx = navInfo.nbPages - 1;
1271 }
1272 }
1273
1274 if (navInfo.activePage == pageIdx) {
1275 p_content
1276 = genericContextComputeNextPageParams(pageIdx, &content, &nbElementsInPage, &flag);
1277 }
1278 else if (navInfo.activePage < pageIdx) {
1279 // Support going more than one step forward.
1280 // It occurs when initializing a navigation on an arbitrary page
1281 for (int i = navInfo.activePage + 1; i <= pageIdx; i++) {
1282 p_content = genericContextComputeNextPageParams(i, &content, &nbElementsInPage, &flag);
1283 }
1284 }
1285 else {
1286 if (pageIdx - navInfo.activePage > 1) {
1287 // We don't support going more than one step backward as it doesn't occurs for now?
1288 LOG_DEBUG(USE_CASE_LOGGER, "Unsupported navigation\n");
1289 return;
1290 }
1291 p_content
1292 = genericContextComputeNextPageParams(pageIdx, &content, &nbElementsInPage, &flag);
1293 }
1294
1295 if (p_content == NULL) {
1296 return;
1297 }
1298 // if the operation is skippable
1299 if ((navType != STREAMING_NAV)
1300 && (bundleNavContext.review.operationType & SKIPPABLE_OPERATION)) {
1301 // only present the "Skip" header on actual tag/value pages
1302 if ((pageIdx > 0) && (pageIdx < (navInfo.nbPages - 1))) {
1303 navInfo.progressIndicator = false;
1304 navInfo.skipText = "Skip";
1305 navInfo.skipToken = SKIP_TOKEN;
1306 }
1307 else {
1308 navInfo.skipText = NULL;
1309 }
1310 }
1311
1312 // Create next page content
1313 nbgl_pageContent_t pageContent = {0};
1314 if (!genericContextPreparePageContent(p_content, nbElementsInPage, flag, &pageContent)) {
1315 return;
1316 }
1317
1318 pageContext = nbgl_pageDrawGenericContent(&pageCallback, &navInfo, &pageContent);
1319
1320 if (forceFullRefresh) {
1322 }
1323 else {
1325 }
1326}
1327
1328// from the current details context, return a pointer on the details at the given page
1329static const char *getDetailsPageAt(uint8_t detailsPage)
1330{
1331 uint8_t page = 0;
1332 const char *currentChar = detailsContext.value;
1333 while (page < detailsPage) {
1334 uint16_t nbLines
1335 = nbgl_getTextNbLinesInWidth(SMALL_BOLD_FONT, currentChar, AVAILABLE_WIDTH, false);
1336 if (nbLines > NB_MAX_LINES_IN_DETAILS) {
1337 uint16_t len;
1338 nbgl_getTextMaxLenInNbLines(SMALL_BOLD_FONT,
1339 currentChar,
1342 &len,
1343 detailsContext.wrapping);
1344 // don't start next page on a \n
1345 if (currentChar[len] == '\n') {
1346 len++;
1347 }
1348 else if (detailsContext.wrapping == false) {
1349 len -= 3;
1350 }
1351 currentChar = currentChar + len;
1352 }
1353 page++;
1354 }
1355 return currentChar;
1356}
1357
1358// function used to display the current page in details review mode
1359static void displayDetailsPage(uint8_t detailsPage, bool forceFullRefresh)
1360{
1361 static nbgl_layoutTagValue_t currentPair;
1362 nbgl_pageNavigationInfo_t info = {.activePage = detailsPage,
1363 .nbPages = detailsContext.nbPages,
1364 .navType = NAV_WITH_BUTTONS,
1365 .quitToken = QUIT_TOKEN,
1366 .navWithButtons.navToken = NAV_TOKEN,
1367 .navWithButtons.quitButton = true,
1368 .navWithButtons.backButton = true,
1369 .navWithButtons.quitText = NULL,
1370 .progressIndicator = false,
1371 .tuneId = TUNE_TAP_CASUAL};
1373 .topRightIcon = NULL,
1374 .tagValueList.nbPairs = 1,
1375 .tagValueList.pairs = &currentPair,
1376 .tagValueList.smallCaseForValue = true,
1377 .tagValueList.wrapping = detailsContext.wrapping};
1378
1379 if (modalPageContext != NULL) {
1380 nbgl_pageRelease(modalPageContext);
1381 }
1382 currentPair.item = detailsContext.tag;
1383 // if move backward or first page
1384 if (detailsPage <= detailsContext.currentPage) {
1385 // recompute current start from beginning
1386 currentPair.value = getDetailsPageAt(detailsPage);
1387 forceFullRefresh = true;
1388 }
1389 // else move forward
1390 else {
1391 currentPair.value = detailsContext.nextPageStart;
1392 }
1393 detailsContext.currentPage = detailsPage;
1394 uint16_t nbLines = nbgl_getTextNbLinesInWidth(
1395 SMALL_BOLD_FONT, currentPair.value, AVAILABLE_WIDTH, detailsContext.wrapping);
1396
1397 if (nbLines > NB_MAX_LINES_IN_DETAILS) {
1398 uint16_t len;
1399 nbgl_getTextMaxLenInNbLines(SMALL_BOLD_FONT,
1400 currentPair.value,
1403 &len,
1404 detailsContext.wrapping);
1406 // don't start next page on a \n
1407 if (currentPair.value[len] == '\n') {
1408 len++;
1409 }
1410 else if (!detailsContext.wrapping) {
1412 len -= 3;
1413 }
1414 // memorize next position to save processing
1415 detailsContext.nextPageStart = currentPair.value + len;
1416 // use special feature to keep only NB_MAX_LINES_IN_DETAILS lines and replace the last 3
1417 // chars by "...", only if the next char to display in next page is not '\n'
1419 }
1420 else {
1421 detailsContext.nextPageStart = NULL;
1422 content.tagValueList.nbMaxLinesForValue = 0;
1423 }
1424 if (info.nbPages == 1) {
1425 // if only one page, no navigation bar, and use a footer instead
1426 info.navWithButtons.quitText = "Close";
1427 }
1428 modalPageContext = nbgl_pageDrawGenericContentExt(&pageModalCallback, &info, &content, true);
1429
1430 if (forceFullRefresh) {
1432 }
1433 else {
1435 }
1436}
1437
1438// function used to display the content of a full value, when touching an alias of a tag/value pair
1439static void displayFullValuePage(const char *backText,
1440 const char *aliasText,
1441 const nbgl_contentValueExt_t *extension)
1442{
1443 const char *modalTitle
1444 = (extension->backText != NULL) ? PIC(extension->backText) : PIC(backText);
1445 if (extension->aliasType == INFO_LIST_ALIAS) {
1446 genericContext.currentInfos = extension->infolist;
1447 displayInfosListModal(modalTitle, extension->infolist, true);
1448 }
1449 else if (extension->aliasType == TAG_VALUE_LIST_ALIAS) {
1450 genericContext.currentTagValues = extension->tagValuelist;
1451 displayTagValueListModal(extension->tagValuelist);
1452 }
1453 else {
1454 nbgl_layoutDescription_t layoutDescription = {.modal = true,
1455 .withLeftBorder = true,
1456 .onActionCallback = &modalLayoutTouchCallback,
1457 .tapActionText = NULL};
1458 nbgl_layoutHeader_t headerDesc = {.type = HEADER_BACK_AND_TEXT,
1459 .separationLine = false,
1460 .backAndText.token = 0,
1461 .backAndText.tuneId = TUNE_TAP_CASUAL,
1462 .backAndText.text = modalTitle};
1463 genericContext.modalLayout = nbgl_layoutGet(&layoutDescription);
1464 // add header with the tag part of the pair, to go back
1465 nbgl_layoutAddHeader(genericContext.modalLayout, &headerDesc);
1466 // add either QR Code or full value text
1467 if (extension->aliasType == QR_CODE_ALIAS) {
1468#ifdef NBGL_QRCODE
1469 nbgl_layoutQRCode_t qrCode
1470 = {.url = extension->fullValue,
1471 .text1 = (extension->title != NULL) ? extension->title : extension->fullValue,
1472 .text2 = extension->explanation,
1473 .centered = true,
1474 .offsetY = 0};
1475
1476 nbgl_layoutAddQRCode(genericContext.modalLayout, &qrCode);
1477#endif // NBGL_QRCODE
1478 }
1479 else {
1480 nbgl_layoutTextContent_t content = {0};
1481 content.title = aliasText;
1482 if (extension->aliasType == ENS_ALIAS) {
1483 content.info = "ENS names are resolved by Ledger backend.";
1484 }
1485 else if (extension->aliasType == ADDRESS_BOOK_ALIAS) {
1486 if (extension->aliasSubName != NULL) {
1487 content.descriptions[content.nbDescriptions] = extension->aliasSubName;
1488 content.nbDescriptions++;
1489 }
1490 }
1491 else {
1492 content.info = extension->explanation;
1493 }
1494 // add full value text
1495 content.descriptions[content.nbDescriptions] = extension->fullValue;
1496 content.nbDescriptions++;
1497 // add trusted name if present (combined Address Book+Trusted Name case)
1498 if ((extension->aliasType == ADDRESS_BOOK_ALIAS) && (extension->explanation != NULL)) {
1499 content.descriptions[content.nbDescriptions] = extension->explanation;
1500 content.nbDescriptions++;
1501 }
1502 nbgl_layoutAddTextContent(genericContext.modalLayout, &content);
1503 }
1504 // draw & refresh
1505 nbgl_layoutDraw(genericContext.modalLayout);
1506 nbgl_refresh();
1507 }
1508}
1509
1510// function used to display the modal containing tip-box infos
1511static void displayInfosListModal(const char *modalTitle,
1512 const nbgl_contentInfoList_t *infos,
1513 bool fromReview)
1514{
1516 .nbPages = 1,
1517 .navType = NAV_WITH_BUTTONS,
1518 .quitToken = QUIT_TIPBOX_MODAL_TOKEN,
1519 .navWithButtons.navToken = NAV_TOKEN,
1520 .navWithButtons.quitButton = false,
1521 .navWithButtons.backButton = true,
1522 .navWithButtons.quitText = NULL,
1523 .progressIndicator = false,
1524 .tuneId = TUNE_TAP_CASUAL};
1525 nbgl_pageContent_t content
1526 = {.type = INFOS_LIST,
1527 .topRightIcon = NULL,
1528 .infosList.nbInfos = infos->nbInfos,
1529 .infosList.withExtensions = infos->withExtensions,
1530 .infosList.infoTypes = infos->infoTypes,
1531 .infosList.infoContents = infos->infoContents,
1532 .infosList.infoExtensions = infos->infoExtensions,
1533 .infosList.token = fromReview ? INFO_ALIAS_TOKEN : INFOS_TIP_BOX_TOKEN,
1534 .title = modalTitle,
1535 .titleToken = QUIT_TIPBOX_MODAL_TOKEN,
1536 .tuneId = TUNE_TAP_CASUAL};
1537
1538 if (modalPageContext != NULL) {
1539 nbgl_pageRelease(modalPageContext);
1540 }
1541 modalPageContext = nbgl_pageDrawGenericContentExt(&pageModalCallback, &info, &content, true);
1542
1544}
1545
1546// function used to display the modal containing alias tag-value pairs
1547static void displayTagValueListModalPage(uint8_t pageIdx, bool forceFullRefresh)
1548{
1549 nbgl_pageNavigationInfo_t info = {.activePage = pageIdx,
1550 .nbPages = detailsContext.nbPages,
1551 .navType = NAV_WITH_BUTTONS,
1552 .quitToken = QUIT_TOKEN,
1553 .navWithButtons.navToken = MODAL_NAV_TOKEN,
1554 .navWithButtons.quitButton = true,
1555 .navWithButtons.backButton = true,
1556 .navWithButtons.quitText = NULL,
1557 .progressIndicator = false,
1558 .tuneId = TUNE_TAP_CASUAL};
1560 .topRightIcon = NULL,
1561 .tagValueList.smallCaseForValue = true,
1562 .tagValueList.wrapping = detailsContext.wrapping};
1563 uint8_t nbElementsInPage;
1564
1565 // if first page or forward
1566 if (detailsContext.currentPage <= pageIdx) {
1567 modalContextGetPageInfo(pageIdx, &nbElementsInPage);
1568 }
1569 else {
1570 // backward direction
1571 modalContextGetPageInfo(pageIdx + 1, &nbElementsInPage);
1572 detailsContext.currentPairIdx -= nbElementsInPage;
1573 modalContextGetPageInfo(pageIdx, &nbElementsInPage);
1574 detailsContext.currentPairIdx -= nbElementsInPage;
1575 }
1576 detailsContext.currentPage = pageIdx;
1577
1578 content.tagValueList.pairs
1579 = &genericContext.currentTagValues->pairs[detailsContext.currentPairIdx];
1580 content.tagValueList.nbPairs = nbElementsInPage;
1581 detailsContext.currentPairIdx += nbElementsInPage;
1582 if (info.nbPages == 1) {
1583 // if only one page, no navigation bar, and use a footer instead
1584 info.navWithButtons.quitText = "Close";
1585 }
1586
1587 if (modalPageContext != NULL) {
1588 nbgl_pageRelease(modalPageContext);
1589 }
1590 modalPageContext = nbgl_pageDrawGenericContentExt(&pageModalCallback, &info, &content, true);
1591
1592 if (forceFullRefresh) {
1594 }
1595 else {
1597 }
1598}
1599
1600#ifdef NBGL_QRCODE
1601static void displayAddressQRCode(void)
1602{
1603 // display the address as QR Code
1604 nbgl_layoutDescription_t layoutDescription = {.modal = true,
1605 .withLeftBorder = true,
1606 .onActionCallback = &modalLayoutTouchCallback,
1607 .tapActionText = NULL};
1608 nbgl_layoutHeader_t headerDesc = {
1609 .type = HEADER_EMPTY, .separationLine = false, .emptySpace.height = SMALL_CENTERING_HEADER};
1610 nbgl_layoutQRCode_t qrCode = {.url = addressConfirmationContext.tagValuePairs[0].value,
1611 .text1 = NULL,
1612 .centered = true,
1613 .offsetY = 0};
1614
1615 addressConfirmationContext.modalLayout = nbgl_layoutGet(&layoutDescription);
1616 // add empty header for better look
1617 nbgl_layoutAddHeader(addressConfirmationContext.modalLayout, &headerDesc);
1618 // compute nb lines to check whether it shall be shorten (max is 3 lines)
1619 uint16_t nbLines = nbgl_getTextNbLinesInWidth(SMALL_REGULAR_FONT,
1620 addressConfirmationContext.tagValuePairs[0].value,
1622 false);
1623
1624 if (nbLines <= QRCODE_NB_MAX_LINES) {
1625 qrCode.text2 = addressConfirmationContext.tagValuePairs[0].value; // in gray
1626 }
1627 else {
1628 // only keep beginning and end of text, and add ... in the middle
1629 nbgl_textReduceOnNbLines(SMALL_REGULAR_FONT,
1630 addressConfirmationContext.tagValuePairs[0].value,
1632 QRCODE_NB_MAX_LINES,
1633 reducedAddress,
1634 QRCODE_REDUCED_ADDR_LEN);
1635 qrCode.text2 = reducedAddress; // in gray
1636 }
1637
1638 nbgl_layoutAddQRCode(addressConfirmationContext.modalLayout, &qrCode);
1639
1640 nbgl_layoutAddFooter(
1641 addressConfirmationContext.modalLayout, "Close", DISMISS_QR_TOKEN, TUNE_TAP_CASUAL);
1642 nbgl_layoutDraw(addressConfirmationContext.modalLayout);
1643 nbgl_refresh();
1644}
1645
1646#endif // NBGL_QRCODE
1647
1648// called when header is touched on modal page, to dismiss it
1649static void modalLayoutTouchCallback(int token, uint8_t index)
1650{
1651 UNUSED(index);
1652 if (token == DISMISS_QR_TOKEN) {
1653 // dismiss modal
1654 nbgl_layoutRelease(addressConfirmationContext.modalLayout);
1655 addressConfirmationContext.modalLayout = NULL;
1657 }
1658 else if (token == DISMISS_WARNING_TOKEN) {
1659 // dismiss modal
1660 nbgl_layoutRelease(reviewWithWarnCtx.modalLayout);
1661 // if already at first level, simply redraw the background
1662 if (reviewWithWarnCtx.securityReportLevel <= 1) {
1663 reviewWithWarnCtx.modalLayout = NULL;
1665 }
1666 else {
1667 // We are at level 2 of warning modal, so re-display the level 1
1668 reviewWithWarnCtx.securityReportLevel = 1;
1669 // if preset is used
1670 if (reviewWithWarnCtx.warning->predefinedSet) {
1671 displaySecurityReport(reviewWithWarnCtx.warning->predefinedSet);
1672 }
1673 else {
1674 // use customized warning
1675 const nbgl_warningDetails_t *details
1676 = (reviewWithWarnCtx.isIntro) ? reviewWithWarnCtx.warning->introDetails
1677 : reviewWithWarnCtx.warning->reviewDetails;
1678 displayCustomizedSecurityReport(details);
1679 }
1680 return;
1681 }
1682 }
1683 else if (token == DISMISS_DETAILS_TOKEN) {
1684 // dismiss modal
1685 nbgl_layoutRelease(choiceWithDetailsCtx.modalLayout);
1686 // if already at first level, simply redraw the background
1687 if (choiceWithDetailsCtx.level <= 1) {
1688 choiceWithDetailsCtx.modalLayout = NULL;
1690 }
1691 else {
1692 // We are at level 2 of details modal, so re-display the level 1
1693 choiceWithDetailsCtx.level = 1;
1694 choiceWithDetailsCtx.modalLayout
1695 = displayModalDetails(choiceWithDetailsCtx.details, DISMISS_DETAILS_TOKEN);
1696 }
1697 }
1698 else if ((token >= FIRST_WARN_BAR_TOKEN) && (token <= LAST_WARN_BAR_TOKEN)) {
1699 if (sharedContext.usage == SHARE_CTX_REVIEW_WITH_WARNING) {
1700 // dismiss modal before creating a new one
1701 nbgl_layoutRelease(reviewWithWarnCtx.modalLayout);
1702 reviewWithWarnCtx.securityReportLevel = 2;
1703 // if preset is used
1704 if (reviewWithWarnCtx.warning->predefinedSet) {
1705 displaySecurityReport(1 << (token - FIRST_WARN_BAR_TOKEN));
1706 }
1707 else {
1708 // use customized warning
1709 const nbgl_warningDetails_t *details
1710 = (reviewWithWarnCtx.isIntro) ? reviewWithWarnCtx.warning->introDetails
1711 : reviewWithWarnCtx.warning->reviewDetails;
1712 if (details->type == BAR_LIST_WARNING) {
1713 displayCustomizedSecurityReport(
1714 &details->barList.details[token - FIRST_WARN_BAR_TOKEN]);
1715 }
1716 }
1717 }
1718 else if (sharedContext.usage == SHARE_CTX_CHOICE_WITH_DETAILS) {
1719 const nbgl_warningDetails_t *details
1720 = &choiceWithDetailsCtx.details->barList.details[token - FIRST_WARN_BAR_TOKEN];
1721 if (details->title != NO_TYPE_WARNING) {
1722 // dismiss modal before creating a new one
1723 nbgl_layoutRelease(choiceWithDetailsCtx.modalLayout);
1724 choiceWithDetailsCtx.level = 2;
1725 choiceWithDetailsCtx.modalLayout
1726 = displayModalDetails(details, DISMISS_DETAILS_TOKEN);
1727 }
1728 }
1729 return;
1730 }
1731 else {
1732 // dismiss modal
1733 nbgl_layoutRelease(genericContext.modalLayout);
1734 genericContext.modalLayout = NULL;
1736 }
1737 nbgl_refresh();
1738}
1739
1740// called when item are touched in layout
1741static void layoutTouchCallback(int token, uint8_t index)
1742{
1743 // choice buttons in initial warning page
1744 if (token == WARNING_CHOICE_TOKEN) {
1745 if (index == 0) { // top button to exit
1746 reviewWithWarnCtx.choiceCallback(false);
1747 }
1748 else { // bottom button to continue to review
1749 reviewWithWarnCtx.isIntro = false;
1750 if (reviewWithWarnCtx.isStreaming) {
1751 useCaseReviewStreamingStart(reviewWithWarnCtx.operationType,
1752 reviewWithWarnCtx.icon,
1753 reviewWithWarnCtx.reviewTitle,
1754 reviewWithWarnCtx.reviewSubTitle,
1755 reviewWithWarnCtx.choiceCallback,
1756 false);
1757 }
1758 else {
1759 useCaseReview(reviewWithWarnCtx.operationType,
1760 reviewWithWarnCtx.tagValueList,
1761 reviewWithWarnCtx.icon,
1762 reviewWithWarnCtx.reviewTitle,
1763 reviewWithWarnCtx.reviewSubTitle,
1764 reviewWithWarnCtx.finishTitle,
1765 &activeTipBox,
1766 reviewWithWarnCtx.choiceCallback,
1767 false,
1768 false);
1769 }
1770 }
1771 }
1772 // top-right button in initial warning page
1773 else if (token == WARNING_BUTTON_TOKEN) {
1774 // start directly at first level of security report
1775 reviewWithWarnCtx.securityReportLevel = 1;
1776 // if preset is used
1777 if (reviewWithWarnCtx.warning->predefinedSet) {
1778 displaySecurityReport(reviewWithWarnCtx.warning->predefinedSet);
1779 }
1780 else {
1781 // use customized warning
1782 const nbgl_warningDetails_t *details = (reviewWithWarnCtx.isIntro)
1783 ? reviewWithWarnCtx.warning->introDetails
1784 : reviewWithWarnCtx.warning->reviewDetails;
1785 displayCustomizedSecurityReport(details);
1786 }
1787 }
1788 // top-right button in choice with details page
1789 else if (token == CHOICE_DETAILS_TOKEN) {
1790 choiceWithDetailsCtx.level = 1;
1791 choiceWithDetailsCtx.modalLayout
1792 = displayModalDetails(choiceWithDetailsCtx.details, DISMISS_DETAILS_TOKEN);
1793 }
1794 // main prelude page
1795 else if (token == PRELUDE_CHOICE_TOKEN) {
1796 if (index == 0) { // top button to display details about prelude
1797 displayCustomizedSecurityReport(reviewWithWarnCtx.warning->prelude->details);
1798 }
1799 else { // footer to continue to review
1800 if (HAS_INITIAL_WARNING(reviewWithWarnCtx.warning)) {
1801 displayInitialWarning();
1802 }
1803 else {
1804 reviewWithWarnCtx.isIntro = false;
1805 if (reviewWithWarnCtx.isStreaming) {
1806 useCaseReviewStreamingStart(reviewWithWarnCtx.operationType,
1807 reviewWithWarnCtx.icon,
1808 reviewWithWarnCtx.reviewTitle,
1809 reviewWithWarnCtx.reviewSubTitle,
1810 reviewWithWarnCtx.choiceCallback,
1811 false);
1812 }
1813 else {
1814 useCaseReview(reviewWithWarnCtx.operationType,
1815 reviewWithWarnCtx.tagValueList,
1816 reviewWithWarnCtx.icon,
1817 reviewWithWarnCtx.reviewTitle,
1818 reviewWithWarnCtx.reviewSubTitle,
1819 reviewWithWarnCtx.finishTitle,
1820 &activeTipBox,
1821 reviewWithWarnCtx.choiceCallback,
1822 false,
1823 false);
1824 }
1825 }
1826 }
1827 }
1828 // choice buttons
1829 else if (token == CHOICE_TOKEN) {
1830 if (onChoice != NULL) {
1831 onChoice((index == 0) ? true : false);
1832 }
1833 }
1834}
1835
1836// called when skip button is touched in footer, during forward only review
1837static void displaySkipWarning(void)
1838{
1840 .cancelText = "Go back to review",
1841 .centeredInfo.text1 = "Skip review?",
1842 .centeredInfo.text2
1843 = "If you're sure you don't need to review all fields, you can skip straight to signing.",
1844 .centeredInfo.text3 = NULL,
1845 .centeredInfo.style = LARGE_CASE_INFO,
1846 .centeredInfo.icon = &IMPORTANT_CIRCLE_ICON,
1847 .centeredInfo.offsetY = 0,
1848 .confirmationText = "Yes, skip",
1849 .confirmationToken = SKIP_TOKEN,
1850 .tuneId = TUNE_TAP_CASUAL,
1851 .modal = true};
1852 if (modalPageContext != NULL) {
1853 nbgl_pageRelease(modalPageContext);
1854 }
1855 modalPageContext = nbgl_pageDrawConfirmation(&pageModalCallback, &info);
1857}
1858
1859#ifdef NBGL_KEYPAD
1860// called to update the keypad and automatically show / hide:
1861// - backspace key if no digits are present
1862// - validation key if the min digit is reached
1863// - keypad if the max number of digit is reached
1864static void updateKeyPad(bool add)
1865{
1866 bool enableValidate, enableBackspace, enableDigits;
1867 bool redrawKeypad = false;
1869
1870 enableDigits = (keypadContext.pinLen < keypadContext.pinMaxDigits);
1871 enableValidate = (keypadContext.pinLen >= keypadContext.pinMinDigits);
1872 enableBackspace = (keypadContext.pinLen > 0);
1873 if (add) {
1874 if ((keypadContext.pinLen == keypadContext.pinMinDigits)
1875 || // activate "validate" button on keypad
1876 (keypadContext.pinLen == keypadContext.pinMaxDigits)
1877 || // deactivate "digits" on keypad
1878 (keypadContext.pinLen == 1)) { // activate "backspace"
1879 redrawKeypad = true;
1880 }
1881 }
1882 else { // remove
1883 if ((keypadContext.pinLen == 0) || // deactivate "backspace" button on keypad
1884 (keypadContext.pinLen == (keypadContext.pinMinDigits - 1))
1885 || // deactivate "validate" button on keypad
1886 (keypadContext.pinLen
1887 == (keypadContext.pinMaxDigits - 1))) { // reactivate "digits" on keypad
1888 redrawKeypad = true;
1889 }
1890 }
1891 if (keypadContext.hidden == true) {
1892 nbgl_layoutUpdateKeypadContent(keypadContext.layoutCtx, true, keypadContext.pinLen, NULL);
1893 }
1894 else {
1896 keypadContext.layoutCtx, false, 0, (const char *) keypadContext.pinEntry);
1897 }
1898 if (redrawKeypad) {
1900 keypadContext.layoutCtx, 0, enableValidate, enableBackspace, enableDigits);
1901 }
1902
1903 if ((!add) && (keypadContext.pinLen == 0)) {
1904 // Full refresh to fully clean the bullets when reaching 0 digits
1905 mode = FULL_COLOR_REFRESH;
1906 }
1908}
1909
1910// called when a key is touched on the keypad
1911static void keypadCallback(char touchedKey)
1912{
1913 switch (touchedKey) {
1914 case BACKSPACE_KEY:
1915 if (keypadContext.pinLen > 0) {
1916 keypadContext.pinLen--;
1917 keypadContext.pinEntry[keypadContext.pinLen] = 0;
1918 }
1919 updateKeyPad(false);
1920 break;
1921
1922 case VALIDATE_KEY:
1923 // Gray out keyboard / buttons as a first user feedback
1924 nbgl_layoutUpdateKeypad(keypadContext.layoutCtx, 0, false, false, true);
1927
1928 keypadContext.onValidatePin(keypadContext.pinEntry, keypadContext.pinLen);
1929 break;
1930
1931 default:
1932 if ((touchedKey >= 0x30) && (touchedKey < 0x40)) {
1933 if (keypadContext.pinLen < keypadContext.pinMaxDigits) {
1934 keypadContext.pinEntry[keypadContext.pinLen] = touchedKey;
1935 keypadContext.pinLen++;
1936 }
1937 updateKeyPad(true);
1938 }
1939 break;
1940 }
1941}
1942
1943static void keypadGeneric_cb(int token, uint8_t index)
1944{
1945 UNUSED(index);
1946 if (token != BACK_TOKEN) {
1947 return;
1948 }
1949 onQuit();
1950}
1951#endif
1952
1953#ifdef NBGL_KEYBOARD
1954// called when a key is touched on the keyboard
1955static void keyboardCallback(char touchedKey)
1956{
1957 uint32_t mask = 0;
1958 size_t textLen = strlen(keyboardContext.entryBuffer);
1959 if (touchedKey == BACKSPACE_KEY) {
1960 if (textLen == 0) {
1961 // No action
1962 return;
1963 }
1964 keyboardContext.entryBuffer[--textLen] = '\0';
1965 }
1966 else {
1967 keyboardContext.entryBuffer[textLen] = touchedKey;
1968 keyboardContext.entryBuffer[++textLen] = '\0';
1969 }
1970 if (keyboardContext.keyboardContent.type == KEYBOARD_WITH_SUGGESTIONS) {
1971 // if suggestions are displayed, we update them at each key press
1972 keyboardContext.getSuggestionButtons(&keyboardContext.keyboardContent, &mask);
1973 }
1974 else if (textLen >= keyboardContext.entryMaxLen) {
1975 // entry length can't be greater, so we mask every characters
1976 mask = -1;
1977 }
1978 nbgl_layoutUpdateKeyboardContent(keyboardContext.layoutCtx, &keyboardContext.keyboardContent);
1979 nbgl_layoutUpdateKeyboard(keyboardContext.layoutCtx,
1980 keyboardContext.keyboardIndex,
1981 mask,
1982 false,
1983 keyboardContext.casing);
1985}
1986
1987static void keyboardGeneric_cb(int token, uint8_t index)
1988{
1989 UNUSED(index);
1990 switch (token) {
1991 case BACK_TOKEN:
1992 onQuit();
1993 break;
1994 case KEYBOARD_CROSS_TOKEN:
1995 // Simulate a word of a single letter 'a' and trigger the backspace action
1996 keyboardContext.entryBuffer[0] = 'a';
1997 keyboardContext.entryBuffer[1] = '\0';
1998 keyboardCallback(BACKSPACE_KEY);
1999 break;
2000 case KEYBOARD_BUTTON_TOKEN:
2001 if (keyboardContext.keyboardContent.type == KEYBOARD_WITH_BUTTON) {
2002 onAction();
2003 }
2004 break;
2005 default:
2006 if ((keyboardContext.keyboardContent.type == KEYBOARD_WITH_SUGGESTIONS)
2007 && (token >= keyboardContext.keyboardContent.suggestionButtons.firstButtonToken)) {
2008 onControls(token, index);
2009 }
2010 break;
2011 }
2012}
2013#endif
2014
2029static uint8_t getNbTagValuesInPage(uint8_t nbPairs,
2030 const nbgl_contentTagValueList_t *tagValueList,
2031 uint8_t startIndex,
2032 bool isSkippable,
2033 bool hasConfirmationButton,
2034 bool hasDetailsButton,
2035 bool *requireSpecificDisplay)
2036{
2037 uint8_t nbPairsInPage = 0;
2038 uint16_t currentHeight = PRE_TAG_VALUE_MARGIN; // upper margin
2039 uint16_t maxUsableHeight = TAG_VALUE_AREA_HEIGHT;
2040
2041 // if the review is skippable, it means that there is less height for tag/value pairs
2042 // the small centering header becomes a touchable header
2043 if (isSkippable) {
2044 maxUsableHeight -= TOUCHABLE_HEADER_BAR_HEIGHT - SMALL_CENTERING_HEADER;
2045 }
2046
2047 *requireSpecificDisplay = false;
2048 while (nbPairsInPage < nbPairs) {
2049 const nbgl_layoutTagValue_t *pair;
2050 nbgl_font_id_e value_font;
2051 uint16_t nbLines;
2052
2053 // margin between pairs
2054 // 12 or 24 px between each tag/value pair
2055 if (nbPairsInPage > 0) {
2056 currentHeight += INTER_TAG_VALUE_MARGIN;
2057 }
2058 // fetch tag/value pair strings.
2059 if (tagValueList->pairs != NULL) {
2060 pair = PIC(&tagValueList->pairs[startIndex + nbPairsInPage]);
2061 }
2062 else {
2063 pair = PIC(tagValueList->callback(startIndex + nbPairsInPage));
2064 }
2065
2066 if (pair->forcePageStart && nbPairsInPage > 0) {
2067 // This pair must be at the top of a page
2068 break;
2069 }
2070
2071 if (pair->centeredInfo) {
2072 if (nbPairsInPage > 0) {
2073 // This pair must be at the top of a page
2074 break;
2075 }
2076 else {
2077 // This pair is the only one of the page and has a specific display behavior
2078 nbPairsInPage = 1;
2079 *requireSpecificDisplay = true;
2080 break;
2081 }
2082 }
2083
2084 // tag height
2085 currentHeight += nbgl_getTextHeightInWidth(
2086 SMALL_REGULAR_FONT, pair->item, AVAILABLE_WIDTH, tagValueList->wrapping);
2087 // space between tag and value
2088 currentHeight += TAG_VALUE_INTERVALE;
2089 // set value font
2090 if (tagValueList->smallCaseForValue) {
2091 value_font = SMALL_REGULAR_FONT;
2092 }
2093 else {
2094 value_font = LARGE_MEDIUM_FONT;
2095 }
2096 // nb lines for value
2098 value_font, pair->value, AVAILABLE_WIDTH, tagValueList->wrapping);
2099 // honor list-level nbMaxLinesForValue: when set, the value will be
2100 // displayed truncated to that many lines, so account for its
2101 // truncated height rather than its full height
2102 if ((tagValueList->nbMaxLinesForValue > 0)
2103 && (nbLines > tagValueList->nbMaxLinesForValue)) {
2104 nbLines = tagValueList->nbMaxLinesForValue;
2105 currentHeight += nbLines * nbgl_getFontLineHeight(value_font);
2106 }
2107 else {
2108 currentHeight += nbgl_getTextHeightInWidth(
2109 value_font, pair->value, AVAILABLE_WIDTH, tagValueList->wrapping);
2110 }
2111
2112 // potential subAlias text
2113 if ((pair->aliasValue) && (pair->extension->aliasSubName)) {
2114 currentHeight += TAG_VALUE_INTERVALE + nbgl_getFontLineHeight(SMALL_REGULAR_FONT);
2115 }
2116 if ((currentHeight >= maxUsableHeight) || (nbLines > NB_MAX_LINES_IN_REVIEW)) {
2117 if (nbPairsInPage == 0) {
2118 // Pair too long to fit in a single screen
2119 // It will be the only one of the page and has a specific display behavior
2120 nbPairsInPage = 1;
2121 *requireSpecificDisplay = true;
2122 }
2123 break;
2124 }
2125 nbPairsInPage++;
2126 }
2127 // if this is a TAG_VALUE_CONFIRM and we have reached the last pairs,
2128 // let's check if it still fits with a CONFIRMATION button, and if not,
2129 // remove the last pair (but never below 1, otherwise the pagination
2130 // loop in getNbPagesForContent would spin forever — the lone oversized
2131 // pair must still occupy this page and will be truncated at display time)
2132 if (hasConfirmationButton && (nbPairsInPage == nbPairs)) {
2133 maxUsableHeight -= UP_FOOTER_BUTTON_HEIGHT;
2134 if ((currentHeight > maxUsableHeight) && (nbPairsInPage > 1)) {
2135 nbPairsInPage--;
2136 }
2137 }
2138 // do the same with just a details button
2139 else if (hasDetailsButton) {
2140 maxUsableHeight -= (SMALL_BUTTON_RADIUS * 2);
2141 if ((currentHeight > maxUsableHeight) && (nbPairsInPage > 1)) {
2142 nbPairsInPage--;
2143 }
2144 }
2145 return nbPairsInPage;
2146}
2147
2157static uint8_t getNbTagValuesInDetailsPage(uint8_t nbPairs,
2158 const nbgl_contentTagValueList_t *tagValueList,
2159 uint8_t startIndex)
2160{
2161 uint8_t nbPairsInPage = 0;
2162 uint16_t currentHeight = PRE_TAG_VALUE_MARGIN; // upper margin
2163 uint16_t maxUsableHeight = TAG_VALUE_AREA_HEIGHT;
2164
2165 while (nbPairsInPage < nbPairs) {
2166 const nbgl_layoutTagValue_t *pair;
2167
2168 // margin between pairs
2169 // 12 or 24 px between each tag/value pair
2170 if (nbPairsInPage > 0) {
2171 currentHeight += INTER_TAG_VALUE_MARGIN;
2172 }
2173 // fetch tag/value pair strings.
2174 if (tagValueList->pairs != NULL) {
2175 pair = PIC(&tagValueList->pairs[startIndex + nbPairsInPage]);
2176 }
2177 else {
2178 pair = PIC(tagValueList->callback(startIndex + nbPairsInPage));
2179 }
2180
2181 // tag height
2182 currentHeight += nbgl_getTextHeightInWidth(
2183 SMALL_REGULAR_FONT, pair->item, AVAILABLE_WIDTH, tagValueList->wrapping);
2184 // space between tag and value
2185 currentHeight += 4;
2186
2187 // value height
2188 currentHeight += nbgl_getTextHeightInWidth(
2189 SMALL_REGULAR_FONT, pair->value, AVAILABLE_WIDTH, tagValueList->wrapping);
2190
2191 // we have reached the maximum height, it means than there are to many pairs
2192 if (currentHeight >= maxUsableHeight) {
2193 break;
2194 }
2195 nbPairsInPage++;
2196 }
2197 return nbPairsInPage;
2198}
2199
2200static uint8_t getNbPagesForContent(const nbgl_content_t *content,
2201 uint8_t pageIdxStart,
2202 bool isLast,
2203 bool isSkippable)
2204{
2205 uint8_t nbElements = 0;
2206 uint8_t nbPages = 0;
2207 uint8_t nbElementsInPage;
2208 uint8_t elemIdx = 0;
2209 bool flag;
2210
2211 nbElements = getContentNbElement(content);
2212
2213 while (nbElements > 0) {
2214 flag = 0;
2215 // if the current page is not the first one (or last), a navigation bar exists
2216 bool hasNav = !isLast || (pageIdxStart > 0) || (elemIdx > 0);
2217 if (content->type == TAG_VALUE_LIST) {
2218 nbElementsInPage = getNbTagValuesInPage(nbElements,
2219 &content->content.tagValueList,
2220 elemIdx,
2221 isSkippable,
2222 false,
2223 false,
2224 &flag);
2225 }
2226 else if (content->type == TAG_VALUE_CONFIRM) {
2227 nbElementsInPage = getNbTagValuesInPage(nbElements,
2229 elemIdx,
2230 isSkippable,
2231 isLast,
2232 !isLast,
2233 &flag);
2234 }
2235 else if (content->type == INFOS_LIST) {
2236 nbElementsInPage = nbgl_useCaseGetNbInfosInPage(
2237 nbElements, &content->content.infosList, elemIdx, hasNav);
2238 }
2239 else if (content->type == SWITCHES_LIST) {
2240 nbElementsInPage = nbgl_useCaseGetNbSwitchesInPage(
2241 nbElements, &content->content.switchesList, elemIdx, hasNav);
2242 }
2243 else if (content->type == BARS_LIST) {
2244 nbElementsInPage = nbgl_useCaseGetNbBarsInPage(
2245 nbElements, &content->content.barsList, elemIdx, hasNav);
2246 }
2247 else if (content->type == CHOICES_LIST) {
2248 nbElementsInPage = nbgl_useCaseGetNbChoicesInPage(
2249 nbElements, &content->content.choicesList, elemIdx, hasNav);
2250 }
2251 else {
2252 nbElementsInPage = MIN(nbMaxElementsPerContentType[content->type], nbElements);
2253 }
2254
2255 elemIdx += nbElementsInPage;
2256 genericContextSetPageInfo(pageIdxStart + nbPages, nbElementsInPage, flag);
2257 nbElements -= nbElementsInPage;
2258 nbPages++;
2259 }
2260
2261 return nbPages;
2262}
2263
2264static uint8_t getNbPagesForGenericContents(const nbgl_genericContents_t *genericContents,
2265 uint8_t pageIdxStart,
2266 bool isSkippable)
2267{
2268 uint8_t nbPages = 0;
2269 nbgl_content_t content;
2270 const nbgl_content_t *p_content;
2271
2272 for (int i = 0; i < genericContents->nbContents; i++) {
2273 p_content = getContentAtIdx(genericContents, i, &content);
2274 if (p_content == NULL) {
2275 return 0;
2276 }
2277 nbPages += getNbPagesForContent(p_content,
2278 pageIdxStart + nbPages,
2279 (i == (genericContents->nbContents - 1)),
2280 isSkippable);
2281 }
2282
2283 return nbPages;
2284}
2285
2286static void prepareAddressConfirmationPages(const char *address,
2287 const nbgl_contentTagValueList_t *tagValueList,
2288 nbgl_content_t *firstPageContent,
2289 nbgl_content_t *secondPageContent)
2290{
2291 nbgl_contentTagValueConfirm_t *tagValueConfirm;
2292 uint8_t nbAddressChunks;
2293
2294 // Split the address into one or more chunks, each occupying its own page.
2295 // Each chunk-pair points into `address` at the chunk's start offset; the
2296 // list-level nbMaxLinesForValue (set further down when nbAddressChunks > 1)
2297 // bounds the rendered slice to NB_MAX_LINES_IN_REVIEW lines, so successive
2298 // chunks visually pick up where the previous left off. forcePageStart on
2299 // all but the first chunk ensures each chunk starts a fresh page.
2300 nbAddressChunks = nbgl_getTextNbPagesInWidth(
2301 LARGE_MEDIUM_FONT, address, NB_MAX_LINES_IN_REVIEW, AVAILABLE_WIDTH);
2302 if (nbAddressChunks > ADDR_VERIF_NB_PAIRS) {
2303 nbAddressChunks = ADDR_VERIF_NB_PAIRS;
2304 }
2305 {
2306 const char *chunkStart = address;
2307 for (uint8_t i = 0; i < nbAddressChunks; i++) {
2308 addressConfirmationContext.tagValuePairs[i].item = "Address";
2309 addressConfirmationContext.tagValuePairs[i].value = chunkStart;
2310 addressConfirmationContext.tagValuePairs[i].forcePageStart = (i > 0);
2311 if (i + 1 < nbAddressChunks) {
2312 uint16_t len = 0;
2313 nbgl_getTextMaxLenInNbLines(LARGE_MEDIUM_FONT,
2314 chunkStart,
2317 &len,
2318 false);
2319 chunkStart += len;
2320 }
2321 }
2322 }
2323 addressConfirmationContext.nbPairs = nbAddressChunks;
2324
2325 // First page
2326 firstPageContent->type = TAG_VALUE_CONFIRM;
2327 tagValueConfirm = &firstPageContent->content.tagValueConfirm;
2328
2329#ifdef NBGL_QRCODE
2330 tagValueConfirm->detailsButtonIcon = &QRCODE_ICON;
2331 // only pack extras on the address page when the address itself fits on a
2332 // single page; for multi-chunk addresses, extras go to their own second page
2333 if ((tagValueList != NULL) && (nbAddressChunks == 1)
2334 && (tagValueList->nbPairs < ADDR_VERIF_NB_PAIRS)) {
2336 bool flag;
2337 // copy in intermediate structure
2338 for (uint8_t i = 0; i < tagValueList->nbPairs; i++) {
2339 memcpy(&addressConfirmationContext.tagValuePairs[1 + i],
2340 &tagValueList->pairs[i],
2341 sizeof(nbgl_contentTagValue_t));
2342 addressConfirmationContext.nbPairs++;
2343 }
2344 // check how many can fit in a page
2345 memcpy(&tmpList, tagValueList, sizeof(nbgl_contentTagValueList_t));
2346 tmpList.nbPairs = addressConfirmationContext.nbPairs;
2347 tmpList.pairs = addressConfirmationContext.tagValuePairs;
2348 addressConfirmationContext.nbPairs = getNbTagValuesInPage(
2349 addressConfirmationContext.nbPairs, &tmpList, 0, false, true, true, &flag);
2350 // if they don't all fit, keep only the address
2351 if (tmpList.nbPairs > addressConfirmationContext.nbPairs) {
2352 addressConfirmationContext.nbPairs = 1;
2353 }
2354 }
2355 else {
2356 tagValueConfirm->detailsButtonText = NULL;
2357 }
2358 tagValueConfirm->detailsButtonToken = ADDRESS_QRCODE_BUTTON_TOKEN;
2359#else // NBGL_QRCODE
2360 tagValueConfirm->detailsButtonText = NULL;
2361 tagValueConfirm->detailsButtonIcon = NULL;
2362#endif // NBGL_QRCODE
2363 tagValueConfirm->tuneId = TUNE_TAP_CASUAL;
2364 tagValueConfirm->tagValueList.nbPairs = addressConfirmationContext.nbPairs;
2365 tagValueConfirm->tagValueList.pairs = addressConfirmationContext.tagValuePairs;
2366 tagValueConfirm->tagValueList.smallCaseForValue = false;
2367 // when the address spans multiple chunks, cap each pair's rendered value
2368 // at NB_MAX_LINES_IN_REVIEW lines so each chunk-pair occupies exactly one page
2369 tagValueConfirm->tagValueList.nbMaxLinesForValue
2370 = (nbAddressChunks > 1) ? NB_MAX_LINES_IN_REVIEW : 0;
2371 tagValueConfirm->tagValueList.hideEndOfLastLine = false;
2372 tagValueConfirm->tagValueList.wrapping = false;
2373
2374 // Number of extras left to place on a second page
2375 uint8_t extrasPlaced
2376 = (tagValueList != NULL) ? (addressConfirmationContext.nbPairs - nbAddressChunks) : 0;
2377 bool extrasNeedSecondPage = (tagValueList != NULL) && (tagValueList->nbPairs > extrasPlaced);
2378
2379 if (extrasNeedSecondPage) {
2380 tagValueConfirm->detailsButtonText = "Show as QR";
2381 tagValueConfirm->confirmationText = NULL;
2382 // the second page is dedicated to the extended tag/value pairs
2383 secondPageContent->type = TAG_VALUE_CONFIRM;
2384 tagValueConfirm = &secondPageContent->content.tagValueConfirm;
2385 tagValueConfirm->confirmationText = "Confirm";
2386 tagValueConfirm->confirmationToken = CONFIRM_TOKEN;
2387 tagValueConfirm->detailsButtonText = NULL;
2388 tagValueConfirm->detailsButtonIcon = NULL;
2389 tagValueConfirm->tuneId = TUNE_TAP_CASUAL;
2390 memcpy(&tagValueConfirm->tagValueList, tagValueList, sizeof(nbgl_contentTagValueList_t));
2391 tagValueConfirm->tagValueList.nbPairs = tagValueList->nbPairs - extrasPlaced;
2392 tagValueConfirm->tagValueList.pairs = &tagValueList->pairs[extrasPlaced];
2393 }
2394 else {
2395 // otherwise no tap to continue but a confirmation button
2396 tagValueConfirm->confirmationText = "Confirm";
2397 tagValueConfirm->confirmationToken = CONFIRM_TOKEN;
2398 }
2399}
2400
2401static void bundleNavStartHome(void)
2402{
2403 nbgl_homeAndSettingsContext_t *context = &bundleNavContext.homeAndSettings;
2404
2405 useCaseHomeExt(context->appName,
2406 context->appIcon,
2407 context->tagline,
2408 context->settingContents != NULL ? true : false,
2409 &context->homeAction,
2410 bundleNavStartSettings,
2411 context->quitCallback);
2412}
2413
2414static void bundleNavStartSettingsAtPage(uint8_t initSettingPage)
2415{
2416 nbgl_homeAndSettingsContext_t *context = &bundleNavContext.homeAndSettings;
2417
2418 nbgl_useCaseGenericSettings(context->appName,
2419 initSettingPage,
2420 context->settingContents,
2421 context->infosList,
2422 bundleNavStartHome);
2423}
2424
2425static void bundleNavStartSettings(void)
2426{
2427 bundleNavStartSettingsAtPage(0);
2428}
2429
2430static void bundleNavReviewConfirmRejection(void)
2431{
2432 bundleNavContext.review.choiceCallback(false);
2433}
2434
2435static void bundleNavReviewAskRejectionConfirmation(nbgl_operationType_t operationType,
2436 nbgl_callback_t callback)
2437{
2438 const char *title;
2439 const char *confirmText;
2440 // clear skip and blind bits
2441 operationType
2443 if (operationType == TYPE_TRANSACTION) {
2444 title = "Reject transaction?";
2445 confirmText = "Go back to transaction";
2446 }
2447 else if (operationType == TYPE_MESSAGE) {
2448 title = "Reject message?";
2449 confirmText = "Go back to message";
2450 }
2451 else {
2452 title = "Reject operation?";
2453 confirmText = "Go back to operation";
2454 }
2455
2456 // display a choice to confirm/cancel rejection
2457 nbgl_useCaseConfirm(title, NULL, "Yes, reject", confirmText, callback);
2458}
2459
2460static void bundleNavReviewChoice(bool confirm)
2461{
2462 if (confirm) {
2463 bundleNavContext.review.choiceCallback(true);
2464 }
2465 else {
2466 bundleNavReviewAskRejectionConfirmation(bundleNavContext.review.operationType,
2467 bundleNavReviewConfirmRejection);
2468 }
2469}
2470
2471static void bundleNavReviewStreamingConfirmRejection(void)
2472{
2473 bundleNavContext.reviewStreaming.choiceCallback(false);
2474}
2475
2476static void bundleNavReviewStreamingChoice(bool confirm)
2477{
2478 if (confirm) {
2479 bundleNavContext.reviewStreaming.choiceCallback(true);
2480 }
2481 else {
2482 bundleNavReviewAskRejectionConfirmation(bundleNavContext.reviewStreaming.operationType,
2483 bundleNavReviewStreamingConfirmRejection);
2484 }
2485}
2486
2487// function used to display the details in modal (from Choice with details or from Customized
2488// security report) it can be either a single page with text or QR code, or a list of touchable bars
2489// leading to single pages
2490static nbgl_layout_t *displayModalDetails(const nbgl_warningDetails_t *details, uint8_t token)
2491{
2492 nbgl_layoutDescription_t layoutDescription = {.modal = true,
2493 .withLeftBorder = true,
2494 .onActionCallback = modalLayoutTouchCallback,
2495 .tapActionText = NULL};
2496 nbgl_layoutHeader_t headerDesc = {.type = HEADER_BACK_AND_TEXT,
2497 .separationLine = true,
2498 .backAndText.icon = NULL,
2499 .backAndText.tuneId = TUNE_TAP_CASUAL,
2500 .backAndText.token = token};
2501 uint8_t i;
2502 nbgl_layout_t *layout;
2503
2504 layout = nbgl_layoutGet(&layoutDescription);
2505 headerDesc.backAndText.text = details->title;
2506 nbgl_layoutAddHeader(layout, &headerDesc);
2507 if (details->type == BAR_LIST_WARNING) {
2508 // if more than one warning, so use a list of touchable bars
2509 for (i = 0; i < details->barList.nbBars; i++) {
2510 nbgl_layoutBar_t bar;
2511 bar.text = details->barList.texts[i];
2512 bar.subText = details->barList.subTexts[i];
2513 // Only assign a right icon if the bar is clickable (i.e. has details to display)
2514 if ((details->barList.details)
2515 && (details->barList.details[i].type != NO_TYPE_WARNING)) {
2516 bar.iconRight = &PUSH_ICON;
2517 }
2518 else {
2519 bar.iconRight = NULL;
2520 }
2521 // Left icon is optional, only set if provided by the warning details
2522 if (details->barList.icons != NULL) {
2523 bar.iconLeft = details->barList.icons[i];
2524 }
2525 else {
2526 bar.iconLeft = NULL;
2527 }
2528 bar.token = FIRST_WARN_BAR_TOKEN + i;
2529 bar.tuneId = TUNE_TAP_CASUAL;
2530 bar.large = false;
2531 bar.inactive = false;
2532 nbgl_layoutAddTouchableBar(layout, &bar);
2533 nbgl_layoutAddSeparationLine(layout);
2534 }
2535 }
2536 else if (details->type == QRCODE_WARNING) {
2537#ifdef NBGL_QRCODE
2538 // display a QR Code
2539 nbgl_layoutAddQRCode(layout, &details->qrCode);
2540#endif // NBGL_QRCODE
2541 headerDesc.backAndText.text = details->title;
2542 }
2543 else if (details->type == CENTERED_INFO_WARNING) {
2544 // display a centered info
2545 nbgl_layoutAddContentCenter(layout, &details->centeredInfo);
2546 headerDesc.separationLine = false;
2547 }
2548 nbgl_layoutDraw(layout);
2549 nbgl_refresh();
2550 return layout;
2551}
2552
2553// function used to display the security level page in modal
2554// it can be either a single page with text or QR code, or a list of touchable bars leading
2555// to single pages
2556static void displaySecurityReport(uint32_t set)
2557{
2558 nbgl_layoutDescription_t layoutDescription = {.modal = true,
2559 .withLeftBorder = true,
2560 .onActionCallback = modalLayoutTouchCallback,
2561 .tapActionText = NULL};
2562 nbgl_layoutHeader_t headerDesc = {.type = HEADER_BACK_AND_TEXT,
2563 .separationLine = true,
2564 .backAndText.icon = NULL,
2565 .backAndText.tuneId = TUNE_TAP_CASUAL,
2566 .backAndText.token = DISMISS_WARNING_TOKEN};
2567 nbgl_layoutFooter_t footerDesc
2568 = {.type = FOOTER_EMPTY, .separationLine = false, .emptySpace.height = 0};
2569 uint8_t i;
2570 const char *provider;
2571
2572 reviewWithWarnCtx.modalLayout = nbgl_layoutGet(&layoutDescription);
2573
2574 // display a list of touchable bars in some conditions:
2575 // - we must be in the first level of security report
2576 // - and be in the review itself (not from the intro/warning screen)
2577 //
2578 if ((reviewWithWarnCtx.securityReportLevel == 1) && (!reviewWithWarnCtx.isIntro)) {
2579 for (i = 0; i < NB_WARNING_TYPES; i++) {
2580 // Skip GATED_SIGNING_WARN from security report bars
2581 if ((i != GATED_SIGNING_WARN)
2582 && (reviewWithWarnCtx.warning->predefinedSet & (1 << i))) {
2583 nbgl_layoutBar_t bar = {0};
2584 if ((i == BLIND_SIGNING_WARN) || (i == W3C_NO_THREAT_WARN) || (i == W3C_ISSUE_WARN)
2585 || (reviewWithWarnCtx.warning->providerMessage == NULL)) {
2586 bar.subText = securityReportItems[i].subText;
2587 }
2588 else {
2589 bar.subText = reviewWithWarnCtx.warning->providerMessage;
2590 }
2591 bar.text = securityReportItems[i].text;
2592 if (i != W3C_NO_THREAT_WARN) {
2593 bar.iconRight = &PUSH_ICON;
2594 bar.token = FIRST_WARN_BAR_TOKEN + i;
2595 bar.tuneId = TUNE_TAP_CASUAL;
2596 }
2597 else {
2599 }
2600 bar.iconLeft = securityReportItems[i].icon;
2601 nbgl_layoutAddTouchableBar(reviewWithWarnCtx.modalLayout, &bar);
2602 nbgl_layoutAddSeparationLine(reviewWithWarnCtx.modalLayout);
2603 }
2604 }
2605 headerDesc.backAndText.text = "Security report";
2606 nbgl_layoutAddHeader(reviewWithWarnCtx.modalLayout, &headerDesc);
2607 nbgl_layoutDraw(reviewWithWarnCtx.modalLayout);
2608 nbgl_refresh();
2609 return;
2610 }
2611 if (reviewWithWarnCtx.warning && reviewWithWarnCtx.warning->reportProvider) {
2612 provider = reviewWithWarnCtx.warning->reportProvider;
2613 }
2614 else {
2615 provider = "[unknown]";
2616 }
2617 if ((set & (1 << W3C_THREAT_DETECTED_WARN)) || (set & (1 << W3C_RISK_DETECTED_WARN))) {
2618 size_t urlLen = 0;
2619 char *destStr
2620 = tmpString
2621 + W3C_DESCRIPTION_MAX_LEN / 2; // use the second half of tmpString for strings
2622#ifdef NBGL_QRCODE
2623 // display a QR Code
2624 nbgl_layoutQRCode_t qrCode = {.url = destStr,
2625 .text1 = reviewWithWarnCtx.warning->reportUrl,
2626 .text2 = "Scan to view full report",
2627 .centered = true,
2628 .offsetY = 0};
2629 // add "https://"" as prefix of the given URL
2630 snprintf(destStr,
2631 W3C_DESCRIPTION_MAX_LEN / 2,
2632 "https://%s",
2633 reviewWithWarnCtx.warning->reportUrl);
2634 urlLen = strlen(destStr) + 1;
2635 nbgl_layoutAddQRCode(reviewWithWarnCtx.modalLayout, &qrCode);
2636 footerDesc.emptySpace.height = 24;
2637#endif // NBGL_QRCODE
2638 // use the next part of destStr for back bar text
2639 snprintf(destStr + urlLen, W3C_DESCRIPTION_MAX_LEN / 2 - urlLen, "%s report", provider);
2640 headerDesc.backAndText.text = destStr + urlLen;
2641 }
2642 else if (set & (1 << BLIND_SIGNING_WARN)) {
2643 // display a centered if in review
2644 nbgl_contentCenter_t info = {0};
2645 info.icon = &LARGE_WARNING_ICON;
2646 info.title = "This transaction cannot be Clear Signed";
2647 info.description
2648 = "This transaction or message cannot be decoded fully. If you choose to sign, you "
2649 "could be authorizing malicious actions that can drain your wallet.\n\nLearn more: "
2650 "ledger.com/e8";
2651 nbgl_layoutAddContentCenter(reviewWithWarnCtx.modalLayout, &info);
2652 footerDesc.emptySpace.height = SMALL_CENTERING_HEADER;
2653 headerDesc.separationLine = false;
2654 }
2655 else if (set & (1 << W3C_ISSUE_WARN)) {
2656 // if W3 Checks issue, display a centered info
2657 nbgl_contentCenter_t info = {0};
2658 info.icon = &LARGE_WARNING_ICON;
2659 info.title = "Transaction Check unavailable";
2660 info.description
2661 = "If you're not using the Ledger Wallet app, Transaction Check might not work. If "
2662 "you "
2663 "are using Ledger Wallet, reject the transaction and try again.\n\nGet help at "
2664 "ledger.com/e11";
2665 nbgl_layoutAddContentCenter(reviewWithWarnCtx.modalLayout, &info);
2666 footerDesc.emptySpace.height = SMALL_CENTERING_HEADER;
2667 headerDesc.separationLine = false;
2668 }
2669 nbgl_layoutAddHeader(reviewWithWarnCtx.modalLayout, &headerDesc);
2670 if (footerDesc.emptySpace.height > 0) {
2671 nbgl_layoutAddExtendedFooter(reviewWithWarnCtx.modalLayout, &footerDesc);
2672 }
2673 nbgl_layoutDraw(reviewWithWarnCtx.modalLayout);
2674 nbgl_refresh();
2675}
2676
2677// function used to display the security level page in modal
2678// it can be either a single page with text or QR code, or a list of touchable bars leading
2679// to single pages
2680static void displayCustomizedSecurityReport(const nbgl_warningDetails_t *details)
2681{
2682 reviewWithWarnCtx.modalLayout = displayModalDetails(details, DISMISS_WARNING_TOKEN);
2683}
2684
2685// function used to display the initial warning page when starting a "review with warning"
2686static void displayInitialWarning(void)
2687{
2688 // Play notification sound
2689#ifdef HAVE_PIEZO_SOUND
2690 tune_index_e tune = TUNE_RESERVED;
2691#endif // HAVE_PIEZO_SOUND
2692 nbgl_layoutDescription_t layoutDescription;
2693 nbgl_layoutChoiceButtons_t buttonsInfo = {.bottomText = "Continue anyway",
2694 .token = WARNING_CHOICE_TOKEN,
2695 .topText = "Back to safety",
2696 .style = ROUNDED_AND_FOOTER_STYLE,
2697 .tuneId = TUNE_TAP_CASUAL};
2698 nbgl_layoutHeader_t headerDesc = {.type = HEADER_EMPTY,
2699 .separationLine = false,
2700 .emptySpace.height = MEDIUM_CENTERING_HEADER};
2701 uint32_t set = reviewWithWarnCtx.warning->predefinedSet
2702 & ~((1 << W3C_NO_THREAT_WARN) | (1 << W3C_ISSUE_WARN));
2703
2704 bool isBlindSigningOnly
2705 = (set != 0) && ((set & ~((1 << BLIND_SIGNING_WARN) | (1 << GATED_SIGNING_WARN))) == 0);
2706 reviewWithWarnCtx.isIntro = true;
2707
2708 layoutDescription.modal = false;
2709 layoutDescription.withLeftBorder = true;
2710
2711 layoutDescription.onActionCallback = layoutTouchCallback;
2712 layoutDescription.tapActionText = NULL;
2713
2714 layoutDescription.ticker.tickerCallback = NULL;
2715 reviewWithWarnCtx.layoutCtx = nbgl_layoutGet(&layoutDescription);
2716
2717 nbgl_layoutAddHeader(reviewWithWarnCtx.layoutCtx, &headerDesc);
2718 if (reviewWithWarnCtx.warning->predefinedSet != 0) {
2719 // icon is different in casee of Blind Siging or Gated Signing
2720 nbgl_layoutAddTopRightButton(reviewWithWarnCtx.layoutCtx,
2721 isBlindSigningOnly ? &INFO_I_ICON : &QRCODE_ICON,
2722 WARNING_BUTTON_TOKEN,
2723 TUNE_TAP_CASUAL);
2724 }
2725 else if (reviewWithWarnCtx.warning->introTopRightIcon != NULL) {
2726 nbgl_layoutAddTopRightButton(reviewWithWarnCtx.layoutCtx,
2727 reviewWithWarnCtx.warning->introTopRightIcon,
2728 WARNING_BUTTON_TOKEN,
2729 TUNE_TAP_CASUAL);
2730 }
2731 // add main content
2732 // if predefined content is configured, use it preferably
2733 if (reviewWithWarnCtx.warning->predefinedSet != 0) {
2734 nbgl_contentCenter_t info = {0};
2735
2736 const char *provider;
2737
2738 // default icon
2739 info.icon = &LARGE_WARNING_ICON;
2740
2741 // use small title only if not Blind signing and not Gated signing
2742 if (isBlindSigningOnly == false) {
2743 if (reviewWithWarnCtx.warning->reportProvider) {
2744 provider = reviewWithWarnCtx.warning->reportProvider;
2745 }
2746 else {
2747 provider = "[unknown]";
2748 }
2749 info.smallTitle = tmpString;
2750 snprintf(tmpString, W3C_DESCRIPTION_MAX_LEN, "Detected by %s", provider);
2751 }
2752
2753 // If Blind Signing or Gated Signing
2754 if (isBlindSigningOnly) {
2755 info.title = "Blind signing ahead";
2756 if (set & (1 << GATED_SIGNING_WARN)) {
2757 info.description
2758 = "If you sign this transaction, you could lose your assets. "
2759 "Explore safer alternatives: ledger.com/integrated-apps";
2760 buttonsInfo.bottomText = "Accept risk and continue";
2761 }
2762 else {
2763 info.description
2764 = "This transaction's details are not fully verifiable. If you sign, you could "
2765 "lose all your assets.";
2766 buttonsInfo.bottomText = "Continue anyway";
2767 }
2768#ifdef HAVE_PIEZO_SOUND
2769 tune = TUNE_NEUTRAL;
2770#endif // HAVE_PIEZO_SOUND
2771 }
2772 else if (set & (1 << W3C_RISK_DETECTED_WARN)) {
2773 info.title = "Potential risk";
2774 if (reviewWithWarnCtx.warning->providerMessage == NULL) {
2775 info.description = "Unidentified risk";
2776 }
2777 else {
2778 info.description = reviewWithWarnCtx.warning->providerMessage;
2779 }
2780 buttonsInfo.bottomText = "Accept risk and continue";
2781#ifdef HAVE_PIEZO_SOUND
2782 tune = TUNE_NEUTRAL;
2783#endif // HAVE_PIEZO_SOUND
2784 }
2785 else if (set & (1 << W3C_THREAT_DETECTED_WARN)) {
2786 info.title = "Critical threat";
2787 if (reviewWithWarnCtx.warning->providerMessage == NULL) {
2788 info.description = "Unidentified threat";
2789 }
2790 else {
2791 info.description = reviewWithWarnCtx.warning->providerMessage;
2792 }
2793 buttonsInfo.bottomText = "Accept threat and continue";
2794#ifdef HAVE_PIEZO_SOUND
2795 tune = TUNE_ERROR;
2796#endif // HAVE_PIEZO_SOUND
2797 }
2798 nbgl_layoutAddContentCenter(reviewWithWarnCtx.layoutCtx, &info);
2799 }
2800 else if (reviewWithWarnCtx.warning->info != NULL) {
2801 // if no predefined content, use custom one
2802 nbgl_layoutAddContentCenter(reviewWithWarnCtx.layoutCtx, reviewWithWarnCtx.warning->info);
2803#ifdef HAVE_PIEZO_SOUND
2804 tune = TUNE_LOOK_AT_ME;
2805#endif // HAVE_PIEZO_SOUND
2806 }
2807 // add button and footer on bottom
2808 nbgl_layoutAddChoiceButtons(reviewWithWarnCtx.layoutCtx, &buttonsInfo);
2809
2810#ifdef HAVE_PIEZO_SOUND
2811 if (tune != TUNE_RESERVED) {
2812 os_io_seph_cmd_piezo_play_tune(tune);
2813 }
2814#endif // HAVE_PIEZO_SOUND
2815 nbgl_layoutDraw(reviewWithWarnCtx.layoutCtx);
2816 nbgl_refresh();
2817}
2818
2819// function used to display the prelude when starting a "review with warning"
2820static void displayPrelude(void)
2821{
2822 nbgl_layoutDescription_t layoutDescription;
2823 nbgl_layoutChoiceButtons_t buttonsInfo
2824 = {.bottomText = reviewWithWarnCtx.warning->prelude->footerText,
2825 .token = PRELUDE_CHOICE_TOKEN,
2826 .topText = reviewWithWarnCtx.warning->prelude->buttonText,
2827 .style = ROUNDED_AND_FOOTER_STYLE,
2828 .tuneId = TUNE_TAP_CASUAL};
2829 nbgl_layoutHeader_t headerDesc = {.type = HEADER_EMPTY,
2830 .separationLine = false,
2831 .emptySpace.height = MEDIUM_CENTERING_HEADER};
2832
2833 reviewWithWarnCtx.isIntro = true;
2834
2835 layoutDescription.modal = false;
2836 layoutDescription.withLeftBorder = true;
2837 layoutDescription.onActionCallback = layoutTouchCallback;
2838 layoutDescription.tapActionText = NULL;
2839 layoutDescription.ticker.tickerCallback = NULL;
2840 reviewWithWarnCtx.layoutCtx = nbgl_layoutGet(&layoutDescription);
2841
2842 nbgl_layoutAddHeader(reviewWithWarnCtx.layoutCtx, &headerDesc);
2843 // add centered content
2844 nbgl_contentCenter_t info = {0};
2845
2846 // default icon
2847 info.icon = reviewWithWarnCtx.warning->prelude->icon;
2848
2849 info.title = reviewWithWarnCtx.warning->prelude->title;
2850 info.description = reviewWithWarnCtx.warning->prelude->description;
2851 nbgl_layoutAddContentCenter(reviewWithWarnCtx.layoutCtx, &info);
2852
2853 // add button and footer on bottom
2854 nbgl_layoutAddChoiceButtons(reviewWithWarnCtx.layoutCtx, &buttonsInfo);
2855
2856#ifdef HAVE_PIEZO_SOUND
2857 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
2858#endif // HAVE_PIEZO_SOUND
2859 nbgl_layoutDraw(reviewWithWarnCtx.layoutCtx);
2860 nbgl_refresh();
2861}
2862
2863// function to factorize code for reviews tipbox
2864static void initWarningTipBox(const nbgl_tipBox_t *tipBox)
2865{
2866 const char *predefinedTipBoxText = NULL;
2867
2868 // if warning is valid and a warning requires a tip-box
2869 if (reviewWithWarnCtx.warning) {
2870 if (reviewWithWarnCtx.warning->predefinedSet & (1 << W3C_ISSUE_WARN)) {
2871 if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
2872 predefinedTipBoxText = "Transaction Check unavailable.\nBlind signing required.";
2873 }
2874 else {
2875 predefinedTipBoxText = "Transaction Check unavailable";
2876 }
2877 }
2878 else if (reviewWithWarnCtx.warning->predefinedSet & (1 << W3C_THREAT_DETECTED_WARN)) {
2879 if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
2880 predefinedTipBoxText = "Critical threat detected.\nBlind signing required.";
2881 }
2882 else {
2883 predefinedTipBoxText = "Critical threat detected.";
2884 }
2885 }
2886 else if (reviewWithWarnCtx.warning->predefinedSet & (1 << W3C_RISK_DETECTED_WARN)) {
2887 if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
2888 predefinedTipBoxText = "Potential risk detected.\nBlind signing required.";
2889 }
2890 else {
2891 predefinedTipBoxText = "Potential risk detected.";
2892 }
2893 }
2894 else if (reviewWithWarnCtx.warning->predefinedSet & (1 << W3C_NO_THREAT_WARN)) {
2895 if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
2896 predefinedTipBoxText
2897 = "No threat detected by Transaction Check but blind signing required.";
2898 }
2899 else {
2900 predefinedTipBoxText = "No threat detected by Transaction Check.";
2901 }
2902 }
2903 else if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
2904 predefinedTipBoxText = "Blind signing required.";
2905 }
2906 }
2907
2908 if ((tipBox != NULL) || (predefinedTipBoxText != NULL)) {
2909 // do not display "Swipe to review" if a tip-box is displayed
2910 STARTING_CONTENT.content.extendedCenter.contentCenter.subText = NULL;
2911 if (predefinedTipBoxText != NULL) {
2912 genericContext.validWarningCtx = true;
2913 STARTING_CONTENT.content.extendedCenter.tipBox.icon = NULL;
2914 STARTING_CONTENT.content.extendedCenter.tipBox.text = predefinedTipBoxText;
2915 }
2916 else {
2917 STARTING_CONTENT.content.extendedCenter.tipBox.icon = tipBox->icon;
2918 STARTING_CONTENT.content.extendedCenter.tipBox.text = tipBox->text;
2919 }
2920 STARTING_CONTENT.content.extendedCenter.tipBox.token = TIP_BOX_TOKEN;
2921 STARTING_CONTENT.content.extendedCenter.tipBox.tuneId = TUNE_TAP_CASUAL;
2922 }
2923}
2924
2925// function to factorize code for all simple reviews
2926static void useCaseReview(nbgl_operationType_t operationType,
2927 const nbgl_contentTagValueList_t *tagValueList,
2928 const nbgl_icon_details_t *icon,
2929 const char *reviewTitle,
2930 const char *reviewSubTitle,
2931 const char *finishTitle,
2932 const nbgl_tipBox_t *tipBox,
2933 nbgl_choiceCallback_t choiceCallback,
2934 bool isLight,
2935 bool playNotifSound)
2936{
2937 bundleNavContext.review.operationType = operationType;
2938 bundleNavContext.review.choiceCallback = choiceCallback;
2939
2940 // memorize context
2941 onChoice = bundleNavReviewChoice;
2942 navType = GENERIC_NAV;
2943 pageTitle = NULL;
2944
2945 genericContext.genericContents.contentsList = localContentsList;
2946 genericContext.genericContents.nbContents = 3;
2947 memset(localContentsList, 0, 3 * sizeof(nbgl_content_t));
2948
2949 // First a centered info
2950 STARTING_CONTENT.type = EXTENDED_CENTER;
2951 prepareReviewFirstPage(
2952 &STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
2953
2954 // Prepare un tipbox if needed
2955 initWarningTipBox(tipBox);
2956
2957 // Then the tag/value pairs
2958 localContentsList[1].type = TAG_VALUE_LIST;
2959 memcpy(&localContentsList[1].content.tagValueList,
2960 tagValueList,
2962 localContentsList[1].contentActionCallback = tagValueList->actionCallback;
2963
2964 // The last page
2965 if (isLight) {
2966 localContentsList[2].type = INFO_BUTTON;
2967 prepareReviewLightLastPage(
2968 operationType, &localContentsList[2].content.infoButton, icon, finishTitle);
2969 }
2970 else {
2971 localContentsList[2].type = INFO_LONG_PRESS;
2972 prepareReviewLastPage(
2973 operationType, &localContentsList[2].content.infoLongPress, icon, finishTitle);
2974 }
2975
2976 // compute number of pages & fill navigation structure
2977 uint8_t nbPages = getNbPagesForGenericContents(
2978 &genericContext.genericContents, 0, (operationType & SKIPPABLE_OPERATION));
2979 prepareNavInfo(true, nbPages, getRejectReviewText(operationType));
2980
2981 // Play notification sound if required
2982 if (playNotifSound) {
2983#ifdef HAVE_PIEZO_SOUND
2984 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
2985#endif // HAVE_PIEZO_SOUND
2986 }
2987
2988 displayGenericContextPage(0, true);
2989}
2990
2991// function to factorize code for all streaming reviews
2992static void useCaseReviewStreamingStart(nbgl_operationType_t operationType,
2993 const nbgl_icon_details_t *icon,
2994 const char *reviewTitle,
2995 const char *reviewSubTitle,
2996 nbgl_choiceCallback_t choiceCallback,
2997 bool playNotifSound)
2998{
2999 bundleNavContext.reviewStreaming.operationType = operationType;
3000 bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
3001 bundleNavContext.reviewStreaming.icon = icon;
3002
3003 // memorize context
3004 onChoice = bundleNavReviewStreamingChoice;
3005 navType = STREAMING_NAV;
3006 pageTitle = NULL;
3007
3008 genericContext.genericContents.contentsList = localContentsList;
3009 genericContext.genericContents.nbContents = 1;
3010 memset(localContentsList, 0, 1 * sizeof(nbgl_content_t));
3011
3012 // First a centered info
3013 STARTING_CONTENT.type = EXTENDED_CENTER;
3014 prepareReviewFirstPage(
3015 &STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
3016
3017 // Prepare un tipbox if needed
3018 initWarningTipBox(NULL);
3019
3020 // compute number of pages & fill navigation structure
3021 bundleNavContext.reviewStreaming.stepPageNb = getNbPagesForGenericContents(
3022 &genericContext.genericContents, 0, (operationType & SKIPPABLE_OPERATION));
3023 prepareNavInfo(true, NBGL_NO_PROGRESS_INDICATOR, getRejectReviewText(operationType));
3024 // no back button on first page
3025 navInfo.navWithButtons.backButton = false;
3026
3027 // Play notification sound if required
3028 if (playNotifSound) {
3029#ifdef HAVE_PIEZO_SOUND
3030 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
3031#endif // HAVE_PIEZO_SOUND
3032 }
3033
3034 displayGenericContextPage(0, true);
3035}
3036
3053static void useCaseHomeExt(const char *appName,
3054 const nbgl_icon_details_t *appIcon,
3055 const char *tagline,
3056 bool withSettings,
3057 nbgl_homeAction_t *homeAction,
3058 nbgl_callback_t topRightCallback,
3059 nbgl_callback_t quitCallback)
3060{
3061 nbgl_pageInfoDescription_t info = {.centeredInfo.icon = appIcon,
3062 .centeredInfo.text1 = appName,
3063 .centeredInfo.text3 = NULL,
3064 .centeredInfo.style = LARGE_CASE_INFO,
3065 .centeredInfo.offsetY = 0,
3066 .footerText = NULL,
3067 .bottomButtonStyle = QUIT_APP_TEXT,
3068 .tapActionText = NULL,
3069 .topRightStyle = withSettings ? SETTINGS_ICON : INFO_ICON,
3070 .topRightToken = CONTINUE_TOKEN,
3071 .tuneId = TUNE_TAP_CASUAL};
3072 reset_callbacks_and_context();
3073
3074 if ((homeAction->text != NULL) || (homeAction->icon != NULL)) {
3075 // trick to use ACTION_BUTTON_TOKEN for action and quit, with index used to distinguish
3076 info.bottomButtonsToken = ACTION_BUTTON_TOKEN;
3077 onAction = homeAction->callback;
3078 info.actionButtonText = homeAction->text;
3079 info.actionButtonIcon = homeAction->icon;
3081 = (homeAction->style == STRONG_HOME_ACTION) ? BLACK_BACKGROUND : WHITE_BACKGROUND;
3082 }
3083 else {
3084 info.bottomButtonsToken = QUIT_TOKEN;
3085 onAction = NULL;
3086 info.actionButtonText = NULL;
3087 info.actionButtonIcon = NULL;
3088 }
3089 if (tagline == NULL) {
3090 if (strlen(appName) > MAX_APP_NAME_FOR_SDK_TAGLINE) {
3091 snprintf(tmpString,
3093 "This app enables signing\ntransactions on its network.");
3094 }
3095 else {
3096 snprintf(tmpString,
3098 "%s %s\n%s",
3100 appName,
3102 }
3103
3104 // If there is more than 3 lines, it means the appName was split, so we put it on the next
3105 // line
3106 if (nbgl_getTextNbLinesInWidth(SMALL_REGULAR_FONT, tmpString, AVAILABLE_WIDTH, false) > 3) {
3107 snprintf(tmpString,
3109 "%s\n%s %s",
3111 appName,
3113 }
3114 info.centeredInfo.text2 = tmpString;
3115 }
3116 else {
3117 info.centeredInfo.text2 = tagline;
3118 }
3119
3120 onContinue = topRightCallback;
3121 onQuit = quitCallback;
3122
3123 pageContext = nbgl_pageDrawInfo(&pageCallback, NULL, &info);
3125}
3126
3135static void displayDetails(const char *tag, const char *value, bool wrapping)
3136{
3137 memset(&detailsContext, 0, sizeof(detailsContext));
3138
3139 uint16_t nbLines
3140 = nbgl_getTextNbLinesInWidth(SMALL_REGULAR_FONT, value, AVAILABLE_WIDTH, wrapping);
3141
3142 // initialize context
3143 detailsContext.tag = tag;
3144 detailsContext.value = value;
3145 detailsContext.nbPages = (nbLines + NB_MAX_LINES_IN_DETAILS - 1) / NB_MAX_LINES_IN_DETAILS;
3146 detailsContext.currentPage = 0;
3147 detailsContext.wrapping = wrapping;
3148 // add some spare for room lost with "..." substitution
3149 if (detailsContext.nbPages > 1) {
3150 uint16_t nbLostChars = (detailsContext.nbPages - 1) * 3;
3151 uint16_t nbLostLines = (nbLostChars + ((AVAILABLE_WIDTH) / 16) - 1)
3152 / ((AVAILABLE_WIDTH) / 16); // 16 for average char width
3153 uint8_t nbLinesInLastPage
3154 = nbLines - ((detailsContext.nbPages - 1) * NB_MAX_LINES_IN_DETAILS);
3155
3156 detailsContext.nbPages += nbLostLines / NB_MAX_LINES_IN_DETAILS;
3157 if ((nbLinesInLastPage + (nbLostLines % NB_MAX_LINES_IN_DETAILS))
3159 detailsContext.nbPages++;
3160 }
3161 }
3162
3163 displayDetailsPage(0, true);
3164}
3165
3166// function used to display the modal containing alias tag-value pairs
3167static void displayTagValueListModal(const nbgl_contentTagValueList_t *tagValues)
3168{
3169 uint8_t nbElements = 0;
3170 uint8_t nbElementsInPage;
3171 uint8_t elemIdx = 0;
3172
3173 // initialize context
3174 memset(&detailsContext, 0, sizeof(detailsContext));
3175 nbElements = tagValues->nbPairs;
3176
3177 while (nbElements > 0) {
3178 nbElementsInPage = getNbTagValuesInDetailsPage(nbElements, tagValues, elemIdx);
3179
3180 elemIdx += nbElementsInPage;
3181 modalContextSetPageInfo(detailsContext.nbPages, nbElementsInPage);
3182 nbElements -= nbElementsInPage;
3183 detailsContext.nbPages++;
3184 }
3185
3186 displayTagValueListModalPage(0, true);
3187}
3188
3189/**********************
3190 * GLOBAL FUNCTIONS
3191 **********************/
3192
3205uint8_t nbgl_useCaseGetNbTagValuesInPage(uint8_t nbPairs,
3206 const nbgl_contentTagValueList_t *tagValueList,
3207 uint8_t startIndex,
3208 bool *requireSpecificDisplay)
3209{
3210 return getNbTagValuesInPage(
3211 nbPairs, tagValueList, startIndex, false, false, false, requireSpecificDisplay);
3212}
3213
3227uint8_t nbgl_useCaseGetNbTagValuesInPageExt(uint8_t nbPairs,
3228 const nbgl_contentTagValueList_t *tagValueList,
3229 uint8_t startIndex,
3230 bool isSkippable,
3231 bool *requireSpecificDisplay)
3232{
3233 return getNbTagValuesInPage(
3234 nbPairs, tagValueList, startIndex, isSkippable, false, false, requireSpecificDisplay);
3235}
3236
3246uint8_t nbgl_useCaseGetNbInfosInPage(uint8_t nbInfos,
3247 const nbgl_contentInfoList_t *infosList,
3248 uint8_t startIndex,
3249 bool withNav)
3250{
3251 uint8_t nbInfosInPage = 0;
3252 uint16_t currentHeight = 0;
3253 uint16_t previousHeight;
3254 uint16_t navHeight = withNav ? SIMPLE_FOOTER_HEIGHT : 0;
3255 const char *const *infoContents = PIC(infosList->infoContents);
3256
3257 while (nbInfosInPage < nbInfos) {
3258 // The type string must be a 1 liner and its height is LIST_ITEM_MIN_TEXT_HEIGHT
3259 currentHeight
3260 += LIST_ITEM_MIN_TEXT_HEIGHT + 2 * LIST_ITEM_PRE_HEADING + LIST_ITEM_HEADING_SUB_TEXT;
3261
3262 // content height
3263 currentHeight += nbgl_getTextHeightInWidth(SMALL_REGULAR_FONT,
3264 PIC(infoContents[startIndex + nbInfosInPage]),
3266 true);
3267 // if height is over the limit
3268 if (currentHeight >= (INFOS_AREA_HEIGHT - navHeight)) {
3269 // if there was no nav, now there will be, so it can be necessary to remove the last
3270 // item
3271 if (!withNav && (previousHeight >= (INFOS_AREA_HEIGHT - SIMPLE_FOOTER_HEIGHT))) {
3272 nbInfosInPage--;
3273 }
3274 break;
3275 }
3276 previousHeight = currentHeight;
3277 nbInfosInPage++;
3278 }
3279 return nbInfosInPage;
3280}
3281
3291uint8_t nbgl_useCaseGetNbSwitchesInPage(uint8_t nbSwitches,
3292 const nbgl_contentSwitchesList_t *switchesList,
3293 uint8_t startIndex,
3294 bool withNav)
3295{
3296 uint8_t nbSwitchesInPage = 0;
3297 uint16_t currentHeight = 0;
3298 uint16_t previousHeight = 0;
3299 uint16_t navHeight = withNav ? SIMPLE_FOOTER_HEIGHT : 0;
3300 nbgl_contentSwitch_t *switchArray = (nbgl_contentSwitch_t *) PIC(switchesList->switches);
3301
3302 while (nbSwitchesInPage < nbSwitches) {
3303 nbgl_contentSwitch_t *curSwitch = &switchArray[startIndex + nbSwitchesInPage];
3304 // The text string is either a 1 liner and its height is LIST_ITEM_MIN_TEXT_HEIGHT
3305 // or we use its height directly
3306 uint16_t textHeight = MAX(
3307 LIST_ITEM_MIN_TEXT_HEIGHT,
3308 nbgl_getTextHeightInWidth(SMALL_BOLD_FONT, curSwitch->text, AVAILABLE_WIDTH, true));
3309 currentHeight += textHeight + 2 * LIST_ITEM_PRE_HEADING;
3310
3311 if (curSwitch->subText) {
3312 currentHeight += LIST_ITEM_HEADING_SUB_TEXT;
3313
3314 // sub-text height
3315 currentHeight += nbgl_getTextHeightInWidth(
3316 SMALL_REGULAR_FONT, curSwitch->subText, AVAILABLE_WIDTH, true);
3317 }
3318 // if height is over the limit
3319 if (currentHeight >= (INFOS_AREA_HEIGHT - navHeight)) {
3320 break;
3321 }
3322 previousHeight = currentHeight;
3323 nbSwitchesInPage++;
3324 }
3325 // if there was no nav, now there will be, so it can be necessary to remove the last
3326 // item
3327 if (!withNav && (previousHeight >= (INFOS_AREA_HEIGHT - SIMPLE_FOOTER_HEIGHT))) {
3328 nbSwitchesInPage--;
3329 }
3330 return nbSwitchesInPage;
3331}
3332
3342uint8_t nbgl_useCaseGetNbBarsInPage(uint8_t nbBars,
3343 const nbgl_contentBarsList_t *barsList,
3344 uint8_t startIndex,
3345 bool withNav)
3346{
3347 uint8_t nbBarsInPage = 0;
3348 uint16_t currentHeight = 0;
3349 uint16_t previousHeight;
3350 uint16_t navHeight = withNav ? SIMPLE_FOOTER_HEIGHT : 0;
3351
3352 UNUSED(barsList);
3353 UNUSED(startIndex);
3354
3355 while (nbBarsInPage < nbBars) {
3356 currentHeight += LIST_ITEM_MIN_TEXT_HEIGHT + 2 * LIST_ITEM_PRE_HEADING;
3357 // if height is over the limit
3358 if (currentHeight >= (INFOS_AREA_HEIGHT - navHeight)) {
3359 break;
3360 }
3361 previousHeight = currentHeight;
3362 nbBarsInPage++;
3363 }
3364 // if there was no nav, now there may will be, so it can be necessary to remove the last
3365 // item
3366 if (!withNav && (previousHeight >= (INFOS_AREA_HEIGHT - SIMPLE_FOOTER_HEIGHT))) {
3367 nbBarsInPage--;
3368 }
3369 return nbBarsInPage;
3370}
3371
3381uint8_t nbgl_useCaseGetNbChoicesInPage(uint8_t nbChoices,
3382 const nbgl_contentRadioChoice_t *choicesList,
3383 uint8_t startIndex,
3384 bool withNav)
3385{
3386 uint8_t nbChoicesInPage = 0;
3387 uint16_t currentHeight = 0;
3388 uint16_t previousHeight;
3389 uint16_t navHeight = withNav ? SIMPLE_FOOTER_HEIGHT : 0;
3390
3391 UNUSED(choicesList);
3392 UNUSED(startIndex);
3393
3394 while (nbChoicesInPage < nbChoices) {
3395 currentHeight += LIST_ITEM_MIN_TEXT_HEIGHT + 2 * LIST_ITEM_PRE_HEADING;
3396 // if height is over the limit
3397 if (currentHeight >= (INFOS_AREA_HEIGHT - navHeight)) {
3398 // if there was no nav, now there will be, so it can be necessary to remove the last
3399 // item
3400 if (!withNav && (previousHeight >= (INFOS_AREA_HEIGHT - SIMPLE_FOOTER_HEIGHT))) {
3401 nbChoicesInPage--;
3402 }
3403 break;
3404 }
3405 previousHeight = currentHeight;
3406 nbChoicesInPage++;
3407 }
3408 return nbChoicesInPage;
3409}
3410
3418{
3419 uint8_t nbPages = 0;
3420 uint8_t nbPairs = tagValueList->nbPairs;
3421 uint8_t nbPairsInPage;
3422 uint8_t i = 0;
3423 bool flag;
3424
3425 while (i < tagValueList->nbPairs) {
3426 // upper margin
3427 nbPairsInPage = nbgl_useCaseGetNbTagValuesInPageExt(nbPairs, tagValueList, i, false, &flag);
3428 i += nbPairsInPage;
3429 nbPairs -= nbPairsInPage;
3430 nbPages++;
3431 }
3432 return nbPages;
3433}
3434
3439void nbgl_useCaseHome(const char *appName,
3440 const nbgl_icon_details_t *appIcon,
3441 const char *tagline,
3442 bool withSettings,
3443 nbgl_callback_t topRightCallback,
3444 nbgl_callback_t quitCallback)
3445{
3446 nbgl_homeAction_t homeAction = {0};
3447 useCaseHomeExt(
3448 appName, appIcon, tagline, withSettings, &homeAction, topRightCallback, quitCallback);
3449}
3450
3455void nbgl_useCaseHomeExt(const char *appName,
3456 const nbgl_icon_details_t *appIcon,
3457 const char *tagline,
3458 bool withSettings,
3459 const char *actionButtonText,
3460 nbgl_callback_t actionCallback,
3461 nbgl_callback_t topRightCallback,
3462 nbgl_callback_t quitCallback)
3463{
3464 nbgl_homeAction_t homeAction = {.callback = actionCallback,
3465 .icon = NULL,
3466 .style = STRONG_HOME_ACTION,
3467 .text = actionButtonText};
3468
3469 useCaseHomeExt(
3470 appName, appIcon, tagline, withSettings, &homeAction, topRightCallback, quitCallback);
3471}
3472
3486void nbgl_useCaseNavigableContent(const char *title,
3487 uint8_t initPage,
3488 uint8_t nbPages,
3489 nbgl_callback_t quitCallback,
3490 nbgl_navCallback_t navCallback,
3491 nbgl_layoutTouchCallback_t controlsCallback)
3492{
3493 reset_callbacks_and_context();
3494
3495 // memorize context
3496 onQuit = quitCallback;
3497 onNav = navCallback;
3498 onControls = controlsCallback;
3499 pageTitle = title;
3500 navType = SETTINGS_NAV;
3501
3502 // fill navigation structure
3503 prepareNavInfo(false, nbPages, NULL);
3504
3505 displaySettingsPage(initPage, true);
3506}
3507
3513void nbgl_useCaseSettings(const char *title,
3514 uint8_t initPage,
3515 uint8_t nbPages,
3516 bool touchable,
3517 nbgl_callback_t quitCallback,
3518 nbgl_navCallback_t navCallback,
3519 nbgl_layoutTouchCallback_t controlsCallback)
3520{
3521 UNUSED(touchable);
3523 title, initPage, nbPages, quitCallback, navCallback, controlsCallback);
3524}
3525
3538void nbgl_useCaseGenericSettings(const char *appName,
3539 uint8_t initPage,
3540 const nbgl_genericContents_t *settingContents,
3541 const nbgl_contentInfoList_t *infosList,
3542 nbgl_callback_t quitCallback)
3543{
3544 reset_callbacks_and_context();
3545
3546 // memorize context
3547 onQuit = quitCallback;
3548 pageTitle = appName;
3549 navType = GENERIC_NAV;
3550
3551 if (settingContents != NULL) {
3552 memcpy(&genericContext.genericContents, settingContents, sizeof(nbgl_genericContents_t));
3553 }
3554 if (infosList != NULL) {
3555 genericContext.hasFinishingContent = true;
3556 memset(&FINISHING_CONTENT, 0, sizeof(nbgl_content_t));
3557 FINISHING_CONTENT.type = INFOS_LIST;
3558 memcpy(&FINISHING_CONTENT.content, infosList, sizeof(nbgl_content_u));
3559 }
3560
3561 // fill navigation structure
3562 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
3563 if (infosList != NULL) {
3564 nbPages += getNbPagesForContent(&FINISHING_CONTENT, nbPages, true, false);
3565 }
3566
3567 prepareNavInfo(false, nbPages, NULL);
3568
3569 displayGenericContextPage(initPage, true);
3570}
3571
3583void nbgl_useCaseGenericConfiguration(const char *title,
3584 uint8_t initPage,
3585 const nbgl_genericContents_t *contents,
3586 nbgl_callback_t quitCallback)
3587{
3588 nbgl_useCaseGenericSettings(title, initPage, contents, NULL, quitCallback);
3589}
3590
3608 const char *appName,
3609 const nbgl_icon_details_t *appIcon,
3610 const char *tagline,
3611 const uint8_t
3612 initSettingPage, // if not INIT_HOME_PAGE, start directly the corresponding setting page
3613 const nbgl_genericContents_t *settingContents,
3614 const nbgl_contentInfoList_t *infosList,
3615 const nbgl_homeAction_t *action, // Set to NULL if no additional action
3616 nbgl_callback_t quitCallback)
3617{
3618 nbgl_homeAndSettingsContext_t *context = &bundleNavContext.homeAndSettings;
3619
3620 reset_callbacks_and_context();
3621
3622 context->appName = appName;
3623 context->appIcon = appIcon;
3624 context->tagline = tagline;
3625 context->settingContents = settingContents;
3626 context->infosList = infosList;
3627 if (action != NULL) {
3628 memcpy(&context->homeAction, action, sizeof(nbgl_homeAction_t));
3629 }
3630 else {
3631 memset(&context->homeAction, 0, sizeof(nbgl_homeAction_t));
3632 }
3633 context->quitCallback = quitCallback;
3634
3635 if (initSettingPage != INIT_HOME_PAGE) {
3636 bundleNavStartSettingsAtPage(initSettingPage);
3637 }
3638 else {
3639 bundleNavStartHome();
3640 }
3641}
3642
3650void nbgl_useCaseStatus(const char *message, bool isSuccess, nbgl_callback_t quitCallback)
3651{
3652 nbgl_screenTickerConfiguration_t ticker = {.tickerCallback = &tickerCallback,
3653 .tickerIntervale = 0, // not periodic
3654 .tickerValue = STATUS_SCREEN_DURATION};
3655 nbgl_pageInfoDescription_t info = {0};
3656
3657 reset_callbacks_and_context();
3658
3659 onQuit = quitCallback;
3660 if (isSuccess) {
3661#ifdef HAVE_PIEZO_SOUND
3662 os_io_seph_cmd_piezo_play_tune(TUNE_LEDGER_MOMENT);
3663#endif // HAVE_PIEZO_SOUND
3664 }
3665 info.centeredInfo.icon = isSuccess ? &CHECK_CIRCLE_ICON : &DENIED_CIRCLE_ICON;
3666 info.centeredInfo.style = LARGE_CASE_INFO;
3667 info.centeredInfo.text1 = message;
3668 info.tapActionText = "";
3669 info.tapActionToken = QUIT_TOKEN;
3670 info.tuneId = TUNE_TAP_CASUAL;
3671 pageContext = nbgl_pageDrawInfo(&pageCallback, &ticker, &info);
3673}
3674
3682 nbgl_callback_t quitCallback)
3683{
3684 const char *msg;
3685 bool isSuccess;
3686 switch (reviewStatusType) {
3688 msg = "Operation signed";
3689 isSuccess = true;
3690 break;
3692 msg = "Operation rejected";
3693 isSuccess = false;
3694 break;
3696 msg = "Transaction signed";
3697 isSuccess = true;
3698 break;
3700 msg = "Transaction rejected";
3701 isSuccess = false;
3702 break;
3704 msg = "Message signed";
3705 isSuccess = true;
3706 break;
3708 msg = "Message rejected";
3709 isSuccess = false;
3710 break;
3712 msg = "Address verified";
3713 isSuccess = true;
3714 break;
3716 msg = "Address verification\ncancelled";
3717 isSuccess = false;
3718 break;
3719 default:
3720 return;
3721 }
3722 nbgl_useCaseStatus(msg, isSuccess, quitCallback);
3723}
3724
3738 const char *message,
3739 const char *subMessage,
3740 const char *confirmText,
3741 const char *cancelText,
3742 nbgl_choiceCallback_t callback)
3743{
3745 // check params
3746 if ((confirmText == NULL) || (cancelText == NULL)) {
3747 return;
3748 }
3749 reset_callbacks_and_context();
3750
3751 info.cancelText = cancelText;
3752 info.centeredInfo.text1 = message;
3753 info.centeredInfo.text2 = subMessage;
3754 info.centeredInfo.style = LARGE_CASE_INFO;
3755 info.centeredInfo.icon = icon;
3756 info.confirmationText = confirmText;
3757 info.confirmationToken = CHOICE_TOKEN;
3758 info.tuneId = TUNE_TAP_CASUAL;
3759
3760 onChoice = callback;
3761 pageContext = nbgl_pageDrawConfirmation(&pageCallback, &info);
3763}
3764
3780 const char *message,
3781 const char *subMessage,
3782 const char *confirmText,
3783 const char *cancelText,
3784 nbgl_genericDetails_t *details,
3785 nbgl_choiceCallback_t callback)
3786{
3788 (details != NULL) ? &SEARCH_ICON : NULL,
3789 message,
3790 subMessage,
3791 NULL,
3792 confirmText,
3793 cancelText,
3794 details,
3795 callback);
3796}
3797
3821 const nbgl_icon_details_t *headerIcon,
3822 const char *title,
3823 const char *message,
3824 const char *subMessage,
3825 const char *confirmText,
3826 const char *cancelText,
3827 nbgl_warningDetails_t *details,
3828 nbgl_choiceCallback_t callback)
3829{
3830 nbgl_layoutDescription_t layoutDescription;
3831 nbgl_layoutChoiceButtons_t buttonsInfo = {.bottomText = cancelText,
3832 .token = CHOICE_TOKEN,
3833 .topText = confirmText,
3834 .style = ROUNDED_AND_FOOTER_STYLE,
3835 .tuneId = TUNE_TAP_CASUAL};
3836 nbgl_contentCenter_t centeredInfo = {0};
3837 nbgl_layoutHeader_t headerDesc = {.type = HEADER_EMPTY,
3838 .separationLine = false,
3839 .emptySpace.height = MEDIUM_CENTERING_HEADER};
3840
3841 if ((confirmText == NULL) || (cancelText == NULL)) {
3842 return;
3843 }
3844
3845 reset_callbacks_and_context();
3846
3847#ifdef HAVE_PIEZO_SOUND
3848 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
3849#endif // HAVE_PIEZO_SOUND
3850
3851 onChoice = callback;
3852 layoutDescription.modal = false;
3853 layoutDescription.withLeftBorder = true;
3854 layoutDescription.onActionCallback = layoutTouchCallback;
3855 layoutDescription.tapActionText = NULL;
3856 layoutDescription.ticker.tickerCallback = NULL;
3857 sharedContext.usage = SHARE_CTX_CHOICE_WITH_DETAILS;
3858 choiceWithDetailsCtx.layoutCtx = nbgl_layoutGet(&layoutDescription);
3859 choiceWithDetailsCtx.details = details;
3860
3861 nbgl_layoutAddHeader(choiceWithDetailsCtx.layoutCtx, &headerDesc);
3862 nbgl_layoutAddChoiceButtons(choiceWithDetailsCtx.layoutCtx, &buttonsInfo);
3863 centeredInfo.icon = centerIcon;
3864 centeredInfo.title = title;
3865 centeredInfo.description = message;
3866 centeredInfo.subText = subMessage;
3867 nbgl_layoutAddContentCenter(choiceWithDetailsCtx.layoutCtx, &centeredInfo);
3868
3869 if ((details != NULL) && (headerIcon != NULL)) {
3870 nbgl_layoutAddTopRightButton(
3871 choiceWithDetailsCtx.layoutCtx, headerIcon, CHOICE_DETAILS_TOKEN, TUNE_TAP_CASUAL);
3872 }
3873
3874 nbgl_layoutDraw(choiceWithDetailsCtx.layoutCtx);
3876}
3877
3891void nbgl_useCaseConfirm(const char *message,
3892 const char *subMessage,
3893 const char *confirmText,
3894 const char *cancelText,
3895 nbgl_callback_t callback)
3896{
3897 // Don't reset callback or nav context as this is just a modal.
3898
3899 nbgl_pageConfirmationDescription_t info = {.cancelText = cancelText,
3900 .centeredInfo.text1 = message,
3901 .centeredInfo.text2 = subMessage,
3902 .centeredInfo.text3 = NULL,
3903 .centeredInfo.style = LARGE_CASE_INFO,
3904 .centeredInfo.icon = &IMPORTANT_CIRCLE_ICON,
3905 .centeredInfo.offsetY = 0,
3906 .confirmationText = confirmText,
3907 .confirmationToken = CHOICE_TOKEN,
3908 .tuneId = TUNE_TAP_CASUAL,
3909 .modal = true};
3910 onModalConfirm = callback;
3911 if (modalPageContext != NULL) {
3912 nbgl_pageRelease(modalPageContext);
3913 }
3914 modalPageContext = nbgl_pageDrawConfirmation(&pageModalCallback, &info);
3916}
3917
3929 const char *message,
3930 const char *actionText,
3931 nbgl_callback_t callback)
3932{
3933 nbgl_pageContent_t content = {0};
3934
3935 reset_callbacks_and_context();
3936 // memorize callback
3937 onAction = callback;
3938
3939 content.tuneId = TUNE_TAP_CASUAL;
3940 content.type = INFO_BUTTON;
3941 content.infoButton.buttonText = actionText;
3942 content.infoButton.text = message;
3943 content.infoButton.icon = icon;
3944 content.infoButton.buttonToken = ACTION_BUTTON_TOKEN;
3945
3946 pageContext = nbgl_pageDrawGenericContent(&pageCallback, NULL, &content);
3948}
3949
3961void nbgl_useCaseReviewStart(const nbgl_icon_details_t *icon,
3962 const char *reviewTitle,
3963 const char *reviewSubTitle,
3964 const char *rejectText,
3965 nbgl_callback_t continueCallback,
3966 nbgl_callback_t rejectCallback)
3967{
3968 nbgl_pageInfoDescription_t info = {.footerText = rejectText,
3969 .footerToken = QUIT_TOKEN,
3970 .tapActionText = NULL,
3971 .isSwipeable = true,
3972 .tapActionToken = CONTINUE_TOKEN,
3973 .topRightStyle = NO_BUTTON_STYLE,
3974 .actionButtonText = NULL,
3975 .tuneId = TUNE_TAP_CASUAL};
3976
3977 reset_callbacks_and_context();
3978
3979 info.centeredInfo.icon = icon;
3980 info.centeredInfo.text1 = reviewTitle;
3981 info.centeredInfo.text2 = reviewSubTitle;
3982 info.centeredInfo.text3 = "Swipe to review";
3983 info.centeredInfo.style = LARGE_CASE_GRAY_INFO;
3984 info.centeredInfo.offsetY = 0;
3985 onQuit = rejectCallback;
3986 onContinue = continueCallback;
3987
3988#ifdef HAVE_PIEZO_SOUND
3989 // Play notification sound
3990 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
3991#endif // HAVE_PIEZO_SOUND
3992
3993 pageContext = nbgl_pageDrawInfo(&pageCallback, NULL, &info);
3994 nbgl_refresh();
3995}
3996
4001void nbgl_useCaseRegularReview(uint8_t initPage,
4002 uint8_t nbPages,
4003 const char *rejectText,
4004 nbgl_layoutTouchCallback_t buttonCallback,
4005 nbgl_navCallback_t navCallback,
4006 nbgl_choiceCallback_t choiceCallback)
4007{
4008 reset_callbacks_and_context();
4009
4010 // memorize context
4011 onChoice = choiceCallback;
4012 onNav = navCallback;
4013 onControls = buttonCallback;
4014 forwardNavOnly = false;
4015 navType = REVIEW_NAV;
4016
4017 // fill navigation structure
4018 UNUSED(rejectText);
4019 prepareNavInfo(true, nbPages, getRejectReviewText(TYPE_OPERATION));
4020
4021 displayReviewPage(initPage, true);
4022}
4023
4036void nbgl_useCaseStaticReview(const nbgl_contentTagValueList_t *tagValueList,
4037 const nbgl_pageInfoLongPress_t *infoLongPress,
4038 const char *rejectText,
4039 nbgl_choiceCallback_t callback)
4040{
4041 uint8_t offset = 0;
4042
4043 reset_callbacks_and_context();
4044
4045 // memorize context
4046 onChoice = callback;
4047 navType = GENERIC_NAV;
4048 pageTitle = NULL;
4049 bundleNavContext.review.operationType = TYPE_OPERATION;
4050
4051 genericContext.genericContents.contentsList = localContentsList;
4052 memset(localContentsList, 0, 2 * sizeof(nbgl_content_t));
4053
4054 if (tagValueList != NULL && tagValueList->nbPairs != 0) {
4055 localContentsList[offset].type = TAG_VALUE_LIST;
4056 memcpy(&localContentsList[offset].content.tagValueList,
4057 tagValueList,
4059 offset++;
4060 }
4061
4062 localContentsList[offset].type = INFO_LONG_PRESS;
4063 memcpy(&localContentsList[offset].content.infoLongPress,
4064 infoLongPress,
4065 sizeof(nbgl_pageInfoLongPress_t));
4066 localContentsList[offset].content.infoLongPress.longPressToken = CONFIRM_TOKEN;
4067 offset++;
4068
4069 genericContext.genericContents.nbContents = offset;
4070
4071 // compute number of pages & fill navigation structure
4072 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
4073 UNUSED(rejectText);
4074 prepareNavInfo(true, nbPages, getRejectReviewText(TYPE_OPERATION));
4075
4076 displayGenericContextPage(0, true);
4077}
4078
4092void nbgl_useCaseStaticReviewLight(const nbgl_contentTagValueList_t *tagValueList,
4093 const nbgl_pageInfoLongPress_t *infoLongPress,
4094 const char *rejectText,
4095 nbgl_choiceCallback_t callback)
4096{
4097 uint8_t offset = 0;
4098
4099 reset_callbacks_and_context();
4100
4101 // memorize context
4102 onChoice = callback;
4103 navType = GENERIC_NAV;
4104 pageTitle = NULL;
4105
4106 genericContext.genericContents.contentsList = localContentsList;
4107 memset(localContentsList, 0, 2 * sizeof(nbgl_content_t));
4108
4109 if (tagValueList != NULL && tagValueList->nbPairs != 0) {
4110 localContentsList[offset].type = TAG_VALUE_LIST;
4111 memcpy(&localContentsList[offset].content.tagValueList,
4112 tagValueList,
4114 offset++;
4115 }
4116
4117 localContentsList[offset].type = INFO_BUTTON;
4118 localContentsList[offset].content.infoButton.text = infoLongPress->text;
4119 localContentsList[offset].content.infoButton.icon = infoLongPress->icon;
4120 localContentsList[offset].content.infoButton.buttonText = infoLongPress->longPressText;
4121 localContentsList[offset].content.infoButton.buttonToken = CONFIRM_TOKEN;
4122 localContentsList[offset].content.infoButton.tuneId = TUNE_TAP_CASUAL;
4123 offset++;
4124
4125 genericContext.genericContents.nbContents = offset;
4126
4127 // compute number of pages & fill navigation structure
4128 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
4129 UNUSED(rejectText);
4130 prepareNavInfo(true, nbPages, getRejectReviewText(TYPE_OPERATION));
4131
4132 displayGenericContextPage(0, true);
4133}
4134
4151void nbgl_useCaseReview(nbgl_operationType_t operationType,
4152 const nbgl_contentTagValueList_t *tagValueList,
4153 const nbgl_icon_details_t *icon,
4154 const char *reviewTitle,
4155 const char *reviewSubTitle,
4156 const char *finishTitle,
4157 nbgl_choiceCallback_t choiceCallback)
4158{
4159 reset_callbacks_and_context();
4160
4161 useCaseReview(operationType,
4162 tagValueList,
4163 icon,
4164 reviewTitle,
4165 reviewSubTitle,
4166 finishTitle,
4167 NULL,
4168 choiceCallback,
4169 false,
4170 true);
4171}
4172
4193 const nbgl_contentTagValueList_t *tagValueList,
4194 const nbgl_icon_details_t *icon,
4195 const char *reviewTitle,
4196 const char *reviewSubTitle,
4197 const char *finishTitle,
4198 const nbgl_tipBox_t *tipBox,
4199 nbgl_choiceCallback_t choiceCallback)
4200{
4201 nbgl_useCaseAdvancedReview(operationType,
4202 tagValueList,
4203 icon,
4204 reviewTitle,
4205 reviewSubTitle,
4206 finishTitle,
4207 tipBox,
4208 &blindSigningWarning,
4209 choiceCallback);
4210}
4211
4235 const nbgl_contentTagValueList_t *tagValueList,
4236 const nbgl_icon_details_t *icon,
4237 const char *reviewTitle,
4238 const char *reviewSubTitle,
4239 const char *finishTitle,
4240 const nbgl_tipBox_t *tipBox,
4241 const nbgl_warning_t *warning,
4242 nbgl_choiceCallback_t choiceCallback)
4243{
4244 reset_callbacks_and_context();
4245
4246 // memorize tipBox because it can be in the call stack of the caller
4247 if (tipBox != NULL) {
4248 memcpy(&activeTipBox, tipBox, sizeof(activeTipBox));
4249 }
4250 // if no warning at all, it's a simple review
4251 if ((warning == NULL)
4252 || ((warning->predefinedSet == 0) && (warning->introDetails == NULL)
4253 && (warning->reviewDetails == NULL) && (warning->prelude == NULL))) {
4254 useCaseReview(operationType,
4255 tagValueList,
4256 icon,
4257 reviewTitle,
4258 reviewSubTitle,
4259 finishTitle,
4260 tipBox,
4261 choiceCallback,
4262 false,
4263 true);
4264 return;
4265 }
4266 if (warning->predefinedSet == (1 << W3C_NO_THREAT_WARN)) {
4267 operationType |= NO_THREAT_OPERATION;
4268 }
4269 else if (warning->predefinedSet != 0) {
4270 operationType |= RISKY_OPERATION;
4271 }
4272 sharedContext.usage = SHARE_CTX_REVIEW_WITH_WARNING;
4273 reviewWithWarnCtx.isStreaming = false;
4274 reviewWithWarnCtx.operationType = operationType;
4275 reviewWithWarnCtx.tagValueList = tagValueList;
4276 reviewWithWarnCtx.icon = icon;
4277 reviewWithWarnCtx.reviewTitle = reviewTitle;
4278 reviewWithWarnCtx.reviewSubTitle = reviewSubTitle;
4279 reviewWithWarnCtx.finishTitle = finishTitle;
4280 reviewWithWarnCtx.warning = warning;
4281 reviewWithWarnCtx.choiceCallback = choiceCallback;
4282
4283 // if the warning contains a prelude, display it first
4284 if (reviewWithWarnCtx.warning->prelude) {
4285 displayPrelude();
4286 }
4287 // display the initial warning only of a risk/threat or blind signing or prelude
4288 else if (HAS_INITIAL_WARNING(warning)) {
4289 displayInitialWarning();
4290 }
4291 else {
4292 useCaseReview(operationType,
4293 tagValueList,
4294 icon,
4295 reviewTitle,
4296 reviewSubTitle,
4297 finishTitle,
4298 tipBox,
4299 choiceCallback,
4300 false,
4301 true);
4302 }
4303}
4304
4322 const nbgl_contentTagValueList_t *tagValueList,
4323 const nbgl_icon_details_t *icon,
4324 const char *reviewTitle,
4325 const char *reviewSubTitle,
4326 const char *finishTitle,
4327 nbgl_choiceCallback_t choiceCallback)
4328{
4329 reset_callbacks_and_context();
4330
4331 useCaseReview(operationType,
4332 tagValueList,
4333 icon,
4334 reviewTitle,
4335 reviewSubTitle,
4336 finishTitle,
4337 NULL,
4338 choiceCallback,
4339 true,
4340 true);
4341}
4342
4352 const char *rejectText,
4353 nbgl_callback_t rejectCallback)
4354{
4355 reset_callbacks_and_context();
4356
4357 // memorize context
4358 onQuit = rejectCallback;
4359 navType = GENERIC_NAV;
4360 pageTitle = NULL;
4361 bundleNavContext.review.operationType = TYPE_OPERATION;
4362
4363 memcpy(&genericContext.genericContents, contents, sizeof(nbgl_genericContents_t));
4364
4365 // compute number of pages & fill navigation structure
4366 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
4367 prepareNavInfo(true, nbPages, rejectText);
4368 navInfo.quitToken = QUIT_TOKEN;
4369
4370#ifdef HAVE_PIEZO_SOUND
4371 // Play notification sound
4372 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
4373#endif // HAVE_PIEZO_SOUND
4374
4375 displayGenericContextPage(0, true);
4376}
4377
4391 const nbgl_icon_details_t *icon,
4392 const char *reviewTitle,
4393 const char *reviewSubTitle,
4394 nbgl_choiceCallback_t choiceCallback)
4395{
4396 reset_callbacks_and_context();
4397
4398 useCaseReviewStreamingStart(
4399 operationType, icon, reviewTitle, reviewSubTitle, choiceCallback, true);
4400}
4401
4416 const nbgl_icon_details_t *icon,
4417 const char *reviewTitle,
4418 const char *reviewSubTitle,
4419 nbgl_choiceCallback_t choiceCallback)
4420{
4422 operationType, icon, reviewTitle, reviewSubTitle, &blindSigningWarning, choiceCallback);
4423}
4424
4441 const nbgl_icon_details_t *icon,
4442 const char *reviewTitle,
4443 const char *reviewSubTitle,
4444 const nbgl_warning_t *warning,
4445 nbgl_choiceCallback_t choiceCallback)
4446{
4447 reset_callbacks_and_context();
4448
4449 // if no warning at all, it's a simple review
4450 if ((warning == NULL)
4451 || ((warning->predefinedSet == 0) && (warning->introDetails == NULL)
4452 && (warning->reviewDetails == NULL) && (warning->prelude == NULL))) {
4453 useCaseReviewStreamingStart(
4454 operationType, icon, reviewTitle, reviewSubTitle, choiceCallback, true);
4455 return;
4456 }
4457 if (warning->predefinedSet == (1 << W3C_NO_THREAT_WARN)) {
4458 operationType |= NO_THREAT_OPERATION;
4459 }
4460 else if (warning->predefinedSet != 0) {
4461 operationType |= RISKY_OPERATION;
4462 }
4463
4464 sharedContext.usage = SHARE_CTX_REVIEW_WITH_WARNING;
4465 reviewWithWarnCtx.isStreaming = true;
4466 reviewWithWarnCtx.operationType = operationType;
4467 reviewWithWarnCtx.icon = icon;
4468 reviewWithWarnCtx.reviewTitle = reviewTitle;
4469 reviewWithWarnCtx.reviewSubTitle = reviewSubTitle;
4470 reviewWithWarnCtx.choiceCallback = choiceCallback;
4471 reviewWithWarnCtx.warning = warning;
4472
4473 // if the warning contains a prelude, display it first
4474 if (reviewWithWarnCtx.warning->prelude) {
4475 displayPrelude();
4476 }
4477 // display the initial warning only of a risk/threat or blind signing
4478 else if (HAS_INITIAL_WARNING(warning)) {
4479 displayInitialWarning();
4480 }
4481 else {
4482 useCaseReviewStreamingStart(
4483 operationType, icon, reviewTitle, reviewSubTitle, choiceCallback, true);
4484 }
4485}
4486
4501 nbgl_choiceCallback_t choiceCallback,
4502 nbgl_callback_t skipCallback)
4503{
4504 // Should follow a call to nbgl_useCaseReviewStreamingStart
4505 memset(&genericContext, 0, sizeof(genericContext));
4506
4507 bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
4508 bundleNavContext.reviewStreaming.skipCallback = skipCallback;
4509
4510 // memorize context
4511 onChoice = bundleNavReviewStreamingChoice;
4512 navType = STREAMING_NAV;
4513 pageTitle = NULL;
4514
4515 genericContext.genericContents.contentsList = localContentsList;
4516 genericContext.genericContents.nbContents = 1;
4517 memset(localContentsList, 0, 1 * sizeof(nbgl_content_t));
4518
4519 // Then the tag/value pairs
4520 STARTING_CONTENT.type = TAG_VALUE_LIST;
4521 memcpy(
4522 &STARTING_CONTENT.content.tagValueList, tagValueList, sizeof(nbgl_contentTagValueList_t));
4523
4524 // compute number of pages & fill navigation structure
4525 bundleNavContext.reviewStreaming.stepPageNb = getNbPagesForGenericContents(
4526 &genericContext.genericContents,
4527 0,
4528 (bundleNavContext.reviewStreaming.operationType & SKIPPABLE_OPERATION));
4529 prepareNavInfo(true,
4531 getRejectReviewText(bundleNavContext.reviewStreaming.operationType));
4532 // if the operation is skippable
4533 if (bundleNavContext.reviewStreaming.operationType & SKIPPABLE_OPERATION) {
4534 navInfo.progressIndicator = false;
4535 navInfo.skipText = "Skip";
4536 navInfo.skipToken = SKIP_TOKEN;
4537 }
4538
4539 displayGenericContextPage(0, true);
4540}
4541
4553 nbgl_choiceCallback_t choiceCallback)
4554{
4555 nbgl_useCaseReviewStreamingContinueExt(tagValueList, choiceCallback, NULL);
4556}
4557
4566void nbgl_useCaseReviewStreamingFinish(const char *finishTitle,
4567 nbgl_choiceCallback_t choiceCallback)
4568{
4569 // Should follow a call to nbgl_useCaseReviewStreamingContinue
4570 memset(&genericContext, 0, sizeof(genericContext));
4571
4572 bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
4573
4574 // memorize context
4575 onChoice = bundleNavReviewStreamingChoice;
4576 navType = STREAMING_NAV;
4577 pageTitle = NULL;
4578
4579 genericContext.genericContents.contentsList = localContentsList;
4580 genericContext.genericContents.nbContents = 1;
4581 memset(localContentsList, 0, 1 * sizeof(nbgl_content_t));
4582
4583 // Eventually the long press page
4584 STARTING_CONTENT.type = INFO_LONG_PRESS;
4585 prepareReviewLastPage(bundleNavContext.reviewStreaming.operationType,
4586 &STARTING_CONTENT.content.infoLongPress,
4587 bundleNavContext.reviewStreaming.icon,
4588 finishTitle);
4589
4590 // compute number of pages & fill navigation structure
4591 bundleNavContext.reviewStreaming.stepPageNb = getNbPagesForGenericContents(
4592 &genericContext.genericContents,
4593 0,
4594 (bundleNavContext.reviewStreaming.operationType & SKIPPABLE_OPERATION));
4595 prepareNavInfo(true, 1, getRejectReviewText(bundleNavContext.reviewStreaming.operationType));
4596
4597 displayGenericContextPage(0, true);
4598}
4599
4604void nbgl_useCaseAddressConfirmationExt(const char *address,
4605 nbgl_choiceCallback_t callback,
4606 const nbgl_contentTagValueList_t *tagValueList)
4607{
4608 reset_callbacks_and_context();
4609 memset(&addressConfirmationContext, 0, sizeof(addressConfirmationContext));
4610
4611 // save context
4612 onChoice = callback;
4613 navType = GENERIC_NAV;
4614 pageTitle = NULL;
4615
4616 genericContext.genericContents.contentsList = localContentsList;
4617 genericContext.genericContents.nbContents = (tagValueList == NULL) ? 1 : 2;
4618 memset(localContentsList, 0, 2 * sizeof(nbgl_content_t));
4619 prepareAddressConfirmationPages(
4620 address, tagValueList, &STARTING_CONTENT, &localContentsList[1]);
4621
4622 // fill navigation structure, common to all pages
4623 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
4624
4625 prepareNavInfo(true, nbPages, "Cancel");
4626
4627#ifdef HAVE_PIEZO_SOUND
4628 // Play notification sound
4629 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
4630#endif // HAVE_PIEZO_SOUND
4631
4632 displayGenericContextPage(0, true);
4633}
4634
4651void nbgl_useCaseAddressReview(const char *address,
4652 const nbgl_contentTagValueList_t *additionalTagValueList,
4653 const nbgl_icon_details_t *icon,
4654 const char *reviewTitle,
4655 const char *reviewSubTitle,
4656 nbgl_choiceCallback_t choiceCallback)
4657{
4658 reset_callbacks_and_context();
4659
4660 // release a potential modal
4661 if (addressConfirmationContext.modalLayout) {
4662 nbgl_layoutRelease(addressConfirmationContext.modalLayout);
4663 }
4664 memset(&addressConfirmationContext, 0, sizeof(addressConfirmationContext));
4665
4666 // save context
4667 onChoice = choiceCallback;
4668 navType = GENERIC_NAV;
4669 pageTitle = NULL;
4670 bundleNavContext.review.operationType = TYPE_OPERATION;
4671
4672 genericContext.genericContents.contentsList = localContentsList;
4673 memset(localContentsList, 0, 3 * sizeof(nbgl_content_t));
4674
4675 // First a centered info
4676 STARTING_CONTENT.type = EXTENDED_CENTER;
4677 prepareReviewFirstPage(
4678 &STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
4679 STARTING_CONTENT.content.extendedCenter.contentCenter.subText = "Swipe to continue";
4680
4681 // Then the address confirmation pages
4682 prepareAddressConfirmationPages(
4683 address, additionalTagValueList, &localContentsList[1], &localContentsList[2]);
4684
4685 // fill navigation structure, common to all pages
4686 genericContext.genericContents.nbContents
4687 = (localContentsList[2].type == TAG_VALUE_CONFIRM) ? 3 : 2;
4688 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
4689
4690 prepareNavInfo(true, nbPages, "Cancel");
4691
4692#ifdef HAVE_PIEZO_SOUND
4693 // Play notification sound
4694 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
4695#endif // HAVE_PIEZO_SOUND
4696
4697 displayGenericContextPage(0, true);
4698}
4699
4708void nbgl_useCaseSpinner(const char *text)
4709{
4710 // if the previous Use Case was not Spinner, fresh start
4711 if (genericContext.type != USE_CASE_SPINNER) {
4712 memset(&genericContext, 0, sizeof(genericContext));
4713 genericContext.type = USE_CASE_SPINNER;
4714 nbgl_layoutDescription_t layoutDescription = {0};
4715
4716 layoutDescription.withLeftBorder = true;
4717
4718 genericContext.backgroundLayout = nbgl_layoutGet(&layoutDescription);
4719
4720 nbgl_layoutAddSpinner(
4721 genericContext.backgroundLayout, text, NULL, genericContext.spinnerPosition);
4722
4723 nbgl_layoutDraw(genericContext.backgroundLayout);
4725 }
4726 else {
4727 // otherwise increment spinner
4728 genericContext.spinnerPosition++;
4729 // there are only NB_SPINNER_POSITIONSpositions
4730 if (genericContext.spinnerPosition == NB_SPINNER_POSITIONS) {
4731 genericContext.spinnerPosition = 0;
4732 }
4733 int ret = nbgl_layoutUpdateSpinner(
4734 genericContext.backgroundLayout, text, NULL, genericContext.spinnerPosition);
4735 if (ret == 1) {
4737 }
4738 else if (ret == 2) {
4740 }
4741 }
4742}
4743
4744#ifdef NBGL_KEYPAD
4763void nbgl_useCaseKeypad(const char *title,
4764 uint8_t minDigits,
4765 uint8_t maxDigits,
4766 bool shuffled,
4767 bool hidden,
4768 nbgl_pinValidCallback_t validatePinCallback,
4769 nbgl_callback_t backCallback)
4770{
4771 nbgl_layoutDescription_t layoutDescription = {0};
4772 nbgl_layoutHeader_t headerDesc = {.type = HEADER_BACK_AND_TEXT,
4773 .separationLine = true,
4774 .backAndText.token = BACK_TOKEN,
4775 .backAndText.tuneId = TUNE_TAP_CASUAL};
4776 int status = -1;
4777
4778 if ((minDigits > KEYPAD_MAX_DIGITS) || (maxDigits > KEYPAD_MAX_DIGITS)) {
4779 return;
4780 }
4781
4782 reset_callbacks_and_context();
4783 // reset the keypad context
4784 memset(&keypadContext, 0, sizeof(KeypadContext_t));
4785
4786 // memorize context
4787 onQuit = backCallback;
4788
4789 // get a layout
4790 layoutDescription.onActionCallback = keypadGeneric_cb;
4791 layoutDescription.modal = false;
4792 layoutDescription.withLeftBorder = false;
4793 keypadContext.layoutCtx = nbgl_layoutGet(&layoutDescription);
4794 keypadContext.hidden = hidden;
4795
4796 // set back key in header
4797 nbgl_layoutAddHeader(keypadContext.layoutCtx, &headerDesc);
4798
4799 // add keypad
4800 status = nbgl_layoutAddKeypad(keypadContext.layoutCtx, keypadCallback, shuffled);
4801 if (status < 0) {
4802 return;
4803 }
4804 // add keypad content
4806 keypadContext.layoutCtx, title, keypadContext.hidden, maxDigits, "");
4807 if (status < 0) {
4808 return;
4809 }
4810
4811 // validation pin callback
4812 keypadContext.onValidatePin = validatePinCallback;
4813 // pin code acceptable lengths
4814 keypadContext.pinMinDigits = minDigits;
4815 keypadContext.pinMaxDigits = maxDigits;
4816
4817 nbgl_layoutDraw(keypadContext.layoutCtx);
4819}
4820#endif // NBGL_KEYPAD
4821
4822#ifdef NBGL_KEYBOARD
4849void nbgl_useCaseKeyboard(const nbgl_keyboardParams_t *params, nbgl_callback_t backCallback)
4850{
4851 // clang-format off
4852 nbgl_layoutDescription_t layoutDescription = {.onActionCallback = keyboardGeneric_cb};
4853 nbgl_layoutHeader_t headerDesc = {.type = HEADER_BACK_AND_TEXT,
4854 .backAndText.token = BACK_TOKEN,
4855 .backAndText.tuneId = TUNE_TAP_CASUAL};
4856 nbgl_layoutKbd_t kbdInfo = {.callback = &keyboardCallback,
4857 .lettersOnly = params->lettersOnly,
4858 .mode = params->mode,
4859 .casing = params->casing};
4860 int status = -1;
4861 // clang-format on
4862
4863 reset_callbacks_and_context();
4864 // reset the keyboard context
4865 memset(&keyboardContext, 0, sizeof(KeyboardContext_t));
4866
4867 // memorize context
4868 onQuit = backCallback;
4869
4870 // get a layout
4871 keyboardContext.layoutCtx = nbgl_layoutGet(&layoutDescription);
4872
4873 // set back key in header
4874 nbgl_layoutAddHeader(keyboardContext.layoutCtx, &headerDesc);
4875
4876 // Add keyboard
4877 status = nbgl_layoutAddKeyboard(keyboardContext.layoutCtx, &kbdInfo);
4878 if (status < 0) {
4879 return;
4880 }
4881 keyboardContext.keyboardIndex = status;
4882 keyboardContext.casing = params->casing;
4883 keyboardContext.entryBuffer = PIC(params->entryBuffer);
4884 keyboardContext.entryMaxLen = params->entryMaxLen;
4885 keyboardContext.entryBuffer[0] = '\0';
4886 // add keyboard content
4887 keyboardContext.keyboardContent = (nbgl_layoutKeyboardContent_t){
4888 .type = params->type,
4889 .title = PIC(params->title),
4890 .numbered = params->numbered,
4891 .number = params->number,
4892 .text = keyboardContext.entryBuffer,
4893 .textToken = KEYBOARD_CROSS_TOKEN,
4894 .tuneId = TUNE_TAP_CASUAL,
4895 };
4896 switch (params->type) {
4898 onAction = PIC(params->confirmationParams.onButtonCallback);
4899 keyboardContext.keyboardContent.confirmationButton = (nbgl_layoutConfirmationButton_t){
4900 .text = PIC(params->confirmationParams.buttonText),
4901 .token = KEYBOARD_BUTTON_TOKEN,
4902 .active = true,
4903 };
4904 break;
4906 onControls = PIC(params->suggestionParams.onButtonCallback);
4907 keyboardContext.getSuggestionButtons
4909 keyboardContext.keyboardContent.suggestionButtons = (nbgl_layoutSuggestionButtons_t){
4910 .buttons = PIC(params->suggestionParams.buttons),
4911 .firstButtonToken = params->suggestionParams.firstButtonToken,
4912 };
4913 break;
4914 default:
4915 return;
4916 }
4917 status = nbgl_layoutAddKeyboardContent(keyboardContext.layoutCtx,
4918 &keyboardContext.keyboardContent);
4919 if (status < 0) {
4920 return;
4921 }
4922
4923 nbgl_layoutDraw(keyboardContext.layoutCtx);
4925}
4926#endif // NBGL_KEYBOARD
4927
4928#endif // HAVE_SE_TOUCH
4929#endif // NBGL_USE_CASE
nbgl_contentTagValue_t *(* nbgl_contentTagValueCallback_t)(uint8_t pairIndex)
prototype of tag/value pair retrieval callback
@ ICON_ILLUSTRATION
simple icon
@ INFO_LONG_PRESS
a centered info and a long press button
@ EXTENDED_CENTER
a centered content and a possible tip-box
@ CHOICES_LIST
list of choices through radio buttons
@ CENTERED_INFO
a centered info
@ SWITCHES_LIST
list of switches with descriptions
@ TAG_VALUE_DETAILS
a tag/value pair and a small button to get details.
@ 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
@ QR_CODE_ALIAS
alias is an address to be displayed as a QR Code
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
debug traces management
#define LOG_DEBUG(__logger,...)
Definition nbgl_debug.h:86
@ USE_CASE_LOGGER
Definition nbgl_debug.h:35
uint8_t nbgl_getTextNbPagesInWidth(nbgl_font_id_e fontId, const char *text, uint8_t nbLinesPerPage, uint16_t maxWidth)
bool nbgl_getTextMaxLenInNbLines(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, uint16_t maxNbLines, uint16_t *len, bool wrapping)
nbgl_font_id_e
Definition nbgl_fonts.h:141
void nbgl_textReduceOnNbLines(nbgl_font_id_e fontId, const char *origText, uint16_t maxWidth, uint8_t nbLines, char *reducedText, uint16_t reducedTextLen)
uint16_t nbgl_getTextHeightInWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, bool wrapping)
uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, bool wrapping)
uint8_t nbgl_getFontLineHeight(nbgl_font_id_e fontId)
void(* nbgl_layoutTouchCallback_t)(int token, uint8_t index)
prototype of function to be called when an object is touched
int nbgl_layoutAddContentCenter(nbgl_layout_t *layout, const nbgl_contentCenter_t *info)
int nbgl_layoutAddKeyboard(nbgl_layout_t *layout, const nbgl_layoutKbd_t *kbdInfo)
Creates a keyboard on bottom of the screen, with the given configuration.
int nbgl_layoutUpdateKeyboard(nbgl_layout_t *layout, uint8_t index, uint32_t keyMask)
Updates an existing keyboard on bottom of the screen, with the given configuration.
int nbgl_layoutUpdateKeypad(nbgl_layout_t *layout, uint8_t index, bool enableValidate, bool enableBackspace)
Updates an existing keypad on bottom of the screen, with the given configuration.
int nbgl_layoutAddKeypadContent(nbgl_layout_t *layout, 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_layoutDraw(nbgl_layout_t *layout)
Applies given layout. The screen will be redrawn.
@ WHITE_BACKGROUND
rounded bordered button, with text/icon in black, on white background
#define AVAILABLE_WIDTH
void * nbgl_layout_t
type shared externally
#define NBGL_INVALID_TOKEN
Definition nbgl_layout.h:30
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
#define NBGL_NO_PROGRESS_INDICATOR
To be used when a control token shall not be used.
Definition nbgl_layout.h:27
int nbgl_layoutAddKeypad(nbgl_layout_t *layout, keyboardCallback_t callback, const char *text, bool shuffled)
Adds a keypad on bottom of the screen, with the associated callback.
@ KEYBOARD_WITH_BUTTON
text entry area + confirmation button
@ KEYBOARD_WITH_SUGGESTIONS
text entry area + suggestion buttons
int nbgl_layoutRelease(nbgl_layout_t *layout)
Release the layout obtained with nbgl_layoutGet()
void nbgl_refresh(void)
keyboardCase_t
Letters casing in which to open/set the keyboard.
Definition nbgl_obj.h:620
#define KEYPAD_MAX_DIGITS
Definition nbgl_obj.h:72
void nbgl_refreshSpecial(nbgl_refresh_mode_t mode)
#define WARNING_ICON
Definition nbgl_obj.h:273
#define BACKSPACE_KEY
Definition nbgl_obj.h:26
void nbgl_refreshSpecialWithPostRefresh(nbgl_refresh_mode_t mode, nbgl_post_refresh_t post_refresh)
#define VALIDATE_KEY
Definition nbgl_obj.h:27
nbgl_page_t * nbgl_pageDrawGenericContent(nbgl_layoutTouchCallback_t onActionCallback, const nbgl_pageNavigationInfo_t *nav, nbgl_pageContent_t *content)
nbgl_page_t * nbgl_pageDrawInfo(nbgl_layoutTouchCallback_t onActionCallback, const nbgl_screenTickerConfiguration_t *ticker, const nbgl_pageInfoDescription_t *info)
void * nbgl_page_t
type shared externally
Definition nbgl_page.h:81
@ NAV_WITH_BUTTONS
move forward and backward with buttons in bottom nav bar
Definition nbgl_page.h:89
nbgl_page_t * nbgl_pageDrawConfirmation(nbgl_layoutTouchCallback_t onActionCallback, const nbgl_pageConfirmationDescription_t *info)
int nbgl_pageRelease(nbgl_page_t *)
nbgl_page_t * nbgl_pageDrawGenericContentExt(nbgl_layoutTouchCallback_t onActionCallback, const nbgl_pageNavigationInfo_t *nav, nbgl_pageContent_t *content, bool modal)
@ QUIT_APP_TEXT
A full width button with "Quit app" text (only for bottom button)
Definition nbgl_page.h:40
@ INFO_ICON
info (i) icon in the button.
Definition nbgl_page.h:39
@ NO_BUTTON_STYLE
no button.
Definition nbgl_page.h:36
@ SETTINGS_ICON
settings (wheel) icon in the button.
Definition nbgl_page.h:37
struct PACKED__ nbgl_screenTickerConfiguration_s nbgl_screenTickerConfiguration_t
struct to configure a screen layer
void nbgl_screenRedraw(void)
@ POST_REFRESH_FORCE_POWER_ON
Force screen power on after refresh.
Definition nbgl_types.h:353
#define MIN(x, y)
Definition nbgl_types.h:118
struct PACKED__ nbgl_icon_details_s nbgl_icon_details_t
Represents all information about an icon.
#define MAX(x, y)
Definition nbgl_types.h:121
nbgl_refresh_mode_t
different modes of refresh for nbgl_refreshSpecial()
Definition nbgl_types.h:325
@ BLACK_AND_WHITE_REFRESH
to be used for pure B&W area, when contrast is important
Definition nbgl_types.h:329
@ FULL_COLOR_CLEAN_REFRESH
to be used for lock screen display (cleaner but longer refresh)
Definition nbgl_types.h:328
@ BLACK_AND_WHITE_FAST_REFRESH
to be used for pure B&W area, when contrast is not priority
Definition nbgl_types.h:330
@ FULL_COLOR_PARTIAL_REFRESH
to be used for small partial refresh (radio buttons, switches)
Definition nbgl_types.h:327
@ FULL_COLOR_REFRESH
to be used for normal refresh
Definition nbgl_types.h:326
API of the Advanced BOLOS Graphical Library, for typical application use-cases.
#define NB_MAX_LINES_IN_REVIEW
maximum number of lines for value field in review pages
@ NO_TYPE_WARNING
Invalid type (to use for bars leading to nothing)
@ CENTERED_INFO_WARNING
Centered info.
@ QRCODE_WARNING
QR Code.
@ BAR_LIST_WARNING
list of touchable bars, to display sub-pages
uint8_t nbgl_useCaseGetNbTagValuesInPageExt(uint8_t nbPairs, const nbgl_contentTagValueList_t *tagValueList, uint8_t startIndex, bool isSkippable, bool *requireSpecificDisplay)
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.
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)
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)
uint8_t nbgl_useCaseGetNbPagesForTagValueList(const nbgl_contentTagValueList_t *tagValueList)
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....
uint8_t nbgl_useCaseGetNbInfosInPage(uint8_t nbInfos, const nbgl_contentInfoList_t *infosList, uint8_t startIndex, bool withNav)
void(* nbgl_choiceCallback_t)(bool confirm)
prototype of choice callback function
uint8_t nbgl_useCaseGetNbBarsInPage(uint8_t nbBars, const nbgl_contentBarsList_t *barsList, uint8_t startIndex, bool withNav)
void nbgl_useCaseNavigableContent(const char *title, uint8_t initPage, uint8_t nbPages, nbgl_callback_t quitCallback, nbgl_navCallback_t navCallback, nbgl_layoutTouchCallback_t controlsCallback)
#define INFOS_AREA_HEIGHT
height available for infos pairs display
@ STRONG_HOME_ACTION
Black button, implicating the main action of the App.
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)
#define NB_MAX_LINES_IN_DETAILS
maximum number of lines for value field in details pages
#define APP_DESCRIPTION_MAX_LEN
Length of buffer used for the default Home tagline.
void nbgl_useCaseStatus(const char *message, bool isSuccess, nbgl_callback_t quitCallback)
@ W3C_THREAT_DETECTED_WARN
Web3 Checks: Threat detected (see reportRisk field)
@ W3C_ISSUE_WARN
Web3 Checks issue (not available)
@ 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)
@ NB_WARNING_TYPES
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)
#define FIRST_USER_TOKEN
when using controls in page content (nbgl_pageContent_t), this is the first token value usable for th...
#define TAG_VALUE_AREA_HEIGHT
height available for tag/value pairs display
#define BLIND_OPERATION
This is to use in nbgl_operationType_t when the operation is "blind" This is used to indicate a warni...
#define TAGLINE_PART1
Default strings used in the Home tagline.
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)
#define TAGLINE_PART2
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 LAST_PAGE_FOR_REVIEW
value of page parameter used with navigation callback when "skip" button is touched,...
#define ADDRESS_BOOK_OPERATION
This is to use in nbgl_operationType_t when the operation is related to "Address Book" to adapt wordi...
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 MAX_APP_NAME_FOR_SDK_TAGLINE
Max supported length of appName used for the default Home tagline.
#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.
@ TYPE_OPERATION
For other types of operation (generic type)
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)
uint8_t nbgl_useCaseGetNbSwitchesInPage(uint8_t nbSwitches, const nbgl_contentSwitchesList_t *switchesList, uint8_t startIndex, bool withNav)
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)
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played when a bar is touched
uint8_t nbBars
number of elements in barTexts and tokens array
This structure contains info to build a centered (vertically and horizontally) area,...
uint16_t iconHug
vertical margin to apply on top and bottom of the icon
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 * subText
sub-text in dark gray regular small case
bool padding
if true, apply a padding of 40px at the bottom
const char * smallTitle
sub-title in black small bold case (can be null)
nbgl_contentIllustrationType_t illustrType
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
nbgl_contentCenter_t contentCenter
centered content (icon + text(s))
This structure contains data to build a centered info + simple black button content.
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
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played when button is touched
This structure contains data to build a INFOS_LIST content.
const char *const * infoContents
array of contents of infos (in black)
const char *const * infoTypes
array of types of infos (in black/bold)
const nbgl_contentValueExt_t * infoExtensions
uint8_t nbInfos
number of elements in infoTypes and infoContents array
This structure contains data to build a centered info + long press button content.
const char * longPressText
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
This structure contains a list of names to build a list of radio buttons (on the right part of screen...
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
const char * subText
description under main text (NULL terminated, single line, may be null)
This structure contains [item,value] pair(s) and info about a potential "details" button,...
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played when details button is touched
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 char * detailsButtonText
this text is used for "details" button (if NULL, no button)
const nbgl_icon_details_t * detailsButtonIcon
icon to use in details button
const nbgl_icon_details_t * detailsButtonIcon
icon to use in details button
const char * detailsButtonText
this text is used for "details" button
nbgl_contentTagValueList_t tagValueList
list of tag/value pairs
This structure contains a 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
uint8_t nbMaxLinesForValue
if > 0, set the max number of lines for value field.
bool hideEndOfLastLine
if set to true, replace 3 last chars of last line by "..."
bool wrapping
if set to true, value text will be wrapped on ' ' to avoid cutting words
uint8_t startIndex
index of the first pair to get with callback
nbgl_contentActionCallback_t actionCallback
called when a valueIcon is touched on 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
int8_t centeredInfo
if set to 1, the tag will be displayed as a centered info
const char * value
string giving the value name
const char * item
string giving the tag name
This structure contains additions to a tag/value pair, to be able to build a screen to display these ...
const char * fullValue
full string of the value when used as an alias
nbgl_contentValueAliasType_t aliasType
type of alias
const struct nbgl_contentTagValueList_s * tagValuelist
if aliasType is TAG_VALUE_LIST_ALIAS
const char * backText
used as title of the popping page, if not NULL, otherwise "item" is used
const char * aliasSubName
string displayed under alias and in details view
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
const struct nbgl_genericDetails_s * details
array of nbBars structures giving what to display when each bar is touched.
uint8_t nbBars
number of touchable bars
const nbgl_icon_details_t ** icons
array of icons for each bar (nbBars items)
const char *const * subTexts
array of texts for each bar (nbBars items, in black)
const char *const * texts
array of texts for each bar (nbBars items, in black/bold)
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
The necessary parameters to build the page(s) displayed when the top-right button is touched in intro...
const char * title
text of the page (used to go back)
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.
const nbgl_icon_details_t * icon
icon to use in action button in Home page
nbgl_callback_t callback
function to call when action button is touched in Home page
const char * text
text to use in action button in Home page
nbgl_homeActionStyle_t style
style of action button
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
uint8_t entryMaxLen
maximum length of text that can be entered
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 clickable "bar" with a text and an icon.
bool inactive
if set to true, the bar is grayed-out and cannot be touched
const char * text
text (can be NULL)
uint8_t token
the token that will be used as argument of the callback
bool large
set to true only for the main level of OS settings
const char * subText
sub text (can be NULL)
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played
const nbgl_icon_details_t * iconLeft
a buffer containing the 1BPP icon for icon on left (can be NULL)
const nbgl_icon_details_t * iconRight
This structure contains info to build a confirmation button.
Structure containing all information when creating a layout. This structure must be passed as argumen...
nbgl_screenTickerConfiguration_t ticker
nbgl_layoutButtonCallback_t onActionCallback
the callback to be called on any action on the layout
This structure contains info to build a keyboard with nbgl_layoutAddKeyboard()
keyboardCallback_t callback
function called when an active key is pressed
This structure contains info to build a keyboard content (controls that are linked to keyboard)
This structure contains info to build suggestion buttons.
This structure contains info for Text content, to be set with nbgl_layoutAddTextContent().
const char * descriptions[NB_MAX_DESCRIPTIONS]
uint8_t nbDescriptions
number of used descriptions in above array
const char * info
description at bottom (in small gray)
const char * title
main text (in large bold font)
Structure containing all specific information when creating a confirmation page.
Definition nbgl_page.h:149
const char * cancelText
the text used for cancel action, if NULL a simple X button is used
Definition nbgl_page.h:152
uint8_t confirmationToken
the token used as argument of the onActionCallback
Definition nbgl_page.h:153
const char * confirmationText
text of the confirmation button
Definition nbgl_page.h:151
nbgl_layoutCenteredInfo_t centeredInfo
description of the centered info to be used
Definition nbgl_page.h:150
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played when button is pressed
Definition nbgl_page.h:157
This structure contains data to build a page in multi-pages mode (nbgl_pageDrawGenericContent)
Definition nbgl_flow.h:58
nbgl_contentTagValueDetails_t tagValueDetails
TAG_VALUE_DETAILS type
Definition nbgl_page.h:68
const char * title
text for the title of the page (if NULL, no title)
Definition nbgl_page.h:53
uint8_t topRightToken
token used when top-right button (if not NULL) is touched
Definition nbgl_page.h:58
nbgl_contentInfoLongPress_t infoLongPress
INFO_LONG_PRESS type
Definition nbgl_page.h:65
nbgl_contentRadioChoice_t choicesList
CHOICES_LIST type
Definition nbgl_flow.h:67
nbgl_contentSwitchesList_t switchesList
SWITCHES_LIST type
Definition nbgl_flow.h:65
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played when title is touched
Definition nbgl_page.h:57
nbgl_contentBarsList_t barsList
BARS_LIST type
Definition nbgl_flow.h:68
nbgl_contentInfoButton_t infoButton
INFO_BUTTON type
Definition nbgl_flow.h:62
nbgl_contentInfoList_t infosList
INFOS_LIST type
Definition nbgl_flow.h:66
nbgl_contentTagValueList_t tagValueList
TAG_VALUE_LIST type
Definition nbgl_flow.h:63
const nbgl_icon_details_t * topRightIcon
Definition nbgl_page.h:59
nbgl_contentType_t type
type of page content in the following union
Definition nbgl_flow.h:59
nbgl_contentCenteredInfo_t centeredInfo
CENTERED_INFO type
Definition nbgl_flow.h:61
nbgl_contentTagValueConfirm_t tagValueConfirm
TAG_VALUE_CONFIRM type
Definition nbgl_flow.h:64
bool isTouchableTitle
if set to true, the title is preceded by <- arrow to go back
Definition nbgl_page.h:54
nbgl_contentExtendedCenter_t extendedCenter
EXTENDED_CENTER type
Definition nbgl_page.h:64
Structure containing all specific information when creating an information page.
Definition nbgl_page.h:185
nbgl_layoutButtonStyle_t actionButtonStyle
style of "action" button
Definition nbgl_page.h:202
const char * actionButtonText
if not NULL an "action" button is set under the centered info
Definition nbgl_page.h:200
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played when button/footer is pressed
Definition nbgl_page.h:204
const nbgl_icon_details_t * actionButtonIcon
potential icon of "action" button
Definition nbgl_page.h:201
nbgl_layoutCenteredInfo_t centeredInfo
description of the centered info to be used
Definition nbgl_page.h:186
Structure containing all specific information when creating a multi-screens page.
Definition nbgl_page.h:127
uint8_t nbPages
the number of pages to display (if <2, no navigation bar)
Definition nbgl_page.h:129
uint8_t quitToken
the token used as argument of the actionCallback when the footer is touched
Definition nbgl_page.h:131
uint8_t skipToken
if skipText is NULL the token used when right part of footer is touched
Definition nbgl_page.h:139
nbgl_pageNavigationType_t navType
Definition nbgl_page.h:132
uint8_t activePage
the index of the page to display at start-up
Definition nbgl_page.h:128
bool progressIndicator
if set to true, display a progress indicator on top of the page
Definition nbgl_page.h:134
nbgl_pageNavWithButtons_t navWithButtons
structure used when navigation with buttons
Definition nbgl_page.h:142
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played when next or back is pressed
Definition nbgl_page.h:136
bool visiblePageIndicator
if set to true, the page indicator will be visible in navigation
Definition nbgl_page.h:116
const char * quitText
the text displayed in footer (on the left), used to quit (only on Flex)
Definition nbgl_page.h:120
bool backButton
if set to true, a back button (<-) is displayed in the nav bar
Definition nbgl_page.h:114
This structure contains data to build a SWITCHES_LIST content.
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...
const char * text
text of the tip-box
const nbgl_icon_details_t * icon
icon of the tip-box
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 * introDetails
const nbgl_warningDetails_t * reviewDetails
uint32_t predefinedSet
Union of the different type of contents.
nbgl_contentInfoList_t infosList
INFOS_LIST type
nbgl_contentInfoLongPress_t infoLongPress
INFO_LONG_PRESS 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_contentExtendedCenter_t extendedCenter
EXTENDED_CENTER type
nbgl_contentSwitchesList_t switchesList
SWITCHES_LIST type
nbgl_contentInfoButton_t infoButton
INFO_BUTTON type
nbgl_contentRadioChoice_t choicesList
CHOICES_LIST type