Skip to content

Commit

Permalink
Merge pull request #627 from LedgerHQ/review-light
Browse files Browse the repository at this point in the history
nbgl_use_case: add nbgl_useCaseReviewLight
  • Loading branch information
sgliner-ledger authored Apr 18, 2024
2 parents 7344925 + c951b1c commit 29e06e7
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib_nbgl/include/nbgl_use_case.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ void nbgl_useCaseReview(nbgl_operationType_t operationType,
const char *finishTitle,
nbgl_choiceCallback_t choiceCallback);

void nbgl_useCaseReviewLight(nbgl_operationType_t operationType,
const nbgl_layoutTagValueList_t *tagValueList,
const nbgl_icon_details_t *icon,
const char *reviewTitle,
const char *reviewSubTitle,
const char *finishTitle,
nbgl_choiceCallback_t choiceCallback);

void nbgl_useCaseAddressReview(const char *address,
const nbgl_layoutTagValueList_t *additionalTagValueList,
const nbgl_icon_details_t *icon,
Expand Down
67 changes: 67 additions & 0 deletions lib_nbgl/src/nbgl_use_case.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,16 @@ static void prepareReviewLastPage(nbgl_contentInfoLongPress_t *infoLongPress,
infoLongPress->longPressToken = CONFIRM_TOKEN;
}

static void prepareReviewLightLastPage(nbgl_contentInfoButton_t *infoButton,
const nbgl_icon_details_t *icon,
const char *finishTitle)
{
infoButton->text = finishTitle;
infoButton->icon = icon;
infoButton->buttonText = "Approve";
infoButton->buttonToken = CONFIRM_TOKEN;
}

static const char *getRejectReviewText(nbgl_operationType_t operationType)
{
#ifdef TARGET_STAX
Expand Down Expand Up @@ -2397,6 +2407,63 @@ void nbgl_useCaseReview(nbgl_operationType_t operationType,
displayGenericContextPage(0, true);
}

/**
* @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".
* @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
*
* @param operationType type of operation (Operation, Transaction, Message)
* @param tagValueList list of tag/value pairs
* @param icon icon used on first and last review page
* @param reviewTitle string used in the first review page
* @param reviewSubTitle string to set under reviewTitle (can be NULL)
* @param finishTitle string used in the last review page
* @param choiceCallback callback called when operation is accepted (param is true) or rejected
* (param is false)
*/
void nbgl_useCaseReviewLight(nbgl_operationType_t operationType,
const nbgl_layoutTagValueList_t *tagValueList,
const nbgl_icon_details_t *icon,
const char *reviewTitle,
const char *reviewSubTitle,
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
localContentsList[0].type = CENTERED_INFO;
prepareReviewFirstPage(
&localContentsList[0].content.centeredInfo, icon, reviewTitle, reviewSubTitle);

// Then the tag/value pairs
localContentsList[1].type = TAG_VALUE_LIST;
memcpy(&localContentsList[1].content.tagValueList,
tagValueList,
sizeof(nbgl_layoutTagValueList_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));

displayGenericContextPage(0, true);
}

/**
* @brief Draws a flow of pages of a review with automatic pagination depending on content
* to be displayed that is passed through contents.
Expand Down
7 changes: 7 additions & 0 deletions lib_ux_sync/include/ux_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ ux_sync_ret_t ux_sync_review(nbgl_operationType_t operationType,
const char *reviewSubTitle,
const char *finishTitle);

ux_sync_ret_t ux_sync_reviewLight(nbgl_operationType_t operationType,
const nbgl_layoutTagValueList_t *tagValueList,
const nbgl_icon_details_t *icon,
const char *reviewTitle,
const char *reviewSubTitle,
const char *finishTitle);

ux_sync_ret_t ux_sync_addressReview(const char *address,
const nbgl_layoutTagValueList_t *additionalTagValueList,
const nbgl_icon_details_t *icon,
Expand Down
34 changes: 34 additions & 0 deletions lib_ux_sync/src/ux_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,40 @@ ux_sync_ret_t ux_sync_review(nbgl_operationType_t operationType,
return ux_sync_wait(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".
* @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
*
* @param operationType type of operation (Operation, Transaction, Message)
* @param tagValueList list of tag/value pairs
* @param icon icon used on first and last review page
* @param reviewTitle string used in the first review page
* @param reviewSubTitle string to set under reviewTitle (can be NULL)
* @param finishTitle string used in the last review page
*
* @return ret code:
* - UX_SYNC_RET_APPROVED
* - UX_SYNC_RET_REJECTED
*/
ux_sync_ret_t ux_sync_reviewLight(nbgl_operationType_t operationType,
const nbgl_layoutTagValueList_t *tagValueList,
const nbgl_icon_details_t *icon,
const char *reviewTitle,
const char *reviewSubTitle,
const char *finishTitle)
{
ux_sync_init();
nbgl_useCaseReviewLight(operationType,
tagValueList,
icon,
reviewTitle,
reviewSubTitle,
finishTitle,
choice_callback);
return ux_sync_wait(false);
}
/**
* @brief Draws a flow of pages of an extended address verification page.
* A back key is available on top-left of the screen,
Expand Down

0 comments on commit 29e06e7

Please sign in to comment.