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 = {0};
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 = {0};
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)) {
2335 nbgl_contentTagValueList_t tmpList = {0};
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 = {0};
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 // Left icon is optional, only set if provided by the warning details
2519 if (details->barList.icons != NULL) {
2520 bar.iconLeft = details->barList.icons[i];
2521 }
2522 bar.token = FIRST_WARN_BAR_TOKEN + i;
2523 bar.tuneId = TUNE_TAP_CASUAL;
2524 nbgl_layoutAddTouchableBar(layout, &bar);
2525 nbgl_layoutAddSeparationLine(layout);
2526 }
2527 }
2528 else if (details->type == QRCODE_WARNING) {
2529#ifdef NBGL_QRCODE
2530 // display a QR Code
2531 nbgl_layoutAddQRCode(layout, &details->qrCode);
2532#endif // NBGL_QRCODE
2533 headerDesc.backAndText.text = details->title;
2534 }
2535 else if (details->type == CENTERED_INFO_WARNING) {
2536 // display a centered info
2537 nbgl_layoutAddContentCenter(layout, &details->centeredInfo);
2538 headerDesc.separationLine = false;
2539 }
2540 nbgl_layoutDraw(layout);
2541 nbgl_refresh();
2542 return layout;
2543}
2544
2545// function used to display the security level page in modal
2546// it can be either a single page with text or QR code, or a list of touchable bars leading
2547// to single pages
2548static void displaySecurityReport(uint32_t set)
2549{
2550 nbgl_layoutDescription_t layoutDescription = {.modal = true,
2551 .withLeftBorder = true,
2552 .onActionCallback = modalLayoutTouchCallback,
2553 .tapActionText = NULL};
2554 nbgl_layoutHeader_t headerDesc = {.type = HEADER_BACK_AND_TEXT,
2555 .separationLine = true,
2556 .backAndText.icon = NULL,
2557 .backAndText.tuneId = TUNE_TAP_CASUAL,
2558 .backAndText.token = DISMISS_WARNING_TOKEN};
2559 nbgl_layoutFooter_t footerDesc
2560 = {.type = FOOTER_EMPTY, .separationLine = false, .emptySpace.height = 0};
2561 uint8_t i;
2562 const char *provider;
2563
2564 reviewWithWarnCtx.modalLayout = nbgl_layoutGet(&layoutDescription);
2565
2566 // display a list of touchable bars in some conditions:
2567 // - we must be in the first level of security report
2568 // - and be in the review itself (not from the intro/warning screen)
2569 //
2570 if ((reviewWithWarnCtx.securityReportLevel == 1) && (!reviewWithWarnCtx.isIntro)) {
2571 for (i = 0; i < NB_WARNING_TYPES; i++) {
2572 // Skip GATED_SIGNING_WARN from security report bars
2573 if ((i != GATED_SIGNING_WARN)
2574 && (reviewWithWarnCtx.warning->predefinedSet & (1 << i))) {
2575 nbgl_layoutBar_t bar = {0};
2576 if ((i == BLIND_SIGNING_WARN) || (i == W3C_NO_THREAT_WARN) || (i == W3C_ISSUE_WARN)
2577 || (reviewWithWarnCtx.warning->providerMessage == NULL)) {
2578 bar.subText = securityReportItems[i].subText;
2579 }
2580 else {
2581 bar.subText = reviewWithWarnCtx.warning->providerMessage;
2582 }
2583 bar.text = securityReportItems[i].text;
2584 if (i != W3C_NO_THREAT_WARN) {
2585 bar.iconRight = &PUSH_ICON;
2586 bar.token = FIRST_WARN_BAR_TOKEN + i;
2587 bar.tuneId = TUNE_TAP_CASUAL;
2588 }
2589 else {
2591 }
2592 bar.iconLeft = securityReportItems[i].icon;
2593 nbgl_layoutAddTouchableBar(reviewWithWarnCtx.modalLayout, &bar);
2594 nbgl_layoutAddSeparationLine(reviewWithWarnCtx.modalLayout);
2595 }
2596 }
2597 headerDesc.backAndText.text = "Security report";
2598 nbgl_layoutAddHeader(reviewWithWarnCtx.modalLayout, &headerDesc);
2599 nbgl_layoutDraw(reviewWithWarnCtx.modalLayout);
2600 nbgl_refresh();
2601 return;
2602 }
2603 if (reviewWithWarnCtx.warning && reviewWithWarnCtx.warning->reportProvider) {
2604 provider = reviewWithWarnCtx.warning->reportProvider;
2605 }
2606 else {
2607 provider = "[unknown]";
2608 }
2609 if ((set & (1 << W3C_THREAT_DETECTED_WARN)) || (set & (1 << W3C_RISK_DETECTED_WARN))) {
2610 size_t urlLen = 0;
2611 char *destStr
2612 = tmpString
2613 + W3C_DESCRIPTION_MAX_LEN / 2; // use the second half of tmpString for strings
2614#ifdef NBGL_QRCODE
2615 // display a QR Code
2616 nbgl_layoutQRCode_t qrCode = {.url = destStr,
2617 .text1 = reviewWithWarnCtx.warning->reportUrl,
2618 .text2 = "Scan to view full report",
2619 .centered = true,
2620 .offsetY = 0};
2621 // add "https://"" as prefix of the given URL
2622 snprintf(destStr,
2623 W3C_DESCRIPTION_MAX_LEN / 2,
2624 "https://%s",
2625 reviewWithWarnCtx.warning->reportUrl);
2626 urlLen = strlen(destStr) + 1;
2627 nbgl_layoutAddQRCode(reviewWithWarnCtx.modalLayout, &qrCode);
2628 footerDesc.emptySpace.height = 24;
2629#endif // NBGL_QRCODE
2630 // use the next part of destStr for back bar text
2631 snprintf(destStr + urlLen, W3C_DESCRIPTION_MAX_LEN / 2 - urlLen, "%s report", provider);
2632 headerDesc.backAndText.text = destStr + urlLen;
2633 }
2634 else if (set & (1 << BLIND_SIGNING_WARN)) {
2635 // display a centered if in review
2636 nbgl_contentCenter_t info = {0};
2637 info.icon = &LARGE_WARNING_ICON;
2638 info.title = "This transaction cannot be Clear Signed";
2639 info.description
2640 = "This transaction or message cannot be decoded fully. If you choose to sign, you "
2641 "could be authorizing malicious actions that can drain your wallet.\n\nLearn more: "
2642 "ledger.com/e8";
2643 nbgl_layoutAddContentCenter(reviewWithWarnCtx.modalLayout, &info);
2644 footerDesc.emptySpace.height = SMALL_CENTERING_HEADER;
2645 headerDesc.separationLine = false;
2646 }
2647 else if (set & (1 << W3C_ISSUE_WARN)) {
2648 // if W3 Checks issue, display a centered info
2649 nbgl_contentCenter_t info = {0};
2650 info.icon = &LARGE_WARNING_ICON;
2651 info.title = "Transaction Check unavailable";
2652 info.description
2653 = "If you're not using the Ledger Wallet app, Transaction Check might not work. If "
2654 "you "
2655 "are using Ledger Wallet, reject the transaction and try again.\n\nGet help at "
2656 "ledger.com/e11";
2657 nbgl_layoutAddContentCenter(reviewWithWarnCtx.modalLayout, &info);
2658 footerDesc.emptySpace.height = SMALL_CENTERING_HEADER;
2659 headerDesc.separationLine = false;
2660 }
2661 nbgl_layoutAddHeader(reviewWithWarnCtx.modalLayout, &headerDesc);
2662 if (footerDesc.emptySpace.height > 0) {
2663 nbgl_layoutAddExtendedFooter(reviewWithWarnCtx.modalLayout, &footerDesc);
2664 }
2665 nbgl_layoutDraw(reviewWithWarnCtx.modalLayout);
2666 nbgl_refresh();
2667}
2668
2669// function used to display the security level page in modal
2670// it can be either a single page with text or QR code, or a list of touchable bars leading
2671// to single pages
2672static void displayCustomizedSecurityReport(const nbgl_warningDetails_t *details)
2673{
2674 reviewWithWarnCtx.modalLayout = displayModalDetails(details, DISMISS_WARNING_TOKEN);
2675}
2676
2677// function used to display the initial warning page when starting a "review with warning"
2678static void displayInitialWarning(void)
2679{
2680 // Play notification sound
2681#ifdef HAVE_PIEZO_SOUND
2682 tune_index_e tune = TUNE_RESERVED;
2683#endif // HAVE_PIEZO_SOUND
2684 // clang-format off
2685 nbgl_layoutDescription_t layoutDescription = {0};
2686 nbgl_layoutChoiceButtons_t buttonsInfo = {.bottomText = "Continue anyway",
2687 .token = WARNING_CHOICE_TOKEN,
2688 .topText = "Back to safety",
2689 .style = ROUNDED_AND_FOOTER_STYLE,
2690 .tuneId = TUNE_TAP_CASUAL};
2691 nbgl_layoutHeader_t headerDesc = {.type = HEADER_EMPTY,
2692 .emptySpace.height = MEDIUM_CENTERING_HEADER};
2693 uint32_t set = reviewWithWarnCtx.warning->predefinedSet & ~((1 << W3C_NO_THREAT_WARN) | (1 << W3C_ISSUE_WARN));
2694 // clang-format on
2695
2696 bool isBlindSigningOnly
2697 = (set != 0) && ((set & ~((1 << BLIND_SIGNING_WARN) | (1 << GATED_SIGNING_WARN))) == 0);
2698 reviewWithWarnCtx.isIntro = true;
2699
2700 layoutDescription.withLeftBorder = true;
2701 layoutDescription.onActionCallback = layoutTouchCallback;
2702 reviewWithWarnCtx.layoutCtx = nbgl_layoutGet(&layoutDescription);
2703
2704 nbgl_layoutAddHeader(reviewWithWarnCtx.layoutCtx, &headerDesc);
2705 if (reviewWithWarnCtx.warning->predefinedSet != 0) {
2706 // icon is different in casee of Blind Siging or Gated Signing
2707 nbgl_layoutAddTopRightButton(reviewWithWarnCtx.layoutCtx,
2708 isBlindSigningOnly ? &INFO_I_ICON : &QRCODE_ICON,
2709 WARNING_BUTTON_TOKEN,
2710 TUNE_TAP_CASUAL);
2711 }
2712 else if (reviewWithWarnCtx.warning->introTopRightIcon != NULL) {
2713 nbgl_layoutAddTopRightButton(reviewWithWarnCtx.layoutCtx,
2714 reviewWithWarnCtx.warning->introTopRightIcon,
2715 WARNING_BUTTON_TOKEN,
2716 TUNE_TAP_CASUAL);
2717 }
2718 // add main content
2719 // if predefined content is configured, use it preferably
2720 if (reviewWithWarnCtx.warning->predefinedSet != 0) {
2721 nbgl_contentCenter_t info = {0};
2722
2723 const char *provider;
2724
2725 // default icon
2726 info.icon = &LARGE_WARNING_ICON;
2727
2728 // use small title only if not Blind signing and not Gated signing
2729 if (isBlindSigningOnly == false) {
2730 if (reviewWithWarnCtx.warning->reportProvider) {
2731 provider = reviewWithWarnCtx.warning->reportProvider;
2732 }
2733 else {
2734 provider = "[unknown]";
2735 }
2736 info.smallTitle = tmpString;
2737 snprintf(tmpString, W3C_DESCRIPTION_MAX_LEN, "Detected by %s", provider);
2738 }
2739
2740 // If Blind Signing or Gated Signing
2741 if (isBlindSigningOnly) {
2742 info.title = "Blind signing ahead";
2743 if (set & (1 << GATED_SIGNING_WARN)) {
2744 info.description
2745 = "If you sign this transaction, you could lose your assets. "
2746 "Explore safer alternatives: ledger.com/integrated-apps";
2747 buttonsInfo.bottomText = "Accept risk and continue";
2748 }
2749 else {
2750 info.description
2751 = "This transaction's details are not fully verifiable. If you sign, you could "
2752 "lose all your assets.";
2753 buttonsInfo.bottomText = "Continue anyway";
2754 }
2755#ifdef HAVE_PIEZO_SOUND
2756 tune = TUNE_NEUTRAL;
2757#endif // HAVE_PIEZO_SOUND
2758 }
2759 else if (set & (1 << W3C_RISK_DETECTED_WARN)) {
2760 info.title = "Potential risk";
2761 if (reviewWithWarnCtx.warning->providerMessage == NULL) {
2762 info.description = "Unidentified risk";
2763 }
2764 else {
2765 info.description = reviewWithWarnCtx.warning->providerMessage;
2766 }
2767 buttonsInfo.bottomText = "Accept risk and continue";
2768#ifdef HAVE_PIEZO_SOUND
2769 tune = TUNE_NEUTRAL;
2770#endif // HAVE_PIEZO_SOUND
2771 }
2772 else if (set & (1 << W3C_THREAT_DETECTED_WARN)) {
2773 info.title = "Critical threat";
2774 if (reviewWithWarnCtx.warning->providerMessage == NULL) {
2775 info.description = "Unidentified threat";
2776 }
2777 else {
2778 info.description = reviewWithWarnCtx.warning->providerMessage;
2779 }
2780 buttonsInfo.bottomText = "Accept threat and continue";
2781#ifdef HAVE_PIEZO_SOUND
2782 tune = TUNE_ERROR;
2783#endif // HAVE_PIEZO_SOUND
2784 }
2785 nbgl_layoutAddContentCenter(reviewWithWarnCtx.layoutCtx, &info);
2786 }
2787 else if (reviewWithWarnCtx.warning->info != NULL) {
2788 // if no predefined content, use custom one
2789 nbgl_layoutAddContentCenter(reviewWithWarnCtx.layoutCtx, reviewWithWarnCtx.warning->info);
2790#ifdef HAVE_PIEZO_SOUND
2791 tune = TUNE_LOOK_AT_ME;
2792#endif // HAVE_PIEZO_SOUND
2793 }
2794 // add button and footer on bottom
2795 nbgl_layoutAddChoiceButtons(reviewWithWarnCtx.layoutCtx, &buttonsInfo);
2796
2797#ifdef HAVE_PIEZO_SOUND
2798 if (tune != TUNE_RESERVED) {
2799 os_io_seph_cmd_piezo_play_tune(tune);
2800 }
2801#endif // HAVE_PIEZO_SOUND
2802 nbgl_layoutDraw(reviewWithWarnCtx.layoutCtx);
2803 nbgl_refresh();
2804}
2805
2806// function used to display the prelude when starting a "review with warning"
2807static void displayPrelude(void)
2808{
2809 // clang-format off
2810 nbgl_layoutDescription_t layoutDescription = {0};
2811 nbgl_layoutChoiceButtons_t buttonsInfo
2812 = {.bottomText = reviewWithWarnCtx.warning->prelude->footerText,
2813 .token = PRELUDE_CHOICE_TOKEN,
2814 .topText = reviewWithWarnCtx.warning->prelude->buttonText,
2815 .style = ROUNDED_AND_FOOTER_STYLE,
2816 .tuneId = TUNE_TAP_CASUAL};
2817 nbgl_layoutHeader_t headerDesc = {.type = HEADER_EMPTY,
2818 .emptySpace.height = MEDIUM_CENTERING_HEADER};
2819 // clang-format on
2820
2821 reviewWithWarnCtx.isIntro = true;
2822
2823 layoutDescription.withLeftBorder = true;
2824 layoutDescription.onActionCallback = layoutTouchCallback;
2825 reviewWithWarnCtx.layoutCtx = nbgl_layoutGet(&layoutDescription);
2826
2827 nbgl_layoutAddHeader(reviewWithWarnCtx.layoutCtx, &headerDesc);
2828 // add centered content
2829 nbgl_contentCenter_t info = {0};
2830
2831 // default icon
2832 info.icon = reviewWithWarnCtx.warning->prelude->icon;
2833
2834 info.title = reviewWithWarnCtx.warning->prelude->title;
2835 info.description = reviewWithWarnCtx.warning->prelude->description;
2836 nbgl_layoutAddContentCenter(reviewWithWarnCtx.layoutCtx, &info);
2837
2838 // add button and footer on bottom
2839 nbgl_layoutAddChoiceButtons(reviewWithWarnCtx.layoutCtx, &buttonsInfo);
2840
2841#ifdef HAVE_PIEZO_SOUND
2842 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
2843#endif // HAVE_PIEZO_SOUND
2844 nbgl_layoutDraw(reviewWithWarnCtx.layoutCtx);
2845 nbgl_refresh();
2846}
2847
2848// function to factorize code for reviews tipbox
2849static void initWarningTipBox(const nbgl_tipBox_t *tipBox)
2850{
2851 const char *predefinedTipBoxText = NULL;
2852
2853 // if warning is valid and a warning requires a tip-box
2854 if (reviewWithWarnCtx.warning) {
2855 if (reviewWithWarnCtx.warning->predefinedSet & (1 << W3C_ISSUE_WARN)) {
2856 if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
2857 predefinedTipBoxText = "Transaction Check unavailable.\nBlind signing required.";
2858 }
2859 else {
2860 predefinedTipBoxText = "Transaction Check unavailable";
2861 }
2862 }
2863 else if (reviewWithWarnCtx.warning->predefinedSet & (1 << W3C_THREAT_DETECTED_WARN)) {
2864 if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
2865 predefinedTipBoxText = "Critical threat detected.\nBlind signing required.";
2866 }
2867 else {
2868 predefinedTipBoxText = "Critical threat detected.";
2869 }
2870 }
2871 else if (reviewWithWarnCtx.warning->predefinedSet & (1 << W3C_RISK_DETECTED_WARN)) {
2872 if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
2873 predefinedTipBoxText = "Potential risk detected.\nBlind signing required.";
2874 }
2875 else {
2876 predefinedTipBoxText = "Potential risk detected.";
2877 }
2878 }
2879 else if (reviewWithWarnCtx.warning->predefinedSet & (1 << W3C_NO_THREAT_WARN)) {
2880 if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
2881 predefinedTipBoxText
2882 = "No threat detected by Transaction Check but blind signing required.";
2883 }
2884 else {
2885 predefinedTipBoxText = "No threat detected by Transaction Check.";
2886 }
2887 }
2888 else if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
2889 predefinedTipBoxText = "Blind signing required.";
2890 }
2891 }
2892
2893 if ((tipBox != NULL) || (predefinedTipBoxText != NULL)) {
2894 // do not display "Swipe to review" if a tip-box is displayed
2895 STARTING_CONTENT.content.extendedCenter.contentCenter.subText = NULL;
2896 if (predefinedTipBoxText != NULL) {
2897 genericContext.validWarningCtx = true;
2898 STARTING_CONTENT.content.extendedCenter.tipBox.icon = NULL;
2899 STARTING_CONTENT.content.extendedCenter.tipBox.text = predefinedTipBoxText;
2900 }
2901 else {
2902 STARTING_CONTENT.content.extendedCenter.tipBox.icon = tipBox->icon;
2903 STARTING_CONTENT.content.extendedCenter.tipBox.text = tipBox->text;
2904 }
2905 STARTING_CONTENT.content.extendedCenter.tipBox.token = TIP_BOX_TOKEN;
2906 STARTING_CONTENT.content.extendedCenter.tipBox.tuneId = TUNE_TAP_CASUAL;
2907 }
2908}
2909
2910// function to factorize code for all simple reviews
2911static void useCaseReview(nbgl_operationType_t operationType,
2912 const nbgl_contentTagValueList_t *tagValueList,
2913 const nbgl_icon_details_t *icon,
2914 const char *reviewTitle,
2915 const char *reviewSubTitle,
2916 const char *finishTitle,
2917 const nbgl_tipBox_t *tipBox,
2918 nbgl_choiceCallback_t choiceCallback,
2919 bool isLight,
2920 bool playNotifSound)
2921{
2922 bundleNavContext.review.operationType = operationType;
2923 bundleNavContext.review.choiceCallback = choiceCallback;
2924
2925 // memorize context
2926 onChoice = bundleNavReviewChoice;
2927 navType = GENERIC_NAV;
2928 pageTitle = NULL;
2929
2930 genericContext.genericContents.contentsList = localContentsList;
2931 genericContext.genericContents.nbContents = 3;
2932 memset(localContentsList, 0, 3 * sizeof(nbgl_content_t));
2933
2934 // First a centered info
2935 STARTING_CONTENT.type = EXTENDED_CENTER;
2936 prepareReviewFirstPage(
2937 &STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
2938
2939 // Prepare un tipbox if needed
2940 initWarningTipBox(tipBox);
2941
2942 // Then the tag/value pairs
2943 localContentsList[1].type = TAG_VALUE_LIST;
2944 memcpy(&localContentsList[1].content.tagValueList,
2945 tagValueList,
2947 localContentsList[1].contentActionCallback = tagValueList->actionCallback;
2948
2949 // The last page
2950 if (isLight) {
2951 localContentsList[2].type = INFO_BUTTON;
2952 prepareReviewLightLastPage(
2953 operationType, &localContentsList[2].content.infoButton, icon, finishTitle);
2954 }
2955 else {
2956 localContentsList[2].type = INFO_LONG_PRESS;
2957 prepareReviewLastPage(
2958 operationType, &localContentsList[2].content.infoLongPress, icon, finishTitle);
2959 }
2960
2961 // compute number of pages & fill navigation structure
2962 uint8_t nbPages = getNbPagesForGenericContents(
2963 &genericContext.genericContents, 0, (operationType & SKIPPABLE_OPERATION));
2964 prepareNavInfo(true, nbPages, getRejectReviewText(operationType));
2965
2966 // Play notification sound if required
2967 if (playNotifSound) {
2968#ifdef HAVE_PIEZO_SOUND
2969 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
2970#endif // HAVE_PIEZO_SOUND
2971 }
2972
2973 displayGenericContextPage(0, true);
2974}
2975
2976// function to factorize code for all streaming reviews
2977static void useCaseReviewStreamingStart(nbgl_operationType_t operationType,
2978 const nbgl_icon_details_t *icon,
2979 const char *reviewTitle,
2980 const char *reviewSubTitle,
2981 nbgl_choiceCallback_t choiceCallback,
2982 bool playNotifSound)
2983{
2984 bundleNavContext.reviewStreaming.operationType = operationType;
2985 bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
2986 bundleNavContext.reviewStreaming.icon = icon;
2987
2988 // memorize context
2989 onChoice = bundleNavReviewStreamingChoice;
2990 navType = STREAMING_NAV;
2991 pageTitle = NULL;
2992
2993 genericContext.genericContents.contentsList = localContentsList;
2994 genericContext.genericContents.nbContents = 1;
2995 memset(localContentsList, 0, 1 * sizeof(nbgl_content_t));
2996
2997 // First a centered info
2998 STARTING_CONTENT.type = EXTENDED_CENTER;
2999 prepareReviewFirstPage(
3000 &STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
3001
3002 // Prepare un tipbox if needed
3003 initWarningTipBox(NULL);
3004
3005 // compute number of pages & fill navigation structure
3006 bundleNavContext.reviewStreaming.stepPageNb = getNbPagesForGenericContents(
3007 &genericContext.genericContents, 0, (operationType & SKIPPABLE_OPERATION));
3008 prepareNavInfo(true, NBGL_NO_PROGRESS_INDICATOR, getRejectReviewText(operationType));
3009 // no back button on first page
3010 navInfo.navWithButtons.backButton = false;
3011
3012 // Play notification sound if required
3013 if (playNotifSound) {
3014#ifdef HAVE_PIEZO_SOUND
3015 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
3016#endif // HAVE_PIEZO_SOUND
3017 }
3018
3019 displayGenericContextPage(0, true);
3020}
3021
3038static void useCaseHomeExt(const char *appName,
3039 const nbgl_icon_details_t *appIcon,
3040 const char *tagline,
3041 bool withSettings,
3042 nbgl_homeAction_t *homeAction,
3043 nbgl_callback_t topRightCallback,
3044 nbgl_callback_t quitCallback)
3045{
3046 nbgl_pageInfoDescription_t info = {.centeredInfo.icon = appIcon,
3047 .centeredInfo.text1 = appName,
3048 .centeredInfo.text3 = NULL,
3049 .centeredInfo.style = LARGE_CASE_INFO,
3050 .centeredInfo.offsetY = 0,
3051 .footerText = NULL,
3052 .bottomButtonStyle = QUIT_APP_TEXT,
3053 .tapActionText = NULL,
3054 .topRightStyle = withSettings ? SETTINGS_ICON : INFO_ICON,
3055 .topRightToken = CONTINUE_TOKEN,
3056 .tuneId = TUNE_TAP_CASUAL};
3057 reset_callbacks_and_context();
3058
3059 if ((homeAction->text != NULL) || (homeAction->icon != NULL)) {
3060 // trick to use ACTION_BUTTON_TOKEN for action and quit, with index used to distinguish
3061 info.bottomButtonsToken = ACTION_BUTTON_TOKEN;
3062 onAction = homeAction->callback;
3063 info.actionButtonText = homeAction->text;
3064 info.actionButtonIcon = homeAction->icon;
3066 = (homeAction->style == STRONG_HOME_ACTION) ? BLACK_BACKGROUND : WHITE_BACKGROUND;
3067 }
3068 else {
3069 info.bottomButtonsToken = QUIT_TOKEN;
3070 onAction = NULL;
3071 info.actionButtonText = NULL;
3072 info.actionButtonIcon = NULL;
3073 }
3074 if (tagline == NULL) {
3075 if (strlen(appName) > MAX_APP_NAME_FOR_SDK_TAGLINE) {
3076 snprintf(tmpString,
3078 "This app enables signing\ntransactions on its network.");
3079 }
3080 else {
3081 snprintf(tmpString,
3083 "%s %s\n%s",
3085 appName,
3087 }
3088
3089 // If there is more than 3 lines, it means the appName was split, so we put it on the next
3090 // line
3091 if (nbgl_getTextNbLinesInWidth(SMALL_REGULAR_FONT, tmpString, AVAILABLE_WIDTH, false) > 3) {
3092 snprintf(tmpString,
3094 "%s\n%s %s",
3096 appName,
3098 }
3099 info.centeredInfo.text2 = tmpString;
3100 }
3101 else {
3102 info.centeredInfo.text2 = tagline;
3103 }
3104
3105 onContinue = topRightCallback;
3106 onQuit = quitCallback;
3107
3108 pageContext = nbgl_pageDrawInfo(&pageCallback, NULL, &info);
3110}
3111
3120static void displayDetails(const char *tag, const char *value, bool wrapping)
3121{
3122 memset(&detailsContext, 0, sizeof(detailsContext));
3123
3124 uint16_t nbLines
3125 = nbgl_getTextNbLinesInWidth(SMALL_REGULAR_FONT, value, AVAILABLE_WIDTH, wrapping);
3126
3127 // initialize context
3128 detailsContext.tag = tag;
3129 detailsContext.value = value;
3130 detailsContext.nbPages = (nbLines + NB_MAX_LINES_IN_DETAILS - 1) / NB_MAX_LINES_IN_DETAILS;
3131 detailsContext.currentPage = 0;
3132 detailsContext.wrapping = wrapping;
3133 // add some spare for room lost with "..." substitution
3134 if (detailsContext.nbPages > 1) {
3135 uint16_t nbLostChars = (detailsContext.nbPages - 1) * 3;
3136 uint16_t nbLostLines = (nbLostChars + ((AVAILABLE_WIDTH) / 16) - 1)
3137 / ((AVAILABLE_WIDTH) / 16); // 16 for average char width
3138 uint8_t nbLinesInLastPage
3139 = nbLines - ((detailsContext.nbPages - 1) * NB_MAX_LINES_IN_DETAILS);
3140
3141 detailsContext.nbPages += nbLostLines / NB_MAX_LINES_IN_DETAILS;
3142 if ((nbLinesInLastPage + (nbLostLines % NB_MAX_LINES_IN_DETAILS))
3144 detailsContext.nbPages++;
3145 }
3146 }
3147
3148 displayDetailsPage(0, true);
3149}
3150
3151// function used to display the modal containing alias tag-value pairs
3152static void displayTagValueListModal(const nbgl_contentTagValueList_t *tagValues)
3153{
3154 uint8_t nbElements = 0;
3155 uint8_t nbElementsInPage;
3156 uint8_t elemIdx = 0;
3157
3158 // initialize context
3159 memset(&detailsContext, 0, sizeof(detailsContext));
3160 nbElements = tagValues->nbPairs;
3161
3162 while (nbElements > 0) {
3163 nbElementsInPage = getNbTagValuesInDetailsPage(nbElements, tagValues, elemIdx);
3164
3165 elemIdx += nbElementsInPage;
3166 modalContextSetPageInfo(detailsContext.nbPages, nbElementsInPage);
3167 nbElements -= nbElementsInPage;
3168 detailsContext.nbPages++;
3169 }
3170
3171 displayTagValueListModalPage(0, true);
3172}
3173
3174/**********************
3175 * GLOBAL FUNCTIONS
3176 **********************/
3177
3190uint8_t nbgl_useCaseGetNbTagValuesInPage(uint8_t nbPairs,
3191 const nbgl_contentTagValueList_t *tagValueList,
3192 uint8_t startIndex,
3193 bool *requireSpecificDisplay)
3194{
3195 return getNbTagValuesInPage(
3196 nbPairs, tagValueList, startIndex, false, false, false, requireSpecificDisplay);
3197}
3198
3212uint8_t nbgl_useCaseGetNbTagValuesInPageExt(uint8_t nbPairs,
3213 const nbgl_contentTagValueList_t *tagValueList,
3214 uint8_t startIndex,
3215 bool isSkippable,
3216 bool *requireSpecificDisplay)
3217{
3218 return getNbTagValuesInPage(
3219 nbPairs, tagValueList, startIndex, isSkippable, false, false, requireSpecificDisplay);
3220}
3221
3231uint8_t nbgl_useCaseGetNbInfosInPage(uint8_t nbInfos,
3232 const nbgl_contentInfoList_t *infosList,
3233 uint8_t startIndex,
3234 bool withNav)
3235{
3236 uint8_t nbInfosInPage = 0;
3237 uint16_t currentHeight = 0;
3238 uint16_t previousHeight;
3239 uint16_t navHeight = withNav ? SIMPLE_FOOTER_HEIGHT : 0;
3240 const char *const *infoContents = PIC(infosList->infoContents);
3241
3242 while (nbInfosInPage < nbInfos) {
3243 // The type string must be a 1 liner and its height is LIST_ITEM_MIN_TEXT_HEIGHT
3244 currentHeight
3245 += LIST_ITEM_MIN_TEXT_HEIGHT + 2 * LIST_ITEM_PRE_HEADING + LIST_ITEM_HEADING_SUB_TEXT;
3246
3247 // content height
3248 currentHeight += nbgl_getTextHeightInWidth(SMALL_REGULAR_FONT,
3249 PIC(infoContents[startIndex + nbInfosInPage]),
3251 true);
3252 // if height is over the limit
3253 if (currentHeight >= (INFOS_AREA_HEIGHT - navHeight)) {
3254 // if there was no nav, now there will be, so it can be necessary to remove the last
3255 // item
3256 if (!withNav && (previousHeight >= (INFOS_AREA_HEIGHT - SIMPLE_FOOTER_HEIGHT))) {
3257 nbInfosInPage--;
3258 }
3259 break;
3260 }
3261 previousHeight = currentHeight;
3262 nbInfosInPage++;
3263 }
3264 return nbInfosInPage;
3265}
3266
3276uint8_t nbgl_useCaseGetNbSwitchesInPage(uint8_t nbSwitches,
3277 const nbgl_contentSwitchesList_t *switchesList,
3278 uint8_t startIndex,
3279 bool withNav)
3280{
3281 uint8_t nbSwitchesInPage = 0;
3282 uint16_t currentHeight = 0;
3283 uint16_t previousHeight = 0;
3284 uint16_t navHeight = withNav ? SIMPLE_FOOTER_HEIGHT : 0;
3285 nbgl_contentSwitch_t *switchArray = (nbgl_contentSwitch_t *) PIC(switchesList->switches);
3286
3287 while (nbSwitchesInPage < nbSwitches) {
3288 nbgl_contentSwitch_t *curSwitch = &switchArray[startIndex + nbSwitchesInPage];
3289 // The text string is either a 1 liner and its height is LIST_ITEM_MIN_TEXT_HEIGHT
3290 // or we use its height directly
3291 uint16_t textHeight = MAX(
3292 LIST_ITEM_MIN_TEXT_HEIGHT,
3293 nbgl_getTextHeightInWidth(SMALL_BOLD_FONT, curSwitch->text, AVAILABLE_WIDTH, true));
3294 currentHeight += textHeight + 2 * LIST_ITEM_PRE_HEADING;
3295
3296 if (curSwitch->subText) {
3297 currentHeight += LIST_ITEM_HEADING_SUB_TEXT;
3298
3299 // sub-text height
3300 currentHeight += nbgl_getTextHeightInWidth(
3301 SMALL_REGULAR_FONT, curSwitch->subText, AVAILABLE_WIDTH, true);
3302 }
3303 // if height is over the limit
3304 if (currentHeight >= (INFOS_AREA_HEIGHT - navHeight)) {
3305 break;
3306 }
3307 previousHeight = currentHeight;
3308 nbSwitchesInPage++;
3309 }
3310 // if there was no nav, now there will be, so it can be necessary to remove the last
3311 // item
3312 if (!withNav && (previousHeight >= (INFOS_AREA_HEIGHT - SIMPLE_FOOTER_HEIGHT))) {
3313 nbSwitchesInPage--;
3314 }
3315 return nbSwitchesInPage;
3316}
3317
3327uint8_t nbgl_useCaseGetNbBarsInPage(uint8_t nbBars,
3328 const nbgl_contentBarsList_t *barsList,
3329 uint8_t startIndex,
3330 bool withNav)
3331{
3332 uint8_t nbBarsInPage = 0;
3333 uint16_t currentHeight = 0;
3334 uint16_t previousHeight;
3335 uint16_t navHeight = withNav ? SIMPLE_FOOTER_HEIGHT : 0;
3336
3337 UNUSED(barsList);
3338 UNUSED(startIndex);
3339
3340 while (nbBarsInPage < nbBars) {
3341 currentHeight += LIST_ITEM_MIN_TEXT_HEIGHT + 2 * LIST_ITEM_PRE_HEADING;
3342 // if height is over the limit
3343 if (currentHeight >= (INFOS_AREA_HEIGHT - navHeight)) {
3344 break;
3345 }
3346 previousHeight = currentHeight;
3347 nbBarsInPage++;
3348 }
3349 // if there was no nav, now there may will be, so it can be necessary to remove the last
3350 // item
3351 if (!withNav && (previousHeight >= (INFOS_AREA_HEIGHT - SIMPLE_FOOTER_HEIGHT))) {
3352 nbBarsInPage--;
3353 }
3354 return nbBarsInPage;
3355}
3356
3366uint8_t nbgl_useCaseGetNbChoicesInPage(uint8_t nbChoices,
3367 const nbgl_contentRadioChoice_t *choicesList,
3368 uint8_t startIndex,
3369 bool withNav)
3370{
3371 uint8_t nbChoicesInPage = 0;
3372 uint16_t currentHeight = 0;
3373 uint16_t previousHeight;
3374 uint16_t navHeight = withNav ? SIMPLE_FOOTER_HEIGHT : 0;
3375
3376 UNUSED(choicesList);
3377 UNUSED(startIndex);
3378
3379 while (nbChoicesInPage < nbChoices) {
3380 currentHeight += LIST_ITEM_MIN_TEXT_HEIGHT + 2 * LIST_ITEM_PRE_HEADING;
3381 // if height is over the limit
3382 if (currentHeight >= (INFOS_AREA_HEIGHT - navHeight)) {
3383 // if there was no nav, now there will be, so it can be necessary to remove the last
3384 // item
3385 if (!withNav && (previousHeight >= (INFOS_AREA_HEIGHT - SIMPLE_FOOTER_HEIGHT))) {
3386 nbChoicesInPage--;
3387 }
3388 break;
3389 }
3390 previousHeight = currentHeight;
3391 nbChoicesInPage++;
3392 }
3393 return nbChoicesInPage;
3394}
3395
3403{
3404 uint8_t nbPages = 0;
3405 uint8_t nbPairs = tagValueList->nbPairs;
3406 uint8_t nbPairsInPage;
3407 uint8_t i = 0;
3408 bool flag;
3409
3410 while (i < tagValueList->nbPairs) {
3411 // upper margin
3412 nbPairsInPage = nbgl_useCaseGetNbTagValuesInPageExt(nbPairs, tagValueList, i, false, &flag);
3413 i += nbPairsInPage;
3414 nbPairs -= nbPairsInPage;
3415 nbPages++;
3416 }
3417 return nbPages;
3418}
3419
3424void nbgl_useCaseHome(const char *appName,
3425 const nbgl_icon_details_t *appIcon,
3426 const char *tagline,
3427 bool withSettings,
3428 nbgl_callback_t topRightCallback,
3429 nbgl_callback_t quitCallback)
3430{
3431 nbgl_homeAction_t homeAction = {0};
3432 useCaseHomeExt(
3433 appName, appIcon, tagline, withSettings, &homeAction, topRightCallback, quitCallback);
3434}
3435
3440void nbgl_useCaseHomeExt(const char *appName,
3441 const nbgl_icon_details_t *appIcon,
3442 const char *tagline,
3443 bool withSettings,
3444 const char *actionButtonText,
3445 nbgl_callback_t actionCallback,
3446 nbgl_callback_t topRightCallback,
3447 nbgl_callback_t quitCallback)
3448{
3449 nbgl_homeAction_t homeAction = {.callback = actionCallback,
3450 .icon = NULL,
3451 .style = STRONG_HOME_ACTION,
3452 .text = actionButtonText};
3453
3454 useCaseHomeExt(
3455 appName, appIcon, tagline, withSettings, &homeAction, topRightCallback, quitCallback);
3456}
3457
3471void nbgl_useCaseNavigableContent(const char *title,
3472 uint8_t initPage,
3473 uint8_t nbPages,
3474 nbgl_callback_t quitCallback,
3475 nbgl_navCallback_t navCallback,
3476 nbgl_layoutTouchCallback_t controlsCallback)
3477{
3478 reset_callbacks_and_context();
3479
3480 // memorize context
3481 onQuit = quitCallback;
3482 onNav = navCallback;
3483 onControls = controlsCallback;
3484 pageTitle = title;
3485 navType = SETTINGS_NAV;
3486
3487 // fill navigation structure
3488 prepareNavInfo(false, nbPages, NULL);
3489
3490 displaySettingsPage(initPage, true);
3491}
3492
3498void nbgl_useCaseSettings(const char *title,
3499 uint8_t initPage,
3500 uint8_t nbPages,
3501 bool touchable,
3502 nbgl_callback_t quitCallback,
3503 nbgl_navCallback_t navCallback,
3504 nbgl_layoutTouchCallback_t controlsCallback)
3505{
3506 UNUSED(touchable);
3508 title, initPage, nbPages, quitCallback, navCallback, controlsCallback);
3509}
3510
3523void nbgl_useCaseGenericSettings(const char *appName,
3524 uint8_t initPage,
3525 const nbgl_genericContents_t *settingContents,
3526 const nbgl_contentInfoList_t *infosList,
3527 nbgl_callback_t quitCallback)
3528{
3529 reset_callbacks_and_context();
3530
3531 // memorize context
3532 onQuit = quitCallback;
3533 pageTitle = appName;
3534 navType = GENERIC_NAV;
3535
3536 if (settingContents != NULL) {
3537 memcpy(&genericContext.genericContents, settingContents, sizeof(nbgl_genericContents_t));
3538 }
3539 if (infosList != NULL) {
3540 genericContext.hasFinishingContent = true;
3541 memset(&FINISHING_CONTENT, 0, sizeof(nbgl_content_t));
3542 FINISHING_CONTENT.type = INFOS_LIST;
3543 memcpy(&FINISHING_CONTENT.content, infosList, sizeof(nbgl_content_u));
3544 }
3545
3546 // fill navigation structure
3547 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
3548 if (infosList != NULL) {
3549 nbPages += getNbPagesForContent(&FINISHING_CONTENT, nbPages, true, false);
3550 }
3551
3552 prepareNavInfo(false, nbPages, NULL);
3553
3554 displayGenericContextPage(initPage, true);
3555}
3556
3568void nbgl_useCaseGenericConfiguration(const char *title,
3569 uint8_t initPage,
3570 const nbgl_genericContents_t *contents,
3571 nbgl_callback_t quitCallback)
3572{
3573 nbgl_useCaseGenericSettings(title, initPage, contents, NULL, quitCallback);
3574}
3575
3593 const char *appName,
3594 const nbgl_icon_details_t *appIcon,
3595 const char *tagline,
3596 const uint8_t
3597 initSettingPage, // if not INIT_HOME_PAGE, start directly the corresponding setting page
3598 const nbgl_genericContents_t *settingContents,
3599 const nbgl_contentInfoList_t *infosList,
3600 const nbgl_homeAction_t *action, // Set to NULL if no additional action
3601 nbgl_callback_t quitCallback)
3602{
3603 nbgl_homeAndSettingsContext_t *context = &bundleNavContext.homeAndSettings;
3604
3605 reset_callbacks_and_context();
3606
3607 context->appName = appName;
3608 context->appIcon = appIcon;
3609 context->tagline = tagline;
3610 context->settingContents = settingContents;
3611 context->infosList = infosList;
3612 if (action != NULL) {
3613 memcpy(&context->homeAction, action, sizeof(nbgl_homeAction_t));
3614 }
3615 else {
3616 memset(&context->homeAction, 0, sizeof(nbgl_homeAction_t));
3617 }
3618 context->quitCallback = quitCallback;
3619
3620 if (initSettingPage != INIT_HOME_PAGE) {
3621 bundleNavStartSettingsAtPage(initSettingPage);
3622 }
3623 else {
3624 bundleNavStartHome();
3625 }
3626}
3627
3635void nbgl_useCaseStatus(const char *message, bool isSuccess, nbgl_callback_t quitCallback)
3636{
3637 nbgl_screenTickerConfiguration_t ticker = {.tickerCallback = &tickerCallback,
3638 .tickerIntervale = 0, // not periodic
3639 .tickerValue = STATUS_SCREEN_DURATION};
3640 nbgl_pageInfoDescription_t info = {0};
3641
3642 reset_callbacks_and_context();
3643
3644 onQuit = quitCallback;
3645 if (isSuccess) {
3646#ifdef HAVE_PIEZO_SOUND
3647 os_io_seph_cmd_piezo_play_tune(TUNE_LEDGER_MOMENT);
3648#endif // HAVE_PIEZO_SOUND
3649 }
3650 info.centeredInfo.icon = isSuccess ? &CHECK_CIRCLE_ICON : &DENIED_CIRCLE_ICON;
3651 info.centeredInfo.style = LARGE_CASE_INFO;
3652 info.centeredInfo.text1 = message;
3653 info.tapActionText = "";
3654 info.tapActionToken = QUIT_TOKEN;
3655 info.tuneId = TUNE_TAP_CASUAL;
3656 pageContext = nbgl_pageDrawInfo(&pageCallback, &ticker, &info);
3658}
3659
3667 nbgl_callback_t quitCallback)
3668{
3669 const char *msg;
3670 bool isSuccess;
3671 switch (reviewStatusType) {
3673 msg = "Operation signed";
3674 isSuccess = true;
3675 break;
3677 msg = "Operation rejected";
3678 isSuccess = false;
3679 break;
3681 msg = "Transaction signed";
3682 isSuccess = true;
3683 break;
3685 msg = "Transaction rejected";
3686 isSuccess = false;
3687 break;
3689 msg = "Message signed";
3690 isSuccess = true;
3691 break;
3693 msg = "Message rejected";
3694 isSuccess = false;
3695 break;
3697 msg = "Address verified";
3698 isSuccess = true;
3699 break;
3701 msg = "Address verification\ncancelled";
3702 isSuccess = false;
3703 break;
3704 default:
3705 return;
3706 }
3707 nbgl_useCaseStatus(msg, isSuccess, quitCallback);
3708}
3709
3723 const char *message,
3724 const char *subMessage,
3725 const char *confirmText,
3726 const char *cancelText,
3727 nbgl_choiceCallback_t callback)
3728{
3730 // check params
3731 if ((confirmText == NULL) || (cancelText == NULL)) {
3732 return;
3733 }
3734 reset_callbacks_and_context();
3735
3736 info.cancelText = cancelText;
3737 info.centeredInfo.text1 = message;
3738 info.centeredInfo.text2 = subMessage;
3739 info.centeredInfo.style = LARGE_CASE_INFO;
3740 info.centeredInfo.icon = icon;
3741 info.confirmationText = confirmText;
3742 info.confirmationToken = CHOICE_TOKEN;
3743 info.tuneId = TUNE_TAP_CASUAL;
3744
3745 onChoice = callback;
3746 pageContext = nbgl_pageDrawConfirmation(&pageCallback, &info);
3748}
3749
3765 const char *message,
3766 const char *subMessage,
3767 const char *confirmText,
3768 const char *cancelText,
3769 nbgl_genericDetails_t *details,
3770 nbgl_choiceCallback_t callback)
3771{
3773 (details != NULL) ? &SEARCH_ICON : NULL,
3774 message,
3775 subMessage,
3776 NULL,
3777 confirmText,
3778 cancelText,
3779 details,
3780 callback);
3781}
3782
3806 const nbgl_icon_details_t *headerIcon,
3807 const char *title,
3808 const char *message,
3809 const char *subMessage,
3810 const char *confirmText,
3811 const char *cancelText,
3812 nbgl_warningDetails_t *details,
3813 nbgl_choiceCallback_t callback)
3814{
3815 // clang-format off
3816 nbgl_layoutDescription_t layoutDescription = {0};
3817 nbgl_layoutChoiceButtons_t buttonsInfo = {.bottomText = cancelText,
3818 .token = CHOICE_TOKEN,
3819 .topText = confirmText,
3820 .style = ROUNDED_AND_FOOTER_STYLE,
3821 .tuneId = TUNE_TAP_CASUAL};
3822 nbgl_contentCenter_t centeredInfo = {0};
3823 nbgl_layoutHeader_t headerDesc = {.type = HEADER_EMPTY,
3824 .emptySpace.height = MEDIUM_CENTERING_HEADER};
3825 // clang-format on
3826
3827 if ((confirmText == NULL) || (cancelText == NULL)) {
3828 return;
3829 }
3830
3831 reset_callbacks_and_context();
3832
3833#ifdef HAVE_PIEZO_SOUND
3834 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
3835#endif // HAVE_PIEZO_SOUND
3836
3837 onChoice = callback;
3838 layoutDescription.withLeftBorder = true;
3839 layoutDescription.onActionCallback = layoutTouchCallback;
3840 sharedContext.usage = SHARE_CTX_CHOICE_WITH_DETAILS;
3841 choiceWithDetailsCtx.layoutCtx = nbgl_layoutGet(&layoutDescription);
3842 choiceWithDetailsCtx.details = details;
3843
3844 nbgl_layoutAddHeader(choiceWithDetailsCtx.layoutCtx, &headerDesc);
3845 nbgl_layoutAddChoiceButtons(choiceWithDetailsCtx.layoutCtx, &buttonsInfo);
3846 centeredInfo.icon = centerIcon;
3847 centeredInfo.title = title;
3848 centeredInfo.description = message;
3849 centeredInfo.subText = subMessage;
3850 nbgl_layoutAddContentCenter(choiceWithDetailsCtx.layoutCtx, &centeredInfo);
3851
3852 if ((details != NULL) && (headerIcon != NULL)) {
3853 nbgl_layoutAddTopRightButton(
3854 choiceWithDetailsCtx.layoutCtx, headerIcon, CHOICE_DETAILS_TOKEN, TUNE_TAP_CASUAL);
3855 }
3856
3857 nbgl_layoutDraw(choiceWithDetailsCtx.layoutCtx);
3859}
3860
3874void nbgl_useCaseConfirm(const char *message,
3875 const char *subMessage,
3876 const char *confirmText,
3877 const char *cancelText,
3878 nbgl_callback_t callback)
3879{
3880 // Don't reset callback or nav context as this is just a modal.
3881
3882 nbgl_pageConfirmationDescription_t info = {.cancelText = cancelText,
3883 .centeredInfo.text1 = message,
3884 .centeredInfo.text2 = subMessage,
3885 .centeredInfo.text3 = NULL,
3886 .centeredInfo.style = LARGE_CASE_INFO,
3887 .centeredInfo.icon = &IMPORTANT_CIRCLE_ICON,
3888 .centeredInfo.offsetY = 0,
3889 .confirmationText = confirmText,
3890 .confirmationToken = CHOICE_TOKEN,
3891 .tuneId = TUNE_TAP_CASUAL,
3892 .modal = true};
3893 onModalConfirm = callback;
3894 if (modalPageContext != NULL) {
3895 nbgl_pageRelease(modalPageContext);
3896 }
3897 modalPageContext = nbgl_pageDrawConfirmation(&pageModalCallback, &info);
3899}
3900
3912 const char *message,
3913 const char *actionText,
3914 nbgl_callback_t callback)
3915{
3916 nbgl_pageContent_t content = {0};
3917
3918 reset_callbacks_and_context();
3919 // memorize callback
3920 onAction = callback;
3921
3922 content.tuneId = TUNE_TAP_CASUAL;
3923 content.type = INFO_BUTTON;
3924 content.infoButton.buttonText = actionText;
3925 content.infoButton.text = message;
3926 content.infoButton.icon = icon;
3927 content.infoButton.buttonToken = ACTION_BUTTON_TOKEN;
3928
3929 pageContext = nbgl_pageDrawGenericContent(&pageCallback, NULL, &content);
3931}
3932
3944void nbgl_useCaseReviewStart(const nbgl_icon_details_t *icon,
3945 const char *reviewTitle,
3946 const char *reviewSubTitle,
3947 const char *rejectText,
3948 nbgl_callback_t continueCallback,
3949 nbgl_callback_t rejectCallback)
3950{
3951 nbgl_pageInfoDescription_t info = {.footerText = rejectText,
3952 .footerToken = QUIT_TOKEN,
3953 .tapActionText = NULL,
3954 .isSwipeable = true,
3955 .tapActionToken = CONTINUE_TOKEN,
3956 .topRightStyle = NO_BUTTON_STYLE,
3957 .actionButtonText = NULL,
3958 .tuneId = TUNE_TAP_CASUAL};
3959
3960 reset_callbacks_and_context();
3961
3962 info.centeredInfo.icon = icon;
3963 info.centeredInfo.text1 = reviewTitle;
3964 info.centeredInfo.text2 = reviewSubTitle;
3965 info.centeredInfo.text3 = "Swipe to review";
3966 info.centeredInfo.style = LARGE_CASE_GRAY_INFO;
3967 info.centeredInfo.offsetY = 0;
3968 onQuit = rejectCallback;
3969 onContinue = continueCallback;
3970
3971#ifdef HAVE_PIEZO_SOUND
3972 // Play notification sound
3973 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
3974#endif // HAVE_PIEZO_SOUND
3975
3976 pageContext = nbgl_pageDrawInfo(&pageCallback, NULL, &info);
3977 nbgl_refresh();
3978}
3979
3984void nbgl_useCaseRegularReview(uint8_t initPage,
3985 uint8_t nbPages,
3986 const char *rejectText,
3987 nbgl_layoutTouchCallback_t buttonCallback,
3988 nbgl_navCallback_t navCallback,
3989 nbgl_choiceCallback_t choiceCallback)
3990{
3991 reset_callbacks_and_context();
3992
3993 // memorize context
3994 onChoice = choiceCallback;
3995 onNav = navCallback;
3996 onControls = buttonCallback;
3997 forwardNavOnly = false;
3998 navType = REVIEW_NAV;
3999
4000 // fill navigation structure
4001 UNUSED(rejectText);
4002 prepareNavInfo(true, nbPages, getRejectReviewText(TYPE_OPERATION));
4003
4004 displayReviewPage(initPage, true);
4005}
4006
4019void nbgl_useCaseStaticReview(const nbgl_contentTagValueList_t *tagValueList,
4020 const nbgl_pageInfoLongPress_t *infoLongPress,
4021 const char *rejectText,
4022 nbgl_choiceCallback_t callback)
4023{
4024 uint8_t offset = 0;
4025
4026 reset_callbacks_and_context();
4027
4028 // memorize context
4029 onChoice = callback;
4030 navType = GENERIC_NAV;
4031 pageTitle = NULL;
4032 bundleNavContext.review.operationType = TYPE_OPERATION;
4033
4034 genericContext.genericContents.contentsList = localContentsList;
4035 memset(localContentsList, 0, 2 * sizeof(nbgl_content_t));
4036
4037 if (tagValueList != NULL && tagValueList->nbPairs != 0) {
4038 localContentsList[offset].type = TAG_VALUE_LIST;
4039 memcpy(&localContentsList[offset].content.tagValueList,
4040 tagValueList,
4042 offset++;
4043 }
4044
4045 localContentsList[offset].type = INFO_LONG_PRESS;
4046 memcpy(&localContentsList[offset].content.infoLongPress,
4047 infoLongPress,
4048 sizeof(nbgl_pageInfoLongPress_t));
4049 localContentsList[offset].content.infoLongPress.longPressToken = CONFIRM_TOKEN;
4050 offset++;
4051
4052 genericContext.genericContents.nbContents = offset;
4053
4054 // compute number of pages & fill navigation structure
4055 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
4056 UNUSED(rejectText);
4057 prepareNavInfo(true, nbPages, getRejectReviewText(TYPE_OPERATION));
4058
4059 displayGenericContextPage(0, true);
4060}
4061
4075void nbgl_useCaseStaticReviewLight(const nbgl_contentTagValueList_t *tagValueList,
4076 const nbgl_pageInfoLongPress_t *infoLongPress,
4077 const char *rejectText,
4078 nbgl_choiceCallback_t callback)
4079{
4080 uint8_t offset = 0;
4081
4082 reset_callbacks_and_context();
4083
4084 // memorize context
4085 onChoice = callback;
4086 navType = GENERIC_NAV;
4087 pageTitle = NULL;
4088
4089 genericContext.genericContents.contentsList = localContentsList;
4090 memset(localContentsList, 0, 2 * sizeof(nbgl_content_t));
4091
4092 if (tagValueList != NULL && tagValueList->nbPairs != 0) {
4093 localContentsList[offset].type = TAG_VALUE_LIST;
4094 memcpy(&localContentsList[offset].content.tagValueList,
4095 tagValueList,
4097 offset++;
4098 }
4099
4100 localContentsList[offset].type = INFO_BUTTON;
4101 localContentsList[offset].content.infoButton.text = infoLongPress->text;
4102 localContentsList[offset].content.infoButton.icon = infoLongPress->icon;
4103 localContentsList[offset].content.infoButton.buttonText = infoLongPress->longPressText;
4104 localContentsList[offset].content.infoButton.buttonToken = CONFIRM_TOKEN;
4105 localContentsList[offset].content.infoButton.tuneId = TUNE_TAP_CASUAL;
4106 offset++;
4107
4108 genericContext.genericContents.nbContents = offset;
4109
4110 // compute number of pages & fill navigation structure
4111 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
4112 UNUSED(rejectText);
4113 prepareNavInfo(true, nbPages, getRejectReviewText(TYPE_OPERATION));
4114
4115 displayGenericContextPage(0, true);
4116}
4117
4134void nbgl_useCaseReview(nbgl_operationType_t operationType,
4135 const nbgl_contentTagValueList_t *tagValueList,
4136 const nbgl_icon_details_t *icon,
4137 const char *reviewTitle,
4138 const char *reviewSubTitle,
4139 const char *finishTitle,
4140 nbgl_choiceCallback_t choiceCallback)
4141{
4142 reset_callbacks_and_context();
4143
4144 useCaseReview(operationType,
4145 tagValueList,
4146 icon,
4147 reviewTitle,
4148 reviewSubTitle,
4149 finishTitle,
4150 NULL,
4151 choiceCallback,
4152 false,
4153 true);
4154}
4155
4176 const nbgl_contentTagValueList_t *tagValueList,
4177 const nbgl_icon_details_t *icon,
4178 const char *reviewTitle,
4179 const char *reviewSubTitle,
4180 const char *finishTitle,
4181 const nbgl_tipBox_t *tipBox,
4182 nbgl_choiceCallback_t choiceCallback)
4183{
4184 nbgl_useCaseAdvancedReview(operationType,
4185 tagValueList,
4186 icon,
4187 reviewTitle,
4188 reviewSubTitle,
4189 finishTitle,
4190 tipBox,
4191 &blindSigningWarning,
4192 choiceCallback);
4193}
4194
4218 const nbgl_contentTagValueList_t *tagValueList,
4219 const nbgl_icon_details_t *icon,
4220 const char *reviewTitle,
4221 const char *reviewSubTitle,
4222 const char *finishTitle,
4223 const nbgl_tipBox_t *tipBox,
4224 const nbgl_warning_t *warning,
4225 nbgl_choiceCallback_t choiceCallback)
4226{
4227 reset_callbacks_and_context();
4228
4229 // memorize tipBox because it can be in the call stack of the caller
4230 if (tipBox != NULL) {
4231 memcpy(&activeTipBox, tipBox, sizeof(activeTipBox));
4232 }
4233 // if no warning at all, it's a simple review
4234 if ((warning == NULL)
4235 || ((warning->predefinedSet == 0) && (warning->introDetails == NULL)
4236 && (warning->reviewDetails == NULL) && (warning->prelude == NULL))) {
4237 useCaseReview(operationType,
4238 tagValueList,
4239 icon,
4240 reviewTitle,
4241 reviewSubTitle,
4242 finishTitle,
4243 tipBox,
4244 choiceCallback,
4245 false,
4246 true);
4247 return;
4248 }
4249 if (warning->predefinedSet == (1 << W3C_NO_THREAT_WARN)) {
4250 operationType |= NO_THREAT_OPERATION;
4251 }
4252 else if (warning->predefinedSet != 0) {
4253 operationType |= RISKY_OPERATION;
4254 }
4255 sharedContext.usage = SHARE_CTX_REVIEW_WITH_WARNING;
4256 reviewWithWarnCtx.isStreaming = false;
4257 reviewWithWarnCtx.operationType = operationType;
4258 reviewWithWarnCtx.tagValueList = tagValueList;
4259 reviewWithWarnCtx.icon = icon;
4260 reviewWithWarnCtx.reviewTitle = reviewTitle;
4261 reviewWithWarnCtx.reviewSubTitle = reviewSubTitle;
4262 reviewWithWarnCtx.finishTitle = finishTitle;
4263 reviewWithWarnCtx.warning = warning;
4264 reviewWithWarnCtx.choiceCallback = choiceCallback;
4265
4266 // if the warning contains a prelude, display it first
4267 if (reviewWithWarnCtx.warning->prelude) {
4268 displayPrelude();
4269 }
4270 // display the initial warning only of a risk/threat or blind signing or prelude
4271 else if (HAS_INITIAL_WARNING(warning)) {
4272 displayInitialWarning();
4273 }
4274 else {
4275 useCaseReview(operationType,
4276 tagValueList,
4277 icon,
4278 reviewTitle,
4279 reviewSubTitle,
4280 finishTitle,
4281 tipBox,
4282 choiceCallback,
4283 false,
4284 true);
4285 }
4286}
4287
4305 const nbgl_contentTagValueList_t *tagValueList,
4306 const nbgl_icon_details_t *icon,
4307 const char *reviewTitle,
4308 const char *reviewSubTitle,
4309 const char *finishTitle,
4310 nbgl_choiceCallback_t choiceCallback)
4311{
4312 reset_callbacks_and_context();
4313
4314 useCaseReview(operationType,
4315 tagValueList,
4316 icon,
4317 reviewTitle,
4318 reviewSubTitle,
4319 finishTitle,
4320 NULL,
4321 choiceCallback,
4322 true,
4323 true);
4324}
4325
4335 const char *rejectText,
4336 nbgl_callback_t rejectCallback)
4337{
4338 reset_callbacks_and_context();
4339
4340 // memorize context
4341 onQuit = rejectCallback;
4342 navType = GENERIC_NAV;
4343 pageTitle = NULL;
4344 bundleNavContext.review.operationType = TYPE_OPERATION;
4345
4346 memcpy(&genericContext.genericContents, contents, sizeof(nbgl_genericContents_t));
4347
4348 // compute number of pages & fill navigation structure
4349 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
4350 prepareNavInfo(true, nbPages, rejectText);
4351 navInfo.quitToken = QUIT_TOKEN;
4352
4353#ifdef HAVE_PIEZO_SOUND
4354 // Play notification sound
4355 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
4356#endif // HAVE_PIEZO_SOUND
4357
4358 displayGenericContextPage(0, true);
4359}
4360
4374 const nbgl_icon_details_t *icon,
4375 const char *reviewTitle,
4376 const char *reviewSubTitle,
4377 nbgl_choiceCallback_t choiceCallback)
4378{
4379 reset_callbacks_and_context();
4380
4381 useCaseReviewStreamingStart(
4382 operationType, icon, reviewTitle, reviewSubTitle, choiceCallback, true);
4383}
4384
4399 const nbgl_icon_details_t *icon,
4400 const char *reviewTitle,
4401 const char *reviewSubTitle,
4402 nbgl_choiceCallback_t choiceCallback)
4403{
4405 operationType, icon, reviewTitle, reviewSubTitle, &blindSigningWarning, choiceCallback);
4406}
4407
4424 const nbgl_icon_details_t *icon,
4425 const char *reviewTitle,
4426 const char *reviewSubTitle,
4427 const nbgl_warning_t *warning,
4428 nbgl_choiceCallback_t choiceCallback)
4429{
4430 reset_callbacks_and_context();
4431
4432 // if no warning at all, it's a simple review
4433 if ((warning == NULL)
4434 || ((warning->predefinedSet == 0) && (warning->introDetails == NULL)
4435 && (warning->reviewDetails == NULL) && (warning->prelude == NULL))) {
4436 useCaseReviewStreamingStart(
4437 operationType, icon, reviewTitle, reviewSubTitle, choiceCallback, true);
4438 return;
4439 }
4440 if (warning->predefinedSet == (1 << W3C_NO_THREAT_WARN)) {
4441 operationType |= NO_THREAT_OPERATION;
4442 }
4443 else if (warning->predefinedSet != 0) {
4444 operationType |= RISKY_OPERATION;
4445 }
4446
4447 sharedContext.usage = SHARE_CTX_REVIEW_WITH_WARNING;
4448 reviewWithWarnCtx.isStreaming = true;
4449 reviewWithWarnCtx.operationType = operationType;
4450 reviewWithWarnCtx.icon = icon;
4451 reviewWithWarnCtx.reviewTitle = reviewTitle;
4452 reviewWithWarnCtx.reviewSubTitle = reviewSubTitle;
4453 reviewWithWarnCtx.choiceCallback = choiceCallback;
4454 reviewWithWarnCtx.warning = warning;
4455
4456 // if the warning contains a prelude, display it first
4457 if (reviewWithWarnCtx.warning->prelude) {
4458 displayPrelude();
4459 }
4460 // display the initial warning only of a risk/threat or blind signing
4461 else if (HAS_INITIAL_WARNING(warning)) {
4462 displayInitialWarning();
4463 }
4464 else {
4465 useCaseReviewStreamingStart(
4466 operationType, icon, reviewTitle, reviewSubTitle, choiceCallback, true);
4467 }
4468}
4469
4484 nbgl_choiceCallback_t choiceCallback,
4485 nbgl_callback_t skipCallback)
4486{
4487 // Should follow a call to nbgl_useCaseReviewStreamingStart
4488 memset(&genericContext, 0, sizeof(genericContext));
4489
4490 bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
4491 bundleNavContext.reviewStreaming.skipCallback = skipCallback;
4492
4493 // memorize context
4494 onChoice = bundleNavReviewStreamingChoice;
4495 navType = STREAMING_NAV;
4496 pageTitle = NULL;
4497
4498 genericContext.genericContents.contentsList = localContentsList;
4499 genericContext.genericContents.nbContents = 1;
4500 memset(localContentsList, 0, 1 * sizeof(nbgl_content_t));
4501
4502 // Then the tag/value pairs
4503 STARTING_CONTENT.type = TAG_VALUE_LIST;
4504 memcpy(
4505 &STARTING_CONTENT.content.tagValueList, tagValueList, sizeof(nbgl_contentTagValueList_t));
4506
4507 // compute number of pages & fill navigation structure
4508 bundleNavContext.reviewStreaming.stepPageNb = getNbPagesForGenericContents(
4509 &genericContext.genericContents,
4510 0,
4511 (bundleNavContext.reviewStreaming.operationType & SKIPPABLE_OPERATION));
4512 prepareNavInfo(true,
4514 getRejectReviewText(bundleNavContext.reviewStreaming.operationType));
4515 // if the operation is skippable
4516 if (bundleNavContext.reviewStreaming.operationType & SKIPPABLE_OPERATION) {
4517 navInfo.progressIndicator = false;
4518 navInfo.skipText = "Skip";
4519 navInfo.skipToken = SKIP_TOKEN;
4520 }
4521
4522 displayGenericContextPage(0, true);
4523}
4524
4536 nbgl_choiceCallback_t choiceCallback)
4537{
4538 nbgl_useCaseReviewStreamingContinueExt(tagValueList, choiceCallback, NULL);
4539}
4540
4549void nbgl_useCaseReviewStreamingFinish(const char *finishTitle,
4550 nbgl_choiceCallback_t choiceCallback)
4551{
4552 // Should follow a call to nbgl_useCaseReviewStreamingContinue
4553 memset(&genericContext, 0, sizeof(genericContext));
4554
4555 bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
4556
4557 // memorize context
4558 onChoice = bundleNavReviewStreamingChoice;
4559 navType = STREAMING_NAV;
4560 pageTitle = NULL;
4561
4562 genericContext.genericContents.contentsList = localContentsList;
4563 genericContext.genericContents.nbContents = 1;
4564 memset(localContentsList, 0, 1 * sizeof(nbgl_content_t));
4565
4566 // Eventually the long press page
4567 STARTING_CONTENT.type = INFO_LONG_PRESS;
4568 prepareReviewLastPage(bundleNavContext.reviewStreaming.operationType,
4569 &STARTING_CONTENT.content.infoLongPress,
4570 bundleNavContext.reviewStreaming.icon,
4571 finishTitle);
4572
4573 // compute number of pages & fill navigation structure
4574 bundleNavContext.reviewStreaming.stepPageNb = getNbPagesForGenericContents(
4575 &genericContext.genericContents,
4576 0,
4577 (bundleNavContext.reviewStreaming.operationType & SKIPPABLE_OPERATION));
4578 prepareNavInfo(true, 1, getRejectReviewText(bundleNavContext.reviewStreaming.operationType));
4579
4580 displayGenericContextPage(0, true);
4581}
4582
4587void nbgl_useCaseAddressConfirmationExt(const char *address,
4588 nbgl_choiceCallback_t callback,
4589 const nbgl_contentTagValueList_t *tagValueList)
4590{
4591 reset_callbacks_and_context();
4592 memset(&addressConfirmationContext, 0, sizeof(addressConfirmationContext));
4593
4594 // save context
4595 onChoice = callback;
4596 navType = GENERIC_NAV;
4597 pageTitle = NULL;
4598
4599 genericContext.genericContents.contentsList = localContentsList;
4600 genericContext.genericContents.nbContents = (tagValueList == NULL) ? 1 : 2;
4601 memset(localContentsList, 0, 2 * sizeof(nbgl_content_t));
4602 prepareAddressConfirmationPages(
4603 address, tagValueList, &STARTING_CONTENT, &localContentsList[1]);
4604
4605 // fill navigation structure, common to all pages
4606 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
4607
4608 prepareNavInfo(true, nbPages, "Cancel");
4609
4610#ifdef HAVE_PIEZO_SOUND
4611 // Play notification sound
4612 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
4613#endif // HAVE_PIEZO_SOUND
4614
4615 displayGenericContextPage(0, true);
4616}
4617
4634void nbgl_useCaseAddressReview(const char *address,
4635 const nbgl_contentTagValueList_t *additionalTagValueList,
4636 const nbgl_icon_details_t *icon,
4637 const char *reviewTitle,
4638 const char *reviewSubTitle,
4639 nbgl_choiceCallback_t choiceCallback)
4640{
4641 reset_callbacks_and_context();
4642
4643 // release a potential modal
4644 if (addressConfirmationContext.modalLayout) {
4645 nbgl_layoutRelease(addressConfirmationContext.modalLayout);
4646 }
4647 memset(&addressConfirmationContext, 0, sizeof(addressConfirmationContext));
4648
4649 // save context
4650 onChoice = choiceCallback;
4651 navType = GENERIC_NAV;
4652 pageTitle = NULL;
4653 bundleNavContext.review.operationType = TYPE_OPERATION;
4654
4655 genericContext.genericContents.contentsList = localContentsList;
4656 memset(localContentsList, 0, 3 * sizeof(nbgl_content_t));
4657
4658 // First a centered info
4659 STARTING_CONTENT.type = EXTENDED_CENTER;
4660 prepareReviewFirstPage(
4661 &STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
4662 STARTING_CONTENT.content.extendedCenter.contentCenter.subText = "Swipe to continue";
4663
4664 // Then the address confirmation pages
4665 prepareAddressConfirmationPages(
4666 address, additionalTagValueList, &localContentsList[1], &localContentsList[2]);
4667
4668 // fill navigation structure, common to all pages
4669 genericContext.genericContents.nbContents
4670 = (localContentsList[2].type == TAG_VALUE_CONFIRM) ? 3 : 2;
4671 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
4672
4673 prepareNavInfo(true, nbPages, "Cancel");
4674
4675#ifdef HAVE_PIEZO_SOUND
4676 // Play notification sound
4677 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
4678#endif // HAVE_PIEZO_SOUND
4679
4680 displayGenericContextPage(0, true);
4681}
4682
4691void nbgl_useCaseSpinner(const char *text)
4692{
4693 // if the previous Use Case was not Spinner, fresh start
4694 if (genericContext.type != USE_CASE_SPINNER) {
4695 memset(&genericContext, 0, sizeof(genericContext));
4696 genericContext.type = USE_CASE_SPINNER;
4697 nbgl_layoutDescription_t layoutDescription = {0};
4698
4699 layoutDescription.withLeftBorder = true;
4700
4701 genericContext.backgroundLayout = nbgl_layoutGet(&layoutDescription);
4702
4703 nbgl_layoutAddSpinner(
4704 genericContext.backgroundLayout, text, NULL, genericContext.spinnerPosition);
4705
4706 nbgl_layoutDraw(genericContext.backgroundLayout);
4708 }
4709 else {
4710 // otherwise increment spinner
4711 genericContext.spinnerPosition++;
4712 // there are only NB_SPINNER_POSITIONSpositions
4713 if (genericContext.spinnerPosition == NB_SPINNER_POSITIONS) {
4714 genericContext.spinnerPosition = 0;
4715 }
4716 int ret = nbgl_layoutUpdateSpinner(
4717 genericContext.backgroundLayout, text, NULL, genericContext.spinnerPosition);
4718 if (ret == 1) {
4720 }
4721 else if (ret == 2) {
4723 }
4724 }
4725}
4726
4727#ifdef NBGL_KEYPAD
4746void nbgl_useCaseKeypad(const char *title,
4747 uint8_t minDigits,
4748 uint8_t maxDigits,
4749 bool shuffled,
4750 bool hidden,
4751 nbgl_pinValidCallback_t validatePinCallback,
4752 nbgl_callback_t backCallback)
4753{
4754 nbgl_layoutDescription_t layoutDescription = {0};
4755 nbgl_layoutHeader_t headerDesc = {.type = HEADER_BACK_AND_TEXT,
4756 .separationLine = true,
4757 .backAndText.token = BACK_TOKEN,
4758 .backAndText.tuneId = TUNE_TAP_CASUAL};
4759 int status = -1;
4760
4761 if ((minDigits > KEYPAD_MAX_DIGITS) || (maxDigits > KEYPAD_MAX_DIGITS)) {
4762 return;
4763 }
4764
4765 reset_callbacks_and_context();
4766 // reset the keypad context
4767 memset(&keypadContext, 0, sizeof(KeypadContext_t));
4768
4769 // memorize context
4770 onQuit = backCallback;
4771
4772 // get a layout
4773 layoutDescription.onActionCallback = keypadGeneric_cb;
4774 keypadContext.layoutCtx = nbgl_layoutGet(&layoutDescription);
4775 keypadContext.hidden = hidden;
4776
4777 // set back key in header
4778 nbgl_layoutAddHeader(keypadContext.layoutCtx, &headerDesc);
4779
4780 // add keypad
4781 status = nbgl_layoutAddKeypad(keypadContext.layoutCtx, keypadCallback, shuffled);
4782 if (status < 0) {
4783 return;
4784 }
4785 // add keypad content
4787 keypadContext.layoutCtx, title, keypadContext.hidden, maxDigits, "");
4788 if (status < 0) {
4789 return;
4790 }
4791
4792 // validation pin callback
4793 keypadContext.onValidatePin = validatePinCallback;
4794 // pin code acceptable lengths
4795 keypadContext.pinMinDigits = minDigits;
4796 keypadContext.pinMaxDigits = maxDigits;
4797
4798 nbgl_layoutDraw(keypadContext.layoutCtx);
4800}
4801#endif // NBGL_KEYPAD
4802
4803#ifdef NBGL_KEYBOARD
4831void nbgl_useCaseKeyboard(const nbgl_keyboardParams_t *params, nbgl_callback_t backCallback)
4832{
4833 // clang-format off
4834 nbgl_layoutDescription_t layoutDescription = {.onActionCallback = keyboardGeneric_cb};
4835 nbgl_layoutHeader_t headerDesc = {.type = HEADER_BACK_AND_TEXT,
4836 .backAndText.token = BACK_TOKEN,
4837 .backAndText.tuneId = TUNE_TAP_CASUAL};
4838 nbgl_layoutKbd_t kbdInfo = {.callback = &keyboardCallback,
4839 .lettersOnly = params->lettersOnly,
4840 .mode = params->mode,
4841 .casing = params->casing};
4842 int status = -1;
4843 // clang-format on
4844
4845 reset_callbacks_and_context();
4846 // reset the keyboard context
4847 memset(&keyboardContext, 0, sizeof(KeyboardContext_t));
4848
4849 // memorize context
4850 onQuit = backCallback;
4851
4852 // get a layout
4853 keyboardContext.layoutCtx = nbgl_layoutGet(&layoutDescription);
4854
4855 // set back key in header
4856 nbgl_layoutAddHeader(keyboardContext.layoutCtx, &headerDesc);
4857
4858 // Add keyboard
4859 status = nbgl_layoutAddKeyboard(keyboardContext.layoutCtx, &kbdInfo);
4860 if (status < 0) {
4861 return;
4862 }
4863 keyboardContext.keyboardIndex = status;
4864 keyboardContext.casing = params->casing;
4865 keyboardContext.entryBuffer = PIC(params->entryBuffer);
4866 keyboardContext.entryMaxLen = params->entryMaxLen;
4867 keyboardContext.entryBuffer[0] = '\0';
4868 // add keyboard content
4869 keyboardContext.keyboardContent = (nbgl_layoutKeyboardContent_t){
4870 .type = params->type,
4871 .title = PIC(params->title),
4872 .numbered = params->numbered,
4873 .number = params->number,
4874 .obfuscated = params->obfuscated,
4875 .text = keyboardContext.entryBuffer,
4876 .textToken = KEYBOARD_CROSS_TOKEN,
4877 .tuneId = TUNE_TAP_CASUAL,
4878 };
4879 switch (params->type) {
4881 onAction = PIC(params->confirmationParams.onButtonCallback);
4882 keyboardContext.keyboardContent.confirmationButton = (nbgl_layoutConfirmationButton_t){
4883 .text = PIC(params->confirmationParams.buttonText),
4884 .token = KEYBOARD_BUTTON_TOKEN,
4885 .active = true,
4886 };
4887 break;
4889 onControls = PIC(params->suggestionParams.onButtonCallback);
4890 keyboardContext.getSuggestionButtons
4892 keyboardContext.keyboardContent.suggestionButtons = (nbgl_layoutSuggestionButtons_t){
4893 .buttons = PIC(params->suggestionParams.buttons),
4894 .firstButtonToken = params->suggestionParams.firstButtonToken,
4895 };
4896 break;
4897 default:
4898 return;
4899 }
4900 status = nbgl_layoutAddKeyboardContent(keyboardContext.layoutCtx,
4901 &keyboardContext.keyboardContent);
4902 if (status < 0) {
4903 return;
4904 }
4905
4906 nbgl_layoutDraw(keyboardContext.layoutCtx);
4908}
4909#endif // NBGL_KEYBOARD
4910
4911#endif // HAVE_SE_TOUCH
4912#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:622
#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
const char * value
string giving the value name
const char * item
string giving the tag name
uint8_t centeredInfo
if set to 1, the tag will be displayed as a centered info
This structure contains additions to a tag/value pair, to be able to build a screen to display these ...
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.
const char * text
text (can be NULL)
uint8_t token
the token that will be used as argument of the callback
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_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