Skip to content

Commit

Permalink
Merge pull request #707 from LedgerHQ/fix-reject-text-for-old-use-case
Browse files Browse the repository at this point in the history
Force reject text when using old Use Case API
  • Loading branch information
nroggeman-ledger committed Jun 24, 2024
2 parents 2e56806 + d8b570a commit 481a418
Showing 1 changed file with 102 additions and 90 deletions.
192 changes: 102 additions & 90 deletions lib_nbgl/src/nbgl_use_case.c
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,64 @@ static void bundleNavReviewStreamingChoice(bool confirm)
}
}

static void 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,
bool isLight)
{
reset_callbacks();
memset(&genericContext, 0, sizeof(genericContext));

bundleNavContext.review.operationType = operationType;
bundleNavContext.review.choiceCallback = choiceCallback;

// memorize context
onChoice = bundleNavReviewChoice;
navType = GENERIC_NAV;
pageTitle = NULL;

genericContext.genericContents.contentsList = localContentsList;
genericContext.genericContents.nbContents = 3;
memset(localContentsList, 0, 3 * sizeof(nbgl_content_t));

// First a centered info
STARTING_CONTENT.type = CENTERED_INFO;
prepareReviewFirstPage(
&STARTING_CONTENT.content.centeredInfo, icon, reviewTitle, reviewSubTitle);

// Then the tag/value pairs
localContentsList[1].type = TAG_VALUE_LIST;
memcpy(&localContentsList[1].content.tagValueList,
tagValueList,
sizeof(nbgl_contentTagValueList_t));
localContentsList[1].contentActionCallback = tagValueList->actionCallback;

// The last page
if (isLight) {
localContentsList[2].type = INFO_BUTTON;
prepareReviewLightLastPage(&localContentsList[2].content.infoButton, icon, finishTitle);
}
else {
localContentsList[2].type = INFO_LONG_PRESS;
prepareReviewLastPage(&localContentsList[2].content.infoLongPress, icon, finishTitle);
}

// compute number of pages & fill navigation structure
uint8_t nbPages = nbgl_useCaseGetNbPagesForGenericContents(&genericContext.genericContents, 0);
prepareNavInfo(true, nbPages, getRejectReviewText(operationType));

#ifdef HAVE_PIEZO_SOUND
// Play notification sound
io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
#endif // HAVE_PIEZO_SOUND

displayGenericContextPage(0, true);
}

/**********************
* GLOBAL FUNCTIONS
**********************/
Expand Down Expand Up @@ -1894,11 +1952,10 @@ void nbgl_useCasePlugInHome(const char *plugInName,
* For each page, the given navCallback will be called to get the content. Only 'type' and
* union has to be set in this content
*
* @param title string to set in touchable (or not) title
* @param title string to set in touchable title
* @param initPage page on which to start [0->(nbPages-1)]
* @param nbPages number of pages
* @param touchable if true, the title is used to quit and quitCallback is called (unused, it is
* always on)
* @param touchable unused, it is always on
* @param quitCallback callback called when quit button (or title) is pressed
* @param navCallback callback called when navigation arrows are pressed
* @param controlsCallback callback called when any controls in the settings (radios, switches) is
Expand Down Expand Up @@ -2290,7 +2347,8 @@ void nbgl_useCaseRegularReview(uint8_t initPage,
navType = REVIEW_NAV;

// fill navigation structure
prepareNavInfo(true, nbPages, rejectText);
UNUSED(rejectText);
prepareNavInfo(true, nbPages, getRejectReviewText(TYPE_OPERATION));

displayReviewPage(initPage, true);
}
Expand Down Expand Up @@ -2326,7 +2384,8 @@ void nbgl_useCaseForwardOnlyReview(const char *rejectText,
navType = REVIEW_NAV;

// fill navigation structure
prepareNavInfo(true, NBGL_NO_PROGRESS_INDICATOR, rejectText);
UNUSED(rejectText);
prepareNavInfo(true, NBGL_NO_PROGRESS_INDICATOR, getRejectReviewText(TYPE_OPERATION));

navInfo.progressIndicator = false;
navInfo.skipText = "Skip";
Expand Down Expand Up @@ -2366,7 +2425,8 @@ void nbgl_useCaseForwardOnlyReviewNoSkip(const char *rejectText,
navType = REVIEW_NAV;

// fill navigation structure
prepareNavInfo(true, NBGL_NO_PROGRESS_INDICATOR, rejectText);
UNUSED(rejectText);
prepareNavInfo(true, NBGL_NO_PROGRESS_INDICATOR, getRejectReviewText(TYPE_OPERATION));
navInfo.progressIndicator = false;
displayReviewPage(0, false);
}
Expand Down Expand Up @@ -2420,7 +2480,8 @@ void nbgl_useCaseStaticReview(const nbgl_contentTagValueList_t *tagValueList,

// compute number of pages & fill navigation structure
uint8_t nbPages = nbgl_useCaseGetNbPagesForGenericContents(&genericContext.genericContents, 0);
prepareNavInfo(true, nbPages, rejectText);
UNUSED(rejectText);
prepareNavInfo(true, nbPages, getRejectReviewText(TYPE_OPERATION));

displayGenericContextPage(0, true);
}
Expand Down Expand Up @@ -2476,14 +2537,16 @@ void nbgl_useCaseStaticReviewLight(const nbgl_contentTagValueList_t *tagValueLis

// compute number of pages & fill navigation structure
uint8_t nbPages = nbgl_useCaseGetNbPagesForGenericContents(&genericContext.genericContents, 0);
prepareNavInfo(true, nbPages, rejectText);
UNUSED(rejectText);
prepareNavInfo(true, nbPages, getRejectReviewText(TYPE_OPERATION));

displayGenericContextPage(0, true);
}

/**
* @brief Draws a flow of pages of a review. A back key is available on top-left of the screen,
* except in first page It is possible to go to next page thanks to "tap to continue".
* @brief Draws a flow of pages of a review. Navigation operates with either swipe or navigation
* keys at bottom right. The last page contains a long-press button with the given finishTitle and
* the given icon.
* @note All tag/value pairs are provided in the API and the number of pages is automatically
* computed, the last page being a long press one
*
Expand All @@ -2504,52 +2567,20 @@ void nbgl_useCaseReview(nbgl_operationType_t operationType,
const char *finishTitle,
nbgl_choiceCallback_t choiceCallback)
{
reset_callbacks();
memset(&genericContext, 0, sizeof(genericContext));

bundleNavContext.review.operationType = operationType;
bundleNavContext.review.choiceCallback = choiceCallback;

// memorize context
onChoice = bundleNavReviewChoice;
navType = GENERIC_NAV;
pageTitle = NULL;

genericContext.genericContents.contentsList = localContentsList;
genericContext.genericContents.nbContents = 3;
memset(localContentsList, 0, 3 * sizeof(nbgl_content_t));

// First a centered info
STARTING_CONTENT.type = CENTERED_INFO;
prepareReviewFirstPage(
&STARTING_CONTENT.content.centeredInfo, icon, reviewTitle, reviewSubTitle);

// Then the tag/value pairs
localContentsList[1].type = TAG_VALUE_LIST;
memcpy(&localContentsList[1].content.tagValueList,
tagValueList,
sizeof(nbgl_contentTagValueList_t));
localContentsList[1].contentActionCallback = tagValueList->actionCallback;

// Eventually the long press page
localContentsList[2].type = INFO_LONG_PRESS;
prepareReviewLastPage(&localContentsList[2].content.infoLongPress, icon, finishTitle);

// compute number of pages & fill navigation structure
uint8_t nbPages = nbgl_useCaseGetNbPagesForGenericContents(&genericContext.genericContents, 0);
prepareNavInfo(true, nbPages, getRejectReviewText(operationType));

#ifdef HAVE_PIEZO_SOUND
// Play notification sound
io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
#endif // HAVE_PIEZO_SOUND

displayGenericContextPage(0, true);
useCaseReview(operationType,
tagValueList,
icon,
reviewTitle,
reviewSubTitle,
finishTitle,
choiceCallback,
false);
}

/**
* @brief Draws a flow of pages of a light review. A back key is available on top-left of the
* screen, except in first page It is possible to go to next page thanks to "tap to continue".
* @brief Draws a flow of pages of a light review. Navigation operates with either swipe or
* navigation keys at bottom right. The last page contains a button/footer with the given
* finishTitle and the given icon.
* @note All tag/value pairs are provided in the API and the number of pages is automatically
* computed, the last page being a short press one
*
Expand All @@ -2570,43 +2601,14 @@ void nbgl_useCaseReviewLight(nbgl_operationType_t operationType,
const char *finishTitle,
nbgl_choiceCallback_t choiceCallback)
{
reset_callbacks();
memset(&genericContext, 0, sizeof(genericContext));

// memorize context
onChoice = choiceCallback;
navType = GENERIC_NAV;
pageTitle = NULL;

genericContext.genericContents.contentsList = localContentsList;
genericContext.genericContents.nbContents = 3;
memset(localContentsList, 0, 3 * sizeof(nbgl_content_t));

// First a centered info
STARTING_CONTENT.type = CENTERED_INFO;
prepareReviewFirstPage(
&STARTING_CONTENT.content.centeredInfo, icon, reviewTitle, reviewSubTitle);

// Then the tag/value pairs
localContentsList[1].type = TAG_VALUE_LIST;
memcpy(&localContentsList[1].content.tagValueList,
tagValueList,
sizeof(nbgl_contentTagValueList_t));

// Eventually the long press page
localContentsList[2].type = INFO_BUTTON;
prepareReviewLightLastPage(&localContentsList[2].content.infoButton, icon, finishTitle);

// compute number of pages & fill navigation structure
uint8_t nbPages = nbgl_useCaseGetNbPagesForGenericContents(&genericContext.genericContents, 0);
prepareNavInfo(true, nbPages, getRejectReviewText(operationType));

#ifdef HAVE_PIEZO_SOUND
// Play notification sound
io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
#endif // HAVE_PIEZO_SOUND

displayGenericContextPage(0, true);
useCaseReview(operationType,
tagValueList,
icon,
reviewTitle,
reviewSubTitle,
finishTitle,
choiceCallback,
true);
}

/**
Expand Down Expand Up @@ -2637,6 +2639,11 @@ void nbgl_useCaseGenericReview(const nbgl_genericContents_t *contents,
prepareNavInfo(true, nbPages, rejectText);
navInfo.quitToken = QUIT_TOKEN;

#ifdef HAVE_PIEZO_SOUND
// Play notification sound
io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
#endif // HAVE_PIEZO_SOUND

displayGenericContextPage(0, true);
}

Expand Down Expand Up @@ -2891,6 +2898,11 @@ void nbgl_useCaseAddressConfirmationExt(const char *addres

prepareNavInfo(true, nbPages, "Cancel");

#ifdef HAVE_PIEZO_SOUND
// Play notification sound
io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
#endif // HAVE_PIEZO_SOUND

displayGenericContextPage(0, true);
}

Expand Down

0 comments on commit 481a418

Please sign in to comment.