Skip to content

Commit 299bfb0

Browse files
Add streaming Blind Signing Review Use Case
1 parent 78658aa commit 299bfb0

File tree

1 file changed

+104
-36
lines changed

1 file changed

+104
-36
lines changed

lib_nbgl/src/nbgl_use_case.c

Lines changed: 104 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ typedef struct KeypadContext_s {
107107
#endif
108108

109109
typedef struct BlindSigningContext_s {
110+
bool isStreaming;
110111
nbgl_operationType_t operationType;
111112
const nbgl_contentTagValueList_t *tagValueList;
112113
const nbgl_icon_details_t *icon;
@@ -281,6 +282,12 @@ static void useCaseReview(nbgl_operationType_t operationType,
281282
nbgl_choiceCallback_t choiceCallback,
282283
bool isLight,
283284
bool playNotifSound);
285+
static void useCaseReviewStreamingStart(nbgl_operationType_t operationType,
286+
const nbgl_icon_details_t *icon,
287+
const char *reviewTitle,
288+
const char *reviewSubTitle,
289+
nbgl_choiceCallback_t choiceCallback,
290+
bool playNotifSound);
284291

285292
static void reset_callbacks(void)
286293
{
@@ -584,16 +591,26 @@ static void pageCallback(int token, uint8_t index)
584591
blindSigningContext.choiceCallback(false);
585592
}
586593
else { // bottom button to continue to review
587-
useCaseReview(blindSigningContext.operationType,
588-
blindSigningContext.tagValueList,
589-
blindSigningContext.icon,
590-
blindSigningContext.reviewTitle,
591-
blindSigningContext.reviewSubTitle,
592-
blindSigningContext.finishTitle,
593-
blindSigningContext.tipBox,
594-
blindSigningContext.choiceCallback,
595-
false,
596-
true);
594+
if (blindSigningContext.isStreaming) {
595+
useCaseReviewStreamingStart(blindSigningContext.operationType,
596+
blindSigningContext.icon,
597+
blindSigningContext.reviewTitle,
598+
blindSigningContext.reviewSubTitle,
599+
blindSigningContext.choiceCallback,
600+
false);
601+
}
602+
else {
603+
useCaseReview(blindSigningContext.operationType,
604+
blindSigningContext.tagValueList,
605+
blindSigningContext.icon,
606+
blindSigningContext.reviewTitle,
607+
blindSigningContext.reviewSubTitle,
608+
blindSigningContext.finishTitle,
609+
blindSigningContext.tipBox,
610+
blindSigningContext.choiceCallback,
611+
false,
612+
false);
613+
}
597614
}
598615
}
599616
else if (token == TIP_BOX_TOKEN) {
@@ -1811,6 +1828,52 @@ static void useCaseReview(nbgl_operationType_t operationType,
18111828
displayGenericContextPage(0, true);
18121829
}
18131830

1831+
// function to factorize code for all streaming reviews
1832+
static void useCaseReviewStreamingStart(nbgl_operationType_t operationType,
1833+
const nbgl_icon_details_t *icon,
1834+
const char *reviewTitle,
1835+
const char *reviewSubTitle,
1836+
nbgl_choiceCallback_t choiceCallback,
1837+
bool playNotifSound)
1838+
{
1839+
reset_callbacks();
1840+
memset(&genericContext, 0, sizeof(genericContext));
1841+
1842+
bundleNavContext.reviewStreaming.operationType = operationType;
1843+
bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
1844+
bundleNavContext.reviewStreaming.icon = icon;
1845+
1846+
// memorize context
1847+
onChoice = bundleNavReviewStreamingChoice;
1848+
navType = STREAMING_NAV;
1849+
pageTitle = NULL;
1850+
1851+
genericContext.genericContents.contentsList = localContentsList;
1852+
genericContext.genericContents.nbContents = 1;
1853+
memset(localContentsList, 0, 1 * sizeof(nbgl_content_t));
1854+
1855+
// First a centered info
1856+
STARTING_CONTENT.type = EXTENDED_CENTER;
1857+
prepareReviewFirstPage(
1858+
&STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
1859+
1860+
// compute number of pages & fill navigation structure
1861+
bundleNavContext.reviewStreaming.stepPageNb
1862+
= nbgl_useCaseGetNbPagesForGenericContents(&genericContext.genericContents, 0);
1863+
prepareNavInfo(true, NBGL_NO_PROGRESS_INDICATOR, getRejectReviewText(operationType));
1864+
// no back button on first page
1865+
navInfo.navWithButtons.backButton = false;
1866+
1867+
// Play notification sound if required
1868+
if (playNotifSound) {
1869+
#ifdef HAVE_PIEZO_SOUND
1870+
io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
1871+
#endif // HAVE_PIEZO_SOUND
1872+
}
1873+
1874+
displayGenericContextPage(0, true);
1875+
}
1876+
18141877
/**********************
18151878
* GLOBAL FUNCTIONS
18161879
**********************/
@@ -3000,6 +3063,7 @@ void nbgl_useCaseReviewBlindSigning(nbgl_operationType_t operationT
30003063
{
30013064
memset(&blindSigningContext, 0, sizeof(blindSigningContext));
30023065

3066+
blindSigningContext.isStreaming = false;
30033067
blindSigningContext.operationType = operationType | BLIND_OPERATION;
30043068
blindSigningContext.tagValueList = tagValueList;
30053069
blindSigningContext.icon = icon;
@@ -3106,40 +3170,44 @@ void nbgl_useCaseReviewStreamingStart(nbgl_operationType_t operationType,
31063170
const char *reviewSubTitle,
31073171
nbgl_choiceCallback_t choiceCallback)
31083172
{
3109-
reset_callbacks();
3110-
memset(&genericContext, 0, sizeof(genericContext));
3111-
3112-
bundleNavContext.reviewStreaming.operationType = operationType;
3113-
bundleNavContext.reviewStreaming.choiceCallback = choiceCallback;
3114-
bundleNavContext.reviewStreaming.icon = icon;
3115-
3116-
// memorize context
3117-
onChoice = bundleNavReviewStreamingChoice;
3118-
navType = STREAMING_NAV;
3119-
pageTitle = NULL;
3120-
3121-
genericContext.genericContents.contentsList = localContentsList;
3122-
genericContext.genericContents.nbContents = 1;
3123-
memset(localContentsList, 0, 1 * sizeof(nbgl_content_t));
3173+
useCaseReviewStreamingStart(
3174+
operationType, icon, reviewTitle, reviewSubTitle, choiceCallback, true);
3175+
}
31243176

3125-
// First a centered info
3126-
STARTING_CONTENT.type = EXTENDED_CENTER;
3127-
prepareReviewFirstPage(
3128-
&STARTING_CONTENT.content.extendedCenter.contentCenter, icon, reviewTitle, reviewSubTitle);
3177+
/**
3178+
* @brief Start drawing the flow of pages of a blind-signing review. The review is preceded by a
3179+
* warning page
3180+
* @note This should be followed by calls to nbgl_useCaseReviewStreamingContinue and finally to
3181+
* nbgl_useCaseReviewStreamingFinish.
3182+
*
3183+
* @param operationType type of operation (Operation, Transaction, Message)
3184+
* @param icon icon used on first and last review page
3185+
* @param reviewTitle string used in the first review page
3186+
* @param reviewSubTitle string to set under reviewTitle (can be NULL)
3187+
* @param choiceCallback callback called when more operation data are needed (param is true) or
3188+
* operation is rejected (param is false)
3189+
*/
3190+
void nbgl_useCaseReviewStreamingBlindSigningStart(nbgl_operationType_t operationType,
3191+
const nbgl_icon_details_t *icon,
3192+
const char *reviewTitle,
3193+
const char *reviewSubTitle,
3194+
nbgl_choiceCallback_t choiceCallback)
3195+
{
3196+
memset(&blindSigningContext, 0, sizeof(blindSigningContext));
31293197

3130-
// compute number of pages & fill navigation structure
3131-
bundleNavContext.reviewStreaming.stepPageNb
3132-
= nbgl_useCaseGetNbPagesForGenericContents(&genericContext.genericContents, 0);
3133-
prepareNavInfo(true, NBGL_NO_PROGRESS_INDICATOR, getRejectReviewText(operationType));
3134-
// no back button on first page
3135-
navInfo.navWithButtons.backButton = false;
3198+
blindSigningContext.isStreaming = true;
3199+
blindSigningContext.operationType = operationType | BLIND_OPERATION;
3200+
blindSigningContext.icon = icon;
3201+
blindSigningContext.reviewTitle = reviewTitle;
3202+
blindSigningContext.reviewSubTitle = reviewSubTitle;
3203+
blindSigningContext.choiceCallback = choiceCallback;
31363204

31373205
#ifdef HAVE_PIEZO_SOUND
31383206
// Play notification sound
31393207
io_seproxyhal_play_tune(TUNE_LOOK_AT_ME);
31403208
#endif // HAVE_PIEZO_SOUND
31413209

3142-
displayGenericContextPage(0, true);
3210+
blindSigningWarning();
31433211
}
31443212

31453213
/**

0 commit comments

Comments
 (0)