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 reviewWithWarnCtx sharedContext.reviewWithWarning
59#define choiceWithDetailsCtx sharedContext.choiceWithDetails
60
61/* max length of the string displaying the description of the Web3 Checks report */
62#define W3C_DESCRIPTION_MAX_LEN 128
63
69#define RISKY_OPERATION (1 << 6)
70
76#define NO_THREAT_OPERATION (1 << 7)
77
78/**********************
79 * TYPEDEFS
80 **********************/
81enum {
82 BACK_TOKEN = 0,
83 NEXT_TOKEN,
84 QUIT_TOKEN,
85 NAV_TOKEN,
86 MODAL_NAV_TOKEN,
87 SKIP_TOKEN,
88 CONTINUE_TOKEN,
89 ADDRESS_QRCODE_BUTTON_TOKEN,
90 ACTION_BUTTON_TOKEN,
91 CHOICE_TOKEN,
92 DETAILS_BUTTON_TOKEN,
93 CONFIRM_TOKEN,
94 REJECT_TOKEN,
95 VALUE_ALIAS_TOKEN,
96 INFO_ALIAS_TOKEN,
97 INFOS_TIP_BOX_TOKEN,
98 BLIND_WARNING_TOKEN,
99 WARNING_BUTTON_TOKEN,
100 CHOICE_DETAILS_TOKEN,
101 TIP_BOX_TOKEN,
102 QUIT_TIPBOX_MODAL_TOKEN,
103 WARNING_CHOICE_TOKEN,
104 DISMISS_QR_TOKEN,
105 DISMISS_WARNING_TOKEN,
106 DISMISS_DETAILS_TOKEN,
107 PRELUDE_CHOICE_TOKEN,
108 FIRST_WARN_BAR_TOKEN,
109 LAST_WARN_BAR_TOKEN = (FIRST_WARN_BAR_TOKEN + NB_WARNING_TYPES - 1),
110};
111
112typedef enum {
113 REVIEW_NAV = 0,
114 SETTINGS_NAV,
115 GENERIC_NAV,
116 STREAMING_NAV
117} NavType_t;
118
119typedef struct DetailsContext_s {
120 uint8_t nbPages;
121 uint8_t currentPage;
122 uint8_t currentPairIdx;
123 bool wrapping;
124 const char *tag;
125 const char *value;
126 const char *nextPageStart;
127} DetailsContext_t;
128
129typedef struct AddressConfirmationContext_s {
130 nbgl_layoutTagValue_t tagValuePairs[ADDR_VERIF_NB_PAIRS];
131 nbgl_layout_t *modalLayout;
132 uint8_t nbPairs;
133} AddressConfirmationContext_t;
134
135#ifdef NBGL_KEYPAD
136typedef struct KeypadContext_s {
137 uint8_t pinEntry[KEYPAD_MAX_DIGITS];
138 uint8_t pinLen;
139 uint8_t pinMinDigits;
140 uint8_t pinMaxDigits;
141 nbgl_layout_t *layoutCtx;
142 bool hidden;
143} KeypadContext_t;
144#endif
145
146typedef struct ReviewWithWarningContext_s {
147 bool isStreaming;
148 nbgl_operationType_t operationType;
149 const nbgl_contentTagValueList_t *tagValueList;
150 const nbgl_icon_details_t *icon;
151 const char *reviewTitle;
152 const char *reviewSubTitle;
153 const char *finishTitle;
154 const nbgl_warning_t *warning;
155 nbgl_choiceCallback_t choiceCallback;
156 nbgl_layout_t *layoutCtx;
157 nbgl_layout_t *modalLayout;
158 uint8_t securityReportLevel; // level 1 is the first level of menus
159 bool isIntro; // set to true during intro (before actual review)
160} ReviewWithWarningContext_t;
161
162typedef struct ChoiceWithDetailsContext_s {
163 const nbgl_genericDetails_t *details;
164 nbgl_layout_t *layoutCtx;
165 nbgl_layout_t *modalLayout;
166 uint8_t level; // level 1 is the first level of menus
167} ChoiceWithDetailsContext_t;
168
169typedef enum {
170 SHARE_CTX_KEYPAD,
171 SHARE_CTX_REVIEW_WITH_WARNING,
172 SHARE_CTX_CHOICE_WITH_DETAILS,
173} SharedContextUsage_t;
174
175// this union is intended to save RAM for context storage
176// indeed, these 3 contexts cannot happen simultaneously
177typedef struct {
178 union {
179#ifdef NBGL_KEYPAD
180 KeypadContext_t keypad;
181#endif
182 ReviewWithWarningContext_t reviewWithWarning;
183 ChoiceWithDetailsContext_t choiceWithDetails;
184 };
185 SharedContextUsage_t usage;
186} SharedContext_t;
187
188typedef enum {
189 USE_CASE_GENERIC = 0,
190 USE_CASE_SPINNER
191} GenericContextType_t;
192
193typedef struct {
194 GenericContextType_t type; // type of Generic context usage
195 uint8_t spinnerPosition;
196 nbgl_genericContents_t genericContents;
197 int8_t currentContentIdx;
198 uint8_t currentContentElementNb;
199 uint8_t currentElementIdx;
200 bool hasStartingContent;
201 bool hasFinishingContent;
202 const char *detailsItem;
203 const char *detailsvalue;
204 bool detailsWrapping;
205 bool validWarningCtx; // set to true if the WarningContext is valid
207 *currentPairs; // to be used to retrieve the pairs with value alias
209 currentCallback; // to be used to retrieve the pairs with value alias
210 nbgl_layout_t modalLayout;
211 nbgl_layout_t backgroundLayout;
212 const nbgl_contentInfoList_t *currentInfos;
213 const nbgl_contentTagValueList_t *currentTagValues;
214 nbgl_tipBox_t tipBox;
215 SharedContext_t sharedCtx; // multi-purpose context shared for non-concurrent usages
216} GenericContext_t;
217
218typedef struct {
219 const char *appName;
220 const nbgl_icon_details_t *appIcon;
221 const char *tagline;
222 const nbgl_genericContents_t *settingContents;
223 const nbgl_contentInfoList_t *infosList;
224 nbgl_homeAction_t homeAction;
225 nbgl_callback_t quitCallback;
226} nbgl_homeAndSettingsContext_t;
227
228typedef struct {
229 nbgl_operationType_t operationType;
230 nbgl_choiceCallback_t choiceCallback;
231} nbgl_reviewContext_t;
232
233typedef struct {
234 nbgl_operationType_t operationType;
235 nbgl_choiceCallback_t choiceCallback;
236 nbgl_callback_t skipCallback;
237 const nbgl_icon_details_t *icon;
238 uint8_t stepPageNb;
239} nbgl_reviewStreamingContext_t;
240
241typedef union {
242 nbgl_homeAndSettingsContext_t homeAndSettings;
243 nbgl_reviewContext_t review;
244 nbgl_reviewStreamingContext_t reviewStreaming;
245} nbgl_BundleNavContext_t;
246
247typedef struct {
248 const nbgl_icon_details_t *icon;
249 const char *text;
250 const char *subText;
251} SecurityReportItem_t;
252
253/**********************
254 * STATIC VARIABLES
255 **********************/
256
257// char buffers to build some strings
258static char tmpString[W3C_DESCRIPTION_MAX_LEN];
259
260// multi-purposes callbacks
261static nbgl_callback_t onQuit;
262static nbgl_callback_t onContinue;
263static nbgl_callback_t onAction;
264static nbgl_navCallback_t onNav;
265static nbgl_layoutTouchCallback_t onControls;
266static nbgl_contentActionCallback_t onContentAction;
267static nbgl_choiceCallback_t onChoice;
268static nbgl_callback_t onModalConfirm;
269#ifdef NBGL_KEYPAD
270static nbgl_pinValidCallback_t onValidatePin;
271#endif
272
273// contexts for background and modal pages
274static nbgl_page_t *pageContext;
275static nbgl_page_t *modalPageContext;
276
277// context for pages
278static const char *pageTitle;
279
280// context for tip-box
281#define activeTipBox genericContext.tipBox
282
283// context for navigation use case
284static nbgl_pageNavigationInfo_t navInfo;
285static bool forwardNavOnly;
286static NavType_t navType;
287
288static DetailsContext_t detailsContext;
289
290// context for address review
291static AddressConfirmationContext_t addressConfirmationContext;
292
293// contexts for generic navigation
294static GenericContext_t genericContext;
295static nbgl_content_t
296 localContentsList[3]; // 3 needed for nbgl_useCaseReview (starting page / tags / final page)
297static uint8_t genericContextPagesInfo[MAX_PAGE_NB / PAGES_PER_UINT8];
298static uint8_t modalContextPagesInfo[MAX_MODAL_PAGE_NB / PAGES_PER_UINT8];
299
300// contexts for bundle navigation
301static nbgl_BundleNavContext_t bundleNavContext;
302
303// indexed by nbgl_contentType_t
304static const uint8_t nbMaxElementsPerContentType[] = {
305 1, // CENTERED_INFO
306 1, // EXTENDED_CENTER
307 1, // INFO_LONG_PRESS
308 1, // INFO_BUTTON
309 1, // TAG_VALUE_LIST (computed dynamically)
310 1, // TAG_VALUE_DETAILS
311 1, // TAG_VALUE_CONFIRM
312 3, // SWITCHES_LIST (computed dynamically)
313 3, // INFOS_LIST (computed dynamically)
314 5, // CHOICES_LIST (computed dynamically)
315 5, // BARS_LIST (computed dynamically)
316};
317
318// clang-format off
319static const SecurityReportItem_t securityReportItems[NB_WARNING_TYPES] = {
321 .icon = &WARNING_ICON,
322 .text = "Blind signing required",
323 .subText = "This transaction's details are not fully verifiable. If "
324 "you sign, you could lose all your assets."
325 },
326 [W3C_ISSUE_WARN] = {
327 .icon = &WARNING_ICON,
328 .text = "Transaction Check unavailable",
329 .subText = NULL
330 },
332 .icon = &WARNING_ICON,
333 .text = "Risk detected",
334 .subText = "This transaction was scanned as risky by Web3 Checks."
335 },
337 .icon = &WARNING_ICON,
338 .text = "Critical threat",
339 .subText = "This transaction was scanned as malicious by Web3 Checks."
340 },
342 .icon = NULL,
343 .text = "No threat detected",
344 .subText = "Transaction Check didn't find any threat, but always "
345 "review transaction details carefully."
346 }
347};
348// clang-format on
349
350// configuration of warning when using @ref nbgl_useCaseReviewBlindSigning()
351static const nbgl_warning_t blindSigningWarning = {.predefinedSet = (1 << BLIND_SIGNING_WARN)};
352
353#ifdef NBGL_QRCODE
354/* buffer to store reduced address under QR Code */
355static char reducedAddress[QRCODE_REDUCED_ADDR_LEN];
356#endif // NBGL_QRCODE
357
358/**********************
359 * STATIC FUNCTIONS
360 **********************/
361static void displayReviewPage(uint8_t page, bool forceFullRefresh);
362static void displayDetailsPage(uint8_t page, bool forceFullRefresh);
363static void displayTagValueListModalPage(uint8_t pageIdx, bool forceFullRefresh);
364static void displayFullValuePage(const char *backText,
365 const char *aliasText,
366 const nbgl_contentValueExt_t *extension);
367static void displayInfosListModal(const char *modalTitle,
368 const nbgl_contentInfoList_t *infos,
369 bool fromReview);
370static void displayTagValueListModal(const nbgl_contentTagValueList_t *tagValues);
371static void displaySettingsPage(uint8_t page, bool forceFullRefresh);
372static void displayGenericContextPage(uint8_t pageIdx, bool forceFullRefresh);
373static void pageCallback(int token, uint8_t index);
374#ifdef NBGL_QRCODE
375static void displayAddressQRCode(void);
376#endif // NBGL_QRCODE
377static void modalLayoutTouchCallback(int token, uint8_t index);
378static void displaySkipWarning(void);
379
380static void bundleNavStartHome(void);
381static void bundleNavStartSettingsAtPage(uint8_t initSettingPage);
382static void bundleNavStartSettings(void);
383
384static void bundleNavReviewStreamingChoice(bool confirm);
385static nbgl_layout_t *displayModalDetails(const nbgl_warningDetails_t *details, uint8_t token);
386static void displaySecurityReport(uint32_t set);
387static void displayCustomizedSecurityReport(const nbgl_warningDetails_t *details);
388static void displayInitialWarning(void);
389static void useCaseReview(nbgl_operationType_t operationType,
390 const nbgl_contentTagValueList_t *tagValueList,
391 const nbgl_icon_details_t *icon,
392 const char *reviewTitle,
393 const char *reviewSubTitle,
394 const char *finishTitle,
395 const nbgl_tipBox_t *tipBox,
396 nbgl_choiceCallback_t choiceCallback,
397 bool isLight,
398 bool playNotifSound);
399static void useCaseReviewStreamingStart(nbgl_operationType_t operationType,
400 const nbgl_icon_details_t *icon,
401 const char *reviewTitle,
402 const char *reviewSubTitle,
403 nbgl_choiceCallback_t choiceCallback,
404 bool playNotifSound);
405static void useCaseHomeExt(const char *appName,
406 const nbgl_icon_details_t *appIcon,
407 const char *tagline,
408 bool withSettings,
409 nbgl_homeAction_t *homeAction,
410 nbgl_callback_t topRightCallback,
411 nbgl_callback_t quitCallback);
412static void displayDetails(const char *tag, const char *value, bool wrapping);
413
414static void reset_callbacks_and_context(void)
415{
416 onQuit = NULL;
417 onContinue = NULL;
418 onAction = NULL;
419 onNav = NULL;
420 onControls = NULL;
421 onContentAction = NULL;
422 onChoice = NULL;
423#ifdef NBGL_KEYPAD
424 onValidatePin = NULL;
425#endif
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 infoButton->buttonText = "Approve";
590 infoButton->buttonToken = CONFIRM_TOKEN;
591}
592
593static const char *getRejectReviewText(nbgl_operationType_t operationType)
594{
595 UNUSED(operationType);
596 return "Reject";
597}
598
599// function called when navigating (or exiting) modal details pages
600// or when skip choice is displayed
601static void pageModalCallback(int token, uint8_t index)
602{
603 LOG_DEBUG(USE_CASE_LOGGER, "pageModalCallback, token = %d, index = %d\n", token, index);
604
605 if (token == INFOS_TIP_BOX_TOKEN) {
606 // the icon next to info type alias has been touched
607 displayFullValuePage(activeTipBox.infos.infoTypes[index],
608 activeTipBox.infos.infoContents[index],
609 &activeTipBox.infos.infoExtensions[index]);
610 return;
611 }
612 else if (token == INFO_ALIAS_TOKEN) {
613 // the icon next to info type alias has been touched, but coming from review
614 displayFullValuePage(genericContext.currentInfos->infoTypes[index],
615 genericContext.currentInfos->infoContents[index],
616 &genericContext.currentInfos->infoExtensions[index]);
617 return;
618 }
619 nbgl_pageRelease(modalPageContext);
620 modalPageContext = NULL;
621 if (token == NAV_TOKEN) {
622 if (index == EXIT_PAGE) {
623 // redraw the background layer
625 nbgl_refresh();
626 }
627 else {
628 displayDetailsPage(index, false);
629 }
630 }
631 if (token == MODAL_NAV_TOKEN) {
632 if (index == EXIT_PAGE) {
633 // redraw the background layer
635 nbgl_refresh();
636 }
637 else {
638 displayTagValueListModalPage(index, false);
639 }
640 }
641 else if (token == QUIT_TOKEN) {
642 // redraw the background layer
644 nbgl_refresh();
645 }
646 else if (token == QUIT_TIPBOX_MODAL_TOKEN) {
647 // if in "warning context", go back to security report
648 if (reviewWithWarnCtx.securityReportLevel == 2) {
649 reviewWithWarnCtx.securityReportLevel = 1;
650 displaySecurityReport(reviewWithWarnCtx.warning->predefinedSet);
651 }
652 else {
653 // redraw the background layer
655 nbgl_refresh();
656 }
657 }
658 else if (token == SKIP_TOKEN) {
659 if (index == 0) {
660 // display the last forward only review page, whatever it is
661 displayGenericContextPage(LAST_PAGE_FOR_REVIEW, true);
662 }
663 else {
664 // display background, which should be the page where skip has been touched
666 nbgl_refresh();
667 }
668 }
669 else if (token == CHOICE_TOKEN) {
670 if (index == 0) {
671 if (onModalConfirm != NULL) {
672 onModalConfirm();
673 onModalConfirm = NULL;
674 }
675 }
676 else {
677 // display background, which should be the page where skip has been touched
679 nbgl_refresh();
680 }
681 }
682}
683
684// generic callback for all pages except modal
685static void pageCallback(int token, uint8_t index)
686{
687 LOG_DEBUG(USE_CASE_LOGGER, "pageCallback, token = %d, index = %d\n", token, index);
688 if (token == QUIT_TOKEN) {
689 if (onQuit != NULL) {
690 onQuit();
691 }
692 }
693 else if (token == CONTINUE_TOKEN) {
694 if (onContinue != NULL) {
695 onContinue();
696 }
697 }
698 else if (token == CHOICE_TOKEN) {
699 if (onChoice != NULL) {
700 onChoice((index == 0) ? true : false);
701 }
702 }
703 else if (token == ACTION_BUTTON_TOKEN) {
704 if ((index == 0) && (onAction != NULL)) {
705 onAction();
706 }
707 else if ((index == 1) && (onQuit != NULL)) {
708 onQuit();
709 }
710 }
711#ifdef NBGL_QRCODE
712 else if (token == ADDRESS_QRCODE_BUTTON_TOKEN) {
713 displayAddressQRCode();
714 }
715#endif // NBGL_QRCODE
716 else if (token == CONFIRM_TOKEN) {
717 if (onChoice != NULL) {
718 onChoice(true);
719 }
720 }
721 else if (token == REJECT_TOKEN) {
722 if (onChoice != NULL) {
723 onChoice(false);
724 }
725 }
726 else if (token == DETAILS_BUTTON_TOKEN) {
727 displayDetails(genericContext.detailsItem,
728 genericContext.detailsvalue,
729 genericContext.detailsWrapping);
730 }
731 else if (token == NAV_TOKEN) {
732 if (index == EXIT_PAGE) {
733 if (onQuit != NULL) {
734 onQuit();
735 }
736 }
737 else {
738 if (navType == GENERIC_NAV || navType == STREAMING_NAV) {
739 displayGenericContextPage(index, false);
740 }
741 else if (navType == REVIEW_NAV) {
742 displayReviewPage(index, false);
743 }
744 else {
745 displaySettingsPage(index, false);
746 }
747 }
748 }
749 else if (token == NEXT_TOKEN) {
750 if (onNav != NULL) {
751 displayReviewPage(navInfo.activePage + 1, false);
752 }
753 else {
754 displayGenericContextPage(navInfo.activePage + 1, false);
755 }
756 }
757 else if (token == BACK_TOKEN) {
758 if (onNav != NULL) {
759 displayReviewPage(navInfo.activePage - 1, true);
760 }
761 else {
762 displayGenericContextPage(navInfo.activePage - 1, false);
763 }
764 }
765 else if (token == SKIP_TOKEN) {
766 // display a modal warning to confirm skip
767 displaySkipWarning();
768 }
769 else if (token == VALUE_ALIAS_TOKEN) {
770 // the icon next to value alias has been touched
771 const nbgl_contentTagValue_t *pair;
772 if (genericContext.currentPairs != NULL) {
773 pair = &genericContext.currentPairs[genericContext.currentElementIdx + index];
774 }
775 else {
776 pair = genericContext.currentCallback(genericContext.currentElementIdx + index);
777 }
778 displayFullValuePage(pair->item, pair->value, pair->extension);
779 }
780 else if (token == BLIND_WARNING_TOKEN) {
781 reviewWithWarnCtx.isIntro = false;
782 reviewWithWarnCtx.warning = NULL;
783 displaySecurityReport(1 << BLIND_SIGNING_WARN);
784 }
785 else if (token == WARNING_BUTTON_TOKEN) {
786 // top-right button, display the security modal
787 reviewWithWarnCtx.securityReportLevel = 1;
788 // if preset is used
789 if (reviewWithWarnCtx.warning->predefinedSet) {
790 displaySecurityReport(reviewWithWarnCtx.warning->predefinedSet);
791 }
792 else {
793 // use customized warning
794 if (reviewWithWarnCtx.isIntro) {
795 displayCustomizedSecurityReport(reviewWithWarnCtx.warning->introDetails);
796 }
797 else {
798 displayCustomizedSecurityReport(reviewWithWarnCtx.warning->reviewDetails);
799 }
800 }
801 }
802 else if (token == TIP_BOX_TOKEN) {
803 // if warning context is valid and if W3C directly display same as top-right
804 if (genericContext.validWarningCtx && (reviewWithWarnCtx.warning->predefinedSet != 0)) {
805 reviewWithWarnCtx.securityReportLevel = 1;
806 displaySecurityReport(reviewWithWarnCtx.warning->predefinedSet);
807 }
808 else {
809 displayInfosListModal(activeTipBox.modalTitle, &activeTipBox.infos, false);
810 }
811 }
812 else { // probably a control provided by caller
813 if (onContentAction != NULL) {
814 onContentAction(token, index, navInfo.activePage);
815 }
816 if (onControls != NULL) {
817 onControls(token, index);
818 }
819 }
820}
821
822// callback used for confirmation
823static void tickerCallback(void)
824{
825 nbgl_pageRelease(pageContext);
826 if (onQuit != NULL) {
827 onQuit();
828 }
829}
830
831// function used to display the current page in review
832static void displaySettingsPage(uint8_t page, bool forceFullRefresh)
833{
834 nbgl_pageContent_t content = {0};
835
836 if ((onNav == NULL) || (onNav(page, &content) == false)) {
837 return;
838 }
839
840 // override some fields
841 content.title = pageTitle;
842 content.isTouchableTitle = true;
843 content.titleToken = QUIT_TOKEN;
844 content.tuneId = TUNE_TAP_CASUAL;
845
846 navInfo.activePage = page;
847 pageContext = nbgl_pageDrawGenericContent(&pageCallback, &navInfo, &content);
848
849 if (forceFullRefresh) {
851 }
852 else {
854 }
855}
856
857// function used to display the current page in review
858static void displayReviewPage(uint8_t page, bool forceFullRefresh)
859{
860 nbgl_pageContent_t content = {0};
861
862 // ensure the page is valid
863 if ((navInfo.nbPages != 0) && (page >= (navInfo.nbPages))) {
864 return;
865 }
866 navInfo.activePage = page;
867 if ((onNav == NULL) || (onNav(navInfo.activePage, &content) == false)) {
868 return;
869 }
870
871 // override some fields
872 content.title = NULL;
873 content.isTouchableTitle = false;
874 content.tuneId = TUNE_TAP_CASUAL;
875
876 if (content.type == INFO_LONG_PRESS) { // last page
877 // for forward only review without known length...
878 // if we don't do that we cannot remove the '>' in the navigation bar at the last page
879 navInfo.nbPages = navInfo.activePage + 1;
880 content.infoLongPress.longPressToken = CONFIRM_TOKEN;
881 if (forwardNavOnly) {
882 // remove the "Skip" button
883 navInfo.skipText = NULL;
884 }
885 }
886
887 // override smallCaseForValue for tag/value types to false
888 if (content.type == TAG_VALUE_DETAILS) {
890 // the maximum displayable number of lines for value is NB_MAX_LINES_IN_REVIEW (without More
891 // button)
894 }
895 else if (content.type == TAG_VALUE_LIST) {
896 content.tagValueList.smallCaseForValue = false;
897 }
898 else if (content.type == TAG_VALUE_CONFIRM) {
900 // use confirm token for black button
901 content.tagValueConfirm.confirmationToken = CONFIRM_TOKEN;
902 }
903
904 pageContext = nbgl_pageDrawGenericContent(&pageCallback, &navInfo, &content);
905
906 if (forceFullRefresh) {
908 }
909 else {
911 }
912}
913
914// Helper that does the computing of which nbgl_content_t and which element in the content should be
915// displayed for the next generic context navigation page
916static const nbgl_content_t *genericContextComputeNextPageParams(uint8_t pageIdx,
917 nbgl_content_t *content,
918 uint8_t *p_nbElementsInNextPage,
919 bool *p_flag)
920{
921 int8_t nextContentIdx = genericContext.currentContentIdx;
922 int16_t nextElementIdx = genericContext.currentElementIdx;
923 uint8_t nbElementsInNextPage;
924
925 // Retrieve info on the next page
926 genericContextGetPageInfo(pageIdx, &nbElementsInNextPage, p_flag);
927 *p_nbElementsInNextPage = nbElementsInNextPage;
928
929 // Handle forward navigation:
930 // add to current index the number of pairs of the currently active page
931 if (pageIdx > navInfo.activePage) {
932 uint8_t nbElementsInCurrentPage;
933
934 genericContextGetPageInfo(navInfo.activePage, &nbElementsInCurrentPage, NULL);
935 nextElementIdx += nbElementsInCurrentPage;
936
937 // Handle case where the content to be displayed is in the next content
938 // In such case start at element index 0.
939 // If currentContentElementNb == 0, means not initialized, so skip
940 if ((nextElementIdx >= genericContext.currentContentElementNb)
941 && (genericContext.currentContentElementNb > 0)) {
942 nextContentIdx += 1;
943 nextElementIdx = 0;
944 }
945 }
946
947 // Handle backward navigation:
948 // add to current index the number of pairs of the currently active page
949 if (pageIdx < navInfo.activePage) {
950 // Backward navigation: remove to current index the number of pairs of the current page
951 nextElementIdx -= nbElementsInNextPage;
952
953 // Handle case where the content to be displayed is in the previous content
954 // In such case set a negative number as element index so that it is handled
955 // later once the previous content is accessible so that its elements number
956 // can be retrieved.
957 if (nextElementIdx < 0) {
958 nextContentIdx -= 1;
959 nextElementIdx = -nbElementsInNextPage;
960 }
961 }
962
963 const nbgl_content_t *p_content;
964 // Retrieve next content
965 if ((nextContentIdx == -1) && (genericContext.hasStartingContent)) {
966 p_content = &STARTING_CONTENT;
967 }
968 else if ((nextContentIdx == genericContext.genericContents.nbContents)
969 && (genericContext.hasFinishingContent)) {
970 p_content = &FINISHING_CONTENT;
971 }
972 else {
973 p_content = getContentAtIdx(&genericContext.genericContents, nextContentIdx, content);
974
975 if (p_content == NULL) {
976 LOG_DEBUG(USE_CASE_LOGGER, "Fail to retrieve content\n");
977 return NULL;
978 }
979 }
980
981 // Handle cases where we are going to display data from a new content:
982 // - navigation to a previous or to the next content
983 // - First page display (genericContext.currentContentElementNb == 0)
984 //
985 // In such case we need to:
986 // - Update genericContext.currentContentIdx
987 // - Update genericContext.currentContentElementNb
988 // - Update onContentAction callback
989 // - Update nextElementIdx in case it was previously not calculable
990 if ((nextContentIdx != genericContext.currentContentIdx)
991 || (genericContext.currentContentElementNb == 0)) {
992 genericContext.currentContentIdx = nextContentIdx;
993 genericContext.currentContentElementNb = getContentNbElement(p_content);
994 onContentAction = PIC(p_content->contentActionCallback);
995 if (nextElementIdx < 0) {
996 nextElementIdx = genericContext.currentContentElementNb + nextElementIdx;
997 }
998 }
999
1000 // Sanity check
1001 if ((nextElementIdx < 0) || (nextElementIdx >= genericContext.currentContentElementNb)) {
1003 "Invalid element index %d / %d\n",
1004 nextElementIdx,
1005 genericContext.currentContentElementNb);
1006 return NULL;
1007 }
1008
1009 // Update genericContext elements
1010 genericContext.currentElementIdx = nextElementIdx;
1011 navInfo.activePage = pageIdx;
1012
1013 return p_content;
1014}
1015
1016// Helper that generates a nbgl_pageContent_t to be displayed for the next generic context
1017// navigation page
1018static bool genericContextPreparePageContent(const nbgl_content_t *p_content,
1019 uint8_t nbElementsInPage,
1020 bool flag,
1021 nbgl_pageContent_t *pageContent)
1022{
1023 uint8_t nextElementIdx = genericContext.currentElementIdx;
1024
1025 pageContent->title = pageTitle;
1026 pageContent->isTouchableTitle = false;
1027 pageContent->titleToken = QUIT_TOKEN;
1028 pageContent->tuneId = TUNE_TAP_CASUAL;
1029
1030 pageContent->type = p_content->type;
1031 switch (pageContent->type) {
1032 case CENTERED_INFO:
1033 memcpy(&pageContent->centeredInfo,
1034 &p_content->content.centeredInfo,
1035 sizeof(pageContent->centeredInfo));
1036 break;
1037 case EXTENDED_CENTER:
1038 memcpy(&pageContent->extendedCenter,
1039 &p_content->content.extendedCenter,
1040 sizeof(pageContent->extendedCenter));
1041 break;
1042 case INFO_LONG_PRESS:
1043 memcpy(&pageContent->infoLongPress,
1044 &p_content->content.infoLongPress,
1045 sizeof(pageContent->infoLongPress));
1046 break;
1047
1048 case INFO_BUTTON:
1049 memcpy(&pageContent->infoButton,
1050 &p_content->content.infoButton,
1051 sizeof(pageContent->infoButton));
1052 break;
1053
1054 case TAG_VALUE_LIST: {
1055 nbgl_contentTagValueList_t *p_tagValueList = &pageContent->tagValueList;
1056
1057 // memorize pairs (or callback) for usage when alias is used
1058 genericContext.currentPairs = p_content->content.tagValueList.pairs;
1059 genericContext.currentCallback = p_content->content.tagValueList.callback;
1060
1061 if (flag) {
1062 // Flag can be set if the pair is too long to fit or because it needs
1063 // to be displayed as centered info.
1064
1065 // First retrieve the pair
1066 const nbgl_layoutTagValue_t *pair;
1067
1068 if (p_content->content.tagValueList.pairs != NULL) {
1069 pair = PIC(&p_content->content.tagValueList.pairs[nextElementIdx]);
1070 }
1071 else {
1072 pair = PIC(p_content->content.tagValueList.callback(nextElementIdx));
1073 }
1074
1075 if (pair->centeredInfo) {
1076 pageContent->type = EXTENDED_CENTER;
1077 prepareReviewFirstPage(&pageContent->extendedCenter.contentCenter,
1078 pair->valueIcon,
1079 pair->item,
1080 pair->value);
1081
1082 // Skip population of nbgl_contentTagValueList_t structure
1083 p_tagValueList = NULL;
1084 }
1085 else {
1086 // if the pair is too long to fit, we use a TAG_VALUE_DETAILS content
1087 pageContent->type = TAG_VALUE_DETAILS;
1088 pageContent->tagValueDetails.detailsButtonText = "More";
1089 pageContent->tagValueDetails.detailsButtonIcon = NULL;
1090 pageContent->tagValueDetails.detailsButtonToken = DETAILS_BUTTON_TOKEN;
1091
1092 p_tagValueList = &pageContent->tagValueDetails.tagValueList;
1093
1094 // Backup pair info for easy data access upon click on button
1095 genericContext.detailsItem = pair->item;
1096 genericContext.detailsvalue = pair->value;
1097 genericContext.detailsWrapping = p_content->content.tagValueList.wrapping;
1098 }
1099 }
1100
1101 if (p_tagValueList != NULL) {
1102 p_tagValueList->nbPairs = nbElementsInPage;
1103 p_tagValueList->token = p_content->content.tagValueList.token;
1104 if (p_content->content.tagValueList.pairs != NULL) {
1105 p_tagValueList->pairs
1106 = PIC(&p_content->content.tagValueList.pairs[nextElementIdx]);
1107 // parse pairs to check if any contains an alias for value
1108 for (uint8_t i = 0; i < nbElementsInPage; i++) {
1109 if (p_tagValueList->pairs[i].aliasValue) {
1110 p_tagValueList->token = VALUE_ALIAS_TOKEN;
1111 break;
1112 }
1113 }
1114 }
1115 else {
1116 p_tagValueList->pairs = NULL;
1117 p_tagValueList->callback = p_content->content.tagValueList.callback;
1118 p_tagValueList->startIndex = nextElementIdx;
1119 // parse pairs to check if any contains an alias for value
1120 for (uint8_t i = 0; i < nbElementsInPage; i++) {
1121 const nbgl_layoutTagValue_t *pair
1122 = PIC(p_content->content.tagValueList.callback(nextElementIdx + i));
1123 if (pair->aliasValue) {
1124 p_tagValueList->token = VALUE_ALIAS_TOKEN;
1125 break;
1126 }
1127 }
1128 }
1129 p_tagValueList->smallCaseForValue = false;
1131 p_tagValueList->hideEndOfLastLine = true;
1132 p_tagValueList->wrapping = p_content->content.tagValueList.wrapping;
1133 }
1134
1135 break;
1136 }
1137 case TAG_VALUE_CONFIRM: {
1138 nbgl_contentTagValueList_t *p_tagValueList;
1139 // only display a TAG_VALUE_CONFIRM if we are at the last page
1140 if ((nextElementIdx + nbElementsInPage)
1142 memcpy(&pageContent->tagValueConfirm,
1143 &p_content->content.tagValueConfirm,
1144 sizeof(pageContent->tagValueConfirm));
1145 p_tagValueList = &pageContent->tagValueConfirm.tagValueList;
1146 }
1147 else {
1148 // else display it as a TAG_VALUE_LIST
1149 pageContent->type = TAG_VALUE_LIST;
1150 p_tagValueList = &pageContent->tagValueList;
1151 }
1152 p_tagValueList->nbPairs = nbElementsInPage;
1153 p_tagValueList->pairs
1154 = PIC(&p_content->content.tagValueConfirm.tagValueList.pairs[nextElementIdx]);
1155 // parse pairs to check if any contains an alias for value
1156 for (uint8_t i = 0; i < nbElementsInPage; i++) {
1157 if (p_tagValueList->pairs[i].aliasValue) {
1158 p_tagValueList->token = VALUE_ALIAS_TOKEN;
1159 break;
1160 }
1161 }
1162 // memorize pairs (or callback) for usage when alias is used
1163 genericContext.currentPairs = p_tagValueList->pairs;
1164 genericContext.currentCallback = p_tagValueList->callback;
1165 break;
1166 }
1167 case SWITCHES_LIST:
1168 pageContent->switchesList.nbSwitches = nbElementsInPage;
1169 pageContent->switchesList.switches
1170 = PIC(&p_content->content.switchesList.switches[nextElementIdx]);
1171 break;
1172 case INFOS_LIST:
1173 pageContent->infosList.nbInfos = nbElementsInPage;
1174 pageContent->infosList.infoTypes
1175 = PIC(&p_content->content.infosList.infoTypes[nextElementIdx]);
1176 pageContent->infosList.infoContents
1177 = PIC(&p_content->content.infosList.infoContents[nextElementIdx]);
1178 break;
1179 case CHOICES_LIST:
1180 memcpy(&pageContent->choicesList,
1181 &p_content->content.choicesList,
1182 sizeof(pageContent->choicesList));
1183 pageContent->choicesList.nbChoices = nbElementsInPage;
1184 pageContent->choicesList.names
1185 = PIC(&p_content->content.choicesList.names[nextElementIdx]);
1186 if ((p_content->content.choicesList.initChoice >= nextElementIdx)
1187 && (p_content->content.choicesList.initChoice
1188 < nextElementIdx + nbElementsInPage)) {
1189 pageContent->choicesList.initChoice
1190 = p_content->content.choicesList.initChoice - nextElementIdx;
1191 }
1192 else {
1193 pageContent->choicesList.initChoice = nbElementsInPage;
1194 }
1195 break;
1196 case BARS_LIST:
1197 pageContent->barsList.nbBars = nbElementsInPage;
1198 pageContent->barsList.barTexts
1199 = PIC(&p_content->content.barsList.barTexts[nextElementIdx]);
1200 pageContent->barsList.tokens = PIC(&p_content->content.barsList.tokens[nextElementIdx]);
1201 pageContent->barsList.tuneId = p_content->content.barsList.tuneId;
1202 break;
1203 default:
1204 LOG_DEBUG(USE_CASE_LOGGER, "Unsupported type %d\n", pageContent->type);
1205 return false;
1206 }
1207
1208 bool isFirstOrLastPage
1209 = ((p_content->type == CENTERED_INFO) || (p_content->type == EXTENDED_CENTER))
1210 || (p_content->type == INFO_LONG_PRESS);
1211 nbgl_operationType_t operationType
1212 = (navType == STREAMING_NAV)
1213 ? bundleNavContext.reviewStreaming.operationType
1214 : ((navType == GENERIC_NAV) ? bundleNavContext.review.operationType : 0);
1215
1216 // if first or last page of review and blind/risky operation, add the warning top-right button
1217 if (isFirstOrLastPage
1218 && (operationType & (BLIND_OPERATION | RISKY_OPERATION | NO_THREAT_OPERATION))) {
1219 // if issue is only Web3Checks "no threat", use privacy icon
1220 if ((operationType & NO_THREAT_OPERATION)
1221 && !(reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN))) {
1222 pageContent->topRightIcon = &PRIVACY_ICON;
1223 }
1224 else {
1225 pageContent->topRightIcon = &WARNING_ICON;
1226 }
1227
1228 pageContent->topRightToken
1229 = (operationType & BLIND_OPERATION) ? BLIND_WARNING_TOKEN : WARNING_BUTTON_TOKEN;
1230 }
1231
1232 return true;
1233}
1234
1235// function used to display the current page in generic context navigation mode
1236static void displayGenericContextPage(uint8_t pageIdx, bool forceFullRefresh)
1237{
1238 // Retrieve next page parameters
1239 nbgl_content_t content;
1240 uint8_t nbElementsInPage;
1241 bool flag;
1242 const nbgl_content_t *p_content = NULL;
1243
1244 if (navType == STREAMING_NAV) {
1245 if (pageIdx == LAST_PAGE_FOR_REVIEW) {
1246 if (bundleNavContext.reviewStreaming.skipCallback != NULL) {
1247 bundleNavContext.reviewStreaming.skipCallback();
1248 }
1249 return;
1250 }
1251 else if (pageIdx >= bundleNavContext.reviewStreaming.stepPageNb) {
1252 bundleNavReviewStreamingChoice(true);
1253 return;
1254 }
1255 }
1256 else {
1257 // if coming from Skip modal, let's say we are at the last page
1258 if (pageIdx == LAST_PAGE_FOR_REVIEW) {
1259 pageIdx = navInfo.nbPages - 1;
1260 }
1261 }
1262
1263 if (navInfo.activePage == pageIdx) {
1264 p_content
1265 = genericContextComputeNextPageParams(pageIdx, &content, &nbElementsInPage, &flag);
1266 }
1267 else if (navInfo.activePage < pageIdx) {
1268 // Support going more than one step forward.
1269 // It occurs when initializing a navigation on an arbitrary page
1270 for (int i = navInfo.activePage + 1; i <= pageIdx; i++) {
1271 p_content = genericContextComputeNextPageParams(i, &content, &nbElementsInPage, &flag);
1272 }
1273 }
1274 else {
1275 if (pageIdx - navInfo.activePage > 1) {
1276 // We don't support going more than one step backward as it doesn't occurs for now?
1277 LOG_DEBUG(USE_CASE_LOGGER, "Unsupported navigation\n");
1278 return;
1279 }
1280 p_content
1281 = genericContextComputeNextPageParams(pageIdx, &content, &nbElementsInPage, &flag);
1282 }
1283
1284 if (p_content == NULL) {
1285 return;
1286 }
1287 // if the operation is skippable
1288 if ((navType != STREAMING_NAV)
1289 && (bundleNavContext.review.operationType & SKIPPABLE_OPERATION)) {
1290 // only present the "Skip" header on actual tag/value pages
1291 if ((pageIdx > 0) && (pageIdx < (navInfo.nbPages - 1))) {
1292 navInfo.progressIndicator = false;
1293 navInfo.skipText = "Skip";
1294 navInfo.skipToken = SKIP_TOKEN;
1295 }
1296 else {
1297 navInfo.skipText = NULL;
1298 }
1299 }
1300
1301 // Create next page content
1302 nbgl_pageContent_t pageContent = {0};
1303 if (!genericContextPreparePageContent(p_content, nbElementsInPage, flag, &pageContent)) {
1304 return;
1305 }
1306
1307 pageContext = nbgl_pageDrawGenericContent(&pageCallback, &navInfo, &pageContent);
1308
1309 if (forceFullRefresh) {
1311 }
1312 else {
1314 }
1315}
1316
1317// from the current details context, return a pointer on the details at the given page
1318static const char *getDetailsPageAt(uint8_t detailsPage)
1319{
1320 uint8_t page = 0;
1321 const char *currentChar = detailsContext.value;
1322 while (page < detailsPage) {
1323 uint16_t nbLines
1324 = nbgl_getTextNbLinesInWidth(SMALL_BOLD_FONT, currentChar, AVAILABLE_WIDTH, false);
1325 if (nbLines > NB_MAX_LINES_IN_DETAILS) {
1326 uint16_t len;
1327 nbgl_getTextMaxLenInNbLines(SMALL_BOLD_FONT,
1328 currentChar,
1331 &len,
1332 detailsContext.wrapping);
1333 // don't start next page on a \n
1334 if (currentChar[len] == '\n') {
1335 len++;
1336 }
1337 else if (detailsContext.wrapping == false) {
1338 len -= 3;
1339 }
1340 currentChar = currentChar + len;
1341 }
1342 page++;
1343 }
1344 return currentChar;
1345}
1346
1347// function used to display the current page in details review mode
1348static void displayDetailsPage(uint8_t detailsPage, bool forceFullRefresh)
1349{
1350 static nbgl_layoutTagValue_t currentPair;
1351 nbgl_pageNavigationInfo_t info = {.activePage = detailsPage,
1352 .nbPages = detailsContext.nbPages,
1353 .navType = NAV_WITH_BUTTONS,
1354 .quitToken = QUIT_TOKEN,
1355 .navWithButtons.navToken = NAV_TOKEN,
1356 .navWithButtons.quitButton = true,
1357 .navWithButtons.backButton = true,
1358 .navWithButtons.quitText = NULL,
1359 .progressIndicator = false,
1360 .tuneId = TUNE_TAP_CASUAL};
1362 .topRightIcon = NULL,
1363 .tagValueList.nbPairs = 1,
1364 .tagValueList.pairs = &currentPair,
1365 .tagValueList.smallCaseForValue = true,
1366 .tagValueList.wrapping = detailsContext.wrapping};
1367
1368 if (modalPageContext != NULL) {
1369 nbgl_pageRelease(modalPageContext);
1370 }
1371 currentPair.item = detailsContext.tag;
1372 // if move backward or first page
1373 if (detailsPage <= detailsContext.currentPage) {
1374 // recompute current start from beginning
1375 currentPair.value = getDetailsPageAt(detailsPage);
1376 forceFullRefresh = true;
1377 }
1378 // else move forward
1379 else {
1380 currentPair.value = detailsContext.nextPageStart;
1381 }
1382 detailsContext.currentPage = detailsPage;
1383 uint16_t nbLines = nbgl_getTextNbLinesInWidth(
1384 SMALL_BOLD_FONT, currentPair.value, AVAILABLE_WIDTH, detailsContext.wrapping);
1385
1386 if (nbLines > NB_MAX_LINES_IN_DETAILS) {
1387 uint16_t len;
1388 nbgl_getTextMaxLenInNbLines(SMALL_BOLD_FONT,
1389 currentPair.value,
1392 &len,
1393 detailsContext.wrapping);
1395 // don't start next page on a \n
1396 if (currentPair.value[len] == '\n') {
1397 len++;
1398 }
1399 else if (!detailsContext.wrapping) {
1401 len -= 3;
1402 }
1403 // memorize next position to save processing
1404 detailsContext.nextPageStart = currentPair.value + len;
1405 // use special feature to keep only NB_MAX_LINES_IN_DETAILS lines and replace the last 3
1406 // chars by "...", only if the next char to display in next page is not '\n'
1408 }
1409 else {
1410 detailsContext.nextPageStart = NULL;
1411 content.tagValueList.nbMaxLinesForValue = 0;
1412 }
1413 if (info.nbPages == 1) {
1414 // if only one page, no navigation bar, and use a footer instead
1415 info.navWithButtons.quitText = "Close";
1416 }
1417 modalPageContext = nbgl_pageDrawGenericContentExt(&pageModalCallback, &info, &content, true);
1418
1419 if (forceFullRefresh) {
1421 }
1422 else {
1424 }
1425}
1426
1427// function used to display the content of a full value, when touching an alias of a tag/value pair
1428static void displayFullValuePage(const char *backText,
1429 const char *aliasText,
1430 const nbgl_contentValueExt_t *extension)
1431{
1432 const char *modalTitle
1433 = (extension->backText != NULL) ? PIC(extension->backText) : PIC(backText);
1434 if (extension->aliasType == INFO_LIST_ALIAS) {
1435 genericContext.currentInfos = extension->infolist;
1436 displayInfosListModal(modalTitle, extension->infolist, true);
1437 }
1438 else if (extension->aliasType == TAG_VALUE_LIST_ALIAS) {
1439 genericContext.currentTagValues = extension->tagValuelist;
1440 displayTagValueListModal(extension->tagValuelist);
1441 }
1442 else {
1443 nbgl_layoutDescription_t layoutDescription = {.modal = true,
1444 .withLeftBorder = true,
1445 .onActionCallback = &modalLayoutTouchCallback,
1446 .tapActionText = NULL};
1448 .separationLine = false,
1449 .backAndText.token = 0,
1450 .backAndText.tuneId = TUNE_TAP_CASUAL,
1451 .backAndText.text = modalTitle};
1452 genericContext.modalLayout = nbgl_layoutGet(&layoutDescription);
1453 // add header with the tag part of the pair, to go back
1454 nbgl_layoutAddHeader(genericContext.modalLayout, &headerDesc);
1455 // add either QR Code or full value text
1456 if (extension->aliasType == QR_CODE_ALIAS) {
1457#ifdef NBGL_QRCODE
1458 nbgl_layoutQRCode_t qrCode
1459 = {.url = extension->fullValue,
1460 .text1 = (extension->title != NULL) ? extension->title : extension->fullValue,
1461 .text2 = extension->explanation,
1462 .centered = true,
1463 .offsetY = 0};
1464
1465 nbgl_layoutAddQRCode(genericContext.modalLayout, &qrCode);
1466#endif // NBGL_QRCODE
1467 }
1468 else {
1469 const char *info;
1470 // add full value text
1471 if (extension->aliasType == ENS_ALIAS) {
1472 info = "ENS names are resolved by Ledger backend.";
1473 }
1474 else if (extension->aliasType == ADDRESS_BOOK_ALIAS) {
1475 info = "This account label comes from your Address Book in Ledger Wallet.";
1476 }
1477 else {
1478 info = extension->explanation;
1479 }
1481 genericContext.modalLayout, aliasText, extension->fullValue, info);
1482 }
1483 // draw & refresh
1484 nbgl_layoutDraw(genericContext.modalLayout);
1485 nbgl_refresh();
1486 }
1487}
1488
1489// function used to display the modal containing tip-box infos
1490static void displayInfosListModal(const char *modalTitle,
1491 const nbgl_contentInfoList_t *infos,
1492 bool fromReview)
1493{
1495 .nbPages = 1,
1496 .navType = NAV_WITH_BUTTONS,
1497 .quitToken = QUIT_TIPBOX_MODAL_TOKEN,
1498 .navWithButtons.navToken = NAV_TOKEN,
1499 .navWithButtons.quitButton = false,
1500 .navWithButtons.backButton = true,
1501 .navWithButtons.quitText = NULL,
1502 .progressIndicator = false,
1503 .tuneId = TUNE_TAP_CASUAL};
1504 nbgl_pageContent_t content
1505 = {.type = INFOS_LIST,
1506 .topRightIcon = NULL,
1507 .infosList.nbInfos = infos->nbInfos,
1508 .infosList.withExtensions = infos->withExtensions,
1509 .infosList.infoTypes = infos->infoTypes,
1510 .infosList.infoContents = infos->infoContents,
1511 .infosList.infoExtensions = infos->infoExtensions,
1512 .infosList.token = fromReview ? INFO_ALIAS_TOKEN : INFOS_TIP_BOX_TOKEN,
1513 .title = modalTitle,
1514 .titleToken = QUIT_TIPBOX_MODAL_TOKEN,
1515 .tuneId = TUNE_TAP_CASUAL};
1516
1517 if (modalPageContext != NULL) {
1518 nbgl_pageRelease(modalPageContext);
1519 }
1520 modalPageContext = nbgl_pageDrawGenericContentExt(&pageModalCallback, &info, &content, true);
1521
1523}
1524
1525// function used to display the modal containing alias tag-value pairs
1526static void displayTagValueListModalPage(uint8_t pageIdx, bool forceFullRefresh)
1527{
1528 nbgl_pageNavigationInfo_t info = {.activePage = pageIdx,
1529 .nbPages = detailsContext.nbPages,
1530 .navType = NAV_WITH_BUTTONS,
1531 .quitToken = QUIT_TOKEN,
1532 .navWithButtons.navToken = MODAL_NAV_TOKEN,
1533 .navWithButtons.quitButton = true,
1534 .navWithButtons.backButton = true,
1535 .navWithButtons.quitText = NULL,
1536 .progressIndicator = false,
1537 .tuneId = TUNE_TAP_CASUAL};
1539 .topRightIcon = NULL,
1540 .tagValueList.smallCaseForValue = true,
1541 .tagValueList.wrapping = detailsContext.wrapping};
1542 uint8_t nbElementsInPage;
1543
1544 // if first page or forward
1545 if (detailsContext.currentPage <= pageIdx) {
1546 modalContextGetPageInfo(pageIdx, &nbElementsInPage);
1547 }
1548 else {
1549 // backward direction
1550 modalContextGetPageInfo(pageIdx + 1, &nbElementsInPage);
1551 detailsContext.currentPairIdx -= nbElementsInPage;
1552 modalContextGetPageInfo(pageIdx, &nbElementsInPage);
1553 detailsContext.currentPairIdx -= nbElementsInPage;
1554 }
1555 detailsContext.currentPage = pageIdx;
1556
1557 content.tagValueList.pairs
1558 = &genericContext.currentTagValues->pairs[detailsContext.currentPairIdx];
1559 content.tagValueList.nbPairs = nbElementsInPage;
1560 detailsContext.currentPairIdx += nbElementsInPage;
1561 if (info.nbPages == 1) {
1562 // if only one page, no navigation bar, and use a footer instead
1563 info.navWithButtons.quitText = "Close";
1564 }
1565
1566 if (modalPageContext != NULL) {
1567 nbgl_pageRelease(modalPageContext);
1568 }
1569 modalPageContext = nbgl_pageDrawGenericContentExt(&pageModalCallback, &info, &content, true);
1570
1571 if (forceFullRefresh) {
1573 }
1574 else {
1576 }
1577}
1578
1579#ifdef NBGL_QRCODE
1580static void displayAddressQRCode(void)
1581{
1582 // display the address as QR Code
1583 nbgl_layoutDescription_t layoutDescription = {.modal = true,
1584 .withLeftBorder = true,
1585 .onActionCallback = &modalLayoutTouchCallback,
1586 .tapActionText = NULL};
1587 nbgl_layoutHeader_t headerDesc = {
1588 .type = HEADER_EMPTY, .separationLine = false, .emptySpace.height = SMALL_CENTERING_HEADER};
1589 nbgl_layoutQRCode_t qrCode = {.url = addressConfirmationContext.tagValuePairs[0].value,
1590 .text1 = NULL,
1591 .centered = true,
1592 .offsetY = 0};
1593
1594 addressConfirmationContext.modalLayout = nbgl_layoutGet(&layoutDescription);
1595 // add empty header for better look
1596 nbgl_layoutAddHeader(addressConfirmationContext.modalLayout, &headerDesc);
1597 // compute nb lines to check whether it shall be shorten (max is 3 lines)
1598 uint16_t nbLines = nbgl_getTextNbLinesInWidth(SMALL_REGULAR_FONT,
1599 addressConfirmationContext.tagValuePairs[0].value,
1601 false);
1602
1603 if (nbLines <= QRCODE_NB_MAX_LINES) {
1604 qrCode.text2 = addressConfirmationContext.tagValuePairs[0].value; // in gray
1605 }
1606 else {
1607 // only keep beginning and end of text, and add ... in the middle
1608 nbgl_textReduceOnNbLines(SMALL_REGULAR_FONT,
1609 addressConfirmationContext.tagValuePairs[0].value,
1611 QRCODE_NB_MAX_LINES,
1612 reducedAddress,
1613 QRCODE_REDUCED_ADDR_LEN);
1614 qrCode.text2 = reducedAddress; // in gray
1615 }
1616
1617 nbgl_layoutAddQRCode(addressConfirmationContext.modalLayout, &qrCode);
1618
1620 addressConfirmationContext.modalLayout, "Close", DISMISS_QR_TOKEN, TUNE_TAP_CASUAL);
1621 nbgl_layoutDraw(addressConfirmationContext.modalLayout);
1622 nbgl_refresh();
1623}
1624
1625#endif // NBGL_QRCODE
1626
1627// called when header is touched on modal page, to dismiss it
1628static void modalLayoutTouchCallback(int token, uint8_t index)
1629{
1630 UNUSED(index);
1631 if (token == DISMISS_QR_TOKEN) {
1632 // dismiss modal
1633 nbgl_layoutRelease(addressConfirmationContext.modalLayout);
1634 addressConfirmationContext.modalLayout = NULL;
1636 }
1637 else if (token == DISMISS_WARNING_TOKEN) {
1638 // dismiss modal
1639 nbgl_layoutRelease(reviewWithWarnCtx.modalLayout);
1640 // if already at first level, simply redraw the background
1641 if (reviewWithWarnCtx.securityReportLevel <= 1) {
1642 reviewWithWarnCtx.modalLayout = NULL;
1644 }
1645 else {
1646 // We are at level 2 of warning modal, so re-display the level 1
1647 reviewWithWarnCtx.securityReportLevel = 1;
1648 // if preset is used
1649 if (reviewWithWarnCtx.warning->predefinedSet) {
1650 displaySecurityReport(reviewWithWarnCtx.warning->predefinedSet);
1651 }
1652 else {
1653 // use customized warning
1654 const nbgl_warningDetails_t *details
1655 = (reviewWithWarnCtx.isIntro) ? reviewWithWarnCtx.warning->introDetails
1656 : reviewWithWarnCtx.warning->reviewDetails;
1657 displayCustomizedSecurityReport(details);
1658 }
1659 return;
1660 }
1661 }
1662 else if (token == DISMISS_DETAILS_TOKEN) {
1663 // dismiss modal
1664 nbgl_layoutRelease(choiceWithDetailsCtx.modalLayout);
1665 // if already at first level, simply redraw the background
1666 if (choiceWithDetailsCtx.level <= 1) {
1667 choiceWithDetailsCtx.modalLayout = NULL;
1669 }
1670 else {
1671 // We are at level 2 of details modal, so re-display the level 1
1672 choiceWithDetailsCtx.level = 1;
1673 choiceWithDetailsCtx.modalLayout
1674 = displayModalDetails(choiceWithDetailsCtx.details, DISMISS_DETAILS_TOKEN);
1675 }
1676 }
1677 else if ((token >= FIRST_WARN_BAR_TOKEN) && (token <= LAST_WARN_BAR_TOKEN)) {
1678 if (sharedContext.usage == SHARE_CTX_REVIEW_WITH_WARNING) {
1679 // dismiss modal before creating a new one
1680 nbgl_layoutRelease(reviewWithWarnCtx.modalLayout);
1681 reviewWithWarnCtx.securityReportLevel = 2;
1682 // if preset is used
1683 if (reviewWithWarnCtx.warning->predefinedSet) {
1684 displaySecurityReport(1 << (token - FIRST_WARN_BAR_TOKEN));
1685 }
1686 else {
1687 // use customized warning
1688 const nbgl_warningDetails_t *details
1689 = (reviewWithWarnCtx.isIntro) ? reviewWithWarnCtx.warning->introDetails
1690 : reviewWithWarnCtx.warning->reviewDetails;
1691 if (details->type == BAR_LIST_WARNING) {
1692 displayCustomizedSecurityReport(
1693 &details->barList.details[token - FIRST_WARN_BAR_TOKEN]);
1694 }
1695 }
1696 }
1697 else if (sharedContext.usage == SHARE_CTX_CHOICE_WITH_DETAILS) {
1698 const nbgl_warningDetails_t *details
1699 = &choiceWithDetailsCtx.details->barList.details[token - FIRST_WARN_BAR_TOKEN];
1700 if (details->title != NO_TYPE_WARNING) {
1701 // dismiss modal before creating a new one
1702 nbgl_layoutRelease(choiceWithDetailsCtx.modalLayout);
1703 choiceWithDetailsCtx.level = 2;
1704 choiceWithDetailsCtx.modalLayout
1705 = displayModalDetails(details, DISMISS_DETAILS_TOKEN);
1706 }
1707 }
1708 return;
1709 }
1710 else {
1711 // dismiss modal
1712 nbgl_layoutRelease(genericContext.modalLayout);
1713 genericContext.modalLayout = NULL;
1715 }
1716 nbgl_refresh();
1717}
1718
1719// called when item are touched in layout
1720static void layoutTouchCallback(int token, uint8_t index)
1721{
1722 // choice buttons in initial warning page
1723 if (token == WARNING_CHOICE_TOKEN) {
1724 if (index == 0) { // top button to exit
1725 reviewWithWarnCtx.choiceCallback(false);
1726 }
1727 else { // bottom button to continue to review
1728 reviewWithWarnCtx.isIntro = false;
1729 if (reviewWithWarnCtx.isStreaming) {
1730 useCaseReviewStreamingStart(reviewWithWarnCtx.operationType,
1731 reviewWithWarnCtx.icon,
1732 reviewWithWarnCtx.reviewTitle,
1733 reviewWithWarnCtx.reviewSubTitle,
1734 reviewWithWarnCtx.choiceCallback,
1735 false);
1736 }
1737 else {
1738 useCaseReview(reviewWithWarnCtx.operationType,
1739 reviewWithWarnCtx.tagValueList,
1740 reviewWithWarnCtx.icon,
1741 reviewWithWarnCtx.reviewTitle,
1742 reviewWithWarnCtx.reviewSubTitle,
1743 reviewWithWarnCtx.finishTitle,
1744 &activeTipBox,
1745 reviewWithWarnCtx.choiceCallback,
1746 false,
1747 false);
1748 }
1749 }
1750 }
1751 // top-right button in initial warning page
1752 else if (token == WARNING_BUTTON_TOKEN) {
1753 // start directly at first level of security report
1754 reviewWithWarnCtx.securityReportLevel = 1;
1755 // if preset is used
1756 if (reviewWithWarnCtx.warning->predefinedSet) {
1757 displaySecurityReport(reviewWithWarnCtx.warning->predefinedSet);
1758 }
1759 else {
1760 // use customized warning
1761 const nbgl_warningDetails_t *details = (reviewWithWarnCtx.isIntro)
1762 ? reviewWithWarnCtx.warning->introDetails
1763 : reviewWithWarnCtx.warning->reviewDetails;
1764 displayCustomizedSecurityReport(details);
1765 }
1766 }
1767 // top-right button in choice with details page
1768 else if (token == CHOICE_DETAILS_TOKEN) {
1769 choiceWithDetailsCtx.level = 1;
1770 choiceWithDetailsCtx.modalLayout
1771 = displayModalDetails(choiceWithDetailsCtx.details, DISMISS_DETAILS_TOKEN);
1772 }
1773 // main prelude page
1774 else if (token == PRELUDE_CHOICE_TOKEN) {
1775 if (index == 0) { // top button to display details about prelude
1776 displayCustomizedSecurityReport(reviewWithWarnCtx.warning->prelude->details);
1777 }
1778 else { // footer to continue to review
1779 if (HAS_INITIAL_WARNING(reviewWithWarnCtx.warning)) {
1780 displayInitialWarning();
1781 }
1782 else {
1783 reviewWithWarnCtx.isIntro = false;
1784 if (reviewWithWarnCtx.isStreaming) {
1785 useCaseReviewStreamingStart(reviewWithWarnCtx.operationType,
1786 reviewWithWarnCtx.icon,
1787 reviewWithWarnCtx.reviewTitle,
1788 reviewWithWarnCtx.reviewSubTitle,
1789 reviewWithWarnCtx.choiceCallback,
1790 false);
1791 }
1792 else {
1793 useCaseReview(reviewWithWarnCtx.operationType,
1794 reviewWithWarnCtx.tagValueList,
1795 reviewWithWarnCtx.icon,
1796 reviewWithWarnCtx.reviewTitle,
1797 reviewWithWarnCtx.reviewSubTitle,
1798 reviewWithWarnCtx.finishTitle,
1799 &activeTipBox,
1800 reviewWithWarnCtx.choiceCallback,
1801 false,
1802 false);
1803 }
1804 }
1805 }
1806 }
1807 // choice buttons
1808 else if (token == CHOICE_TOKEN) {
1809 if (onChoice != NULL) {
1810 onChoice((index == 0) ? true : false);
1811 }
1812 }
1813}
1814
1815// called when skip button is touched in footer, during forward only review
1816static void displaySkipWarning(void)
1817{
1819 .cancelText = "Go back to review",
1820 .centeredInfo.text1 = "Skip review?",
1821 .centeredInfo.text2
1822 = "If you're sure you don't need to review all fields, you can skip straight to signing.",
1823 .centeredInfo.text3 = NULL,
1824 .centeredInfo.style = LARGE_CASE_INFO,
1825 .centeredInfo.icon = &IMPORTANT_CIRCLE_ICON,
1826 .centeredInfo.offsetY = 0,
1827 .confirmationText = "Yes, skip",
1828 .confirmationToken = SKIP_TOKEN,
1829 .tuneId = TUNE_TAP_CASUAL,
1830 .modal = true};
1831 if (modalPageContext != NULL) {
1832 nbgl_pageRelease(modalPageContext);
1833 }
1834 modalPageContext = nbgl_pageDrawConfirmation(&pageModalCallback, &info);
1836}
1837
1838#ifdef NBGL_KEYPAD
1839// called to update the keypad and automatically show / hide:
1840// - backspace key if no digits are present
1841// - validation key if the min digit is reached
1842// - keypad if the max number of digit is reached
1843static void updateKeyPad(bool add)
1844{
1845 bool enableValidate, enableBackspace, enableDigits;
1846 bool redrawKeypad = false;
1848
1849 enableDigits = (keypadContext.pinLen < keypadContext.pinMaxDigits);
1850 enableValidate = (keypadContext.pinLen >= keypadContext.pinMinDigits);
1851 enableBackspace = (keypadContext.pinLen > 0);
1852 if (add) {
1853 if ((keypadContext.pinLen == keypadContext.pinMinDigits)
1854 || // activate "validate" button on keypad
1855 (keypadContext.pinLen == keypadContext.pinMaxDigits)
1856 || // deactivate "digits" on keypad
1857 (keypadContext.pinLen == 1)) { // activate "backspace"
1858 redrawKeypad = true;
1859 }
1860 }
1861 else { // remove
1862 if ((keypadContext.pinLen == 0) || // deactivate "backspace" button on keypad
1863 (keypadContext.pinLen == (keypadContext.pinMinDigits - 1))
1864 || // deactivate "validate" button on keypad
1865 (keypadContext.pinLen
1866 == (keypadContext.pinMaxDigits - 1))) { // reactivate "digits" on keypad
1867 redrawKeypad = true;
1868 }
1869 }
1870 if (keypadContext.hidden == true) {
1871 nbgl_layoutUpdateKeypadContent(keypadContext.layoutCtx, true, keypadContext.pinLen, NULL);
1872 }
1873 else {
1875 keypadContext.layoutCtx, false, 0, (const char *) keypadContext.pinEntry);
1876 }
1877 if (redrawKeypad) {
1879 keypadContext.layoutCtx, 0, enableValidate, enableBackspace, enableDigits);
1880 }
1881
1882 if ((!add) && (keypadContext.pinLen == 0)) {
1883 // Full refresh to fully clean the bullets when reaching 0 digits
1884 mode = FULL_COLOR_REFRESH;
1885 }
1887}
1888
1889// called when a key is touched on the keypad
1890static void keypadCallback(char touchedKey)
1891{
1892 switch (touchedKey) {
1893 case BACKSPACE_KEY:
1894 if (keypadContext.pinLen > 0) {
1895 keypadContext.pinLen--;
1896 keypadContext.pinEntry[keypadContext.pinLen] = 0;
1897 }
1898 updateKeyPad(false);
1899 break;
1900
1901 case VALIDATE_KEY:
1902 // Gray out keyboard / buttons as a first user feedback
1903 nbgl_layoutUpdateKeypad(keypadContext.layoutCtx, 0, false, false, true);
1906
1907 onValidatePin(keypadContext.pinEntry, keypadContext.pinLen);
1908 break;
1909
1910 default:
1911 if ((touchedKey >= 0x30) && (touchedKey < 0x40)) {
1912 if (keypadContext.pinLen < keypadContext.pinMaxDigits) {
1913 keypadContext.pinEntry[keypadContext.pinLen] = touchedKey;
1914 keypadContext.pinLen++;
1915 }
1916 updateKeyPad(true);
1917 }
1918 break;
1919 }
1920}
1921
1922static void keypadGeneric_cb(int token, uint8_t index)
1923{
1924 UNUSED(index);
1925 if (token != BACK_TOKEN) {
1926 return;
1927 }
1928 onQuit();
1929}
1930#endif
1931
1946static uint8_t getNbTagValuesInPage(uint8_t nbPairs,
1947 const nbgl_contentTagValueList_t *tagValueList,
1948 uint8_t startIndex,
1949 bool isSkippable,
1950 bool hasConfirmationButton,
1951 bool hasDetailsButton,
1952 bool *requireSpecificDisplay)
1953{
1954 uint8_t nbPairsInPage = 0;
1955 uint16_t currentHeight = PRE_TAG_VALUE_MARGIN; // upper margin
1956 uint16_t maxUsableHeight = TAG_VALUE_AREA_HEIGHT;
1957
1958 // if the review is skippable, it means that there is less height for tag/value pairs
1959 // the small centering header becomes a touchable header
1960 if (isSkippable) {
1961 maxUsableHeight -= TOUCHABLE_HEADER_BAR_HEIGHT - SMALL_CENTERING_HEADER;
1962 }
1963
1964 *requireSpecificDisplay = false;
1965 while (nbPairsInPage < nbPairs) {
1966 const nbgl_layoutTagValue_t *pair;
1967 nbgl_font_id_e value_font;
1968 uint16_t nbLines;
1969
1970 // margin between pairs
1971 // 12 or 24 px between each tag/value pair
1972 if (nbPairsInPage > 0) {
1973 currentHeight += INTER_TAG_VALUE_MARGIN;
1974 }
1975 // fetch tag/value pair strings.
1976 if (tagValueList->pairs != NULL) {
1977 pair = PIC(&tagValueList->pairs[startIndex + nbPairsInPage]);
1978 }
1979 else {
1980 pair = PIC(tagValueList->callback(startIndex + nbPairsInPage));
1981 }
1982
1983 if (pair->forcePageStart && nbPairsInPage > 0) {
1984 // This pair must be at the top of a page
1985 break;
1986 }
1987
1988 if (pair->centeredInfo) {
1989 if (nbPairsInPage > 0) {
1990 // This pair must be at the top of a page
1991 break;
1992 }
1993 else {
1994 // This pair is the only one of the page and has a specific display behavior
1995 nbPairsInPage = 1;
1996 *requireSpecificDisplay = true;
1997 break;
1998 }
1999 }
2000
2001 // tag height
2002 currentHeight += nbgl_getTextHeightInWidth(
2003 SMALL_REGULAR_FONT, pair->item, AVAILABLE_WIDTH, tagValueList->wrapping);
2004 // space between tag and value
2005 currentHeight += 4;
2006 // set value font
2007 if (tagValueList->smallCaseForValue) {
2008 value_font = SMALL_REGULAR_FONT;
2009 }
2010 else {
2011 value_font = LARGE_MEDIUM_FONT;
2012 }
2013 // value height
2014 currentHeight += nbgl_getTextHeightInWidth(
2015 value_font, pair->value, AVAILABLE_WIDTH, tagValueList->wrapping);
2016 // nb lines for value
2018 value_font, pair->value, AVAILABLE_WIDTH, tagValueList->wrapping);
2019 if ((currentHeight >= maxUsableHeight) || (nbLines > NB_MAX_LINES_IN_REVIEW)) {
2020 if (nbPairsInPage == 0) {
2021 // Pair too long to fit in a single screen
2022 // It will be the only one of the page and has a specific display behavior
2023 nbPairsInPage = 1;
2024 *requireSpecificDisplay = true;
2025 }
2026 break;
2027 }
2028 nbPairsInPage++;
2029 }
2030 // if this is a TAG_VALUE_CONFIRM and we have reached the last pairs,
2031 // let's check if it still fits with a CONFIRMATION button, and if not,
2032 // remove the last pair
2033 if (hasConfirmationButton && (nbPairsInPage == nbPairs)) {
2034 maxUsableHeight -= UP_FOOTER_BUTTON_HEIGHT;
2035 if (currentHeight > maxUsableHeight) {
2036 nbPairsInPage--;
2037 }
2038 }
2039 // do the same with just a details button
2040 else if (hasDetailsButton) {
2041 maxUsableHeight -= (SMALL_BUTTON_RADIUS * 2);
2042 if (currentHeight > maxUsableHeight) {
2043 nbPairsInPage--;
2044 }
2045 }
2046 return nbPairsInPage;
2047}
2048
2058static uint8_t getNbTagValuesInDetailsPage(uint8_t nbPairs,
2059 const nbgl_contentTagValueList_t *tagValueList,
2060 uint8_t startIndex)
2061{
2062 uint8_t nbPairsInPage = 0;
2063 uint16_t currentHeight = PRE_TAG_VALUE_MARGIN; // upper margin
2064 uint16_t maxUsableHeight = TAG_VALUE_AREA_HEIGHT;
2065
2066 while (nbPairsInPage < nbPairs) {
2067 const nbgl_layoutTagValue_t *pair;
2068
2069 // margin between pairs
2070 // 12 or 24 px between each tag/value pair
2071 if (nbPairsInPage > 0) {
2072 currentHeight += INTER_TAG_VALUE_MARGIN;
2073 }
2074 // fetch tag/value pair strings.
2075 if (tagValueList->pairs != NULL) {
2076 pair = PIC(&tagValueList->pairs[startIndex + nbPairsInPage]);
2077 }
2078 else {
2079 pair = PIC(tagValueList->callback(startIndex + nbPairsInPage));
2080 }
2081
2082 // tag height
2083 currentHeight += nbgl_getTextHeightInWidth(
2084 SMALL_REGULAR_FONT, pair->item, AVAILABLE_WIDTH, tagValueList->wrapping);
2085 // space between tag and value
2086 currentHeight += 4;
2087
2088 // value height
2089 currentHeight += nbgl_getTextHeightInWidth(
2090 SMALL_REGULAR_FONT, pair->value, AVAILABLE_WIDTH, tagValueList->wrapping);
2091
2092 // we have reached the maximum height, it means than there are to many pairs
2093 if (currentHeight >= maxUsableHeight) {
2094 break;
2095 }
2096 nbPairsInPage++;
2097 }
2098 return nbPairsInPage;
2099}
2100
2101static uint8_t getNbPagesForContent(const nbgl_content_t *content,
2102 uint8_t pageIdxStart,
2103 bool isLast,
2104 bool isSkippable)
2105{
2106 uint8_t nbElements = 0;
2107 uint8_t nbPages = 0;
2108 uint8_t nbElementsInPage;
2109 uint8_t elemIdx = 0;
2110 bool flag;
2111
2112 nbElements = getContentNbElement(content);
2113
2114 while (nbElements > 0) {
2115 flag = 0;
2116 // if the current page is not the first one (or last), a navigation bar exists
2117 bool hasNav = !isLast || (pageIdxStart > 0) || (elemIdx > 0);
2118 if (content->type == TAG_VALUE_LIST) {
2119 nbElementsInPage = getNbTagValuesInPage(nbElements,
2120 &content->content.tagValueList,
2121 elemIdx,
2122 isSkippable,
2123 false,
2124 false,
2125 &flag);
2126 }
2127 else if (content->type == TAG_VALUE_CONFIRM) {
2128 nbElementsInPage = getNbTagValuesInPage(nbElements,
2130 elemIdx,
2131 isSkippable,
2132 isLast,
2133 !isLast,
2134 &flag);
2135 }
2136 else if (content->type == INFOS_LIST) {
2137 nbElementsInPage = nbgl_useCaseGetNbInfosInPage(
2138 nbElements, &content->content.infosList, elemIdx, hasNav);
2139 }
2140 else if (content->type == SWITCHES_LIST) {
2141 nbElementsInPage = nbgl_useCaseGetNbSwitchesInPage(
2142 nbElements, &content->content.switchesList, elemIdx, hasNav);
2143 }
2144 else if (content->type == BARS_LIST) {
2145 nbElementsInPage = nbgl_useCaseGetNbBarsInPage(
2146 nbElements, &content->content.barsList, elemIdx, hasNav);
2147 }
2148 else if (content->type == CHOICES_LIST) {
2149 nbElementsInPage = nbgl_useCaseGetNbChoicesInPage(
2150 nbElements, &content->content.choicesList, elemIdx, hasNav);
2151 }
2152 else {
2153 nbElementsInPage = MIN(nbMaxElementsPerContentType[content->type], nbElements);
2154 }
2155
2156 elemIdx += nbElementsInPage;
2157 genericContextSetPageInfo(pageIdxStart + nbPages, nbElementsInPage, flag);
2158 nbElements -= nbElementsInPage;
2159 nbPages++;
2160 }
2161
2162 return nbPages;
2163}
2164
2165static uint8_t getNbPagesForGenericContents(const nbgl_genericContents_t *genericContents,
2166 uint8_t pageIdxStart,
2167 bool isSkippable)
2168{
2169 uint8_t nbPages = 0;
2170 nbgl_content_t content;
2171 const nbgl_content_t *p_content;
2172
2173 for (int i = 0; i < genericContents->nbContents; i++) {
2174 p_content = getContentAtIdx(genericContents, i, &content);
2175 if (p_content == NULL) {
2176 return 0;
2177 }
2178 nbPages += getNbPagesForContent(p_content,
2179 pageIdxStart + nbPages,
2180 (i == (genericContents->nbContents - 1)),
2181 isSkippable);
2182 }
2183
2184 return nbPages;
2185}
2186
2187static void prepareAddressConfirmationPages(const char *address,
2188 const nbgl_contentTagValueList_t *tagValueList,
2189 nbgl_content_t *firstPageContent,
2190 nbgl_content_t *secondPageContent)
2191{
2192 nbgl_contentTagValueConfirm_t *tagValueConfirm;
2193
2194 addressConfirmationContext.tagValuePairs[0].item = "Address";
2195 addressConfirmationContext.tagValuePairs[0].value = address;
2196 addressConfirmationContext.nbPairs = 1;
2197
2198 // First page
2199 firstPageContent->type = TAG_VALUE_CONFIRM;
2200 tagValueConfirm = &firstPageContent->content.tagValueConfirm;
2201
2202#ifdef NBGL_QRCODE
2203 tagValueConfirm->detailsButtonIcon = &QRCODE_ICON;
2204 // only use "Show as QR" when address & pairs are not fitting in a single page
2205 if ((tagValueList != NULL) && (tagValueList->nbPairs < ADDR_VERIF_NB_PAIRS)) {
2207 bool flag;
2208 // copy in intermediate structure
2209 for (uint8_t i = 0; i < tagValueList->nbPairs; i++) {
2210 memcpy(&addressConfirmationContext.tagValuePairs[1 + i],
2211 &tagValueList->pairs[i],
2212 sizeof(nbgl_contentTagValue_t));
2213 addressConfirmationContext.nbPairs++;
2214 }
2215 // check how many can fit in a page
2216 memcpy(&tmpList, tagValueList, sizeof(nbgl_contentTagValueList_t));
2217 tmpList.nbPairs = addressConfirmationContext.nbPairs;
2218 tmpList.pairs = addressConfirmationContext.tagValuePairs;
2219 addressConfirmationContext.nbPairs = getNbTagValuesInPage(
2220 addressConfirmationContext.nbPairs, &tmpList, 0, false, true, true, &flag);
2221 // if they don't all fit, keep only the address
2222 if (tmpList.nbPairs > addressConfirmationContext.nbPairs) {
2223 addressConfirmationContext.nbPairs = 1;
2224 }
2225 }
2226 else {
2227 tagValueConfirm->detailsButtonText = NULL;
2228 }
2229 tagValueConfirm->detailsButtonToken = ADDRESS_QRCODE_BUTTON_TOKEN;
2230#else // NBGL_QRCODE
2231 tagValueConfirm->detailsButtonText = NULL;
2232 tagValueConfirm->detailsButtonIcon = NULL;
2233#endif // NBGL_QRCODE
2234 tagValueConfirm->tuneId = TUNE_TAP_CASUAL;
2235 tagValueConfirm->tagValueList.nbPairs = addressConfirmationContext.nbPairs;
2236 tagValueConfirm->tagValueList.pairs = addressConfirmationContext.tagValuePairs;
2237 tagValueConfirm->tagValueList.smallCaseForValue = false;
2238 tagValueConfirm->tagValueList.nbMaxLinesForValue = 0;
2239 tagValueConfirm->tagValueList.wrapping = false;
2240 // if it's an extended address verif, it takes 2 pages, so display a "Tap to continue", and
2241 // no confirmation button
2242 if ((tagValueList != NULL)
2243 && (tagValueList->nbPairs > (addressConfirmationContext.nbPairs - 1))) {
2244 tagValueConfirm->detailsButtonText = "Show as QR";
2245 tagValueConfirm->confirmationText = NULL;
2246 // the second page is dedicated to the extended tag/value pairs
2247 secondPageContent->type = TAG_VALUE_CONFIRM;
2248 tagValueConfirm = &secondPageContent->content.tagValueConfirm;
2249 tagValueConfirm->confirmationText = "Confirm";
2250 tagValueConfirm->confirmationToken = CONFIRM_TOKEN;
2251 tagValueConfirm->detailsButtonText = NULL;
2252 tagValueConfirm->detailsButtonIcon = NULL;
2253 tagValueConfirm->tuneId = TUNE_TAP_CASUAL;
2254 memcpy(&tagValueConfirm->tagValueList, tagValueList, sizeof(nbgl_contentTagValueList_t));
2255 tagValueConfirm->tagValueList.nbPairs
2256 = tagValueList->nbPairs - (addressConfirmationContext.nbPairs - 1);
2257 tagValueConfirm->tagValueList.pairs
2258 = &tagValueList->pairs[addressConfirmationContext.nbPairs - 1];
2259 }
2260 else {
2261 // otherwise no tap to continue but a confirmation button
2262 tagValueConfirm->confirmationText = "Confirm";
2263 tagValueConfirm->confirmationToken = CONFIRM_TOKEN;
2264 }
2265}
2266
2267static void bundleNavStartHome(void)
2268{
2269 nbgl_homeAndSettingsContext_t *context = &bundleNavContext.homeAndSettings;
2270
2271 useCaseHomeExt(context->appName,
2272 context->appIcon,
2273 context->tagline,
2274 context->settingContents != NULL ? true : false,
2275 &context->homeAction,
2276 bundleNavStartSettings,
2277 context->quitCallback);
2278}
2279
2280static void bundleNavStartSettingsAtPage(uint8_t initSettingPage)
2281{
2282 nbgl_homeAndSettingsContext_t *context = &bundleNavContext.homeAndSettings;
2283
2284 nbgl_useCaseGenericSettings(context->appName,
2285 initSettingPage,
2286 context->settingContents,
2287 context->infosList,
2288 bundleNavStartHome);
2289}
2290
2291static void bundleNavStartSettings(void)
2292{
2293 bundleNavStartSettingsAtPage(0);
2294}
2295
2296static void bundleNavReviewConfirmRejection(void)
2297{
2298 bundleNavContext.review.choiceCallback(false);
2299}
2300
2301static void bundleNavReviewAskRejectionConfirmation(nbgl_operationType_t operationType,
2302 nbgl_callback_t callback)
2303{
2304 const char *title;
2305 const char *confirmText;
2306 // clear skip and blind bits
2307 operationType
2308 &= ~(SKIPPABLE_OPERATION | BLIND_OPERATION | RISKY_OPERATION | NO_THREAT_OPERATION);
2309 if (operationType == TYPE_TRANSACTION) {
2310 title = "Reject transaction?";
2311 confirmText = "Go back to transaction";
2312 }
2313 else if (operationType == TYPE_MESSAGE) {
2314 title = "Reject message?";
2315 confirmText = "Go back to message";
2316 }
2317 else {
2318 title = "Reject operation?";
2319 confirmText = "Go back to operation";
2320 }
2321
2322 // display a choice to confirm/cancel rejection
2323 nbgl_useCaseConfirm(title, NULL, "Yes, reject", confirmText, callback);
2324}
2325
2326static void bundleNavReviewChoice(bool confirm)
2327{
2328 if (confirm) {
2329 bundleNavContext.review.choiceCallback(true);
2330 }
2331 else {
2332 bundleNavReviewAskRejectionConfirmation(bundleNavContext.review.operationType,
2333 bundleNavReviewConfirmRejection);
2334 }
2335}
2336
2337static void bundleNavReviewStreamingConfirmRejection(void)
2338{
2339 bundleNavContext.reviewStreaming.choiceCallback(false);
2340}
2341
2342static void bundleNavReviewStreamingChoice(bool confirm)
2343{
2344 if (confirm) {
2345 bundleNavContext.reviewStreaming.choiceCallback(true);
2346 }
2347 else {
2348 bundleNavReviewAskRejectionConfirmation(bundleNavContext.reviewStreaming.operationType,
2349 bundleNavReviewStreamingConfirmRejection);
2350 }
2351}
2352
2353// function used to display the details in modal (from Choice with details or from Customized
2354// security report) it can be either a single page with text or QR code, or a list of touchable bars
2355// leading to single pages
2356static nbgl_layout_t *displayModalDetails(const nbgl_warningDetails_t *details, uint8_t token)
2357{
2358 nbgl_layoutDescription_t layoutDescription = {.modal = true,
2359 .withLeftBorder = true,
2360 .onActionCallback = modalLayoutTouchCallback,
2361 .tapActionText = NULL};
2363 .separationLine = true,
2364 .backAndText.icon = NULL,
2365 .backAndText.tuneId = TUNE_TAP_CASUAL,
2366 .backAndText.token = token};
2367 uint8_t i;
2368 nbgl_layout_t *layout;
2369
2370 layout = nbgl_layoutGet(&layoutDescription);
2371 headerDesc.backAndText.text = details->title;
2372 nbgl_layoutAddHeader(layout, &headerDesc);
2373 if (details->type == BAR_LIST_WARNING) {
2374 // if more than one warning, so use a list of touchable bars
2375 for (i = 0; i < details->barList.nbBars; i++) {
2376 nbgl_layoutBar_t bar;
2377 bar.text = details->barList.texts[i];
2378 bar.subText = details->barList.subTexts[i];
2379 bar.iconRight
2380 = (details->barList.details[i].type != NO_TYPE_WARNING) ? &PUSH_ICON : NULL;
2381 bar.iconLeft = details->barList.icons[i];
2382 bar.token = FIRST_WARN_BAR_TOKEN + i;
2383 bar.tuneId = TUNE_TAP_CASUAL;
2384 bar.large = false;
2385 bar.inactive = false;
2386 nbgl_layoutAddTouchableBar(layout, &bar);
2388 }
2389 }
2390 else if (details->type == QRCODE_WARNING) {
2391#ifdef NBGL_QRCODE
2392 // display a QR Code
2393 nbgl_layoutAddQRCode(layout, &details->qrCode);
2394#endif // NBGL_QRCODE
2395 headerDesc.backAndText.text = details->title;
2396 }
2397 else if (details->type == CENTERED_INFO_WARNING) {
2398 // display a centered info
2399 nbgl_layoutAddContentCenter(layout, &details->centeredInfo);
2400 headerDesc.separationLine = false;
2401 }
2402 nbgl_layoutDraw(layout);
2403 nbgl_refresh();
2404 return layout;
2405}
2406
2407// function used to display the security level page in modal
2408// it can be either a single page with text or QR code, or a list of touchable bars leading
2409// to single pages
2410static void displaySecurityReport(uint32_t set)
2411{
2412 nbgl_layoutDescription_t layoutDescription = {.modal = true,
2413 .withLeftBorder = true,
2414 .onActionCallback = modalLayoutTouchCallback,
2415 .tapActionText = NULL};
2417 .separationLine = true,
2418 .backAndText.icon = NULL,
2419 .backAndText.tuneId = TUNE_TAP_CASUAL,
2420 .backAndText.token = DISMISS_WARNING_TOKEN};
2421 nbgl_layoutFooter_t footerDesc
2422 = {.type = FOOTER_EMPTY, .separationLine = false, .emptySpace.height = 0};
2423 uint8_t i;
2424 const char *provider;
2425
2426 reviewWithWarnCtx.modalLayout = nbgl_layoutGet(&layoutDescription);
2427
2428 // display a list of touchable bars in some conditions:
2429 // - we must be in the first level of security report
2430 // - and be in the review itself (not from the intro/warning screen)
2431 //
2432 if ((reviewWithWarnCtx.securityReportLevel == 1) && (!reviewWithWarnCtx.isIntro)) {
2433 for (i = 0; i < NB_WARNING_TYPES; i++) {
2434 // Skip GATED_SIGNING_WARN from security report bars
2435 if ((i != GATED_SIGNING_WARN)
2436 && (reviewWithWarnCtx.warning->predefinedSet & (1 << i))) {
2437 nbgl_layoutBar_t bar = {0};
2438 if ((i == BLIND_SIGNING_WARN) || (i == W3C_NO_THREAT_WARN) || (i == W3C_ISSUE_WARN)
2439 || (reviewWithWarnCtx.warning->providerMessage == NULL)) {
2440 bar.subText = securityReportItems[i].subText;
2441 }
2442 else {
2443 bar.subText = reviewWithWarnCtx.warning->providerMessage;
2444 }
2445 bar.text = securityReportItems[i].text;
2446 if (i != W3C_NO_THREAT_WARN) {
2447 bar.iconRight = &PUSH_ICON;
2448 bar.token = FIRST_WARN_BAR_TOKEN + i;
2449 bar.tuneId = TUNE_TAP_CASUAL;
2450 }
2451 else {
2453 }
2454 bar.iconLeft = securityReportItems[i].icon;
2455 nbgl_layoutAddTouchableBar(reviewWithWarnCtx.modalLayout, &bar);
2456 nbgl_layoutAddSeparationLine(reviewWithWarnCtx.modalLayout);
2457 }
2458 }
2459 headerDesc.backAndText.text = "Security report";
2460 nbgl_layoutAddHeader(reviewWithWarnCtx.modalLayout, &headerDesc);
2461 nbgl_layoutDraw(reviewWithWarnCtx.modalLayout);
2462 nbgl_refresh();
2463 return;
2464 }
2465 if (reviewWithWarnCtx.warning && reviewWithWarnCtx.warning->reportProvider) {
2466 provider = reviewWithWarnCtx.warning->reportProvider;
2467 }
2468 else {
2469 provider = "[unknown]";
2470 }
2471 if ((set & (1 << W3C_THREAT_DETECTED_WARN)) || (set & (1 << W3C_RISK_DETECTED_WARN))) {
2472 size_t urlLen = 0;
2473 char *destStr
2474 = tmpString
2475 + W3C_DESCRIPTION_MAX_LEN / 2; // use the second half of tmpString for strings
2476#ifdef NBGL_QRCODE
2477 // display a QR Code
2478 nbgl_layoutQRCode_t qrCode = {.url = destStr,
2479 .text1 = reviewWithWarnCtx.warning->reportUrl,
2480 .text2 = "Scan to view full report",
2481 .centered = true,
2482 .offsetY = 0};
2483 // add "https://"" as prefix of the given URL
2484 snprintf(destStr,
2485 W3C_DESCRIPTION_MAX_LEN / 2,
2486 "https://%s",
2487 reviewWithWarnCtx.warning->reportUrl);
2488 urlLen = strlen(destStr) + 1;
2489 nbgl_layoutAddQRCode(reviewWithWarnCtx.modalLayout, &qrCode);
2490 footerDesc.emptySpace.height = 24;
2491#endif // NBGL_QRCODE
2492 // use the next part of destStr for back bar text
2493 snprintf(destStr + urlLen, W3C_DESCRIPTION_MAX_LEN / 2 - urlLen, "%s report", provider);
2494 headerDesc.backAndText.text = destStr + urlLen;
2495 }
2496 else if (set & (1 << BLIND_SIGNING_WARN)) {
2497 // display a centered if in review
2498 nbgl_contentCenter_t info = {0};
2499 info.icon = &LARGE_WARNING_ICON;
2500 info.title = "This transaction cannot be Clear Signed";
2501 info.description
2502 = "This transaction or message cannot be decoded fully. If you choose to sign, you "
2503 "could be authorizing malicious actions that can drain your wallet.\n\nLearn more: "
2504 "ledger.com/e8";
2505 nbgl_layoutAddContentCenter(reviewWithWarnCtx.modalLayout, &info);
2506 footerDesc.emptySpace.height = SMALL_CENTERING_HEADER;
2507 headerDesc.separationLine = false;
2508 }
2509 else if (set & (1 << W3C_ISSUE_WARN)) {
2510 // if W3 Checks issue, display a centered info
2511 nbgl_contentCenter_t info = {0};
2512 info.icon = &LARGE_WARNING_ICON;
2513 info.title = "Transaction Check unavailable";
2514 info.description
2515 = "If you're not using the Ledger Wallet app, Transaction Check might not work. If "
2516 "you "
2517 "are using Ledger Wallet, reject the transaction and try again.\n\nGet help at "
2518 "ledger.com/e11";
2519 nbgl_layoutAddContentCenter(reviewWithWarnCtx.modalLayout, &info);
2520 footerDesc.emptySpace.height = SMALL_CENTERING_HEADER;
2521 headerDesc.separationLine = false;
2522 }
2523 nbgl_layoutAddHeader(reviewWithWarnCtx.modalLayout, &headerDesc);
2524 if (footerDesc.emptySpace.height > 0) {
2525 nbgl_layoutAddExtendedFooter(reviewWithWarnCtx.modalLayout, &footerDesc);
2526 }
2527 nbgl_layoutDraw(reviewWithWarnCtx.modalLayout);
2528 nbgl_refresh();
2529}
2530
2531// function used to display the security level page in modal
2532// it can be either a single page with text or QR code, or a list of touchable bars leading
2533// to single pages
2534static void displayCustomizedSecurityReport(const nbgl_warningDetails_t *details)
2535{
2536 reviewWithWarnCtx.modalLayout = displayModalDetails(details, DISMISS_WARNING_TOKEN);
2537}
2538
2539// function used to display the initial warning page when starting a "review with warning"
2540static void displayInitialWarning(void)
2541{
2542 // Play notification sound
2543#ifdef HAVE_PIEZO_SOUND
2544 tune_index_e tune = TUNE_RESERVED;
2545#endif // HAVE_PIEZO_SOUND
2546 nbgl_layoutDescription_t layoutDescription;
2547 nbgl_layoutChoiceButtons_t buttonsInfo = {.bottomText = "Continue anyway",
2548 .token = WARNING_CHOICE_TOKEN,
2549 .topText = "Back to safety",
2550 .style = ROUNDED_AND_FOOTER_STYLE,
2551 .tuneId = TUNE_TAP_CASUAL};
2552 nbgl_layoutHeader_t headerDesc = {.type = HEADER_EMPTY,
2553 .separationLine = false,
2554 .emptySpace.height = MEDIUM_CENTERING_HEADER};
2555 uint32_t set = reviewWithWarnCtx.warning->predefinedSet
2556 & ~((1 << W3C_NO_THREAT_WARN) | (1 << W3C_ISSUE_WARN));
2557
2558 bool isBlindSigningOnly
2559 = (set != 0) && ((set & ~((1 << BLIND_SIGNING_WARN) | (1 << GATED_SIGNING_WARN))) == 0);
2560 reviewWithWarnCtx.isIntro = true;
2561
2562 layoutDescription.modal = false;
2563 layoutDescription.withLeftBorder = true;
2564
2565 layoutDescription.onActionCallback = layoutTouchCallback;
2566 layoutDescription.tapActionText = NULL;
2567
2568 layoutDescription.ticker.tickerCallback = NULL;
2569 reviewWithWarnCtx.layoutCtx = nbgl_layoutGet(&layoutDescription);
2570
2571 nbgl_layoutAddHeader(reviewWithWarnCtx.layoutCtx, &headerDesc);
2572 if (reviewWithWarnCtx.warning->predefinedSet != 0) {
2573 // icon is different in casee of Blind Siging or Gated Signing
2574 nbgl_layoutAddTopRightButton(reviewWithWarnCtx.layoutCtx,
2575 isBlindSigningOnly ? &INFO_I_ICON : &QRCODE_ICON,
2576 WARNING_BUTTON_TOKEN,
2577 TUNE_TAP_CASUAL);
2578 }
2579 else if (reviewWithWarnCtx.warning->introTopRightIcon != NULL) {
2580 nbgl_layoutAddTopRightButton(reviewWithWarnCtx.layoutCtx,
2581 reviewWithWarnCtx.warning->introTopRightIcon,
2582 WARNING_BUTTON_TOKEN,
2583 TUNE_TAP_CASUAL);
2584 }
2585 // add main content
2586 // if predefined content is configured, use it preferably
2587 if (reviewWithWarnCtx.warning->predefinedSet != 0) {
2588 nbgl_contentCenter_t info = {0};
2589
2590 const char *provider;
2591
2592 // default icon
2593 info.icon = &LARGE_WARNING_ICON;
2594
2595 // use small title only if not Blind signing and not Gated signing
2596 if (isBlindSigningOnly == false) {
2597 if (reviewWithWarnCtx.warning->reportProvider) {
2598 provider = reviewWithWarnCtx.warning->reportProvider;
2599 }
2600 else {
2601 provider = "[unknown]";
2602 }
2603 info.smallTitle = tmpString;
2604 snprintf(tmpString, W3C_DESCRIPTION_MAX_LEN, "Detected by %s", provider);
2605 }
2606
2607 // If Blind Signing or Gated Signing
2608 if (isBlindSigningOnly) {
2609 info.title = "Blind signing ahead";
2610 if (set & (1 << GATED_SIGNING_WARN)) {
2611 info.description
2612 = "If you sign this transaction, you could loose all your assets. "
2613 "Explore safer alternatives: ledger.com/integrated-apps";
2614 buttonsInfo.bottomText = "Accept risk and continue";
2615 }
2616 else {
2617 info.description
2618 = "This transaction's details are not fully verifiable. If you sign, you could "
2619 "lose all your assets.";
2620 buttonsInfo.bottomText = "Continue anyway";
2621 }
2622#ifdef HAVE_PIEZO_SOUND
2623 tune = TUNE_NEUTRAL;
2624#endif // HAVE_PIEZO_SOUND
2625 }
2626 else if (set & (1 << W3C_RISK_DETECTED_WARN)) {
2627 info.title = "Potential risk";
2628 if (reviewWithWarnCtx.warning->providerMessage == NULL) {
2629 info.description = "Unidentified risk";
2630 }
2631 else {
2632 info.description = reviewWithWarnCtx.warning->providerMessage;
2633 }
2634 buttonsInfo.bottomText = "Accept risk and continue";
2635#ifdef HAVE_PIEZO_SOUND
2636 tune = TUNE_NEUTRAL;
2637#endif // HAVE_PIEZO_SOUND
2638 }
2639 else if (set & (1 << W3C_THREAT_DETECTED_WARN)) {
2640 info.title = "Critical threat";
2641 if (reviewWithWarnCtx.warning->providerMessage == NULL) {
2642 info.description = "Unidentified threat";
2643 }
2644 else {
2645 info.description = reviewWithWarnCtx.warning->providerMessage;
2646 }
2647 buttonsInfo.bottomText = "Accept threat and continue";
2648#ifdef HAVE_PIEZO_SOUND
2649 tune = TUNE_ERROR;
2650#endif // HAVE_PIEZO_SOUND
2651 }
2652 nbgl_layoutAddContentCenter(reviewWithWarnCtx.layoutCtx, &info);
2653 }
2654 else if (reviewWithWarnCtx.warning->info != NULL) {
2655 // if no predefined content, use custom one
2656 nbgl_layoutAddContentCenter(reviewWithWarnCtx.layoutCtx, reviewWithWarnCtx.warning->info);
2657#ifdef HAVE_PIEZO_SOUND
2658 tune = TUNE_LOOK_AT_ME;
2659#endif // HAVE_PIEZO_SOUND
2660 }
2661 // add button and footer on bottom
2662 nbgl_layoutAddChoiceButtons(reviewWithWarnCtx.layoutCtx, &buttonsInfo);
2663
2664#ifdef HAVE_PIEZO_SOUND
2665 if (tune != TUNE_RESERVED) {
2666 os_io_seph_cmd_piezo_play_tune(tune);
2667 }
2668#endif // HAVE_PIEZO_SOUND
2669 nbgl_layoutDraw(reviewWithWarnCtx.layoutCtx);
2670 nbgl_refresh();
2671}
2672
2673// function used to display the prelude when starting a "review with warning"
2674static void displayPrelude(void)
2675{
2676 nbgl_layoutDescription_t layoutDescription;
2677 nbgl_layoutChoiceButtons_t buttonsInfo
2678 = {.bottomText = reviewWithWarnCtx.warning->prelude->footerText,
2679 .token = PRELUDE_CHOICE_TOKEN,
2680 .topText = reviewWithWarnCtx.warning->prelude->buttonText,
2681 .style = ROUNDED_AND_FOOTER_STYLE,
2682 .tuneId = TUNE_TAP_CASUAL};
2683 nbgl_layoutHeader_t headerDesc = {.type = HEADER_EMPTY,
2684 .separationLine = false,
2685 .emptySpace.height = MEDIUM_CENTERING_HEADER};
2686
2687 reviewWithWarnCtx.isIntro = true;
2688
2689 layoutDescription.modal = false;
2690 layoutDescription.withLeftBorder = true;
2691 layoutDescription.onActionCallback = layoutTouchCallback;
2692 layoutDescription.tapActionText = NULL;
2693 layoutDescription.ticker.tickerCallback = NULL;
2694 reviewWithWarnCtx.layoutCtx = nbgl_layoutGet(&layoutDescription);
2695
2696 nbgl_layoutAddHeader(reviewWithWarnCtx.layoutCtx, &headerDesc);
2697 // add centered content
2698 nbgl_contentCenter_t info = {0};
2699
2700 // default icon
2701 info.icon = reviewWithWarnCtx.warning->prelude->icon;
2702
2703 info.title = reviewWithWarnCtx.warning->prelude->title;
2704 info.description = reviewWithWarnCtx.warning->prelude->description;
2705 nbgl_layoutAddContentCenter(reviewWithWarnCtx.layoutCtx, &info);
2706
2707 // add button and footer on bottom
2708 nbgl_layoutAddChoiceButtons(reviewWithWarnCtx.layoutCtx, &buttonsInfo);
2709
2710#ifdef HAVE_PIEZO_SOUND
2711 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
2712#endif // HAVE_PIEZO_SOUND
2713 nbgl_layoutDraw(reviewWithWarnCtx.layoutCtx);
2714 nbgl_refresh();
2715}
2716
2717// function to factorize code for reviews tipbox
2718static void initWarningTipBox(const nbgl_tipBox_t *tipBox)
2719{
2720 const char *predefinedTipBoxText = NULL;
2721
2722 // if warning is valid and a warning requires a tip-box
2723 if (reviewWithWarnCtx.warning) {
2724 if (reviewWithWarnCtx.warning->predefinedSet & (1 << W3C_ISSUE_WARN)) {
2725 if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
2726 predefinedTipBoxText = "Transaction Check unavailable.\nBlind signing required.";
2727 }
2728 else {
2729 predefinedTipBoxText = "Transaction Check unavailable";
2730 }
2731 }
2732 else if (reviewWithWarnCtx.warning->predefinedSet & (1 << W3C_THREAT_DETECTED_WARN)) {
2733 if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
2734 predefinedTipBoxText = "Critical threat detected.\nBlind signing required.";
2735 }
2736 else {
2737 predefinedTipBoxText = "Critical threat detected.";
2738 }
2739 }
2740 else if (reviewWithWarnCtx.warning->predefinedSet & (1 << W3C_RISK_DETECTED_WARN)) {
2741 if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
2742 predefinedTipBoxText = "Potential risk detected.\nBlind signing required.";
2743 }
2744 else {
2745 predefinedTipBoxText = "Potential risk detected.";
2746 }
2747 }
2748 else if (reviewWithWarnCtx.warning->predefinedSet & (1 << W3C_NO_THREAT_WARN)) {
2749 if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
2750 predefinedTipBoxText
2751 = "No threat detected by Transaction Check but blind signing required.";
2752 }
2753 else {
2754 predefinedTipBoxText = "No threat detected by Transaction Check.";
2755 }
2756 }
2757 else if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
2758 predefinedTipBoxText = "Blind signing required.";
2759 }
2760 }
2761
2762 if ((tipBox != NULL) || (predefinedTipBoxText != NULL)) {
2763 // do not display "Swipe to review" if a tip-box is displayed
2764 STARTING_CONTENT.content.extendedCenter.contentCenter.subText = NULL;
2765 if (predefinedTipBoxText != NULL) {
2766 genericContext.validWarningCtx = true;
2767 STARTING_CONTENT.content.extendedCenter.tipBox.icon = NULL;
2768 STARTING_CONTENT.content.extendedCenter.tipBox.text = predefinedTipBoxText;
2769 }
2770 else {
2771 STARTING_CONTENT.content.extendedCenter.tipBox.icon = tipBox->icon;
2772 STARTING_CONTENT.content.extendedCenter.tipBox.text = tipBox->text;
2773 }
2774 STARTING_CONTENT.content.extendedCenter.tipBox.token = TIP_BOX_TOKEN;
2775 STARTING_CONTENT.content.extendedCenter.tipBox.tuneId = TUNE_TAP_CASUAL;
2776 }
2777}
2778
2779// function to factorize code for all simple reviews
2780static void useCaseReview(nbgl_operationType_t operationType,
2781 const nbgl_contentTagValueList_t *tagValueList,
2782 const nbgl_icon_details_t *icon,
2783 const char *reviewTitle,
2784 const char *reviewSubTitle,
2785 const char *finishTitle,
2786 const nbgl_tipBox_t *tipBox,
2787 nbgl_choiceCallback_t choiceCallback,
2788 bool isLight,
2789 bool playNotifSound)
2790{
2791 bundleNavContext.review.operationType = operationType;
2792 bundleNavContext.review.choiceCallback = choiceCallback;
2793
2794 // memorize context
2795 onChoice = bundleNavReviewChoice;
2796 navType = GENERIC_NAV;
2797 pageTitle = NULL;
2798
2799 genericContext.genericContents.contentsList = localContentsList;
2800 genericContext.genericContents.nbContents = 3;
2801 memset(localContentsList, 0, 3 * sizeof(nbgl_content_t));
2802
2803 // First a centered info
2804 STARTING_CONTENT.type = EXTENDED_CENTER;
2805 prepareReviewFirstPage(
2806 &STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
2807
2808 // Prepare un tipbox if needed
2809 initWarningTipBox(tipBox);
2810
2811 // Then the tag/value pairs
2812 localContentsList[1].type = TAG_VALUE_LIST;
2813 memcpy(&localContentsList[1].content.tagValueList,
2814 tagValueList,
2816 localContentsList[1].contentActionCallback = tagValueList->actionCallback;
2817
2818 // The last page
2819 if (isLight) {
2820 localContentsList[2].type = INFO_BUTTON;
2821 prepareReviewLightLastPage(
2822 operationType, &localContentsList[2].content.infoButton, icon, finishTitle);
2823 }
2824 else {
2825 localContentsList[2].type = INFO_LONG_PRESS;
2826 prepareReviewLastPage(
2827 operationType, &localContentsList[2].content.infoLongPress, icon, finishTitle);
2828 }
2829
2830 // compute number of pages & fill navigation structure
2831 uint8_t nbPages = getNbPagesForGenericContents(
2832 &genericContext.genericContents, 0, (operationType & SKIPPABLE_OPERATION));
2833 prepareNavInfo(true, nbPages, getRejectReviewText(operationType));
2834
2835 // Play notification sound if required
2836 if (playNotifSound) {
2837#ifdef HAVE_PIEZO_SOUND
2838 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
2839#endif // HAVE_PIEZO_SOUND
2840 }
2841
2842 displayGenericContextPage(0, true);
2843}
2844
2845// function to factorize code for all streaming reviews
2846static void useCaseReviewStreamingStart(nbgl_operationType_t operationType,
2847 const nbgl_icon_details_t *icon,
2848 const char *reviewTitle,
2849 const char *reviewSubTitle,
2850 nbgl_choiceCallback_t choiceCallback,
2851 bool playNotifSound)
2852{
2853 bundleNavContext.reviewStreaming.operationType = operationType;
2854 bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
2855 bundleNavContext.reviewStreaming.icon = icon;
2856
2857 // memorize context
2858 onChoice = bundleNavReviewStreamingChoice;
2859 navType = STREAMING_NAV;
2860 pageTitle = NULL;
2861
2862 genericContext.genericContents.contentsList = localContentsList;
2863 genericContext.genericContents.nbContents = 1;
2864 memset(localContentsList, 0, 1 * sizeof(nbgl_content_t));
2865
2866 // First a centered info
2867 STARTING_CONTENT.type = EXTENDED_CENTER;
2868 prepareReviewFirstPage(
2869 &STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
2870
2871 // Prepare un tipbox if needed
2872 initWarningTipBox(NULL);
2873
2874 // compute number of pages & fill navigation structure
2875 bundleNavContext.reviewStreaming.stepPageNb = getNbPagesForGenericContents(
2876 &genericContext.genericContents, 0, (operationType & SKIPPABLE_OPERATION));
2877 prepareNavInfo(true, NBGL_NO_PROGRESS_INDICATOR, getRejectReviewText(operationType));
2878 // no back button on first page
2879 navInfo.navWithButtons.backButton = false;
2880
2881 // Play notification sound if required
2882 if (playNotifSound) {
2883#ifdef HAVE_PIEZO_SOUND
2884 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
2885#endif // HAVE_PIEZO_SOUND
2886 }
2887
2888 displayGenericContextPage(0, true);
2889}
2890
2907static void useCaseHomeExt(const char *appName,
2908 const nbgl_icon_details_t *appIcon,
2909 const char *tagline,
2910 bool withSettings,
2911 nbgl_homeAction_t *homeAction,
2912 nbgl_callback_t topRightCallback,
2913 nbgl_callback_t quitCallback)
2914{
2915 nbgl_pageInfoDescription_t info = {.centeredInfo.icon = appIcon,
2916 .centeredInfo.text1 = appName,
2917 .centeredInfo.text3 = NULL,
2918 .centeredInfo.style = LARGE_CASE_INFO,
2919 .centeredInfo.offsetY = 0,
2920 .footerText = NULL,
2921 .bottomButtonStyle = QUIT_APP_TEXT,
2922 .tapActionText = NULL,
2923 .topRightStyle = withSettings ? SETTINGS_ICON : INFO_ICON,
2924 .topRightToken = CONTINUE_TOKEN,
2925 .tuneId = TUNE_TAP_CASUAL};
2926 reset_callbacks_and_context();
2927
2928 if ((homeAction->text != NULL) || (homeAction->icon != NULL)) {
2929 // trick to use ACTION_BUTTON_TOKEN for action and quit, with index used to distinguish
2930 info.bottomButtonsToken = ACTION_BUTTON_TOKEN;
2931 onAction = homeAction->callback;
2932 info.actionButtonText = homeAction->text;
2933 info.actionButtonIcon = homeAction->icon;
2936 }
2937 else {
2938 info.bottomButtonsToken = QUIT_TOKEN;
2939 onAction = NULL;
2940 info.actionButtonText = NULL;
2941 info.actionButtonIcon = NULL;
2942 }
2943 if (tagline == NULL) {
2944 if (strlen(appName) > MAX_APP_NAME_FOR_SDK_TAGLINE) {
2945 snprintf(tmpString,
2947 "This app enables signing\ntransactions on its network.");
2948 }
2949 else {
2950 snprintf(tmpString,
2952 "%s %s\n%s",
2954 appName,
2956 }
2957
2958 // If there is more than 3 lines, it means the appName was split, so we put it on the next
2959 // line
2960 if (nbgl_getTextNbLinesInWidth(SMALL_REGULAR_FONT, tmpString, AVAILABLE_WIDTH, false) > 3) {
2961 snprintf(tmpString,
2963 "%s\n%s %s",
2965 appName,
2967 }
2968 info.centeredInfo.text2 = tmpString;
2969 }
2970 else {
2971 info.centeredInfo.text2 = tagline;
2972 }
2973
2974 onContinue = topRightCallback;
2975 onQuit = quitCallback;
2976
2977 pageContext = nbgl_pageDrawInfo(&pageCallback, NULL, &info);
2979}
2980
2989static void displayDetails(const char *tag, const char *value, bool wrapping)
2990{
2991 memset(&detailsContext, 0, sizeof(detailsContext));
2992
2993 uint16_t nbLines
2994 = nbgl_getTextNbLinesInWidth(SMALL_REGULAR_FONT, value, AVAILABLE_WIDTH, wrapping);
2995
2996 // initialize context
2997 detailsContext.tag = tag;
2998 detailsContext.value = value;
2999 detailsContext.nbPages = (nbLines + NB_MAX_LINES_IN_DETAILS - 1) / NB_MAX_LINES_IN_DETAILS;
3000 detailsContext.currentPage = 0;
3001 detailsContext.wrapping = wrapping;
3002 // add some spare for room lost with "..." substitution
3003 if (detailsContext.nbPages > 1) {
3004 uint16_t nbLostChars = (detailsContext.nbPages - 1) * 3;
3005 uint16_t nbLostLines = (nbLostChars + ((AVAILABLE_WIDTH) / 16) - 1)
3006 / ((AVAILABLE_WIDTH) / 16); // 16 for average char width
3007 uint8_t nbLinesInLastPage
3008 = nbLines - ((detailsContext.nbPages - 1) * NB_MAX_LINES_IN_DETAILS);
3009
3010 detailsContext.nbPages += nbLostLines / NB_MAX_LINES_IN_DETAILS;
3011 if ((nbLinesInLastPage + (nbLostLines % NB_MAX_LINES_IN_DETAILS))
3013 detailsContext.nbPages++;
3014 }
3015 }
3016
3017 displayDetailsPage(0, true);
3018}
3019
3020// function used to display the modal containing alias tag-value pairs
3021static void displayTagValueListModal(const nbgl_contentTagValueList_t *tagValues)
3022{
3023 uint8_t nbElements = 0;
3024 uint8_t nbElementsInPage;
3025 uint8_t elemIdx = 0;
3026
3027 // initialize context
3028 memset(&detailsContext, 0, sizeof(detailsContext));
3029 nbElements = tagValues->nbPairs;
3030
3031 while (nbElements > 0) {
3032 nbElementsInPage = getNbTagValuesInDetailsPage(nbElements, tagValues, elemIdx);
3033
3034 elemIdx += nbElementsInPage;
3035 modalContextSetPageInfo(detailsContext.nbPages, nbElementsInPage);
3036 nbElements -= nbElementsInPage;
3037 detailsContext.nbPages++;
3038 }
3039
3040 displayTagValueListModalPage(0, true);
3041}
3042
3043/**********************
3044 * GLOBAL FUNCTIONS
3045 **********************/
3046
3059uint8_t nbgl_useCaseGetNbTagValuesInPage(uint8_t nbPairs,
3060 const nbgl_contentTagValueList_t *tagValueList,
3061 uint8_t startIndex,
3062 bool *requireSpecificDisplay)
3063{
3064 return getNbTagValuesInPage(
3065 nbPairs, tagValueList, startIndex, false, false, false, requireSpecificDisplay);
3066}
3067
3081uint8_t nbgl_useCaseGetNbTagValuesInPageExt(uint8_t nbPairs,
3082 const nbgl_contentTagValueList_t *tagValueList,
3083 uint8_t startIndex,
3084 bool isSkippable,
3085 bool *requireSpecificDisplay)
3086{
3087 return getNbTagValuesInPage(
3088 nbPairs, tagValueList, startIndex, isSkippable, false, false, requireSpecificDisplay);
3089}
3090
3100uint8_t nbgl_useCaseGetNbInfosInPage(uint8_t nbInfos,
3101 const nbgl_contentInfoList_t *infosList,
3102 uint8_t startIndex,
3103 bool withNav)
3104{
3105 uint8_t nbInfosInPage = 0;
3106 uint16_t currentHeight = 0;
3107 uint16_t previousHeight;
3108 uint16_t navHeight = withNav ? SIMPLE_FOOTER_HEIGHT : 0;
3109 const char *const *infoContents = PIC(infosList->infoContents);
3110
3111 while (nbInfosInPage < nbInfos) {
3112 // The type string must be a 1 liner and its height is LIST_ITEM_MIN_TEXT_HEIGHT
3113 currentHeight
3114 += LIST_ITEM_MIN_TEXT_HEIGHT + 2 * LIST_ITEM_PRE_HEADING + LIST_ITEM_HEADING_SUB_TEXT;
3115
3116 // content height
3117 currentHeight += nbgl_getTextHeightInWidth(SMALL_REGULAR_FONT,
3118 PIC(infoContents[startIndex + nbInfosInPage]),
3120 true);
3121 // if height is over the limit
3122 if (currentHeight >= (INFOS_AREA_HEIGHT - navHeight)) {
3123 // if there was no nav, now there will be, so it can be necessary to remove the last
3124 // item
3125 if (!withNav && (previousHeight >= (INFOS_AREA_HEIGHT - SIMPLE_FOOTER_HEIGHT))) {
3126 nbInfosInPage--;
3127 }
3128 break;
3129 }
3130 previousHeight = currentHeight;
3131 nbInfosInPage++;
3132 }
3133 return nbInfosInPage;
3134}
3135
3145uint8_t nbgl_useCaseGetNbSwitchesInPage(uint8_t nbSwitches,
3146 const nbgl_contentSwitchesList_t *switchesList,
3147 uint8_t startIndex,
3148 bool withNav)
3149{
3150 uint8_t nbSwitchesInPage = 0;
3151 uint16_t currentHeight = 0;
3152 uint16_t previousHeight = 0;
3153 uint16_t navHeight = withNav ? SIMPLE_FOOTER_HEIGHT : 0;
3154 nbgl_contentSwitch_t *switchArray = (nbgl_contentSwitch_t *) PIC(switchesList->switches);
3155
3156 while (nbSwitchesInPage < nbSwitches) {
3157 nbgl_contentSwitch_t *curSwitch = &switchArray[startIndex + nbSwitchesInPage];
3158 // The text string is either a 1 liner and its height is LIST_ITEM_MIN_TEXT_HEIGHT
3159 // or we use its height directly
3160 uint16_t textHeight = MAX(
3161 LIST_ITEM_MIN_TEXT_HEIGHT,
3162 nbgl_getTextHeightInWidth(SMALL_BOLD_FONT, curSwitch->text, AVAILABLE_WIDTH, true));
3163 currentHeight += textHeight + 2 * LIST_ITEM_PRE_HEADING;
3164
3165 if (curSwitch->subText) {
3166 currentHeight += LIST_ITEM_HEADING_SUB_TEXT;
3167
3168 // sub-text height
3169 currentHeight += nbgl_getTextHeightInWidth(
3170 SMALL_REGULAR_FONT, curSwitch->subText, AVAILABLE_WIDTH, true);
3171 }
3172 // if height is over the limit
3173 if (currentHeight >= (INFOS_AREA_HEIGHT - navHeight)) {
3174 break;
3175 }
3176 previousHeight = currentHeight;
3177 nbSwitchesInPage++;
3178 }
3179 // if there was no nav, now there will be, so it can be necessary to remove the last
3180 // item
3181 if (!withNav && (previousHeight >= (INFOS_AREA_HEIGHT - SIMPLE_FOOTER_HEIGHT))) {
3182 nbSwitchesInPage--;
3183 }
3184 return nbSwitchesInPage;
3185}
3186
3196uint8_t nbgl_useCaseGetNbBarsInPage(uint8_t nbBars,
3197 const nbgl_contentBarsList_t *barsList,
3198 uint8_t startIndex,
3199 bool withNav)
3200{
3201 uint8_t nbBarsInPage = 0;
3202 uint16_t currentHeight = 0;
3203 uint16_t previousHeight;
3204 uint16_t navHeight = withNav ? SIMPLE_FOOTER_HEIGHT : 0;
3205
3206 UNUSED(barsList);
3207 UNUSED(startIndex);
3208
3209 while (nbBarsInPage < nbBars) {
3210 currentHeight += LIST_ITEM_MIN_TEXT_HEIGHT + 2 * LIST_ITEM_PRE_HEADING;
3211 // if height is over the limit
3212 if (currentHeight >= (INFOS_AREA_HEIGHT - navHeight)) {
3213 break;
3214 }
3215 previousHeight = currentHeight;
3216 nbBarsInPage++;
3217 }
3218 // if there was no nav, now there may will be, so it can be necessary to remove the last
3219 // item
3220 if (!withNav && (previousHeight >= (INFOS_AREA_HEIGHT - SIMPLE_FOOTER_HEIGHT))) {
3221 nbBarsInPage--;
3222 }
3223 return nbBarsInPage;
3224}
3225
3235uint8_t nbgl_useCaseGetNbChoicesInPage(uint8_t nbChoices,
3236 const nbgl_contentRadioChoice_t *choicesList,
3237 uint8_t startIndex,
3238 bool withNav)
3239{
3240 uint8_t nbChoicesInPage = 0;
3241 uint16_t currentHeight = 0;
3242 uint16_t previousHeight;
3243 uint16_t navHeight = withNav ? SIMPLE_FOOTER_HEIGHT : 0;
3244
3245 UNUSED(choicesList);
3246 UNUSED(startIndex);
3247
3248 while (nbChoicesInPage < nbChoices) {
3249 currentHeight += LIST_ITEM_MIN_TEXT_HEIGHT + 2 * LIST_ITEM_PRE_HEADING;
3250 // if height is over the limit
3251 if (currentHeight >= (INFOS_AREA_HEIGHT - navHeight)) {
3252 // if there was no nav, now there will be, so it can be necessary to remove the last
3253 // item
3254 if (!withNav && (previousHeight >= (INFOS_AREA_HEIGHT - SIMPLE_FOOTER_HEIGHT))) {
3255 nbChoicesInPage--;
3256 }
3257 break;
3258 }
3259 previousHeight = currentHeight;
3260 nbChoicesInPage++;
3261 }
3262 return nbChoicesInPage;
3263}
3264
3272{
3273 uint8_t nbPages = 0;
3274 uint8_t nbPairs = tagValueList->nbPairs;
3275 uint8_t nbPairsInPage;
3276 uint8_t i = 0;
3277 bool flag;
3278
3279 while (i < tagValueList->nbPairs) {
3280 // upper margin
3281 nbPairsInPage = nbgl_useCaseGetNbTagValuesInPageExt(nbPairs, tagValueList, i, false, &flag);
3282 i += nbPairsInPage;
3283 nbPairs -= nbPairsInPage;
3284 nbPages++;
3285 }
3286 return nbPages;
3287}
3288
3293void nbgl_useCaseHome(const char *appName,
3294 const nbgl_icon_details_t *appIcon,
3295 const char *tagline,
3296 bool withSettings,
3297 nbgl_callback_t topRightCallback,
3298 nbgl_callback_t quitCallback)
3299{
3300 nbgl_homeAction_t homeAction = {0};
3301 useCaseHomeExt(
3302 appName, appIcon, tagline, withSettings, &homeAction, topRightCallback, quitCallback);
3303}
3304
3309void nbgl_useCaseHomeExt(const char *appName,
3310 const nbgl_icon_details_t *appIcon,
3311 const char *tagline,
3312 bool withSettings,
3313 const char *actionButtonText,
3314 nbgl_callback_t actionCallback,
3315 nbgl_callback_t topRightCallback,
3316 nbgl_callback_t quitCallback)
3317{
3318 nbgl_homeAction_t homeAction = {.callback = actionCallback,
3319 .icon = NULL,
3320 .style = STRONG_HOME_ACTION,
3321 .text = actionButtonText};
3322
3323 useCaseHomeExt(
3324 appName, appIcon, tagline, withSettings, &homeAction, topRightCallback, quitCallback);
3325}
3326
3340void nbgl_useCaseNavigableContent(const char *title,
3341 uint8_t initPage,
3342 uint8_t nbPages,
3343 nbgl_callback_t quitCallback,
3344 nbgl_navCallback_t navCallback,
3345 nbgl_layoutTouchCallback_t controlsCallback)
3346{
3347 reset_callbacks_and_context();
3348
3349 // memorize context
3350 onQuit = quitCallback;
3351 onNav = navCallback;
3352 onControls = controlsCallback;
3353 pageTitle = title;
3354 navType = SETTINGS_NAV;
3355
3356 // fill navigation structure
3357 prepareNavInfo(false, nbPages, NULL);
3358
3359 displaySettingsPage(initPage, true);
3360}
3361
3367void nbgl_useCaseSettings(const char *title,
3368 uint8_t initPage,
3369 uint8_t nbPages,
3370 bool touchable,
3371 nbgl_callback_t quitCallback,
3372 nbgl_navCallback_t navCallback,
3373 nbgl_layoutTouchCallback_t controlsCallback)
3374{
3375 UNUSED(touchable);
3377 title, initPage, nbPages, quitCallback, navCallback, controlsCallback);
3378}
3379
3392void nbgl_useCaseGenericSettings(const char *appName,
3393 uint8_t initPage,
3394 const nbgl_genericContents_t *settingContents,
3395 const nbgl_contentInfoList_t *infosList,
3396 nbgl_callback_t quitCallback)
3397{
3398 reset_callbacks_and_context();
3399
3400 // memorize context
3401 onQuit = quitCallback;
3402 pageTitle = appName;
3403 navType = GENERIC_NAV;
3404
3405 if (settingContents != NULL) {
3406 memcpy(&genericContext.genericContents, settingContents, sizeof(nbgl_genericContents_t));
3407 }
3408 if (infosList != NULL) {
3409 genericContext.hasFinishingContent = true;
3410 memset(&FINISHING_CONTENT, 0, sizeof(nbgl_content_t));
3411 FINISHING_CONTENT.type = INFOS_LIST;
3412 memcpy(&FINISHING_CONTENT.content, infosList, sizeof(nbgl_content_u));
3413 }
3414
3415 // fill navigation structure
3416 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
3417 if (infosList != NULL) {
3418 nbPages += getNbPagesForContent(&FINISHING_CONTENT, nbPages, true, false);
3419 }
3420
3421 prepareNavInfo(false, nbPages, NULL);
3422
3423 displayGenericContextPage(initPage, true);
3424}
3425
3437void nbgl_useCaseGenericConfiguration(const char *title,
3438 uint8_t initPage,
3439 const nbgl_genericContents_t *contents,
3440 nbgl_callback_t quitCallback)
3441{
3442 nbgl_useCaseGenericSettings(title, initPage, contents, NULL, quitCallback);
3443}
3444
3462 const char *appName,
3463 const nbgl_icon_details_t *appIcon,
3464 const char *tagline,
3465 const uint8_t
3466 initSettingPage, // if not INIT_HOME_PAGE, start directly the corresponding setting page
3467 const nbgl_genericContents_t *settingContents,
3468 const nbgl_contentInfoList_t *infosList,
3469 const nbgl_homeAction_t *action, // Set to NULL if no additional action
3470 nbgl_callback_t quitCallback)
3471{
3472 nbgl_homeAndSettingsContext_t *context = &bundleNavContext.homeAndSettings;
3473
3474 reset_callbacks_and_context();
3475
3476 context->appName = appName;
3477 context->appIcon = appIcon;
3478 context->tagline = tagline;
3479 context->settingContents = settingContents;
3480 context->infosList = infosList;
3481 if (action != NULL) {
3482 memcpy(&context->homeAction, action, sizeof(nbgl_homeAction_t));
3483 }
3484 else {
3485 memset(&context->homeAction, 0, sizeof(nbgl_homeAction_t));
3486 }
3487 context->quitCallback = quitCallback;
3488
3489 if (initSettingPage != INIT_HOME_PAGE) {
3490 bundleNavStartSettingsAtPage(initSettingPage);
3491 }
3492 else {
3493 bundleNavStartHome();
3494 }
3495}
3496
3504void nbgl_useCaseStatus(const char *message, bool isSuccess, nbgl_callback_t quitCallback)
3505{
3506 nbgl_screenTickerConfiguration_t ticker = {.tickerCallback = &tickerCallback,
3507 .tickerIntervale = 0, // not periodic
3508 .tickerValue = STATUS_SCREEN_DURATION};
3509 nbgl_pageInfoDescription_t info = {0};
3510
3511 reset_callbacks_and_context();
3512
3513 onQuit = quitCallback;
3514 if (isSuccess) {
3515#ifdef HAVE_PIEZO_SOUND
3516 os_io_seph_cmd_piezo_play_tune(TUNE_LEDGER_MOMENT);
3517#endif // HAVE_PIEZO_SOUND
3518 }
3519 info.centeredInfo.icon = isSuccess ? &CHECK_CIRCLE_ICON : &DENIED_CIRCLE_ICON;
3521 info.centeredInfo.text1 = message;
3522 info.tapActionText = "";
3523 info.tapActionToken = QUIT_TOKEN;
3524 info.tuneId = TUNE_TAP_CASUAL;
3525 pageContext = nbgl_pageDrawInfo(&pageCallback, &ticker, &info);
3527}
3528
3536 nbgl_callback_t quitCallback)
3537{
3538 const char *msg;
3539 bool isSuccess;
3540 switch (reviewStatusType) {
3542 msg = "Operation signed";
3543 isSuccess = true;
3544 break;
3546 msg = "Operation rejected";
3547 isSuccess = false;
3548 break;
3550 msg = "Transaction signed";
3551 isSuccess = true;
3552 break;
3554 msg = "Transaction rejected";
3555 isSuccess = false;
3556 break;
3558 msg = "Message signed";
3559 isSuccess = true;
3560 break;
3562 msg = "Message rejected";
3563 isSuccess = false;
3564 break;
3566 msg = "Address verified";
3567 isSuccess = true;
3568 break;
3570 msg = "Address verification\ncancelled";
3571 isSuccess = false;
3572 break;
3573 default:
3574 return;
3575 }
3576 nbgl_useCaseStatus(msg, isSuccess, quitCallback);
3577}
3578
3592 const char *message,
3593 const char *subMessage,
3594 const char *confirmText,
3595 const char *cancelText,
3596 nbgl_choiceCallback_t callback)
3597{
3599 // check params
3600 if ((confirmText == NULL) || (cancelText == NULL)) {
3601 return;
3602 }
3603 reset_callbacks_and_context();
3604
3605 info.cancelText = cancelText;
3606 info.centeredInfo.text1 = message;
3607 info.centeredInfo.text2 = subMessage;
3609 info.centeredInfo.icon = icon;
3610 info.confirmationText = confirmText;
3611 info.confirmationToken = CHOICE_TOKEN;
3612 info.tuneId = TUNE_TAP_CASUAL;
3613
3614 onChoice = callback;
3615 pageContext = nbgl_pageDrawConfirmation(&pageCallback, &info);
3617}
3618
3634 const char *message,
3635 const char *subMessage,
3636 const char *confirmText,
3637 const char *cancelText,
3638 nbgl_genericDetails_t *details,
3639 nbgl_choiceCallback_t callback)
3640{
3641 nbgl_layoutDescription_t layoutDescription;
3642 nbgl_layoutChoiceButtons_t buttonsInfo = {.bottomText = cancelText,
3643 .token = CHOICE_TOKEN,
3644 .topText = confirmText,
3645 .style = ROUNDED_AND_FOOTER_STYLE,
3646 .tuneId = TUNE_TAP_CASUAL};
3647 nbgl_contentCenter_t centeredInfo = {0};
3648 nbgl_layoutHeader_t headerDesc = {.type = HEADER_EMPTY,
3649 .separationLine = false,
3650 .emptySpace.height = MEDIUM_CENTERING_HEADER};
3651
3652 // check params
3653 if ((confirmText == NULL) || (cancelText == NULL)) {
3654 return;
3655 }
3656
3657 reset_callbacks_and_context();
3658
3659 onChoice = callback;
3660 layoutDescription.modal = false;
3661 layoutDescription.withLeftBorder = true;
3662
3663 layoutDescription.onActionCallback = layoutTouchCallback;
3664 layoutDescription.tapActionText = NULL;
3665
3666 layoutDescription.ticker.tickerCallback = NULL;
3667 sharedContext.usage = SHARE_CTX_CHOICE_WITH_DETAILS;
3668 choiceWithDetailsCtx.layoutCtx = nbgl_layoutGet(&layoutDescription);
3669 choiceWithDetailsCtx.details = details;
3670
3671 nbgl_layoutAddHeader(choiceWithDetailsCtx.layoutCtx, &headerDesc);
3672 nbgl_layoutAddChoiceButtons(choiceWithDetailsCtx.layoutCtx, &buttonsInfo);
3673 centeredInfo.icon = icon;
3674 centeredInfo.title = message;
3675 centeredInfo.description = subMessage;
3676 nbgl_layoutAddContentCenter(choiceWithDetailsCtx.layoutCtx, &centeredInfo);
3677
3678 if (details != NULL) {
3680 choiceWithDetailsCtx.layoutCtx, &SEARCH_ICON, CHOICE_DETAILS_TOKEN, TUNE_TAP_CASUAL);
3681 }
3682
3683 nbgl_layoutDraw(choiceWithDetailsCtx.layoutCtx);
3685}
3686
3700void nbgl_useCaseConfirm(const char *message,
3701 const char *subMessage,
3702 const char *confirmText,
3703 const char *cancelText,
3704 nbgl_callback_t callback)
3705{
3706 // Don't reset callback or nav context as this is just a modal.
3707
3708 nbgl_pageConfirmationDescription_t info = {.cancelText = cancelText,
3709 .centeredInfo.text1 = message,
3710 .centeredInfo.text2 = subMessage,
3711 .centeredInfo.text3 = NULL,
3712 .centeredInfo.style = LARGE_CASE_INFO,
3713 .centeredInfo.icon = &IMPORTANT_CIRCLE_ICON,
3714 .centeredInfo.offsetY = 0,
3715 .confirmationText = confirmText,
3716 .confirmationToken = CHOICE_TOKEN,
3717 .tuneId = TUNE_TAP_CASUAL,
3718 .modal = true};
3719 onModalConfirm = callback;
3720 if (modalPageContext != NULL) {
3721 nbgl_pageRelease(modalPageContext);
3722 }
3723 modalPageContext = nbgl_pageDrawConfirmation(&pageModalCallback, &info);
3725}
3726
3738 const char *message,
3739 const char *actionText,
3740 nbgl_callback_t callback)
3741{
3742 nbgl_pageContent_t content = {0};
3743
3744 reset_callbacks_and_context();
3745 // memorize callback
3746 onAction = callback;
3747
3748 content.tuneId = TUNE_TAP_CASUAL;
3749 content.type = INFO_BUTTON;
3750 content.infoButton.buttonText = actionText;
3751 content.infoButton.text = message;
3752 content.infoButton.icon = icon;
3753 content.infoButton.buttonToken = ACTION_BUTTON_TOKEN;
3754
3755 pageContext = nbgl_pageDrawGenericContent(&pageCallback, NULL, &content);
3757}
3758
3771 const char *reviewTitle,
3772 const char *reviewSubTitle,
3773 const char *rejectText,
3774 nbgl_callback_t continueCallback,
3775 nbgl_callback_t rejectCallback)
3776{
3777 nbgl_pageInfoDescription_t info = {.footerText = rejectText,
3778 .footerToken = QUIT_TOKEN,
3779 .tapActionText = NULL,
3780 .isSwipeable = true,
3781 .tapActionToken = CONTINUE_TOKEN,
3782 .topRightStyle = NO_BUTTON_STYLE,
3783 .actionButtonText = NULL,
3784 .tuneId = TUNE_TAP_CASUAL};
3785
3786 reset_callbacks_and_context();
3787
3788 info.centeredInfo.icon = icon;
3789 info.centeredInfo.text1 = reviewTitle;
3790 info.centeredInfo.text2 = reviewSubTitle;
3791 info.centeredInfo.text3 = "Swipe to review";
3793 info.centeredInfo.offsetY = 0;
3794 onQuit = rejectCallback;
3795 onContinue = continueCallback;
3796
3797#ifdef HAVE_PIEZO_SOUND
3798 // Play notification sound
3799 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
3800#endif // HAVE_PIEZO_SOUND
3801
3802 pageContext = nbgl_pageDrawInfo(&pageCallback, NULL, &info);
3803 nbgl_refresh();
3804}
3805
3810void nbgl_useCaseRegularReview(uint8_t initPage,
3811 uint8_t nbPages,
3812 const char *rejectText,
3813 nbgl_layoutTouchCallback_t buttonCallback,
3814 nbgl_navCallback_t navCallback,
3815 nbgl_choiceCallback_t choiceCallback)
3816{
3817 reset_callbacks_and_context();
3818
3819 // memorize context
3820 onChoice = choiceCallback;
3821 onNav = navCallback;
3822 onControls = buttonCallback;
3823 forwardNavOnly = false;
3824 navType = REVIEW_NAV;
3825
3826 // fill navigation structure
3827 UNUSED(rejectText);
3828 prepareNavInfo(true, nbPages, getRejectReviewText(TYPE_OPERATION));
3829
3830 displayReviewPage(initPage, true);
3831}
3832
3846 const nbgl_pageInfoLongPress_t *infoLongPress,
3847 const char *rejectText,
3848 nbgl_choiceCallback_t callback)
3849{
3850 uint8_t offset = 0;
3851
3852 reset_callbacks_and_context();
3853
3854 // memorize context
3855 onChoice = callback;
3856 navType = GENERIC_NAV;
3857 pageTitle = NULL;
3858 bundleNavContext.review.operationType = TYPE_OPERATION;
3859
3860 genericContext.genericContents.contentsList = localContentsList;
3861 memset(localContentsList, 0, 2 * sizeof(nbgl_content_t));
3862
3863 if (tagValueList != NULL && tagValueList->nbPairs != 0) {
3864 localContentsList[offset].type = TAG_VALUE_LIST;
3865 memcpy(&localContentsList[offset].content.tagValueList,
3866 tagValueList,
3868 offset++;
3869 }
3870
3871 localContentsList[offset].type = INFO_LONG_PRESS;
3872 memcpy(&localContentsList[offset].content.infoLongPress,
3873 infoLongPress,
3874 sizeof(nbgl_pageInfoLongPress_t));
3875 localContentsList[offset].content.infoLongPress.longPressToken = CONFIRM_TOKEN;
3876 offset++;
3877
3878 genericContext.genericContents.nbContents = offset;
3879
3880 // compute number of pages & fill navigation structure
3881 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
3882 UNUSED(rejectText);
3883 prepareNavInfo(true, nbPages, getRejectReviewText(TYPE_OPERATION));
3884
3885 displayGenericContextPage(0, true);
3886}
3887
3902 const nbgl_pageInfoLongPress_t *infoLongPress,
3903 const char *rejectText,
3904 nbgl_choiceCallback_t callback)
3905{
3906 uint8_t offset = 0;
3907
3908 reset_callbacks_and_context();
3909
3910 // memorize context
3911 onChoice = callback;
3912 navType = GENERIC_NAV;
3913 pageTitle = NULL;
3914
3915 genericContext.genericContents.contentsList = localContentsList;
3916 memset(localContentsList, 0, 2 * sizeof(nbgl_content_t));
3917
3918 if (tagValueList != NULL && tagValueList->nbPairs != 0) {
3919 localContentsList[offset].type = TAG_VALUE_LIST;
3920 memcpy(&localContentsList[offset].content.tagValueList,
3921 tagValueList,
3923 offset++;
3924 }
3925
3926 localContentsList[offset].type = INFO_BUTTON;
3927 localContentsList[offset].content.infoButton.text = infoLongPress->text;
3928 localContentsList[offset].content.infoButton.icon = infoLongPress->icon;
3929 localContentsList[offset].content.infoButton.buttonText = infoLongPress->longPressText;
3930 localContentsList[offset].content.infoButton.buttonToken = CONFIRM_TOKEN;
3931 localContentsList[offset].content.infoButton.tuneId = TUNE_TAP_CASUAL;
3932 offset++;
3933
3934 genericContext.genericContents.nbContents = offset;
3935
3936 // compute number of pages & fill navigation structure
3937 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
3938 UNUSED(rejectText);
3939 prepareNavInfo(true, nbPages, getRejectReviewText(TYPE_OPERATION));
3940
3941 displayGenericContextPage(0, true);
3942}
3943
3960void nbgl_useCaseReview(nbgl_operationType_t operationType,
3961 const nbgl_contentTagValueList_t *tagValueList,
3962 const nbgl_icon_details_t *icon,
3963 const char *reviewTitle,
3964 const char *reviewSubTitle,
3965 const char *finishTitle,
3966 nbgl_choiceCallback_t choiceCallback)
3967{
3968 reset_callbacks_and_context();
3969
3970 useCaseReview(operationType,
3971 tagValueList,
3972 icon,
3973 reviewTitle,
3974 reviewSubTitle,
3975 finishTitle,
3976 NULL,
3977 choiceCallback,
3978 false,
3979 true);
3980}
3981
4002 const nbgl_contentTagValueList_t *tagValueList,
4003 const nbgl_icon_details_t *icon,
4004 const char *reviewTitle,
4005 const char *reviewSubTitle,
4006 const char *finishTitle,
4007 const nbgl_tipBox_t *tipBox,
4008 nbgl_choiceCallback_t choiceCallback)
4009{
4010 nbgl_useCaseAdvancedReview(operationType,
4011 tagValueList,
4012 icon,
4013 reviewTitle,
4014 reviewSubTitle,
4015 finishTitle,
4016 tipBox,
4017 &blindSigningWarning,
4018 choiceCallback);
4019}
4020
4044 const nbgl_contentTagValueList_t *tagValueList,
4045 const nbgl_icon_details_t *icon,
4046 const char *reviewTitle,
4047 const char *reviewSubTitle,
4048 const char *finishTitle,
4049 const nbgl_tipBox_t *tipBox,
4050 const nbgl_warning_t *warning,
4051 nbgl_choiceCallback_t choiceCallback)
4052{
4053 reset_callbacks_and_context();
4054
4055 // memorize tipBox because it can be in the call stack of the caller
4056 if (tipBox != NULL) {
4057 memcpy(&activeTipBox, tipBox, sizeof(activeTipBox));
4058 }
4059 // if no warning at all, it's a simple review
4060 if ((warning == NULL)
4061 || ((warning->predefinedSet == 0) && (warning->introDetails == NULL)
4062 && (warning->reviewDetails == NULL) && (warning->prelude == NULL))) {
4063 useCaseReview(operationType,
4064 tagValueList,
4065 icon,
4066 reviewTitle,
4067 reviewSubTitle,
4068 finishTitle,
4069 tipBox,
4070 choiceCallback,
4071 false,
4072 true);
4073 return;
4074 }
4075 if (warning->predefinedSet == (1 << W3C_NO_THREAT_WARN)) {
4076 operationType |= NO_THREAT_OPERATION;
4077 }
4078 else if (warning->predefinedSet != 0) {
4079 operationType |= RISKY_OPERATION;
4080 }
4081 sharedContext.usage = SHARE_CTX_REVIEW_WITH_WARNING;
4082 reviewWithWarnCtx.isStreaming = false;
4083 reviewWithWarnCtx.operationType = operationType;
4084 reviewWithWarnCtx.tagValueList = tagValueList;
4085 reviewWithWarnCtx.icon = icon;
4086 reviewWithWarnCtx.reviewTitle = reviewTitle;
4087 reviewWithWarnCtx.reviewSubTitle = reviewSubTitle;
4088 reviewWithWarnCtx.finishTitle = finishTitle;
4089 reviewWithWarnCtx.warning = warning;
4090 reviewWithWarnCtx.choiceCallback = choiceCallback;
4091
4092 // if the warning contains a prelude, display it first
4093 if (reviewWithWarnCtx.warning->prelude) {
4094 displayPrelude();
4095 }
4096 // display the initial warning only of a risk/threat or blind signing or prelude
4097 else if (HAS_INITIAL_WARNING(warning)) {
4098 displayInitialWarning();
4099 }
4100 else {
4101 useCaseReview(operationType,
4102 tagValueList,
4103 icon,
4104 reviewTitle,
4105 reviewSubTitle,
4106 finishTitle,
4107 tipBox,
4108 choiceCallback,
4109 false,
4110 true);
4111 }
4112}
4113
4131 const nbgl_contentTagValueList_t *tagValueList,
4132 const nbgl_icon_details_t *icon,
4133 const char *reviewTitle,
4134 const char *reviewSubTitle,
4135 const char *finishTitle,
4136 nbgl_choiceCallback_t choiceCallback)
4137{
4138 reset_callbacks_and_context();
4139
4140 useCaseReview(operationType,
4141 tagValueList,
4142 icon,
4143 reviewTitle,
4144 reviewSubTitle,
4145 finishTitle,
4146 NULL,
4147 choiceCallback,
4148 true,
4149 true);
4150}
4151
4161 const char *rejectText,
4162 nbgl_callback_t rejectCallback)
4163{
4164 reset_callbacks_and_context();
4165
4166 // memorize context
4167 onQuit = rejectCallback;
4168 navType = GENERIC_NAV;
4169 pageTitle = NULL;
4170 bundleNavContext.review.operationType = TYPE_OPERATION;
4171
4172 memcpy(&genericContext.genericContents, contents, sizeof(nbgl_genericContents_t));
4173
4174 // compute number of pages & fill navigation structure
4175 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
4176 prepareNavInfo(true, nbPages, rejectText);
4177 navInfo.quitToken = QUIT_TOKEN;
4178
4179#ifdef HAVE_PIEZO_SOUND
4180 // Play notification sound
4181 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
4182#endif // HAVE_PIEZO_SOUND
4183
4184 displayGenericContextPage(0, true);
4185}
4186
4200 const nbgl_icon_details_t *icon,
4201 const char *reviewTitle,
4202 const char *reviewSubTitle,
4203 nbgl_choiceCallback_t choiceCallback)
4204{
4205 reset_callbacks_and_context();
4206
4207 useCaseReviewStreamingStart(
4208 operationType, icon, reviewTitle, reviewSubTitle, choiceCallback, true);
4209}
4210
4225 const nbgl_icon_details_t *icon,
4226 const char *reviewTitle,
4227 const char *reviewSubTitle,
4228 nbgl_choiceCallback_t choiceCallback)
4229{
4231 operationType, icon, reviewTitle, reviewSubTitle, &blindSigningWarning, choiceCallback);
4232}
4233
4250 const nbgl_icon_details_t *icon,
4251 const char *reviewTitle,
4252 const char *reviewSubTitle,
4253 const nbgl_warning_t *warning,
4254 nbgl_choiceCallback_t choiceCallback)
4255{
4256 reset_callbacks_and_context();
4257
4258 // if no warning at all, it's a simple review
4259 if ((warning == NULL)
4260 || ((warning->predefinedSet == 0) && (warning->introDetails == NULL)
4261 && (warning->reviewDetails == NULL) && (warning->prelude == NULL))) {
4262 useCaseReviewStreamingStart(
4263 operationType, icon, reviewTitle, reviewSubTitle, choiceCallback, true);
4264 return;
4265 }
4266 if (warning->predefinedSet == (1 << W3C_NO_THREAT_WARN)) {
4267 operationType |= NO_THREAT_OPERATION;
4268 }
4269 else if (warning->predefinedSet != 0) {
4270 operationType |= RISKY_OPERATION;
4271 }
4272
4273 sharedContext.usage = SHARE_CTX_REVIEW_WITH_WARNING;
4274 reviewWithWarnCtx.isStreaming = true;
4275 reviewWithWarnCtx.operationType = operationType;
4276 reviewWithWarnCtx.icon = icon;
4277 reviewWithWarnCtx.reviewTitle = reviewTitle;
4278 reviewWithWarnCtx.reviewSubTitle = reviewSubTitle;
4279 reviewWithWarnCtx.choiceCallback = choiceCallback;
4280 reviewWithWarnCtx.warning = warning;
4281
4282 // if the warning contains a prelude, display it first
4283 if (reviewWithWarnCtx.warning->prelude) {
4284 displayPrelude();
4285 }
4286 // display the initial warning only of a risk/threat or blind signing
4287 else if (HAS_INITIAL_WARNING(warning)) {
4288 displayInitialWarning();
4289 }
4290 else {
4291 useCaseReviewStreamingStart(
4292 operationType, icon, reviewTitle, reviewSubTitle, choiceCallback, true);
4293 }
4294}
4295
4310 nbgl_choiceCallback_t choiceCallback,
4311 nbgl_callback_t skipCallback)
4312{
4313 // Should follow a call to nbgl_useCaseReviewStreamingStart
4314 memset(&genericContext, 0, sizeof(genericContext));
4315
4316 bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
4317 bundleNavContext.reviewStreaming.skipCallback = skipCallback;
4318
4319 // memorize context
4320 onChoice = bundleNavReviewStreamingChoice;
4321 navType = STREAMING_NAV;
4322 pageTitle = NULL;
4323
4324 genericContext.genericContents.contentsList = localContentsList;
4325 genericContext.genericContents.nbContents = 1;
4326 memset(localContentsList, 0, 1 * sizeof(nbgl_content_t));
4327
4328 // Then the tag/value pairs
4329 STARTING_CONTENT.type = TAG_VALUE_LIST;
4330 memcpy(
4331 &STARTING_CONTENT.content.tagValueList, tagValueList, sizeof(nbgl_contentTagValueList_t));
4332
4333 // compute number of pages & fill navigation structure
4334 bundleNavContext.reviewStreaming.stepPageNb = getNbPagesForGenericContents(
4335 &genericContext.genericContents,
4336 0,
4337 (bundleNavContext.reviewStreaming.operationType & SKIPPABLE_OPERATION));
4338 prepareNavInfo(true,
4340 getRejectReviewText(bundleNavContext.reviewStreaming.operationType));
4341 // if the operation is skippable
4342 if (bundleNavContext.reviewStreaming.operationType & SKIPPABLE_OPERATION) {
4343 navInfo.progressIndicator = false;
4344 navInfo.skipText = "Skip";
4345 navInfo.skipToken = SKIP_TOKEN;
4346 }
4347
4348 displayGenericContextPage(0, true);
4349}
4350
4362 nbgl_choiceCallback_t choiceCallback)
4363{
4364 nbgl_useCaseReviewStreamingContinueExt(tagValueList, choiceCallback, NULL);
4365}
4366
4375void nbgl_useCaseReviewStreamingFinish(const char *finishTitle,
4376 nbgl_choiceCallback_t choiceCallback)
4377{
4378 // Should follow a call to nbgl_useCaseReviewStreamingContinue
4379 memset(&genericContext, 0, sizeof(genericContext));
4380
4381 bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
4382
4383 // memorize context
4384 onChoice = bundleNavReviewStreamingChoice;
4385 navType = STREAMING_NAV;
4386 pageTitle = NULL;
4387
4388 genericContext.genericContents.contentsList = localContentsList;
4389 genericContext.genericContents.nbContents = 1;
4390 memset(localContentsList, 0, 1 * sizeof(nbgl_content_t));
4391
4392 // Eventually the long press page
4393 STARTING_CONTENT.type = INFO_LONG_PRESS;
4394 prepareReviewLastPage(bundleNavContext.reviewStreaming.operationType,
4395 &STARTING_CONTENT.content.infoLongPress,
4396 bundleNavContext.reviewStreaming.icon,
4397 finishTitle);
4398
4399 // compute number of pages & fill navigation structure
4400 bundleNavContext.reviewStreaming.stepPageNb = getNbPagesForGenericContents(
4401 &genericContext.genericContents,
4402 0,
4403 (bundleNavContext.reviewStreaming.operationType & SKIPPABLE_OPERATION));
4404 prepareNavInfo(true, 1, getRejectReviewText(bundleNavContext.reviewStreaming.operationType));
4405
4406 displayGenericContextPage(0, true);
4407}
4408
4413void nbgl_useCaseAddressConfirmationExt(const char *address,
4414 nbgl_choiceCallback_t callback,
4415 const nbgl_contentTagValueList_t *tagValueList)
4416{
4417 reset_callbacks_and_context();
4418 memset(&addressConfirmationContext, 0, sizeof(addressConfirmationContext));
4419
4420 // save context
4421 onChoice = callback;
4422 navType = GENERIC_NAV;
4423 pageTitle = NULL;
4424
4425 genericContext.genericContents.contentsList = localContentsList;
4426 genericContext.genericContents.nbContents = (tagValueList == NULL) ? 1 : 2;
4427 memset(localContentsList, 0, 2 * sizeof(nbgl_content_t));
4428 prepareAddressConfirmationPages(
4429 address, tagValueList, &STARTING_CONTENT, &localContentsList[1]);
4430
4431 // fill navigation structure, common to all pages
4432 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
4433
4434 prepareNavInfo(true, nbPages, "Cancel");
4435
4436#ifdef HAVE_PIEZO_SOUND
4437 // Play notification sound
4438 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
4439#endif // HAVE_PIEZO_SOUND
4440
4441 displayGenericContextPage(0, true);
4442}
4443
4460void nbgl_useCaseAddressReview(const char *address,
4461 const nbgl_contentTagValueList_t *additionalTagValueList,
4462 const nbgl_icon_details_t *icon,
4463 const char *reviewTitle,
4464 const char *reviewSubTitle,
4465 nbgl_choiceCallback_t choiceCallback)
4466{
4467 reset_callbacks_and_context();
4468
4469 // release a potential modal
4470 if (addressConfirmationContext.modalLayout) {
4471 nbgl_layoutRelease(addressConfirmationContext.modalLayout);
4472 }
4473 memset(&addressConfirmationContext, 0, sizeof(addressConfirmationContext));
4474
4475 // save context
4476 onChoice = choiceCallback;
4477 navType = GENERIC_NAV;
4478 pageTitle = NULL;
4479 bundleNavContext.review.operationType = TYPE_OPERATION;
4480
4481 genericContext.genericContents.contentsList = localContentsList;
4482 memset(localContentsList, 0, 3 * sizeof(nbgl_content_t));
4483
4484 // First a centered info
4485 STARTING_CONTENT.type = EXTENDED_CENTER;
4486 prepareReviewFirstPage(
4487 &STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
4488 STARTING_CONTENT.content.extendedCenter.contentCenter.subText = "Swipe to continue";
4489
4490 // Then the address confirmation pages
4491 prepareAddressConfirmationPages(
4492 address, additionalTagValueList, &localContentsList[1], &localContentsList[2]);
4493
4494 // fill navigation structure, common to all pages
4495 genericContext.genericContents.nbContents
4496 = (localContentsList[2].type == TAG_VALUE_CONFIRM) ? 3 : 2;
4497 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
4498
4499 prepareNavInfo(true, nbPages, "Cancel");
4500
4501#ifdef HAVE_PIEZO_SOUND
4502 // Play notification sound
4503 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
4504#endif // HAVE_PIEZO_SOUND
4505
4506 displayGenericContextPage(0, true);
4507}
4508
4517void nbgl_useCaseSpinner(const char *text)
4518{
4519 // if the previous Use Case was not Spinner, fresh start
4520 if (genericContext.type != USE_CASE_SPINNER) {
4521 memset(&genericContext, 0, sizeof(genericContext));
4522 genericContext.type = USE_CASE_SPINNER;
4523 nbgl_layoutDescription_t layoutDescription = {0};
4524
4525 layoutDescription.withLeftBorder = true;
4526
4527 genericContext.backgroundLayout = nbgl_layoutGet(&layoutDescription);
4528
4530 genericContext.backgroundLayout, text, NULL, genericContext.spinnerPosition);
4531
4532 nbgl_layoutDraw(genericContext.backgroundLayout);
4534 }
4535 else {
4536 // otherwise increment spinner
4537 genericContext.spinnerPosition++;
4538 // there are only NB_SPINNER_POSITIONSpositions
4539 if (genericContext.spinnerPosition == NB_SPINNER_POSITIONS) {
4540 genericContext.spinnerPosition = 0;
4541 }
4542 int ret = nbgl_layoutUpdateSpinner(
4543 genericContext.backgroundLayout, text, NULL, genericContext.spinnerPosition);
4544 if (ret == 1) {
4546 }
4547 else if (ret == 2) {
4549 }
4550 }
4551}
4552
4553#ifdef NBGL_KEYPAD
4572void nbgl_useCaseKeypad(const char *title,
4573 uint8_t minDigits,
4574 uint8_t maxDigits,
4575 bool shuffled,
4576 bool hidden,
4577 nbgl_pinValidCallback_t validatePinCallback,
4578 nbgl_callback_t backCallback)
4579{
4580 nbgl_layoutDescription_t layoutDescription = {0};
4582 .separationLine = true,
4583 .backAndText.token = BACK_TOKEN,
4584 .backAndText.tuneId = TUNE_TAP_CASUAL,
4585 .backAndText.text = NULL};
4586 int status = -1;
4587
4588 if ((minDigits > KEYPAD_MAX_DIGITS) || (maxDigits > KEYPAD_MAX_DIGITS)) {
4589 return;
4590 }
4591
4592 reset_callbacks_and_context();
4593 // reset the keypad context
4594 memset(&keypadContext, 0, sizeof(KeypadContext_t));
4595
4596 // memorize context
4597 onQuit = backCallback;
4598
4599 // get a layout
4600 layoutDescription.onActionCallback = keypadGeneric_cb;
4601 layoutDescription.modal = false;
4602 layoutDescription.withLeftBorder = false;
4603 keypadContext.layoutCtx = nbgl_layoutGet(&layoutDescription);
4604 keypadContext.hidden = hidden;
4605
4606 // set back key in header
4607 nbgl_layoutAddHeader(keypadContext.layoutCtx, &headerDesc);
4608
4609 // add keypad
4610 status = nbgl_layoutAddKeypad(keypadContext.layoutCtx, keypadCallback, shuffled);
4611 if (status < 0) {
4612 return;
4613 }
4614 // add keypad content
4616 keypadContext.layoutCtx, title, keypadContext.hidden, maxDigits, "");
4617
4618 if (status < 0) {
4619 return;
4620 }
4621
4622 // validation pin callback
4623 onValidatePin = validatePinCallback;
4624 // pin code acceptable lengths
4625 keypadContext.pinMinDigits = minDigits;
4626 keypadContext.pinMaxDigits = maxDigits;
4627
4628 nbgl_layoutDraw(keypadContext.layoutCtx);
4630}
4631#endif // NBGL_KEYPAD
4632
4633#endif // HAVE_SE_TOUCH
4634#endif // NBGL_USE_CASE
nbgl_contentTagValue_t *(* nbgl_contentTagValueCallback_t)(uint8_t pairIndex)
prototype of tag/value pair retrieval callback
@ ICON_ILLUSTRATION
simple icon
@ LARGE_CASE_GRAY_INFO
@ LARGE_CASE_INFO
text in BLACK and large case (INTER 32px), subText in black in Inter24px
@ 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
bool nbgl_getTextMaxLenInNbLines(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, uint16_t maxNbLines, uint16_t *len, bool wrapping)
compute the len of the given text (in bytes) fitting in the given maximum nb lines,...
Definition nbgl_fonts.c:552
nbgl_font_id_e
Definition nbgl_fonts.h:132
void nbgl_textReduceOnNbLines(nbgl_font_id_e fontId, const char *origText, uint16_t maxWidth, uint8_t nbLines, char *reducedText, uint16_t reducedTextLen)
Create a reduced version of given ASCII text to wrap it on the given max width (in pixels),...
uint16_t nbgl_getTextHeightInWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, bool wrapping)
return the height of the given multiline text, with the given font.
uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, bool wrapping)
compute the number of lines of the given text fitting in the given maxWidth
Definition nbgl_fonts.c:704
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)
Creates an area on the center of the main panel, with a possible icon, and possible texts under it.
int nbgl_layoutAddTextContent(nbgl_layout_t *layout, const char *title, const char *description, const char *info)
Creates in the main container three text areas:
int nbgl_layoutUpdateKeypad(nbgl_layout_t *layout, uint8_t index, bool enableValidate, bool enableBackspace, bool enableDigits)
Updates an existing keypad on bottom of the screen, with the given configuration.
int nbgl_layoutAddSeparationLine(nbgl_layout_t *layout)
adds a separation line on bottom of the last added item
int nbgl_layoutAddQRCode(nbgl_layout_t *layout, const nbgl_layoutQRCode_t *info)
Creates an area on the center of the main panel, with a QRCode, a possible text in black (bold) under...
int nbgl_layoutDraw(nbgl_layout_t *layout)
Applies given layout. The screen will be redrawn.
int nbgl_layoutAddTouchableBar(nbgl_layout_t *layout, const nbgl_layoutBar_t *barLayout)
Creates a touchable bar in main panel.
@ WHITE_BACKGROUND
rounded bordered button, with text/icon in black, on white background
@ BLACK_BACKGROUND
rounded bordered button, with text/icon in white, on black background
int nbgl_layoutAddTopRightButton(nbgl_layout_t *layout, const nbgl_icon_details_t *icon, uint8_t token, tune_index_e tuneId)
Creates a Top-right button in the top right corner of the top panel.
#define AVAILABLE_WIDTH
void * nbgl_layout_t
type shared externally
@ HEADER_EMPTY
empty space, to have a better vertical centering of centered info
@ HEADER_BACK_AND_TEXT
back key and optional text
int nbgl_layoutAddKeypadContent(nbgl_layout_t *layout, const char *title, bool hidden, uint8_t nbDigits, const char *text)
Adds an area with a title and a placeholder for hidden digits on top of a keypad, to represent the en...
#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
int nbgl_layoutAddExtendedFooter(nbgl_layout_t *layout, const nbgl_layoutFooter_t *footerDesc)
Creates a touchable area at the footer of the screen, containing various controls,...
@ ROUNDED_AND_FOOTER_STYLE
A black background button on top of a footer.
int nbgl_layoutAddChoiceButtons(nbgl_layout_t *layout, const nbgl_layoutChoiceButtons_t *info)
Creates two buttons to make a choice. Both buttons are mandatory. Both buttons are full width,...
int nbgl_layoutAddSpinner(nbgl_layout_t *layout, const char *text, const char *subText, uint8_t initPosition)
Creates a centered (vertically & horizontally) spinner with a text under it.
int nbgl_layoutUpdateSpinner(nbgl_layout_t *layout, const char *text, const char *subText, uint8_t position)
Update an existing spinner (must be the only object of the layout)
#define NBGL_NO_PROGRESS_INDICATOR
To be used when a control token shall not be used.
Definition nbgl_layout.h:27
int nbgl_layoutAddHeader(nbgl_layout_t *layout, const nbgl_layoutHeader_t *headerDesc)
Creates a touchable (or not) area at the header of the screen, containing various controls,...
@ FOOTER_EMPTY
empty space, to have a better vertical centering of centered info
int nbgl_layoutRelease(nbgl_layout_t *layout)
Release the layout obtained with nbgl_layoutGet()
#define EXIT_PAGE
Definition nbgl_layout.h:35
int nbgl_layoutAddFooter(nbgl_layout_t *layout, const char *text, uint8_t token, tune_index_e tuneId)
Creates a touchable text at the footer of the screen, separated with a thin line from the rest of the...
int nbgl_layoutAddKeypad(nbgl_layout_t *layout, keyboardCallback_t callback, bool shuffled)
Adds a keypad on bottom of the screen, with the associated callback.
#define NB_SPINNER_POSITIONS
Definition nbgl_obj.h:264
void nbgl_refresh(void)
This functions refreshes the actual screen on display with what has changed since the last refresh.
Definition nbgl_obj.c:1725
#define KEYPAD_MAX_DIGITS
Definition nbgl_obj.h:67
void nbgl_refreshSpecial(nbgl_refresh_mode_t mode)
This functions refreshes the actual screen on display with what has changed since the last refresh,...
Definition nbgl_obj.c:1735
#define BACKSPACE_KEY
Definition nbgl_obj.h:26
void nbgl_refreshSpecialWithPostRefresh(nbgl_refresh_mode_t mode, nbgl_post_refresh_t post_refresh)
Definition nbgl_obj.c:1751
#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)
draw a generic content page, with the given content, and if nav parameter is not NULL,...
Definition nbgl_page.c:612
nbgl_page_t * nbgl_pageDrawInfo(nbgl_layoutTouchCallback_t onActionCallback, const nbgl_screenTickerConfiguration_t *ticker, const nbgl_pageInfoDescription_t *info)
draw a page with a centered info (icon and/or texts) with a touchable footer, in a potential "tapable...
Definition nbgl_page.c:324
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)
draw a confirmation page, with a centered info (icon and/or text), a button to confirm and a footer t...
Definition nbgl_page.c:442
int nbgl_pageRelease(nbgl_page_t *)
Release the page obtained with any of the nbgl_pageDrawXXX() functions.
Definition nbgl_page.c:625
nbgl_page_t * nbgl_pageDrawGenericContentExt(nbgl_layoutTouchCallback_t onActionCallback, const nbgl_pageNavigationInfo_t *nav, nbgl_pageContent_t *content, bool modal)
draw a generic content page, with the given content, and if nav parameter is not NULL,...
Definition nbgl_page.c:483
@ 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)
This function redraws the whole screen on top of stack and its children.
Definition nbgl_screen.c:66
@ POST_REFRESH_FORCE_POWER_ON
Force screen power on after refresh.
Definition nbgl_types.h:354
#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:326
@ FULL_COLOR_CLEAN_REFRESH
to be used for lock screen display (cleaner but longer refresh)
Definition nbgl_types.h:329
@ BLACK_AND_WHITE_FAST_REFRESH
to be used for pure B&W area, when contrast is not priority
Definition nbgl_types.h:331
@ FULL_COLOR_PARTIAL_REFRESH
to be used for small partial refresh (radio buttons, switches)
Definition nbgl_types.h:328
@ FULL_COLOR_REFRESH
to be used for normal refresh
Definition nbgl_types.h:327
API of the Advanced BOLOS Graphical Library, for typical application use-cases.
DEPRECATED void nbgl_useCaseHome(const char *appName, const nbgl_icon_details_t *appIcon, const char *tagline, bool withSettings, nbgl_callback_t topRightCallback, nbgl_callback_t quitCallback)
#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
DEPRECATED void nbgl_useCaseSettings(const char *settingsTitle, uint8_t initPage, uint8_t nbPages, bool touchableTitle, nbgl_callback_t quitCallback, nbgl_navCallback_t navCallback, nbgl_layoutTouchCallback_t controlsCallback)
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)
DEPRECATED void nbgl_useCaseRegularReview(uint8_t initPage, uint8_t nbPages, const char *rejectText, nbgl_layoutTouchCallback_t buttonCallback, nbgl_navCallback_t navCallback, nbgl_choiceCallback_t choiceCallback)
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)
void nbgl_useCaseStaticReviewLight(const nbgl_contentTagValueList_t *tagValueList, const nbgl_pageInfoLongPress_t *infoLongPress, const char *rejectText, nbgl_choiceCallback_t callback)
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)
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_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
void nbgl_useCaseReviewStart(const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, const char *rejectText, nbgl_callback_t continueCallback, nbgl_callback_t rejectCallback)
DEPRECATED void nbgl_useCaseHomeExt(const char *appName, const nbgl_icon_details_t *appIcon, const char *tagline, bool withSettings, const char *actionButtonText, nbgl_callback_t actionCallback, nbgl_callback_t topRightCallback, nbgl_callback_t quitCallback)
#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
DEPRECATED void nbgl_useCaseAddressConfirmationExt(const char *address, nbgl_choiceCallback_t callback, const nbgl_contentTagValueList_t *tagValueList)
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 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
#define TAGLINE_PART2
void nbgl_useCaseStaticReview(const nbgl_contentTagValueList_t *tagValueList, const nbgl_pageInfoLongPress_t *infoLongPress, const char *rejectText, nbgl_choiceCallback_t callback)
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)
#define REAL_TYPE_MASK
This is the mask to apply on nbgl_operationType_t to get the real type provided by app.
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,...
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
int16_t offsetY
vertical shift to apply to this info (if >0, shift to bottom)
const char * text3
third text (can be null)
const nbgl_icon_details_t * icon
a buffer containing the 1BPP icon
nbgl_contentCenter_t contentCenter
centered content (icon + text(s))
This structure contains data to build a centered info + simple black button content.
const char * buttonText
text of the long press button
const nbgl_icon_details_t * icon
a buffer containing the 1BPP icon
const char * text
centered text in large case
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played when button is touched
This structure contains data to build a INFOS_LIST content.
const char *const * infoContents
array of contents of infos (in black)
const char *const * infoTypes
array of types of infos (in black/bold)
const nbgl_contentValueExt_t * infoExtensions
uint8_t nbInfos
number of elements in infoTypes and infoContents array
This structure contains data to build a centered info + long press button content.
const char * longPressText
text of the long press button
const nbgl_icon_details_t * icon
a buffer containing the 1BPP icon
const char * text
centered text in large case
This structure contains a list of names to build a list of radio buttons (on the right part of screen...
uint8_t initChoice
index of the current choice
const char *const * names
array of strings giving the choices (nbChoices)
uint8_t nbChoices
number of choices
This structure contains info to build a switch (on the right) with a description (on the left),...
const char * text
main text for the switch
const char * subText
description under main text (NULL terminated, single line, may be null)
This structure contains [item,value] pair(s) and info about a potential "details" button,...
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played when details button is touched
const char * confirmationText
text of the confirmation button, if NULL "It matches" is used
uint8_t confirmationToken
the token used as argument of the onActionCallback
nbgl_contentTagValueList_t tagValueList
list of tag/value pairs
const char * detailsButtonText
this text is used for "details" button (if NULL, no button)
const nbgl_icon_details_t * detailsButtonIcon
icon to use in details button
const nbgl_icon_details_t * detailsButtonIcon
icon to use in details button
const char * detailsButtonText
this text is used for "details" button
nbgl_contentTagValueList_t tagValueList
list of tag/value pairs
This structure contains a list of [tag,value] pairs.
const nbgl_contentTagValue_t * pairs
array of [tag,value] pairs (nbPairs items). If NULL, callback is used instead
nbgl_contentTagValueCallback_t callback
function to call to retrieve a given pair
uint8_t nbMaxLinesForValue
if > 0, set the max number of lines for value field.
bool hideEndOfLastLine
if set to true, replace 3 last chars of last line by "..."
bool wrapping
if set to true, value text will be wrapped on ' ' to avoid cutting words
uint8_t startIndex
index of the first pair to get with callback
nbgl_contentActionCallback_t actionCallback
called when a valueIcon is touched on a given pair
This structure contains a [tag,value] pair and possible extensions.
const nbgl_contentValueExt_t * extension
if not NULL, gives additional info on value field
const nbgl_icon_details_t * valueIcon
int8_t centeredInfo
if set to 1, the tag will be displayed as a centered info
const char * value
string giving the value name
const char * item
string giving the tag name
This structure contains additions to a tag/value pair, to be able to build a screen to display these ...
const char * fullValue
full string of the value when used as an alias
nbgl_contentValueAliasType_t aliasType
type of alias
const struct nbgl_contentTagValueList_s * tagValuelist
if aliasType is TAG_VALUE_LIST_ALIAS
const char * backText
used as title of the popping page, if not NULL, otherwise "item" is used
const 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_layoutQRCode_t qrCode
QR code, if type == QRCODE_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
This structure contains info to build a clickable "bar" with a text and an icon.
bool inactive
if set to true, the bar is grayed-out and cannot be touched
const char * text
text (can be NULL)
uint8_t token
the token that will be used as argument of the callback
bool large
set to true only for the main level of OS settings
const char * subText
sub text (can be NULL)
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played
const nbgl_icon_details_t * iconLeft
a buffer containing the 1BPP icon for icon on left (can be NULL)
const nbgl_icon_details_t * iconRight
This structure contains info to build a pair of buttons, one on top of the other.
const char * bottomText
bottom-button text (index 1)
Structure containing all information when creating a layout. This structure must be passed as argumen...
nbgl_screenTickerConfiguration_t ticker
const char * tapActionText
Light gray text used when main container is "tapable".
nbgl_layoutTouchCallback_t onActionCallback
the callback to be called on any action on the layout
This structure contains info to build an extended footer.
struct nbgl_layoutFooter_t::@19::@21 emptySpace
if type is FOOTER_EMPTY
nbgl_layoutFooterType_t type
type of footer
This structure contains info to build a header.
nbgl_layoutHeaderType_t type
type of header
bool separationLine
if true, a separation line is added at the bottom of this control
const char * text
can be NULL if no text
struct nbgl_layoutHeader_t::@11::@14 backAndText
if type is HEADER_BACK_ICON_AND_TEXT or HEADER_BACK_AND_TEXT
This structure contains info to build a centered (vertically and horizontally) area,...
const char * text2
second text (can be null)
const char * url
URL for QR code.
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:66
nbgl_contentSwitchesList_t switchesList
SWITCHES_LIST type
Definition nbgl_flow.h:64
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:67
nbgl_contentInfoButton_t infoButton
INFO_BUTTON type
Definition nbgl_flow.h:62
nbgl_contentInfoList_t infosList
INFOS_LIST type
Definition nbgl_flow.h:65
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_page.h:69
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