18 #include "os_helpers.h"
25 #define PAGE_NB_ELEMENTS_BITS 3
26 #define GET_PAGE_NB_ELEMENTS(pageData) ((pageData) &0x07)
27 #define SET_PAGE_NB_ELEMENTS(nbElements) ((nbElements) &0x07)
29 #define PAGE_FLAG_BITS 1
30 #define GET_PAGE_FLAG(pageData) (((pageData) &0x08) >> 3)
31 #define SET_PAGE_FLAG(flag) (((flag) &0x01) << 3)
33 #define PAGE_DATA_BITS (PAGE_NB_ELEMENTS_BITS + PAGE_FLAG_BITS)
34 #define PAGES_PER_UINT8 (8 / PAGE_DATA_BITS)
35 #define SET_PAGE_DATA(pageIdx, pageData) \
36 (pagesData[pageIdx / PAGES_PER_UINT8] = pageData \
37 << ((pageIdx % PAGES_PER_UINT8) * PAGE_DATA_BITS))
39 #define MAX_PAGE_NB 256
42 #define STARTING_CONTENT localContentsList[0]
43 #define FINISHING_CONTENT localContentsList[1]
46 #define QRCODE_NB_MAX_LINES 3
48 #define QRCODE_REDUCED_ADDR_LEN 128
51 #define keypadContext sharedContext.keypad
52 #define blindSigningContext sharedContext.blindSigning
64 ADDRESS_QRCODE_BUTTON_TOKEN,
83 typedef struct DetailsContext_s {
89 const char *nextPageStart;
92 typedef struct AddressConfirmationContext_s {
95 } AddressConfirmationContext_t;
98 typedef struct KeypadContext_s {
108 typedef struct BlindSigningContext_s {
113 const char *reviewTitle;
114 const char *reviewSubTitle;
115 const char *finishTitle;
119 } BlindSigningContext_t;
125 KeypadContext_t keypad;
127 BlindSigningContext_t blindSigning;
133 uint8_t currentContentElementNb;
135 bool hasStartingContent;
136 bool hasFinishingContent;
137 const char *detailsItem;
138 const char *detailsvalue;
139 bool detailsWrapping;
156 } nbgl_homeAndSettingsContext_t;
161 } nbgl_reviewContext_t;
169 } nbgl_reviewStreamingContext_t;
172 nbgl_homeAndSettingsContext_t homeAndSettings;
173 nbgl_reviewContext_t review;
174 nbgl_reviewStreamingContext_t reviewStreaming;
175 } nbgl_BundleNavContext_t;
202 static const char *pageTitle;
205 static const char *tipBoxModalTitle;
210 static bool forwardNavOnly;
211 static NavType_t navType;
213 static DetailsContext_t detailsContext;
216 static SharedContext_t sharedContext;
219 static AddressConfirmationContext_t addressConfirmationContext;
222 static GenericContext_t genericContext;
224 localContentsList[3];
225 static uint8_t genericContextPagesInfo[MAX_PAGE_NB / PAGES_PER_UINT8];
228 static nbgl_BundleNavContext_t bundleNavContext;
231 static const uint8_t nbMaxElementsPerContentType[] = {
247 static char reducedAddress[QRCODE_REDUCED_ADDR_LEN];
253 static void displayReviewPage(
uint8_t page,
bool forceFullRefresh);
254 static void displayDetailsPage(
uint8_t page,
bool forceFullRefresh);
255 static void displayFullValuePage(
const char *backText,
256 const char *aliasText,
258 static void displayBlindWarning(
void);
259 static void displayTipBoxModal(
void);
260 static void displaySettingsPage(
uint8_t page,
bool forceFullRefresh);
261 static void displayGenericContextPage(
uint8_t pageIdx,
bool forceFullRefresh);
262 static void pageCallback(
int token,
uint8_t index);
264 static void displayAddressQRCode(
void);
265 static void addressLayoutTouchCallbackQR(
int token,
uint8_t index);
267 static void modalLayoutTouchCallback(
int token,
uint8_t index);
268 static void displaySkipWarning(
void);
270 static void bundleNavStartHome(
void);
271 static void bundleNavStartSettingsAtPage(
uint8_t initSettingPage);
272 static void bundleNavStartSettings(
void);
274 static void bundleNavReviewStreamingChoice(
bool confirm);
275 static void blindSigningWarning(
void);
279 const char *reviewTitle,
280 const char *reviewSubTitle,
281 const char *finishTitle,
285 bool playNotifSound);
288 const char *reviewTitle,
289 const char *reviewSubTitle,
291 bool playNotifSound);
292 static void useCaseHomeExt(
const char *appName,
299 static void displayDetails(
const char *tag,
const char *value,
bool wrapping);
301 static void reset_callbacks(
void)
308 onContentAction = NULL;
310 onModalConfirm = NULL;
312 onValidatePin = NULL;
317 static void genericContextSetPageInfo(
uint8_t pageIdx,
uint8_t nbElements,
bool flag)
319 uint8_t pageData = SET_PAGE_NB_ELEMENTS(nbElements) + SET_PAGE_FLAG(flag);
321 genericContextPagesInfo[pageIdx / PAGES_PER_UINT8]
322 &= ~(0x0F << ((pageIdx % PAGES_PER_UINT8) * PAGE_DATA_BITS));
323 genericContextPagesInfo[pageIdx / PAGES_PER_UINT8]
324 |= pageData << ((pageIdx % PAGES_PER_UINT8) * PAGE_DATA_BITS);
328 static void genericContextGetPageInfo(
uint8_t pageIdx,
uint8_t *nbElements,
bool *flag)
330 uint8_t pageData = genericContextPagesInfo[pageIdx / PAGES_PER_UINT8]
331 >> ((pageIdx % PAGES_PER_UINT8) * PAGE_DATA_BITS);
332 if (nbElements != NULL) {
333 *nbElements = GET_PAGE_NB_ELEMENTS(pageData);
336 *flag = GET_PAGE_FLAG(pageData);
343 switch (content->
type) {
365 if (contentIdx < 0 || contentIdx >= genericContents->
nbContents) {
382 static void prepareNavInfo(
bool isReview,
uint8_t nbPages,
const char *rejectText)
384 memset(&navInfo, 0,
sizeof(navInfo));
387 navInfo.
tuneId = TUNE_TAP_CASUAL;
391 if (isReview ==
false) {
400 = ((navType == STREAMING_NAV) && (nbPages < 2)) ?
false :
true;
407 const char *reviewTitle,
408 const char *reviewSubTitle)
410 contentCenter->
icon = icon;
411 contentCenter->
title = reviewTitle;
413 contentCenter->
subText =
"Swipe to review";
416 contentCenter->
padding =
false;
421 const char *finishTitle)
423 infoLongPress->
text = finishTitle;
424 infoLongPress->
icon = icon;
431 const char *finishTitle)
433 infoButton->
text = finishTitle;
434 infoButton->
icon = icon;
441 UNUSED(operationType);
447 static void pageModalCallback(
int token,
uint8_t index)
451 if (token == INFO_ALIAS_TOKEN) {
453 displayFullValuePage(tipBoxInfoList.
infoTypes[index],
459 modalPageContext = NULL;
460 if (token == NAV_TOKEN) {
467 displayDetailsPage(index,
false);
470 if (token == QUIT_TOKEN) {
475 else if (token == SKIP_TOKEN) {
486 else if (token == CHOICE_TOKEN) {
488 if (onModalConfirm != NULL) {
501 static void pageCallback(
int token,
uint8_t index)
504 if (token == QUIT_TOKEN) {
505 if (onQuit != NULL) {
509 else if (token == CONTINUE_TOKEN) {
510 if (onContinue != NULL) {
514 else if (token == CHOICE_TOKEN) {
515 if (onChoice != NULL) {
516 onChoice((index == 0) ?
true :
false);
519 else if (token == ACTION_BUTTON_TOKEN) {
520 if ((index == 0) && (onAction != NULL)) {
523 else if ((index == 1) && (onQuit != NULL)) {
528 else if (token == ADDRESS_QRCODE_BUTTON_TOKEN) {
529 displayAddressQRCode();
532 else if (token == CONFIRM_TOKEN) {
533 if (onChoice != NULL) {
537 else if (token == REJECT_TOKEN) {
538 if (onChoice != NULL) {
542 else if (token == DETAILS_BUTTON_TOKEN) {
543 displayDetails(genericContext.detailsItem,
544 genericContext.detailsvalue,
545 genericContext.detailsWrapping);
547 else if (token == NAV_TOKEN) {
549 if (onQuit != NULL) {
554 if (navType == GENERIC_NAV || navType == STREAMING_NAV) {
555 displayGenericContextPage(index,
false);
557 else if (navType == REVIEW_NAV) {
558 displayReviewPage(index,
false);
561 displaySettingsPage(index,
false);
565 else if (token == NEXT_TOKEN) {
567 displayReviewPage(navInfo.
activePage + 1,
false);
570 displayGenericContextPage(navInfo.
activePage + 1,
false);
573 else if (token == BACK_TOKEN) {
575 displayReviewPage(navInfo.
activePage - 1,
true);
578 displayGenericContextPage(navInfo.
activePage - 1,
false);
581 else if (token == SKIP_TOKEN) {
583 displaySkipWarning();
585 else if (token == VALUE_ALIAS_TOKEN) {
588 if (genericContext.currentPairs != NULL) {
589 pair = &genericContext.currentPairs[genericContext.currentElementIdx + index];
592 pair = genericContext.currentCallback(genericContext.currentElementIdx + index);
596 else if (token == BLIND_WARNING_TOKEN) {
597 displayBlindWarning();
599 else if (token == TIP_BOX_TOKEN) {
600 displayTipBoxModal();
603 if (onContentAction != NULL) {
604 onContentAction(token, index, navInfo.
activePage);
606 if (onControls != NULL) {
607 onControls(token, index);
613 static void tickerCallback(
void)
616 if (onQuit != NULL) {
622 static void displaySettingsPage(
uint8_t page,
bool forceFullRefresh)
626 if ((onNav == NULL) || (onNav(page, &content) ==
false)) {
631 content.title = pageTitle;
632 content.isTouchableTitle =
true;
633 content.titleToken = QUIT_TOKEN;
634 content.tuneId = TUNE_TAP_CASUAL;
639 if (forceFullRefresh) {
648 static void displayReviewPage(
uint8_t page,
bool forceFullRefresh)
657 if ((onNav == NULL) || (onNav(navInfo.
activePage, &content) ==
false)) {
662 content.title = NULL;
663 content.isTouchableTitle =
false;
664 content.tuneId = TUNE_TAP_CASUAL;
670 content.infoLongPress.longPressToken = CONFIRM_TOKEN;
671 if (forwardNavOnly) {
679 content.tagValueDetails.tagValueList.smallCaseForValue =
false;
685 content.tagValueList.smallCaseForValue =
false;
688 content.tagValueConfirm.tagValueList.smallCaseForValue =
false;
690 content.tagValueConfirm.confirmationToken = CONFIRM_TOKEN;
695 if (forceFullRefresh) {
707 uint8_t *p_nbElementsInNextPage,
710 int8_t nextContentIdx = genericContext.currentContentIdx;
711 int16_t nextElementIdx = genericContext.currentElementIdx;
715 genericContextGetPageInfo(pageIdx, &nbElementsInNextPage, p_flag);
716 *p_nbElementsInNextPage = nbElementsInNextPage;
721 uint8_t nbElementsInCurrentPage;
723 genericContextGetPageInfo(navInfo.
activePage, &nbElementsInCurrentPage, NULL);
724 nextElementIdx += nbElementsInCurrentPage;
729 if ((nextElementIdx >= genericContext.currentContentElementNb)
730 && (genericContext.currentContentElementNb > 0)) {
740 nextElementIdx -= nbElementsInNextPage;
746 if (nextElementIdx < 0) {
748 nextElementIdx = -nbElementsInNextPage;
754 if ((nextContentIdx == -1) && (genericContext.hasStartingContent)) {
755 p_content = &STARTING_CONTENT;
757 else if ((nextContentIdx == genericContext.genericContents.nbContents)
758 && (genericContext.hasFinishingContent)) {
759 p_content = &FINISHING_CONTENT;
762 p_content = getContentAtIdx(&genericContext.genericContents, nextContentIdx, content);
764 if (p_content == NULL) {
779 if ((nextContentIdx != genericContext.currentContentIdx)
780 || (genericContext.currentContentElementNb == 0)) {
781 genericContext.currentContentIdx = nextContentIdx;
782 genericContext.currentContentElementNb = getContentNbElement(p_content);
784 if (nextElementIdx < 0) {
785 nextElementIdx = genericContext.currentContentElementNb + nextElementIdx;
790 if ((nextElementIdx < 0) || (nextElementIdx >= genericContext.currentContentElementNb)) {
792 "Invalid element index %d / %d\n",
794 genericContext.currentContentElementNb);
799 genericContext.currentElementIdx = nextElementIdx;
807 static bool genericContextPreparePageContent(
const nbgl_content_t *p_content,
812 uint8_t nextElementIdx = genericContext.currentElementIdx;
814 pageContent->title = pageTitle;
815 pageContent->isTouchableTitle =
false;
816 pageContent->titleToken = QUIT_TOKEN;
817 pageContent->tuneId = TUNE_TAP_CASUAL;
819 pageContent->type = p_content->
type;
820 switch (pageContent->type) {
822 memcpy(&pageContent->centeredInfo,
824 sizeof(pageContent->centeredInfo));
827 memcpy(&pageContent->extendedCenter,
829 sizeof(pageContent->extendedCenter));
832 memcpy(&pageContent->infoLongPress,
834 sizeof(pageContent->infoLongPress));
838 memcpy(&pageContent->infoButton,
840 sizeof(pageContent->infoButton));
866 prepareReviewFirstPage(&pageContent->extendedCenter.contentCenter,
872 p_tagValueList = NULL;
877 pageContent->tagValueDetails.detailsButtonText =
"More";
878 pageContent->tagValueDetails.detailsButtonIcon = NULL;
879 pageContent->tagValueDetails.detailsButtonToken = DETAILS_BUTTON_TOKEN;
881 p_tagValueList = &pageContent->tagValueDetails.tagValueList;
884 genericContext.detailsItem = pair->
item;
885 genericContext.detailsvalue = pair->
value;
890 if (p_tagValueList != NULL) {
891 p_tagValueList->
nbPairs = nbElementsInPage;
894 p_tagValueList->
pairs
897 for (
uint8_t i = 0; i < nbElementsInPage; i++) {
899 p_tagValueList->
token = VALUE_ALIAS_TOKEN;
905 p_tagValueList->
pairs = NULL;
909 for (
uint8_t i = 0; i < nbElementsInPage; i++) {
913 p_tagValueList->
token = VALUE_ALIAS_TOKEN;
926 memcpy(&pageContent->tagValueConfirm,
928 sizeof(pageContent->tagValueConfirm));
931 pageContent->switchesList.nbSwitches = nbElementsInPage;
932 pageContent->switchesList.switches
936 pageContent->infosList.nbInfos = nbElementsInPage;
937 pageContent->infosList.infoTypes
939 pageContent->infosList.infoContents
943 memcpy(&pageContent->choicesList,
945 sizeof(pageContent->choicesList));
946 pageContent->choicesList.nbChoices = nbElementsInPage;
947 pageContent->choicesList.names
951 < nextElementIdx + nbElementsInPage)) {
952 pageContent->choicesList.initChoice
956 pageContent->choicesList.initChoice = nbElementsInPage;
960 pageContent->barsList.nbBars = nbElementsInPage;
961 pageContent->barsList.barTexts
971 bool isFirstOrLastPage
974 bool isStreamingNavAndBlindOperation
975 = (navType == STREAMING_NAV)
977 bool isGenericNavAndBlindOperation
978 = (navType == GENERIC_NAV) && (bundleNavContext.review.operationType &
BLIND_OPERATION);
981 if (isFirstOrLastPage && (isStreamingNavAndBlindOperation || isGenericNavAndBlindOperation)) {
983 pageContent->topRightToken = BLIND_WARNING_TOKEN;
990 static void displayGenericContextPage(
uint8_t pageIdx,
bool forceFullRefresh)
998 if (navType == STREAMING_NAV) {
1000 if (bundleNavContext.reviewStreaming.skipCallback != NULL) {
1001 bundleNavContext.reviewStreaming.skipCallback();
1005 else if (pageIdx >= bundleNavContext.reviewStreaming.stepPageNb) {
1006 bundleNavReviewStreamingChoice(
true);
1013 = genericContextComputeNextPageParams(pageIdx, &content, &nbElementsInPage, &flag);
1018 for (
int i = navInfo.
activePage + 1; i <= pageIdx; i++) {
1019 p_content = genericContextComputeNextPageParams(i, &content, &nbElementsInPage, &flag);
1029 = genericContextComputeNextPageParams(pageIdx, &content, &nbElementsInPage, &flag);
1032 if (p_content == NULL) {
1038 if (!genericContextPreparePageContent(p_content, nbElementsInPage, flag, &pageContent)) {
1044 if (forceFullRefresh) {
1053 static const char *getDetailsPageAt(
uint8_t detailsPage)
1056 const char *currentChar = detailsContext.value;
1057 while (page < detailsPage) {
1067 detailsContext.wrapping);
1069 currentChar = currentChar + len;
1077 static void displayDetailsPage(
uint8_t detailsPage,
bool forceFullRefresh)
1081 .nbPages = detailsContext.nbPages,
1083 .quitToken = QUIT_TOKEN,
1084 .navWithButtons.navToken = NAV_TOKEN,
1085 .navWithButtons.quitButton =
true,
1086 .navWithButtons.backButton =
true,
1087 .navWithButtons.quitText = NULL,
1088 .progressIndicator =
false,
1089 .tuneId = TUNE_TAP_CASUAL};
1091 .topRightIcon = NULL,
1092 .tagValueList.nbPairs = 1,
1093 .tagValueList.pairs = ¤tPair,
1094 .tagValueList.smallCaseForValue =
true,
1095 .tagValueList.wrapping = detailsContext.wrapping};
1097 if (modalPageContext != NULL) {
1100 currentPair.
item = detailsContext.tag;
1102 if (detailsPage <= detailsContext.currentPage) {
1104 currentPair.
value = getDetailsPageAt(detailsPage);
1105 forceFullRefresh =
true;
1109 currentPair.
value = detailsContext.nextPageStart;
1111 detailsContext.currentPage = detailsPage;
1122 detailsContext.wrapping);
1125 detailsContext.nextPageStart = currentPair.
value + len;
1131 detailsContext.nextPageStart = NULL;
1132 content.tagValueList.nbMaxLinesForValue = 0;
1140 if (forceFullRefresh) {
1149 static void displayFullValuePage(
const char *backText,
1150 const char *aliasText,
1154 .withLeftBorder =
true,
1155 .onActionCallback = &modalLayoutTouchCallback,
1156 .tapActionText = NULL};
1158 .separationLine =
false,
1159 .backAndText.token = 0,
1160 .backAndText.tuneId = TUNE_TAP_CASUAL,
1161 .backAndText.text = PIC(backText)};
1182 info =
"ENS names are resolved by Ledger backend.";
1185 info =
"This account label comes from your Address Book in Ledger Live.";
1191 genericContext.modalLayout, aliasText, extension->
fullValue, info);
1199 static void displayBlindWarning(
void)
1202 .withLeftBorder =
true,
1203 .onActionCallback = &modalLayoutTouchCallback,
1204 .tapActionText = NULL};
1206 .separationLine =
false,
1207 .backAndText.token = 0,
1208 .backAndText.tuneId = TUNE_TAP_CASUAL,
1209 .backAndText.text = NULL};
1212 centeredInfo.
text1 =
"Security risk detected";
1214 =
"This transaction or message cannot be decoded fully. If you choose to sign, you could "
1215 "be authorizing malicious actions that can drain your wallet.\n\n"
1216 "Learn more: ledger.com/e8";
1230 static void displayTipBoxModal(
void)
1235 .quitToken = QUIT_TOKEN,
1236 .navWithButtons.navToken = NAV_TOKEN,
1237 .navWithButtons.quitButton =
false,
1238 .navWithButtons.backButton =
true,
1239 .navWithButtons.quitText = NULL,
1240 .progressIndicator =
false,
1241 .tuneId = TUNE_TAP_CASUAL};
1243 .topRightIcon = NULL,
1244 .infosList.nbInfos = tipBoxInfoList.
nbInfos,
1246 .infosList.infoTypes = tipBoxInfoList.
infoTypes,
1249 .infosList.token = INFO_ALIAS_TOKEN,
1250 .
title = tipBoxModalTitle,
1251 .titleToken = QUIT_TOKEN};
1253 if (modalPageContext != NULL) {
1262 static void displayAddressQRCode(
void)
1266 .withLeftBorder =
true,
1267 .onActionCallback = &addressLayoutTouchCallbackQR,
1268 .tapActionText = NULL};
1276 addressConfirmationContext.modalLayout =
nbgl_layoutGet(&layoutDescription);
1281 SMALL_REGULAR_FONT, addressConfirmationContext.tagValuePair.value,
AVAILABLE_WIDTH,
false);
1283 if (nbLines <= QRCODE_NB_MAX_LINES) {
1284 qrCode.
text2 = addressConfirmationContext.tagValuePair.value;
1289 addressConfirmationContext.tagValuePair.value,
1291 QRCODE_NB_MAX_LINES,
1293 QRCODE_REDUCED_ADDR_LEN);
1294 qrCode.
text2 = reducedAddress;
1305 static void addressLayoutTouchCallbackQR(
int token,
uint8_t index)
1312 addressConfirmationContext.modalLayout = NULL;
1319 static void modalLayoutTouchCallback(
int token,
uint8_t index)
1326 genericContext.modalLayout = NULL;
1332 static void displaySkipWarning(
void)
1335 .cancelText =
"Go back to review",
1336 .centeredInfo.text1 =
"Skip review?",
1338 =
"If you're sure you don't need to review all fields, you can skip straight to signing.",
1339 .centeredInfo.text3 = NULL,
1341 .centeredInfo.icon = &C_Important_Circle_64px,
1342 .centeredInfo.offsetY = 0,
1343 .confirmationText =
"Yes, skip",
1344 .confirmationToken = SKIP_TOKEN,
1345 .tuneId = TUNE_TAP_CASUAL,
1347 if (modalPageContext != NULL) {
1359 static void updateKeyPad(
bool add)
1361 bool enableValidate, enableBackspace, enableDigits;
1362 bool redrawKeypad =
false;
1365 enableDigits = (keypadContext.pinLen < keypadContext.pinMaxDigits);
1366 enableValidate = (keypadContext.pinLen >= keypadContext.pinMinDigits);
1367 enableBackspace = (keypadContext.pinLen > 0);
1369 if ((keypadContext.pinLen == keypadContext.pinMinDigits)
1371 (keypadContext.pinLen == keypadContext.pinMaxDigits)
1373 (keypadContext.pinLen == 1)) {
1374 redrawKeypad =
true;
1378 if ((keypadContext.pinLen == 0) ||
1379 (keypadContext.pinLen == (keypadContext.pinMinDigits - 1))
1381 (keypadContext.pinLen
1382 == (keypadContext.pinMaxDigits - 1))) {
1383 redrawKeypad =
true;
1386 if (keypadContext.hidden ==
true) {
1391 keypadContext.layoutCtx,
false, 0, (
const char *) keypadContext.pinEntry);
1395 keypadContext.layoutCtx, 0, enableValidate, enableBackspace, enableDigits);
1398 if ((!add) && (keypadContext.pinLen == 0)) {
1406 static void keypadCallback(
char touchedKey)
1408 switch (touchedKey) {
1410 if (keypadContext.pinLen > 0) {
1411 keypadContext.pinLen--;
1412 keypadContext.pinEntry[keypadContext.pinLen] = 0;
1414 updateKeyPad(
false);
1423 onValidatePin(keypadContext.pinEntry, keypadContext.pinLen);
1427 if ((touchedKey >= 0x30) && (touchedKey < 0x40)) {
1428 if (keypadContext.pinLen < keypadContext.pinMaxDigits) {
1429 keypadContext.pinEntry[keypadContext.pinLen] = touchedKey;
1430 keypadContext.pinLen++;
1439 static void keypadGenericUseCase(
const char *title,
1445 tune_index_e tuneId,
1451 .separationLine =
true,
1452 .backAndText.token = backToken,
1453 .backAndText.tuneId = tuneId,
1454 .backAndText.text = NULL};
1463 memset(&keypadContext, 0,
sizeof(KeypadContext_t));
1467 layoutDescription.
modal =
false;
1470 keypadContext.hidden = hidden;
1482 keypadContext.layoutCtx, title, keypadContext.hidden, maxDigits,
"");
1489 onValidatePin = validatePinCallback;
1491 keypadContext.pinMinDigits = minDigits;
1492 keypadContext.pinMaxDigits = maxDigits;
1510 nbElements = getContentNbElement(content);
1512 while (nbElements > 0) {
1515 bool hasNav = !isLast || (pageIdxStart > 0) || (elemIdx > 0);
1537 nbElementsInPage =
MIN(nbMaxElementsPerContentType[content->
type], nbElements);
1540 elemIdx += nbElementsInPage;
1541 genericContextSetPageInfo(pageIdxStart + nbPages, nbElementsInPage, flag);
1542 nbElements -= nbElementsInPage;
1557 for (
int i = 0; i < genericContents->
nbContents; i++) {
1558 p_content = getContentAtIdx(genericContents, i, &content);
1559 if (p_content == NULL) {
1562 nbPages += nbgl_useCaseGetNbPagesForContent(p_content,
1563 pageIdxStart + nbPages,
1571 static void prepareAddressConfirmationPages(
const char *address,
1578 addressConfirmationContext.tagValuePair.item =
"Address";
1579 addressConfirmationContext.tagValuePair.value = address;
1588 if (tagValueList != NULL) {
1599 tagValueConfirm->tuneId = TUNE_TAP_CASUAL;
1607 if (tagValueList != NULL) {
1617 if (tagValueList != NULL) {
1625 tagValueConfirm->tuneId = TUNE_TAP_CASUAL;
1630 static void bundleNavStartHome(
void)
1632 nbgl_homeAndSettingsContext_t *context = &bundleNavContext.homeAndSettings;
1634 useCaseHomeExt(context->appName,
1637 context->settingContents != NULL ?
true :
false,
1638 &context->homeAction,
1639 bundleNavStartSettings,
1640 context->quitCallback);
1643 static void bundleNavStartSettingsAtPage(
uint8_t initSettingPage)
1645 nbgl_homeAndSettingsContext_t *context = &bundleNavContext.homeAndSettings;
1649 context->settingContents,
1651 bundleNavStartHome);
1654 static void bundleNavStartSettings(
void)
1656 bundleNavStartSettingsAtPage(0);
1659 static void bundleNavReviewConfirmRejection(
void)
1661 bundleNavContext.review.choiceCallback(
false);
1668 const char *confirmText;
1672 title =
"Reject transaction?";
1673 confirmText =
"Go back to transaction";
1676 title =
"Reject message?";
1677 confirmText =
"Go back to message";
1680 title =
"Reject operation?";
1681 confirmText =
"Go back to operation";
1688 static void bundleNavReviewChoice(
bool confirm)
1691 bundleNavContext.review.choiceCallback(
true);
1694 bundleNavReviewAskRejectionConfirmation(bundleNavContext.review.operationType,
1695 bundleNavReviewConfirmRejection);
1699 static void bundleNavReviewStreamingConfirmRejection(
void)
1701 bundleNavContext.reviewStreaming.choiceCallback(
false);
1704 static void bundleNavReviewStreamingChoice(
bool confirm)
1711 bundleNavContext.reviewStreaming.choiceCallback(
true);
1714 bundleNavReviewAskRejectionConfirmation(bundleNavContext.reviewStreaming.operationType,
1715 bundleNavReviewStreamingConfirmRejection);
1720 static void blindSigningWarningCallback(
bool confirm)
1723 blindSigningContext.choiceCallback(
false);
1726 if (blindSigningContext.isStreaming) {
1727 useCaseReviewStreamingStart(blindSigningContext.operationType,
1728 blindSigningContext.icon,
1729 blindSigningContext.reviewTitle,
1730 blindSigningContext.reviewSubTitle,
1731 blindSigningContext.choiceCallback,
1735 useCaseReview(blindSigningContext.operationType,
1736 blindSigningContext.tagValueList,
1737 blindSigningContext.icon,
1738 blindSigningContext.reviewTitle,
1739 blindSigningContext.reviewSubTitle,
1740 blindSigningContext.finishTitle,
1741 blindSigningContext.tipBox,
1742 blindSigningContext.choiceCallback,
1750 static void blindSigningWarning(
void)
1753 #ifdef HAVE_PIEZO_SOUND
1754 io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
1757 "Blind signing ahead",
1758 "The details of this transaction or message are not fully verifiable. If "
1759 "you sign it, you could lose all "
1763 blindSigningWarningCallback);
1770 const char *reviewTitle,
1771 const char *reviewSubTitle,
1772 const char *finishTitle,
1776 bool playNotifSound)
1779 memset(&genericContext, 0,
sizeof(genericContext));
1781 bundleNavContext.review.operationType = operationType;
1782 bundleNavContext.review.choiceCallback = choiceCallback;
1785 onChoice = bundleNavReviewChoice;
1786 navType = GENERIC_NAV;
1789 genericContext.genericContents.contentsList = localContentsList;
1790 genericContext.genericContents.nbContents = 3;
1795 prepareReviewFirstPage(
1796 &STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
1797 if (tipBox != NULL) {
1799 STARTING_CONTENT.content.extendedCenter.contentCenter.subText = NULL;
1801 STARTING_CONTENT.content.extendedCenter.tipBox.icon = tipBox->
icon;
1802 STARTING_CONTENT.content.extendedCenter.tipBox.text = tipBox->
text;
1803 STARTING_CONTENT.content.extendedCenter.tipBox.token = TIP_BOX_TOKEN;
1804 STARTING_CONTENT.content.extendedCenter.tipBox.tuneId = TUNE_TAP_CASUAL;
1818 memcpy(&localContentsList[1].content.tagValueList,
1826 prepareReviewLightLastPage(&localContentsList[2].content.infoButton, icon, finishTitle);
1830 prepareReviewLastPage(&localContentsList[2].content.infoLongPress, icon, finishTitle);
1834 uint8_t nbPages = getNbPagesForGenericContents(
1836 prepareNavInfo(
true, nbPages, getRejectReviewText(operationType));
1839 if (playNotifSound) {
1840 #ifdef HAVE_PIEZO_SOUND
1841 io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
1845 displayGenericContextPage(0,
true);
1851 const char *reviewTitle,
1852 const char *reviewSubTitle,
1854 bool playNotifSound)
1857 memset(&genericContext, 0,
sizeof(genericContext));
1859 bundleNavContext.reviewStreaming.operationType = operationType;
1860 bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
1861 bundleNavContext.reviewStreaming.icon = icon;
1864 onChoice = bundleNavReviewStreamingChoice;
1865 navType = STREAMING_NAV;
1868 genericContext.genericContents.contentsList = localContentsList;
1869 genericContext.genericContents.nbContents = 1;
1874 prepareReviewFirstPage(
1875 &STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
1878 bundleNavContext.reviewStreaming.stepPageNb = getNbPagesForGenericContents(
1885 if (playNotifSound) {
1886 #ifdef HAVE_PIEZO_SOUND
1887 io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
1891 displayGenericContextPage(0,
true);
1910 static void useCaseHomeExt(
const char *appName,
1912 const char *tagline,
1921 .centeredInfo.text1 = appName,
1922 .centeredInfo.text3 = NULL,
1924 .centeredInfo.offsetY = 0,
1927 .tapActionText = NULL,
1929 .topRightToken = CONTINUE_TOKEN,
1930 .tuneId = TUNE_TAP_CASUAL};
1931 if ((homeAction->
text != NULL) || (homeAction->
icon != NULL)) {
1946 if (tagline == NULL) {
1948 snprintf(appDescription,
1950 "This app enables signing\ntransactions on its network.");
1953 snprintf(appDescription,
1965 snprintf(appDescription,
1978 onContinue = topRightCallback;
1979 onQuit = quitCallback;
1993 static void displayDetails(
const char *tag,
const char *value,
bool wrapping)
1995 memset(&detailsContext, 0,
sizeof(detailsContext));
2001 detailsContext.tag = tag;
2002 detailsContext.value = value;
2004 detailsContext.currentPage = 0;
2005 detailsContext.wrapping = wrapping;
2007 if (detailsContext.nbPages > 1) {
2008 uint16_t nbLostChars = (detailsContext.nbPages - 1) * 3;
2017 detailsContext.nbPages++;
2021 displayDetailsPage(0,
true);
2043 bool *requireSpecificDisplay)
2046 nbPairs, tagValueList, startIndex,
false, requireSpecificDisplay);
2066 bool *requireSpecificDisplay)
2082 *requireSpecificDisplay =
false;
2083 while (nbPairsInPage < nbPairs) {
2090 if (nbPairsInPage > 0) {
2092 currentHeight += 12;
2094 currentHeight += 24;
2098 if (tagValueList->
pairs != NULL) {
2099 pair = PIC(&tagValueList->
pairs[startIndex + nbPairsInPage]);
2102 pair = PIC(tagValueList->
callback(startIndex + nbPairsInPage));
2111 if (nbPairsInPage > 0) {
2118 *requireSpecificDisplay =
true;
2130 value_font = SMALL_REGULAR_FONT;
2133 value_font = LARGE_MEDIUM_FONT;
2142 if (nbPairsInPage == 0) {
2146 *requireSpecificDisplay =
true;
2152 return nbPairsInPage;
2173 const char *
const *infoTypes = PIC(infosList->
infoTypes);
2174 const char *
const *infoContents = PIC(infosList->
infoContents);
2176 while (nbInfosInPage < nbInfos) {
2182 SMALL_BOLD_FONT, PIC(infoTypes[startIndex + nbInfosInPage]),
AVAILABLE_WIDTH,
true);
2188 PIC(infoContents[startIndex + nbInfosInPage]),
2201 previousHeight = currentHeight;
2204 return nbInfosInPage;
2227 while (nbSwitchesInPage < nbSwitches) {
2233 switchArray[startIndex + nbSwitchesInPage].text,
2242 switchArray[startIndex + nbSwitchesInPage].subText,
2255 previousHeight = currentHeight;
2258 return nbSwitchesInPage;
2283 while (nbBarsInPage < nbBars) {
2289 previousHeight = currentHeight;
2297 return nbBarsInPage;
2319 UNUSED(choicesList);
2322 while (nbChoicesInPage < nbChoices) {
2333 previousHeight = currentHeight;
2336 return nbChoicesInPage;
2353 while (i < tagValueList->nbPairs) {
2357 nbPairs -= nbPairsInPage;
2369 const char *tagline,
2376 appName, appIcon, tagline, withSettings, &homeAction, topRightCallback, quitCallback);
2385 const char *tagline,
2387 const char *actionButtonText,
2395 .text = actionButtonText};
2398 appName, appIcon, tagline, withSettings, &homeAction, topRightCallback, quitCallback);
2424 onQuit = quitCallback;
2425 onNav = navCallback;
2426 onControls = controlsCallback;
2428 navType = SETTINGS_NAV;
2431 prepareNavInfo(
false, nbPages, NULL);
2433 displaySettingsPage(initPage,
true);
2451 title, initPage, nbPages, quitCallback, navCallback, controlsCallback);
2473 memset(&genericContext, 0,
sizeof(genericContext));
2476 onQuit = quitCallback;
2477 pageTitle = appName;
2478 navType = GENERIC_NAV;
2480 if (settingContents != NULL) {
2483 if (infosList != NULL) {
2484 genericContext.hasFinishingContent =
true;
2487 memcpy(&FINISHING_CONTENT.content, infosList,
sizeof(
nbgl_content_u));
2491 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0,
false);
2492 if (infosList != NULL) {
2493 nbPages += nbgl_useCaseGetNbPagesForContent(&FINISHING_CONTENT, nbPages,
true,
false);
2496 prepareNavInfo(
false, nbPages, NULL);
2498 displayGenericContextPage(initPage,
true);
2537 const char *appName,
2539 const char *tagline,
2547 nbgl_homeAndSettingsContext_t *context = &bundleNavContext.homeAndSettings;
2549 context->appName = appName;
2550 context->appIcon = appIcon;
2551 context->tagline = tagline;
2552 context->settingContents = settingContents;
2553 context->infosList = infosList;
2554 if (action != NULL) {
2560 context->quitCallback = quitCallback;
2563 bundleNavStartSettingsAtPage(initSettingPage);
2566 bundleNavStartHome();
2582 .tickerCallback = &tickerCallback,
2583 .tickerIntervale = 0,
2586 onQuit = quitCallback;
2588 #ifdef HAVE_PIEZO_SOUND
2589 io_seproxyhal_play_tune(TUNE_LEDGER_MOMENT);
2597 .centeredInfo.icon = &C_Denied_Circle_64px,
2599 .centeredInfo.onTop =
false,
2601 .centeredInfo.text1 = message,
2602 .centeredInfo.text2 = NULL,
2603 .centeredInfo.text3 = NULL,
2604 .tapActionText =
"",
2605 .isSwipeable =
false,
2606 .tapActionToken = QUIT_TOKEN,
2608 .actionButtonText = NULL,
2609 .tuneId = TUNE_TAP_CASUAL};
2626 switch (reviewStatusType) {
2628 msg =
"Operation signed";
2632 msg =
"Operation rejected";
2636 msg =
"Transaction signed";
2640 msg =
"Transaction rejected";
2644 msg =
"Message signed";
2648 msg =
"Message rejected";
2652 msg =
"Address verified";
2656 msg =
"Address verification\ncancelled";
2678 const char *message,
2679 const char *subMessage,
2680 const char *confirmText,
2681 const char *cancelText,
2688 .centeredInfo.text2 = subMessage,
2689 .centeredInfo.text3 = NULL,
2691 .centeredInfo.icon = icon,
2692 .centeredInfo.offsetY = 0,
2693 .confirmationText = confirmText,
2694 .confirmationToken = CHOICE_TOKEN,
2695 .tuneId = TUNE_TAP_CASUAL,
2698 if ((confirmText == NULL) || (cancelText == NULL)) {
2701 onChoice = callback;
2720 const char *subMessage,
2721 const char *confirmText,
2722 const char *cancelText,
2728 .centeredInfo.text1 = message,
2729 .centeredInfo.text2 = subMessage,
2730 .centeredInfo.text3 = NULL,
2732 .centeredInfo.icon = &C_Important_Circle_64px,
2733 .centeredInfo.offsetY = 0,
2734 .confirmationText = confirmText,
2735 .confirmationToken = CHOICE_TOKEN,
2736 .tuneId = TUNE_TAP_CASUAL,
2738 onModalConfirm = callback;
2739 if (modalPageContext != NULL) {
2758 const char *reviewTitle,
2759 const char *reviewSubTitle,
2760 const char *rejectText,
2767 .footerToken = QUIT_TOKEN,
2768 .tapActionText = NULL,
2769 .isSwipeable =
true,
2770 .tapActionToken = CONTINUE_TOKEN,
2772 .actionButtonText = NULL,
2773 .tuneId = TUNE_TAP_CASUAL};
2780 onQuit = rejectCallback;
2781 onContinue = continueCallback;
2783 #ifdef HAVE_PIEZO_SOUND
2785 io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
2807 const char *rejectText,
2815 onChoice = choiceCallback;
2816 onNav = navCallback;
2817 onControls = buttonCallback;
2818 forwardNavOnly =
false;
2819 navType = REVIEW_NAV;
2823 prepareNavInfo(
true, nbPages, getRejectReviewText(
TYPE_OPERATION));
2825 displayReviewPage(initPage,
true);
2842 const char *rejectText,
2848 memset(&genericContext, 0,
sizeof(genericContext));
2851 onChoice = callback;
2852 navType = GENERIC_NAV;
2856 genericContext.genericContents.contentsList = localContentsList;
2859 if (tagValueList != NULL && tagValueList->
nbPairs != 0) {
2861 memcpy(&localContentsList[offset].content.tagValueList,
2868 memcpy(&localContentsList[offset].content.infoLongPress,
2874 genericContext.genericContents.nbContents = offset;
2877 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0,
false);
2879 prepareNavInfo(
true, nbPages, getRejectReviewText(
TYPE_OPERATION));
2881 displayGenericContextPage(0,
true);
2899 const char *rejectText,
2905 memset(&genericContext, 0,
sizeof(genericContext));
2908 onChoice = callback;
2909 navType = GENERIC_NAV;
2912 genericContext.genericContents.contentsList = localContentsList;
2915 if (tagValueList != NULL && tagValueList->
nbPairs != 0) {
2917 memcpy(&localContentsList[offset].content.tagValueList,
2931 genericContext.genericContents.nbContents = offset;
2934 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0,
false);
2936 prepareNavInfo(
true, nbPages, getRejectReviewText(
TYPE_OPERATION));
2938 displayGenericContextPage(0,
true);
2960 const char *reviewTitle,
2961 const char *reviewSubTitle,
2962 const char *finishTitle,
2965 useCaseReview(operationType,
2997 const char *reviewTitle,
2998 const char *reviewSubTitle,
2999 const char *finishTitle,
3003 useCaseReview(operationType,
3037 const char *reviewTitle,
3038 const char *reviewSubTitle,
3039 const char *finishTitle,
3043 memset(&blindSigningContext, 0,
sizeof(blindSigningContext));
3045 blindSigningContext.isStreaming =
false;
3047 blindSigningContext.tagValueList = tagValueList;
3048 blindSigningContext.icon = icon;
3049 blindSigningContext.reviewTitle = reviewTitle;
3050 blindSigningContext.reviewSubTitle = reviewSubTitle;
3051 blindSigningContext.finishTitle = finishTitle;
3052 blindSigningContext.tipBox = tipBox;
3053 blindSigningContext.choiceCallback = choiceCallback;
3055 blindSigningWarning();
3076 const char *reviewTitle,
3077 const char *reviewSubTitle,
3078 const char *finishTitle,
3081 useCaseReview(operationType,
3102 const char *rejectText,
3106 memset(&genericContext, 0,
sizeof(genericContext));
3109 onQuit = rejectCallback;
3110 navType = GENERIC_NAV;
3117 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0,
false);
3118 prepareNavInfo(
true, nbPages, rejectText);
3121 #ifdef HAVE_PIEZO_SOUND
3123 io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
3126 displayGenericContextPage(0,
true);
3143 const char *reviewTitle,
3144 const char *reviewSubTitle,
3147 useCaseReviewStreamingStart(
3148 operationType, icon, reviewTitle, reviewSubTitle, choiceCallback,
true);
3166 const char *reviewTitle,
3167 const char *reviewSubTitle,
3170 memset(&blindSigningContext, 0,
sizeof(blindSigningContext));
3172 blindSigningContext.isStreaming =
true;
3174 blindSigningContext.icon = icon;
3175 blindSigningContext.reviewTitle = reviewTitle;
3176 blindSigningContext.reviewSubTitle = reviewSubTitle;
3177 blindSigningContext.choiceCallback = choiceCallback;
3179 blindSigningWarning();
3200 memset(&genericContext, 0,
sizeof(genericContext));
3202 bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
3203 bundleNavContext.reviewStreaming.skipCallback = skipCallback;
3206 onChoice = bundleNavReviewStreamingChoice;
3207 navType = STREAMING_NAV;
3210 genericContext.genericContents.contentsList = localContentsList;
3211 genericContext.genericContents.nbContents = 1;
3220 bundleNavContext.reviewStreaming.stepPageNb = getNbPagesForGenericContents(
3221 &genericContext.genericContents,
3224 prepareNavInfo(
true,
3226 getRejectReviewText(bundleNavContext.reviewStreaming.operationType));
3234 displayGenericContextPage(0,
true);
3265 memset(&genericContext, 0,
sizeof(genericContext));
3267 bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
3270 onChoice = bundleNavReviewStreamingChoice;
3271 navType = STREAMING_NAV;
3274 genericContext.genericContents.contentsList = localContentsList;
3275 genericContext.genericContents.nbContents = 1;
3280 prepareReviewLastPage(&STARTING_CONTENT.content.infoLongPress,
3281 bundleNavContext.reviewStreaming.icon,
3285 bundleNavContext.reviewStreaming.stepPageNb = getNbPagesForGenericContents(
3286 &genericContext.genericContents,
3289 prepareNavInfo(
true, 1, getRejectReviewText(bundleNavContext.reviewStreaming.operationType));
3291 displayGenericContextPage(0,
true);
3303 memset(&genericContext, 0,
sizeof(genericContext));
3304 memset(&addressConfirmationContext, 0,
sizeof(addressConfirmationContext));
3307 onChoice = callback;
3308 navType = GENERIC_NAV;
3311 genericContext.genericContents.contentsList = localContentsList;
3312 genericContext.genericContents.nbContents = (tagValueList == NULL) ? 1 : 2;
3314 prepareAddressConfirmationPages(
3315 address, tagValueList, &STARTING_CONTENT, &localContentsList[1]);
3318 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0,
false);
3320 prepareNavInfo(
true, nbPages,
"Cancel");
3322 #ifdef HAVE_PIEZO_SOUND
3324 io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
3327 displayGenericContextPage(0,
true);
3349 const char *reviewTitle,
3350 const char *reviewSubTitle,
3354 memset(&genericContext, 0,
sizeof(genericContext));
3356 if (addressConfirmationContext.modalLayout) {
3359 memset(&addressConfirmationContext, 0,
sizeof(addressConfirmationContext));
3362 onChoice = choiceCallback;
3363 navType = GENERIC_NAV;
3367 genericContext.genericContents.contentsList = localContentsList;
3368 genericContext.genericContents.nbContents = (additionalTagValueList == NULL) ? 2 : 3;
3373 prepareReviewFirstPage(
3374 &STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
3375 STARTING_CONTENT.content.extendedCenter.contentCenter.subText =
"Swipe to continue";
3378 prepareAddressConfirmationPages(
3379 address, additionalTagValueList, &localContentsList[1], &localContentsList[2]);
3382 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0,
false);
3384 prepareNavInfo(
true, nbPages,
"Cancel");
3386 #ifdef HAVE_PIEZO_SOUND
3388 io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
3391 displayGenericContextPage(0,
true);
3431 tune_index_e tuneId,
3435 keypadGenericUseCase(title,
3442 validatePinCallback,
3469 tune_index_e tuneId,
3473 keypadGenericUseCase(title,
3480 validatePinCallback,
@ LARGE_CASE_INFO
text in BLACK and large case (INTER 32px), subText in black in Inter24px
nbgl_contentTagValue_t *(* nbgl_contentTagValueCallback_t)(uint8_t pairIndex)
prototype of tag/value pair retrieval callback
@ 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
@ 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
#define LOG_DEBUG(__logger,...)
bool nbgl_getTextMaxLenInNbLines(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, uint16_t maxNbLines, uint16_t *len, bool wrapping)
compute the len of the given text (in bytes) fitting in the given maximum nb lines,...
void nbgl_textReduceOnNbLines(nbgl_font_id_e fontId, const char *origText, uint16_t maxWidth, uint8_t nbLines, char *reducedText, uint16_t reducedTextLen)
Create a reduced version of given ASCII text to wrap it on the given max width (in pixels),...
uint16_t nbgl_getTextHeightInWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, bool wrapping)
return the height of the given multiline text, with the given font.
uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, bool wrapping)
compute the number of lines of the given text fitting in the given maxWidth
void(* nbgl_layoutTouchCallback_t)(int token, uint8_t index)
prototype of function to be called when an object is touched
#define SIMPLE_FOOTER_HEIGHT
int nbgl_layoutAddTextContent(nbgl_layout_t *layout, const char *title, const char *description, const char *info)
Creates in the main container three text areas:
int nbgl_layoutUpdateKeypad(nbgl_layout_t *layout, uint8_t index, bool enableValidate, bool enableBackspace, bool enableDigits)
Updates an existing keypad on bottom of the screen, with the given configuration.
#define TEXT_SUBTEXT_MARGIN
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_layoutAddCenteredInfo(nbgl_layout_t *layout, const nbgl_layoutCenteredInfo_t *info)
Creates an area on the center of the main panel, with a possible icon/image, a possible text in black...
#define TOUCHABLE_BAR_HEIGHT
int nbgl_layoutDraw(nbgl_layout_t *layout)
Applies given layout. The screen will be redrawn.
@ WHITE_BACKGROUND
rounded bordered button, with text/icon in black, on white background
@ BLACK_BACKGROUND
rounded bordered button, with text/icon in white, on black background
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
#define SMALL_FOOTER_HEIGHT
int nbgl_layoutAddKeypadContent(nbgl_layout_t *layout, const char *title, bool hidden, uint8_t nbDigits, const char *text)
Adds an area with a title and a placeholder for hidden digits on top of a keypad, to represent the en...
int nbgl_layoutUpdateKeypadContent(nbgl_layout_t *layout, bool hidden, uint8_t nbActiveDigits, const char *text)
Updates an existing set of hidden digits, with the given configuration.
#define NBGL_NO_PROGRESS_INDICATOR
To be used when a control token shall not be used.
#define POST_SUBTEXT_MARGIN
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 SMALL_CENTERING_HEADER
int nbgl_layoutRelease(nbgl_layout_t *layout)
Release the layout obtained with nbgl_layoutGet()
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_layout_t * nbgl_layoutGet(const nbgl_layoutDescription_t *description)
returns a layout of the given type. The layout is reset
#define TOUCHABLE_HEADER_BAR_HEIGHT
void nbgl_refresh(void)
This functions refreshes the actual screen on display with what has changed since the last refresh.
#define KEYPAD_MAX_DIGITS
void nbgl_refreshSpecial(nbgl_refresh_mode_t mode)
This functions refreshes the actual screen on display with what has changed since the last refresh,...
void nbgl_refreshSpecialWithPostRefresh(nbgl_refresh_mode_t mode, nbgl_post_refresh_t post_refresh)
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,...
nbgl_page_t * nbgl_pageDrawSpinner(nbgl_layoutTouchCallback_t onActionCallback, const char *text)
draw a spinner page with the given parameters. The spinner will "rotate" automatically every 800 ms
nbgl_page_t * nbgl_pageDrawLedgerInfo(nbgl_layoutTouchCallback_t onActionCallback, const nbgl_screenTickerConfiguration_t *ticker, const char *text, int tapActionToken)
draw a page with a centered text in large case, with a round check icon
void * nbgl_page_t
type shared externally
@ NAV_WITH_BUTTONS
move forward and backward with buttons in bottom nav bar
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,...
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...
int nbgl_pageRelease(nbgl_page_t *)
Release the page obtained with any of the nbgl_pageDrawXXX() functions.
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...
@ QUIT_APP_TEXT
A full width button with "Quit app" text (only for bottom button)
@ INFO_ICON
info (i) icon in the button.
@ NO_BUTTON_STYLE
no button.
@ SETTINGS_ICON
settings (wheel) icon in the button.
struct PACKED__ nbgl_screenTickerConfiguration_s nbgl_screenTickerConfiguration_t
struct to configure a screen layer
void nbgl_screenRedraw(void)
This function redraws the whole screen on top of stack and its children.
@ POST_REFRESH_FORCE_POWER_ON
Force screen power on after refresh.
struct PACKED__ nbgl_icon_details_s nbgl_icon_details_t
Represents all information about an icon.
nbgl_refresh_mode_t
different modes of refresh for nbgl_refreshSpecial()
@ FULL_COLOR_CLEAN_REFRESH
to be used for lock screen display (cleaner but longer refresh)
@ BLACK_AND_WHITE_FAST_REFRESH
to be used for pure B&W area, when contrast is not priority
@ FULL_COLOR_PARTIAL_REFRESH
to be used for small partial refresh (radio buttons, switches)
@ FULL_COLOR_REFRESH
to be used for normal refresh
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
DEPRECATED void nbgl_useCaseSettings(const char *settingsTitle, uint8_t initPage, uint8_t nbPages, bool touchableTitle, nbgl_callback_t quitCallback, nbgl_navCallback_t navCallback, nbgl_layoutTouchCallback_t controlsCallback)
uint8_t nbgl_useCaseGetNbTagValuesInPageExt(uint8_t nbPairs, const nbgl_contentTagValueList_t *tagValueList, uint8_t startIndex, bool isSkippable, bool *requireSpecificDisplay)
void(* nbgl_callback_t)(void)
prototype of generic callback function
#define SKIPPABLE_OPERATION
This is to use in nbgl_operationType_t when the operation is skippable. This is used.
void nbgl_useCaseGenericSettings(const char *appName, uint8_t initPage, const nbgl_genericContents_t *settingContents, const nbgl_contentInfoList_t *infosList, nbgl_callback_t quitCallback)
void nbgl_useCaseKeypadPIN(const char *title, uint8_t minDigits, uint8_t maxDigits, uint8_t backToken, bool shuffled, tune_index_e tuneId, nbgl_pinValidCallback_t validatePinCallback, nbgl_layoutTouchCallback_t actionCallback)
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)
uint8_t nbgl_useCaseGetNbTagValuesInPage(uint8_t nbPairs, const nbgl_contentTagValueList_t *tagValueList, uint8_t startIndex, bool *requireSpecificDisplay)
uint8_t nbgl_useCaseGetNbPagesForTagValueList(const nbgl_contentTagValueList_t *tagValueList)
void nbgl_useCaseReviewStreamingStart(nbgl_operationType_t operationType, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, nbgl_choiceCallback_t choiceCallback)
void nbgl_useCaseHomeAndSettings(const char *appName, const nbgl_icon_details_t *appIcon, const char *tagline, const uint8_t initSettingPage, const nbgl_genericContents_t *settingContents, const nbgl_contentInfoList_t *infosList, const nbgl_homeAction_t *action, nbgl_callback_t quitCallback)
void nbgl_useCaseStaticReviewLight(const nbgl_contentTagValueList_t *tagValueList, const nbgl_pageInfoLongPress_t *infoLongPress, const char *rejectText, nbgl_choiceCallback_t callback)
uint8_t nbgl_useCaseGetNbInfosInPage(uint8_t nbInfos, const nbgl_contentInfoList_t *infosList, uint8_t startIndex, bool withNav)
void(* nbgl_choiceCallback_t)(bool confirm)
prototype of choice callback function
uint8_t nbgl_useCaseGetNbBarsInPage(uint8_t nbBars, const nbgl_contentBarsList_t *barsList, uint8_t startIndex, bool withNav)
void nbgl_useCaseNavigableContent(const char *title, uint8_t initPage, uint8_t nbPages, nbgl_callback_t quitCallback, nbgl_navCallback_t navCallback, nbgl_layoutTouchCallback_t controlsCallback)
#define INFOS_AREA_HEIGHT
height available for infos pairs display
@ STRONG_HOME_ACTION
Black button, implicating the main action of the App.
void nbgl_useCaseReviewStreamingFinish(const char *finishTitle, nbgl_choiceCallback_t choiceCallback)
void nbgl_useCaseSpinner(const char *text)
void nbgl_useCaseConfirm(const char *message, const char *subMessage, const char *confirmText, const char *rejectText, nbgl_callback_t callback)
#define NB_MAX_LINES_IN_DETAILS
maximum number of lines for value field in details pages
void nbgl_useCaseReviewStart(const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, const char *rejectText, nbgl_callback_t continueCallback, nbgl_callback_t rejectCallback)
DEPRECATED void nbgl_useCaseHomeExt(const char *appName, const nbgl_icon_details_t *appIcon, const char *tagline, bool withSettings, const char *actionButtonText, nbgl_callback_t actionCallback, nbgl_callback_t topRightCallback, nbgl_callback_t quitCallback)
void nbgl_useCaseKeypadDigits(const char *title, uint8_t minDigits, uint8_t maxDigits, uint8_t backToken, bool shuffled, tune_index_e tuneId, nbgl_pinValidCallback_t validatePinCallback, nbgl_layoutTouchCallback_t actionCallback)
#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)
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_useCaseReviewStreamingContinueExt(const nbgl_contentTagValueList_t *tagValueList, nbgl_choiceCallback_t choiceCallback, nbgl_callback_t skipCallback)
void nbgl_useCaseReviewBlindSigning(nbgl_operationType_t operationType, const nbgl_contentTagValueList_t *tagValueList, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, const char *finishTitle, const nbgl_tipBox_t *tipBox, nbgl_choiceCallback_t choiceCallback)
void nbgl_useCaseChoice(const nbgl_icon_details_t *icon, const char *message, const char *subMessage, const char *confirmText, const char *rejectString, nbgl_choiceCallback_t callback)
#define TAG_VALUE_AREA_HEIGHT
height available for tag/value pairs display
#define BLIND_OPERATION
This is to use in nbgl_operationType_t when the operation is "blind" This is used to indicate a warni...
#define TAGLINE_PART1
Default strings used in the Home tagline.
void nbgl_useCaseGenericReview(const nbgl_genericContents_t *contents, const char *rejectText, nbgl_callback_t rejectCallback)
void nbgl_useCaseRegularReview(uint8_t initPage, uint8_t nbPages, const char *rejectText, nbgl_layoutTouchCallback_t buttonCallback, nbgl_navCallback_t navCallback, nbgl_choiceCallback_t choiceCallback)
void nbgl_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_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, 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_useCaseReviewStatus(nbgl_reviewStatusType_t reviewStatusType, nbgl_callback_t quitCallback)
#define LAST_PAGE_FOR_REVIEW
value of page parameter used with navigation callback when "skip" button is touched,...
nbgl_reviewStatusType_t
The different types of review status.
@ STATUS_TYPE_TRANSACTION_REJECTED
@ STATUS_TYPE_ADDRESS_REJECTED
@ STATUS_TYPE_TRANSACTION_SIGNED
@ STATUS_TYPE_OPERATION_REJECTED
@ STATUS_TYPE_OPERATION_SIGNED
@ STATUS_TYPE_ADDRESS_VERIFIED
@ STATUS_TYPE_MESSAGE_SIGNED
@ STATUS_TYPE_MESSAGE_REJECTED
bool(* nbgl_navCallback_t)(uint8_t page, nbgl_pageContent_t *content)
prototype of navigation callback function
#define MAX_APP_NAME_FOR_SDK_TAGLINE
Max supported length of appName used for the default Home tagline.
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_TRANSACTION
For operations transferring a coin or taken from an account to another.
@ TYPE_OPERATION
For other types of operation (generic type)
void(* nbgl_pinValidCallback_t)(const uint8_t *content, uint8_t page)
prototype of pin validation callback function
uint8_t nbgl_useCaseGetNbSwitchesInPage(uint8_t nbSwitches, const nbgl_contentSwitchesList_t *switchesList, uint8_t startIndex, bool withNav)
This structure contains data to build a BARS_LIST content.
const uint8_t * tokens
array of tokens, one for each bar (nbBars items)
const char *const * barTexts
array of texts for each bar (nbBars items, in black/bold)
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)
This structure contains info to build a centered (vertically and horizontally) area,...
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
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
This structure contains data to build a INFOS_LIST content.
uint8_t nbInfos
number of elements in infoTypes and infoContents array
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
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),...
This structure contains [item,value] pair(s) and info about a potential "details" button,...
const char * confirmationText
text of the confirmation button, if NULL "It matches" is used
uint8_t detailsButtonToken
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
This structure contains a list of [tag,value] pairs.
nbgl_contentActionCallback_t actionCallback
called when a valueIcon is touched on a given pair
const nbgl_contentTagValue_t * pairs
array of [tag,value] pairs (nbPairs items). If NULL, callback is used instead
bool wrapping
if set to true, value text will be wrapped on ' ' to avoid cutting words
uint8_t startIndex
index of the first pair to get with callback
nbgl_contentTagValueCallback_t callback
function to call to retrieve a given pair
uint8_t nbMaxLinesForValue
This structure contains a [tag,value] pair.
const nbgl_contentValueExt_t * extension
if not NULL, gives additional info on value field
const nbgl_icon_details_t * valueIcon
int8_t centeredInfo
if set to 1, the tag will be displayed as a centered info
const char * value
string giving the value name
const char * item
string giving the tag name
This structure contains additions to a tag/value pair, to be able to build a screen to display these ...
const char * fullValue
full string of the value when used as an alias
nbgl_contentValueAliasType_t aliasType
type of alias
This structure contains data to build a content.
nbgl_contentActionCallback_t contentActionCallback
callback to be called when an action on an object occurs
nbgl_contentType_t type
type of page content in the content union
uint8_t 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
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
Structure containing all information when creating a layout. This structure must be passed as argumen...
nbgl_layoutTouchCallback_t onActionCallback
the callback to be called on any action on the layout
This structure contains info to build a centered (vertically and horizontally) area,...
const char * text2
second text (can be null)
const char * url
URL for QR code.
Structure containing all specific information when creating a confirmation page.
const char * cancelText
the text used for cancel action, if NULL a simple X button is used
nbgl_layoutCenteredInfo_t centeredInfo
description of the centered info to be used
Structure containing all specific information when creating an information page.
nbgl_layoutButtonStyle_t actionButtonStyle
style of "action" button
const char * actionButtonText
if not NULL an "action" button is set under the centered info
uint8_t bottomButtonsToken
const nbgl_icon_details_t * actionButtonIcon
potential icon of "action" button
nbgl_pageButtonStyle_t bottomButtonStyle
style to apply to the Bottom button
nbgl_layoutCenteredInfo_t centeredInfo
description of the centered info to be used
Structure containing all specific information when creating a multi-screens page.
uint8_t nbPages
the number of pages to display (if <2, no navigation bar)
uint8_t quitToken
the token used as argument of the actionCallback when the footer is touched
uint8_t skipToken
if skipText is NULL the token used when right part of footer is touched
nbgl_pageNavigationType_t navType
uint8_t activePage
the index of the page to display at start-up
bool progressIndicator
if set to true, display a progress indicator on top of the page
nbgl_pageNavWithButtons_t navWithButtons
structure used when navigation with buttons
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played when next or back is pressed
bool visiblePageIndicator
if set to true, the page indicator will be visible in navigation
const char * quitText
the text displayed in footer (on the left), used to quit (only on Flex)
bool backButton
if set to true, a back button (<-) is displayed in the nav bar
This structure contains data to build a SWITCHES_LIST content.
uint8_t nbSwitches
number of elements in switches and tokens array
const nbgl_contentSwitch_t * switches
array of switches (nbSwitches items)
Structure containing all specific information when creating a NBGL step.
The necessary parameters to build a tip-box in first review page and the modal if this tip box is tou...
const nbgl_contentInfoList_t infos
infos pairs displayed in modal.
const char * modalTitle
title given to modal window displayed when tip-box is touched
const char * text
text of the tip-box
nbgl_contentType_t type
type of page content in the following union
const nbgl_icon_details_t * icon
icon of the tip-box
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