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;
422 const char *finishTitle)
424 infoLongPress->
text = finishTitle;
425 infoLongPress->
icon = icon;
432 const char *finishTitle)
434 infoButton->
text = finishTitle;
435 infoButton->
icon = icon;
442 UNUSED(operationType);
448 static void pageModalCallback(
int token,
uint8_t index)
452 if (token == INFO_ALIAS_TOKEN) {
454 displayFullValuePage(tipBoxInfoList.
infoTypes[index],
460 modalPageContext = NULL;
461 if (token == NAV_TOKEN) {
468 displayDetailsPage(index,
false);
471 if (token == QUIT_TOKEN) {
476 else if (token == SKIP_TOKEN) {
487 else if (token == CHOICE_TOKEN) {
489 if (onModalConfirm != NULL) {
502 static void pageCallback(
int token,
uint8_t index)
505 if (token == QUIT_TOKEN) {
506 if (onQuit != NULL) {
510 else if (token == CONTINUE_TOKEN) {
511 if (onContinue != NULL) {
515 else if (token == CHOICE_TOKEN) {
516 if (onChoice != NULL) {
517 onChoice((index == 0) ?
true :
false);
520 else if (token == ACTION_BUTTON_TOKEN) {
521 if ((index == 0) && (onAction != NULL)) {
524 else if ((index == 1) && (onQuit != NULL)) {
529 else if (token == ADDRESS_QRCODE_BUTTON_TOKEN) {
530 displayAddressQRCode();
533 else if (token == CONFIRM_TOKEN) {
534 if (onChoice != NULL) {
538 else if (token == REJECT_TOKEN) {
539 if (onChoice != NULL) {
543 else if (token == DETAILS_BUTTON_TOKEN) {
544 displayDetails(genericContext.detailsItem,
545 genericContext.detailsvalue,
546 genericContext.detailsWrapping);
548 else if (token == NAV_TOKEN) {
550 if (onQuit != NULL) {
555 if (navType == GENERIC_NAV || navType == STREAMING_NAV) {
556 displayGenericContextPage(index,
false);
558 else if (navType == REVIEW_NAV) {
559 displayReviewPage(index,
false);
562 displaySettingsPage(index,
false);
566 else if (token == NEXT_TOKEN) {
568 displayReviewPage(navInfo.
activePage + 1,
false);
571 displayGenericContextPage(navInfo.
activePage + 1,
false);
574 else if (token == BACK_TOKEN) {
576 displayReviewPage(navInfo.
activePage - 1,
true);
579 displayGenericContextPage(navInfo.
activePage - 1,
false);
582 else if (token == SKIP_TOKEN) {
584 displaySkipWarning();
586 else if (token == VALUE_ALIAS_TOKEN) {
589 if (genericContext.currentPairs != NULL) {
590 pair = &genericContext.currentPairs[genericContext.currentElementIdx + index];
593 pair = genericContext.currentCallback(genericContext.currentElementIdx + index);
597 else if (token == BLIND_WARNING_TOKEN) {
598 displayBlindWarning();
600 else if (token == TIP_BOX_TOKEN) {
601 displayTipBoxModal();
604 if (onContentAction != NULL) {
605 onContentAction(token, index, navInfo.
activePage);
607 if (onControls != NULL) {
608 onControls(token, index);
614 static void tickerCallback(
void)
617 if (onQuit != NULL) {
623 static void displaySettingsPage(
uint8_t page,
bool forceFullRefresh)
627 if ((onNav == NULL) || (onNav(page, &content) ==
false)) {
632 content.title = pageTitle;
633 content.isTouchableTitle =
true;
634 content.titleToken = QUIT_TOKEN;
635 content.tuneId = TUNE_TAP_CASUAL;
640 if (forceFullRefresh) {
649 static void displayReviewPage(
uint8_t page,
bool forceFullRefresh)
658 if ((onNav == NULL) || (onNav(navInfo.
activePage, &content) ==
false)) {
663 content.title = NULL;
664 content.isTouchableTitle =
false;
665 content.tuneId = TUNE_TAP_CASUAL;
671 content.infoLongPress.longPressToken = CONFIRM_TOKEN;
672 if (forwardNavOnly) {
680 content.tagValueDetails.tagValueList.smallCaseForValue =
false;
686 content.tagValueList.smallCaseForValue =
false;
689 content.tagValueConfirm.tagValueList.smallCaseForValue =
false;
691 content.tagValueConfirm.confirmationToken = CONFIRM_TOKEN;
696 if (forceFullRefresh) {
708 uint8_t *p_nbElementsInNextPage,
711 int8_t nextContentIdx = genericContext.currentContentIdx;
712 int16_t nextElementIdx = genericContext.currentElementIdx;
716 genericContextGetPageInfo(pageIdx, &nbElementsInNextPage, p_flag);
717 *p_nbElementsInNextPage = nbElementsInNextPage;
722 uint8_t nbElementsInCurrentPage;
724 genericContextGetPageInfo(navInfo.
activePage, &nbElementsInCurrentPage, NULL);
725 nextElementIdx += nbElementsInCurrentPage;
730 if ((nextElementIdx >= genericContext.currentContentElementNb)
731 && (genericContext.currentContentElementNb > 0)) {
741 nextElementIdx -= nbElementsInNextPage;
747 if (nextElementIdx < 0) {
749 nextElementIdx = -nbElementsInNextPage;
755 if ((nextContentIdx == -1) && (genericContext.hasStartingContent)) {
756 p_content = &STARTING_CONTENT;
758 else if ((nextContentIdx == genericContext.genericContents.nbContents)
759 && (genericContext.hasFinishingContent)) {
760 p_content = &FINISHING_CONTENT;
763 p_content = getContentAtIdx(&genericContext.genericContents, nextContentIdx, content);
765 if (p_content == NULL) {
780 if ((nextContentIdx != genericContext.currentContentIdx)
781 || (genericContext.currentContentElementNb == 0)) {
782 genericContext.currentContentIdx = nextContentIdx;
783 genericContext.currentContentElementNb = getContentNbElement(p_content);
785 if (nextElementIdx < 0) {
786 nextElementIdx = genericContext.currentContentElementNb + nextElementIdx;
791 if ((nextElementIdx < 0) || (nextElementIdx >= genericContext.currentContentElementNb)) {
793 "Invalid element index %d / %d\n",
795 genericContext.currentContentElementNb);
800 genericContext.currentElementIdx = nextElementIdx;
808 static bool genericContextPreparePageContent(
const nbgl_content_t *p_content,
813 uint8_t nextElementIdx = genericContext.currentElementIdx;
815 pageContent->title = pageTitle;
816 pageContent->isTouchableTitle =
false;
817 pageContent->titleToken = QUIT_TOKEN;
818 pageContent->tuneId = TUNE_TAP_CASUAL;
820 pageContent->type = p_content->
type;
821 switch (pageContent->type) {
823 memcpy(&pageContent->centeredInfo,
825 sizeof(pageContent->centeredInfo));
828 memcpy(&pageContent->extendedCenter,
830 sizeof(pageContent->extendedCenter));
833 memcpy(&pageContent->infoLongPress,
835 sizeof(pageContent->infoLongPress));
839 memcpy(&pageContent->infoButton,
841 sizeof(pageContent->infoButton));
867 prepareReviewFirstPage(&pageContent->extendedCenter.contentCenter,
873 p_tagValueList = NULL;
878 pageContent->tagValueDetails.detailsButtonText =
"More";
879 pageContent->tagValueDetails.detailsButtonIcon = NULL;
880 pageContent->tagValueDetails.detailsButtonToken = DETAILS_BUTTON_TOKEN;
882 p_tagValueList = &pageContent->tagValueDetails.tagValueList;
885 genericContext.detailsItem = pair->
item;
886 genericContext.detailsvalue = pair->
value;
891 if (p_tagValueList != NULL) {
892 p_tagValueList->
nbPairs = nbElementsInPage;
895 p_tagValueList->
pairs
898 for (
uint8_t i = 0; i < nbElementsInPage; i++) {
900 p_tagValueList->
token = VALUE_ALIAS_TOKEN;
906 p_tagValueList->
pairs = NULL;
910 for (
uint8_t i = 0; i < nbElementsInPage; i++) {
914 p_tagValueList->
token = VALUE_ALIAS_TOKEN;
927 memcpy(&pageContent->tagValueConfirm,
929 sizeof(pageContent->tagValueConfirm));
932 pageContent->switchesList.nbSwitches = nbElementsInPage;
933 pageContent->switchesList.switches
937 pageContent->infosList.nbInfos = nbElementsInPage;
938 pageContent->infosList.infoTypes
940 pageContent->infosList.infoContents
944 memcpy(&pageContent->choicesList,
946 sizeof(pageContent->choicesList));
947 pageContent->choicesList.nbChoices = nbElementsInPage;
948 pageContent->choicesList.names
952 < nextElementIdx + nbElementsInPage)) {
953 pageContent->choicesList.initChoice
957 pageContent->choicesList.initChoice = nbElementsInPage;
961 pageContent->barsList.nbBars = nbElementsInPage;
962 pageContent->barsList.barTexts
972 bool isFirstOrLastPage
975 bool isStreamingNavAndBlindOperation
976 = (navType == STREAMING_NAV)
978 bool isGenericNavAndBlindOperation
979 = (navType == GENERIC_NAV) && (bundleNavContext.review.operationType &
BLIND_OPERATION);
982 if (isFirstOrLastPage && (isStreamingNavAndBlindOperation || isGenericNavAndBlindOperation)) {
984 pageContent->topRightToken = BLIND_WARNING_TOKEN;
991 static void displayGenericContextPage(
uint8_t pageIdx,
bool forceFullRefresh)
999 if (navType == STREAMING_NAV) {
1001 if (bundleNavContext.reviewStreaming.skipCallback != NULL) {
1002 bundleNavContext.reviewStreaming.skipCallback();
1006 else if (pageIdx >= bundleNavContext.reviewStreaming.stepPageNb) {
1007 bundleNavReviewStreamingChoice(
true);
1014 = genericContextComputeNextPageParams(pageIdx, &content, &nbElementsInPage, &flag);
1019 for (
int i = navInfo.
activePage + 1; i <= pageIdx; i++) {
1020 p_content = genericContextComputeNextPageParams(i, &content, &nbElementsInPage, &flag);
1030 = genericContextComputeNextPageParams(pageIdx, &content, &nbElementsInPage, &flag);
1033 if (p_content == NULL) {
1039 if (!genericContextPreparePageContent(p_content, nbElementsInPage, flag, &pageContent)) {
1045 if (forceFullRefresh) {
1054 static const char *getDetailsPageAt(
uint8_t detailsPage)
1057 const char *currentChar = detailsContext.value;
1058 while (page < detailsPage) {
1068 detailsContext.wrapping);
1070 currentChar = currentChar + len;
1078 static void displayDetailsPage(
uint8_t detailsPage,
bool forceFullRefresh)
1082 .nbPages = detailsContext.nbPages,
1084 .quitToken = QUIT_TOKEN,
1085 .navWithButtons.navToken = NAV_TOKEN,
1086 .navWithButtons.quitButton =
true,
1087 .navWithButtons.backButton =
true,
1088 .navWithButtons.quitText = NULL,
1089 .progressIndicator =
false,
1090 .tuneId = TUNE_TAP_CASUAL};
1092 .topRightIcon = NULL,
1093 .tagValueList.nbPairs = 1,
1094 .tagValueList.pairs = ¤tPair,
1095 .tagValueList.smallCaseForValue =
true,
1096 .tagValueList.wrapping = detailsContext.wrapping};
1098 if (modalPageContext != NULL) {
1101 currentPair.
item = detailsContext.tag;
1103 if (detailsPage <= detailsContext.currentPage) {
1105 currentPair.
value = getDetailsPageAt(detailsPage);
1106 forceFullRefresh =
true;
1110 currentPair.
value = detailsContext.nextPageStart;
1112 detailsContext.currentPage = detailsPage;
1123 detailsContext.wrapping);
1126 detailsContext.nextPageStart = currentPair.
value + len;
1132 detailsContext.nextPageStart = NULL;
1133 content.tagValueList.nbMaxLinesForValue = 0;
1141 if (forceFullRefresh) {
1150 static void displayFullValuePage(
const char *backText,
1151 const char *aliasText,
1155 .withLeftBorder =
true,
1156 .onActionCallback = &modalLayoutTouchCallback,
1157 .tapActionText = NULL};
1159 .separationLine =
false,
1160 .backAndText.token = 0,
1161 .backAndText.tuneId = TUNE_TAP_CASUAL,
1162 .backAndText.text = PIC(backText)};
1183 info =
"ENS names are resolved by Ledger backend.";
1186 info =
"This account label comes from your Address Book in Ledger Live.";
1192 genericContext.modalLayout, aliasText, extension->
fullValue, info);
1200 static void displayBlindWarning(
void)
1203 .withLeftBorder =
true,
1204 .onActionCallback = &modalLayoutTouchCallback,
1205 .tapActionText = NULL};
1207 .separationLine =
false,
1208 .backAndText.token = 0,
1209 .backAndText.tuneId = TUNE_TAP_CASUAL,
1210 .backAndText.text = NULL};
1213 centeredInfo.
text1 =
"Security risk detected";
1215 =
"This transaction or message cannot be decoded fully. If you choose to sign, you could "
1216 "be authorizing malicious actions that can drain your wallet.\n\n"
1217 "Learn more: ledger.com/e8";
1231 static void displayTipBoxModal(
void)
1236 .quitToken = QUIT_TOKEN,
1237 .navWithButtons.navToken = NAV_TOKEN,
1238 .navWithButtons.quitButton =
false,
1239 .navWithButtons.backButton =
true,
1240 .navWithButtons.quitText = NULL,
1241 .progressIndicator =
false,
1242 .tuneId = TUNE_TAP_CASUAL};
1244 .topRightIcon = NULL,
1245 .infosList.nbInfos = tipBoxInfoList.
nbInfos,
1247 .infosList.infoTypes = tipBoxInfoList.
infoTypes,
1250 .infosList.token = INFO_ALIAS_TOKEN,
1251 .
title = tipBoxModalTitle,
1252 .titleToken = QUIT_TOKEN,
1253 .tuneId = TUNE_TAP_CASUAL};
1255 if (modalPageContext != NULL) {
1264 static void displayAddressQRCode(
void)
1268 .withLeftBorder =
true,
1269 .onActionCallback = &addressLayoutTouchCallbackQR,
1270 .tapActionText = NULL};
1278 addressConfirmationContext.modalLayout =
nbgl_layoutGet(&layoutDescription);
1283 SMALL_REGULAR_FONT, addressConfirmationContext.tagValuePair.value,
AVAILABLE_WIDTH,
false);
1285 if (nbLines <= QRCODE_NB_MAX_LINES) {
1286 qrCode.
text2 = addressConfirmationContext.tagValuePair.value;
1291 addressConfirmationContext.tagValuePair.value,
1293 QRCODE_NB_MAX_LINES,
1295 QRCODE_REDUCED_ADDR_LEN);
1296 qrCode.
text2 = reducedAddress;
1307 static void addressLayoutTouchCallbackQR(
int token,
uint8_t index)
1314 addressConfirmationContext.modalLayout = NULL;
1321 static void modalLayoutTouchCallback(
int token,
uint8_t index)
1328 genericContext.modalLayout = NULL;
1334 static void displaySkipWarning(
void)
1337 .cancelText =
"Go back to review",
1338 .centeredInfo.text1 =
"Skip review?",
1340 =
"If you're sure you don't need to review all fields, you can skip straight to signing.",
1341 .centeredInfo.text3 = NULL,
1343 .centeredInfo.icon = &C_Important_Circle_64px,
1344 .centeredInfo.offsetY = 0,
1345 .confirmationText =
"Yes, skip",
1346 .confirmationToken = SKIP_TOKEN,
1347 .tuneId = TUNE_TAP_CASUAL,
1349 if (modalPageContext != NULL) {
1361 static void updateKeyPad(
bool add)
1363 bool enableValidate, enableBackspace, enableDigits;
1364 bool redrawKeypad =
false;
1367 enableDigits = (keypadContext.pinLen < keypadContext.pinMaxDigits);
1368 enableValidate = (keypadContext.pinLen >= keypadContext.pinMinDigits);
1369 enableBackspace = (keypadContext.pinLen > 0);
1371 if ((keypadContext.pinLen == keypadContext.pinMinDigits)
1373 (keypadContext.pinLen == keypadContext.pinMaxDigits)
1375 (keypadContext.pinLen == 1)) {
1376 redrawKeypad =
true;
1380 if ((keypadContext.pinLen == 0) ||
1381 (keypadContext.pinLen == (keypadContext.pinMinDigits - 1))
1383 (keypadContext.pinLen
1384 == (keypadContext.pinMaxDigits - 1))) {
1385 redrawKeypad =
true;
1388 if (keypadContext.hidden ==
true) {
1393 keypadContext.layoutCtx,
false, 0, (
const char *) keypadContext.pinEntry);
1397 keypadContext.layoutCtx, 0, enableValidate, enableBackspace, enableDigits);
1400 if ((!add) && (keypadContext.pinLen == 0)) {
1408 static void keypadCallback(
char touchedKey)
1410 switch (touchedKey) {
1412 if (keypadContext.pinLen > 0) {
1413 keypadContext.pinLen--;
1414 keypadContext.pinEntry[keypadContext.pinLen] = 0;
1416 updateKeyPad(
false);
1425 onValidatePin(keypadContext.pinEntry, keypadContext.pinLen);
1429 if ((touchedKey >= 0x30) && (touchedKey < 0x40)) {
1430 if (keypadContext.pinLen < keypadContext.pinMaxDigits) {
1431 keypadContext.pinEntry[keypadContext.pinLen] = touchedKey;
1432 keypadContext.pinLen++;
1441 static void keypadGenericUseCase(
const char *title,
1447 tune_index_e tuneId,
1453 .separationLine =
true,
1454 .backAndText.token = backToken,
1455 .backAndText.tuneId = tuneId,
1456 .backAndText.text = NULL};
1465 memset(&keypadContext, 0,
sizeof(KeypadContext_t));
1469 layoutDescription.
modal =
false;
1472 keypadContext.hidden = hidden;
1484 keypadContext.layoutCtx, title, keypadContext.hidden, maxDigits,
"");
1491 onValidatePin = validatePinCallback;
1493 keypadContext.pinMinDigits = minDigits;
1494 keypadContext.pinMaxDigits = maxDigits;
1512 nbElements = getContentNbElement(content);
1514 while (nbElements > 0) {
1517 bool hasNav = !isLast || (pageIdxStart > 0) || (elemIdx > 0);
1539 nbElementsInPage =
MIN(nbMaxElementsPerContentType[content->
type], nbElements);
1542 elemIdx += nbElementsInPage;
1543 genericContextSetPageInfo(pageIdxStart + nbPages, nbElementsInPage, flag);
1544 nbElements -= nbElementsInPage;
1559 for (
int i = 0; i < genericContents->
nbContents; i++) {
1560 p_content = getContentAtIdx(genericContents, i, &content);
1561 if (p_content == NULL) {
1564 nbPages += nbgl_useCaseGetNbPagesForContent(p_content,
1565 pageIdxStart + nbPages,
1573 static void prepareAddressConfirmationPages(
const char *address,
1580 addressConfirmationContext.tagValuePair.item =
"Address";
1581 addressConfirmationContext.tagValuePair.value = address;
1590 if (tagValueList != NULL) {
1601 tagValueConfirm->tuneId = TUNE_TAP_CASUAL;
1609 if (tagValueList != NULL) {
1619 if (tagValueList != NULL) {
1627 tagValueConfirm->tuneId = TUNE_TAP_CASUAL;
1632 static void bundleNavStartHome(
void)
1634 nbgl_homeAndSettingsContext_t *context = &bundleNavContext.homeAndSettings;
1636 useCaseHomeExt(context->appName,
1639 context->settingContents != NULL ?
true :
false,
1640 &context->homeAction,
1641 bundleNavStartSettings,
1642 context->quitCallback);
1645 static void bundleNavStartSettingsAtPage(
uint8_t initSettingPage)
1647 nbgl_homeAndSettingsContext_t *context = &bundleNavContext.homeAndSettings;
1651 context->settingContents,
1653 bundleNavStartHome);
1656 static void bundleNavStartSettings(
void)
1658 bundleNavStartSettingsAtPage(0);
1661 static void bundleNavReviewConfirmRejection(
void)
1663 bundleNavContext.review.choiceCallback(
false);
1670 const char *confirmText;
1674 title =
"Reject transaction?";
1675 confirmText =
"Go back to transaction";
1678 title =
"Reject message?";
1679 confirmText =
"Go back to message";
1682 title =
"Reject operation?";
1683 confirmText =
"Go back to operation";
1690 static void bundleNavReviewChoice(
bool confirm)
1693 bundleNavContext.review.choiceCallback(
true);
1696 bundleNavReviewAskRejectionConfirmation(bundleNavContext.review.operationType,
1697 bundleNavReviewConfirmRejection);
1701 static void bundleNavReviewStreamingConfirmRejection(
void)
1703 bundleNavContext.reviewStreaming.choiceCallback(
false);
1706 static void bundleNavReviewStreamingChoice(
bool confirm)
1713 bundleNavContext.reviewStreaming.choiceCallback(
true);
1716 bundleNavReviewAskRejectionConfirmation(bundleNavContext.reviewStreaming.operationType,
1717 bundleNavReviewStreamingConfirmRejection);
1722 static void blindSigningWarningCallback(
bool confirm)
1725 blindSigningContext.choiceCallback(
false);
1728 if (blindSigningContext.isStreaming) {
1729 useCaseReviewStreamingStart(blindSigningContext.operationType,
1730 blindSigningContext.icon,
1731 blindSigningContext.reviewTitle,
1732 blindSigningContext.reviewSubTitle,
1733 blindSigningContext.choiceCallback,
1737 useCaseReview(blindSigningContext.operationType,
1738 blindSigningContext.tagValueList,
1739 blindSigningContext.icon,
1740 blindSigningContext.reviewTitle,
1741 blindSigningContext.reviewSubTitle,
1742 blindSigningContext.finishTitle,
1743 blindSigningContext.tipBox,
1744 blindSigningContext.choiceCallback,
1752 static void blindSigningWarning(
void)
1755 #ifdef HAVE_PIEZO_SOUND
1756 io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
1759 "Blind signing ahead",
1760 "The details of this transaction or message are not fully verifiable. If "
1761 "you sign it, you could lose all "
1765 blindSigningWarningCallback);
1772 const char *reviewTitle,
1773 const char *reviewSubTitle,
1774 const char *finishTitle,
1778 bool playNotifSound)
1781 memset(&genericContext, 0,
sizeof(genericContext));
1783 bundleNavContext.review.operationType = operationType;
1784 bundleNavContext.review.choiceCallback = choiceCallback;
1787 onChoice = bundleNavReviewChoice;
1788 navType = GENERIC_NAV;
1791 genericContext.genericContents.contentsList = localContentsList;
1792 genericContext.genericContents.nbContents = 3;
1797 prepareReviewFirstPage(
1798 &STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
1799 if (tipBox != NULL) {
1801 STARTING_CONTENT.content.extendedCenter.contentCenter.subText = NULL;
1803 STARTING_CONTENT.content.extendedCenter.tipBox.icon = tipBox->
icon;
1804 STARTING_CONTENT.content.extendedCenter.tipBox.text = tipBox->
text;
1805 STARTING_CONTENT.content.extendedCenter.tipBox.token = TIP_BOX_TOKEN;
1806 STARTING_CONTENT.content.extendedCenter.tipBox.tuneId = TUNE_TAP_CASUAL;
1820 memcpy(&localContentsList[1].content.tagValueList,
1828 prepareReviewLightLastPage(&localContentsList[2].content.infoButton, icon, finishTitle);
1832 prepareReviewLastPage(&localContentsList[2].content.infoLongPress, icon, finishTitle);
1836 uint8_t nbPages = getNbPagesForGenericContents(
1838 prepareNavInfo(
true, nbPages, getRejectReviewText(operationType));
1841 if (playNotifSound) {
1842 #ifdef HAVE_PIEZO_SOUND
1843 io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
1847 displayGenericContextPage(0,
true);
1853 const char *reviewTitle,
1854 const char *reviewSubTitle,
1856 bool playNotifSound)
1859 memset(&genericContext, 0,
sizeof(genericContext));
1861 bundleNavContext.reviewStreaming.operationType = operationType;
1862 bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
1863 bundleNavContext.reviewStreaming.icon = icon;
1866 onChoice = bundleNavReviewStreamingChoice;
1867 navType = STREAMING_NAV;
1870 genericContext.genericContents.contentsList = localContentsList;
1871 genericContext.genericContents.nbContents = 1;
1876 prepareReviewFirstPage(
1877 &STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
1880 bundleNavContext.reviewStreaming.stepPageNb = getNbPagesForGenericContents(
1887 if (playNotifSound) {
1888 #ifdef HAVE_PIEZO_SOUND
1889 io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
1893 displayGenericContextPage(0,
true);
1912 static void useCaseHomeExt(
const char *appName,
1914 const char *tagline,
1923 .centeredInfo.text1 = appName,
1924 .centeredInfo.text3 = NULL,
1926 .centeredInfo.offsetY = 0,
1929 .tapActionText = NULL,
1931 .topRightToken = CONTINUE_TOKEN,
1932 .tuneId = TUNE_TAP_CASUAL};
1933 if ((homeAction->
text != NULL) || (homeAction->
icon != NULL)) {
1948 if (tagline == NULL) {
1950 snprintf(appDescription,
1952 "This app enables signing\ntransactions on its network.");
1955 snprintf(appDescription,
1967 snprintf(appDescription,
1980 onContinue = topRightCallback;
1981 onQuit = quitCallback;
1995 static void displayDetails(
const char *tag,
const char *value,
bool wrapping)
1997 memset(&detailsContext, 0,
sizeof(detailsContext));
2003 detailsContext.tag = tag;
2004 detailsContext.value = value;
2006 detailsContext.currentPage = 0;
2007 detailsContext.wrapping = wrapping;
2009 if (detailsContext.nbPages > 1) {
2010 uint16_t nbLostChars = (detailsContext.nbPages - 1) * 3;
2019 detailsContext.nbPages++;
2023 displayDetailsPage(0,
true);
2045 bool *requireSpecificDisplay)
2048 nbPairs, tagValueList, startIndex,
false, requireSpecificDisplay);
2068 bool *requireSpecificDisplay)
2084 *requireSpecificDisplay =
false;
2085 while (nbPairsInPage < nbPairs) {
2092 if (nbPairsInPage > 0) {
2094 currentHeight += 12;
2096 currentHeight += 24;
2100 if (tagValueList->
pairs != NULL) {
2101 pair = PIC(&tagValueList->
pairs[startIndex + nbPairsInPage]);
2104 pair = PIC(tagValueList->
callback(startIndex + nbPairsInPage));
2113 if (nbPairsInPage > 0) {
2120 *requireSpecificDisplay =
true;
2132 value_font = SMALL_REGULAR_FONT;
2135 value_font = LARGE_MEDIUM_FONT;
2144 if (nbPairsInPage == 0) {
2148 *requireSpecificDisplay =
true;
2154 return nbPairsInPage;
2175 const char *
const *infoTypes = PIC(infosList->
infoTypes);
2176 const char *
const *infoContents = PIC(infosList->
infoContents);
2178 while (nbInfosInPage < nbInfos) {
2184 SMALL_BOLD_FONT, PIC(infoTypes[startIndex + nbInfosInPage]),
AVAILABLE_WIDTH,
true);
2190 PIC(infoContents[startIndex + nbInfosInPage]),
2203 previousHeight = currentHeight;
2206 return nbInfosInPage;
2229 while (nbSwitchesInPage < nbSwitches) {
2235 switchArray[startIndex + nbSwitchesInPage].text,
2244 switchArray[startIndex + nbSwitchesInPage].subText,
2257 previousHeight = currentHeight;
2260 return nbSwitchesInPage;
2285 while (nbBarsInPage < nbBars) {
2291 previousHeight = currentHeight;
2299 return nbBarsInPage;
2321 UNUSED(choicesList);
2324 while (nbChoicesInPage < nbChoices) {
2335 previousHeight = currentHeight;
2338 return nbChoicesInPage;
2355 while (i < tagValueList->nbPairs) {
2359 nbPairs -= nbPairsInPage;
2371 const char *tagline,
2378 appName, appIcon, tagline, withSettings, &homeAction, topRightCallback, quitCallback);
2387 const char *tagline,
2389 const char *actionButtonText,
2397 .text = actionButtonText};
2400 appName, appIcon, tagline, withSettings, &homeAction, topRightCallback, quitCallback);
2426 onQuit = quitCallback;
2427 onNav = navCallback;
2428 onControls = controlsCallback;
2430 navType = SETTINGS_NAV;
2433 prepareNavInfo(
false, nbPages, NULL);
2435 displaySettingsPage(initPage,
true);
2453 title, initPage, nbPages, quitCallback, navCallback, controlsCallback);
2475 memset(&genericContext, 0,
sizeof(genericContext));
2478 onQuit = quitCallback;
2479 pageTitle = appName;
2480 navType = GENERIC_NAV;
2482 if (settingContents != NULL) {
2485 if (infosList != NULL) {
2486 genericContext.hasFinishingContent =
true;
2489 memcpy(&FINISHING_CONTENT.content, infosList,
sizeof(
nbgl_content_u));
2493 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0,
false);
2494 if (infosList != NULL) {
2495 nbPages += nbgl_useCaseGetNbPagesForContent(&FINISHING_CONTENT, nbPages,
true,
false);
2498 prepareNavInfo(
false, nbPages, NULL);
2500 displayGenericContextPage(initPage,
true);
2539 const char *appName,
2541 const char *tagline,
2549 nbgl_homeAndSettingsContext_t *context = &bundleNavContext.homeAndSettings;
2551 context->appName = appName;
2552 context->appIcon = appIcon;
2553 context->tagline = tagline;
2554 context->settingContents = settingContents;
2555 context->infosList = infosList;
2556 if (action != NULL) {
2562 context->quitCallback = quitCallback;
2565 bundleNavStartSettingsAtPage(initSettingPage);
2568 bundleNavStartHome();
2584 .tickerCallback = &tickerCallback,
2585 .tickerIntervale = 0,
2588 onQuit = quitCallback;
2590 #ifdef HAVE_PIEZO_SOUND
2591 io_seproxyhal_play_tune(TUNE_LEDGER_MOMENT);
2599 .centeredInfo.icon = &C_Denied_Circle_64px,
2601 .centeredInfo.onTop =
false,
2603 .centeredInfo.text1 = message,
2604 .centeredInfo.text2 = NULL,
2605 .centeredInfo.text3 = NULL,
2606 .tapActionText =
"",
2607 .isSwipeable =
false,
2608 .tapActionToken = QUIT_TOKEN,
2610 .actionButtonText = NULL,
2611 .tuneId = TUNE_TAP_CASUAL};
2628 switch (reviewStatusType) {
2630 msg =
"Operation signed";
2634 msg =
"Operation rejected";
2638 msg =
"Transaction signed";
2642 msg =
"Transaction rejected";
2646 msg =
"Message signed";
2650 msg =
"Message rejected";
2654 msg =
"Address verified";
2658 msg =
"Address verification\ncancelled";
2680 const char *message,
2681 const char *subMessage,
2682 const char *confirmText,
2683 const char *cancelText,
2690 .centeredInfo.text2 = subMessage,
2691 .centeredInfo.text3 = NULL,
2693 .centeredInfo.icon = icon,
2694 .centeredInfo.offsetY = 0,
2695 .confirmationText = confirmText,
2696 .confirmationToken = CHOICE_TOKEN,
2697 .tuneId = TUNE_TAP_CASUAL,
2700 if ((confirmText == NULL) || (cancelText == NULL)) {
2703 onChoice = callback;
2722 const char *subMessage,
2723 const char *confirmText,
2724 const char *cancelText,
2730 .centeredInfo.text1 = message,
2731 .centeredInfo.text2 = subMessage,
2732 .centeredInfo.text3 = NULL,
2734 .centeredInfo.icon = &C_Important_Circle_64px,
2735 .centeredInfo.offsetY = 0,
2736 .confirmationText = confirmText,
2737 .confirmationToken = CHOICE_TOKEN,
2738 .tuneId = TUNE_TAP_CASUAL,
2740 onModalConfirm = callback;
2741 if (modalPageContext != NULL) {
2760 const char *reviewTitle,
2761 const char *reviewSubTitle,
2762 const char *rejectText,
2769 .footerToken = QUIT_TOKEN,
2770 .tapActionText = NULL,
2771 .isSwipeable =
true,
2772 .tapActionToken = CONTINUE_TOKEN,
2774 .actionButtonText = NULL,
2775 .tuneId = TUNE_TAP_CASUAL};
2782 onQuit = rejectCallback;
2783 onContinue = continueCallback;
2785 #ifdef HAVE_PIEZO_SOUND
2787 io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
2809 const char *rejectText,
2817 onChoice = choiceCallback;
2818 onNav = navCallback;
2819 onControls = buttonCallback;
2820 forwardNavOnly =
false;
2821 navType = REVIEW_NAV;
2825 prepareNavInfo(
true, nbPages, getRejectReviewText(
TYPE_OPERATION));
2827 displayReviewPage(initPage,
true);
2844 const char *rejectText,
2850 memset(&genericContext, 0,
sizeof(genericContext));
2853 onChoice = callback;
2854 navType = GENERIC_NAV;
2858 genericContext.genericContents.contentsList = localContentsList;
2861 if (tagValueList != NULL && tagValueList->
nbPairs != 0) {
2863 memcpy(&localContentsList[offset].content.tagValueList,
2870 memcpy(&localContentsList[offset].content.infoLongPress,
2876 genericContext.genericContents.nbContents = offset;
2879 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0,
false);
2881 prepareNavInfo(
true, nbPages, getRejectReviewText(
TYPE_OPERATION));
2883 displayGenericContextPage(0,
true);
2901 const char *rejectText,
2907 memset(&genericContext, 0,
sizeof(genericContext));
2910 onChoice = callback;
2911 navType = GENERIC_NAV;
2914 genericContext.genericContents.contentsList = localContentsList;
2917 if (tagValueList != NULL && tagValueList->
nbPairs != 0) {
2919 memcpy(&localContentsList[offset].content.tagValueList,
2933 genericContext.genericContents.nbContents = offset;
2936 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0,
false);
2938 prepareNavInfo(
true, nbPages, getRejectReviewText(
TYPE_OPERATION));
2940 displayGenericContextPage(0,
true);
2962 const char *reviewTitle,
2963 const char *reviewSubTitle,
2964 const char *finishTitle,
2967 useCaseReview(operationType,
2999 const char *reviewTitle,
3000 const char *reviewSubTitle,
3001 const char *finishTitle,
3005 useCaseReview(operationType,
3039 const char *reviewTitle,
3040 const char *reviewSubTitle,
3041 const char *finishTitle,
3045 memset(&blindSigningContext, 0,
sizeof(blindSigningContext));
3047 blindSigningContext.isStreaming =
false;
3049 blindSigningContext.tagValueList = tagValueList;
3050 blindSigningContext.icon = icon;
3051 blindSigningContext.reviewTitle = reviewTitle;
3052 blindSigningContext.reviewSubTitle = reviewSubTitle;
3053 blindSigningContext.finishTitle = finishTitle;
3054 blindSigningContext.tipBox = tipBox;
3055 blindSigningContext.choiceCallback = choiceCallback;
3057 blindSigningWarning();
3078 const char *reviewTitle,
3079 const char *reviewSubTitle,
3080 const char *finishTitle,
3083 useCaseReview(operationType,
3104 const char *rejectText,
3108 memset(&genericContext, 0,
sizeof(genericContext));
3111 onQuit = rejectCallback;
3112 navType = GENERIC_NAV;
3119 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0,
false);
3120 prepareNavInfo(
true, nbPages, rejectText);
3123 #ifdef HAVE_PIEZO_SOUND
3125 io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
3128 displayGenericContextPage(0,
true);
3145 const char *reviewTitle,
3146 const char *reviewSubTitle,
3149 useCaseReviewStreamingStart(
3150 operationType, icon, reviewTitle, reviewSubTitle, choiceCallback,
true);
3168 const char *reviewTitle,
3169 const char *reviewSubTitle,
3172 memset(&blindSigningContext, 0,
sizeof(blindSigningContext));
3174 blindSigningContext.isStreaming =
true;
3176 blindSigningContext.icon = icon;
3177 blindSigningContext.reviewTitle = reviewTitle;
3178 blindSigningContext.reviewSubTitle = reviewSubTitle;
3179 blindSigningContext.choiceCallback = choiceCallback;
3181 blindSigningWarning();
3202 memset(&genericContext, 0,
sizeof(genericContext));
3204 bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
3205 bundleNavContext.reviewStreaming.skipCallback = skipCallback;
3208 onChoice = bundleNavReviewStreamingChoice;
3209 navType = STREAMING_NAV;
3212 genericContext.genericContents.contentsList = localContentsList;
3213 genericContext.genericContents.nbContents = 1;
3222 bundleNavContext.reviewStreaming.stepPageNb = getNbPagesForGenericContents(
3223 &genericContext.genericContents,
3226 prepareNavInfo(
true,
3228 getRejectReviewText(bundleNavContext.reviewStreaming.operationType));
3236 displayGenericContextPage(0,
true);
3267 memset(&genericContext, 0,
sizeof(genericContext));
3269 bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
3272 onChoice = bundleNavReviewStreamingChoice;
3273 navType = STREAMING_NAV;
3276 genericContext.genericContents.contentsList = localContentsList;
3277 genericContext.genericContents.nbContents = 1;
3282 prepareReviewLastPage(&STARTING_CONTENT.content.infoLongPress,
3283 bundleNavContext.reviewStreaming.icon,
3287 bundleNavContext.reviewStreaming.stepPageNb = getNbPagesForGenericContents(
3288 &genericContext.genericContents,
3291 prepareNavInfo(
true, 1, getRejectReviewText(bundleNavContext.reviewStreaming.operationType));
3293 displayGenericContextPage(0,
true);
3305 memset(&genericContext, 0,
sizeof(genericContext));
3306 memset(&addressConfirmationContext, 0,
sizeof(addressConfirmationContext));
3309 onChoice = callback;
3310 navType = GENERIC_NAV;
3313 genericContext.genericContents.contentsList = localContentsList;
3314 genericContext.genericContents.nbContents = (tagValueList == NULL) ? 1 : 2;
3316 prepareAddressConfirmationPages(
3317 address, tagValueList, &STARTING_CONTENT, &localContentsList[1]);
3320 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0,
false);
3322 prepareNavInfo(
true, nbPages,
"Cancel");
3324 #ifdef HAVE_PIEZO_SOUND
3326 io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
3329 displayGenericContextPage(0,
true);
3351 const char *reviewTitle,
3352 const char *reviewSubTitle,
3356 memset(&genericContext, 0,
sizeof(genericContext));
3358 if (addressConfirmationContext.modalLayout) {
3361 memset(&addressConfirmationContext, 0,
sizeof(addressConfirmationContext));
3364 onChoice = choiceCallback;
3365 navType = GENERIC_NAV;
3369 genericContext.genericContents.contentsList = localContentsList;
3370 genericContext.genericContents.nbContents = (additionalTagValueList == NULL) ? 2 : 3;
3375 prepareReviewFirstPage(
3376 &STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
3377 STARTING_CONTENT.content.extendedCenter.contentCenter.subText =
"Swipe to continue";
3380 prepareAddressConfirmationPages(
3381 address, additionalTagValueList, &localContentsList[1], &localContentsList[2]);
3384 uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0,
false);
3386 prepareNavInfo(
true, nbPages,
"Cancel");
3388 #ifdef HAVE_PIEZO_SOUND
3390 io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
3393 displayGenericContextPage(0,
true);
3433 tune_index_e tuneId,
3437 keypadGenericUseCase(title,
3444 validatePinCallback,
3471 tune_index_e tuneId,
3475 keypadGenericUseCase(title,
3482 validatePinCallback,
@ ICON_ILLUSTRATION
simple icon
@ 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)
nbgl_contentIllustrationType_t illustrType
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 char * modalTitle
title given to modal window displayed when tip-box is touched
nbgl_contentInfoList_t infos
infos pairs displayed in modal.
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