Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
nbgl_use_case.c
Go to the documentation of this file.
1
5
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"
16#include "glyphs.h"
17#include "os_io_seph_ux.h"
18#include "os_pic.h"
19#include "os_print.h"
20#include "os_helpers.h"
21
22/*********************
23 * DEFINES
24 *********************/
25
26/* Defines for definition and usage of genericContextPagesInfo */
27#define PAGE_NB_ELEMENTS_BITS 3
28#define GET_PAGE_NB_ELEMENTS(pageData) ((pageData) &0x07)
29#define SET_PAGE_NB_ELEMENTS(nbElements) ((nbElements) &0x07)
30
31#define PAGE_FLAG_BITS 1
32#define GET_PAGE_FLAG(pageData) (((pageData) &0x08) >> 3)
33#define SET_PAGE_FLAG(flag) (((flag) &0x01) << 3)
34
35#define PAGE_DATA_BITS (PAGE_NB_ELEMENTS_BITS + PAGE_FLAG_BITS)
36#define PAGES_PER_UINT8 (8 / PAGE_DATA_BITS)
37#define SET_PAGE_DATA(pageIdx, pageData) \
38 (pagesData[pageIdx / PAGES_PER_UINT8] = pageData \
39 << ((pageIdx % PAGES_PER_UINT8) * PAGE_DATA_BITS))
40
41#define MAX_PAGE_NB 256
42
43/* Alias to clarify usage of genericContext hasStartingContent and hasFinishingContent feature */
44#define STARTING_CONTENT localContentsList[0]
45#define FINISHING_CONTENT localContentsList[1]
46
47/* max number of lines for address under QR Code */
48#define QRCODE_NB_MAX_LINES 3
49/* max number of char for reduced QR Code address */
50#define QRCODE_REDUCED_ADDR_LEN 128
51
52/* maximum number of pairs in a page of address confirm */
53#define ADDR_VERIF_NB_PAIRS 3
54
55// macros to ease access to shared contexts
56#define sharedContext genericContext.sharedCtx
57#define keypadContext sharedContext.keypad
58#define keyboardContext sharedContext.keyboard
59#define reviewWithWarnCtx sharedContext.reviewWithWarning
60#define choiceWithDetailsCtx sharedContext.choiceWithDetails
61
62/* max length of the string displaying the description of the Web3 Checks report */
63#define W3C_DESCRIPTION_MAX_LEN 128
64
65/**********************
66 * TYPEDEFS
67 **********************/
68enum {
69 BACK_TOKEN = 0,
70 NEXT_TOKEN,
71 QUIT_TOKEN,
72 NAV_TOKEN,
73 MODAL_NAV_TOKEN,
74 SKIP_TOKEN,
75 CONTINUE_TOKEN,
76 ADDRESS_QRCODE_BUTTON_TOKEN,
77 ACTION_BUTTON_TOKEN,
78 CHOICE_TOKEN,
79 DETAILS_BUTTON_TOKEN,
80 CONFIRM_TOKEN,
81 REJECT_TOKEN,
82 VALUE_ALIAS_TOKEN,
83 INFO_ALIAS_TOKEN,
84 INFOS_TIP_BOX_TOKEN,
85 BLIND_WARNING_TOKEN,
86 WARNING_BUTTON_TOKEN,
87 CHOICE_DETAILS_TOKEN,
88 TIP_BOX_TOKEN,
89 QUIT_TIPBOX_MODAL_TOKEN,
90 WARNING_CHOICE_TOKEN,
91 DISMISS_QR_TOKEN,
92 DISMISS_WARNING_TOKEN,
93 DISMISS_DETAILS_TOKEN,
94 PRELUDE_CHOICE_TOKEN,
95 KEYBOARD_BUTTON_TOKEN,
96 KEYBOARD_CROSS_TOKEN,
97 FIRST_WARN_BAR_TOKEN,
98 LAST_WARN_BAR_TOKEN = (FIRST_WARN_BAR_TOKEN + NB_WARNING_TYPES - 1),
99};
100CCASSERT(NBGL_TOKENS, LAST_WARN_BAR_TOKEN + 1 < FIRST_USER_TOKEN);
101
102typedef enum {
103 REVIEW_NAV = 0,
104 SETTINGS_NAV,
105 GENERIC_NAV,
106 STREAMING_NAV
107} NavType_t;
108
109typedef struct DetailsContext_s {
110 uint8_t nbPages;
111 uint8_t currentPage;
112 bool wrapping;
113 const char *tag;
114 const char *value;
115 const char *nextPageStart;
116} DetailsContext_t;
117
118typedef struct AddressConfirmationContext_s {
119 nbgl_layoutTagValue_t tagValuePairs[ADDR_VERIF_NB_PAIRS];
120 nbgl_layout_t *modalLayout;
121 uint8_t nbPairs;
122} AddressConfirmationContext_t;
123
124#ifdef NBGL_KEYPAD
125typedef struct KeypadContext_s {
126 uint8_t pinEntry[KEYPAD_MAX_DIGITS + 1]; // +1 for the NUL terminator
127 uint8_t pinLen;
128 uint8_t pinMinDigits;
129 uint8_t pinMaxDigits;
130 nbgl_layout_t *layoutCtx;
131 bool hidden;
132 nbgl_pinValidCallback_t onValidatePin;
133} KeypadContext_t;
134#endif
135
136#ifdef NBGL_KEYBOARD
137typedef struct KeyboardContext_s {
138 nbgl_layoutKeyboardContent_t keyboardContent;
139 char *entryBuffer;
140 uint8_t entryMaxLen;
141 int keyboardIndex;
142 keyboardCase_t casing;
143 nbgl_layout_t *layoutCtx;
144 nbgl_keyboardButtonsCallback_t getSuggestionButtons;
145} KeyboardContext_t;
146#endif
147
148typedef struct ReviewWithWarningContext_s {
149 bool isStreaming;
150 nbgl_operationType_t operationType;
151 const nbgl_contentTagValueList_t *tagValueList;
152 const nbgl_icon_details_t *icon;
153 const char *reviewTitle;
154 const char *reviewSubTitle;
155 const char *finishTitle;
156 const nbgl_warning_t *warning;
157 nbgl_choiceCallback_t choiceCallback;
158 nbgl_layout_t *layoutCtx;
159 nbgl_layout_t *modalLayout;
160 uint8_t securityReportLevel; // level 1 is the first level of menus
161 bool isIntro; // set to true during intro (before actual review)
162} ReviewWithWarningContext_t;
163
164typedef struct ChoiceWithDetailsContext_s {
165 const nbgl_genericDetails_t *details;
166 nbgl_layout_t *layoutCtx;
167 nbgl_layout_t *modalLayout;
168 uint8_t level; // level 1 is the first level of menus
169} ChoiceWithDetailsContext_t;
170
171typedef enum {
172 SHARE_CTX_KEYPAD,
173 SHARE_CTX_REVIEW_WITH_WARNING,
174 SHARE_CTX_CHOICE_WITH_DETAILS,
175} SharedContextUsage_t;
176
177// this union is intended to save RAM for context storage
178// indeed, these 3 contexts cannot happen simultaneously
179typedef struct {
180 union {
181#ifdef NBGL_KEYPAD
182 KeypadContext_t keypad;
183#endif
184#ifdef NBGL_KEYBOARD
185 KeyboardContext_t keyboard;
186#endif
187 ReviewWithWarningContext_t reviewWithWarning;
188 ChoiceWithDetailsContext_t choiceWithDetails;
189 };
190 SharedContextUsage_t usage;
191} SharedContext_t;
192
193typedef enum {
194 USE_CASE_GENERIC = 0,
195 USE_CASE_SPINNER,
196 USE_CASE_IDLE // Home page (or empty page with NBGL_NO_HOME): Info & Settings can be shown
197} GenericContextType_t;
198
199typedef struct {
200 GenericContextType_t type; // type of Generic context usage
201 uint8_t spinnerPosition;
202 nbgl_genericContents_t genericContents;
203 int8_t currentContentIdx;
204 uint8_t currentContentElementNb;
205 uint8_t currentElementIdx;
206 bool hasStartingContent;
207 bool hasFinishingContent;
208 const char *detailsItem;
209 const char *detailsvalue;
210 bool detailsWrapping;
211 bool validWarningCtx; // set to true if the WarningContext is valid
213 *currentPairs; // to be used to retrieve the pairs with value alias
215 currentCallback; // to be used to retrieve the pairs with value alias
216 uint8_t currentNbPairs; // total number of pairs in currentPairs (or currentCallback)
217 uint8_t currentStartIndex; // index of the first pair to get with currentCallback
218 nbgl_layout_t modalLayout;
219 nbgl_layout_t backgroundLayout;
220 const nbgl_contentInfoList_t *currentInfos;
221 const nbgl_contentTagValueList_t *currentTagValues;
222 // unsliced infos list of the current generic page, to retrieve the extension of a touched
223 // info (copied, because the content may come from a temporary buffer)
224 nbgl_contentInfoList_t currentPageInfos;
225 nbgl_tipBox_t tipBox;
226 SharedContext_t sharedCtx; // multi-purpose context shared for non-concurrent usages
227} GenericContext_t;
228
229typedef struct {
230 const char *appName;
231 const nbgl_icon_details_t *appIcon;
232 const char *tagline;
233 const nbgl_genericContents_t *settingContents;
234 const nbgl_contentInfoList_t *infosList;
235 nbgl_homeAction_t homeAction;
236 nbgl_callback_t quitCallback;
237} nbgl_homeAndSettingsContext_t;
238
239typedef struct {
240 nbgl_operationType_t operationType;
241 nbgl_choiceCallback_t choiceCallback;
242} nbgl_reviewContext_t;
243
244typedef struct {
245 nbgl_operationType_t operationType;
246 nbgl_choiceCallback_t choiceCallback;
247 nbgl_callback_t skipCallback;
248 const nbgl_icon_details_t *icon;
249 uint8_t stepPageNb;
250} nbgl_reviewStreamingContext_t;
251
252typedef union {
253 nbgl_homeAndSettingsContext_t homeAndSettings;
254 nbgl_reviewContext_t review;
255 nbgl_reviewStreamingContext_t reviewStreaming;
256} nbgl_BundleNavContext_t;
257
258typedef struct {
259 const nbgl_icon_details_t *icon;
260 const char *text;
261 const char *subText;
262} SecurityReportItem_t;
263
264/**********************
265 * STATIC VARIABLES
266 **********************/
267
268// char buffers to build some strings
269static char tmpString[W3C_DESCRIPTION_MAX_LEN];
270
271// multi-purposes callbacks
272static nbgl_callback_t onQuit;
273static nbgl_callback_t onContinue;
274static nbgl_callback_t onAction;
275static nbgl_navCallback_t onNav;
276static nbgl_layoutTouchCallback_t onControls;
277static nbgl_contentActionCallback_t onContentAction;
278static nbgl_choiceCallback_t onChoice;
279static nbgl_callback_t onModalConfirm;
280
281// contexts for background and modal pages
282static nbgl_page_t *pageContext;
283static nbgl_page_t *modalPageContext;
284
285// context for pages
286static const char *pageTitle;
287
288// context for tip-box
289#define activeTipBox genericContext.tipBox
290
291// context for navigation use case
292static nbgl_pageNavigationInfo_t navInfo;
293static NavType_t navType;
294
295static DetailsContext_t detailsContext;
296
297// context for address review
298static AddressConfirmationContext_t addressConfirmationContext;
299
300// contexts for generic navigation
301static GenericContext_t genericContext;
302static nbgl_content_t
303 localContentsList[3]; // 3 needed for nbgl_useCaseReview (starting page / tags / final page)
304static uint8_t genericContextPagesInfo[MAX_PAGE_NB / PAGES_PER_UINT8];
305
306// contexts for bundle navigation
307static nbgl_BundleNavContext_t bundleNavContext;
308
309// indexed by nbgl_contentType_t
310static const uint8_t nbMaxElementsPerContentType[] = {
311 1, // CENTERED_INFO
312 1, // EXTENDED_CENTER
313 1, // INFO_LONG_PRESS
314 1, // INFO_BUTTON
315 1, // TAG_VALUE_LIST (computed dynamically)
316 1, // TAG_VALUE_DETAILS
317 1, // TAG_VALUE_CONFIRM
318 3, // SWITCHES_LIST (computed dynamically)
319 3, // INFOS_LIST (computed dynamically)
320 5, // CHOICES_LIST (computed dynamically)
321 5, // BARS_LIST (computed dynamically)
322};
323
324// clang-format off
325static const SecurityReportItem_t securityReportItems[NB_WARNING_TYPES] = {
327 .icon = &WARNING_ICON,
328 .text = "Blind signing required",
329 .subText = "This transaction's details are not fully verifiable. If "
330 "you sign, you could lose all your assets."
331 },
332 [W3C_ISSUE_WARN] = {
333 .icon = &WARNING_ICON,
334 .text = "Transaction Check unavailable",
335 .subText = NULL
336 },
338 .icon = &WARNING_ICON,
339 .text = "Risk detected",
340 .subText = "This transaction was scanned as risky by Web3 Checks."
341 },
343 .icon = &WARNING_ICON,
344 .text = "Critical threat",
345 .subText = "This transaction was scanned as malicious by Web3 Checks."
346 },
348 .icon = NULL,
349 .text = "No threat detected",
350 .subText = "Transaction Check didn't find any threat, but always "
351 "review transaction details carefully."
352 }
353};
354// clang-format on
355
356// configuration of warning when using @ref nbgl_useCaseReviewBlindSigning()
357static const nbgl_warning_t blindSigningWarning = {.predefinedSet = (1 << BLIND_SIGNING_WARN)};
358
359// local copy of a caller's warning, used when it has to be normalized (see normalizeWarning())
360static nbgl_warning_t normalizedWarning;
361
362#ifdef NBGL_QRCODE
363/* buffer to store reduced address under QR Code */
364static char reducedAddress[QRCODE_REDUCED_ADDR_LEN];
365#endif // NBGL_QRCODE
366
367/**********************
368 * STATIC FUNCTIONS
369 **********************/
370static void displayReviewPage(uint8_t page, bool forceFullRefresh);
371static void displayDetailsPage(uint8_t page, bool forceFullRefresh);
372static void displayTagValueListModalPage(uint8_t pageIdx, bool forceFullRefresh);
373static void displayFullValuePage(const char *backText,
374 const char *aliasText,
375 const nbgl_contentValueExt_t *extension);
376static void displayInfosListModal(const char *modalTitle,
377 const nbgl_contentInfoList_t *infos,
378 bool fromReview);
379static void displayTagValueListModal(const nbgl_contentTagValueList_t *tagValues);
380static void displaySettingsPage(uint8_t page, bool forceFullRefresh);
381static void displayGenericContextPage(uint8_t pageIdx, bool forceFullRefresh);
382static void pageCallback(int token, uint8_t index);
383
384static uint8_t getNbInfosInPage(uint8_t nbInfos,
385 const nbgl_contentInfoList_t *infosList,
386 uint8_t startIndex,
387 bool withNav);
388static uint8_t getNbSwitchesInPage(uint8_t nbSwitches,
389 const nbgl_contentSwitchesList_t *switchesList,
390 uint8_t startIndex,
391 bool withNav);
392static uint8_t getNbBarsInPage(uint8_t nbBars,
393 const nbgl_contentBarsList_t *barsList,
394 uint8_t startIndex,
395 bool withNav);
396#ifdef NBGL_QRCODE
397static void displayAddressQRCode(void);
398#endif // NBGL_QRCODE
399
400static uint8_t getNbLinesInDetailsPage(const nbgl_contentTagValue_t *pair);
401static uint8_t getNbTagValuesInDetailsPage(uint8_t nbPairs,
402 const nbgl_contentTagValueList_t *tagValueList,
403 uint8_t startIndex);
404
405static void modalLayoutTouchCallback(int token, uint8_t index);
406static void displaySkipWarning(void);
407
408#ifdef NBGL_NO_HOME
409static void bundleNavStartIdle(void);
410#else // NBGL_NO_HOME
411static void bundleNavStartHome(void);
412static void bundleNavStartSettings(void);
413#endif // NBGL_NO_HOME
414static void bundleNavStartSettingsAtPage(uint8_t initSettingPage);
415
416static void bundleNavReviewStreamingChoice(bool confirm);
417static nbgl_layout_t *displayModalDetails(const nbgl_warningDetails_t *details, uint8_t token);
418static void displaySecurityReport(uint32_t set);
419static void displayCustomizedSecurityReport(const nbgl_warningDetails_t *details);
420static void displayInitialWarning(void);
421static void useCaseReview(nbgl_operationType_t operationType,
422 const nbgl_contentTagValueList_t *tagValueList,
423 const nbgl_icon_details_t *icon,
424 const char *reviewTitle,
425 const char *reviewSubTitle,
426 const char *finishTitle,
427 const nbgl_tipBox_t *tipBox,
428 nbgl_choiceCallback_t choiceCallback,
429 bool isLight,
430 bool playNotifSound);
431static void useCaseReviewStreamingStart(nbgl_operationType_t operationType,
432 const nbgl_icon_details_t *icon,
433 const char *reviewTitle,
434 const char *reviewSubTitle,
435 nbgl_choiceCallback_t choiceCallback,
436 bool playNotifSound);
437static void useCaseHomeExt(const char *appName,
438 const nbgl_icon_details_t *appIcon,
439 const char *tagline,
440 bool withSettings,
441 nbgl_homeAction_t *homeAction,
442 nbgl_callback_t topRightCallback,
443 nbgl_callback_t quitCallback);
444static void displayDetails(const char *tag, const char *value, bool wrapping);
445
446static void reset_callbacks_and_context(void)
447{
448 onQuit = NULL;
449 onContinue = NULL;
450 onAction = NULL;
451 onNav = NULL;
452 onControls = NULL;
453 onContentAction = NULL;
454 onChoice = NULL;
455 memset(&genericContext, 0, sizeof(genericContext));
456}
457
458// Helper to set genericContext page info
459static void genericContextSetPageInfo(uint8_t pageIdx, uint8_t nbElements, bool flag)
460{
461 uint8_t pageData = SET_PAGE_NB_ELEMENTS(nbElements) + SET_PAGE_FLAG(flag);
462
463 genericContextPagesInfo[pageIdx / PAGES_PER_UINT8]
464 &= ~(0x0F << ((pageIdx % PAGES_PER_UINT8) * PAGE_DATA_BITS));
465 genericContextPagesInfo[pageIdx / PAGES_PER_UINT8]
466 |= pageData << ((pageIdx % PAGES_PER_UINT8) * PAGE_DATA_BITS);
467}
468
469// Helper to get genericContext page info
470static void genericContextGetPageInfo(uint8_t pageIdx, uint8_t *nbElements, bool *flag)
471{
472 uint8_t pageData = genericContextPagesInfo[pageIdx / PAGES_PER_UINT8]
473 >> ((pageIdx % PAGES_PER_UINT8) * PAGE_DATA_BITS);
474 if (nbElements != NULL) {
475 *nbElements = GET_PAGE_NB_ELEMENTS(pageData);
476 }
477 if (flag != NULL) {
478 *flag = GET_PAGE_FLAG(pageData);
479 }
480}
481
482// Simple helper to get the number of elements inside a nbgl_content_t
483static uint8_t getContentNbElement(const nbgl_content_t *content)
484{
485 switch (content->type) {
486 case TAG_VALUE_LIST:
487 return content->content.tagValueList.nbPairs;
490 case SWITCHES_LIST:
491 return content->content.switchesList.nbSwitches;
492 case INFOS_LIST:
493 return content->content.infosList.nbInfos;
494 case CHOICES_LIST:
495 return content->content.choicesList.nbChoices;
496 case BARS_LIST:
497 return content->content.barsList.nbBars;
498 default:
499 return 1;
500 }
501}
502
503// Helper to retrieve the pair at the given index in a tag/value list, either from the pairs array
504// or using the callback. The index is relative to the first pair of the list, so with a callback,
505// the startIndex of the list is added to it
506static const nbgl_contentTagValue_t *getTagValuePair(const nbgl_contentTagValueList_t *tagValueList,
507 uint8_t index)
508{
509 static nbgl_contentTagValue_t emptyPair;
510 const nbgl_contentTagValue_t *pair;
511
512 if (tagValueList->pairs != NULL) {
513 return PIC(&tagValueList->pairs[index]);
514 }
515 pair = PIC(tagValueList->callback(tagValueList->startIndex + index));
516 if (pair == NULL) {
517 // an empty pair is used if the callback doesn't provide one
518 LOG_WARN(USE_CASE_LOGGER, "getTagValuePair(): no pair for index %d\n", index);
519 memset(&emptyPair, 0, sizeof(emptyPair));
520 emptyPair.item = "";
521 emptyPair.value = "";
522 pair = &emptyPair;
523 }
524 return pair;
525}
526
527// Callback given to the layer drawing the current page, to retrieve its pairs from the application
528// callback, with the same empty pair fallback
529static nbgl_contentTagValue_t *getCurrentPageTagValuePair(uint8_t pairIndex)
530{
531 nbgl_contentTagValueList_t tagValueList = {0};
532
533 tagValueList.callback = genericContext.currentCallback;
534 return (nbgl_contentTagValue_t *) getTagValuePair(&tagValueList, pairIndex);
535}
536
537// Callback given to the layer drawing a modal page of a TAG_VALUE_LIST_ALIAS alias, to retrieve
538// its pairs from the callback of the alias list, with the same empty pair fallback.
539// (genericContext.currentCallback can't be used, it is the one of the review page behind the modal)
540static nbgl_contentTagValue_t *getModalTagValuePair(uint8_t pairIndex)
541{
542 nbgl_contentTagValueList_t tagValueList = {0};
543
544 tagValueList.callback = genericContext.currentTagValues->callback;
545 return (nbgl_contentTagValue_t *) getTagValuePair(&tagValueList, pairIndex);
546}
547
548// Computes the index of the first pair (relative to the list) of the given page of the alias
549// tag/value list modal, and the number of pairs in this page, by replaying the pagination from the
550// first page. No page table is used, so that the number of pages is not bounded (at most one page
551// per pair, see getNbTagValuesInDetailsPage()), and so that the number of pairs per page is not
552// limited by the encoding of a page table
553static uint8_t getTagValueListModalPage(const nbgl_contentTagValueList_t *tagValues,
554 uint8_t pageIdx,
555 uint8_t *nbPairsInPage)
556{
557 uint8_t startIdx = 0;
558 uint8_t page = 0;
559
560 *nbPairsInPage = 0;
561 while (startIdx < tagValues->nbPairs) {
562 uint8_t nbPairs
563 = getNbTagValuesInDetailsPage(tagValues->nbPairs - startIdx, tagValues, startIdx);
564 if (page == pageIdx) {
565 *nbPairsInPage = nbPairs;
566 break;
567 }
568 startIdx += nbPairs;
569 page++;
570 }
571 return startIdx;
572}
573
574static bool checkTagValueList(const nbgl_contentTagValueList_t *tagValueList, bool checkAliases);
575
576// Helper to check that the details of a pair displayed as an alias can be displayed in full:
577// the list of an INFO_LIST_ALIAS or TAG_VALUE_LIST_ALIAS alias must exist and must not be empty
578// (its modal would have no page), and the one of a TAG_VALUE_LIST_ALIAS alias using a callback
579// must be provided with all its pairs by it. Otherwise touching the alias would crash, or display
580// empty details, or nothing at all, preventing to verify the actual value.
581// (pairs of an alias list are not checked for aliases, since their details are not reachable)
582static bool isAliasDetailsValid(const nbgl_contentTagValue_t *pair)
583{
584 const nbgl_contentValueExt_t *extension;
585
586 // the extension is in an union with valueIcon, only relevant for an alias
587 if (!pair->aliasValue || (pair->extension == NULL)) {
588 return true;
589 }
590 extension = PIC(pair->extension);
591 if (extension->aliasType == INFO_LIST_ALIAS) {
592 const nbgl_contentInfoList_t *infoList = PIC(extension->infolist);
593 return (infoList != NULL) && (infoList->nbInfos > 0);
594 }
595 if (extension->aliasType == TAG_VALUE_LIST_ALIAS) {
596 const nbgl_contentTagValueList_t *aliasList = PIC(extension->tagValuelist);
597 return (aliasList != NULL) && (aliasList->nbPairs > 0)
598 && checkTagValueList(aliasList, false);
599 }
600 return true;
601}
602
603// Helper to check that all pairs of a non NULL tag/value list retrieved with a callback are
604// provided by it, with an index fitting in uint8_t (from startIndex to startIndex + nbPairs - 1).
605// If checkAliases is true, the details of every pair displayed as an alias are checked too
606// (see isAliasDetailsValid()).
607// An empty list is valid, since no pair is retrieved from it.
608static bool checkTagValueList(const nbgl_contentTagValueList_t *tagValueList, bool checkAliases)
609{
610 if (tagValueList->nbPairs == 0) {
611 return true;
612 }
613 if (tagValueList->pairs == NULL) {
614 if ((tagValueList->callback == NULL)
615 || (((uint16_t) tagValueList->startIndex + tagValueList->nbPairs) > (UINT8_MAX + 1))) {
616 return false;
617 }
618 }
619 else if (!checkAliases) {
620 return true;
621 }
622 for (uint8_t i = 0; i < tagValueList->nbPairs; i++) {
623 const nbgl_contentTagValue_t *pair;
624
625 if (tagValueList->pairs != NULL) {
626 pair = PIC(&tagValueList->pairs[i]);
627 }
628 else {
629 pair = PIC(tagValueList->callback(tagValueList->startIndex + i));
630 }
631 if ((pair == NULL) || (checkAliases && !isAliasDetailsValid(pair))) {
632 return false;
633 }
634 }
635 return true;
636}
637
638// Helper to check that all pairs of a tag/value list retrieved with a callback are provided by it,
639// with an index fitting in uint8_t (from startIndex to startIndex + nbPairs - 1), and that the
640// details of all its aliases can be displayed in full.
641// A NULL list is valid: callers where the list is mandatory must reject it themselves.
642// An empty list is valid too, since no pair is retrieved from it.
643static bool isTagValueListValid(const nbgl_contentTagValueList_t *tagValueList)
644{
645 return (tagValueList == NULL) || checkTagValueList(tagValueList, true);
646}
647
648// Helper to check that the whole address to verify can be displayed in the ADDR_VERIF_NB_PAIRS
649// pages of the address confirmation, otherwise a suffix of the address would never be displayed
650// before the "Confirm" action. A null number of pages is also rejected, in case of overflow.
651static bool isAddressReviewable(const char *address)
652{
653 if (address == NULL) {
654 return false;
655 }
656 uint8_t nbChunks = nbgl_getTextNbPagesInWidth(
657 LARGE_MEDIUM_FONT, address, NB_MAX_LINES_IN_REVIEW, AVAILABLE_WIDTH);
658 return (nbChunks > 0) && (nbChunks <= ADDR_VERIF_NB_PAIRS);
659}
660
661// Helper to retrieve the content inside a nbgl_genericContents_t using
662// either the contentsList or using the contentGetterCallback
663static const nbgl_content_t *getContentAtIdx(const nbgl_genericContents_t *genericContents,
664 int8_t contentIdx,
665 nbgl_content_t *content)
666{
667 if (contentIdx < 0 || contentIdx >= genericContents->nbContents) {
668 LOG_DEBUG(USE_CASE_LOGGER, "No content available at %d\n", contentIdx);
669 return NULL;
670 }
671
672 if (genericContents->callbackCallNeeded) {
673 // Retrieve content through callback, but first memset the content.
674 memset(content, 0, sizeof(nbgl_content_t));
675 genericContents->contentGetterCallback(contentIdx, content);
676 return content;
677 }
678 else {
679 // Retrieve content through list
680 return PIC(&genericContents->contentsList[contentIdx]);
681 }
682}
683
684// Helper to check that all tag/value lists in a nbgl_genericContents_t are valid and not empty
685// (an empty list would give a page without content, preventing to go further in the review)
686static bool isGenericContentsValid(const nbgl_genericContents_t *genericContents)
687{
688 nbgl_content_t content = {0};
689 const nbgl_content_t *p_content;
690 const nbgl_contentTagValueList_t *tagValueList;
691
692 for (int i = 0; i < genericContents->nbContents; i++) {
693 p_content = getContentAtIdx(genericContents, i, &content);
694 if (p_content == NULL) {
695 return false;
696 }
697 if (p_content->type == TAG_VALUE_LIST) {
698 tagValueList = &p_content->content.tagValueList;
699 }
700 else if (p_content->type == TAG_VALUE_CONFIRM) {
701 tagValueList = &p_content->content.tagValueConfirm.tagValueList;
702 }
703 else {
704 continue;
705 }
706 if ((tagValueList->nbPairs == 0) || !isTagValueListValid(tagValueList)) {
707 return false;
708 }
709 }
710 return true;
711}
712
713static void prepareNavInfo(bool isReview, uint8_t nbPages, const char *rejectText)
714{
715 memset(&navInfo, 0, sizeof(navInfo));
716
717 navInfo.nbPages = nbPages;
718 navInfo.tuneId = TUNE_TAP_CASUAL;
719 navInfo.progressIndicator = false;
720 navInfo.navType = NAV_WITH_BUTTONS;
721
722 if (isReview == false) {
723 navInfo.navWithButtons.navToken = NAV_TOKEN;
724 navInfo.navWithButtons.backButton = true;
725 }
726 else {
727 navInfo.quitToken = REJECT_TOKEN;
728 navInfo.navWithButtons.quitText = rejectText;
729 navInfo.navWithButtons.navToken = NAV_TOKEN;
731 = ((navType == STREAMING_NAV) && (nbPages < 2)) ? false : true;
732 navInfo.navWithButtons.visiblePageIndicator = (navType != STREAMING_NAV);
733 }
734}
735
736static void prepareReviewFirstPage(nbgl_contentCenter_t *contentCenter,
737 const nbgl_icon_details_t *icon,
738 const char *reviewTitle,
739 const char *reviewSubTitle)
740{
741 contentCenter->icon = icon;
742 contentCenter->title = reviewTitle;
743 contentCenter->description = reviewSubTitle;
744 contentCenter->subText = "Swipe to review";
745 contentCenter->smallTitle = NULL;
746 contentCenter->iconHug = 0;
747 contentCenter->padding = false;
748 contentCenter->illustrType = ICON_ILLUSTRATION;
749}
750
751static const char *getFinishTitle(nbgl_operationType_t operationType, const char *finishTitle)
752{
753 if (finishTitle != NULL) {
754 return finishTitle;
755 }
756 switch (operationType & REAL_TYPE_MASK) {
757 case TYPE_TRANSACTION:
758 return "Sign transaction";
759 case TYPE_MESSAGE:
760 return "Sign message";
761 default:
762 return "Sign operation";
763 }
764}
765
766static void prepareReviewLastPage(nbgl_operationType_t operationType,
767 nbgl_contentInfoLongPress_t *infoLongPress,
768 const nbgl_icon_details_t *icon,
769 const char *finishTitle)
770{
771 infoLongPress->text = getFinishTitle(operationType, finishTitle);
772 infoLongPress->icon = icon;
773 infoLongPress->longPressText = "Hold to sign";
774 infoLongPress->longPressToken = CONFIRM_TOKEN;
775}
776
777static void prepareReviewLightLastPage(nbgl_operationType_t operationType,
778 nbgl_contentInfoButton_t *infoButton,
779 const nbgl_icon_details_t *icon,
780 const char *finishTitle)
781{
782 infoButton->text = getFinishTitle(operationType, finishTitle);
783 infoButton->icon = icon;
784 if (operationType & ADDRESS_BOOK_OPERATION) {
785 infoButton->buttonText = "Confirm";
786 }
787 else {
788 infoButton->buttonText = "Approve";
789 }
790 infoButton->buttonToken = CONFIRM_TOKEN;
791}
792
793static const char *getRejectReviewText(nbgl_operationType_t operationType)
794{
795 if (operationType & ADDRESS_BOOK_OPERATION) {
796 return "Cancel";
797 }
798 return "Reject";
799}
800
801// function called when navigating (or exiting) modal details pages
802// or when skip choice is displayed
803static void pageModalCallback(int token, uint8_t index)
804{
805 LOG_DEBUG(USE_CASE_LOGGER, "pageModalCallback, token = %d, index = %d\n", token, index);
806
807 if (token == INFOS_TIP_BOX_TOKEN) {
808 // the icon next to info type alias has been touched
809 displayFullValuePage(activeTipBox.infos.infoTypes[index],
810 activeTipBox.infos.infoContents[index],
811 &activeTipBox.infos.infoExtensions[index]);
812 return;
813 }
814 else if (token == INFO_ALIAS_TOKEN) {
815 // the icon next to info type alias has been touched, but coming from review
816 displayFullValuePage(genericContext.currentInfos->infoTypes[index],
817 genericContext.currentInfos->infoContents[index],
818 &genericContext.currentInfos->infoExtensions[index]);
819 return;
820 }
821 nbgl_pageRelease(modalPageContext);
822 modalPageContext = NULL;
823 if (token == NAV_TOKEN) {
824 if (index == EXIT_PAGE) {
825 // redraw the background layer
827 nbgl_refresh();
828 }
829 else {
830 displayDetailsPage(index, false);
831 }
832 }
833 if (token == MODAL_NAV_TOKEN) {
834 if (index == EXIT_PAGE) {
835 // redraw the background layer
837 nbgl_refresh();
838 }
839 else {
840 displayTagValueListModalPage(index, false);
841 }
842 }
843 else if (token == QUIT_TOKEN) {
844 // redraw the background layer
846 nbgl_refresh();
847 }
848 else if (token == QUIT_TIPBOX_MODAL_TOKEN) {
849 // if in "warning context", go back to security report
850 if (reviewWithWarnCtx.securityReportLevel == 2) {
851 reviewWithWarnCtx.securityReportLevel = 1;
852 displaySecurityReport(reviewWithWarnCtx.warning->predefinedSet);
853 }
854 else {
855 // redraw the background layer
857 nbgl_refresh();
858 }
859 }
860 else if (token == SKIP_TOKEN) {
861 if (index == 0) {
862 // display the last forward only review page, whatever it is
863 displayGenericContextPage(LAST_PAGE_FOR_REVIEW, true);
864 }
865 else {
866 // display background, which should be the page where skip has been touched
868 nbgl_refresh();
869 }
870 }
871 else if (token == CHOICE_TOKEN) {
872 if (index == 0) {
873 if (onModalConfirm != NULL) {
874 onModalConfirm();
875 onModalConfirm = NULL;
876 }
877 }
878 else {
879 // display background, which should be the page where skip has been touched
881 nbgl_refresh();
882 }
883 }
884}
885
886// generic callback for all pages except modal
887static void pageCallback(int token, uint8_t index)
888{
889 LOG_DEBUG(USE_CASE_LOGGER, "pageCallback, token = %d, index = %d\n", token, index);
890 if (token == QUIT_TOKEN) {
891 if (onQuit != NULL) {
892 onQuit();
893 }
894 }
895 else if (token == CONTINUE_TOKEN) {
896 if (onContinue != NULL) {
897 onContinue();
898 }
899 }
900 else if (token == CHOICE_TOKEN) {
901 if (onChoice != NULL) {
902 onChoice((index == 0) ? true : false);
903 }
904 }
905 else if (token == ACTION_BUTTON_TOKEN) {
906 if ((index == 0) && (onAction != NULL)) {
907 onAction();
908 }
909 else if ((index == 1) && (onQuit != NULL)) {
910 onQuit();
911 }
912 }
913#ifdef NBGL_QRCODE
914 else if (token == ADDRESS_QRCODE_BUTTON_TOKEN) {
915 displayAddressQRCode();
916 }
917#endif // NBGL_QRCODE
918 else if (token == CONFIRM_TOKEN) {
919 if (onChoice != NULL) {
920 onChoice(true);
921 }
922 }
923 else if (token == REJECT_TOKEN) {
924 if (onChoice != NULL) {
925 onChoice(false);
926 }
927 }
928 else if (token == DETAILS_BUTTON_TOKEN) {
929 displayDetails(genericContext.detailsItem,
930 genericContext.detailsvalue,
931 genericContext.detailsWrapping);
932 }
933 else if (token == NAV_TOKEN) {
934 if (index == EXIT_PAGE) {
935 if (onQuit != NULL) {
936 onQuit();
937 }
938 }
939 else {
940 if (navType == GENERIC_NAV || navType == STREAMING_NAV) {
941 displayGenericContextPage(index, false);
942 }
943 else if (navType == REVIEW_NAV) {
944 displayReviewPage(index, false);
945 }
946 else {
947 displaySettingsPage(index, false);
948 }
949 }
950 }
951 else if (token == NEXT_TOKEN) {
952 if (onNav != NULL) {
953 displayReviewPage(navInfo.activePage + 1, false);
954 }
955 else {
956 displayGenericContextPage(navInfo.activePage + 1, false);
957 }
958 }
959 else if (token == BACK_TOKEN) {
960 if (onNav != NULL) {
961 displayReviewPage(navInfo.activePage - 1, true);
962 }
963 else {
964 displayGenericContextPage(navInfo.activePage - 1, false);
965 }
966 }
967 else if (token == SKIP_TOKEN) {
968 // display a modal warning to confirm skip
969 displaySkipWarning();
970 }
971 else if (token == VALUE_ALIAS_TOKEN) {
972 // the icon next to value alias has been touched
973 const nbgl_contentTagValue_t *pair = NULL;
974 // currentPairs (or currentCallback) is the unsliced list, so the absolute index of the
975 // touched pair is the index of the first pair of the page plus the index in the page
976 uint16_t absoluteIdx = (uint16_t) genericContext.currentElementIdx + index;
977 if (absoluteIdx < genericContext.currentNbPairs) {
978 if (genericContext.currentPairs != NULL) {
979 pair = &genericContext.currentPairs[absoluteIdx];
980 }
981 else if (genericContext.currentCallback != NULL) {
982 pair = PIC(
983 genericContext.currentCallback(genericContext.currentStartIndex + absoluteIdx));
984 }
985 }
986 if ((pair != NULL) && (pair->extension != NULL)) {
987 displayFullValuePage(pair->item, pair->value, PIC(pair->extension));
988 }
989 else {
990 LOG_WARN(USE_CASE_LOGGER, "pageCallback(): no alias for index %d\n", absoluteIdx);
991 }
992 }
993 else if (token == INFO_ALIAS_TOKEN) {
994 // the icon next to an info of a (possibly paginated) generic infos list has been
995 // touched: currentPageInfos is the unsliced list, so use the absolute index
996 const nbgl_contentInfoList_t *infos = &genericContext.currentPageInfos;
997 uint16_t absoluteIdx = (uint16_t) genericContext.currentElementIdx + index;
998 if ((absoluteIdx < infos->nbInfos) && (infos->withExtensions)
999 && (infos->infoExtensions != NULL)) {
1000 const nbgl_contentValueExt_t *extension = PIC(&infos->infoExtensions[absoluteIdx]);
1001 displayFullValuePage(PIC(((const char *const *) PIC(infos->infoTypes))[absoluteIdx]),
1002 PIC(((const char *const *) PIC(infos->infoContents))[absoluteIdx]),
1003 extension);
1004 }
1005 else {
1006 LOG_WARN(USE_CASE_LOGGER, "pageCallback(): no info alias for index %d\n", absoluteIdx);
1007 }
1008 }
1009 else if (token == BLIND_WARNING_TOKEN) {
1010 reviewWithWarnCtx.isIntro = false;
1011 reviewWithWarnCtx.warning = NULL;
1012 displaySecurityReport(1 << BLIND_SIGNING_WARN);
1013 }
1014 else if (token == WARNING_BUTTON_TOKEN) {
1015 // top-right button, display the security modal
1016 reviewWithWarnCtx.securityReportLevel = 1;
1017 // if preset is used
1018 if (reviewWithWarnCtx.warning->predefinedSet) {
1019 displaySecurityReport(reviewWithWarnCtx.warning->predefinedSet);
1020 }
1021 else {
1022 // use customized warning
1023 if (reviewWithWarnCtx.isIntro) {
1024 displayCustomizedSecurityReport(reviewWithWarnCtx.warning->introDetails);
1025 }
1026 else {
1027 displayCustomizedSecurityReport(reviewWithWarnCtx.warning->reviewDetails);
1028 }
1029 }
1030 }
1031 else if (token == TIP_BOX_TOKEN) {
1032 // if warning context is valid and if W3C directly display same as top-right
1033 if (genericContext.validWarningCtx && (reviewWithWarnCtx.warning->predefinedSet != 0)) {
1034 reviewWithWarnCtx.securityReportLevel = 1;
1035 displaySecurityReport(reviewWithWarnCtx.warning->predefinedSet);
1036 }
1037 else {
1038 displayInfosListModal(activeTipBox.modalTitle, &activeTipBox.infos, false);
1039 }
1040 }
1041 else { // probably a control provided by caller
1042 if (onContentAction != NULL) {
1043 onContentAction(token, index, navInfo.activePage);
1044 }
1045 if (onControls != NULL) {
1046 onControls(token, index);
1047 }
1048 }
1049}
1050
1051// callback used for confirmation
1052static void tickerCallback(void)
1053{
1054 nbgl_pageRelease(pageContext);
1055 if (onQuit != NULL) {
1056 onQuit();
1057 }
1058}
1059
1060// function used to display the current page in review
1061static void displaySettingsPage(uint8_t page, bool forceFullRefresh)
1062{
1063 nbgl_pageContent_t content = {0};
1064
1065 if (onNav == NULL) {
1066 LOG_WARN(USE_CASE_LOGGER, "displaySettingsPage(): onNav callback is NULL\n");
1067 return;
1068 }
1069 if (onNav(page, &content) == false) {
1070 return;
1071 }
1072
1073 // override some fields
1074 content.title = pageTitle;
1075 content.isTouchableTitle = true;
1076 content.titleToken = QUIT_TOKEN;
1077 content.tuneId = TUNE_TAP_CASUAL;
1078
1079 navInfo.activePage = page;
1080 pageContext = nbgl_pageDrawGenericContent(&pageCallback, &navInfo, &content);
1081
1082 if (forceFullRefresh) {
1084 }
1085 else {
1087 }
1088}
1089
1090// function used to display the current page in review
1091static void displayReviewPage(uint8_t page, bool forceFullRefresh)
1092{
1093 nbgl_pageContent_t content = {0};
1094
1095 // ensure the page is valid
1096 if ((navInfo.nbPages != 0) && (page >= (navInfo.nbPages))) {
1097 return;
1098 }
1099 navInfo.activePage = page;
1100 if (onNav == NULL) {
1101 LOG_WARN(USE_CASE_LOGGER, "displayReviewPage(): onNav callback is NULL\n");
1102 return;
1103 }
1104 if (onNav(navInfo.activePage, &content) == false) {
1105 return;
1106 }
1107
1108 // override some fields
1109 content.title = NULL;
1110 content.isTouchableTitle = false;
1111 content.tuneId = TUNE_TAP_CASUAL;
1112
1113 if (content.type == INFO_LONG_PRESS) { // last page
1114 // for forward only review without known length...
1115 // if we don't do that we cannot remove the '>' in the navigation bar at the last page
1116 navInfo.nbPages = navInfo.activePage + 1;
1117 content.infoLongPress.longPressToken = CONFIRM_TOKEN;
1118 }
1119
1120 // override smallCaseForValue for tag/value types to false
1121 if (content.type == TAG_VALUE_DETAILS) {
1123 // the maximum displayable number of lines for value is NB_MAX_LINES_IN_REVIEW (without More
1124 // button)
1127 }
1128 else if (content.type == TAG_VALUE_LIST) {
1129 content.tagValueList.smallCaseForValue = false;
1130 }
1131 else if (content.type == TAG_VALUE_CONFIRM) {
1133 // use confirm token for black button
1134 content.tagValueConfirm.confirmationToken = CONFIRM_TOKEN;
1135 }
1136
1137 pageContext = nbgl_pageDrawGenericContent(&pageCallback, &navInfo, &content);
1138
1139 if (forceFullRefresh) {
1141 }
1142 else {
1144 }
1145}
1146
1147// Helper that does the computing of which nbgl_content_t and which element in the content should be
1148// displayed for the next generic context navigation page
1149static const nbgl_content_t *genericContextComputeNextPageParams(uint8_t pageIdx,
1150 nbgl_content_t *content,
1151 uint8_t *p_nbElementsInNextPage,
1152 bool *p_flag)
1153{
1154 int8_t nextContentIdx = genericContext.currentContentIdx;
1155 int16_t nextElementIdx = genericContext.currentElementIdx;
1156 uint8_t nbElementsInNextPage;
1157
1158 // Retrieve info on the next page
1159 genericContextGetPageInfo(pageIdx, &nbElementsInNextPage, p_flag);
1160 *p_nbElementsInNextPage = nbElementsInNextPage;
1161
1162 // Handle forward navigation:
1163 // add to current index the number of pairs of the currently active page
1164 if (pageIdx > navInfo.activePage) {
1165 uint8_t nbElementsInCurrentPage;
1166
1167 genericContextGetPageInfo(navInfo.activePage, &nbElementsInCurrentPage, NULL);
1168 nextElementIdx += nbElementsInCurrentPage;
1169
1170 // Handle case where the content to be displayed is in the next content
1171 // In such case start at element index 0.
1172 // If currentContentElementNb == 0, means not initialized, so skip
1173 if ((nextElementIdx >= genericContext.currentContentElementNb)
1174 && (genericContext.currentContentElementNb > 0)) {
1175 nextContentIdx += 1;
1176 nextElementIdx = 0;
1177 }
1178 }
1179
1180 // Handle backward navigation:
1181 // add to current index the number of pairs of the currently active page
1182 if (pageIdx < navInfo.activePage) {
1183 // Backward navigation: remove to current index the number of pairs of the current page
1184 nextElementIdx -= nbElementsInNextPage;
1185
1186 // Handle case where the content to be displayed is in the previous content
1187 // In such case set a negative number as element index so that it is handled
1188 // later once the previous content is accessible so that its elements number
1189 // can be retrieved.
1190 if (nextElementIdx < 0) {
1191 nextContentIdx -= 1;
1192 nextElementIdx = -nbElementsInNextPage;
1193 }
1194 }
1195
1196 const nbgl_content_t *p_content;
1197 // Retrieve next content
1198 if ((nextContentIdx == -1) && (genericContext.hasStartingContent)) {
1199 p_content = &STARTING_CONTENT;
1200 }
1201 else if ((nextContentIdx == genericContext.genericContents.nbContents)
1202 && (genericContext.hasFinishingContent)) {
1203 p_content = &FINISHING_CONTENT;
1204 }
1205 else {
1206 p_content = getContentAtIdx(&genericContext.genericContents, nextContentIdx, content);
1207
1208 if (p_content == NULL) {
1209 LOG_DEBUG(USE_CASE_LOGGER, "Fail to retrieve content\n");
1210 return NULL;
1211 }
1212 }
1213
1214 // Handle cases where we are going to display data from a new content:
1215 // - navigation to a previous or to the next content
1216 // - First page display (genericContext.currentContentElementNb == 0)
1217 //
1218 // In such case we need to:
1219 // - Update genericContext.currentContentIdx
1220 // - Update genericContext.currentContentElementNb
1221 // - Update onContentAction callback
1222 // - Update nextElementIdx in case it was previously not calculable
1223 if ((nextContentIdx != genericContext.currentContentIdx)
1224 || (genericContext.currentContentElementNb == 0)) {
1225 genericContext.currentContentIdx = nextContentIdx;
1226 genericContext.currentContentElementNb = getContentNbElement(p_content);
1227 onContentAction = PIC(p_content->contentActionCallback);
1228 if (nextElementIdx < 0) {
1229 nextElementIdx = genericContext.currentContentElementNb + nextElementIdx;
1230 }
1231 }
1232
1233 // Sanity check
1234 if ((nextElementIdx < 0) || (nextElementIdx >= genericContext.currentContentElementNb)) {
1236 "Invalid element index %d / %d\n",
1237 nextElementIdx,
1238 genericContext.currentContentElementNb);
1239 return NULL;
1240 }
1241
1242 // Update genericContext elements
1243 genericContext.currentElementIdx = nextElementIdx;
1244 navInfo.activePage = pageIdx;
1245
1246 return p_content;
1247}
1248
1249// Helper that generates a nbgl_pageContent_t to be displayed for the next generic context
1250// navigation page
1251static bool genericContextPreparePageContent(const nbgl_content_t *p_content,
1252 uint8_t nbElementsInPage,
1253 bool flag,
1254 nbgl_pageContent_t *pageContent)
1255{
1256 uint8_t nextElementIdx = genericContext.currentElementIdx;
1257
1258 pageContent->title = pageTitle;
1259 pageContent->isTouchableTitle = false;
1260 pageContent->titleToken = QUIT_TOKEN;
1261 pageContent->tuneId = TUNE_TAP_CASUAL;
1262
1263 pageContent->type = p_content->type;
1264 switch (pageContent->type) {
1265 case CENTERED_INFO:
1266 memcpy(&pageContent->centeredInfo,
1267 &p_content->content.centeredInfo,
1268 sizeof(pageContent->centeredInfo));
1269 break;
1270 case EXTENDED_CENTER:
1271 memcpy(&pageContent->extendedCenter,
1272 &p_content->content.extendedCenter,
1273 sizeof(pageContent->extendedCenter));
1274 break;
1275 case INFO_LONG_PRESS:
1276 memcpy(&pageContent->infoLongPress,
1277 &p_content->content.infoLongPress,
1278 sizeof(pageContent->infoLongPress));
1279 break;
1280
1281 case INFO_BUTTON:
1282 memcpy(&pageContent->infoButton,
1283 &p_content->content.infoButton,
1284 sizeof(pageContent->infoButton));
1285 break;
1286
1287 case TAG_VALUE_LIST: {
1288 nbgl_contentTagValueList_t *p_tagValueList = &pageContent->tagValueList;
1289
1290 // memorize pairs (or callback) for usage when alias is used
1291 genericContext.currentPairs = p_content->content.tagValueList.pairs;
1292 genericContext.currentCallback = p_content->content.tagValueList.callback;
1293 genericContext.currentNbPairs = p_content->content.tagValueList.nbPairs;
1294 genericContext.currentStartIndex = p_content->content.tagValueList.startIndex;
1295
1296 if (flag) {
1297 // Flag can be set if the pair is too long to fit or because it needs
1298 // to be displayed as centered info.
1299
1300 // First retrieve the pair
1301 const nbgl_layoutTagValue_t *pair
1302 = getTagValuePair(&p_content->content.tagValueList, nextElementIdx);
1303
1304 if (pair->centeredInfo) {
1305 pageContent->type = EXTENDED_CENTER;
1306 prepareReviewFirstPage(&pageContent->extendedCenter.contentCenter,
1307 pair->valueIcon,
1308 pair->item,
1309 pair->value);
1310
1311 // Skip population of nbgl_contentTagValueList_t structure
1312 p_tagValueList = NULL;
1313 }
1314 else {
1315 // if the pair is too long to fit, we use a TAG_VALUE_DETAILS content
1316 pageContent->type = TAG_VALUE_DETAILS;
1317 pageContent->tagValueDetails.detailsButtonText = "More";
1318 pageContent->tagValueDetails.detailsButtonIcon = NULL;
1319 pageContent->tagValueDetails.detailsButtonToken = DETAILS_BUTTON_TOKEN;
1320
1321 p_tagValueList = &pageContent->tagValueDetails.tagValueList;
1322
1323 // Backup pair info for easy data access upon click on button
1324 genericContext.detailsItem = pair->item;
1325 genericContext.detailsvalue = pair->value;
1326 genericContext.detailsWrapping = p_content->content.tagValueList.wrapping;
1327 }
1328 }
1329
1330 if (p_tagValueList != NULL) {
1331 p_tagValueList->nbPairs = nbElementsInPage;
1332 p_tagValueList->token = p_content->content.tagValueList.token;
1333 if (p_content->content.tagValueList.pairs != NULL) {
1334 p_tagValueList->pairs
1335 = PIC(&p_content->content.tagValueList.pairs[nextElementIdx]);
1336 // parse pairs to check if any contains an alias for value
1337 for (uint8_t i = 0; i < nbElementsInPage; i++) {
1338 if (p_tagValueList->pairs[i].aliasValue) {
1339 p_tagValueList->token = VALUE_ALIAS_TOKEN;
1340 break;
1341 }
1342 }
1343 }
1344 else {
1345 p_tagValueList->pairs = NULL;
1346 p_tagValueList->callback = getCurrentPageTagValuePair;
1347 p_tagValueList->startIndex
1348 = p_content->content.tagValueList.startIndex + nextElementIdx;
1349 // parse pairs to check if any contains an alias for value
1350 for (uint8_t i = 0; i < nbElementsInPage; i++) {
1351 const nbgl_layoutTagValue_t *pair
1352 = getTagValuePair(&p_content->content.tagValueList, nextElementIdx + i);
1353 if (pair->aliasValue) {
1354 p_tagValueList->token = VALUE_ALIAS_TOKEN;
1355 break;
1356 }
1357 }
1358 }
1359 // (smallCaseForValue is also forced to false in getNbPagesForContent())
1360 p_tagValueList->smallCaseForValue = false;
1362 p_tagValueList->hideEndOfLastLine = true;
1363 p_tagValueList->wrapping = p_content->content.tagValueList.wrapping;
1364 }
1365
1366 break;
1367 }
1368 case TAG_VALUE_CONFIRM: {
1369 nbgl_contentTagValueList_t *p_tagValueList;
1370 // only display a TAG_VALUE_CONFIRM if we are at the last page
1371 if ((nextElementIdx + nbElementsInPage)
1373 memcpy(&pageContent->tagValueConfirm,
1374 &p_content->content.tagValueConfirm,
1375 sizeof(pageContent->tagValueConfirm));
1376 p_tagValueList = &pageContent->tagValueConfirm.tagValueList;
1377 }
1378 else {
1379 // else display it as a TAG_VALUE_LIST: preserve list-level
1380 // settings (nbMaxLinesForValue, wrapping, smallCaseForValue,
1381 // hideEndOfLastLine, token...) so intermediate pages render
1382 // identically to the last page
1383 pageContent->type = TAG_VALUE_LIST;
1384 pageContent->tagValueList = p_content->content.tagValueConfirm.tagValueList;
1385 p_tagValueList = &pageContent->tagValueList;
1386 }
1387 p_tagValueList->nbPairs = nbElementsInPage;
1388 if (p_content->content.tagValueConfirm.tagValueList.pairs != NULL) {
1389 p_tagValueList->pairs
1390 = PIC(&p_content->content.tagValueConfirm.tagValueList.pairs[nextElementIdx]);
1391 // parse pairs to check if any contains an alias for value
1392 for (uint8_t i = 0; i < nbElementsInPage; i++) {
1393 if (p_tagValueList->pairs[i].aliasValue) {
1394 p_tagValueList->token = VALUE_ALIAS_TOKEN;
1395 break;
1396 }
1397 }
1398 }
1399 else {
1400 p_tagValueList->pairs = NULL;
1401 p_tagValueList->callback = getCurrentPageTagValuePair;
1402 p_tagValueList->startIndex
1403 = p_content->content.tagValueConfirm.tagValueList.startIndex + nextElementIdx;
1404 // parse pairs to check if any contains an alias for value
1405 for (uint8_t i = 0; i < nbElementsInPage; i++) {
1406 const nbgl_layoutTagValue_t *pair = getTagValuePair(
1407 &p_content->content.tagValueConfirm.tagValueList, nextElementIdx + i);
1408 if ((pair != NULL) && (pair->aliasValue)) {
1409 p_tagValueList->token = VALUE_ALIAS_TOKEN;
1410 break;
1411 }
1412 }
1413 }
1414 // memorize pairs (or callback) for usage when alias is used: the unsliced list must
1415 // be used, because the touched pair is retrieved with its absolute index
1416 genericContext.currentPairs
1417 = PIC(p_content->content.tagValueConfirm.tagValueList.pairs);
1418 genericContext.currentCallback
1420 genericContext.currentNbPairs = p_content->content.tagValueConfirm.tagValueList.nbPairs;
1421 genericContext.currentStartIndex
1423 break;
1424 }
1425 case SWITCHES_LIST:
1426 pageContent->switchesList.nbSwitches = nbElementsInPage;
1427 pageContent->switchesList.switches
1428 = PIC(&p_content->content.switchesList.switches[nextElementIdx]);
1429 break;
1430 case INFOS_LIST:
1431 pageContent->infosList.nbInfos = nbElementsInPage;
1432 pageContent->infosList.infoTypes
1433 = PIC(&p_content->content.infosList.infoTypes[nextElementIdx]);
1434 pageContent->infosList.infoContents
1435 = PIC(&p_content->content.infosList.infoContents[nextElementIdx]);
1436 // keep extensions (full values), sliced like the texts, so that they remain
1437 // inspectable when the list is paginated
1438 if ((p_content->content.infosList.withExtensions)
1439 && (p_content->content.infosList.infoExtensions != NULL)) {
1440 pageContent->infosList.withExtensions = true;
1441 pageContent->infosList.infoExtensions
1442 = PIC(&p_content->content.infosList.infoExtensions[nextElementIdx]);
1443 pageContent->infosList.token = INFO_ALIAS_TOKEN;
1444 // memorize the unsliced list, the touched info is retrieved with its absolute
1445 // index
1446 genericContext.currentPageInfos = p_content->content.infosList;
1447 }
1448 break;
1449 case CHOICES_LIST:
1450 memcpy(&pageContent->choicesList,
1451 &p_content->content.choicesList,
1452 sizeof(pageContent->choicesList));
1453 pageContent->choicesList.nbChoices = nbElementsInPage;
1454 pageContent->choicesList.names
1455 = PIC(&p_content->content.choicesList.names[nextElementIdx]);
1456 if ((p_content->content.choicesList.initChoice >= nextElementIdx)
1457 && (p_content->content.choicesList.initChoice
1458 < nextElementIdx + nbElementsInPage)) {
1459 pageContent->choicesList.initChoice
1460 = p_content->content.choicesList.initChoice - nextElementIdx;
1461 }
1462 else {
1463 pageContent->choicesList.initChoice = nbElementsInPage;
1464 }
1465 break;
1466 case BARS_LIST:
1467 pageContent->barsList.nbBars = nbElementsInPage;
1468 pageContent->barsList.barTexts
1469 = PIC(&p_content->content.barsList.barTexts[nextElementIdx]);
1470 pageContent->barsList.tokens = PIC(&p_content->content.barsList.tokens[nextElementIdx]);
1471 pageContent->barsList.tuneId = p_content->content.barsList.tuneId;
1472 break;
1473 default:
1474 LOG_DEBUG(USE_CASE_LOGGER, "Unsupported type %d\n", pageContent->type);
1475 return false;
1476 }
1477
1478 bool isFirstOrLastPage
1479 = ((p_content->type == CENTERED_INFO) || (p_content->type == EXTENDED_CENTER))
1480 || (p_content->type == INFO_LONG_PRESS);
1481 nbgl_operationType_t operationType
1482 = (navType == STREAMING_NAV)
1483 ? bundleNavContext.reviewStreaming.operationType
1484 : ((navType == GENERIC_NAV) ? bundleNavContext.review.operationType : 0);
1485
1486 // if first or last page of review and blind/risky operation, add the warning top-right button
1487 if (isFirstOrLastPage
1488 && (operationType & (BLIND_OPERATION | RISKY_OPERATION | NO_THREAT_OPERATION))) {
1489 // if issue is only Web3Checks "no threat", use privacy icon
1490 if ((operationType & NO_THREAT_OPERATION)
1491 && !(reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN))) {
1492 pageContent->topRightIcon = &PRIVACY_ICON;
1493 }
1494 else {
1495 pageContent->topRightIcon = &WARNING_ICON;
1496 }
1497
1498 pageContent->topRightToken
1499 = (operationType & BLIND_OPERATION) ? BLIND_WARNING_TOKEN : WARNING_BUTTON_TOKEN;
1500 }
1501 // if first or last page of an advanced review with customized review details, add the
1502 // top-right button giving access to these details, with the caller provided icon
1503 else if (isFirstOrLastPage && ((navType == STREAMING_NAV) || (navType == GENERIC_NAV))
1504 && (sharedContext.usage == SHARE_CTX_REVIEW_WITH_WARNING)
1505 && (reviewWithWarnCtx.warning != NULL)
1506 && (reviewWithWarnCtx.warning->predefinedSet == 0)
1507 && (reviewWithWarnCtx.warning->reviewDetails != NULL)) {
1508 pageContent->topRightIcon = (reviewWithWarnCtx.warning->reviewTopRightIcon != NULL)
1509 ? reviewWithWarnCtx.warning->reviewTopRightIcon
1510 : &WARNING_ICON;
1511 pageContent->topRightToken = WARNING_BUTTON_TOKEN;
1512 }
1513
1514 return true;
1515}
1516
1517// function used to display the current page in generic context navigation mode
1518static void displayGenericContextPage(uint8_t pageIdx, bool forceFullRefresh)
1519{
1520 // Retrieve next page parameters
1521 nbgl_content_t content = {0};
1522 uint8_t nbElementsInPage;
1523 bool flag;
1524 const nbgl_content_t *p_content = NULL;
1525
1526 if (navType == STREAMING_NAV) {
1527 if (pageIdx == LAST_PAGE_FOR_REVIEW) {
1528 if (bundleNavContext.reviewStreaming.skipCallback != NULL) {
1529 bundleNavContext.reviewStreaming.skipCallback();
1530 }
1531 return;
1532 }
1533 else if (pageIdx >= bundleNavContext.reviewStreaming.stepPageNb) {
1534 bundleNavReviewStreamingChoice(true);
1535 return;
1536 }
1537 }
1538 else {
1539 // if coming from Skip modal, let's say we are at the last page
1540 if (pageIdx == LAST_PAGE_FOR_REVIEW) {
1541 pageIdx = navInfo.nbPages - 1;
1542 }
1543 }
1544
1545 if (navInfo.activePage == pageIdx) {
1546 p_content
1547 = genericContextComputeNextPageParams(pageIdx, &content, &nbElementsInPage, &flag);
1548 }
1549 else if (navInfo.activePage < pageIdx) {
1550 // Support going more than one step forward.
1551 // It occurs when initializing a navigation on an arbitrary page
1552 for (int i = navInfo.activePage + 1; i <= pageIdx; i++) {
1553 p_content = genericContextComputeNextPageParams(i, &content, &nbElementsInPage, &flag);
1554 }
1555 }
1556 else {
1557 if (pageIdx - navInfo.activePage > 1) {
1558 // We don't support going more than one step backward as it doesn't occurs for now?
1559 LOG_DEBUG(USE_CASE_LOGGER, "Unsupported navigation\n");
1560 return;
1561 }
1562 p_content
1563 = genericContextComputeNextPageParams(pageIdx, &content, &nbElementsInPage, &flag);
1564 }
1565
1566 if (p_content == NULL) {
1567 return;
1568 }
1569 // if the operation is skippable
1570 if ((navType != STREAMING_NAV)
1571 && (bundleNavContext.review.operationType & SKIPPABLE_OPERATION)) {
1572 // only present the "Skip" header on actual tag/value pages
1573 if ((pageIdx > 0) && (pageIdx < (navInfo.nbPages - 1))) {
1574 navInfo.progressIndicator = false;
1575 navInfo.skipText = "Skip";
1576 navInfo.skipToken = SKIP_TOKEN;
1577 }
1578 else {
1579 navInfo.skipText = NULL;
1580 }
1581 }
1582
1583 // Create next page content
1584 nbgl_pageContent_t pageContent = {0};
1585 if (!genericContextPreparePageContent(p_content, nbElementsInPage, flag, &pageContent)) {
1586 return;
1587 }
1588
1589 pageContext = nbgl_pageDrawGenericContent(&pageCallback, &navInfo, &pageContent);
1590
1591 if (forceFullRefresh) {
1593 }
1594 else {
1596 }
1597}
1598
1599// from the given position in the value of the current details context, return the number of bytes
1600// to skip to start the next details page, or 0 if all the remaining text fits in the page. Used to
1601// count, display and go back to the pages, so that they always match.
1602// If not NULL, ellipsis is set to true if the page ends with "..." (replacing its last 3 chars,
1603// which are displayed again at the beginning of the next page)
1604static uint16_t getDetailsPageLen(const char *text, bool *ellipsis)
1605{
1606 uint16_t len;
1607
1608 if (ellipsis != NULL) {
1609 *ellipsis = false;
1610 }
1611 if (nbgl_getTextNbLinesInWidth(SMALL_BOLD_FONT, text, AVAILABLE_WIDTH, detailsContext.wrapping)
1613 return 0;
1614 }
1615 nbgl_getTextMaxLenInNbLines(SMALL_BOLD_FONT,
1616 text,
1619 &len,
1620 detailsContext.wrapping);
1621 // don't start next page on a \n
1622 if (text[len] == '\n') {
1623 len++;
1624 }
1625 else if (!detailsContext.wrapping) {
1626 len -= 3;
1627 if (ellipsis != NULL) {
1628 *ellipsis = true;
1629 }
1630 }
1631 return len;
1632}
1633
1634// from the current details context, return a pointer on the details at the given page
1635static const char *getDetailsPageAt(uint8_t detailsPage)
1636{
1637 uint8_t page = 0;
1638 const char *currentChar = detailsContext.value;
1639 while (page < detailsPage) {
1640 currentChar = currentChar + getDetailsPageLen(currentChar, NULL);
1641 page++;
1642 }
1643 return currentChar;
1644}
1645
1646// function used to display the current page in details review mode
1647static void displayDetailsPage(uint8_t detailsPage, bool forceFullRefresh)
1648{
1649 static nbgl_layoutTagValue_t currentPair;
1650 nbgl_pageNavigationInfo_t info = {.activePage = detailsPage,
1651 .nbPages = detailsContext.nbPages,
1652 .navType = NAV_WITH_BUTTONS,
1653 .quitToken = QUIT_TOKEN,
1654 .navWithButtons.navToken = NAV_TOKEN,
1655 .navWithButtons.quitButton = true,
1656 .navWithButtons.backButton = true,
1657 .navWithButtons.quitText = NULL,
1658 .progressIndicator = false,
1659 .tuneId = TUNE_TAP_CASUAL};
1660 nbgl_pageContent_t content = {.type = TAG_VALUE_LIST,
1661 .topRightIcon = NULL,
1662 .tagValueList.nbPairs = 1,
1663 .tagValueList.pairs = &currentPair,
1664 .tagValueList.smallCaseForValue = true,
1665 .tagValueList.wrapping = detailsContext.wrapping};
1666
1667 if (modalPageContext != NULL) {
1668 nbgl_pageRelease(modalPageContext);
1669 }
1670 currentPair.item = detailsContext.tag;
1671 // if move backward or first page
1672 if (detailsPage <= detailsContext.currentPage) {
1673 // recompute current start from beginning
1674 currentPair.value = getDetailsPageAt(detailsPage);
1675 forceFullRefresh = true;
1676 }
1677 // else move forward
1678 else {
1679 currentPair.value = detailsContext.nextPageStart;
1680 }
1681 detailsContext.currentPage = detailsPage;
1682 bool ellipsis;
1683 uint16_t len = getDetailsPageLen(currentPair.value, &ellipsis);
1684
1685 if (len > 0) {
1687 // memorize next position to save processing
1688 detailsContext.nextPageStart = currentPair.value + len;
1689 // use special feature to keep only NB_MAX_LINES_IN_DETAILS lines and replace the last 3
1690 // chars by "...", only if the next char to display in next page is not '\n'
1692 }
1693 else {
1694 detailsContext.nextPageStart = NULL;
1695 content.tagValueList.nbMaxLinesForValue = 0;
1696 }
1697 if (info.nbPages == 1) {
1698 // if only one page, no navigation bar, and use a footer instead
1699 info.navWithButtons.quitText = "Close";
1700 }
1701 modalPageContext = nbgl_pageDrawGenericContentExt(&pageModalCallback, &info, &content, true);
1702
1703 if (forceFullRefresh) {
1705 }
1706 else {
1708 }
1709}
1710
1711// function used to display the content of a full value, when touching an alias of a tag/value pair
1712static void displayFullValuePage(const char *backText,
1713 const char *aliasText,
1714 const nbgl_contentValueExt_t *extension)
1715{
1716 const char *modalTitle
1717 = (extension->backText != NULL) ? PIC(extension->backText) : PIC(backText);
1718 if (extension->aliasType == INFO_LIST_ALIAS) {
1719 // such a list is rejected when starting the review (see isAliasDetailsValid()), but
1720 // nothing must be drawn from it anyway
1721 if ((extension->infolist == NULL) || (extension->infolist->nbInfos == 0)) {
1722 LOG_WARN(USE_CASE_LOGGER, "displayFullValuePage(): no info list to display\n");
1723 return;
1724 }
1725 genericContext.currentInfos = extension->infolist;
1726 displayInfosListModal(modalTitle, extension->infolist, true);
1727 }
1728 else if (extension->aliasType == TAG_VALUE_LIST_ALIAS) {
1729 genericContext.currentTagValues = extension->tagValuelist;
1730 displayTagValueListModal(extension->tagValuelist);
1731 }
1732 else {
1733 nbgl_layoutDescription_t layoutDescription = {.modal = true,
1734 .withLeftBorder = true,
1735 .onActionCallback = &modalLayoutTouchCallback,
1736 .tapActionText = NULL};
1737 nbgl_layoutHeader_t headerDesc = {.type = HEADER_BACK_AND_TEXT,
1738 .separationLine = false,
1739 .backAndText.token = 0,
1740 .backAndText.tuneId = TUNE_TAP_CASUAL,
1741 .backAndText.text = modalTitle};
1742 genericContext.modalLayout = nbgl_layoutGet(&layoutDescription);
1743 // add header with the tag part of the pair, to go back
1744 nbgl_layoutAddHeader(genericContext.modalLayout, &headerDesc);
1745 // add either QR Code or full value text
1746 if (extension->aliasType == QR_CODE_ALIAS) {
1747#ifdef NBGL_QRCODE
1748 nbgl_layoutQRCode_t qrCode
1749 = {.url = extension->fullValue,
1750 .text1 = (extension->title != NULL) ? extension->title : extension->fullValue,
1751 .text2 = extension->explanation,
1752 .centered = true,
1753 .offsetY = 0};
1754
1755 nbgl_layoutAddQRCode(genericContext.modalLayout, &qrCode);
1756#endif // NBGL_QRCODE
1757 }
1758 else {
1759 nbgl_layoutTextContent_t content = {0};
1760 content.title = aliasText;
1761 if (extension->aliasType == ENS_ALIAS) {
1762 content.info = "ENS names are resolved by Ledger backend.";
1763 }
1764 else if (extension->aliasType == ADDRESS_BOOK_ALIAS) {
1765 if (extension->aliasSubName != NULL) {
1766 content.descriptions[content.nbDescriptions] = extension->aliasSubName;
1767 content.nbDescriptions++;
1768 }
1769 }
1770 else {
1771 content.info = extension->explanation;
1772 }
1773 // add full value text
1774 content.descriptions[content.nbDescriptions] = extension->fullValue;
1775 content.nbDescriptions++;
1776 // add trusted name if present (combined Address Book+Trusted Name case)
1777 if ((extension->aliasType == ADDRESS_BOOK_ALIAS) && (extension->explanation != NULL)) {
1778 content.descriptions[content.nbDescriptions] = extension->explanation;
1779 content.nbDescriptions++;
1780 }
1781 nbgl_layoutAddTextContent(genericContext.modalLayout, &content);
1782 }
1783 // draw & refresh
1784 nbgl_layoutDraw(genericContext.modalLayout);
1785 nbgl_refresh();
1786 }
1787}
1788
1789// function used to display the modal containing tip-box infos
1790static void displayInfosListModal(const char *modalTitle,
1791 const nbgl_contentInfoList_t *infos,
1792 bool fromReview)
1793{
1794 nbgl_pageNavigationInfo_t info = {.activePage = 0,
1795 .nbPages = 1,
1796 .navType = NAV_WITH_BUTTONS,
1797 .quitToken = QUIT_TIPBOX_MODAL_TOKEN,
1798 .navWithButtons.navToken = NAV_TOKEN,
1799 .navWithButtons.quitButton = false,
1800 .navWithButtons.backButton = true,
1801 .navWithButtons.quitText = NULL,
1802 .progressIndicator = false,
1803 .tuneId = TUNE_TAP_CASUAL};
1804 nbgl_pageContent_t content
1805 = {.type = INFOS_LIST,
1806 .topRightIcon = NULL,
1807 .infosList.nbInfos = infos->nbInfos,
1808 .infosList.withExtensions = infos->withExtensions,
1809 .infosList.infoTypes = infos->infoTypes,
1810 .infosList.infoContents = infos->infoContents,
1811 .infosList.infoExtensions = infos->infoExtensions,
1812 .infosList.token = fromReview ? INFO_ALIAS_TOKEN : INFOS_TIP_BOX_TOKEN,
1813 .title = modalTitle,
1814 .titleToken = QUIT_TIPBOX_MODAL_TOKEN,
1815 .tuneId = TUNE_TAP_CASUAL};
1816
1817 if (modalPageContext != NULL) {
1818 nbgl_pageRelease(modalPageContext);
1819 }
1820 modalPageContext = nbgl_pageDrawGenericContentExt(&pageModalCallback, &info, &content, true);
1821
1823}
1824
1825// function used to display the modal containing alias tag-value pairs
1826static void displayTagValueListModalPage(uint8_t pageIdx, bool forceFullRefresh)
1827{
1828 nbgl_pageNavigationInfo_t info = {.activePage = pageIdx,
1829 .nbPages = detailsContext.nbPages,
1830 .navType = NAV_WITH_BUTTONS,
1831 .quitToken = QUIT_TOKEN,
1832 .navWithButtons.navToken = MODAL_NAV_TOKEN,
1833 .navWithButtons.quitButton = true,
1834 .navWithButtons.backButton = true,
1835 .navWithButtons.quitText = NULL,
1836 .progressIndicator = false,
1837 .tuneId = TUNE_TAP_CASUAL};
1838 nbgl_pageContent_t content = {.type = TAG_VALUE_LIST,
1839 .topRightIcon = NULL,
1840 .tagValueList.smallCaseForValue = true,
1841 .tagValueList.wrapping = detailsContext.wrapping};
1842 uint8_t nbElementsInPage;
1843 uint8_t firstPairIdx;
1844
1845 firstPairIdx
1846 = getTagValueListModalPage(genericContext.currentTagValues, pageIdx, &nbElementsInPage);
1847 detailsContext.currentPage = pageIdx;
1848
1849 content.tagValueList.nbPairs = nbElementsInPage;
1850 if (genericContext.currentTagValues->pairs != NULL) {
1851 content.tagValueList.pairs = &genericContext.currentTagValues->pairs[firstPairIdx];
1852 }
1853 else {
1854 // index of the pairs of the page is relative to the startIndex of the list
1855 content.tagValueList.callback = getModalTagValuePair;
1856 content.tagValueList.startIndex
1857 = genericContext.currentTagValues->startIndex + firstPairIdx;
1858 }
1859 if (nbElementsInPage == 1) {
1860 // a pair alone in its page may be too long to fit (see getNbTagValuesInDetailsPage()):
1861 // its value is then truncated to the lines fitting in the page, ending with "..."
1862 content.tagValueList.nbMaxLinesForValue = getNbLinesInDetailsPage(
1863 getTagValuePair(genericContext.currentTagValues, firstPairIdx));
1864 content.tagValueList.hideEndOfLastLine = true;
1865 }
1866 if (info.nbPages == 1) {
1867 // if only one page, no navigation bar, and use a footer instead
1868 info.navWithButtons.quitText = "Close";
1869 }
1870
1871 if (modalPageContext != NULL) {
1872 nbgl_pageRelease(modalPageContext);
1873 }
1874 modalPageContext = nbgl_pageDrawGenericContentExt(&pageModalCallback, &info, &content, true);
1875
1876 if (forceFullRefresh) {
1878 }
1879 else {
1881 }
1882}
1883
1884#ifdef NBGL_QRCODE
1885static void displayAddressQRCode(void)
1886{
1887 // display the address as QR Code
1888 nbgl_layoutDescription_t layoutDescription = {.modal = true,
1889 .withLeftBorder = true,
1890 .onActionCallback = &modalLayoutTouchCallback,
1891 .tapActionText = NULL};
1892 nbgl_layoutHeader_t headerDesc = {
1893 .type = HEADER_EMPTY, .separationLine = false, .emptySpace.height = SMALL_CENTERING_HEADER};
1894 nbgl_layoutQRCode_t qrCode = {.url = addressConfirmationContext.tagValuePairs[0].value,
1895 .text1 = NULL,
1896 .centered = true,
1897 .offsetY = 0};
1898
1899 addressConfirmationContext.modalLayout = nbgl_layoutGet(&layoutDescription);
1900 // add empty header for better look
1901 nbgl_layoutAddHeader(addressConfirmationContext.modalLayout, &headerDesc);
1902 // compute nb lines to check whether it shall be shorten (max is 3 lines)
1903 uint16_t nbLines = nbgl_getTextNbLinesInWidth(SMALL_REGULAR_FONT,
1904 addressConfirmationContext.tagValuePairs[0].value,
1906 false);
1907
1908 if (nbLines <= QRCODE_NB_MAX_LINES) {
1909 qrCode.text2 = addressConfirmationContext.tagValuePairs[0].value; // in gray
1910 }
1911 else {
1912 // only keep beginning and end of text, and add ... in the middle
1913 nbgl_textReduceOnNbLines(SMALL_REGULAR_FONT,
1914 addressConfirmationContext.tagValuePairs[0].value,
1916 QRCODE_NB_MAX_LINES,
1917 reducedAddress,
1918 QRCODE_REDUCED_ADDR_LEN);
1919 qrCode.text2 = reducedAddress; // in gray
1920 }
1921
1922 nbgl_layoutAddQRCode(addressConfirmationContext.modalLayout, &qrCode);
1923
1925 addressConfirmationContext.modalLayout, "Close", DISMISS_QR_TOKEN, TUNE_TAP_CASUAL);
1926 nbgl_layoutDraw(addressConfirmationContext.modalLayout);
1927 nbgl_refresh();
1928}
1929
1930#endif // NBGL_QRCODE
1931
1932// called when header is touched on modal page, to dismiss it
1933static void modalLayoutTouchCallback(int token, uint8_t index)
1934{
1935 UNUSED(index);
1936 if (token == DISMISS_QR_TOKEN) {
1937 // dismiss modal
1938 nbgl_layoutRelease(addressConfirmationContext.modalLayout);
1939 addressConfirmationContext.modalLayout = NULL;
1941 }
1942 else if (token == DISMISS_WARNING_TOKEN) {
1943 // dismiss modal
1944 nbgl_layoutRelease(reviewWithWarnCtx.modalLayout);
1945 // if already at first level, simply redraw the background
1946 if (reviewWithWarnCtx.securityReportLevel <= 1) {
1947 reviewWithWarnCtx.modalLayout = NULL;
1949 }
1950 else {
1951 // We are at level 2 of warning modal, so re-display the level 1
1952 reviewWithWarnCtx.securityReportLevel = 1;
1953 // if preset is used
1954 if (reviewWithWarnCtx.warning->predefinedSet) {
1955 displaySecurityReport(reviewWithWarnCtx.warning->predefinedSet);
1956 }
1957 else {
1958 // use customized warning
1959 const nbgl_warningDetails_t *details
1960 = (reviewWithWarnCtx.isIntro) ? reviewWithWarnCtx.warning->introDetails
1961 : reviewWithWarnCtx.warning->reviewDetails;
1962 displayCustomizedSecurityReport(details);
1963 }
1964 return;
1965 }
1966 }
1967 else if (token == DISMISS_DETAILS_TOKEN) {
1968 // dismiss modal
1969 nbgl_layoutRelease(choiceWithDetailsCtx.modalLayout);
1970 // if already at first level, simply redraw the background
1971 if (choiceWithDetailsCtx.level <= 1) {
1972 choiceWithDetailsCtx.modalLayout = NULL;
1974 }
1975 else {
1976 // We are at level 2 of details modal, so re-display the level 1
1977 choiceWithDetailsCtx.level = 1;
1978 choiceWithDetailsCtx.modalLayout
1979 = displayModalDetails(choiceWithDetailsCtx.details, DISMISS_DETAILS_TOKEN);
1980 }
1981 }
1982 else if ((token >= FIRST_WARN_BAR_TOKEN) && (token <= LAST_WARN_BAR_TOKEN)) {
1983 if (sharedContext.usage == SHARE_CTX_REVIEW_WITH_WARNING) {
1984 // dismiss modal before creating a new one
1985 nbgl_layoutRelease(reviewWithWarnCtx.modalLayout);
1986 reviewWithWarnCtx.securityReportLevel = 2;
1987 // if preset is used
1988 if (reviewWithWarnCtx.warning->predefinedSet) {
1989 displaySecurityReport(1 << (token - FIRST_WARN_BAR_TOKEN));
1990 }
1991 else {
1992 // use customized warning
1993 const nbgl_warningDetails_t *details
1994 = (reviewWithWarnCtx.isIntro) ? reviewWithWarnCtx.warning->introDetails
1995 : reviewWithWarnCtx.warning->reviewDetails;
1996 if (details->type == BAR_LIST_WARNING) {
1997 displayCustomizedSecurityReport(
1998 &details->barList.details[token - FIRST_WARN_BAR_TOKEN]);
1999 }
2000 }
2001 }
2002 else if ((sharedContext.usage == SHARE_CTX_CHOICE_WITH_DETAILS)
2003 && (choiceWithDetailsCtx.details->barList.details != NULL)) {
2004 const nbgl_warningDetails_t *details
2005 = &choiceWithDetailsCtx.details->barList.details[token - FIRST_WARN_BAR_TOKEN];
2006 if (details->type != NO_TYPE_WARNING) {
2007 // dismiss modal before creating a new one
2008 nbgl_layoutRelease(choiceWithDetailsCtx.modalLayout);
2009 choiceWithDetailsCtx.level = 2;
2010 choiceWithDetailsCtx.modalLayout
2011 = displayModalDetails(details, DISMISS_DETAILS_TOKEN);
2012 }
2013 }
2014 return;
2015 }
2016 else {
2017 // dismiss modal
2018 nbgl_layoutRelease(genericContext.modalLayout);
2019 genericContext.modalLayout = NULL;
2021 }
2022 nbgl_refresh();
2023}
2024
2025// called when item are touched in layout
2026static void layoutTouchCallback(int token, uint8_t index)
2027{
2028 // choice buttons in initial warning page
2029 if (token == WARNING_CHOICE_TOKEN) {
2030 if (index == 0) { // top button to exit
2031 reviewWithWarnCtx.choiceCallback(false);
2032 }
2033 else { // bottom button to continue to review
2034 reviewWithWarnCtx.isIntro = false;
2035 if (reviewWithWarnCtx.isStreaming) {
2036 useCaseReviewStreamingStart(reviewWithWarnCtx.operationType,
2037 reviewWithWarnCtx.icon,
2038 reviewWithWarnCtx.reviewTitle,
2039 reviewWithWarnCtx.reviewSubTitle,
2040 reviewWithWarnCtx.choiceCallback,
2041 false);
2042 }
2043 else {
2044 useCaseReview(reviewWithWarnCtx.operationType,
2045 reviewWithWarnCtx.tagValueList,
2046 reviewWithWarnCtx.icon,
2047 reviewWithWarnCtx.reviewTitle,
2048 reviewWithWarnCtx.reviewSubTitle,
2049 reviewWithWarnCtx.finishTitle,
2050 &activeTipBox,
2051 reviewWithWarnCtx.choiceCallback,
2052 false,
2053 false);
2054 }
2055 }
2056 }
2057 // top-right button in initial warning page
2058 else if (token == WARNING_BUTTON_TOKEN) {
2059 // start directly at first level of security report
2060 reviewWithWarnCtx.securityReportLevel = 1;
2061 // if preset is used
2062 if (reviewWithWarnCtx.warning->predefinedSet) {
2063 displaySecurityReport(reviewWithWarnCtx.warning->predefinedSet);
2064 }
2065 else {
2066 // use customized warning
2067 const nbgl_warningDetails_t *details = (reviewWithWarnCtx.isIntro)
2068 ? reviewWithWarnCtx.warning->introDetails
2069 : reviewWithWarnCtx.warning->reviewDetails;
2070 displayCustomizedSecurityReport(details);
2071 }
2072 }
2073 // top-right button in choice with details page
2074 else if (token == CHOICE_DETAILS_TOKEN) {
2075 choiceWithDetailsCtx.level = 1;
2076 choiceWithDetailsCtx.modalLayout
2077 = displayModalDetails(choiceWithDetailsCtx.details, DISMISS_DETAILS_TOKEN);
2078 }
2079 // main prelude page
2080 else if (token == PRELUDE_CHOICE_TOKEN) {
2081 if (index == 0) { // top button to display details about prelude
2082 displayCustomizedSecurityReport(reviewWithWarnCtx.warning->prelude->details);
2083 }
2084 else { // footer to continue to review
2085 if (HAS_INITIAL_WARNING(reviewWithWarnCtx.warning)) {
2086 displayInitialWarning();
2087 }
2088 else {
2089 reviewWithWarnCtx.isIntro = false;
2090 if (reviewWithWarnCtx.isStreaming) {
2091 useCaseReviewStreamingStart(reviewWithWarnCtx.operationType,
2092 reviewWithWarnCtx.icon,
2093 reviewWithWarnCtx.reviewTitle,
2094 reviewWithWarnCtx.reviewSubTitle,
2095 reviewWithWarnCtx.choiceCallback,
2096 false);
2097 }
2098 else {
2099 useCaseReview(reviewWithWarnCtx.operationType,
2100 reviewWithWarnCtx.tagValueList,
2101 reviewWithWarnCtx.icon,
2102 reviewWithWarnCtx.reviewTitle,
2103 reviewWithWarnCtx.reviewSubTitle,
2104 reviewWithWarnCtx.finishTitle,
2105 &activeTipBox,
2106 reviewWithWarnCtx.choiceCallback,
2107 false,
2108 false);
2109 }
2110 }
2111 }
2112 }
2113 // choice buttons
2114 else if (token == CHOICE_TOKEN) {
2115 if (onChoice != NULL) {
2116 onChoice((index == 0) ? true : false);
2117 }
2118 }
2119}
2120
2121// called when skip button is touched in footer, during forward only review
2122static void displaySkipWarning(void)
2123{
2125 .cancelText = "Go back to review",
2126 .centeredInfo.text1 = "Skip review?",
2127 .centeredInfo.text2
2128 = "If you're sure you don't need to review all fields, you can skip straight to signing.",
2129 .centeredInfo.text3 = NULL,
2130 .centeredInfo.style = LARGE_CASE_INFO,
2131 .centeredInfo.icon = &IMPORTANT_CIRCLE_ICON,
2132 .centeredInfo.offsetY = 0,
2133 .confirmationText = "Yes, skip",
2134 .confirmationToken = SKIP_TOKEN,
2135 .cancelToken = SKIP_TOKEN,
2136 .tuneId = TUNE_TAP_CASUAL,
2137 .modal = true};
2138 if (modalPageContext != NULL) {
2139 nbgl_pageRelease(modalPageContext);
2140 }
2141 modalPageContext = nbgl_pageDrawConfirmation(&pageModalCallback, &info);
2143}
2144
2145#ifdef NBGL_KEYPAD
2146// called to update the keypad and automatically show / hide:
2147// - backspace key if no digits are present
2148// - validation key if the min digit is reached
2149// - keypad if the max number of digit is reached
2150static void updateKeyPad(bool add)
2151{
2152 bool enableValidate, enableBackspace, enableDigits;
2153 bool redrawKeypad = false;
2155
2156 enableDigits = (keypadContext.pinLen < keypadContext.pinMaxDigits);
2157 enableValidate = (keypadContext.pinLen >= keypadContext.pinMinDigits);
2158 enableBackspace = (keypadContext.pinLen > 0);
2159 if (add) {
2160 if ((keypadContext.pinLen == keypadContext.pinMinDigits)
2161 || // activate "validate" button on keypad
2162 (keypadContext.pinLen == keypadContext.pinMaxDigits)
2163 || // deactivate "digits" on keypad
2164 (keypadContext.pinLen == 1)) { // activate "backspace"
2165 redrawKeypad = true;
2166 }
2167 }
2168 else { // remove
2169 if ((keypadContext.pinLen == 0) || // deactivate "backspace" button on keypad
2170 (keypadContext.pinLen == (keypadContext.pinMinDigits - 1))
2171 || // deactivate "validate" button on keypad
2172 (keypadContext.pinLen
2173 == (keypadContext.pinMaxDigits - 1))) { // reactivate "digits" on keypad
2174 redrawKeypad = true;
2175 }
2176 }
2177 if (keypadContext.hidden == true) {
2178 nbgl_layoutUpdateKeypadContent(keypadContext.layoutCtx, true, keypadContext.pinLen, NULL);
2179 }
2180 else {
2182 keypadContext.layoutCtx, false, 0, (const char *) keypadContext.pinEntry);
2183 }
2184 if (redrawKeypad) {
2186 keypadContext.layoutCtx, 0, enableValidate, enableBackspace, enableDigits);
2187 }
2188
2189 if ((!add) && (keypadContext.pinLen == 0)) {
2190 // Full refresh to fully clean the bullets when reaching 0 digits
2191 mode = FULL_COLOR_REFRESH;
2192 }
2194}
2195
2196// called when a key is touched on the keypad
2197static void keypadCallback(char touchedKey)
2198{
2199 switch (touchedKey) {
2200 case BACKSPACE_KEY:
2201 if (keypadContext.pinLen > 0) {
2202 keypadContext.pinLen--;
2203 keypadContext.pinEntry[keypadContext.pinLen] = 0;
2204 }
2205 updateKeyPad(false);
2206 break;
2207
2208 case VALIDATE_KEY:
2209 // Gray out keyboard / buttons as a first user feedback
2210 nbgl_layoutUpdateKeypad(keypadContext.layoutCtx, 0, false, false, true);
2213
2214 keypadContext.onValidatePin(keypadContext.pinEntry, keypadContext.pinLen);
2215 break;
2216
2217 default:
2218 if ((touchedKey >= 0x30) && (touchedKey < 0x40)) {
2219 if (keypadContext.pinLen < keypadContext.pinMaxDigits) {
2220 keypadContext.pinEntry[keypadContext.pinLen] = touchedKey;
2221 keypadContext.pinLen++;
2222 }
2223 updateKeyPad(true);
2224 }
2225 break;
2226 }
2227}
2228
2229static void keypadGeneric_cb(int token, uint8_t index)
2230{
2231 UNUSED(index);
2232 if (token != BACK_TOKEN) {
2233 return;
2234 }
2235 onQuit();
2236}
2237#endif
2238
2239#ifdef NBGL_KEYBOARD
2240// called when a key is touched on the keyboard
2241static void keyboardCallback(char touchedKey)
2242{
2243 uint32_t mask = 0;
2244 size_t textLen = strlen(keyboardContext.entryBuffer);
2245 if (touchedKey == BACKSPACE_KEY) {
2246 if (textLen == 0) {
2247 // No action
2248 return;
2249 }
2250 keyboardContext.entryBuffer[--textLen] = '\0';
2251 }
2252 else {
2253 if (textLen >= keyboardContext.entryMaxLen) {
2254 // entry length can't be greater, so we mask every characters
2255 mask = -1;
2256 }
2257 else {
2258 keyboardContext.entryBuffer[textLen] = touchedKey;
2259 keyboardContext.entryBuffer[++textLen] = '\0';
2260 }
2261 }
2262 if (keyboardContext.keyboardContent.type == KEYBOARD_WITH_SUGGESTIONS) {
2263 // if suggestions are displayed, we update them at each key press
2264 keyboardContext.getSuggestionButtons(&keyboardContext.keyboardContent, &mask);
2265 }
2266 if (textLen >= keyboardContext.entryMaxLen) {
2267 // entry length can't be greater, so whatever the suggestions, we mask every characters
2268 mask = -1;
2269 }
2270 nbgl_layoutUpdateKeyboardContent(keyboardContext.layoutCtx, &keyboardContext.keyboardContent);
2271 nbgl_layoutUpdateKeyboard(keyboardContext.layoutCtx,
2272 keyboardContext.keyboardIndex,
2273 mask,
2274 false,
2275 keyboardContext.casing);
2277}
2278
2279static void keyboardGeneric_cb(int token, uint8_t index)
2280{
2281 UNUSED(index);
2282 switch (token) {
2283 case BACK_TOKEN:
2284 onQuit();
2285 break;
2286 case KEYBOARD_CROSS_TOKEN:
2287 // Simulate a word of a single letter 'a' and trigger the backspace action
2288 keyboardContext.entryBuffer[0] = 'a';
2289 keyboardContext.entryBuffer[1] = '\0';
2290 keyboardCallback(BACKSPACE_KEY);
2291 break;
2292 case KEYBOARD_BUTTON_TOKEN:
2293 if (keyboardContext.keyboardContent.type == KEYBOARD_WITH_BUTTON) {
2294 onAction();
2295 }
2296 break;
2297 default:
2298 // only forward tokens matching a currently used suggestion button
2299 if ((keyboardContext.keyboardContent.type == KEYBOARD_WITH_SUGGESTIONS)
2300 && (token >= keyboardContext.keyboardContent.suggestionButtons.firstButtonToken)
2301 && (token < (keyboardContext.keyboardContent.suggestionButtons.firstButtonToken
2302 + keyboardContext.keyboardContent.suggestionButtons.nbUsedButtons))) {
2303 onControls(token, index);
2304 }
2305 break;
2306 }
2307}
2308#endif
2309
2320static uint16_t getTagValueHeight(const nbgl_contentTagValue_t *pair,
2321 nbgl_font_id_e valueFont,
2322 uint8_t listMaxLines,
2323 bool wrapping,
2324 uint16_t *nbLines)
2325{
2326 uint16_t height;
2327 uint8_t maxLines = layoutGetTagValueMaxLines(listMaxLines, pair, NULL);
2328
2329 // tag height (the tag is always wrapped), and space between tag and value
2330 height = nbgl_getTextHeightInWidth(SMALL_REGULAR_FONT, pair->item, AVAILABLE_WIDTH, true)
2332 // value height, in a width reduced if there is an icon on its right, possibly limited to
2333 // maxLines lines
2334 *nbLines = nbgl_getTextNbLinesInWidth(
2335 valueFont, pair->value, layoutGetTagValueWidth(layoutGetTagValueIcon(pair)), wrapping);
2336 if ((maxLines > 0) && (*nbLines > maxLines)) {
2337 *nbLines = maxLines;
2338 }
2339 height += *nbLines * nbgl_getFontLineHeight(valueFont);
2340 // potential alias sub-name, under the value
2341 if ((pair->aliasValue) && (pair->extension != NULL) && (pair->extension->aliasSubName)) {
2342 height += TAG_VALUE_INTERVALE + nbgl_getFontLineHeight(SMALL_REGULAR_FONT);
2343 }
2344 return height;
2345}
2346
2362static uint8_t getNbTagValuesInPage(uint8_t nbPairs,
2363 const nbgl_contentTagValueList_t *tagValueList,
2364 uint8_t startIndex,
2365 bool isSkippable,
2366 bool hasConfirmationButton,
2367 bool hasDetailsButton,
2368 bool *requireSpecificDisplay)
2369{
2370 uint8_t nbPairsInPage = 0;
2371 uint16_t currentHeight = PRE_TAG_VALUE_MARGIN; // upper margin
2372 uint16_t maxUsableHeight = TAG_VALUE_AREA_HEIGHT;
2373
2374 // if the review is skippable, it means that there is less height for tag/value pairs
2375 // the small centering header becomes a touchable header
2376 if (isSkippable) {
2377 maxUsableHeight -= TOUCHABLE_HEADER_BAR_HEIGHT - SMALL_CENTERING_HEADER;
2378 }
2379
2380 *requireSpecificDisplay = false;
2381 while (nbPairsInPage < nbPairs) {
2382 const nbgl_layoutTagValue_t *pair;
2383 nbgl_font_id_e value_font;
2384 uint16_t nbLines;
2385
2386 // margin between pairs
2387 // 12 or 24 px between each tag/value pair
2388 if (nbPairsInPage > 0) {
2389 currentHeight += INTER_TAG_VALUE_MARGIN;
2390 }
2391 // fetch tag/value pair strings.
2392 pair = getTagValuePair(tagValueList, startIndex + nbPairsInPage);
2393
2394 if (pair->forcePageStart && nbPairsInPage > 0) {
2395 // This pair must be at the top of a page
2396 break;
2397 }
2398
2399 if (pair->centeredInfo) {
2400 if (nbPairsInPage > 0) {
2401 // This pair must be at the top of a page
2402 break;
2403 }
2404 else {
2405 // This pair is the only one of the page and has a specific display behavior
2406 nbPairsInPage = 1;
2407 *requireSpecificDisplay = true;
2408 break;
2409 }
2410 }
2411
2412 // value font, as in nbgl_layoutAddTagValueList(), from the smallCaseForValue of the given
2413 // list (the use cases give it with the one used to draw the page, the public helpers with
2414 // the one of the application)
2415 value_font = layoutGetTagValueFont(tagValueList->smallCaseForValue);
2416 // honor list-level nbMaxLinesForValue: when set, the value will be
2417 // displayed truncated to that many lines, so account for its
2418 // truncated height rather than its full height.
2419 // Caveat: review TAG_VALUE_LIST/TAG_VALUE_DETAILS pages always render
2420 // up to NB_MAX_LINES_IN_REVIEW lines, because the display path forces
2421 // nbMaxLinesForValue back to NB_MAX_LINES_IN_REVIEW (see
2422 // genericContextPreparePageContent / displayReviewPage). So a list-level
2423 // value smaller than NB_MAX_LINES_IN_REVIEW must NOT shorten the height
2424 // estimate here, otherwise the page gets under-allocated and content is
2425 // drawn off-screen. Only honor a value that the display will actually
2426 // apply (i.e. >= NB_MAX_LINES_IN_REVIEW).
2427 uint8_t listMaxLines = tagValueList->nbMaxLinesForValue;
2428 if ((listMaxLines > 0) && (listMaxLines < NB_MAX_LINES_IN_REVIEW)) {
2429 listMaxLines = 0;
2430 }
2431 // tag/value height (the max number of lines of the pair itself is never overridden, so it
2432 // is combined with the list one exactly as nbgl_layoutAddTagValueList() does)
2433 currentHeight
2434 += getTagValueHeight(pair, value_font, listMaxLines, tagValueList->wrapping, &nbLines);
2435 if ((currentHeight >= maxUsableHeight) || (nbLines > NB_MAX_LINES_IN_REVIEW)) {
2436 if (nbPairsInPage == 0) {
2437 // Pair too long to fit in a single screen
2438 // It will be the only one of the page and has a specific display behavior
2439 nbPairsInPage = 1;
2440 *requireSpecificDisplay = true;
2441 }
2442 break;
2443 }
2444 nbPairsInPage++;
2445 }
2446 // if this is a TAG_VALUE_CONFIRM and we have reached the last pairs,
2447 // let's check if it still fits with a CONFIRMATION button, and if not,
2448 // remove the last pair (but never below 1, otherwise the pagination
2449 // loop in getNbPagesForContent would spin forever — the lone oversized
2450 // pair must still occupy this page and will be truncated at display time)
2451 if (hasConfirmationButton && (nbPairsInPage == nbPairs)) {
2452 maxUsableHeight -= UP_FOOTER_BUTTON_HEIGHT;
2453 if ((currentHeight > maxUsableHeight) && (nbPairsInPage > 1)) {
2454 nbPairsInPage--;
2455 }
2456 }
2457 // do the same with just a details button
2458 else if (hasDetailsButton) {
2459 maxUsableHeight -= (SMALL_BUTTON_RADIUS * 2);
2460 if ((currentHeight > maxUsableHeight) && (nbPairsInPage > 1)) {
2461 nbPairsInPage--;
2462 }
2463 }
2464 return nbPairsInPage;
2465}
2466
2477static uint8_t getNbTagValuesInDetailsPage(uint8_t nbPairs,
2478 const nbgl_contentTagValueList_t *tagValueList,
2479 uint8_t startIndex)
2480{
2481 uint8_t nbPairsInPage = 0;
2482 uint16_t currentHeight = PRE_TAG_VALUE_MARGIN; // upper margin
2483 uint16_t maxUsableHeight = TAG_VALUE_AREA_HEIGHT;
2484
2485 while (nbPairsInPage < nbPairs) {
2486 const nbgl_layoutTagValue_t *pair;
2487 uint16_t nbLines;
2488
2489 // margin between pairs
2490 // 12 or 24 px between each tag/value pair
2491 if (nbPairsInPage > 0) {
2492 currentHeight += INTER_TAG_VALUE_MARGIN;
2493 }
2494 // fetch tag/value pair strings.
2495 pair = getTagValuePair(tagValueList, startIndex + nbPairsInPage);
2496
2497 // tag/value height, with the parameters used by displayTagValueListModalPage() to draw it:
2498 // small case (so bold font) for values, wrapping of the details context, no list limit
2499 currentHeight
2500 += getTagValueHeight(pair, SMALL_BOLD_FONT, 0, detailsContext.wrapping, &nbLines);
2501
2502 // we have reached the maximum height, it means than there are to many pairs
2503 if (currentHeight >= maxUsableHeight) {
2504 if (nbPairsInPage == 0) {
2505 // Pair too long to fit in a single page: it is the only one of the page, otherwise
2506 // it would never be displayed (and the pages would all be empty). Its value is
2507 // truncated to fit (see getNbLinesInDetailsPage())
2508 nbPairsInPage = 1;
2509 }
2510 break;
2511 }
2512 nbPairsInPage++;
2513 }
2514 // never return 0, otherwise the modal pages would be empty: a lone pair too tall to fit in a
2515 // page must still occupy this page
2516 if ((nbPairsInPage == 0) && (nbPairs > 0)) {
2517 nbPairsInPage = 1;
2518 }
2519 return nbPairsInPage;
2520}
2521
2529static uint8_t getNbLinesInDetailsPage(const nbgl_contentTagValue_t *pair)
2530{
2531 const uint16_t lineHeight = nbgl_getFontLineHeight(SMALL_BOLD_FONT);
2532 uint16_t nbLines;
2533 // same height as in getNbTagValuesInDetailsPage()
2534 uint16_t height
2535 = PRE_TAG_VALUE_MARGIN
2536 + getTagValueHeight(pair, SMALL_BOLD_FONT, 0, detailsContext.wrapping, &nbLines);
2537
2538 if (height < TAG_VALUE_AREA_HEIGHT) {
2539 return 0;
2540 }
2541 // height of the pair without its value
2542 height -= nbLines * lineHeight;
2543 if ((height + lineHeight) >= TAG_VALUE_AREA_HEIGHT) {
2544 // tag too long to even display a line of value: display at least one line
2545 return 1;
2546 }
2547 return (TAG_VALUE_AREA_HEIGHT - 1 - height) / lineHeight;
2548}
2549
2550static uint8_t getNbPagesForContent(const nbgl_content_t *content,
2551 uint8_t pageIdxStart,
2552 bool isLast,
2553 bool isSkippable)
2554{
2555 uint8_t nbElements = 0;
2556 uint8_t nbPages = 0;
2557 uint8_t nbElementsInPage;
2558 uint8_t elemIdx = 0;
2559 bool flag;
2560
2561 nbElements = getContentNbElement(content);
2562
2563 // the pages of a TAG_VALUE_LIST are drawn with smallCaseForValue forced to false (see
2564 // genericContextPreparePageContent()), so its pairs must be measured the same way
2565 nbgl_contentTagValueList_t drawnList = {0};
2566 if (content->type == TAG_VALUE_LIST) {
2567 drawnList = content->content.tagValueList;
2568 drawnList.smallCaseForValue = false;
2569 }
2570
2571 while (nbElements > 0) {
2572 flag = 0;
2573 // if the current page is not the first one (or last), a navigation bar exists
2574 bool hasNav = !isLast || (pageIdxStart > 0) || (elemIdx > 0);
2575 if (content->type == TAG_VALUE_LIST) {
2576 nbElementsInPage = getNbTagValuesInPage(
2577 nbElements, &drawnList, elemIdx, isSkippable, false, false, &flag);
2578 }
2579 else if (content->type == TAG_VALUE_CONFIRM) {
2580 nbElementsInPage = getNbTagValuesInPage(nbElements,
2582 elemIdx,
2583 isSkippable,
2584 isLast,
2585 !isLast,
2586 &flag);
2587 }
2588 else if (content->type == INFOS_LIST) {
2589 nbElementsInPage
2590 = getNbInfosInPage(nbElements, &content->content.infosList, elemIdx, hasNav);
2591 }
2592 else if (content->type == SWITCHES_LIST) {
2593 nbElementsInPage
2594 = getNbSwitchesInPage(nbElements, &content->content.switchesList, elemIdx, hasNav);
2595 }
2596 else if (content->type == BARS_LIST) {
2597 nbElementsInPage
2598 = getNbBarsInPage(nbElements, &content->content.barsList, elemIdx, hasNav);
2599 }
2600 else if (content->type == CHOICES_LIST) {
2601 nbElementsInPage = nbgl_useCaseGetNbChoicesInPage(
2602 nbElements, &content->content.choicesList, elemIdx, hasNav);
2603 }
2604 else {
2605 nbElementsInPage = MIN(nbMaxElementsPerContentType[content->type], nbElements);
2606 }
2607 // every page must consume at least one element, otherwise this loop never ends
2608 if (nbElementsInPage == 0) {
2610 "getNbPagesForContent(): element %d doesn't fit in a page\n",
2611 elemIdx);
2612 nbElementsInPage = 1;
2613 }
2614
2615 elemIdx += nbElementsInPage;
2616 genericContextSetPageInfo(pageIdxStart + nbPages, nbElementsInPage, flag);
2617 nbElements -= nbElementsInPage;
2618 nbPages++;
2619 }
2620
2621 return nbPages;
2622}
2623
2624static uint8_t getNbPagesForGenericContents(const nbgl_genericContents_t *genericContents,
2625 uint8_t pageIdxStart,
2626 bool isSkippable)
2627{
2628 uint8_t nbPages = 0;
2629 nbgl_content_t content = {0};
2630 const nbgl_content_t *p_content;
2631
2632 for (int i = 0; i < genericContents->nbContents; i++) {
2633 p_content = getContentAtIdx(genericContents, i, &content);
2634 if (p_content == NULL) {
2635 return 0;
2636 }
2637 nbPages += getNbPagesForContent(p_content,
2638 pageIdxStart + nbPages,
2639 (i == (genericContents->nbContents - 1)),
2640 isSkippable);
2641 }
2642
2643 return nbPages;
2644}
2645
2646static void prepareAddressConfirmationPages(const char *address,
2647 const nbgl_contentTagValueList_t *tagValueList,
2648 nbgl_content_t *firstPageContent,
2649 nbgl_content_t *secondPageContent)
2650{
2651 nbgl_contentTagValueConfirm_t *tagValueConfirm;
2652 uint8_t nbAddressChunks;
2653
2654 // Split the address into one or more chunks, each occupying its own page.
2655 // Each chunk-pair points into `address` at the chunk's start offset; the
2656 // list-level nbMaxLinesForValue (set further down when nbAddressChunks > 1)
2657 // bounds the rendered slice to NB_MAX_LINES_IN_REVIEW lines, so successive
2658 // chunks visually pick up where the previous left off. forcePageStart on
2659 // all but the first chunk ensures each chunk starts a fresh page.
2660 // The address is never truncated: callers reject it beforehand (see isAddressReviewable())
2661 // if it needs more than ADDR_VERIF_NB_PAIRS chunks.
2662 nbAddressChunks = nbgl_getTextNbPagesInWidth(
2663 LARGE_MEDIUM_FONT, address, NB_MAX_LINES_IN_REVIEW, AVAILABLE_WIDTH);
2664 // Defensive bound (should never trigger thanks to isAddressReviewable())
2665 if (nbAddressChunks > ADDR_VERIF_NB_PAIRS) {
2666 nbAddressChunks = ADDR_VERIF_NB_PAIRS;
2667 }
2668 {
2669 const char *chunkStart = address;
2670 for (uint8_t i = 0; i < nbAddressChunks; i++) {
2671 addressConfirmationContext.tagValuePairs[i].item = "Address";
2672 addressConfirmationContext.tagValuePairs[i].value = chunkStart;
2673 addressConfirmationContext.tagValuePairs[i].forcePageStart = (i > 0);
2674 if (i + 1 < nbAddressChunks) {
2675 uint16_t len = 0;
2676 nbgl_getTextMaxLenInNbLines(LARGE_MEDIUM_FONT,
2677 chunkStart,
2680 &len,
2681 false);
2682 chunkStart += len;
2683 }
2684 }
2685 }
2686 addressConfirmationContext.nbPairs = nbAddressChunks;
2687
2688 // First page
2689 firstPageContent->type = TAG_VALUE_CONFIRM;
2690 tagValueConfirm = &firstPageContent->content.tagValueConfirm;
2691
2692#ifdef NBGL_QRCODE
2693 tagValueConfirm->detailsButtonIcon = &QRCODE_ICON;
2694 // only pack extras on the address page when the address itself fits on a
2695 // single page; for multi-chunk addresses, extras go to their own second page
2696 if ((tagValueList != NULL) && (nbAddressChunks == 1)
2697 && (tagValueList->nbPairs < ADDR_VERIF_NB_PAIRS)) {
2698 nbgl_contentTagValueList_t tmpList = {0};
2699 bool flag;
2700 // copy in intermediate structure
2701 for (uint8_t i = 0; i < tagValueList->nbPairs; i++) {
2702 memcpy(&addressConfirmationContext.tagValuePairs[1 + i],
2703 &tagValueList->pairs[i],
2704 sizeof(nbgl_contentTagValue_t));
2705 addressConfirmationContext.nbPairs++;
2706 }
2707 // check how many can fit in a page
2708 memcpy(&tmpList, tagValueList, sizeof(nbgl_contentTagValueList_t));
2709 tmpList.nbPairs = addressConfirmationContext.nbPairs;
2710 tmpList.pairs = addressConfirmationContext.tagValuePairs;
2711 // the page is drawn with smallCaseForValue set to false (see below)
2712 tmpList.smallCaseForValue = false;
2713 addressConfirmationContext.nbPairs = getNbTagValuesInPage(
2714 addressConfirmationContext.nbPairs, &tmpList, 0, false, true, true, &flag);
2715 // if they don't all fit, keep only the address
2716 if (tmpList.nbPairs > addressConfirmationContext.nbPairs) {
2717 addressConfirmationContext.nbPairs = 1;
2718 }
2719 }
2720 else {
2721 tagValueConfirm->detailsButtonText = NULL;
2722 }
2723 tagValueConfirm->detailsButtonToken = ADDRESS_QRCODE_BUTTON_TOKEN;
2724#else // NBGL_QRCODE
2725 tagValueConfirm->detailsButtonText = NULL;
2726 tagValueConfirm->detailsButtonIcon = NULL;
2727#endif // NBGL_QRCODE
2728 tagValueConfirm->tuneId = TUNE_TAP_CASUAL;
2729 tagValueConfirm->tagValueList.nbPairs = addressConfirmationContext.nbPairs;
2730 tagValueConfirm->tagValueList.pairs = addressConfirmationContext.tagValuePairs;
2731 tagValueConfirm->tagValueList.smallCaseForValue = false;
2732 // when the address spans multiple chunks, cap each pair's rendered value
2733 // at NB_MAX_LINES_IN_REVIEW lines so each chunk-pair occupies exactly one page
2734 tagValueConfirm->tagValueList.nbMaxLinesForValue
2735 = (nbAddressChunks > 1) ? NB_MAX_LINES_IN_REVIEW : 0;
2736 tagValueConfirm->tagValueList.hideEndOfLastLine = false;
2737 tagValueConfirm->tagValueList.wrapping = false;
2738
2739 // Number of extras left to place on a second page
2740 uint8_t extrasPlaced
2741 = (tagValueList != NULL) ? (addressConfirmationContext.nbPairs - nbAddressChunks) : 0;
2742 bool extrasNeedSecondPage = (tagValueList != NULL) && (tagValueList->nbPairs > extrasPlaced);
2743
2744 if (extrasNeedSecondPage) {
2745 tagValueConfirm->detailsButtonText = "Show as QR";
2746 tagValueConfirm->confirmationText = NULL;
2747 // the second page is dedicated to the extended tag/value pairs
2748 secondPageContent->type = TAG_VALUE_CONFIRM;
2749 tagValueConfirm = &secondPageContent->content.tagValueConfirm;
2750 tagValueConfirm->confirmationText = "Confirm";
2751 tagValueConfirm->confirmationToken = CONFIRM_TOKEN;
2752 tagValueConfirm->detailsButtonText = NULL;
2753 tagValueConfirm->detailsButtonIcon = NULL;
2754 tagValueConfirm->tuneId = TUNE_TAP_CASUAL;
2755 memcpy(&tagValueConfirm->tagValueList, tagValueList, sizeof(nbgl_contentTagValueList_t));
2756 tagValueConfirm->tagValueList.nbPairs = tagValueList->nbPairs - extrasPlaced;
2757 tagValueConfirm->tagValueList.pairs = &tagValueList->pairs[extrasPlaced];
2758 }
2759 else {
2760 // otherwise no tap to continue but a confirmation button
2761 tagValueConfirm->confirmationText = "Confirm";
2762 tagValueConfirm->confirmationToken = CONFIRM_TOKEN;
2763 }
2764}
2765
2766#ifndef NBGL_NO_HOME
2767static void bundleNavStartHome(void)
2768{
2769 nbgl_homeAndSettingsContext_t *context = &bundleNavContext.homeAndSettings;
2770
2771 useCaseHomeExt(context->appName,
2772 context->appIcon,
2773 context->tagline,
2774 context->settingContents != NULL ? true : false,
2775 &context->homeAction,
2776 bundleNavStartSettings,
2777 context->quitCallback);
2778 genericContext.type = USE_CASE_IDLE;
2779}
2780
2781static void bundleNavStartSettings(void)
2782{
2783 bundleNavStartSettingsAtPage(0);
2784}
2785#else // NBGL_NO_HOME
2786// No Home page: the app draws an empty page and waits for APDUs
2787static void bundleNavStartIdle(void)
2788{
2789 nbgl_layoutDescription_t layoutDescription = {0};
2790
2791 reset_callbacks_and_context();
2792 genericContext.type = USE_CASE_IDLE;
2793
2794 genericContext.backgroundLayout = nbgl_layoutGet(&layoutDescription);
2795 nbgl_layoutDraw(genericContext.backgroundLayout);
2797}
2798#endif // NBGL_NO_HOME
2799
2800static void bundleNavStartSettingsAtPage(uint8_t initSettingPage)
2801{
2802 nbgl_homeAndSettingsContext_t *context = &bundleNavContext.homeAndSettings;
2803
2804 nbgl_useCaseGenericSettings(context->appName,
2805 initSettingPage,
2806 context->settingContents,
2807 context->infosList,
2808#ifdef NBGL_NO_HOME
2809 bundleNavStartIdle);
2810#else // NBGL_NO_HOME
2811 bundleNavStartHome);
2812#endif // NBGL_NO_HOME
2813}
2814
2815static void bundleNavReviewConfirmRejection(void)
2816{
2817 bundleNavContext.review.choiceCallback(false);
2818}
2819
2820static void bundleNavReviewAskRejectionConfirmation(nbgl_operationType_t operationType,
2821 nbgl_callback_t callback)
2822{
2823 const char *title;
2824 const char *confirmText;
2825 // clear skip and blind bits
2826 operationType
2828 if (operationType == TYPE_TRANSACTION) {
2829 title = "Reject transaction?";
2830 confirmText = "Go back to transaction";
2831 }
2832 else if (operationType == TYPE_MESSAGE) {
2833 title = "Reject message?";
2834 confirmText = "Go back to message";
2835 }
2836 else {
2837 title = "Reject operation?";
2838 confirmText = "Go back to operation";
2839 }
2840
2841 // display a choice to confirm/cancel rejection
2842 nbgl_useCaseConfirm(title, NULL, "Yes, reject", confirmText, callback);
2843}
2844
2845static void bundleNavReviewChoice(bool confirm)
2846{
2847 if (confirm) {
2848 bundleNavContext.review.choiceCallback(true);
2849 }
2850 else {
2851 bundleNavReviewAskRejectionConfirmation(bundleNavContext.review.operationType,
2852 bundleNavReviewConfirmRejection);
2853 }
2854}
2855
2856static void bundleNavReviewStreamingConfirmRejection(void)
2857{
2858 bundleNavContext.reviewStreaming.choiceCallback(false);
2859}
2860
2861static void bundleNavReviewStreamingChoice(bool confirm)
2862{
2863 if (confirm) {
2864 bundleNavContext.reviewStreaming.choiceCallback(true);
2865 }
2866 else {
2867 bundleNavReviewAskRejectionConfirmation(bundleNavContext.reviewStreaming.operationType,
2868 bundleNavReviewStreamingConfirmRejection);
2869 }
2870}
2871
2872// function used to display the details in modal (from Choice with details or from Customized
2873// security report) it can be either a single page with text or QR code, or a list of touchable bars
2874// leading to single pages
2875static nbgl_layout_t *displayModalDetails(const nbgl_warningDetails_t *details, uint8_t token)
2876{
2877 nbgl_layoutDescription_t layoutDescription = {.modal = true,
2878 .withLeftBorder = true,
2879 .onActionCallback = modalLayoutTouchCallback,
2880 .tapActionText = NULL};
2881 nbgl_layoutHeader_t headerDesc = {.type = HEADER_BACK_AND_TEXT,
2882 .separationLine = true,
2883 .backAndText.icon = NULL,
2884 .backAndText.tuneId = TUNE_TAP_CASUAL,
2885 .backAndText.token = token};
2886 uint8_t i;
2887 nbgl_layout_t *layout;
2888
2889 layout = nbgl_layoutGet(&layoutDescription);
2890 headerDesc.backAndText.text = details->title;
2891 if (details->type == LEFT_CONTENT_WARNING) {
2892 headerDesc.separationLine = false;
2893 }
2894 nbgl_layoutAddHeader(layout, &headerDesc);
2895 if (details->type == BAR_LIST_WARNING) {
2896 // if more than one warning, so use a list of touchable bars
2897 for (i = 0; i < details->barList.nbBars; i++) {
2898 nbgl_layoutBar_t bar = {0};
2899 bar.text = details->barList.texts[i];
2900 bar.subText = details->barList.subTexts[i];
2901 // Only assign a right icon if the bar is clickable (i.e. has details to display)
2902 if ((details->barList.details)
2903 && (details->barList.details[i].type != NO_TYPE_WARNING)) {
2904 bar.iconRight = &PUSH_ICON;
2905 }
2906 // Left icon is optional, only set if provided by the warning details
2907 if (details->barList.icons != NULL) {
2908 bar.iconLeft = details->barList.icons[i];
2909 }
2910 bar.token = FIRST_WARN_BAR_TOKEN + i;
2911 bar.tuneId = TUNE_TAP_CASUAL;
2912 nbgl_layoutAddTouchableBar(layout, &bar);
2914 }
2915 }
2916 else if (details->type == QRCODE_WARNING) {
2917#ifdef NBGL_QRCODE
2918 // display a QR Code
2919 nbgl_layoutAddQRCode(layout, &details->qrCode);
2920#endif // NBGL_QRCODE
2921 headerDesc.backAndText.text = details->title;
2922 }
2923 else if (details->type == CENTERED_INFO_WARNING) {
2924 // display a centered info
2925 nbgl_layoutAddContentCenter(layout, &details->centeredInfo);
2926 headerDesc.separationLine = false;
2927 }
2928 else if (details->type == LEFT_CONTENT_WARNING) {
2929 nbgl_layoutAddLeftContent(layout, &details->leftContent);
2930 }
2931 nbgl_layoutDraw(layout);
2932 nbgl_refresh();
2933 return layout;
2934}
2935
2936// function used to display the security level page in modal
2937// it can be either a single page with text or QR code, or a list of touchable bars leading
2938// to single pages
2939static void displaySecurityReport(uint32_t set)
2940{
2941 nbgl_layoutDescription_t layoutDescription = {.modal = true,
2942 .withLeftBorder = true,
2943 .onActionCallback = modalLayoutTouchCallback,
2944 .tapActionText = NULL};
2945 nbgl_layoutHeader_t headerDesc = {.type = HEADER_BACK_AND_TEXT,
2946 .separationLine = true,
2947 .backAndText.icon = NULL,
2948 .backAndText.tuneId = TUNE_TAP_CASUAL,
2949 .backAndText.token = DISMISS_WARNING_TOKEN};
2950 nbgl_layoutFooter_t footerDesc
2951 = {.type = FOOTER_EMPTY, .separationLine = false, .emptySpace.height = 0};
2952 uint8_t i;
2953 const char *provider;
2954
2955 reviewWithWarnCtx.modalLayout = nbgl_layoutGet(&layoutDescription);
2956
2957 // display a list of touchable bars in some conditions:
2958 // - we must be in the first level of security report
2959 // - and be in the review itself (not from the intro/warning screen)
2960 //
2961 if ((reviewWithWarnCtx.securityReportLevel == 1) && (!reviewWithWarnCtx.isIntro)) {
2962 for (i = 0; i < NB_WARNING_TYPES; i++) {
2963 // Skip GATED_SIGNING_WARN from security report bars
2964 if ((i != GATED_SIGNING_WARN)
2965 && (reviewWithWarnCtx.warning->predefinedSet & (1 << i))) {
2966 nbgl_layoutBar_t bar = {0};
2967 if ((i == BLIND_SIGNING_WARN) || (i == W3C_NO_THREAT_WARN) || (i == W3C_ISSUE_WARN)
2968 || (reviewWithWarnCtx.warning->providerMessage == NULL)) {
2969 bar.subText = securityReportItems[i].subText;
2970 }
2971 else {
2972 bar.subText = reviewWithWarnCtx.warning->providerMessage;
2973 }
2974 bar.text = securityReportItems[i].text;
2975 if (i != W3C_NO_THREAT_WARN) {
2976 bar.iconRight = &PUSH_ICON;
2977 bar.token = FIRST_WARN_BAR_TOKEN + i;
2978 bar.tuneId = TUNE_TAP_CASUAL;
2979 }
2980 else {
2982 }
2983 bar.iconLeft = securityReportItems[i].icon;
2984 nbgl_layoutAddTouchableBar(reviewWithWarnCtx.modalLayout, &bar);
2985 nbgl_layoutAddSeparationLine(reviewWithWarnCtx.modalLayout);
2986 }
2987 }
2988 headerDesc.backAndText.text = "Security report";
2989 nbgl_layoutAddHeader(reviewWithWarnCtx.modalLayout, &headerDesc);
2990 nbgl_layoutDraw(reviewWithWarnCtx.modalLayout);
2991 nbgl_refresh();
2992 return;
2993 }
2994 if (reviewWithWarnCtx.warning && reviewWithWarnCtx.warning->reportProvider) {
2995 provider = reviewWithWarnCtx.warning->reportProvider;
2996 }
2997 else {
2998 provider = "[unknown]";
2999 }
3000 if ((set & (1 << W3C_THREAT_DETECTED_WARN)) || (set & (1 << W3C_RISK_DETECTED_WARN))) {
3001 // use the second half of tmpString for strings (the first half may be used by the
3002 // underlying warning page)
3003 const size_t destSize = W3C_DESCRIPTION_MAX_LEN / 2;
3004 char *destStr = tmpString + destSize;
3005 // remaining size in destStr
3006 size_t destLen = destSize;
3007 int len;
3008#ifdef NBGL_QRCODE
3009 const char *reportUrl = reviewWithWarnCtx.warning->reportUrl;
3010 // add "https://" as prefix of the given URL, and only display the QR Code if the whole
3011 // URL fits, to never encode a truncated URL
3012 len = (reportUrl != NULL) ? snprintf(destStr, destLen, "https://%s", reportUrl) : -1;
3013 if ((len >= 0) && ((size_t) len < destLen)) {
3014 nbgl_layoutQRCode_t qrCode = {.url = destStr,
3015 .text1 = reportUrl,
3016 .text2 = "Scan to view full report",
3017 .centered = true,
3018 .offsetY = 0};
3019 nbgl_layoutAddQRCode(reviewWithWarnCtx.modalLayout, &qrCode);
3020 footerDesc.emptySpace.height = 24;
3021 // use the next part of destStr for back bar text
3022 destStr += len + 1;
3023 destLen -= len + 1;
3024 }
3025 else if (reportUrl != NULL) {
3026 // URL too long to be encoded, only display it as text
3027 nbgl_contentCenter_t info = {0};
3028 info.smallTitle = "View full report at:";
3029 info.description = reportUrl;
3030 nbgl_layoutAddContentCenter(reviewWithWarnCtx.modalLayout, &info);
3031 footerDesc.emptySpace.height = SMALL_CENTERING_HEADER;
3032 }
3033#endif // NBGL_QRCODE
3034 // use a default back bar text if the given provider doesn't fit
3035 len = (destLen > 0) ? snprintf(destStr, destLen, "%s report", provider) : -1;
3036 if ((len >= 0) && ((size_t) len < destLen)) {
3037 headerDesc.backAndText.text = destStr;
3038 }
3039 else {
3040 headerDesc.backAndText.text = "Security report";
3041 }
3042 }
3043 else if (set & (1 << BLIND_SIGNING_WARN)) {
3044 // display a centered if in review
3045 nbgl_contentCenter_t info = {0};
3046 info.icon = &LARGE_WARNING_ICON;
3047 info.title = "This transaction cannot be Clear Signed";
3048 info.description
3049 = "This transaction or message cannot be decoded fully. If you choose to sign, you "
3050 "could be authorizing malicious actions that can drain your wallet.\n\nLearn more: "
3051 "ledger.com/e8";
3052 nbgl_layoutAddContentCenter(reviewWithWarnCtx.modalLayout, &info);
3053 footerDesc.emptySpace.height = SMALL_CENTERING_HEADER;
3054 headerDesc.separationLine = false;
3055 }
3056 else if (set & (1 << W3C_ISSUE_WARN)) {
3057 // if W3 Checks issue, display a centered info
3058 nbgl_contentCenter_t info = {0};
3059 info.icon = &LARGE_WARNING_ICON;
3060 info.title = "Transaction Check unavailable";
3061 info.description
3062 = "If you're not using the Ledger Wallet app, Transaction Check might not work. If "
3063 "you "
3064 "are using Ledger Wallet, reject the transaction and try again.\n\nGet help at "
3065 "ledger.com/e11";
3066 nbgl_layoutAddContentCenter(reviewWithWarnCtx.modalLayout, &info);
3067 footerDesc.emptySpace.height = SMALL_CENTERING_HEADER;
3068 headerDesc.separationLine = false;
3069 }
3070 nbgl_layoutAddHeader(reviewWithWarnCtx.modalLayout, &headerDesc);
3071 if (footerDesc.emptySpace.height > 0) {
3072 nbgl_layoutAddExtendedFooter(reviewWithWarnCtx.modalLayout, &footerDesc);
3073 }
3074 nbgl_layoutDraw(reviewWithWarnCtx.modalLayout);
3075 nbgl_refresh();
3076}
3077
3078// function used to display the security level page in modal
3079// it can be either a single page with text or QR code, or a list of touchable bars leading
3080// to single pages
3081static void displayCustomizedSecurityReport(const nbgl_warningDetails_t *details)
3082{
3083 reviewWithWarnCtx.modalLayout = displayModalDetails(details, DISMISS_WARNING_TOKEN);
3084}
3085
3086// function used to display the initial warning page when starting a "review with warning"
3087static void displayInitialWarning(void)
3088{
3089 // Play notification sound
3090#ifdef HAVE_PIEZO_SOUND
3091 tune_index_e tune = TUNE_RESERVED;
3092#endif // HAVE_PIEZO_SOUND
3093 // clang-format off
3094 nbgl_layoutDescription_t layoutDescription = {0};
3095 nbgl_layoutChoiceButtons_t buttonsInfo = {.bottomText = "Continue anyway",
3096 .token = WARNING_CHOICE_TOKEN,
3097 .topText = "Back to safety",
3098 .style = ROUNDED_AND_FOOTER_STYLE,
3099 .tuneId = TUNE_TAP_CASUAL};
3100 nbgl_layoutHeader_t headerDesc = {.type = HEADER_EMPTY,
3101 .emptySpace.height = MEDIUM_CENTERING_HEADER};
3102 uint32_t set = reviewWithWarnCtx.warning->predefinedSet & ~((1 << W3C_NO_THREAT_WARN) | (1 << W3C_ISSUE_WARN));
3103 // clang-format on
3104
3105 bool isBlindSigningOnly
3106 = (set != 0) && ((set & ~((1 << BLIND_SIGNING_WARN) | (1 << GATED_SIGNING_WARN))) == 0);
3107 reviewWithWarnCtx.isIntro = true;
3108
3109 layoutDescription.withLeftBorder = true;
3110 layoutDescription.onActionCallback = layoutTouchCallback;
3111 reviewWithWarnCtx.layoutCtx = nbgl_layoutGet(&layoutDescription);
3112
3113 nbgl_layoutAddHeader(reviewWithWarnCtx.layoutCtx, &headerDesc);
3114 if (reviewWithWarnCtx.warning->predefinedSet != 0) {
3115 // icon is different in casee of Blind Siging or Gated Signing
3116 nbgl_layoutAddTopRightButton(reviewWithWarnCtx.layoutCtx,
3117 isBlindSigningOnly ? &INFO_I_ICON : &QRCODE_ICON,
3118 WARNING_BUTTON_TOKEN,
3119 TUNE_TAP_CASUAL);
3120 }
3121 else if (reviewWithWarnCtx.warning->introTopRightIcon != NULL) {
3122 nbgl_layoutAddTopRightButton(reviewWithWarnCtx.layoutCtx,
3123 reviewWithWarnCtx.warning->introTopRightIcon,
3124 WARNING_BUTTON_TOKEN,
3125 TUNE_TAP_CASUAL);
3126 }
3127 // add main content
3128 // if predefined content is configured, use it preferably
3129 if (reviewWithWarnCtx.warning->predefinedSet != 0) {
3130 nbgl_contentCenter_t info = {0};
3131
3132 const char *provider;
3133
3134 // default icon
3135 info.icon = &LARGE_WARNING_ICON;
3136
3137 // use small title only if not Blind signing and not Gated signing
3138 if (isBlindSigningOnly == false) {
3139 if (reviewWithWarnCtx.warning->reportProvider) {
3140 provider = reviewWithWarnCtx.warning->reportProvider;
3141 }
3142 else {
3143 provider = "[unknown]";
3144 }
3145 info.smallTitle = tmpString;
3146 snprintf(tmpString, W3C_DESCRIPTION_MAX_LEN, "Detected by %s", provider);
3147 }
3148
3149 // If Blind Signing or Gated Signing
3150 if (isBlindSigningOnly) {
3151 info.title = "Blind signing ahead";
3152 if (set & (1 << GATED_SIGNING_WARN)) {
3153 info.description
3154 = "If you sign this transaction, you could lose your assets. "
3155 "Explore safer alternatives: ledger.com/integrated-apps";
3156 buttonsInfo.bottomText = "Accept risk and continue";
3157 }
3158 else {
3159 info.description
3160 = "This transaction's details are not fully verifiable. If you sign, you could "
3161 "lose all your assets.";
3162 buttonsInfo.bottomText = "Continue anyway";
3163 }
3164#ifdef HAVE_PIEZO_SOUND
3165 tune = TUNE_NEUTRAL;
3166#endif // HAVE_PIEZO_SOUND
3167 }
3168 else if (set & (1 << W3C_THREAT_DETECTED_WARN)) {
3169 info.title = "Critical threat";
3170 if (reviewWithWarnCtx.warning->providerMessage == NULL) {
3171 info.description = "Unidentified threat";
3172 }
3173 else {
3174 info.description = reviewWithWarnCtx.warning->providerMessage;
3175 }
3176 buttonsInfo.bottomText = "Accept threat and continue";
3177#ifdef HAVE_PIEZO_SOUND
3178 tune = TUNE_ERROR;
3179#endif // HAVE_PIEZO_SOUND
3180 }
3181 else if (set & (1 << W3C_RISK_DETECTED_WARN)) {
3182 info.title = "Potential risk";
3183 if (reviewWithWarnCtx.warning->providerMessage == NULL) {
3184 info.description = "Unidentified risk";
3185 }
3186 else {
3187 info.description = reviewWithWarnCtx.warning->providerMessage;
3188 }
3189 buttonsInfo.bottomText = "Accept risk and continue";
3190#ifdef HAVE_PIEZO_SOUND
3191 tune = TUNE_NEUTRAL;
3192#endif // HAVE_PIEZO_SOUND
3193 }
3194 nbgl_layoutAddContentCenter(reviewWithWarnCtx.layoutCtx, &info);
3195 }
3196 else if (reviewWithWarnCtx.warning->info != NULL) {
3197 // if no predefined content, use custom one
3198 nbgl_layoutAddContentCenter(reviewWithWarnCtx.layoutCtx, reviewWithWarnCtx.warning->info);
3199#ifdef HAVE_PIEZO_SOUND
3200 tune = TUNE_LOOK_AT_ME;
3201#endif // HAVE_PIEZO_SOUND
3202 }
3203 // add button and footer on bottom
3204 nbgl_layoutAddChoiceButtons(reviewWithWarnCtx.layoutCtx, &buttonsInfo);
3205
3206#ifdef HAVE_PIEZO_SOUND
3207 if (tune != TUNE_RESERVED) {
3208 os_io_seph_cmd_piezo_play_tune(tune);
3209 }
3210#endif // HAVE_PIEZO_SOUND
3211 nbgl_layoutDraw(reviewWithWarnCtx.layoutCtx);
3212 nbgl_refresh();
3213}
3214
3215// function used to display the prelude when starting a "review with warning"
3216static void displayPrelude(void)
3217{
3218 // clang-format off
3219 nbgl_layoutDescription_t layoutDescription = {0};
3220 nbgl_layoutChoiceButtons_t buttonsInfo
3221 = {.bottomText = reviewWithWarnCtx.warning->prelude->footerText,
3222 .token = PRELUDE_CHOICE_TOKEN,
3223 .topText = reviewWithWarnCtx.warning->prelude->buttonText,
3224 .style = ROUNDED_AND_FOOTER_STYLE,
3225 .tuneId = TUNE_TAP_CASUAL};
3226 nbgl_layoutHeader_t headerDesc = {.type = HEADER_EMPTY,
3227 .emptySpace.height = MEDIUM_CENTERING_HEADER};
3228 // clang-format on
3229
3230 reviewWithWarnCtx.isIntro = true;
3231
3232 layoutDescription.withLeftBorder = true;
3233 layoutDescription.onActionCallback = layoutTouchCallback;
3234 reviewWithWarnCtx.layoutCtx = nbgl_layoutGet(&layoutDescription);
3235
3236 nbgl_layoutAddHeader(reviewWithWarnCtx.layoutCtx, &headerDesc);
3237 // add centered content
3238 nbgl_contentCenter_t info = {0};
3239
3240 // default icon
3241 info.icon = reviewWithWarnCtx.warning->prelude->icon;
3242
3243 info.title = reviewWithWarnCtx.warning->prelude->title;
3244 info.description = reviewWithWarnCtx.warning->prelude->description;
3245 nbgl_layoutAddContentCenter(reviewWithWarnCtx.layoutCtx, &info);
3246
3247 // add button and footer on bottom
3248 nbgl_layoutAddChoiceButtons(reviewWithWarnCtx.layoutCtx, &buttonsInfo);
3249
3250#ifdef HAVE_PIEZO_SOUND
3251 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
3252#endif // HAVE_PIEZO_SOUND
3253 nbgl_layoutDraw(reviewWithWarnCtx.layoutCtx);
3254 nbgl_refresh();
3255}
3256
3257// function to factorize code for reviews tipbox
3258static void initWarningTipBox(const nbgl_tipBox_t *tipBox)
3259{
3260 const char *predefinedTipBoxText = NULL;
3261
3262 // if warning is valid and a warning requires a tip-box
3263 if (reviewWithWarnCtx.warning) {
3264 if (reviewWithWarnCtx.warning->predefinedSet & (1 << W3C_ISSUE_WARN)) {
3265 if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
3266 predefinedTipBoxText = "Transaction Check unavailable.\nBlind signing required.";
3267 }
3268 else {
3269 predefinedTipBoxText = "Transaction Check unavailable";
3270 }
3271 }
3272 else if (reviewWithWarnCtx.warning->predefinedSet & (1 << W3C_THREAT_DETECTED_WARN)) {
3273 if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
3274 predefinedTipBoxText = "Critical threat detected.\nBlind signing required.";
3275 }
3276 else {
3277 predefinedTipBoxText = "Critical threat detected.";
3278 }
3279 }
3280 else if (reviewWithWarnCtx.warning->predefinedSet & (1 << W3C_RISK_DETECTED_WARN)) {
3281 if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
3282 predefinedTipBoxText = "Potential risk detected.\nBlind signing required.";
3283 }
3284 else {
3285 predefinedTipBoxText = "Potential risk detected.";
3286 }
3287 }
3288 else if (reviewWithWarnCtx.warning->predefinedSet & (1 << W3C_NO_THREAT_WARN)) {
3289 if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
3290 predefinedTipBoxText
3291 = "No threat detected by Transaction Check but blind signing required.";
3292 }
3293 else {
3294 predefinedTipBoxText = "No threat detected by Transaction Check.";
3295 }
3296 }
3297 else if (reviewWithWarnCtx.warning->predefinedSet & (1 << BLIND_SIGNING_WARN)) {
3298 predefinedTipBoxText = "Blind signing required.";
3299 }
3300 }
3301
3302 if ((tipBox != NULL) || (predefinedTipBoxText != NULL)) {
3303 // do not display "Swipe to review" if a tip-box is displayed
3304 STARTING_CONTENT.content.extendedCenter.contentCenter.subText = NULL;
3305 if (predefinedTipBoxText != NULL) {
3306 genericContext.validWarningCtx = true;
3307 STARTING_CONTENT.content.extendedCenter.tipBox.icon = NULL;
3308 STARTING_CONTENT.content.extendedCenter.tipBox.text = predefinedTipBoxText;
3309 }
3310 else {
3311 STARTING_CONTENT.content.extendedCenter.tipBox.icon = tipBox->icon;
3312 STARTING_CONTENT.content.extendedCenter.tipBox.text = tipBox->text;
3313 }
3314 STARTING_CONTENT.content.extendedCenter.tipBox.token = TIP_BOX_TOKEN;
3315 STARTING_CONTENT.content.extendedCenter.tipBox.tuneId = TUNE_TAP_CASUAL;
3316 }
3317}
3318
3319// function to factorize code for all simple reviews
3320static void useCaseReview(nbgl_operationType_t operationType,
3321 const nbgl_contentTagValueList_t *tagValueList,
3322 const nbgl_icon_details_t *icon,
3323 const char *reviewTitle,
3324 const char *reviewSubTitle,
3325 const char *finishTitle,
3326 const nbgl_tipBox_t *tipBox,
3327 nbgl_choiceCallback_t choiceCallback,
3328 bool isLight,
3329 bool playNotifSound)
3330{
3331 // an empty list would give a page without content, preventing to reach the approval page
3332 if ((tagValueList == NULL) || (tagValueList->nbPairs == 0)
3333 || !isTagValueListValid(tagValueList)) {
3334 if (choiceCallback != NULL) {
3335 choiceCallback(false);
3336 }
3337 return;
3338 }
3339 bundleNavContext.review.operationType = operationType;
3340 bundleNavContext.review.choiceCallback = choiceCallback;
3341
3342 // memorize context
3343 onChoice = bundleNavReviewChoice;
3344 navType = GENERIC_NAV;
3345 pageTitle = NULL;
3346
3347 genericContext.genericContents.contentsList = localContentsList;
3348 genericContext.genericContents.nbContents = 3;
3349 memset(localContentsList, 0, 3 * sizeof(nbgl_content_t));
3350
3351 // First a centered info
3352 STARTING_CONTENT.type = EXTENDED_CENTER;
3353 prepareReviewFirstPage(
3354 &STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
3355
3356 // Prepare un tipbox if needed
3357 initWarningTipBox(tipBox);
3358
3359 // Then the tag/value pairs
3360 localContentsList[1].type = TAG_VALUE_LIST;
3361 memcpy(&localContentsList[1].content.tagValueList,
3362 tagValueList,
3364 localContentsList[1].contentActionCallback = tagValueList->actionCallback;
3365
3366 // The last page
3367 if (isLight) {
3368 localContentsList[2].type = INFO_BUTTON;
3369 prepareReviewLightLastPage(
3370 operationType, &localContentsList[2].content.infoButton, icon, finishTitle);
3371 }
3372 else {
3373 localContentsList[2].type = INFO_LONG_PRESS;
3374 prepareReviewLastPage(
3375 operationType, &localContentsList[2].content.infoLongPress, icon, finishTitle);
3376 }
3377
3378 // compute number of pages & fill navigation structure
3379 uint8_t nbPages = getNbPagesForGenericContents(
3380 &genericContext.genericContents, 0, (operationType & SKIPPABLE_OPERATION));
3381 prepareNavInfo(true, nbPages, getRejectReviewText(operationType));
3382
3383 // Play notification sound if required
3384 if (playNotifSound) {
3385#ifdef HAVE_PIEZO_SOUND
3386 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
3387#endif // HAVE_PIEZO_SOUND
3388 }
3389
3390 displayGenericContextPage(0, true);
3391}
3392
3393// function to factorize code for all streaming reviews
3394static void useCaseReviewStreamingStart(nbgl_operationType_t operationType,
3395 const nbgl_icon_details_t *icon,
3396 const char *reviewTitle,
3397 const char *reviewSubTitle,
3398 nbgl_choiceCallback_t choiceCallback,
3399 bool playNotifSound)
3400{
3401 bundleNavContext.reviewStreaming.operationType = operationType;
3402 bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
3403 bundleNavContext.reviewStreaming.icon = icon;
3404
3405 // memorize context
3406 onChoice = bundleNavReviewStreamingChoice;
3407 navType = STREAMING_NAV;
3408 pageTitle = NULL;
3409
3410 genericContext.genericContents.contentsList = localContentsList;
3411 genericContext.genericContents.nbContents = 1;
3412 memset(localContentsList, 0, 1 * sizeof(nbgl_content_t));
3413
3414 // First a centered info
3415 STARTING_CONTENT.type = EXTENDED_CENTER;
3416 prepareReviewFirstPage(
3417 &STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
3418
3419 // Prepare un tipbox if needed
3420 initWarningTipBox(NULL);
3421
3422 // compute number of pages & fill navigation structure
3423 bundleNavContext.reviewStreaming.stepPageNb = getNbPagesForGenericContents(
3424 &genericContext.genericContents, 0, (operationType & SKIPPABLE_OPERATION));
3425 prepareNavInfo(true, NBGL_NO_PROGRESS_INDICATOR, getRejectReviewText(operationType));
3426 // no back button on first page
3427 navInfo.navWithButtons.backButton = false;
3428
3429 // Play notification sound if required
3430 if (playNotifSound) {
3431#ifdef HAVE_PIEZO_SOUND
3432 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
3433#endif // HAVE_PIEZO_SOUND
3434 }
3435
3436 displayGenericContextPage(0, true);
3437}
3438
3455static void useCaseHomeExt(const char *appName,
3456 const nbgl_icon_details_t *appIcon,
3457 const char *tagline,
3458 bool withSettings,
3459 nbgl_homeAction_t *homeAction,
3460 nbgl_callback_t topRightCallback,
3461 nbgl_callback_t quitCallback)
3462{
3463 nbgl_pageInfoDescription_t info = {.centeredInfo.icon = appIcon,
3464 .centeredInfo.text1 = appName,
3465 .centeredInfo.text3 = NULL,
3466 .centeredInfo.style = LARGE_CASE_INFO,
3467 .centeredInfo.offsetY = 0,
3468 .footerText = NULL,
3469 .bottomButtonStyle = QUIT_APP_TEXT,
3470 .tapActionText = NULL,
3471 .topRightStyle = withSettings ? SETTINGS_ICON : INFO_ICON,
3472 .topRightToken = CONTINUE_TOKEN,
3473 .tuneId = TUNE_TAP_CASUAL};
3474 reset_callbacks_and_context();
3475
3476 if ((homeAction->text != NULL) || (homeAction->icon != NULL)) {
3477 // trick to use ACTION_BUTTON_TOKEN for action and quit, with index used to distinguish
3478 info.bottomButtonsToken = ACTION_BUTTON_TOKEN;
3479 onAction = homeAction->callback;
3480 info.actionButtonText = homeAction->text;
3481 info.actionButtonIcon = homeAction->icon;
3484 }
3485 else {
3486 info.bottomButtonsToken = QUIT_TOKEN;
3487 onAction = NULL;
3488 info.actionButtonText = NULL;
3489 info.actionButtonIcon = NULL;
3490 }
3491 if (tagline == NULL) {
3492 if (strlen(appName) > MAX_APP_NAME_FOR_SDK_TAGLINE) {
3493 snprintf(tmpString,
3495 "This app enables signing\ntransactions on its network.");
3496 }
3497 else {
3498 snprintf(tmpString,
3500 "%s %s\n%s",
3502 appName,
3504 }
3505
3506 // If there is more than 3 lines, it means the appName was split, so we put it on the next
3507 // line
3508 if (nbgl_getTextNbLinesInWidth(SMALL_REGULAR_FONT, tmpString, AVAILABLE_WIDTH, false) > 3) {
3509 snprintf(tmpString,
3511 "%s\n%s %s",
3513 appName,
3515 }
3516 info.centeredInfo.text2 = tmpString;
3517 }
3518 else {
3519 info.centeredInfo.text2 = tagline;
3520 }
3521
3522 onContinue = topRightCallback;
3523 onQuit = quitCallback;
3524
3525 pageContext = nbgl_pageDrawInfo(&pageCallback, NULL, &info);
3527}
3528
3537static void displayDetails(const char *tag, const char *value, bool wrapping)
3538{
3539 memset(&detailsContext, 0, sizeof(detailsContext));
3540
3541 // initialize context
3542 detailsContext.tag = tag;
3543 detailsContext.value = value;
3544 detailsContext.currentPage = 0;
3545 detailsContext.wrapping = wrapping;
3546 // count the pages with exactly the same split as the one used to display them
3547 detailsContext.nbPages = 1;
3548 uint16_t len;
3549 while (((len = getDetailsPageLen(value, NULL)) > 0) && (detailsContext.nbPages < UINT8_MAX)) {
3550 value += len;
3551 detailsContext.nbPages++;
3552 }
3553
3554 displayDetailsPage(0, true);
3555}
3556
3557// function used to display the modal containing alias tag-value pairs
3558static void displayTagValueListModal(const nbgl_contentTagValueList_t *tagValues)
3559{
3560 uint8_t nbElements = 0;
3561 uint8_t nbElementsInPage;
3562 uint8_t elemIdx = 0;
3563
3564 // such a list is rejected when starting the review (see isAliasDetailsValid()), but
3565 // nothing must be drawn from it anyway
3566 if ((tagValues == NULL) || (tagValues->nbPairs == 0)) {
3567 LOG_WARN(USE_CASE_LOGGER, "displayTagValueListModal(): no tag/value list to display\n");
3568 return;
3569 }
3570
3571 // initialize context
3572 memset(&detailsContext, 0, sizeof(detailsContext));
3573 nbElements = tagValues->nbPairs;
3574
3575 // count the pages, without any limit: as every page contains at least one pair (see
3576 // getNbTagValuesInDetailsPage()), there are at most nbPairs (<= 255) pages, so all pairs are
3577 // always reachable
3578 while (nbElements > 0) {
3579 nbElementsInPage = getNbTagValuesInDetailsPage(nbElements, tagValues, elemIdx);
3580
3581 elemIdx += nbElementsInPage;
3582 nbElements -= nbElementsInPage;
3583 detailsContext.nbPages++;
3584 }
3585
3586 displayTagValueListModalPage(0, true);
3587}
3588
3589// returns true if the given warning contains nothing to display, so that a simple review can be
3590// used. Every field leading to a warning page (info, prelude) or button must be checked
3591static bool isWarningEmpty(const nbgl_warning_t *warning)
3592{
3593 return (warning == NULL)
3594 || ((warning->predefinedSet == 0) && (warning->info == NULL)
3595 && (warning->introDetails == NULL) && (warning->reviewDetails == NULL)
3596 && (warning->prelude == NULL));
3597}
3598
3599// Gated signing is a stricter flavor of blind signing: it must go through the whole blind signing
3600// warning flow (initial warning page with explicit risk acceptance, security report, tip-box...).
3601// If the caller only set GATED_SIGNING_WARN, use a local copy with BLIND_SIGNING_WARN also set,
3602// so that no warning page or report entry is silently skipped.
3603static const nbgl_warning_t *normalizeWarning(const nbgl_warning_t *warning)
3604{
3605 if ((warning == NULL) || ((warning->predefinedSet & (1 << GATED_SIGNING_WARN)) == 0)
3606 || (warning->predefinedSet & (1 << BLIND_SIGNING_WARN))) {
3607 return warning;
3608 }
3609 memcpy(&normalizedWarning, warning, sizeof(normalizedWarning));
3610 normalizedWarning.predefinedSet |= (1 << BLIND_SIGNING_WARN);
3611 return &normalizedWarning;
3612}
3613
3614/**********************
3615 * GLOBAL FUNCTIONS
3616 **********************/
3617
3631uint8_t nbgl_useCaseGetNbTagValuesInPage(uint8_t nbPairs,
3632 const nbgl_contentTagValueList_t *tagValueList,
3633 uint8_t startIndex,
3634 bool *requireSpecificDisplay)
3635{
3636 return getNbTagValuesInPage(
3637 nbPairs, tagValueList, startIndex, false, false, false, requireSpecificDisplay);
3638}
3639
3649static uint8_t getNbInfosInPage(uint8_t nbInfos,
3650 const nbgl_contentInfoList_t *infosList,
3651 uint8_t startIndex,
3652 bool withNav)
3653{
3654 uint8_t nbInfosInPage = 0;
3655 uint16_t currentHeight = 0;
3656 uint16_t previousHeight = 0;
3657 uint16_t navHeight = withNav ? SIMPLE_FOOTER_HEIGHT : 0;
3658 const char *const *infoContents = PIC(infosList->infoContents);
3659
3660 while (nbInfosInPage < nbInfos) {
3661 // The type string must be a 1 liner and its height is LIST_ITEM_MIN_TEXT_HEIGHT
3662 currentHeight
3663 += LIST_ITEM_MIN_TEXT_HEIGHT + 2 * LIST_ITEM_PRE_HEADING + LIST_ITEM_HEADING_SUB_TEXT;
3664
3665 // content height
3666 currentHeight += nbgl_getTextHeightInWidth(SMALL_REGULAR_FONT,
3667 PIC(infoContents[startIndex + nbInfosInPage]),
3669 true);
3670 // if height is over the limit
3671 if (currentHeight >= (INFOS_AREA_HEIGHT - navHeight)) {
3672 // if there was no nav, now there will be, so it can be necessary to remove the last
3673 // item
3674 if (!withNav && (previousHeight >= (INFOS_AREA_HEIGHT - SIMPLE_FOOTER_HEIGHT))) {
3675 nbInfosInPage--;
3676 }
3677 break;
3678 }
3679 previousHeight = currentHeight;
3680 nbInfosInPage++;
3681 }
3682 // never return 0, otherwise the pagination loop in getNbPagesForContent would spin forever:
3683 // a lone info too tall to fit in a page must still occupy this page
3684 if ((nbInfosInPage == 0) && (nbInfos > 0)) {
3685 nbInfosInPage = 1;
3686 }
3687 return nbInfosInPage;
3688}
3689
3699static uint8_t getNbSwitchesInPage(uint8_t nbSwitches,
3700 const nbgl_contentSwitchesList_t *switchesList,
3701 uint8_t startIndex,
3702 bool withNav)
3703{
3704 uint8_t nbSwitchesInPage = 0;
3705 uint16_t currentHeight = 0;
3706 uint16_t previousHeight = 0;
3707 uint16_t navHeight = withNav ? SIMPLE_FOOTER_HEIGHT : 0;
3708 nbgl_contentSwitch_t *switchArray = (nbgl_contentSwitch_t *) PIC(switchesList->switches);
3709
3710 while (nbSwitchesInPage < nbSwitches) {
3711 nbgl_contentSwitch_t *curSwitch = &switchArray[startIndex + nbSwitchesInPage];
3712 // The text string is either a 1 liner and its height is LIST_ITEM_MIN_TEXT_HEIGHT
3713 // or we use its height directly
3714 uint16_t textHeight = MAX(
3715 LIST_ITEM_MIN_TEXT_HEIGHT,
3716 nbgl_getTextHeightInWidth(SMALL_BOLD_FONT, curSwitch->text, AVAILABLE_WIDTH, true));
3717 currentHeight += textHeight + 2 * LIST_ITEM_PRE_HEADING;
3718
3719 if (curSwitch->subText) {
3720 currentHeight += LIST_ITEM_HEADING_SUB_TEXT;
3721
3722 // sub-text height
3723 currentHeight += nbgl_getTextHeightInWidth(
3724 SMALL_REGULAR_FONT, curSwitch->subText, AVAILABLE_WIDTH, true);
3725 }
3726 // if height is over the limit
3727 if (currentHeight >= (INFOS_AREA_HEIGHT - navHeight)) {
3728 break;
3729 }
3730 previousHeight = currentHeight;
3731 nbSwitchesInPage++;
3732 }
3733 // if there was no nav, now there will be, so it can be necessary to remove the last
3734 // item
3735 if (!withNav && (previousHeight >= (INFOS_AREA_HEIGHT - SIMPLE_FOOTER_HEIGHT))) {
3736 nbSwitchesInPage--;
3737 }
3738 // never return 0, otherwise the pagination loop in getNbPagesForContent would spin forever:
3739 // a lone switch too tall to fit in a page must still occupy this page
3740 if ((nbSwitchesInPage == 0) && (nbSwitches > 0)) {
3741 nbSwitchesInPage = 1;
3742 }
3743 return nbSwitchesInPage;
3744}
3745
3755static uint8_t getNbBarsInPage(uint8_t nbBars,
3756 const nbgl_contentBarsList_t *barsList,
3757 uint8_t startIndex,
3758 bool withNav)
3759{
3760 uint8_t nbBarsInPage = 0;
3761 uint16_t currentHeight = 0;
3762 uint16_t previousHeight = 0;
3763 uint16_t navHeight = withNav ? SIMPLE_FOOTER_HEIGHT : 0;
3764
3765 UNUSED(barsList);
3766 UNUSED(startIndex);
3767
3768 while (nbBarsInPage < nbBars) {
3769 currentHeight += LIST_ITEM_MIN_TEXT_HEIGHT + 2 * LIST_ITEM_PRE_HEADING;
3770 // if height is over the limit
3771 if (currentHeight >= (INFOS_AREA_HEIGHT - navHeight)) {
3772 break;
3773 }
3774 previousHeight = currentHeight;
3775 nbBarsInPage++;
3776 }
3777 // if there was no nav, now there may will be, so it can be necessary to remove the last
3778 // item
3779 if (!withNav && (previousHeight >= (INFOS_AREA_HEIGHT - SIMPLE_FOOTER_HEIGHT))) {
3780 nbBarsInPage--;
3781 }
3782 return nbBarsInPage;
3783}
3784
3798uint8_t nbgl_useCaseGetNbChoicesInPage(uint8_t nbChoices,
3799 const nbgl_contentRadioChoice_t *choicesList,
3800 uint8_t startIndex,
3801 bool withNav)
3802{
3803 uint8_t nbChoicesInPage = 0;
3804 uint16_t currentHeight = 0;
3805 uint16_t previousHeight = 0;
3806 uint16_t navHeight = withNav ? SIMPLE_FOOTER_HEIGHT : 0;
3807
3808 UNUSED(choicesList);
3809 UNUSED(startIndex);
3810
3811 while (nbChoicesInPage < nbChoices) {
3812 currentHeight += LIST_ITEM_MIN_TEXT_HEIGHT + 2 * LIST_ITEM_PRE_HEADING;
3813 // if height is over the limit
3814 if (currentHeight >= (INFOS_AREA_HEIGHT - navHeight)) {
3815 // if there was no nav, now there will be, so it can be necessary to remove the last
3816 // item
3817 if (!withNav && (previousHeight >= (INFOS_AREA_HEIGHT - SIMPLE_FOOTER_HEIGHT))) {
3818 nbChoicesInPage--;
3819 }
3820 break;
3821 }
3822 previousHeight = currentHeight;
3823 nbChoicesInPage++;
3824 }
3825 return nbChoicesInPage;
3826}
3827
3832void nbgl_useCaseHome(const char *appName,
3833 const nbgl_icon_details_t *appIcon,
3834 const char *tagline,
3835 bool withSettings,
3836 nbgl_callback_t topRightCallback,
3837 nbgl_callback_t quitCallback)
3838{
3839 nbgl_homeAction_t homeAction = {0};
3840 useCaseHomeExt(
3841 appName, appIcon, tagline, withSettings, &homeAction, topRightCallback, quitCallback);
3842}
3843
3857void nbgl_useCaseNavigableContent(const char *title,
3858 uint8_t initPage,
3859 uint8_t nbPages,
3860 nbgl_callback_t quitCallback,
3861 nbgl_navCallback_t navCallback,
3862 nbgl_layoutTouchCallback_t controlsCallback)
3863{
3864 reset_callbacks_and_context();
3865
3866 // memorize context
3867 onQuit = quitCallback;
3868 onNav = navCallback;
3869 onControls = controlsCallback;
3870 pageTitle = title;
3871 navType = SETTINGS_NAV;
3872
3873 // fill navigation structure
3874 prepareNavInfo(false, nbPages, NULL);
3875
3876 displaySettingsPage(initPage, true);
3877}
3878
3884void nbgl_useCaseSettings(const char *title,
3885 uint8_t initPage,
3886 uint8_t nbPages,
3887 bool touchable,
3888 nbgl_callback_t quitCallback,
3889 nbgl_navCallback_t navCallback,
3890 nbgl_layoutTouchCallback_t controlsCallback)
3891{
3892 UNUSED(touchable);
3894 title, initPage, nbPages, quitCallback, navCallback, controlsCallback);
3895}
3896
3909void nbgl_useCaseGenericSettings(const char *appName,
3910 uint8_t initPage,
3911 const nbgl_genericContents_t *settingContents,
3912 const nbgl_contentInfoList_t *infosList,
3913 nbgl_callback_t quitCallback)
3914{
3915 reset_callbacks_and_context();
3916
3917 // memorize context
3918 onQuit = quitCallback;
3919 pageTitle = appName;
3920 navType = GENERIC_NAV;
3921
3922 if (settingContents != NULL) {
3923 memcpy(&genericContext.genericContents, settingContents, sizeof(nbgl_genericContents_t));
3924 }
3925 if (infosList != NULL) {
3926 genericContext.hasFinishingContent = true;
3927 memset(&FINISHING_CONTENT, 0, sizeof(nbgl_content_t));
3928 FINISHING_CONTENT.type = INFOS_LIST;
3929 memcpy(&FINISHING_CONTENT.content, infosList, sizeof(nbgl_content_u));
3930 }
3931
3932 // fill navigation structure
3933 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
3934 if (infosList != NULL) {
3935 nbPages += getNbPagesForContent(&FINISHING_CONTENT, nbPages, true, false);
3936 }
3937
3938 prepareNavInfo(false, nbPages, NULL);
3939
3940 displayGenericContextPage(initPage, true);
3941}
3942
3954void nbgl_useCaseGenericConfiguration(const char *title,
3955 uint8_t initPage,
3956 const nbgl_genericContents_t *contents,
3957 nbgl_callback_t quitCallback)
3958{
3959 nbgl_useCaseGenericSettings(title, initPage, contents, NULL, quitCallback);
3960}
3961
3984 const char *appName,
3985 const nbgl_icon_details_t *appIcon,
3986 const char *tagline,
3987 const uint8_t
3988 initSettingPage, // if not INIT_HOME_PAGE, start directly the corresponding setting page
3989 const nbgl_genericContents_t *settingContents,
3990 const nbgl_contentInfoList_t *infosList,
3991 const nbgl_homeAction_t *action, // Set to NULL if no additional action
3992 nbgl_callback_t quitCallback)
3993{
3994 nbgl_homeAndSettingsContext_t *context = &bundleNavContext.homeAndSettings;
3995
3996 reset_callbacks_and_context();
3997
3998 context->appName = appName;
3999 context->appIcon = appIcon;
4000 context->tagline = tagline;
4001 context->settingContents = settingContents;
4002 context->infosList = infosList;
4003 if (action != NULL) {
4004 memcpy(&context->homeAction, action, sizeof(nbgl_homeAction_t));
4005 }
4006 else {
4007 memset(&context->homeAction, 0, sizeof(nbgl_homeAction_t));
4008 }
4009 context->quitCallback = quitCallback;
4010
4011 if (initSettingPage != INIT_HOME_PAGE) {
4012 bundleNavStartSettingsAtPage(initSettingPage);
4013 }
4014 else {
4015#ifdef NBGL_NO_HOME
4016 // no Home page: the content is kept for the Info & Settings request
4017 bundleNavStartIdle();
4018#else // NBGL_NO_HOME
4019 bundleNavStartHome();
4020#endif // NBGL_NO_HOME
4021 }
4022}
4023
4034bool nbgl_useCaseShowInfoAndSettings(uint8_t initPage)
4035{
4036 if ((genericContext.type != USE_CASE_IDLE) || (modalPageContext != NULL)
4037 || (bundleNavContext.homeAndSettings.appName == NULL)
4038 || ((bundleNavContext.homeAndSettings.settingContents == NULL)
4039 && (bundleNavContext.homeAndSettings.infosList == NULL))) {
4040 return false;
4041 }
4042 bundleNavStartSettingsAtPage(initPage);
4043 return true;
4044}
4045
4053void nbgl_useCaseStatus(const char *message, bool isSuccess, nbgl_callback_t quitCallback)
4054{
4055 nbgl_screenTickerConfiguration_t ticker = {.tickerCallback = &tickerCallback,
4056 .tickerIntervale = 0, // not periodic
4057 .tickerValue = STATUS_SCREEN_DURATION};
4058 nbgl_pageInfoDescription_t info = {0};
4059
4060 reset_callbacks_and_context();
4061
4062 onQuit = quitCallback;
4063 if (isSuccess) {
4064#ifdef HAVE_PIEZO_SOUND
4065 os_io_seph_cmd_piezo_play_tune(TUNE_LEDGER_MOMENT);
4066#endif // HAVE_PIEZO_SOUND
4067 }
4068 info.centeredInfo.icon = isSuccess ? &CHECK_CIRCLE_ICON : &DENIED_CIRCLE_ICON;
4070 info.centeredInfo.text1 = message;
4071 info.tapActionText = "";
4072 info.tapActionToken = QUIT_TOKEN;
4073 info.tuneId = TUNE_TAP_CASUAL;
4074 pageContext = nbgl_pageDrawInfo(&pageCallback, &ticker, &info);
4076}
4077
4085 nbgl_callback_t quitCallback)
4086{
4087 const char *msg;
4088 bool isSuccess;
4089 switch (reviewStatusType) {
4091 msg = "Operation signed";
4092 isSuccess = true;
4093 break;
4095 msg = "Operation rejected";
4096 isSuccess = false;
4097 break;
4099 msg = "Transaction signed";
4100 isSuccess = true;
4101 break;
4103 msg = "Transaction rejected";
4104 isSuccess = false;
4105 break;
4107 msg = "Message signed";
4108 isSuccess = true;
4109 break;
4111 msg = "Message rejected";
4112 isSuccess = false;
4113 break;
4115 msg = "Address verified";
4116 isSuccess = true;
4117 break;
4119 msg = "Address verification\ncancelled";
4120 isSuccess = false;
4121 break;
4122 default:
4123 return;
4124 }
4125 nbgl_useCaseStatus(msg, isSuccess, quitCallback);
4126}
4127
4141 const char *message,
4142 const char *subMessage,
4143 const char *confirmText,
4144 const char *cancelText,
4145 nbgl_choiceCallback_t callback)
4146{
4148 // check params
4149 if ((confirmText == NULL) || (cancelText == NULL)) {
4150 LOG_WARN(USE_CASE_LOGGER, "nbgl_useCaseChoice(): confirmText or cancelText is NULL\n");
4151 return;
4152 }
4153 reset_callbacks_and_context();
4154
4155 info.cancelText = cancelText;
4156 info.centeredInfo.text1 = message;
4157 info.centeredInfo.text2 = subMessage;
4159 info.centeredInfo.icon = icon;
4160 info.confirmationText = confirmText;
4161 info.confirmationToken = CHOICE_TOKEN;
4162 info.cancelToken = CHOICE_TOKEN;
4163 info.tuneId = TUNE_TAP_CASUAL;
4164
4165 onChoice = callback;
4166 pageContext = nbgl_pageDrawConfirmation(&pageCallback, &info);
4168}
4169
4185 const char *message,
4186 const char *subMessage,
4187 const char *confirmText,
4188 const char *cancelText,
4189 nbgl_genericDetails_t *details,
4190 nbgl_choiceCallback_t callback)
4191{
4193 (details != NULL) ? &SEARCH_ICON : NULL,
4194 message,
4195 subMessage,
4196 NULL,
4197 confirmText,
4198 cancelText,
4199 details,
4200 callback);
4201}
4202
4226 const nbgl_icon_details_t *headerIcon,
4227 const char *title,
4228 const char *message,
4229 const char *subMessage,
4230 const char *confirmText,
4231 const char *cancelText,
4232 nbgl_warningDetails_t *details,
4233 nbgl_choiceCallback_t callback)
4234{
4235 // clang-format off
4236 nbgl_layoutDescription_t layoutDescription = {0};
4237 nbgl_layoutChoiceButtons_t buttonsInfo = {.bottomText = cancelText,
4238 .token = CHOICE_TOKEN,
4239 .topText = confirmText,
4240 .style = ROUNDED_AND_FOOTER_STYLE,
4241 .tuneId = TUNE_TAP_CASUAL};
4242 nbgl_contentCenter_t centeredInfo = {0};
4243 nbgl_layoutHeader_t headerDesc = {.type = HEADER_EMPTY,
4244 .emptySpace.height = MEDIUM_CENTERING_HEADER};
4245 // clang-format on
4246
4247 if ((confirmText == NULL) || (cancelText == NULL)) {
4249 "nbgl_useCaseAdvancedChoiceWithDetails(): confirmText or cancelText is NULL\n");
4250 return;
4251 }
4252
4253 reset_callbacks_and_context();
4254
4255#ifdef HAVE_PIEZO_SOUND
4256 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
4257#endif // HAVE_PIEZO_SOUND
4258
4259 onChoice = callback;
4260 layoutDescription.withLeftBorder = true;
4261 layoutDescription.onActionCallback = layoutTouchCallback;
4262 sharedContext.usage = SHARE_CTX_CHOICE_WITH_DETAILS;
4263 choiceWithDetailsCtx.layoutCtx = nbgl_layoutGet(&layoutDescription);
4264 choiceWithDetailsCtx.details = details;
4265
4266 nbgl_layoutAddHeader(choiceWithDetailsCtx.layoutCtx, &headerDesc);
4267 nbgl_layoutAddChoiceButtons(choiceWithDetailsCtx.layoutCtx, &buttonsInfo);
4268 centeredInfo.icon = centerIcon;
4269 centeredInfo.title = title;
4270 centeredInfo.description = message;
4271 centeredInfo.subText = subMessage;
4272 nbgl_layoutAddContentCenter(choiceWithDetailsCtx.layoutCtx, &centeredInfo);
4273
4274 if ((details != NULL) && (headerIcon != NULL)) {
4276 choiceWithDetailsCtx.layoutCtx, headerIcon, CHOICE_DETAILS_TOKEN, TUNE_TAP_CASUAL);
4277 }
4278
4279 nbgl_layoutDraw(choiceWithDetailsCtx.layoutCtx);
4281}
4282
4296void nbgl_useCaseConfirm(const char *message,
4297 const char *subMessage,
4298 const char *confirmText,
4299 const char *cancelText,
4300 nbgl_callback_t callback)
4301{
4302 // Don't reset callback or nav context as this is just a modal.
4303
4304 nbgl_pageConfirmationDescription_t info = {.cancelText = cancelText,
4305 .centeredInfo.text1 = message,
4306 .centeredInfo.text2 = subMessage,
4307 .centeredInfo.text3 = NULL,
4308 .centeredInfo.style = LARGE_CASE_INFO,
4309 .centeredInfo.icon = &IMPORTANT_CIRCLE_ICON,
4310 .centeredInfo.offsetY = 0,
4311 .confirmationText = confirmText,
4312 .confirmationToken = CHOICE_TOKEN,
4313 .cancelToken = CHOICE_TOKEN,
4314 .tuneId = TUNE_TAP_CASUAL,
4315 .modal = true};
4316 onModalConfirm = callback;
4317 if (modalPageContext != NULL) {
4318 nbgl_pageRelease(modalPageContext);
4319 }
4320 modalPageContext = nbgl_pageDrawConfirmation(&pageModalCallback, &info);
4322}
4323
4335 const char *message,
4336 const char *actionText,
4337 nbgl_callback_t callback)
4338{
4339 nbgl_pageContent_t content = {0};
4340
4341 reset_callbacks_and_context();
4342 // memorize callback
4343 onAction = callback;
4344
4345 content.tuneId = TUNE_TAP_CASUAL;
4346 content.type = INFO_BUTTON;
4347 content.infoButton.buttonText = actionText;
4348 content.infoButton.text = message;
4349 content.infoButton.icon = icon;
4350 content.infoButton.buttonToken = ACTION_BUTTON_TOKEN;
4351
4352 pageContext = nbgl_pageDrawGenericContent(&pageCallback, NULL, &content);
4354}
4355
4368 const char *reviewTitle,
4369 const char *reviewSubTitle,
4370 const char *rejectText,
4371 nbgl_callback_t continueCallback,
4372 nbgl_callback_t rejectCallback)
4373{
4374 nbgl_pageInfoDescription_t info = {.footerText = rejectText,
4375 .footerToken = QUIT_TOKEN,
4376 .tapActionText = NULL,
4377 .isSwipeable = true,
4378 .tapActionToken = CONTINUE_TOKEN,
4379 .topRightStyle = NO_BUTTON_STYLE,
4380 .actionButtonText = NULL,
4381 .tuneId = TUNE_TAP_CASUAL};
4382
4383 reset_callbacks_and_context();
4384
4385 info.centeredInfo.icon = icon;
4386 info.centeredInfo.text1 = reviewTitle;
4387 info.centeredInfo.text2 = reviewSubTitle;
4388 info.centeredInfo.text3 = "Swipe to review";
4390 info.centeredInfo.offsetY = 0;
4391 onQuit = rejectCallback;
4392 onContinue = continueCallback;
4393
4394#ifdef HAVE_PIEZO_SOUND
4395 // Play notification sound
4396 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
4397#endif // HAVE_PIEZO_SOUND
4398
4399 pageContext = nbgl_pageDrawInfo(&pageCallback, NULL, &info);
4400 nbgl_refresh();
4401}
4402
4416 const nbgl_pageInfoLongPress_t *infoLongPress,
4417 const char *rejectText,
4418 nbgl_choiceCallback_t callback)
4419{
4420 uint8_t offset = 0;
4421
4422 if (!isTagValueListValid(tagValueList)) {
4423 if (callback != NULL) {
4424 callback(false);
4425 }
4426 return;
4427 }
4428 reset_callbacks_and_context();
4429
4430 // memorize context
4431 onChoice = callback;
4432 navType = GENERIC_NAV;
4433 pageTitle = NULL;
4434 bundleNavContext.review.operationType = TYPE_OPERATION;
4435
4436 genericContext.genericContents.contentsList = localContentsList;
4437 memset(localContentsList, 0, 2 * sizeof(nbgl_content_t));
4438
4439 if (tagValueList != NULL && tagValueList->nbPairs != 0) {
4440 localContentsList[offset].type = TAG_VALUE_LIST;
4441 memcpy(&localContentsList[offset].content.tagValueList,
4442 tagValueList,
4444 offset++;
4445 }
4446
4447 localContentsList[offset].type = INFO_LONG_PRESS;
4448 memcpy(&localContentsList[offset].content.infoLongPress,
4449 infoLongPress,
4450 sizeof(nbgl_pageInfoLongPress_t));
4451 localContentsList[offset].content.infoLongPress.longPressToken = CONFIRM_TOKEN;
4452 offset++;
4453
4454 genericContext.genericContents.nbContents = offset;
4455
4456 // compute number of pages & fill navigation structure
4457 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
4458 UNUSED(rejectText);
4459 prepareNavInfo(true, nbPages, getRejectReviewText(TYPE_OPERATION));
4460
4461 displayGenericContextPage(0, true);
4462}
4463
4478 const nbgl_pageInfoLongPress_t *infoLongPress,
4479 const char *rejectText,
4480 nbgl_choiceCallback_t callback)
4481{
4482 uint8_t offset = 0;
4483
4484 if (!isTagValueListValid(tagValueList)) {
4485 if (callback != NULL) {
4486 callback(false);
4487 }
4488 return;
4489 }
4490 reset_callbacks_and_context();
4491
4492 // memorize context
4493 onChoice = callback;
4494 navType = GENERIC_NAV;
4495 pageTitle = NULL;
4496
4497 genericContext.genericContents.contentsList = localContentsList;
4498 memset(localContentsList, 0, 2 * sizeof(nbgl_content_t));
4499
4500 if (tagValueList != NULL && tagValueList->nbPairs != 0) {
4501 localContentsList[offset].type = TAG_VALUE_LIST;
4502 memcpy(&localContentsList[offset].content.tagValueList,
4503 tagValueList,
4505 offset++;
4506 }
4507
4508 localContentsList[offset].type = INFO_BUTTON;
4509 localContentsList[offset].content.infoButton.text = infoLongPress->text;
4510 localContentsList[offset].content.infoButton.icon = infoLongPress->icon;
4511 localContentsList[offset].content.infoButton.buttonText = infoLongPress->longPressText;
4512 localContentsList[offset].content.infoButton.buttonToken = CONFIRM_TOKEN;
4513 localContentsList[offset].content.infoButton.tuneId = TUNE_TAP_CASUAL;
4514 offset++;
4515
4516 genericContext.genericContents.nbContents = offset;
4517
4518 // compute number of pages & fill navigation structure
4519 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
4520 UNUSED(rejectText);
4521 prepareNavInfo(true, nbPages, getRejectReviewText(TYPE_OPERATION));
4522
4523 displayGenericContextPage(0, true);
4524}
4525
4542void nbgl_useCaseReview(nbgl_operationType_t operationType,
4543 const nbgl_contentTagValueList_t *tagValueList,
4544 const nbgl_icon_details_t *icon,
4545 const char *reviewTitle,
4546 const char *reviewSubTitle,
4547 const char *finishTitle,
4548 nbgl_choiceCallback_t choiceCallback)
4549{
4550 reset_callbacks_and_context();
4551
4552 useCaseReview(operationType,
4553 tagValueList,
4554 icon,
4555 reviewTitle,
4556 reviewSubTitle,
4557 finishTitle,
4558 NULL,
4559 choiceCallback,
4560 false,
4561 true);
4562}
4563
4584 const nbgl_contentTagValueList_t *tagValueList,
4585 const nbgl_icon_details_t *icon,
4586 const char *reviewTitle,
4587 const char *reviewSubTitle,
4588 const char *finishTitle,
4589 const nbgl_tipBox_t *tipBox,
4590 nbgl_choiceCallback_t choiceCallback)
4591{
4592 nbgl_useCaseAdvancedReview(operationType,
4593 tagValueList,
4594 icon,
4595 reviewTitle,
4596 reviewSubTitle,
4597 finishTitle,
4598 tipBox,
4599 &blindSigningWarning,
4600 choiceCallback);
4601}
4602
4626 const nbgl_contentTagValueList_t *tagValueList,
4627 const nbgl_icon_details_t *icon,
4628 const char *reviewTitle,
4629 const char *reviewSubTitle,
4630 const char *finishTitle,
4631 const nbgl_tipBox_t *tipBox,
4632 const nbgl_warning_t *warning,
4633 nbgl_choiceCallback_t choiceCallback)
4634{
4635 reset_callbacks_and_context();
4636
4637 // memorize tipBox because it can be in the call stack of the caller
4638 if (tipBox != NULL) {
4639 memcpy(&activeTipBox, tipBox, sizeof(activeTipBox));
4640 }
4641 // if no warning at all, it's a simple review
4642 if (isWarningEmpty(warning)) {
4643 useCaseReview(operationType,
4644 tagValueList,
4645 icon,
4646 reviewTitle,
4647 reviewSubTitle,
4648 finishTitle,
4649 tipBox,
4650 choiceCallback,
4651 false,
4652 true);
4653 return;
4654 }
4655 if (warning->predefinedSet == (1 << W3C_NO_THREAT_WARN)) {
4656 operationType |= NO_THREAT_OPERATION;
4657 }
4658 else if (warning->predefinedSet != 0) {
4659 operationType |= RISKY_OPERATION;
4660 }
4661 sharedContext.usage = SHARE_CTX_REVIEW_WITH_WARNING;
4662 reviewWithWarnCtx.isStreaming = false;
4663 reviewWithWarnCtx.operationType = operationType;
4664 reviewWithWarnCtx.tagValueList = tagValueList;
4665 reviewWithWarnCtx.icon = icon;
4666 reviewWithWarnCtx.reviewTitle = reviewTitle;
4667 reviewWithWarnCtx.reviewSubTitle = reviewSubTitle;
4668 reviewWithWarnCtx.finishTitle = finishTitle;
4669 reviewWithWarnCtx.warning = normalizeWarning(warning);
4670 reviewWithWarnCtx.choiceCallback = choiceCallback;
4671
4672 // if the warning contains a prelude, display it first
4673 if (reviewWithWarnCtx.warning->prelude) {
4674 displayPrelude();
4675 }
4676 // display the initial warning only of a risk/threat or blind signing or prelude
4677 else if (HAS_INITIAL_WARNING(reviewWithWarnCtx.warning)) {
4678 displayInitialWarning();
4679 }
4680 else {
4681 useCaseReview(operationType,
4682 tagValueList,
4683 icon,
4684 reviewTitle,
4685 reviewSubTitle,
4686 finishTitle,
4687 tipBox,
4688 choiceCallback,
4689 false,
4690 true);
4691 }
4692}
4693
4711 const nbgl_contentTagValueList_t *tagValueList,
4712 const nbgl_icon_details_t *icon,
4713 const char *reviewTitle,
4714 const char *reviewSubTitle,
4715 const char *finishTitle,
4716 nbgl_choiceCallback_t choiceCallback)
4717{
4718 reset_callbacks_and_context();
4719
4720 useCaseReview(operationType,
4721 tagValueList,
4722 icon,
4723 reviewTitle,
4724 reviewSubTitle,
4725 finishTitle,
4726 NULL,
4727 choiceCallback,
4728 true,
4729 true);
4730}
4731
4741 const char *rejectText,
4742 nbgl_callback_t rejectCallback)
4743{
4744 if (!isGenericContentsValid(contents)) {
4745 if (rejectCallback != NULL) {
4746 rejectCallback();
4747 }
4748 return;
4749 }
4750 reset_callbacks_and_context();
4751
4752 // memorize context
4753 onQuit = rejectCallback;
4754 navType = GENERIC_NAV;
4755 pageTitle = NULL;
4756 bundleNavContext.review.operationType = TYPE_OPERATION;
4757
4758 memcpy(&genericContext.genericContents, contents, sizeof(nbgl_genericContents_t));
4759
4760 // compute number of pages & fill navigation structure
4761 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
4762 prepareNavInfo(true, nbPages, rejectText);
4763 navInfo.quitToken = QUIT_TOKEN;
4764
4765#ifdef HAVE_PIEZO_SOUND
4766 // Play notification sound
4767 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
4768#endif // HAVE_PIEZO_SOUND
4769
4770 displayGenericContextPage(0, true);
4771}
4772
4786 const nbgl_icon_details_t *icon,
4787 const char *reviewTitle,
4788 const char *reviewSubTitle,
4789 nbgl_choiceCallback_t choiceCallback)
4790{
4791 reset_callbacks_and_context();
4792
4793 useCaseReviewStreamingStart(
4794 operationType, icon, reviewTitle, reviewSubTitle, choiceCallback, true);
4795}
4796
4811 const nbgl_icon_details_t *icon,
4812 const char *reviewTitle,
4813 const char *reviewSubTitle,
4814 nbgl_choiceCallback_t choiceCallback)
4815{
4817 operationType, icon, reviewTitle, reviewSubTitle, &blindSigningWarning, choiceCallback);
4818}
4819
4836 const nbgl_icon_details_t *icon,
4837 const char *reviewTitle,
4838 const char *reviewSubTitle,
4839 const nbgl_warning_t *warning,
4840 nbgl_choiceCallback_t choiceCallback)
4841{
4842 reset_callbacks_and_context();
4843
4844 // if no warning at all, it's a simple review
4845 if (isWarningEmpty(warning)) {
4846 useCaseReviewStreamingStart(
4847 operationType, icon, reviewTitle, reviewSubTitle, choiceCallback, true);
4848 return;
4849 }
4850 if (warning->predefinedSet == (1 << W3C_NO_THREAT_WARN)) {
4851 operationType |= NO_THREAT_OPERATION;
4852 }
4853 else if (warning->predefinedSet != 0) {
4854 operationType |= RISKY_OPERATION;
4855 }
4856
4857 sharedContext.usage = SHARE_CTX_REVIEW_WITH_WARNING;
4858 reviewWithWarnCtx.isStreaming = true;
4859 reviewWithWarnCtx.operationType = operationType;
4860 reviewWithWarnCtx.icon = icon;
4861 reviewWithWarnCtx.reviewTitle = reviewTitle;
4862 reviewWithWarnCtx.reviewSubTitle = reviewSubTitle;
4863 reviewWithWarnCtx.choiceCallback = choiceCallback;
4864 reviewWithWarnCtx.warning = normalizeWarning(warning);
4865
4866 // if the warning contains a prelude, display it first
4867 if (reviewWithWarnCtx.warning->prelude) {
4868 displayPrelude();
4869 }
4870 // display the initial warning only of a risk/threat or blind signing
4871 else if (HAS_INITIAL_WARNING(reviewWithWarnCtx.warning)) {
4872 displayInitialWarning();
4873 }
4874 else {
4875 useCaseReviewStreamingStart(
4876 operationType, icon, reviewTitle, reviewSubTitle, choiceCallback, true);
4877 }
4878}
4879
4894 nbgl_choiceCallback_t choiceCallback,
4895 nbgl_callback_t skipCallback)
4896{
4897 if ((tagValueList == NULL) || !isTagValueListValid(tagValueList)) {
4898 if (choiceCallback != NULL) {
4899 choiceCallback(false);
4900 }
4901 return;
4902 }
4903 // Should follow a call to nbgl_useCaseReviewStreamingStart
4904 // Keep the shared context set up by the streaming start.
4905 memset(&genericContext, 0, offsetof(GenericContext_t, sharedCtx));
4906
4907 bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
4908 bundleNavContext.reviewStreaming.skipCallback = skipCallback;
4909
4910 // memorize context
4911 onChoice = bundleNavReviewStreamingChoice;
4912 navType = STREAMING_NAV;
4913 pageTitle = NULL;
4914
4915 genericContext.genericContents.contentsList = localContentsList;
4916 genericContext.genericContents.nbContents = 1;
4917 memset(localContentsList, 0, 1 * sizeof(nbgl_content_t));
4918
4919 // Then the tag/value pairs
4920 STARTING_CONTENT.type = TAG_VALUE_LIST;
4921 memcpy(
4922 &STARTING_CONTENT.content.tagValueList, tagValueList, sizeof(nbgl_contentTagValueList_t));
4923
4924 // compute number of pages & fill navigation structure
4925 bundleNavContext.reviewStreaming.stepPageNb = getNbPagesForGenericContents(
4926 &genericContext.genericContents,
4927 0,
4928 (bundleNavContext.reviewStreaming.operationType & SKIPPABLE_OPERATION));
4929 prepareNavInfo(true,
4931 getRejectReviewText(bundleNavContext.reviewStreaming.operationType));
4932 // if the operation is skippable
4933 if (bundleNavContext.reviewStreaming.operationType & SKIPPABLE_OPERATION) {
4934 navInfo.progressIndicator = false;
4935 navInfo.skipText = "Skip";
4936 navInfo.skipToken = SKIP_TOKEN;
4937 }
4938
4939 displayGenericContextPage(0, true);
4940}
4941
4953 nbgl_choiceCallback_t choiceCallback)
4954{
4955 nbgl_useCaseReviewStreamingContinueExt(tagValueList, choiceCallback, NULL);
4956}
4957
4966void nbgl_useCaseReviewStreamingFinish(const char *finishTitle,
4967 nbgl_choiceCallback_t choiceCallback)
4968{
4969 // Should follow a call to nbgl_useCaseReviewStreamingContinue
4970 // Keep the shared context set up by the streaming start.
4971 memset(&genericContext, 0, offsetof(GenericContext_t, sharedCtx));
4972
4973 bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
4974
4975 // memorize context
4976 onChoice = bundleNavReviewStreamingChoice;
4977 navType = STREAMING_NAV;
4978 pageTitle = NULL;
4979
4980 genericContext.genericContents.contentsList = localContentsList;
4981 genericContext.genericContents.nbContents = 1;
4982 memset(localContentsList, 0, 1 * sizeof(nbgl_content_t));
4983
4984 // Eventually the long press page
4985 STARTING_CONTENT.type = INFO_LONG_PRESS;
4986 prepareReviewLastPage(bundleNavContext.reviewStreaming.operationType,
4987 &STARTING_CONTENT.content.infoLongPress,
4988 bundleNavContext.reviewStreaming.icon,
4989 finishTitle);
4990
4991 // compute number of pages & fill navigation structure
4992 bundleNavContext.reviewStreaming.stepPageNb = getNbPagesForGenericContents(
4993 &genericContext.genericContents,
4994 0,
4995 (bundleNavContext.reviewStreaming.operationType & SKIPPABLE_OPERATION));
4996 prepareNavInfo(true, 1, getRejectReviewText(bundleNavContext.reviewStreaming.operationType));
4997
4998 displayGenericContextPage(0, true);
4999}
5000
5005void nbgl_useCaseAddressConfirmationExt(const char *address,
5006 nbgl_choiceCallback_t callback,
5007 const nbgl_contentTagValueList_t *tagValueList)
5008{
5009 if (!isAddressReviewable(address) || !isTagValueListValid(tagValueList)) {
5010 if (callback != NULL) {
5011 callback(false);
5012 }
5013 return;
5014 }
5015 reset_callbacks_and_context();
5016 memset(&addressConfirmationContext, 0, sizeof(addressConfirmationContext));
5017
5018 // save context
5019 onChoice = callback;
5020 navType = GENERIC_NAV;
5021 pageTitle = NULL;
5022
5023 genericContext.genericContents.contentsList = localContentsList;
5024 genericContext.genericContents.nbContents = (tagValueList == NULL) ? 1 : 2;
5025 memset(localContentsList, 0, 2 * sizeof(nbgl_content_t));
5026 prepareAddressConfirmationPages(
5027 address, tagValueList, &STARTING_CONTENT, &localContentsList[1]);
5028
5029 // fill navigation structure, common to all pages
5030 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
5031
5032 prepareNavInfo(true, nbPages, "Cancel");
5033
5034#ifdef HAVE_PIEZO_SOUND
5035 // Play notification sound
5036 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
5037#endif // HAVE_PIEZO_SOUND
5038
5039 displayGenericContextPage(0, true);
5040}
5041
5058void nbgl_useCaseAddressReview(const char *address,
5059 const nbgl_contentTagValueList_t *additionalTagValueList,
5060 const nbgl_icon_details_t *icon,
5061 const char *reviewTitle,
5062 const char *reviewSubTitle,
5063 nbgl_choiceCallback_t choiceCallback)
5064{
5065 if (!isAddressReviewable(address) || !isTagValueListValid(additionalTagValueList)) {
5066 if (choiceCallback != NULL) {
5067 choiceCallback(false);
5068 }
5069 return;
5070 }
5071 reset_callbacks_and_context();
5072
5073 // release a potential modal
5074 if (addressConfirmationContext.modalLayout) {
5075 nbgl_layoutRelease(addressConfirmationContext.modalLayout);
5076 }
5077 memset(&addressConfirmationContext, 0, sizeof(addressConfirmationContext));
5078
5079 // save context
5080 onChoice = choiceCallback;
5081 navType = GENERIC_NAV;
5082 pageTitle = NULL;
5083 bundleNavContext.review.operationType = TYPE_OPERATION;
5084
5085 genericContext.genericContents.contentsList = localContentsList;
5086 memset(localContentsList, 0, 3 * sizeof(nbgl_content_t));
5087
5088 // First a centered info
5089 STARTING_CONTENT.type = EXTENDED_CENTER;
5090 prepareReviewFirstPage(
5091 &STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
5092 STARTING_CONTENT.content.extendedCenter.contentCenter.subText = "Swipe to continue";
5093
5094 // Then the address confirmation pages
5095 prepareAddressConfirmationPages(
5096 address, additionalTagValueList, &localContentsList[1], &localContentsList[2]);
5097
5098 // fill navigation structure, common to all pages
5099 genericContext.genericContents.nbContents
5100 = (localContentsList[2].type == TAG_VALUE_CONFIRM) ? 3 : 2;
5101 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
5102
5103 prepareNavInfo(true, nbPages, "Cancel");
5104
5105#ifdef HAVE_PIEZO_SOUND
5106 // Play notification sound
5107 os_io_seph_cmd_piezo_play_tune(TUNE_LOOK_AT_ME);
5108#endif // HAVE_PIEZO_SOUND
5109
5110 displayGenericContextPage(0, true);
5111}
5112
5121void nbgl_useCaseSpinner(const char *text)
5122{
5123 // if the previous Use Case was not Spinner, fresh start
5124 if (genericContext.type != USE_CASE_SPINNER) {
5125 memset(&genericContext, 0, sizeof(genericContext));
5126 genericContext.type = USE_CASE_SPINNER;
5127 nbgl_layoutDescription_t layoutDescription = {0};
5128
5129 layoutDescription.withLeftBorder = true;
5130
5131 genericContext.backgroundLayout = nbgl_layoutGet(&layoutDescription);
5132
5134 genericContext.backgroundLayout, text, NULL, genericContext.spinnerPosition);
5135
5136 nbgl_layoutDraw(genericContext.backgroundLayout);
5138 }
5139 else {
5140 // otherwise increment spinner
5141 genericContext.spinnerPosition++;
5142 // there are only NB_SPINNER_POSITIONSpositions
5143 if (genericContext.spinnerPosition == NB_SPINNER_POSITIONS) {
5144 genericContext.spinnerPosition = 0;
5145 }
5146 int ret = nbgl_layoutUpdateSpinner(
5147 genericContext.backgroundLayout, text, NULL, genericContext.spinnerPosition);
5148 if (ret == 1) {
5150 }
5151 else if (ret == 2) {
5153 }
5154 }
5155}
5156
5157#ifdef NBGL_KEYPAD
5176void nbgl_useCaseKeypad(const char *title,
5177 uint8_t minDigits,
5178 uint8_t maxDigits,
5179 bool shuffled,
5180 bool hidden,
5181 nbgl_pinValidCallback_t validatePinCallback,
5182 nbgl_callback_t backCallback)
5183{
5184 nbgl_layoutDescription_t layoutDescription = {0};
5185 nbgl_layoutHeader_t headerDesc = {.type = HEADER_BACK_AND_TEXT,
5186 .separationLine = true,
5187 .backAndText.token = BACK_TOKEN,
5188 .backAndText.tuneId = TUNE_TAP_CASUAL};
5189 int status = -1;
5190
5191 if ((minDigits > KEYPAD_MAX_DIGITS) || (maxDigits > KEYPAD_MAX_DIGITS)) {
5193 "nbgl_useCaseKeypad(): digits out of range (%d/%d > %d)\n",
5194 minDigits,
5195 maxDigits,
5197 return;
5198 }
5199
5200 reset_callbacks_and_context();
5201 // reset the keypad context
5202 memset(&keypadContext, 0, sizeof(KeypadContext_t));
5203
5204 // memorize context
5205 onQuit = backCallback;
5206
5207 // get a layout
5208 layoutDescription.onActionCallback = keypadGeneric_cb;
5209 keypadContext.layoutCtx = nbgl_layoutGet(&layoutDescription);
5210 keypadContext.hidden = hidden;
5211
5212 // set back key in header
5213 nbgl_layoutAddHeader(keypadContext.layoutCtx, &headerDesc);
5214
5215 // add keypad
5216 status = nbgl_layoutAddKeypad(keypadContext.layoutCtx, keypadCallback, shuffled);
5217 if (status < 0) {
5218 LOG_WARN(
5219 USE_CASE_LOGGER, "nbgl_useCaseKeypad(): layout setup failed (status=%d)\n", status);
5220 return;
5221 }
5222 // add keypad content
5224 keypadContext.layoutCtx, title, keypadContext.hidden, maxDigits, "");
5225 if (status < 0) {
5226 LOG_WARN(
5227 USE_CASE_LOGGER, "nbgl_useCaseKeypad(): layout setup failed (status=%d)\n", status);
5228 return;
5229 }
5230
5231 // validation pin callback
5232 keypadContext.onValidatePin = validatePinCallback;
5233 // pin code acceptable lengths
5234 keypadContext.pinMinDigits = minDigits;
5235 keypadContext.pinMaxDigits = maxDigits;
5236
5237 nbgl_layoutDraw(keypadContext.layoutCtx);
5239}
5240#endif // NBGL_KEYPAD
5241
5242#ifdef NBGL_KEYBOARD
5271void nbgl_useCaseKeyboard(const nbgl_keyboardParams_t *params, nbgl_callback_t backCallback)
5272{
5273 // clang-format off
5274 nbgl_layoutDescription_t layoutDescription = {.onActionCallback = keyboardGeneric_cb};
5275 nbgl_layoutHeader_t headerDesc = {.type = HEADER_BACK_AND_TEXT,
5276 .backAndText.token = BACK_TOKEN,
5277 .backAndText.tuneId = TUNE_TAP_CASUAL};
5278 nbgl_layoutKbd_t kbdInfo = {.callback = &keyboardCallback,
5279 .lettersOnly = params->lettersOnly,
5280 .mode = params->mode,
5281 .casing = params->casing};
5282 int status = -1;
5283 // clang-format on
5284
5285 // the buffer must at least hold one character and its NUL terminator
5286 if ((params->entryBuffer == NULL) || (params->entryMaxLen == 0)) {
5287 LOG_WARN(USE_CASE_LOGGER, "nbgl_useCaseKeyboard(): invalid entry buffer\n");
5288 return;
5289 }
5290
5291 reset_callbacks_and_context();
5292 // reset the keyboard context
5293 memset(&keyboardContext, 0, sizeof(KeyboardContext_t));
5294
5295 // memorize context
5296 onQuit = backCallback;
5297
5298 // get a layout
5299 keyboardContext.layoutCtx = nbgl_layoutGet(&layoutDescription);
5300
5301 // set back key in header
5302 nbgl_layoutAddHeader(keyboardContext.layoutCtx, &headerDesc);
5303
5304 // Add keyboard
5305 status = nbgl_layoutAddKeyboard(keyboardContext.layoutCtx, &kbdInfo);
5306 if (status < 0) {
5307 LOG_WARN(
5308 USE_CASE_LOGGER, "nbgl_useCaseKeyboard(): layout setup failed (status=%d)\n", status);
5309 return;
5310 }
5311 keyboardContext.keyboardIndex = status;
5312 keyboardContext.casing = params->casing;
5313 keyboardContext.entryBuffer = PIC(params->entryBuffer);
5314 keyboardContext.entryMaxLen = params->entryMaxLen;
5315 keyboardContext.entryBuffer[0] = '\0';
5316 // add keyboard content
5317 keyboardContext.keyboardContent = (nbgl_layoutKeyboardContent_t){
5318 .type = params->type,
5319 .title = PIC(params->title),
5320 .numbered = params->numbered,
5321 .number = params->number,
5322 .obfuscated = params->obfuscated,
5323 .text = keyboardContext.entryBuffer,
5324 .textToken = KEYBOARD_CROSS_TOKEN,
5325 .tuneId = TUNE_TAP_CASUAL,
5326 };
5327 switch (params->type) {
5329 onAction = PIC(params->confirmationParams.onButtonCallback);
5330 keyboardContext.keyboardContent.confirmationButton = (nbgl_layoutConfirmationButton_t){
5331 .text = PIC(params->confirmationParams.buttonText),
5332 .token = KEYBOARD_BUTTON_TOKEN,
5333 .active = true,
5334 };
5335 break;
5337 onControls = PIC(params->suggestionParams.onButtonCallback);
5338 keyboardContext.getSuggestionButtons
5340 keyboardContext.keyboardContent.suggestionButtons = (nbgl_layoutSuggestionButtons_t){
5341 .buttons = PIC(params->suggestionParams.buttons),
5342 .firstButtonToken = params->suggestionParams.firstButtonToken,
5343 };
5344 break;
5345 default:
5346 return;
5347 }
5348 status = nbgl_layoutAddKeyboardContent(keyboardContext.layoutCtx,
5349 &keyboardContext.keyboardContent);
5350 if (status < 0) {
5351 LOG_WARN(
5352 USE_CASE_LOGGER, "nbgl_useCaseKeyboard(): layout setup failed (status=%d)\n", status);
5353 return;
5354 }
5355
5356 nbgl_layoutDraw(keyboardContext.layoutCtx);
5358}
5359#endif // NBGL_KEYBOARD
5360
5361#endif // HAVE_SE_TOUCH
5362#endif // NBGL_USE_CASE
struct nbgl_pageSwitchesList_s nbgl_contentSwitchesList_t
This structure contains data to build a SWITCHES_LIST content.
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
struct nbgl_contentTagValueList_s nbgl_contentTagValueList_t
This structure contains a list of [tag,value] pairs.
@ 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
struct nbgl_contentInfoList_s nbgl_contentInfoList_t
This structure contains data to build a INFOS_LIST content.
debug traces management
#define LOG_WARN(__logger,...)
Definition nbgl_debug.h:89
@ USE_CASE_LOGGER
Definition nbgl_debug.h:37
#define LOG_DEBUG(__logger,...)
Definition nbgl_debug.h:88
struct nbgl_pageContent_s nbgl_pageContent_t
This structure contains data to build a page in multi-pages mode (nbgl_pageDrawGenericContent).
uint8_t nbgl_getTextNbPagesInWidth(nbgl_font_id_e fontId, const char *text, uint8_t nbLinesPerPage, uint16_t maxWidth)
bool nbgl_getTextMaxLenInNbLines(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, uint16_t maxNbLines, uint16_t *len, bool wrapping)
nbgl_font_id_e
Definition nbgl_fonts.h:143
void nbgl_textReduceOnNbLines(nbgl_font_id_e fontId, const char *origText, uint16_t maxWidth, uint8_t nbLines, char *reducedText, uint16_t reducedTextLen)
uint16_t nbgl_getTextHeightInWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, bool wrapping)
uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, bool wrapping)
uint8_t nbgl_getFontLineHeight(nbgl_font_id_e fontId)
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_layoutUpdateKeyboard(nbgl_layout_t *layout, uint8_t index, uint32_t keyMask, bool updateCasing, keyboardCase_t casing)
Updates an existing keyboard on bottom of the screen, with the given configuration.
int nbgl_layoutAddKeyboard(nbgl_layout_t *layout, const nbgl_layoutKbd_t *kbdInfo)
Creates a keyboard on bottom of the screen, with the given configuration.
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_layoutAddKeyboardContent(nbgl_layout_t *layout, nbgl_layoutKeyboardContent_t *content)
Adds an area containing a potential title, a text entry and either confirmation or suggestion buttons...
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
int nbgl_layoutAddTextContent(nbgl_layout_t *layout, nbgl_layoutTextContent_t *content)
Creates in the main container three text areas:
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_layoutUpdateKeyboardContent(nbgl_layout_t *layout, nbgl_layoutKeyboardContent_t *content)
Updates an area containing a potential title, a text entry and either confirmation or suggestion butt...
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:32
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,...
int nbgl_layoutAddLeftContent(nbgl_layout_t *layout, const nbgl_layoutLeftContent_t *info)
Creates an area with a title, and rows of icon + text, left aligned.
@ 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:29
struct nbgl_layoutDescription_s nbgl_layoutDescription_t
Structure containing all information when creating a layout. This structure must be passed as argumen...
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,...
#define TAG_VALUE_INTERVALE
@ 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:37
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.
nbgl_contentTagValue_t nbgl_layoutTagValue_t
Deprecated, kept for retro compatibility.
Internal functions/constants of NBGL layout layer.
static nbgl_font_id_e layoutGetTagValueFont(bool smallCaseForValue)
returns the font used to display the values of a list of tag/value pairs
static uint8_t layoutGetTagValueMaxLines(uint8_t listMaxLines, const nbgl_contentTagValue_t *pair, bool *forceEllipsis)
returns the max number of lines of the value of the given tag/value pair, which is the smallest non-z...
static uint16_t layoutGetTagValueWidth(const nbgl_icon_details_t *icon)
returns the width of the value of a tag/value pair. Shared by the layout and the use cases,...
static const nbgl_icon_details_t * layoutGetTagValueIcon(const nbgl_contentTagValue_t *pair)
returns the icon displayed on the right of the value of the given tag/value pair
void(* nbgl_layoutTouchCallback_t)(int token, uint8_t index)
prototype of function to be called when an object is touched
@ KEYBOARD_WITH_BUTTON
text entry area + confirmation button
@ KEYBOARD_WITH_SUGGESTIONS
text entry area + suggestion buttons
#define NB_SPINNER_POSITIONS
Definition nbgl_obj.h:158
void nbgl_refresh(void)
#define KEYPAD_MAX_DIGITS
Definition nbgl_obj.h:76
void nbgl_refreshSpecial(nbgl_refresh_mode_t mode)
#define BACKSPACE_KEY
Definition nbgl_obj.h:30
void nbgl_refreshSpecialWithPostRefresh(nbgl_refresh_mode_t mode, nbgl_post_refresh_t post_refresh)
#define VALIDATE_KEY
Definition nbgl_obj.h:31
keyboardCase_t
Letters casing in which to open/set the keyboard.
struct nbgl_pageInfoDescription_s nbgl_pageInfoDescription_t
Structure containing all specific information when creating an information page.
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:633
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:351
void * nbgl_page_t
type shared externally
Definition nbgl_page.h:50
@ NAV_WITH_BUTTONS
move forward and backward with buttons in bottom nav bar
Definition nbgl_page.h:58
struct nbgl_pageMultiScreensDescription_s nbgl_pageNavigationInfo_t
Structure containing all specific information when creating a multi-screens page.
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:471
struct nbgl_pageConfirmationDescription_s nbgl_pageConfirmationDescription_t
Structure containing all specific information when creating a confirmation page.
int nbgl_pageRelease(nbgl_page_t *)
Release the page obtained with any of the nbgl_pageDrawXXX() functions.
Definition nbgl_page.c:646
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:511
@ QUIT_APP_TEXT
A full width button with "Quit app" text (only for bottom button).
Definition nbgl_page.h:43
@ INFO_ICON
info (i) icon in the button.
Definition nbgl_page.h:42
@ NO_BUTTON_STYLE
no button.
Definition nbgl_page.h:39
@ SETTINGS_ICON
settings (wheel) icon in the button.
Definition nbgl_page.h:40
nbgl_contentInfoLongPress_t nbgl_pageInfoLongPress_t
Deprecated, kept for retro compatibility.
struct PACKED__ nbgl_screenTickerConfiguration_s nbgl_screenTickerConfiguration_t
struct to configure a screen layer
void nbgl_screenRedraw(void)
@ POST_REFRESH_FORCE_POWER_ON
Force screen power on after refresh.
Definition nbgl_types.h:366
#define MIN(x, y)
Definition nbgl_types.h:131
struct PACKED__ nbgl_icon_details_s nbgl_icon_details_t
Represents all information about an icon.
#define MAX(x, y)
Definition nbgl_types.h:134
nbgl_refresh_mode_t
different modes of refresh for nbgl_refreshSpecial()
Definition nbgl_types.h:338
@ BLACK_AND_WHITE_REFRESH
to be used for pure B&W area, when contrast is important
Definition nbgl_types.h:342
@ FULL_COLOR_CLEAN_REFRESH
to be used for lock screen display (cleaner but longer refresh)
Definition nbgl_types.h:341
@ BLACK_AND_WHITE_FAST_REFRESH
to be used for pure B&W area, when contrast is not priority
Definition nbgl_types.h:343
@ FULL_COLOR_PARTIAL_REFRESH
to be used for small partial refresh (radio buttons, switches)
Definition nbgl_types.h:340
@ FULL_COLOR_REFRESH
to be used for normal refresh
Definition nbgl_types.h:339
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).
@ LEFT_CONTENT_WARNING
left-aligned title and icon/text rows (touch devices only)
@ 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)
void(* nbgl_callback_t)(void)
prototype of generic callback function
#define SKIPPABLE_OPERATION
This is to use in nbgl_operationType_t when the operation is skippable. This is used to add a Skip bu...
void nbgl_useCaseGenericSettings(const char *appName, uint8_t initPage, const nbgl_genericContents_t *settingContents, const nbgl_contentInfoList_t *infosList, nbgl_callback_t quitCallback)
uint32_t nbgl_operationType_t
This mask is used to describe the type of operation to review with additional options It is a mask of...
void nbgl_useCaseReview(nbgl_operationType_t operationType, const nbgl_contentTagValueList_t *tagValueList, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, const char *finishTitle, nbgl_choiceCallback_t choiceCallback)
struct nbgl_genericDetails_s nbgl_genericDetails_t
The necessary parameters to build the page(s) displayed when the top-right button is touched in intro...
void nbgl_useCaseAction(const nbgl_icon_details_t *icon, const char *message, const char *actionText, nbgl_callback_t callback)
uint8_t nbgl_useCaseGetNbTagValuesInPage(uint8_t nbPairs, const nbgl_contentTagValueList_t *tagValueList, uint8_t startIndex, bool *requireSpecificDisplay)
void(* nbgl_pinValidCallback_t)(const uint8_t *pin, uint8_t pinLen)
prototype of pin validation callback function
void nbgl_useCaseReviewStreamingStart(nbgl_operationType_t operationType, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, nbgl_choiceCallback_t choiceCallback)
void nbgl_useCaseHomeAndSettings(const char *appName, const nbgl_icon_details_t *appIcon, const char *tagline, const uint8_t initSettingPage, const nbgl_genericContents_t *settingContents, const nbgl_contentInfoList_t *infosList, const nbgl_homeAction_t *action, nbgl_callback_t quitCallback)
nbgl_genericDetails_t nbgl_warningDetails_t
void nbgl_useCaseStaticReviewLight(const nbgl_contentTagValueList_t *tagValueList, const nbgl_pageInfoLongPress_t *infoLongPress, const char *rejectText, nbgl_choiceCallback_t callback)
#define RISKY_OPERATION
This is to use in nbgl_operationType_t when the operation is concerned by an internal warning....
void(* nbgl_choiceCallback_t)(bool confirm)
prototype of choice callback function
void nbgl_useCaseNavigableContent(const char *title, uint8_t initPage, uint8_t nbPages, nbgl_callback_t quitCallback, nbgl_navCallback_t navCallback, nbgl_layoutTouchCallback_t controlsCallback)
#define INFOS_AREA_HEIGHT
height available for infos pairs display
@ STRONG_HOME_ACTION
Black button, implicating the main action of the App.
void nbgl_useCaseReviewStreamingFinish(const char *finishTitle, nbgl_choiceCallback_t choiceCallback)
#define NO_THREAT_OPERATION
This is to use in nbgl_operationType_t when the operation is concerned by an internal information....
void nbgl_useCaseChoiceWithDetails(const nbgl_icon_details_t *icon, const char *message, const char *subMessage, const char *confirmText, const char *cancelText, nbgl_warningDetails_t *details, nbgl_choiceCallback_t callback)
void nbgl_useCaseAdvancedChoiceWithDetails(const nbgl_icon_details_t *centerIcon, const nbgl_icon_details_t *headerIcon, const char *title, const char *message, const char *subMessage, const char *confirmText, const char *cancelText, nbgl_warningDetails_t *details, nbgl_choiceCallback_t callback)
void nbgl_useCaseSpinner(const char *text)
void nbgl_useCaseConfirm(const char *message, const char *subMessage, const char *confirmText, const char *rejectText, nbgl_callback_t callback)
#define NB_MAX_LINES_IN_DETAILS
maximum number of lines for value field in details pages
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)
bool nbgl_useCaseShowInfoAndSettings(uint8_t initPage)
#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 FIRST_USER_TOKEN
when using controls in page content (nbgl_pageContent_t), this is the first token value usable for th...
#define TAG_VALUE_AREA_HEIGHT
height available for tag/value pairs display
#define BLIND_OPERATION
This is to use in nbgl_operationType_t when the operation is "blind" This is used to indicate a warni...
#define TAGLINE_PART1
Default strings used in the Home tagline.
void nbgl_useCaseGenericReview(const nbgl_genericContents_t *contents, const char *rejectText, nbgl_callback_t rejectCallback)
#define STATUS_SCREEN_DURATION
void nbgl_useCaseKeyboard(const nbgl_keyboardParams_t *params, nbgl_callback_t backCallback)
#define TAGLINE_PART2
void nbgl_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)
void(* nbgl_keyboardButtonsCallback_t)(nbgl_layoutKeyboardContent_t *content, uint32_t *mask)
prototype of keyboard buttons callback function
#define REAL_TYPE_MASK
Mask to apply on nbgl_operationType_t to extract the base nbgl_opType_t. Bits 0-3 are reserved for th...
void nbgl_useCaseReviewStatus(nbgl_reviewStatusType_t reviewStatusType, nbgl_callback_t quitCallback)
#define LAST_PAGE_FOR_REVIEW
value of page parameter used with navigation callback when "skip" button is touched,...
#define ADDRESS_BOOK_OPERATION
This is to use in nbgl_operationType_t when the operation is related to "AddressBook" to adapt wordin...
nbgl_reviewStatusType_t
The different types of review status.
@ STATUS_TYPE_TRANSACTION_REJECTED
@ STATUS_TYPE_ADDRESS_REJECTED
@ STATUS_TYPE_TRANSACTION_SIGNED
@ STATUS_TYPE_OPERATION_REJECTED
@ STATUS_TYPE_OPERATION_SIGNED
@ STATUS_TYPE_ADDRESS_VERIFIED
@ STATUS_TYPE_MESSAGE_SIGNED
@ STATUS_TYPE_MESSAGE_REJECTED
bool(* nbgl_navCallback_t)(uint8_t page, nbgl_pageContent_t *content)
prototype of navigation callback function
#define 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)
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
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
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
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
nbgl_contentActionCallback_t actionCallback
called when a valueIcon is touched on a given pair
This structure contains a [tag,value] pair and possible extensions.
const nbgl_contentValueExt_t * extension
if not NULL, gives additional info on value field
const nbgl_icon_details_t * valueIcon
const char * value
string giving the value name
const char * item
string giving the tag name
uint8_t centeredInfo
if set to 1, the tag will be displayed as a centered info
This structure contains additions to a tag/value pair, to be able to build a screen to display these ...
const char * fullValue
full string of the value when used as an alias
nbgl_contentValueAliasType_t aliasType
type of alias
const struct nbgl_contentTagValueList_s * tagValuelist
if aliasType is TAG_VALUE_LIST_ALIAS
const char * backText
used as title of the popping page, if not NULL, otherwise "item" is used
const char * aliasSubName
string displayed under alias and in details view
const struct nbgl_contentInfoList_s * infolist
if aliasType is INFO_LIST_ALIAS
This structure contains data to build a content.
nbgl_content_u content
nbgl_contentActionCallback_t contentActionCallback
callback to be called when an action on an object occurs
nbgl_contentType_t type
type of page content in the content union
const struct nbgl_genericDetails_s * details
array of nbBars structures giving what to display when each bar is touched.
uint8_t nbBars
number of touchable bars
const nbgl_icon_details_t ** icons
array of icons for each bar (nbBars items)
const char *const * subTexts
array of texts for each bar (nbBars items, in black)
const char *const * texts
array of texts for each bar (nbBars items, in black/bold)
uint8_t nbContents
number of contents
const nbgl_content_t * contentsList
array of nbgl_content_t (nbContents items).
nbgl_contentCallback_t contentGetterCallback
function to call to retrieve a given content
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
nbgl_layoutLeftContent_t leftContent
left content, if type == LEFT_CONTENT_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
const char * buttonText
button title
nbgl_callback_t onButtonCallback
callback to call when the button is pressed
nbgl_keyboardButtonsCallback_t updateButtonsCallback
callback to call when a key is pressed to update suggestions
nbgl_layoutTouchCallback_t onButtonCallback
callback to call when one of the buttons is pressed
const char ** buttons
array of strings for buttons (last ones can be NULL)
int firstButtonToken
first token used for buttons, provided in onButtonCallback
Structure containing all parameters for keyboard use case.
keyboardMode_t mode
keyboard mode to start with
nbgl_kbdSuggestParams_t suggestionParams
nbgl_kbdButtonParams_t confirmationParams
used if type is KEYBOARD_WITH_SUGGESTIONS
bool lettersOnly
if true, only display letter keys and Backspace
nbgl_layoutKeyboardContentType_t type
type of content
bool numbered
if set to true, the text is preceded on the left by 'number.'
keyboardCase_t casing
keyboard casing mode (lower, upper once or upper locked)
const char * title
centered title explaining the screen
bool obfuscated
if true, entered text and suggestions use the obfuscated font
char * entryBuffer
already entered text
uint8_t number
if numbered is true, number used to build 'number.' text
This structure contains info to build a clickable "bar" with a text and an icon.
const char * text
text (can be NULL)
uint8_t token
the token that will be used as argument of the callback
const char * subText
sub text (can be NULL)
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played
const nbgl_icon_details_t * iconLeft
a buffer containing the 1BPP icon for icon on left (can be NULL)
const nbgl_icon_details_t * iconRight
This structure contains info to build a pair of buttons, one on top of the other.
const char * bottomText
bottom-button text (index 1)
This structure contains info to build a confirmation button.
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::@317013035216204022361376155037350165325274163355::@336200035172265150334226242147226175342317012327 emptySpace
if type is FOOTER_EMPTY
This structure contains info to build a 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::@201253247212346330206060073156270274242030216100::@055026106344036336271111310103226046273153034166 backAndText
if type is HEADER_BACK_ICON_AND_TEXT or HEADER_BACK_AND_TEXT
This structure contains info to build a keyboard with nbgl_layoutAddKeyboard().
This structure contains info to build a keyboard content (controls that are linked to keyboard).
This structure contains info to build a centered (vertically and horizontally) area,...
const char * text2
second text (can be null)
This structure contains info to build suggestion buttons.
This structure contains info for Text content, to be set with nbgl_layoutAddTextContent().
const char * descriptions[NB_MAX_DESCRIPTIONS]
uint8_t nbDescriptions
number of used descriptions in above array
const char * info
description at bottom (in small gray)
const char * title
main text (in large bold font)
const char * cancelText
the text used for cancel action, if NULL a simple X button is used
Definition nbgl_page.h:121
uint8_t confirmationToken
the token used as argument of the onActionCallback
Definition nbgl_page.h:122
const char * confirmationText
text of the confirmation button
Definition nbgl_page.h:120
nbgl_layoutCenteredInfo_t centeredInfo
description of the centered info to be used
Definition nbgl_page.h:119
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played when button is pressed
Definition nbgl_page.h:126
nbgl_contentTagValueDetails_t tagValueDetails
TAG_VALUE_DETAILS type
const char * title
text for the title of the page (if NULL, no title)
uint8_t topRightToken
token used when top-right button (if not NULL) is touched
nbgl_contentInfoLongPress_t infoLongPress
INFO_LONG_PRESS type
nbgl_contentRadioChoice_t choicesList
CHOICES_LIST type
Definition nbgl_flow.h:69
nbgl_contentSwitchesList_t switchesList
SWITCHES_LIST type
Definition nbgl_flow.h:67
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played when title is touched
nbgl_contentBarsList_t barsList
BARS_LIST type
Definition nbgl_flow.h:70
nbgl_contentInfoButton_t infoButton
INFO_BUTTON type
Definition nbgl_flow.h:64
nbgl_contentInfoList_t infosList
INFOS_LIST type
Definition nbgl_flow.h:68
nbgl_contentTagValueList_t tagValueList
TAG_VALUE_LIST type
Definition nbgl_flow.h:65
const nbgl_icon_details_t * topRightIcon
nbgl_contentType_t type
type of page content in the following union
Definition nbgl_flow.h:61
nbgl_contentCenteredInfo_t centeredInfo
CENTERED_INFO type
Definition nbgl_flow.h:63
nbgl_contentTagValueConfirm_t tagValueConfirm
TAG_VALUE_CONFIRM type
Definition nbgl_flow.h:66
bool isTouchableTitle
if set to true, the title is preceded by <- arrow to go back
nbgl_contentExtendedCenter_t extendedCenter
EXTENDED_CENTER type
nbgl_layoutButtonStyle_t actionButtonStyle
style of "action" button
Definition nbgl_page.h:171
const char * actionButtonText
if not NULL an "action" button is set under the centered info
Definition nbgl_page.h:169
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played when button/footer is pressed
Definition nbgl_page.h:173
const nbgl_icon_details_t * actionButtonIcon
potential icon of "action" button
Definition nbgl_page.h:170
nbgl_layoutCenteredInfo_t centeredInfo
description of the centered info to be used
Definition nbgl_page.h:155
uint8_t nbPages
the number of pages to display (if <2, no navigation bar)
Definition nbgl_page.h:98
uint8_t quitToken
the token used as argument of the actionCallback when the footer is touched
Definition nbgl_page.h:100
uint8_t skipToken
if skipText is NULL the token used when right part of footer is touched
Definition nbgl_page.h:108
nbgl_pageNavigationType_t navType
Definition nbgl_page.h:101
uint8_t activePage
the index of the page to display at start-up
Definition nbgl_page.h:97
bool progressIndicator
if set to true, display a progress indicator on top of the page
Definition nbgl_page.h:103
nbgl_pageNavWithButtons_t navWithButtons
structure used when navigation with buttons
Definition nbgl_page.h:111
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played when next or back is pressed
Definition nbgl_page.h:105
bool visiblePageIndicator
if set to true, the page indicator will be visible in navigation
Definition nbgl_page.h:85
const char * quitText
the text displayed in footer (on the left), used to quit (only on Flex)
Definition nbgl_page.h:89
bool backButton
if set to true, a back button (<-) is displayed in the nav bar
Definition nbgl_page.h:83
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
const nbgl_contentCenter_t * info
parameters to build the intro warning page, if not using pre-defined
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