18#include "os_helpers.h"
29typedef struct ReviewContext_s {
33 const char *reviewTitle;
34 const char *reviewSubTitle;
35 const char *finishTitle;
40 uint8_t dataDirection;
41 uint8_t currentTagValueIndex;
42 uint8_t currentExtensionPage;
43 uint8_t nbExtensionPages;
49typedef struct ChoiceContext_s {
52 const char *subMessage;
53 const char *confirmText;
54 const char *cancelText;
59typedef struct ConfirmContext_s {
61 const char *subMessage;
62 const char *confirmText;
63 const char *cancelText;
68typedef struct ContentContext_s {
71 const char *rejectText;
77typedef struct HomeContext_s {
87typedef struct ActionContext_s {
92typedef struct KeypadContext_s {
106typedef struct KeyboardContext_s {
109 uint16_t entryMaxLen;
111 uint8_t keyboardIndex;
124 GENERIC_REVIEW_USE_CASE,
125 ADDRESS_REVIEW_USE_CASE,
126 STREAMING_START_REVIEW_USE_CASE,
127 STREAMING_CONTINUE_REVIEW_USE_CASE,
128 STREAMING_FINISH_REVIEW_USE_CASE,
142typedef struct UseCaseContext_s {
147 uint8_t firstPairPage;
152 ReviewContext_t review;
153 ChoiceContext_t choice;
154 ConfirmContext_t confirm;
156 ContentContext_t content;
158 KeypadContext_t keypad;
161 KeyboardContext_t keyboard;
163 ActionContext_t action;
167typedef struct PageContent_s {
181typedef struct ReviewWithWarningContext_s {
186 const char *reviewTitle;
187 const char *reviewSubTitle;
188 const char *finishTitle;
191 uint8_t securityReportLevel;
194 uint8_t nbWarningPages;
195 uint8_t firstWarningPage;
196 uint8_t barDetailIdx;
197} ReviewWithWarningContext_t;
208static UseCaseContext_t context;
210static ReviewWithWarningContext_t reviewWithWarnCtx;
228static void displaySpinner(
const char *text);
230static void startUseCaseHome(
void);
231static void startUseCaseInfo(
void);
232static void startUseCaseSettings(
void);
233static void startUseCaseSettingsAtPage(uint8_t initSettingPage);
234static void startUseCaseContent(
void);
236static void statusTickerCallback(
void);
239static void displayWarningStep(
void);
244 switch (content->
type) {
274 if (contentIdx >= genericContents->
nbContents) {
280 if (content == NULL) {
286 if (context.content.navCallback) {
287 if (context.content.navCallback(contentIdx, &pageContent) ==
true) {
290 switch (content->
type) {
339 uint8_t *elemContentIdx,
345 uint8_t elemNbPages = 0;
347 switch (context.type) {
348 case SETTINGS_USE_CASE:
350 case GENERIC_SETTINGS:
351 genericContents = context.home.settingContents;
353 case CONTENT_USE_CASE:
354 case GENERIC_REVIEW_USE_CASE:
355 genericContents = &context.content.genericContents;
360 for (
unsigned int i = 0; i < genericContents->
nbContents; i++) {
361 p_content = getContentAtIdx(genericContents, i, content);
362 elemNbPages = getContentNbElement(p_content);
363 if (nbPages + elemNbPages > elemIdx) {
364 *elemContentIdx = context.currentPage - nbPages;
367 nbPages += elemNbPages;
373static const char *getChoiceName(uint8_t choiceIndex)
383 p_content = getContentElemAtIdx(context.currentPage, &elemIdx, &content);
384 if (p_content == NULL) {
387 switch (p_content->
type) {
390 names = (
char **) PIC(contentChoices->
names);
395 names = (
char **) PIC(contentBars->
barTexts);
396 nbValues = contentBars->
nbBars;
402 if (choiceIndex >= nbValues) {
406 return (
const char *) PIC(names[choiceIndex]);
409static void onChoiceSelected(uint8_t choiceIndex)
418 p_content = getContentElemAtIdx(context.currentPage, &elemIdx, &content);
419 if (p_content == NULL) {
422 switch (p_content->
type) {
425 if (choiceIndex < contentChoices->nbChoices) {
426 token = contentChoices->
token;
431 if (choiceIndex < contentBars->nbBars) {
432 token = ((
const uint8_t *) PIC(contentBars->
tokens))[choiceIndex];
445 actionCallback(token, choiceIndex, context.currentPage);
448 if (context.content.controlsCallback != NULL) {
449 context.content.controlsCallback(token, choiceIndex);
457 if ((context.type == GENERIC_SETTINGS) && (context.home.quitCallback != NULL)) {
458 context.home.quitCallback();
461 if (context.type == SETTINGS_USE_CASE) {
465 if (context.content.quitCallback != NULL) {
466 context.content.quitCallback();
476 bool *isCenteredInfo)
480 if (tagValueList->
pairs != NULL) {
481 pair = PIC(&tagValueList->
pairs[index]);
484 pair = PIC(tagValueList->
callback(index));
487 *value = pair->
value;
492 *isCenteredInfo =
true;
500static void onReviewAccept(
void)
502 if (context.review.onChoice) {
503 context.review.onChoice(
true);
507static void onReviewReject(
void)
509 if (context.review.onChoice) {
510 context.review.onChoice(
false);
514static void onChoiceAccept(
void)
516 if (context.choice.onChoice) {
517 context.choice.onChoice(
true);
521static void onChoiceReject(
void)
523 if (context.choice.onChoice) {
524 context.choice.onChoice(
false);
528static void onConfirmAccept(
void)
530 if (context.confirm.currentStep) {
533 if (context.confirm.onConfirm) {
534 context.confirm.onConfirm();
538static void onConfirmReject(
void)
540 if (context.confirm.currentStep) {
547static void onSwitchAction(
void)
554 p_content = getContentElemAtIdx(context.currentPage, &elemIdx, &content);
560 switch (context.type) {
561 case SETTINGS_USE_CASE:
563 case GENERIC_SETTINGS:
566 case CONTENT_USE_CASE:
567 case GENERIC_REVIEW_USE_CASE:
575 actionCallback(contentSwitch->
token,
577 context.currentPage);
579 else if (context.content.controlsCallback != NULL) {
580 context.content.controlsCallback(contentSwitch->
token, 0);
590 ForcedType_t forcedType,
602 .tickerIntervale = 0,
608 if ((context.type == STREAMING_CONTINUE_REVIEW_USE_CASE)
609 && (context.review.skipCallback != NULL) && (context.review.nbDataSets > 1)) {
612 if ((context.type == STATUS_USE_CASE) || (context.type == SPINNER_USE_CASE)) {
615 if ((context.type == CONFIRM_USE_CASE) && (context.confirm.currentStep != NULL)) {
620 p_content = getContentElemAtIdx(context.currentPage, &elemIdx, &content);
622 switch (p_content->
type) {
644 else if ((icon == NULL) && (forcedType != FORCE_CENTERED_INFO)) {
646 if (subTxt != NULL) {
647 style = (forcedType == FORCE_BUTTON) ? BUTTON_INFO : BOLD_TEXT1_INFO;
650 style = REGULAR_INFO;
652 newStep =
nbgl_stepDrawText(pos, onActionCallback, p_ticker, txt, subTxt, style, modal);
659 info.bottomIcon = bottomIcon;
660 if ((subTxt != NULL) || (context.stepCallback != NULL) || context.forceAction) {
661 info.
style = BOLD_TEXT1_INFO;
664 info.
style = REGULAR_INFO;
668 if (context.type == CONFIRM_USE_CASE) {
669 context.confirm.currentStep = newStep;
675 const char *description,
684 switchInfo.
text = title;
685 switchInfo.
subText = description;
698 if (context.currentPage > 0) {
699 context.currentPage--;
703 else if ((context.type != STREAMING_CONTINUE_REVIEW_USE_CASE)
704 || (context.review.skipCallback == NULL) || (context.review.nbDataSets == 1)) {
711 if (context.currentPage < (
int) (context.nbPages - 1)) {
712 context.currentPage++;
722 if (context.stepCallback != NULL) {
723 context.stepCallback();
725 else if ((context.type == CONTENT_USE_CASE) || (context.type == SETTINGS_USE_CASE)
726 || (context.type == GENERIC_SETTINGS)
727 || (context.type == GENERIC_REVIEW_USE_CASE)) {
728 p_content = getContentElemAtIdx(context.currentPage, &elemIdx, &content);
729 if (p_content != NULL) {
730 switch (p_content->
type) {
744 token = ((
const uint8_t *) PIC(
755 if (elemIdx < p_content->content.tagValueConfirm.tagValueList.nbPairs) {
764 bool used_action_callback
766 ContextType_t prev_type = context.type;
767 if (used_action_callback) {
770 actionCallback(token, index, context.currentPage);
772 else if (context.content.controlsCallback != NULL) {
773 context.content.controlsCallback(token, index);
779 if (context.type != prev_type) {
792 if (used_action_callback
810 if (!buttonGenericCallback(event, &pos)) {
815 context.review.dataDirection = pos;
817 displayReviewPage(pos);
829 && (context.currentPage > context.firstPairPage)) {
830 context.currentPage--;
837 && (context.currentPage < (
int) (context.nbPages - 1))
838 && (context.currentPage > context.firstPairPage)) {
839 context.currentPage++;
845 if (context.firstPairPage == 0) {
847 context.review.skipCallback();
851 context.currentPage = context.nbPages - 2;
860 if (context.firstPairPage == 0) {
861 displayStreamingReviewPage(pos);
864 displayReviewPage(pos);
874 context.action.actionCallback();
883 if (!buttonGenericCallback(event, &pos)) {
888 context.review.dataDirection = pos;
891 displayStreamingReviewPage(pos);
899 if (!buttonGenericCallback(event, &pos)) {
903 displaySettingsPage(pos,
false);
911 if (!buttonGenericCallback(event, &pos)) {
915 displayInfoPage(pos);
923 if (!buttonGenericCallback(event, &pos)) {
927 displayHomePage(pos);
935 if (!buttonGenericCallback(event, &pos)) {
939 displayChoicePage(pos);
947 if (!buttonGenericCallback(event, &pos)) {
960 if (context.stepCallback != NULL) {
961 context.stepCallback();
971 if (!buttonGenericCallback(event, &pos)) {
975 displayContent(pos,
false);
979static void statusTickerCallback(
void)
981 if (context.stepCallback != NULL) {
982 context.stepCallback();
994 if (context.review.currentExtensionPage > 0) {
995 context.review.currentExtensionPage--;
1001 if (context.review.currentExtensionPage < (context.review.nbExtensionPages - 1)) {
1002 context.review.currentExtensionPage++;
1008 if (context.review.currentExtensionPage == (context.review.nbExtensionPages - 1)) {
1018 displayExtensionStep(pos);
1027 const char *text = NULL;
1028 const char *subText = NULL;
1030 if (context.review.extensionStepCtx != NULL) {
1033 if (context.review.currentExtensionPage < (context.review.nbExtensionPages - 1)) {
1034 if (context.review.currentExtensionPage == 0) {
1041 switch (context.review.extension->aliasType) {
1043 text = context.review.extension->title;
1044 subText = context.review.extension->fullValue;
1047 bool has_scope = (context.review.extension->aliasSubName != NULL);
1048 bool has_tn = (context.review.extension->explanation != NULL);
1049 uint8_t page = context.review.currentExtensionPage;
1051 text = context.review.extension->title;
1052 subText = has_scope ? context.review.extension->aliasSubName
1053 : context.review.extension->fullValue;
1055 else if (has_scope && page == 1) {
1056 text = context.review.extension->title;
1057 subText = context.review.extension->fullValue;
1060 text = context.review.extension->explanation;
1065 infoList = context.review.extension->infolist;
1066 text = PIC(infoList->
infoTypes[context.review.currentExtensionPage]);
1067 subText = PIC(infoList->
infoContents[context.review.currentExtensionPage]);
1070 tagValueList = context.review.extension->tagValuelist;
1071 text = PIC(tagValueList->
pairs[context.review.currentExtensionPage].
item);
1072 subText = PIC(tagValueList->
pairs[context.review.currentExtensionPage].
value);
1079 pos, extensionNavigate, NULL, text, subText, BOLD_TEXT1_INFO,
true);
1082 else if (context.review.currentExtensionPage == (context.review.nbExtensionPages - 1)) {
1084 info.
icon = &C_icon_back_x;
1085 info.
text1 =
"Back";
1086 info.
style = BOLD_TEXT1_INFO;
1088 context.review.extensionStepCtx
1094static void displayAliasFullValue(
void)
1096 const char *text = NULL;
1097 const char *subText = NULL;
1099 bool isCenteredInfo;
1101 getPairData(context.review.tagValueList,
1102 context.review.currentTagValueIndex,
1105 &context.review.extension,
1108 if (context.review.extension == NULL) {
1111 "displayAliasFullValue: extension nor found for pair %d\n",
1112 context.review.currentTagValueIndex);
1115 context.review.currentExtensionPage = 0;
1116 context.review.extensionStepCtx = NULL;
1118 switch (context.review.extension->aliasType) {
1120 context.review.nbExtensionPages = 2;
1123 context.review.nbExtensionPages
1124 = 2 + ((context.review.extension->aliasSubName != NULL) ? 1 : 0)
1125 + ((context.review.extension->explanation != NULL) ? 1 : 0);
1128 context.review.nbExtensionPages = context.review.extension->infolist->nbInfos + 1;
1131 context.review.nbExtensionPages = context.review.extension->tagValuelist->nbPairs + 1;
1135 "displayAliasFullValue: unsupported alias type %d\n",
1136 context.review.extension->aliasType);
1142static void getLastPageInfo(
bool approve,
const nbgl_icon_details_t **icon,
const char **text)
1146 *icon = &C_icon_validate_14;
1148 if ((context.type == REVIEW_USE_CASE) && (context.review.finishTitle != NULL)) {
1149 *text = context.review.finishTitle;
1152 *text =
"Confirm contact details";
1155 else if (context.type == ADDRESS_REVIEW_USE_CASE) {
1160 if (context.review.finishTitle != NULL) {
1161 *text = context.review.finishTitle;
1167 *text =
"Accept risk and sign transaction";
1170 *text =
"Sign transaction";
1175 *text =
"Accept risk and sign message";
1178 *text =
"Sign message";
1183 *text =
"Accept risk and sign operation";
1186 *text =
"Sign operation";
1192 context.stepCallback = onReviewAccept;
1196 *icon = &C_icon_crossmark;
1197 if ((context.type == ADDRESS_REVIEW_USE_CASE)
1202 *text =
"Reject transaction";
1205 *text =
"Reject message";
1208 *text =
"Reject operation";
1210 context.stepCallback = onReviewReject;
1217 uint8_t reviewPages = 0;
1218 uint8_t finalPages = 0;
1219 uint8_t pairIndex = 0;
1220 const char *text = NULL;
1221 const char *subText = NULL;
1223 uint8_t currentIndex = 0;
1224 uint8_t titleIndex = 255;
1225 uint8_t subIndex = 255;
1226 uint8_t approveIndex = 255;
1227 uint8_t rejectIndex = 255;
1229 ForcedType_t forcedType = NO_FORCED_TYPE;
1231 context.stepCallback = NULL;
1235 titleIndex = currentIndex++;
1237 if (context.review.reviewSubTitle) {
1239 subIndex = currentIndex++;
1242 approveIndex = context.nbPages - 2;
1243 rejectIndex = context.nbPages - 1;
1244 finalPages = approveIndex;
1247 if (context.currentPage >= finalPages) {
1248 if (context.currentPage == approveIndex) {
1250 getLastPageInfo(
true, &icon, &text);
1252 else if (context.currentPage == rejectIndex) {
1254 getLastPageInfo(
false, &icon, &text);
1257 else if (context.currentPage < reviewPages) {
1258 if (context.currentPage == titleIndex) {
1260 icon = context.review.icon;
1261 text = context.review.reviewTitle;
1263 else if (context.currentPage == subIndex) {
1265 text = context.review.reviewSubTitle;
1268 else if ((context.review.address != NULL) && (context.currentPage == reviewPages)) {
1271 subText = context.review.address;
1277 if ((context.operationType &
SKIPPABLE_OPERATION) && (context.review.skipDisplay ==
false)
1278 && ((context.currentPage > reviewPages)
1282 if ((context.review.nbDataSets == 1) || (context.currentPage > 0)) {
1285 info.
icon = &C_Information_circle_14px;
1286 info.
text1 =
"Press right button to continue message or \bpress both to skip\b";
1289 context.review.skipDisplay =
true;
1290 context.firstPairPage = reviewPages;
1293 context.review.skipDisplay =
false;
1294 bool isCenteredInfo =
false;
1295 pairIndex = context.currentPage - reviewPages;
1296 if (context.review.address != NULL) {
1299 getPairData(context.review.tagValueList,
1306 if (extension != NULL) {
1307 context.stepCallback = displayAliasFullValue;
1308 context.review.currentTagValueIndex = pairIndex;
1309 forcedType = FORCE_BUTTON;
1312 if (isCenteredInfo) {
1313 forcedType = FORCE_CENTERED_INFO;
1318 drawStep(pos, icon, text, subText, reviewCallback,
false, forcedType,
false);
1325 const char *text = NULL;
1326 const char *subText = NULL;
1328 uint8_t reviewPages = 0;
1329 uint8_t titleIndex = 255;
1330 uint8_t subIndex = 255;
1332 ForcedType_t forcedType = NO_FORCED_TYPE;
1334 context.stepCallback = NULL;
1335 switch (context.type) {
1336 case STREAMING_START_REVIEW_USE_CASE:
1338 titleIndex = reviewPages++;
1339 if (context.review.reviewSubTitle) {
1341 subIndex = reviewPages++;
1344 if (context.currentPage >= reviewPages) {
1349 if (context.currentPage == titleIndex) {
1351 icon = context.review.icon;
1352 text = context.review.reviewTitle;
1354 else if (context.currentPage == subIndex) {
1356 text = context.review.reviewSubTitle;
1360 case STREAMING_CONTINUE_REVIEW_USE_CASE:
1361 if (context.currentPage >= context.review.tagValueList->nbPairs) {
1368 if ((context.review.skipCallback != NULL) && (context.review.skipDisplay ==
false)
1369 && ((context.review.nbDataSets > 1) || (context.currentPage > 0)
1373 if ((context.review.nbDataSets == 1) || (context.currentPage > 0)) {
1376 info.
icon = &C_Information_circle_14px;
1377 info.
text1 =
"Press right button to continue message or \bpress both to skip\b";
1380 context.review.skipDisplay =
true;
1383 context.review.skipDisplay =
false;
1384 bool isCenteredInfo =
false;
1385 getPairData(context.review.tagValueList,
1386 context.currentPage,
1392 if (extension != NULL) {
1393 forcedType = FORCE_BUTTON;
1396 if (isCenteredInfo) {
1397 forcedType = FORCE_CENTERED_INFO;
1402 case STREAMING_FINISH_REVIEW_USE_CASE:
1404 if (context.currentPage == 0) {
1406 getLastPageInfo(
true, &icon, &text);
1410 getLastPageInfo(
false, &icon, &text);
1415 drawStep(pos, icon, text, subText, streamingReviewCallback,
false, forcedType,
false);
1422 const char *text = NULL;
1423 const char *subText = NULL;
1426 context.stepCallback = NULL;
1428 if (context.currentPage < (context.nbPages - 1)) {
1430 ((
const char *
const *) PIC(context.home.infosList->infoTypes))[context.currentPage]);
1432 ((
const char *
const *) PIC(context.home.infosList->infoContents))[context.currentPage]);
1435 icon = &C_icon_back_x;
1437 context.stepCallback = startUseCaseHome;
1440 drawStep(pos, icon, text, subText, infoCallback,
false, FORCE_CENTERED_INFO,
false);
1445static void getContentPage(
bool toogle_state, PageContent_t *contentPage)
1447 uint8_t elemIdx = 0;
1452 char **names = NULL;
1454 char **texts = NULL;
1455 p_content = getContentElemAtIdx(context.currentPage, &elemIdx, &content);
1456 if (p_content == NULL) {
1459 switch (p_content->
type) {
1476 &contentPage->subText,
1477 &contentPage->extension,
1479 &contentPage->isCenteredInfo);
1482 if (elemIdx < p_content->content.tagValueConfirm.tagValueList.nbPairs) {
1486 &contentPage->subText,
1487 &contentPage->extension,
1489 &contentPage->isCenteredInfo);
1493 contentPage->icon = &C_icon_validate_14;
1494 contentPage->isAction =
true;
1498 contentPage->isSwitch =
true;
1501 contentPage->
text = contentSwitch->
text;
1502 contentPage->state = contentSwitch->
initState;
1506 context.stepCallback = onSwitchAction;
1507 contentPage->subText = contentSwitch->
subText;
1512 contentPage->subText
1521 if (contentChoices->vertical) {
1524 names = (
char **) PIC(contentChoices->
names);
1527 if (contentChoices->title != NULL) {
1528 contentPage->text = PIC(contentChoices->title);
1529 contentPage->subText = (
const char *) PIC(names[elemIdx]);
1531 else if ((context.type == CONTENT_USE_CASE) && (context.content.title != NULL)) {
1532 contentPage->text = PIC(context.content.title);
1533 contentPage->subText = (
const char *) PIC(names[elemIdx]);
1535 else if (((context.type == GENERIC_SETTINGS) || (context.type == SETTINGS_USE_CASE))
1536 && (context.home.appName != NULL)) {
1543 contentPage->text = PIC(context.home.appName);
1544 contentPage->subText = (
const char *) PIC(names[elemIdx]);
1547 contentPage->text = (
const char *) PIC(names[elemIdx]);
1553 if ((contentChoices->selectionIcon != NULL)
1554 && (elemIdx == contentChoices->
initChoice)) {
1555 contentPage->icon = PIC(contentChoices->selectionIcon);
1556 contentPage->bottomIcon =
true;
1561 if (contentBars->vertical) {
1564 texts = (
char **) PIC(contentBars->
barTexts);
1567 if (contentBars->title != NULL) {
1568 contentPage->text = PIC(contentBars->title);
1569 contentPage->subText = PIC(texts[elemIdx]);
1571 else if ((context.type == CONTENT_USE_CASE) && (context.content.title != NULL)) {
1572 contentPage->text = PIC(context.content.title);
1573 contentPage->subText = PIC(texts[elemIdx]);
1575 else if ((context.type == GENERIC_SETTINGS) && (context.home.appName != NULL)) {
1576 contentPage->text = PIC(context.home.appName);
1577 contentPage->subText = PIC(texts[elemIdx]);
1580 contentPage->text = PIC(texts[elemIdx]);
1588 contentPage->icon = &C_icon_down;
1589 contentPage->bottomIcon =
true;
1599 PageContent_t contentPage = {0};
1601 context.stepCallback = NULL;
1603 if (context.currentPage < (context.nbPages - 1)) {
1604 getContentPage(toogle_state, &contentPage);
1607 contentPage.icon = &C_icon_back_x;
1608 contentPage.text =
"Back";
1609 if (context.type == GENERIC_SETTINGS) {
1610 context.stepCallback = context.home.quitCallback;
1613 context.stepCallback = startUseCaseHome;
1617 if (contentPage.isSwitch) {
1619 pos, contentPage.text, contentPage.subText, contentPage.state, settingsCallback,
false);
1625 contentPage.subText,
1629 contentPage.bottomIcon);
1635static void startUseCaseHome(
void)
1637 switch (context.type) {
1638 case SETTINGS_USE_CASE:
1640 context.currentPage = 1;
1641 if (context.home.homeAction) {
1643 context.currentPage++;
1648 context.currentPage = 1;
1649 if (context.home.homeAction) {
1651 context.currentPage++;
1653 if (context.home.settingContents) {
1655 context.currentPage++;
1660 context.currentPage = 0;
1664 context.type = HOME_USE_CASE;
1665 context.nbPages = 2;
1666 if (context.home.settingContents) {
1669 if (context.home.infosList) {
1672 if (context.home.homeAction) {
1678static void startUseCaseInfo(
void)
1680 context.type = INFO_USE_CASE;
1681 context.nbPages = context.home.infosList->nbInfos + 1;
1682 context.currentPage = 0;
1687static void startUseCaseSettingsAtPage(uint8_t initSettingPage)
1693 if (context.type != GENERIC_SETTINGS) {
1694 context.
type = SETTINGS_USE_CASE;
1697 context.nbPages = 1;
1698 for (
unsigned int i = 0; i < context.home.settingContents->nbContents; i++) {
1699 p_content = getContentAtIdx(context.home.settingContents, i, &content);
1700 context.nbPages += getContentNbElement(p_content);
1702 context.currentPage = initSettingPage;
1707static void startUseCaseSettings(
void)
1709 startUseCaseSettingsAtPage(0);
1712static void startUseCaseContent(
void)
1714 uint8_t contentIdx = 0;
1718 context.nbPages = 1;
1720 for (contentIdx = 0; contentIdx < context.content.genericContents.nbContents; contentIdx++) {
1721 p_content = getContentAtIdx(&context.content.genericContents, contentIdx, &content);
1722 context.nbPages += getContentNbElement(p_content);
1726 if (context.currentPage >= context.nbPages) {
1736 const char *text = NULL;
1737 const char *subText = NULL;
1739 uint8_t currentIndex = 0;
1740 uint8_t homeIndex = 255;
1741 uint8_t actionIndex = 255;
1742 uint8_t settingsIndex = 255;
1743 uint8_t infoIndex = 255;
1745 context.stepCallback = NULL;
1748 homeIndex = currentIndex++;
1749 if (context.home.homeAction) {
1750 actionIndex = currentIndex++;
1752 if (context.home.settingContents) {
1753 settingsIndex = currentIndex++;
1755 if (context.home.infosList) {
1756 infoIndex = currentIndex++;
1759 if (context.currentPage == homeIndex) {
1761 icon = context.home.appIcon;
1762 if (context.home.tagline != NULL) {
1763 text = context.home.tagline;
1766 text = context.home.appName;
1767 subText =
"app is ready";
1770 else if (context.currentPage == actionIndex) {
1772 icon = context.home.homeAction->icon;
1773 text = PIC(context.home.homeAction->text);
1774 context.stepCallback = context.home.homeAction->callback;
1776 else if (context.currentPage == settingsIndex) {
1778 icon = &C_icon_coggle;
1779 text =
"App settings";
1780 context.stepCallback = startUseCaseSettings;
1782 else if (context.currentPage == infoIndex) {
1784 icon = &C_Information_circle_14px;
1786 context.stepCallback = startUseCaseInfo;
1789 icon = &C_Quit_14px;
1791 context.stepCallback = context.home.quitCallback;
1794 drawStep(pos, icon, text, subText, homeCallback,
false, NO_FORCED_TYPE,
false);
1801 const char *text = NULL;
1802 const char *subText = NULL;
1807 uint8_t acceptPage = 0;
1810 uint8_t nbDetailPages = 0;
1812 if (context.choice.message != NULL) {
1813 if ((context.choice.icon == NULL) || (context.choice.subMessage == NULL)) {
1820 if ((context.choice.details != NULL) && (context.choice.details->type ==
BAR_LIST_WARNING)) {
1821 nbDetailPages = context.choice.details->barList.nbBars;
1823 context.stepCallback = NULL;
1825 if (context.currentPage < acceptPage) {
1826 if (context.currentPage == 0) {
1827 text = context.choice.message;
1828 if (context.choice.icon != NULL) {
1829 icon = context.choice.icon;
1832 subText = context.choice.subMessage;
1835 else if ((acceptPage == 2) && (context.currentPage == 1)) {
1837 text = context.choice.message;
1838 subText = context.choice.subMessage;
1841 else if (context.currentPage < (acceptPage + nbDetailPages)) {
1843 uint8_t idx = context.currentPage - acceptPage;
1844 text = (context.choice.details->barList.texts != NULL)
1845 ? context.choice.details->barList.texts[idx]
1847 subText = (context.choice.details->barList.subTexts != NULL)
1848 ? context.choice.details->barList.subTexts[idx]
1851 else if (context.currentPage == (acceptPage + nbDetailPages)) {
1852 icon = &C_icon_validate_14;
1853 text = context.choice.confirmText;
1854 context.stepCallback = onChoiceAccept;
1857 icon = &C_icon_crossmark;
1858 text = context.choice.cancelText;
1859 context.stepCallback = onChoiceReject;
1863 drawStep(pos, icon, text, subText, genericChoiceCallback,
false, NO_FORCED_TYPE,
false);
1870 const char *text = NULL;
1871 const char *subText = NULL;
1874 context.stepCallback = NULL;
1875 switch (context.currentPage) {
1878 text = context.confirm.message;
1879 subText = context.confirm.subMessage;
1883 icon = &C_icon_validate_14;
1884 text = context.confirm.confirmText;
1885 context.stepCallback = onConfirmAccept;
1889 icon = &C_icon_crossmark;
1890 text = context.confirm.cancelText;
1891 context.stepCallback = onConfirmReject;
1895 drawStep(pos, icon, text, subText, genericConfirmCallback,
true, NO_FORCED_TYPE,
false);
1902 PageContent_t contentPage = {0};
1903 ForcedType_t forcedType = NO_FORCED_TYPE;
1905 context.stepCallback = NULL;
1907 if (context.currentPage < (context.nbPages - 1)) {
1908 getContentPage(toogle_state, &contentPage);
1909 if (contentPage.isCenteredInfo) {
1910 forcedType = FORCE_CENTERED_INFO;
1912 context.forceAction = contentPage.isAction;
1915 if (context.content.rejectText) {
1916 contentPage.text = context.content.rejectText;
1919 contentPage.text =
"Back";
1921 if (context.type == GENERIC_REVIEW_USE_CASE) {
1922 contentPage.icon = &C_icon_crossmark;
1925 contentPage.icon = &C_icon_back_x;
1927 context.stepCallback = context.content.quitCallback;
1930 if (contentPage.isSwitch) {
1932 pos, contentPage.text, contentPage.subText, contentPage.state, contentCallback,
false);
1938 contentPage.subText,
1942 contentPage.bottomIcon);
1944 context.forceAction =
false;
1948static void displaySpinner(
const char *text)
1950 drawStep(
SINGLE_STEP, &C_icon_processing, text, NULL, NULL,
false, NO_FORCED_TYPE,
false);
1955static void useCaseReview(ContextType_t type,
1959 const char *reviewTitle,
1960 const char *reviewSubTitle,
1961 const char *finishTitle,
1964 memset(&context, 0,
sizeof(UseCaseContext_t));
1965 context.type = type;
1966 context.operationType = operationType;
1967 context.review.tagValueList = tagValueList;
1968 context.review.reviewTitle = reviewTitle;
1969 context.review.reviewSubTitle = reviewSubTitle;
1970 context.review.finishTitle = finishTitle;
1971 context.review.icon = icon;
1972 context.review.onChoice = choiceCallback;
1973 context.currentPage = 0;
1975 context.nbPages = tagValueList->
nbPairs + 3;
1976 if (reviewSubTitle) {
1984static void setPinCodeText(
void)
1986 bool enableValidate =
false;
1987 bool enableBackspace =
true;
1990 enableValidate = (context.keypad.pinLen >= context.keypad.pinMinDigits);
1992 enableBackspace = (context.keypad.pinLen > 0) || (context.keypad.backCallback != NULL);
1994 context.keypad.hidden,
1995 context.keypad.pinLen,
1996 (
const char *) context.keypad.pinEntry);
1998 context.keypad.layoutCtx, context.keypad.keypadIndex, enableValidate, enableBackspace);
2004static void keypadCallback(
char touchedKey)
2006 switch (touchedKey) {
2008 if (context.keypad.pinLen > 0) {
2009 context.keypad.pinLen--;
2010 context.keypad.pinEntry[context.keypad.pinLen] = 0;
2012 else if (context.keypad.backCallback != NULL) {
2013 context.keypad.backCallback();
2020 context.keypad.validatePin(context.keypad.pinEntry, context.keypad.pinLen);
2024 if ((touchedKey >= 0x30) && (touchedKey < 0x40)) {
2025 if (context.keypad.pinLen < context.keypad.pinMaxDigits) {
2026 context.keypad.pinEntry[context.keypad.pinLen] = touchedKey;
2027 context.keypad.pinLen++;
2040 const char **buttons;
2041 int firstButtonToken;
2042 uint8_t nbUsedButtons;
2045 char title[KEYBOARD_MAX_TITLE];
2046} savedKeyboardContext;
2061static void displaySuggestionSelection(
void)
2064 savedKeyboardContext.buttons = context.keyboard.content.suggestionButtons.buttons;
2065 savedKeyboardContext.firstButtonToken
2066 = context.keyboard.content.suggestionButtons.firstButtonToken;
2067 savedKeyboardContext.nbUsedButtons = context.keyboard.content.suggestionButtons.nbUsedButtons;
2068 savedKeyboardContext.onButtonCallback = context.keyboard.onButtonCallback;
2069 savedKeyboardContext.backCallback = context.keyboard.backCallback;
2073 context.keyboard.layoutCtx = NULL;
2075 snprintf(savedKeyboardContext.title,
2076 sizeof(savedKeyboardContext.title),
2078 context.keyboard.content.number);
2082 savedKeyboardContext.backCallback,
2083 suggestionNavCallback,
2084 savedKeyboardContext.onButtonCallback);
2088static void keyboardCallback(
char touchedKey)
2091 size_t textLen = strlen(context.keyboard.entryBuffer);
2092 PRINTF(
"[keyboardCallback] touchedKey: '%c'\n", touchedKey);
2096 context.keyboard.backCallback();
2099 context.keyboard.entryBuffer[--textLen] =
'\0';
2102 context.keyboard.actionCallback();
2106 context.keyboard.entryBuffer[textLen] = touchedKey;
2107 context.keyboard.entryBuffer[++textLen] =
'\0';
2112 context.keyboard.getSuggestButtons(&context.keyboard.content, &mask);
2114 = &context.keyboard.content.suggestionButtons;
2121 bool allCandidatesFit;
2123 allCandidatesFit = (suggestions->
nbCandidates <= NB_MAX_SUGGESTION_BUTTONS);
2126 allCandidatesFit = (suggestions->
nbUsedButtons < NB_MAX_SUGGESTION_BUTTONS);
2129 displaySuggestionSelection();
2133 else if (textLen >= context.keyboard.entryMaxLen) {
2139 context.keyboard.layoutCtx, context.keyboard.textIndex, context.keyboard.entryBuffer);
2145static void launchReviewAfterWarning(
void)
2147 if (reviewWithWarnCtx.type == REVIEW_USE_CASE) {
2148 useCaseReview(reviewWithWarnCtx.type,
2149 reviewWithWarnCtx.operationType,
2150 reviewWithWarnCtx.tagValueList,
2151 reviewWithWarnCtx.icon,
2152 reviewWithWarnCtx.reviewTitle,
2153 reviewWithWarnCtx.reviewSubTitle,
2154 reviewWithWarnCtx.finishTitle,
2155 reviewWithWarnCtx.choiceCallback);
2157 else if (reviewWithWarnCtx.type == STREAMING_START_REVIEW_USE_CASE) {
2167 displayWarningStep();
2172static void displayBarDetailStep(
void)
2175 = &reviewWithWarnCtx.warning->introDetails->
barList.
details[reviewWithWarnCtx.barDetailIdx];
2182 info.
style = BOLD_TEXT1_INFO;
2198 if (reviewWithWarnCtx.warningPage > 0) {
2199 reviewWithWarnCtx.warningPage--;
2204 if (reviewWithWarnCtx.warningPage < (reviewWithWarnCtx.nbWarningPages - 1)) {
2205 reviewWithWarnCtx.warningPage++;
2207 else if ((reviewWithWarnCtx.warning->predefinedSet == 0)
2208 && (reviewWithWarnCtx.warning->info != NULL)) {
2209 launchReviewAfterWarning();
2216 if (reviewWithWarnCtx.warningPage == reviewWithWarnCtx.firstWarningPage) {
2217 launchReviewAfterWarning();
2220 else if (reviewWithWarnCtx.warningPage == (reviewWithWarnCtx.nbWarningPages - 1)) {
2221 reviewWithWarnCtx.choiceCallback(
false);
2225 else if ((event ==
BUTTON_BOTH_PRESSED) && (reviewWithWarnCtx.warning->introDetails != NULL)
2227 && (reviewWithWarnCtx.warningPage > reviewWithWarnCtx.firstWarningPage)) {
2229 barIdx = reviewWithWarnCtx.warningPage - reviewWithWarnCtx.firstWarningPage - 1;
2230 if ((reviewWithWarnCtx.warning->introDetails->barList.details != NULL)
2231 && (reviewWithWarnCtx.warning->introDetails->barList.details[barIdx].type
2233 reviewWithWarnCtx.barDetailIdx = barIdx;
2234 displayBarDetailStep();
2241 displayWarningStep();
2245static void displayWarningStep(
void)
2250 if ((reviewWithWarnCtx.warning->prelude) && (reviewWithWarnCtx.warningPage == 0)) {
2255 reviewWithWarnCtx.warning->prelude->title,
2256 reviewWithWarnCtx.warning->prelude->description,
2263 if (reviewWithWarnCtx.warningPage == reviewWithWarnCtx.firstWarningPage) {
2265 info.
icon = &C_icon_warning;
2266 info.
text1 =
"Blind signing ahead";
2267 info.
text2 =
"To accept risk, press both buttons";
2268 pos = (reviewWithWarnCtx.firstWarningPage == 0) ?
FIRST_STEP
2272 else if (reviewWithWarnCtx.warningPage == (reviewWithWarnCtx.nbWarningPages - 1)) {
2273 getLastPageInfo(
false, &info.
icon, &info.
text1);
2277 else if ((reviewWithWarnCtx.warning->predefinedSet == 0)
2278 && (reviewWithWarnCtx.warning->info != NULL)) {
2279 if (reviewWithWarnCtx.warningPage == reviewWithWarnCtx.firstWarningPage) {
2280 info.
icon = reviewWithWarnCtx.warning->info->icon;
2281 info.
text1 = reviewWithWarnCtx.warning->info->title;
2282 info.
text2 = reviewWithWarnCtx.warning->info->description;
2283 pos = (reviewWithWarnCtx.firstWarningPage == 0) ?
FIRST_STEP
2287 else if ((reviewWithWarnCtx.warning->introDetails != NULL)
2290 barIdx = reviewWithWarnCtx.warningPage - reviewWithWarnCtx.firstWarningPage - 1;
2291 if (reviewWithWarnCtx.warning->introDetails->barList.icons) {
2292 info.
icon = reviewWithWarnCtx.warning->introDetails->barList.icons[barIdx];
2294 info.
text1 = reviewWithWarnCtx.warning->introDetails->barList.texts[barIdx];
2295 if (reviewWithWarnCtx.warning->introDetails->barList.subTexts) {
2296 info.
text2 = reviewWithWarnCtx.warning->introDetails->barList.subTexts[barIdx];
2300 else if (reviewWithWarnCtx.warningPage == (reviewWithWarnCtx.nbWarningPages - 1)) {
2301 if ((reviewWithWarnCtx.warning->introDetails != NULL)
2303 info.
icon = reviewWithWarnCtx.warning->introDetails->centeredInfo.icon;
2304 info.
text1 = reviewWithWarnCtx.warning->introDetails->centeredInfo.title;
2305 info.
text2 = reviewWithWarnCtx.warning->introDetails->centeredInfo.description;
2318 info.
style = BOLD_TEXT1_INFO;
2324static void displayInitialWarning(
void)
2327 reviewWithWarnCtx.warningPage = 0;
2329 || ((reviewWithWarnCtx.warning->introDetails)
2331 reviewWithWarnCtx.nbWarningPages = 2;
2333 else if ((reviewWithWarnCtx.warning->introDetails)
2335 reviewWithWarnCtx.nbWarningPages
2336 = reviewWithWarnCtx.warning->introDetails->barList.nbBars + 1;
2340 reviewWithWarnCtx.nbWarningPages = 1;
2343 reviewWithWarnCtx.firstWarningPage = 0;
2344 displayWarningStep();
2348static void displayPrelude(
void)
2351 reviewWithWarnCtx.warningPage = 0;
2353 || ((reviewWithWarnCtx.warning->introDetails)
2355 reviewWithWarnCtx.nbWarningPages = 3;
2359 reviewWithWarnCtx.nbWarningPages = 2;
2361 reviewWithWarnCtx.firstWarningPage = 1;
2362 displayWarningStep();
2383 bool *requireSpecificDisplay)
2386 UNUSED(tagValueList);
2388 *requireSpecificDisplay =
true;
2408 bool *requireSpecificDisplay)
2411 UNUSED(tagValueList);
2413 UNUSED(isSkippable);
2414 *requireSpecificDisplay =
true;
2452 UNUSED(switchesList);
2492 UNUSED(choicesList);
2506 uint8_t nbPages = 0;
2507 uint8_t nbPairs = tagValueList->
nbPairs;
2508 uint8_t nbPairsInPage;
2512 while (i < tagValueList->nbPairs) {
2516 nbPairs -= nbPairsInPage;
2542 memset(&context, 0,
sizeof(UseCaseContext_t));
2543 context.type = CONTENT_USE_CASE;
2544 context.currentPage = initPage;
2545 context.content.title = title;
2546 context.content.quitCallback = quitCallback;
2547 context.content.navCallback = navCallback;
2548 context.content.controlsCallback = controlsCallback;
2549 context.content.genericContents.callbackCallNeeded =
true;
2550 context.content.genericContents.nbContents = nbPages;
2552 startUseCaseContent();
2571 const char *tagline,
2572 const uint8_t initSettingPage,
2578 memset(&context, 0,
sizeof(UseCaseContext_t));
2579 context.home.appName = appName;
2580 context.home.appIcon = appIcon;
2581 context.home.tagline = tagline;
2582 context.home.settingContents = PIC(settingContents);
2583 context.home.infosList = PIC(infosList);
2584 context.home.homeAction = action;
2585 context.home.quitCallback = quitCallback;
2587 if ((initSettingPage !=
INIT_HOME_PAGE) && (settingContents != NULL)) {
2588 startUseCaseSettingsAtPage(initSettingPage);
2613 memset(&context, 0,
sizeof(UseCaseContext_t));
2614 context.type = GENERIC_SETTINGS;
2615 context.home.appName = appName;
2616 context.home.settingContents = PIC(settingContents);
2617 context.home.infosList = PIC(infosList);
2618 context.home.quitCallback = quitCallback;
2620 startUseCaseSettingsAtPage(initPage);
2659 const char *reviewTitle,
2660 const char *reviewSubTitle,
2661 const char *finishTitle,
2664 useCaseReview(REVIEW_USE_CASE,
2699 const char *reviewTitle,
2700 const char *reviewSubTitle,
2701 const char *finishTitle,
2707 ContextType_t type = REVIEW_USE_CASE;
2710 if ((warning == NULL)
2730 memset(&reviewWithWarnCtx, 0,
sizeof(reviewWithWarnCtx));
2731 reviewWithWarnCtx.type = type;
2732 reviewWithWarnCtx.operationType = operationType;
2733 reviewWithWarnCtx.tagValueList = tagValueList;
2734 reviewWithWarnCtx.icon = icon;
2735 reviewWithWarnCtx.reviewTitle = reviewTitle;
2736 reviewWithWarnCtx.reviewSubTitle = reviewSubTitle;
2737 reviewWithWarnCtx.finishTitle = finishTitle;
2738 reviewWithWarnCtx.warning = warning;
2739 reviewWithWarnCtx.choiceCallback = choiceCallback;
2742 if (reviewWithWarnCtx.warning->prelude) {
2747 displayInitialWarning();
2783 const char *reviewTitle,
2784 const char *reviewSubTitle,
2785 const char *finishTitle,
2796 &blindSigningWarning,
2817 const char *reviewTitle,
2818 const char *reviewSubTitle,
2819 const char *finishTitle,
2850 const char *reviewTitle,
2851 const char *reviewSubTitle,
2854 memset(&context, 0,
sizeof(UseCaseContext_t));
2855 context.type = ADDRESS_REVIEW_USE_CASE;
2856 context.review.address = address;
2857 context.review.reviewTitle = reviewTitle;
2858 context.review.reviewSubTitle = reviewSubTitle;
2859 context.review.icon = icon;
2860 context.review.onChoice = choiceCallback;
2861 context.currentPage = 0;
2864 context.nbPages = reviewSubTitle ? 5 : 4;
2865 if (additionalTagValueList) {
2866 context.review.tagValueList = PIC(additionalTagValueList);
2867 context.nbPages += additionalTagValueList->
nbPairs;
2882 const char *rejectText,
2885 memset(&context, 0,
sizeof(UseCaseContext_t));
2886 context.type = GENERIC_REVIEW_USE_CASE;
2887 context.content.rejectText = rejectText;
2888 context.content.quitCallback = rejectCallback;
2889 context.content.genericContents.nbContents = contents->
nbContents;
2895 context.content.genericContents.contentsList = PIC(contents->
contentsList);
2898 startUseCaseContent();
2912 memset(&context, 0,
sizeof(UseCaseContext_t));
2913 context.type = STATUS_USE_CASE;
2914 context.stepCallback = quitCallback;
2915 context.currentPage = 0;
2916 context.nbPages = 1;
2922 statusButtonCallback,
2939 switch (reviewStatusType) {
2941 msg =
"Operation signed";
2945 msg =
"Operation rejected";
2949 msg =
"Transaction signed";
2953 msg =
"Transaction rejected";
2957 msg =
"Message signed";
2961 msg =
"Message rejected";
2965 msg =
"Address verified";
2969 msg =
"Address verification cancelled";
2992 const char *reviewTitle,
2993 const char *reviewSubTitle,
2997 streamingOpType = operationType;
2999 memset(&context, 0,
sizeof(UseCaseContext_t));
3000 context.type = STREAMING_START_REVIEW_USE_CASE;
3001 context.operationType = operationType;
3002 context.review.reviewTitle = reviewTitle;
3003 context.review.reviewSubTitle = reviewSubTitle;
3004 context.review.icon = icon;
3005 context.review.onChoice = choiceCallback;
3006 context.currentPage = 0;
3007 context.nbPages = reviewSubTitle ? 3 : 2;
3027 const char *reviewTitle,
3028 const char *reviewSubTitle,
3032 operationType, icon, reviewTitle, reviewSubTitle, &blindSigningWarning, choiceCallback);
3052 const char *reviewTitle,
3053 const char *reviewSubTitle,
3057 memset(&context, 0,
sizeof(UseCaseContext_t));
3058 context.type = STREAMING_START_REVIEW_USE_CASE;
3059 context.operationType = operationType;
3060 context.review.reviewTitle = reviewTitle;
3061 context.review.reviewSubTitle = reviewSubTitle;
3062 context.review.icon = icon;
3063 context.review.onChoice = choiceCallback;
3064 context.currentPage = 0;
3065 context.nbPages = reviewSubTitle ? 3 : 2;
3068 streamingOpType = operationType;
3071 if ((warning == NULL)
3083 memset(&reviewWithWarnCtx, 0,
sizeof(reviewWithWarnCtx));
3085 reviewWithWarnCtx.type = context.type;
3086 reviewWithWarnCtx.operationType = operationType;
3087 reviewWithWarnCtx.icon = icon;
3088 reviewWithWarnCtx.reviewTitle = reviewTitle;
3089 reviewWithWarnCtx.reviewSubTitle = reviewSubTitle;
3090 reviewWithWarnCtx.choiceCallback = choiceCallback;
3091 reviewWithWarnCtx.warning = warning;
3094 if (reviewWithWarnCtx.warning->prelude) {
3099 displayInitialWarning();
3123 uint8_t curNbDataSets = context.review.nbDataSets;
3125 memset(&context, 0,
sizeof(UseCaseContext_t));
3126 context.type = STREAMING_CONTINUE_REVIEW_USE_CASE;
3127 context.operationType = streamingOpType;
3128 context.review.tagValueList = tagValueList;
3129 context.review.onChoice = choiceCallback;
3130 context.currentPage = 0;
3131 context.nbPages = tagValueList->
nbPairs + 1;
3132 context.review.skipCallback = skipCallback;
3133 context.review.nbDataSets = curNbDataSets + 1;
3157 memset(&context, 0,
sizeof(UseCaseContext_t));
3158 context.type = STREAMING_FINISH_REVIEW_USE_CASE;
3159 context.operationType = streamingOpType;
3160 context.review.onChoice = choiceCallback;
3161 context.review.finishTitle = finishTitle;
3162 context.currentPage = 0;
3163 context.nbPages = 2;
3175 memset(&context, 0,
sizeof(UseCaseContext_t));
3176 context.type = SPINNER_USE_CASE;
3177 context.currentPage = 0;
3178 context.nbPages = 1;
3180 displaySpinner(text);
3196 const char *message,
3197 const char *subMessage,
3198 const char *confirmText,
3199 const char *cancelText,
3203 icon, message, subMessage, confirmText, cancelText, NULL, callback);
3221 const char *message,
3222 const char *subMessage,
3223 const char *confirmText,
3224 const char *cancelText,
3228 memset(&context, 0,
sizeof(UseCaseContext_t));
3229 context.type = CHOICE_USE_CASE;
3230 context.choice.icon = icon;
3231 context.choice.message = message;
3232 context.choice.subMessage = subMessage;
3233 context.choice.confirmText = confirmText;
3234 context.choice.cancelText = cancelText;
3235 context.choice.onChoice = callback;
3236 context.choice.details = details;
3237 context.currentPage = 0;
3238 context.nbPages = 2;
3239 if (message != NULL) {
3242 if ((icon != NULL) && (subMessage != NULL)) {
3246 if (details != NULL) {
3263 const char *message,
3264 const char *subMessage,
3265 const char *confirmText,
3266 const char *cancelText,
3273 centerIcon, title, message, confirmText, cancelText, details, callback);
3290 const char *subMessage,
3291 const char *confirmText,
3292 const char *cancelText,
3295 memset(&context, 0,
sizeof(UseCaseContext_t));
3296 context.type = CONFIRM_USE_CASE;
3297 context.confirm.message = message;
3298 context.confirm.subMessage = subMessage;
3299 context.confirm.confirmText = confirmText;
3300 context.confirm.cancelText = cancelText;
3301 context.confirm.onConfirm = callback;
3302 context.currentPage = 0;
3303 context.nbPages = 1 + 2;
3318 const char *message,
3319 const char *actionText,
3327 memset(&context, 0,
sizeof(UseCaseContext_t));
3328 context.type = ACTION_USE_CASE;
3329 context.action.actionCallback = callback;
3331 centeredInfo.
icon = icon;
3332 centeredInfo.
text1 = message;
3333 centeredInfo.
style = BOLD_TEXT1_INFO;
3368 memset(&context, 0,
sizeof(KeypadContext_t));
3369 context.type = KEYPAD_USE_CASE;
3370 context.currentPage = 0;
3371 context.nbPages = 1;
3372 context.keypad.validatePin = validatePinCallback;
3373 context.keypad.backCallback = backCallback;
3374 context.keypad.pinMinDigits = minDigits;
3375 context.keypad.pinMaxDigits = maxDigits;
3376 context.keypad.hidden = hidden;
3384 context.keypad.keypadIndex = status;
3392 if (context.keypad.backCallback != NULL) {
3433 .mode = params->
mode,
3439 memset(&context, 0,
sizeof(UseCaseContext_t));
3440 context.type = KEYBOARD_USE_CASE;
3441 context.currentPage = 0;
3442 context.nbPages = 1;
3443 context.keyboard.entryBuffer = PIC(params->
entryBuffer);
3444 context.keyboard.entryMaxLen = params->
entryMaxLen;
3445 context.keyboard.entryBuffer[0] =
'\0';
3447 context.keyboard.content.type = params->
type;
3450 context.keyboard.backCallback = PIC(backCallback);
3452 switch (params->
type) {
3459 context.keyboard.getSuggestButtons
3482 context.keyboard.keyboardIndex = status;
3489 context.keyboard.textIndex = status;
3491 nbgl_layoutAddNavigation(context.keyboard.layoutCtx, &navInfo);
nbgl_contentCenteredInfoStyle_t
possible styles for Centered Info Area
@ CHOICES_LIST
list of choices through radio buttons
@ CENTERED_INFO
a centered info
@ SWITCHES_LIST
list of switches with descriptions
@ INFOS_LIST
list of infos with titles
@ TAG_VALUE_CONFIRM
tag/value pairs and a black button/footer to confirm/cancel.
@ TAG_VALUE_LIST
list of tag/value pairs
@ BARS_LIST
list of touchable bars (with > on the right to go to sub-pages)
@ INFO_BUTTON
a centered info and a simple black button
@ INFO_LIST_ALIAS
alias is list of infos
@ ENS_ALIAS
alias comes from ENS
@ ADDRESS_BOOK_ALIAS
alias comes from Address Book
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_WARN(__logger,...)
#define LOG_DEBUG(__logger,...)
void(* nbgl_stepCallback_t)(void)
prototype of function to be called when a step is using a callback on "double-key" action
void(* nbgl_layoutTouchCallback_t)(int token, uint8_t index)
prototype of function to be called when an object is touched
DEPRECATED int nbgl_layoutAddEnteredText(nbgl_layout_t *layout, bool numbered, uint8_t number, const char *text, bool grayedOut, int offsetY, int token)
Adds a "text entry" area under the previously entered object. This area can be preceded (beginning of...
int nbgl_layoutUpdateKeyboard(nbgl_layout_t *layout, uint8_t index, uint32_t keyMask, bool updateCasing, keyboardCase_t casing)
Updates an existing keyboard on bottom of the screen, with the given configuration.
int nbgl_layoutAddKeyboard(nbgl_layout_t *layout, const nbgl_layoutKbd_t *kbdInfo)
Creates a keyboard on bottom of the screen, with the given configuration.
@ HORIZONTAL_NAV
'<' and '>' are displayed, to navigate between pages and steps
@ LEFT_ARROW
left arrow is used
@ RIGHT_ARROW
right arrow is used
int nbgl_layoutUpdateKeypad(nbgl_layout_t *layout, uint8_t index, bool enableValidate, bool enableBackspace, bool enableDigits)
Updates an existing keypad on bottom of the screen, with the given configuration.
int nbgl_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...
int nbgl_layoutDraw(nbgl_layout_t *layout)
Applies given layout. The screen will be redrawn.
void * nbgl_layout_t
type shared externally
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.
nbgl_layout_t * nbgl_layoutGet(const nbgl_layoutDescription_t *description)
returns a layout of the given type. The layout is reset
@ KEYBOARD_WITH_BUTTON
text entry area + confirmation button
@ KEYBOARD_WITH_SUGGESTIONS
text entry area + suggestion buttons
int nbgl_layoutRelease(nbgl_layout_t *layout)
Release the layout obtained with nbgl_layoutGet()
DEPRECATED int nbgl_layoutUpdateEnteredText(nbgl_layout_t *layout, uint8_t index, bool numbered, uint8_t number, const char *text, bool grayedOut)
Updates an existing "text entry" area, created with nbgl_layoutAddEnteredText()
int nbgl_layoutAddKeypad(nbgl_layout_t *layout, keyboardCallback_t callback, bool shuffled)
Adds a keypad on bottom of the screen, with the associated callback.
@ BUTTON_BOTH_PRESSED
Sent when both buttons are released.
@ BUTTON_LEFT_PRESSED
Sent when Left button is released.
@ BUTTON_RIGHT_PRESSED
Send when Right button is released.
struct PACKED__ nbgl_screenTickerConfiguration_s nbgl_screenTickerConfiguration_t
struct to configure a screen layer
void nbgl_screenRedraw(void)
void(* nbgl_stepButtonCallback_t)(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
prototype of function to be called when buttons are touched on a screen
#define GET_POS_OF_STEP(_step, _nb_steps)
nbgl_step_t nbgl_stepDrawSwitch(nbgl_stepPosition_t pos, nbgl_stepButtonCallback_t onActionCallback, nbgl_screenTickerConfiguration_t *ticker, nbgl_layoutSwitch_t *switchInfo, bool modal)
void * nbgl_step_t
type shared externally
uint8_t nbgl_stepPosition_t
this type is a bitfield containing:
nbgl_step_t nbgl_stepDrawMenuList(nbgl_stepMenuListCallback_t onActionCallback, nbgl_screenTickerConfiguration_t *ticker, nbgl_layoutMenuList_t *list, bool modal)
#define ACTION_ON_ANY_BUTTON
When action callback applies only on both button press.
@ NEITHER_FIRST_NOR_LAST_STEP
neither first nor last in a multiple steps flow
@ SINGLE_STEP
single step flow
@ LAST_STEP
last in a multiple steps flow
@ FIRST_STEP
first in a multiple steps flow
int nbgl_stepRelease(nbgl_step_t step)
#define FORWARD_DIRECTION
When the flow is navigated from last to first step.
nbgl_step_t nbgl_stepDrawText(nbgl_stepPosition_t pos, nbgl_stepButtonCallback_t onActionCallback, nbgl_screenTickerConfiguration_t *ticker, const char *text, const char *subText, nbgl_contentCenteredInfoStyle_t style, bool modal)
nbgl_step_t nbgl_stepDrawCenteredInfo(nbgl_stepPosition_t pos, nbgl_stepButtonCallback_t onActionCallback, nbgl_screenTickerConfiguration_t *ticker, nbgl_layoutCenteredInfo_t *info, bool modal)
#define BACKWARD_DIRECTION
When action callback applies on any button press.
nbgl_state_t
to represent a boolean state.
struct PACKED__ nbgl_icon_details_s nbgl_icon_details_t
Represents all information about an icon.
API of the Advanced BOLOS Graphical Library, for typical application use-cases.
@ NO_TYPE_WARNING
Invalid type (to use for bars leading to nothing)
@ CENTERED_INFO_WARNING
Centered info.
@ BAR_LIST_WARNING
list of touchable bars, to display sub-pages
uint8_t nbgl_useCaseGetNbTagValuesInPageExt(uint8_t nbPairs, const nbgl_contentTagValueList_t *tagValueList, uint8_t startIndex, bool isSkippable, bool *requireSpecificDisplay)
void(* nbgl_callback_t)(void)
prototype of generic callback function
#define SKIPPABLE_OPERATION
This is to use in nbgl_operationType_t when the operation is skippable. This is used.
void nbgl_useCaseGenericSettings(const char *appName, uint8_t initPage, const nbgl_genericContents_t *settingContents, const nbgl_contentInfoList_t *infosList, nbgl_callback_t quitCallback)
uint32_t nbgl_operationType_t
This mask is used to describe the type of operation to review with additional options It is a mask of...
void nbgl_useCaseReview(nbgl_operationType_t operationType, const nbgl_contentTagValueList_t *tagValueList, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, const char *finishTitle, nbgl_choiceCallback_t choiceCallback)
void nbgl_useCaseAction(const nbgl_icon_details_t *icon, const char *message, const char *actionText, nbgl_callback_t callback)
uint8_t nbgl_useCaseGetNbTagValuesInPage(uint8_t nbPairs, const nbgl_contentTagValueList_t *tagValueList, uint8_t startIndex, bool *requireSpecificDisplay)
uint8_t nbgl_useCaseGetNbPagesForTagValueList(const nbgl_contentTagValueList_t *tagValueList)
void(* nbgl_pinValidCallback_t)(const uint8_t *pin, uint8_t pinLen)
prototype of pin validation callback function
void nbgl_useCaseReviewStreamingStart(nbgl_operationType_t operationType, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, nbgl_choiceCallback_t choiceCallback)
void nbgl_useCaseHomeAndSettings(const char *appName, const nbgl_icon_details_t *appIcon, const char *tagline, const uint8_t initSettingPage, const nbgl_genericContents_t *settingContents, const nbgl_contentInfoList_t *infosList, const nbgl_homeAction_t *action, nbgl_callback_t quitCallback)
#define RISKY_OPERATION
This is to use in nbgl_operationType_t when the operation is concerned by an internal warning....
uint8_t nbgl_useCaseGetNbInfosInPage(uint8_t nbInfos, const nbgl_contentInfoList_t *infosList, uint8_t startIndex, bool withNav)
void(* nbgl_choiceCallback_t)(bool confirm)
prototype of choice callback function
uint8_t nbgl_useCaseGetNbBarsInPage(uint8_t nbBars, const nbgl_contentBarsList_t *barsList, uint8_t startIndex, bool withNav)
void nbgl_useCaseNavigableContent(const char *title, uint8_t initPage, uint8_t nbPages, nbgl_callback_t quitCallback, nbgl_navCallback_t navCallback, nbgl_layoutTouchCallback_t controlsCallback)
void nbgl_useCaseReviewStreamingFinish(const char *finishTitle, nbgl_choiceCallback_t choiceCallback)
#define NO_THREAT_OPERATION
This is to use in nbgl_operationType_t when the operation is concerned by an internal information....
void nbgl_useCaseChoiceWithDetails(const nbgl_icon_details_t *icon, const char *message, const char *subMessage, const char *confirmText, const char *cancelText, nbgl_warningDetails_t *details, nbgl_choiceCallback_t callback)
void nbgl_useCaseAdvancedChoiceWithDetails(const nbgl_icon_details_t *centerIcon, const nbgl_icon_details_t *headerIcon, const char *title, const char *message, const char *subMessage, const char *confirmText, const char *cancelText, nbgl_warningDetails_t *details, nbgl_choiceCallback_t callback)
void nbgl_useCaseSpinner(const char *text)
void nbgl_useCaseConfirm(const char *message, const char *subMessage, const char *confirmText, const char *rejectText, nbgl_callback_t callback)
void nbgl_useCaseStatus(const char *message, bool isSuccess, nbgl_callback_t quitCallback)
@ BLIND_SIGNING_WARN
Blind signing.
@ W3C_NO_THREAT_WARN
Web3 Checks: No Threat detected.
void nbgl_useCaseGenericConfiguration(const char *title, uint8_t initPage, const nbgl_genericContents_t *contents, nbgl_callback_t quitCallback)
#define INIT_HOME_PAGE
Value to pass to nbgl_useCaseHomeAndSettings() initSettingPage parameter to initialize the use case o...
void nbgl_useCaseKeypad(const char *title, uint8_t minDigits, uint8_t maxDigits, bool shuffled, bool hidden, nbgl_pinValidCallback_t validatePinCallback, nbgl_callback_t backCallback)
void nbgl_useCaseReviewStreamingContinueExt(const nbgl_contentTagValueList_t *tagValueList, nbgl_choiceCallback_t choiceCallback, nbgl_callback_t skipCallback)
void nbgl_useCaseReviewBlindSigning(nbgl_operationType_t operationType, const nbgl_contentTagValueList_t *tagValueList, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, const char *finishTitle, const nbgl_tipBox_t *tipBox, nbgl_choiceCallback_t choiceCallback)
void nbgl_useCaseChoice(const nbgl_icon_details_t *icon, const char *message, const char *subMessage, const char *confirmText, const char *rejectString, nbgl_choiceCallback_t callback)
void nbgl_useCaseGenericReview(const nbgl_genericContents_t *contents, const char *rejectText, nbgl_callback_t rejectCallback)
#define STATUS_SCREEN_DURATION
void nbgl_useCaseKeyboard(const nbgl_keyboardParams_t *params, nbgl_callback_t backCallback)
void nbgl_useCaseReviewStreamingBlindSigningStart(nbgl_operationType_t operationType, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, nbgl_choiceCallback_t choiceCallback)
void nbgl_useCaseReviewStreamingContinue(const nbgl_contentTagValueList_t *tagValueList, nbgl_choiceCallback_t choiceCallback)
void nbgl_useCaseReviewLight(nbgl_operationType_t operationType, const nbgl_contentTagValueList_t *tagValueList, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, const char *finishTitle, nbgl_choiceCallback_t choiceCallback)
uint8_t nbgl_useCaseGetNbChoicesInPage(uint8_t nbChoices, const nbgl_contentRadioChoice_t *choicesList, uint8_t startIndex, bool withNav)
void(* nbgl_keyboardButtonsCallback_t)(nbgl_layoutKeyboardContent_t *content, uint32_t *mask)
prototype of keyboard buttons callback function
#define REAL_TYPE_MASK
Mask to apply on nbgl_operationType_t to extract the base nbgl_opType_t. Bits 0-3 are reserved for th...
void nbgl_useCaseReviewStatus(nbgl_reviewStatusType_t reviewStatusType, nbgl_callback_t quitCallback)
#define ADDRESS_BOOK_OPERATION
This is to use in nbgl_operationType_t when the operation is related to "Address Book" to adapt wordi...
nbgl_reviewStatusType_t
The different types of review status.
@ STATUS_TYPE_TRANSACTION_REJECTED
@ STATUS_TYPE_ADDRESS_REJECTED
@ STATUS_TYPE_TRANSACTION_SIGNED
@ STATUS_TYPE_OPERATION_REJECTED
@ STATUS_TYPE_OPERATION_SIGNED
@ STATUS_TYPE_ADDRESS_VERIFIED
@ STATUS_TYPE_MESSAGE_SIGNED
@ STATUS_TYPE_MESSAGE_REJECTED
bool(* nbgl_navCallback_t)(uint8_t page, nbgl_pageContent_t *content)
prototype of navigation callback function
#define HAS_INITIAL_WARNING(_warning)
void nbgl_useCaseAddressReview(const char *address, const nbgl_contentTagValueList_t *additionalTagValueList, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, nbgl_choiceCallback_t choiceCallback)
@ TYPE_TRANSACTION
For operations transferring a coin or taken from an account to another.
void nbgl_useCaseAdvancedReviewStreamingStart(nbgl_operationType_t operationType, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, const nbgl_warning_t *warning, nbgl_choiceCallback_t choiceCallback)
void nbgl_useCaseAdvancedReview(nbgl_operationType_t operationType, const nbgl_contentTagValueList_t *tagValueList, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, const char *finishTitle, const nbgl_tipBox_t *tipBox, const nbgl_warning_t *warning, nbgl_choiceCallback_t choiceCallback)
uint8_t nbgl_useCaseGetNbSwitchesInPage(uint8_t nbSwitches, const nbgl_contentSwitchesList_t *switchesList, uint8_t startIndex, bool withNav)
This structure contains data to build a BARS_LIST content.
const uint8_t * tokens
array of tokens, one for each bar (nbBars items)
const char *const * barTexts
array of texts for each bar (nbBars items, in black/bold)
uint8_t nbBars
number of elements in barTexts and tokens array
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)
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
const nbgl_icon_details_t * icon
a buffer containing the 1BPP icon
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.
const char *const * infoContents
array of contents of infos (in black)
const char *const * infoTypes
array of types of infos (in black/bold)
uint8_t nbInfos
number of elements in infoTypes and infoContents array
This structure contains a list of names to build a list of radio buttons (on the right part of screen...
uint8_t token
the token that will be used as argument of the callback
uint8_t initChoice
index of the current choice
const char *const * names
array of strings giving the choices (nbChoices)
uint8_t nbChoices
number of choices
This structure contains info to build a switch (on the right) with a description (on the left),...
const char * text
main text for the switch
uint8_t token
the token that will be used as argument of the callback (unused on Nano)
nbgl_state_t initState
initial state of the switch
const char * subText
description under main text (NULL terminated, single line, may be null)
const char * confirmationText
text of the confirmation button, if NULL "It matches" is used
uint8_t confirmationToken
the token used as argument of the onActionCallback
nbgl_contentTagValueList_t tagValueList
list of tag/value pairs
This structure contains a list of [tag,value] pairs.
const nbgl_contentTagValue_t * pairs
array of [tag,value] pairs (nbPairs items). If NULL, callback is used instead
nbgl_contentTagValueCallback_t callback
function to call to retrieve a given pair
This structure contains a [tag,value] pair and possible extensions.
const nbgl_contentValueExt_t * extension
if not NULL, gives additional info on value field
const nbgl_icon_details_t * valueIcon
const char * value
string giving the value name
const char * item
string giving the tag name
uint8_t centeredInfo
if set to 1, the tag will be displayed as a centered info
This structure contains additions to a tag/value pair, to be able to build a screen to display these ...
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
const struct nbgl_genericDetails_s * details
array of nbBars structures giving what to display when each bar is touched.
uint8_t nbBars
number of touchable bars
uint8_t nbContents
number of contents
const nbgl_content_t * contentsList
array of nbgl_content_t (nbContents items).
nbgl_contentCallback_t contentGetterCallback
function to call to retrieve a given content
The necessary parameters to build the page(s) displayed when the top-right button is touched in intro...
nbgl_genericBarList_t barList
touchable bars list, if type == BAR_LIST_WARNING
nbgl_genericDetailsType_t type
type of content in the page, determining what to use in the following union
nbgl_contentCenter_t centeredInfo
centered info, if type == CENTERED_INFO_WARNING
Structure describing the action button in Home Screen.
nbgl_keyboardButtonsCallback_t updateButtonsCallback
callback to call when a key is pressed to update suggestions
nbgl_layoutTouchCallback_t onButtonCallback
callback to call when one of the buttons is pressed
const char ** buttons
array of strings for buttons (last ones can be NULL)
int firstButtonToken
first token used for buttons, provided in onButtonCallback
Structure containing all parameters for keyboard use case.
keyboardMode_t mode
keyboard mode to start with
nbgl_kbdSuggestParams_t suggestionParams
nbgl_kbdButtonParams_t confirmationParams
used if type is KEYBOARD_WITH_SUGGESTIONS
bool lettersOnly
if true, only display letter keys and Backspace
uint8_t entryMaxLen
maximum length of text that can be entered
nbgl_layoutKeyboardContentType_t type
type of content
const char * title
centered title explaining the screen
char * entryBuffer
already entered text
Structure containing all information when creating a layout. This structure must be passed as argumen...
This structure contains info to build a keyboard with nbgl_layoutAddKeyboard()
keyboardCallback_t callback
function called when an active key is pressed
This structure contains info to build a keyboard content (controls that are linked to keyboard)
This structure contains info to build a navigation bar at the bottom of the screen.
nbgl_layoutNavDirection_t direction
vertical or horizontal navigation
This structure contains data to build a page in multi-pages mode (nbgl_pageDrawGenericContent)
nbgl_contentRadioChoice_t choicesList
CHOICES_LIST type
nbgl_contentSwitchesList_t switchesList
SWITCHES_LIST type
nbgl_contentBarsList_t barsList
BARS_LIST type
nbgl_contentInfoButton_t infoButton
INFO_BUTTON type
nbgl_contentInfoList_t infosList
INFOS_LIST type
nbgl_contentTagValueList_t tagValueList
TAG_VALUE_LIST type
nbgl_contentType_t type
type of page content in the following union
nbgl_contentCenteredInfo_t centeredInfo
CENTERED_INFO type
nbgl_contentTagValueConfirm_t tagValueConfirm
TAG_VALUE_CONFIRM type
This structure contains data to build a SWITCHES_LIST content.
uint8_t nbSwitches
number of elements in switches and tokens array
const nbgl_contentSwitch_t * switches
array of switches (nbSwitches items)
The necessary parameters to build a tip-box in first review page and the modal if this tip box is tou...
The necessary parameters to build a warning page preceding a review. One can either use predefinedSet...
const nbgl_preludeDetails_t * prelude
if not null, means that the review can start by a prelude
const nbgl_warningDetails_t * reviewDetails
const nbgl_contentCenter_t * info
parameters to build the intro warning page, if not using pre-defined
nbgl_contentInfoList_t infosList
INFOS_LIST 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_contentSwitchesList_t switchesList
SWITCHES_LIST type
nbgl_contentInfoButton_t infoButton
INFO_BUTTON type
nbgl_contentRadioChoice_t choicesList
CHOICES_LIST type