-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathnbgl_use_case_nanos.c
More file actions
3060 lines (2844 loc) · 115 KB
/
Copy pathnbgl_use_case_nanos.c
File metadata and controls
3060 lines (2844 loc) · 115 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file nbgl_use_case_nanos.c
* @brief Implementation of typical pages (or sets of pages) for Applications, for Nanos (X, SP)
*/
#ifdef NBGL_USE_CASE
#ifndef HAVE_SE_TOUCH
/*********************
* INCLUDES
*********************/
#include <string.h>
#include <stdio.h>
#include "nbgl_debug.h"
#include "nbgl_use_case.h"
#include "glyphs.h"
#include "os_pic.h"
#include "os_helpers.h"
#include "ux.h"
/*********************
* DEFINES
*********************/
#define WITH_HORIZONTAL_CHOICES_LIST
#define WITH_HORIZONTAL_BARS_LIST
/**
* @brief This is to use in @ref nbgl_operationType_t when the operation is concerned by an internal
* warning This is used to indicate a warning with a top-right button in review first & last page
*
*/
#define RISKY_OPERATION (1 << 6)
/**
* @brief This is to use in @ref nbgl_operationType_t when the operation is concerned by an internal
* information. This is used to indicate an info with a top-right button in review first & last page
*
*/
#define NO_THREAT_OPERATION (1 << 7)
/**********************
* TYPEDEFS
**********************/
typedef struct ReviewContext_s {
nbgl_choiceCallback_t onChoice;
const nbgl_contentTagValueList_t *tagValueList;
const nbgl_icon_details_t *icon;
const char *reviewTitle;
const char *reviewSubTitle;
const char *finishTitle;
const char *address; // for address confirmation review
nbgl_callback_t skipCallback; // callback provided by used
uint8_t nbDataSets; // number of sets of data received by StreamingContinue
bool skipDisplay; // if set to true, means that we are displaying the skip page
uint8_t dataDirection; // used to know whether the skip page is reached from back or forward
uint8_t currentTagValueIndex;
uint8_t currentExtensionPage;
uint8_t nbExtensionPages;
const nbgl_contentValueExt_t *extension;
nbgl_step_t extensionStepCtx;
} ReviewContext_t;
typedef struct ChoiceContext_s {
const nbgl_icon_details_t *icon;
const char *message;
const char *subMessage;
const char *confirmText;
const char *cancelText;
nbgl_choiceCallback_t onChoice;
const nbgl_genericDetails_t *details;
} ChoiceContext_t;
typedef struct ConfirmContext_s {
const char *message;
const char *subMessage;
const char *confirmText;
const char *cancelText;
nbgl_callback_t onConfirm;
nbgl_step_t currentStep;
} ConfirmContext_t;
typedef struct ContentContext_s {
const char *title; // For CHOICES_LIST /BARS_LIST
nbgl_genericContents_t genericContents;
const char *rejectText;
nbgl_layoutTouchCallback_t controlsCallback;
nbgl_navCallback_t navCallback;
nbgl_callback_t quitCallback;
} ContentContext_t;
typedef struct HomeContext_s {
const char *appName;
const nbgl_icon_details_t *appIcon;
const char *tagline;
const nbgl_genericContents_t *settingContents;
const nbgl_contentInfoList_t *infosList;
const nbgl_homeAction_t *homeAction;
nbgl_callback_t quitCallback;
} HomeContext_t;
typedef struct ActionContext_s {
nbgl_callback_t actionCallback;
} ActionContext_t;
#ifdef NBGL_KEYPAD
typedef struct KeypadContext_s {
uint8_t pinEntry[8];
uint8_t pinLen;
uint8_t pinMinDigits;
uint8_t pinMaxDigits;
nbgl_layout_t *layoutCtx;
bool hidden;
uint8_t keypadIndex;
nbgl_pinValidCallback_t validatePin;
nbgl_callback_t backCallback;
} KeypadContext_t;
#endif
typedef enum {
NONE_USE_CASE,
SPINNER_USE_CASE,
REVIEW_USE_CASE,
GENERIC_REVIEW_USE_CASE,
ADDRESS_REVIEW_USE_CASE,
STREAMING_START_REVIEW_USE_CASE,
STREAMING_CONTINUE_REVIEW_USE_CASE,
STREAMING_FINISH_REVIEW_USE_CASE,
CHOICE_USE_CASE,
STATUS_USE_CASE,
CONFIRM_USE_CASE,
KEYPAD_USE_CASE,
HOME_USE_CASE,
INFO_USE_CASE,
SETTINGS_USE_CASE,
GENERIC_SETTINGS,
CONTENT_USE_CASE,
ACTION_USE_CASE
} ContextType_t;
typedef struct UseCaseContext_s {
ContextType_t type;
nbgl_operationType_t operationType;
uint8_t nbPages;
int8_t currentPage;
int8_t firstPairPage;
bool forceAction;
nbgl_stepCallback_t
stepCallback; ///< if not NULL, function to be called on "double-key" action
union {
ReviewContext_t review;
ChoiceContext_t choice;
ConfirmContext_t confirm;
HomeContext_t home;
ContentContext_t content;
#ifdef NBGL_KEYPAD
KeypadContext_t keypad;
#endif
ActionContext_t action;
};
} UseCaseContext_t;
typedef struct PageContent_s {
bool isSwitch;
const char *text;
const char *subText;
const nbgl_icon_details_t *icon;
const nbgl_contentValueExt_t *extension;
nbgl_state_t state;
bool isCenteredInfo;
bool isAction;
} PageContent_t;
typedef struct ReviewWithWarningContext_s {
ContextType_t type;
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_warning_t *warning;
nbgl_choiceCallback_t choiceCallback;
uint8_t securityReportLevel; // level 1 is the first level of menus
bool isIntro; // set to true during intro (before actual review)
uint8_t warningPage;
uint8_t nbWarningPages;
uint8_t firstWarningPage;
} ReviewWithWarningContext_t;
typedef enum {
NO_FORCED_TYPE = 0,
FORCE_BUTTON,
FORCE_CENTERED_INFO
} ForcedType_t;
/**********************
* STATIC VARIABLES
**********************/
static UseCaseContext_t context;
static ReviewWithWarningContext_t reviewWithWarnCtx;
// configuration of warning when using @ref nbgl_useCaseReviewBlindSigning()
static const nbgl_warning_t blindSigningWarning = {.predefinedSet = (1 << BLIND_SIGNING_WARN)};
// Operation type for streaming (because the one in 'context' is reset at each streaming API call)
nbgl_operationType_t streamingOpType;
/**********************
* STATIC FUNCTIONS
**********************/
static void displayReviewPage(nbgl_stepPosition_t pos);
static void displayStreamingReviewPage(nbgl_stepPosition_t pos);
static void displayHomePage(nbgl_stepPosition_t pos);
static void displayInfoPage(nbgl_stepPosition_t pos);
static void displaySettingsPage(nbgl_stepPosition_t pos, bool toogle_state);
static void displayChoicePage(nbgl_stepPosition_t pos);
static void displayConfirm(nbgl_stepPosition_t pos);
static void displayContent(nbgl_stepPosition_t pos, bool toogle_state);
static void displaySpinner(const char *text);
static void startUseCaseHome(void);
static void startUseCaseInfo(void);
static void startUseCaseSettings(void);
static void startUseCaseSettingsAtPage(uint8_t initSettingPage);
static void startUseCaseContent(void);
static void statusTickerCallback(void);
static void displayExtensionStep(nbgl_stepPosition_t pos);
static void displayWarningStep(void);
// Simple helper to get the number of elements inside a nbgl_content_t
static uint8_t getContentNbElement(const nbgl_content_t *content)
{
switch (content->type) {
case CENTERED_INFO:
return 1;
case INFO_BUTTON:
return 1;
case TAG_VALUE_LIST:
return content->content.tagValueList.nbPairs;
case TAG_VALUE_CONFIRM:
// last element is for Confirm page
return content->content.tagValueConfirm.tagValueList.nbPairs + 1;
case SWITCHES_LIST:
return content->content.switchesList.nbSwitches;
case INFOS_LIST:
return content->content.infosList.nbInfos;
case CHOICES_LIST:
return content->content.choicesList.nbChoices;
case BARS_LIST:
return content->content.barsList.nbBars;
default:
return 0;
}
}
// Helper to retrieve the content inside a nbgl_genericContents_t using
// either the contentsList or using the contentGetterCallback
static const nbgl_content_t *getContentAtIdx(const nbgl_genericContents_t *genericContents,
int8_t contentIdx,
nbgl_content_t *content)
{
nbgl_pageContent_t pageContent = {0};
if (contentIdx < 0 || contentIdx >= genericContents->nbContents) {
LOG_DEBUG(USE_CASE_LOGGER, "No content available at %d\n", contentIdx);
return NULL;
}
if (genericContents->callbackCallNeeded) {
if (content == NULL) {
LOG_DEBUG(USE_CASE_LOGGER, "Invalid content variable\n");
return NULL;
}
// Retrieve content through callback, but first memset the content.
memset(content, 0, sizeof(nbgl_content_t));
if (context.content.navCallback) {
if (context.content.navCallback(contentIdx, &pageContent) == true) {
// Copy the Page Content to the Content variable
content->type = pageContent.type;
switch (content->type) {
case CENTERED_INFO:
content->content.centeredInfo = pageContent.centeredInfo;
break;
case INFO_BUTTON:
content->content.infoButton = pageContent.infoButton;
break;
case TAG_VALUE_LIST:
content->content.tagValueList = pageContent.tagValueList;
break;
case TAG_VALUE_CONFIRM:
content->content.tagValueConfirm = pageContent.tagValueConfirm;
break;
case SWITCHES_LIST:
content->content.switchesList = pageContent.switchesList;
break;
case INFOS_LIST:
content->content.infosList = pageContent.infosList;
break;
case CHOICES_LIST:
content->content.choicesList = pageContent.choicesList;
break;
case BARS_LIST:
content->content.barsList = pageContent.barsList;
break;
default:
LOG_DEBUG(USE_CASE_LOGGER, "Invalid content type\n");
return NULL;
}
}
else {
LOG_DEBUG(USE_CASE_LOGGER, "Error getting page content\n");
return NULL;
}
}
else {
genericContents->contentGetterCallback(contentIdx, content);
}
return content;
}
else {
// Retrieve content through list
return PIC(&genericContents->contentsList[contentIdx]);
}
}
// Helper to retrieve the content inside a nbgl_genericContents_t using
// either the contentsList or using the contentGetterCallback
static const nbgl_content_t *getContentElemAtIdx(uint8_t elemIdx,
uint8_t *elemContentIdx,
nbgl_content_t *content)
{
const nbgl_genericContents_t *genericContents = NULL;
const nbgl_content_t *p_content = NULL;
uint8_t nbPages = 0;
uint8_t elemNbPages = 0;
switch (context.type) {
case SETTINGS_USE_CASE:
case HOME_USE_CASE:
case GENERIC_SETTINGS:
genericContents = context.home.settingContents;
break;
case CONTENT_USE_CASE:
case GENERIC_REVIEW_USE_CASE:
genericContents = &context.content.genericContents;
break;
default:
return NULL;
}
for (int i = 0; i < genericContents->nbContents; i++) {
p_content = getContentAtIdx(genericContents, i, content);
elemNbPages = getContentNbElement(p_content);
if (nbPages + elemNbPages > elemIdx) {
*elemContentIdx = context.currentPage - nbPages;
break;
}
nbPages += elemNbPages;
}
return p_content;
}
static const char *getChoiceName(uint8_t choiceIndex)
{
uint8_t elemIdx;
uint8_t nbValues;
const nbgl_content_t *p_content = NULL;
nbgl_content_t content = {0};
nbgl_contentRadioChoice_t *contentChoices = NULL;
nbgl_contentBarsList_t *contentBars = NULL;
char **names = NULL;
p_content = getContentElemAtIdx(context.currentPage, &elemIdx, &content);
if (p_content == NULL) {
return NULL;
}
switch (p_content->type) {
case CHOICES_LIST:
contentChoices = (nbgl_contentRadioChoice_t *) PIC(&p_content->content.choicesList);
names = (char **) PIC(contentChoices->names);
nbValues = contentChoices->nbChoices;
break;
case BARS_LIST:
contentBars = ((nbgl_contentBarsList_t *) PIC(&p_content->content.barsList));
names = (char **) PIC(contentBars->barTexts);
nbValues = contentBars->nbBars;
break;
default:
// Not supported as vertical MenuList
return NULL;
}
if (choiceIndex >= nbValues) {
// Last item is always "Back" button
return "Back";
}
return (const char *) PIC(names[choiceIndex]);
}
static void onChoiceSelected(uint8_t choiceIndex)
{
uint8_t elemIdx;
uint8_t token = 255;
const nbgl_content_t *p_content = NULL;
nbgl_content_t content = {0};
nbgl_contentRadioChoice_t *contentChoices = NULL;
nbgl_contentBarsList_t *contentBars = NULL;
p_content = getContentElemAtIdx(context.currentPage, &elemIdx, &content);
if (p_content == NULL) {
return;
}
switch (p_content->type) {
case CHOICES_LIST:
contentChoices = (nbgl_contentRadioChoice_t *) PIC(&p_content->content.choicesList);
if (choiceIndex < contentChoices->nbChoices) {
token = contentChoices->token;
}
break;
case BARS_LIST:
contentBars = ((nbgl_contentBarsList_t *) PIC(&p_content->content.barsList));
if (choiceIndex < contentBars->nbBars) {
token = contentBars->tokens[choiceIndex];
}
break;
default:
// Not supported as vertical MenuList
break;
}
if ((token != 255) && (context.content.controlsCallback != NULL)) {
context.content.controlsCallback(token, 0);
}
else if (context.content.quitCallback != NULL) {
context.content.quitCallback();
}
}
static void getPairData(const nbgl_contentTagValueList_t *tagValueList,
uint8_t index,
const char **item,
const char **value,
const nbgl_contentValueExt_t **extension,
const nbgl_icon_details_t **icon,
bool *isCenteredInfo)
{
const nbgl_contentTagValue_t *pair;
if (tagValueList->pairs != NULL) {
pair = PIC(&tagValueList->pairs[index]);
}
else {
pair = PIC(tagValueList->callback(index));
}
*item = pair->item;
*value = pair->value;
if (pair->aliasValue) {
*extension = pair->extension;
}
else if (pair->centeredInfo) {
*isCenteredInfo = true;
*icon = pair->valueIcon;
}
else {
*extension = NULL;
}
}
static void onReviewAccept(void)
{
if (context.review.onChoice) {
context.review.onChoice(true);
}
}
static void onReviewReject(void)
{
if (context.review.onChoice) {
context.review.onChoice(false);
}
}
static void onChoiceAccept(void)
{
if (context.choice.onChoice) {
context.choice.onChoice(true);
}
}
static void onChoiceReject(void)
{
if (context.choice.onChoice) {
context.choice.onChoice(false);
}
}
static void onConfirmAccept(void)
{
if (context.confirm.currentStep) {
nbgl_stepRelease(context.confirm.currentStep);
}
if (context.confirm.onConfirm) {
context.confirm.onConfirm();
}
}
static void onConfirmReject(void)
{
if (context.confirm.currentStep) {
nbgl_stepRelease(context.confirm.currentStep);
nbgl_screenRedraw();
nbgl_refresh();
}
}
static void onSwitchAction(void)
{
const nbgl_contentSwitch_t *contentSwitch = NULL;
const nbgl_content_t *p_content = NULL;
nbgl_content_t content = {0};
uint8_t elemIdx;
p_content = getContentElemAtIdx(context.currentPage, &elemIdx, &content);
if ((p_content == NULL) || (p_content->type != SWITCHES_LIST)) {
return;
}
contentSwitch
= &((const nbgl_contentSwitch_t *) PIC(p_content->content.switchesList.switches))[elemIdx];
switch (context.type) {
case SETTINGS_USE_CASE:
case HOME_USE_CASE:
case GENERIC_SETTINGS:
displaySettingsPage(FORWARD_DIRECTION, true);
break;
case CONTENT_USE_CASE:
case GENERIC_REVIEW_USE_CASE:
displayContent(FORWARD_DIRECTION, true);
break;
default:
break;
}
if (p_content->contentActionCallback != NULL) {
nbgl_contentActionCallback_t actionCallback = PIC(p_content->contentActionCallback);
actionCallback(contentSwitch->token,
(contentSwitch->initState == ON_STATE) ? OFF_STATE : ON_STATE,
context.currentPage);
}
else if (context.content.controlsCallback != NULL) {
context.content.controlsCallback(contentSwitch->token, 0);
}
}
static void drawStep(nbgl_stepPosition_t pos,
const nbgl_icon_details_t *icon,
const char *txt,
const char *subTxt,
nbgl_stepButtonCallback_t onActionCallback,
bool modal,
ForcedType_t forcedType)
{
uint8_t elemIdx;
nbgl_step_t newStep = NULL;
const nbgl_content_t *p_content = NULL;
nbgl_content_t content = {0};
nbgl_contentRadioChoice_t *contentChoices = NULL;
nbgl_contentBarsList_t *contentBars = NULL;
nbgl_screenTickerConfiguration_t *p_ticker = NULL;
nbgl_layoutMenuList_t list = {0};
nbgl_screenTickerConfiguration_t ticker = {.tickerCallback = PIC(statusTickerCallback),
.tickerIntervale = 0, // not periodic
.tickerValue = STATUS_SCREEN_DURATION};
pos |= GET_POS_OF_STEP(context.currentPage, context.nbPages);
// if we are in streaming+skip case, enable going backward even for first tag/value of the set
// (except the first set) because the set starts with a "skip" page
if ((context.type == STREAMING_CONTINUE_REVIEW_USE_CASE)
&& (context.review.skipCallback != NULL) && (context.review.nbDataSets > 1)) {
pos |= LAST_STEP;
}
if ((context.type == STATUS_USE_CASE) || (context.type == SPINNER_USE_CASE)) {
p_ticker = &ticker;
}
if ((context.type == CONFIRM_USE_CASE) && (context.confirm.currentStep != NULL)) {
nbgl_stepRelease(context.confirm.currentStep);
}
if (txt == NULL) {
p_content = getContentElemAtIdx(context.currentPage, &elemIdx, &content);
if (p_content) {
switch (p_content->type) {
case CHOICES_LIST:
contentChoices
= ((nbgl_contentRadioChoice_t *) PIC(&p_content->content.choicesList));
list.nbChoices = contentChoices->nbChoices + 1; // For Back button
list.selectedChoice = contentChoices->initChoice;
list.callback = getChoiceName;
newStep = nbgl_stepDrawMenuList(onChoiceSelected, p_ticker, &list, modal);
break;
case BARS_LIST:
contentBars = ((nbgl_contentBarsList_t *) PIC(&p_content->content.barsList));
list.nbChoices = contentBars->nbBars + 1; // For Back button
list.selectedChoice = 0;
list.callback = getChoiceName;
newStep = nbgl_stepDrawMenuList(onChoiceSelected, p_ticker, &list, modal);
break;
default:
// Not supported as vertical MenuList
break;
}
}
}
else if ((icon == NULL) && (forcedType != FORCE_CENTERED_INFO)) {
nbgl_contentCenteredInfoStyle_t style;
if (subTxt != NULL) {
style = (forcedType == FORCE_BUTTON) ? BUTTON_INFO : BOLD_TEXT1_INFO;
}
else {
style = REGULAR_INFO;
}
newStep = nbgl_stepDrawText(pos, onActionCallback, p_ticker, txt, subTxt, style, modal);
}
else {
nbgl_layoutCenteredInfo_t info;
info.icon = icon;
info.text1 = txt;
info.text2 = subTxt;
info.onTop = false;
if ((subTxt != NULL) || (context.stepCallback != NULL) || context.forceAction) {
info.style = BOLD_TEXT1_INFO;
}
else {
info.style = REGULAR_INFO;
}
newStep = nbgl_stepDrawCenteredInfo(pos, onActionCallback, p_ticker, &info, modal);
}
if (context.type == CONFIRM_USE_CASE) {
context.confirm.currentStep = newStep;
}
}
static void drawSwitchStep(nbgl_stepPosition_t pos,
const char *title,
const char *description,
bool state,
nbgl_stepButtonCallback_t onActionCallback,
bool modal)
{
nbgl_layoutSwitch_t switchInfo;
pos |= GET_POS_OF_STEP(context.currentPage, context.nbPages);
switchInfo.initState = state;
switchInfo.text = title;
switchInfo.subText = description;
nbgl_stepDrawSwitch(pos, onActionCallback, NULL, &switchInfo, modal);
}
static bool buttonGenericCallback(nbgl_buttonEvent_t event, nbgl_stepPosition_t *pos)
{
uint8_t elemIdx;
uint8_t token = 0;
uint8_t index = 0;
const nbgl_content_t *p_content = NULL;
nbgl_content_t content = {0};
if (event == BUTTON_LEFT_PRESSED) {
if (context.currentPage > 0) {
context.currentPage--;
}
// in streaming+skip case, it is allowed to go backward at the first tag/value, except for
// the first set
else if ((context.type != STREAMING_CONTINUE_REVIEW_USE_CASE)
|| (context.review.skipCallback == NULL) || (context.review.nbDataSets == 1)) {
// Drop the event
return false;
}
*pos = BACKWARD_DIRECTION;
}
else if (event == BUTTON_RIGHT_PRESSED) {
if (context.currentPage < (int) (context.nbPages - 1)) {
context.currentPage++;
}
else {
// Drop the event
return false;
}
*pos = FORWARD_DIRECTION;
}
else {
if (event == BUTTON_BOTH_PRESSED) {
if (context.stepCallback != NULL) {
context.stepCallback();
}
else if ((context.type == CONTENT_USE_CASE) || (context.type == SETTINGS_USE_CASE)
|| (context.type == GENERIC_SETTINGS)
|| (context.type == GENERIC_REVIEW_USE_CASE)) {
p_content = getContentElemAtIdx(context.currentPage, &elemIdx, &content);
if (p_content != NULL) {
switch (p_content->type) {
case CENTERED_INFO:
// No associated callback
return false;
case INFO_BUTTON:
token = p_content->content.infoButton.buttonToken;
break;
case SWITCHES_LIST:
token = p_content->content.switchesList.switches->token;
break;
case BARS_LIST:
token = p_content->content.barsList.tokens[context.currentPage];
break;
case CHOICES_LIST:
token = p_content->content.choicesList.token;
index = context.currentPage;
break;
case TAG_VALUE_LIST:
return false;
case TAG_VALUE_CONFIRM:
if (elemIdx < p_content->content.tagValueConfirm.tagValueList.nbPairs) {
return false;
}
token = p_content->content.tagValueConfirm.confirmationToken;
break;
default:
break;
}
if ((p_content) && (p_content->contentActionCallback != NULL)) {
p_content->contentActionCallback(token, 0, context.currentPage);
}
else if (context.content.controlsCallback != NULL) {
context.content.controlsCallback(token, index);
}
}
}
}
return false;
}
return true;
}
static void reviewCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
{
UNUSED(stepCtx);
nbgl_stepPosition_t pos;
if (!buttonGenericCallback(event, &pos)) {
return;
}
else {
// memorize last direction
context.review.dataDirection = pos;
}
displayReviewPage(pos);
}
// this is the callback used when button action on the "skip" page
static void buttonSkipCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
{
UNUSED(stepCtx);
nbgl_stepPosition_t pos;
if (event == BUTTON_LEFT_PRESSED) {
// only decrement page if we are going backward but coming from forward (back & forth)
if ((context.review.dataDirection == FORWARD_DIRECTION)
&& (context.currentPage > context.firstPairPage)) {
context.currentPage--;
}
pos = BACKWARD_DIRECTION;
}
else if (event == BUTTON_RIGHT_PRESSED) {
// only increment page if we are going forward but coming from backward (back & forth)
if ((context.review.dataDirection == BACKWARD_DIRECTION)
&& (context.currentPage < (int) (context.nbPages - 1))
&& (context.currentPage > context.firstPairPage)) {
context.currentPage++;
}
pos = FORWARD_DIRECTION;
}
else if (event == BUTTON_BOTH_PRESSED) {
// the first tag/value page is at page 0 only in streaming case
if (context.firstPairPage == 0) {
// in streaming, we have to call the provided callback
context.review.skipCallback();
}
else {
// if not in streaming, go directly to the "approve" page
context.currentPage = context.nbPages - 2;
displayReviewPage(FORWARD_DIRECTION);
}
return;
}
else {
return;
}
// the first tag/value page is at page 0 only in streaming case
if (context.firstPairPage == 0) {
displayStreamingReviewPage(pos);
}
else {
displayReviewPage(pos);
}
}
// this is the callback used when buttons in "Action" use case are pressed
static void useCaseActionCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
{
UNUSED(stepCtx);
if (event == BUTTON_BOTH_PRESSED) {
context.action.actionCallback();
}
}
static void streamingReviewCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
{
nbgl_stepPosition_t pos;
UNUSED(stepCtx);
if (!buttonGenericCallback(event, &pos)) {
return;
}
else {
// memorize last direction
context.review.dataDirection = pos;
}
displayStreamingReviewPage(pos);
}
static void settingsCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
{
UNUSED(stepCtx);
nbgl_stepPosition_t pos;
if (!buttonGenericCallback(event, &pos)) {
return;
}
displaySettingsPage(pos, false);
}
static void infoCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
{
UNUSED(stepCtx);
nbgl_stepPosition_t pos;
if (!buttonGenericCallback(event, &pos)) {
return;
}
displayInfoPage(pos);
}
static void homeCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
{
UNUSED(stepCtx);
nbgl_stepPosition_t pos;
if (!buttonGenericCallback(event, &pos)) {
return;
}
displayHomePage(pos);
}
static void genericChoiceCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
{
UNUSED(stepCtx);
nbgl_stepPosition_t pos;
if (!buttonGenericCallback(event, &pos)) {
return;
}
displayChoicePage(pos);
}
static void genericConfirmCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
{
UNUSED(stepCtx);
nbgl_stepPosition_t pos;
if (!buttonGenericCallback(event, &pos)) {
return;
}
displayConfirm(pos);
}
static void statusButtonCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
{
UNUSED(stepCtx);
// any button press should dismiss the status screen
if ((event == BUTTON_BOTH_PRESSED) || (event == BUTTON_LEFT_PRESSED)
|| (event == BUTTON_RIGHT_PRESSED)) {
if (context.stepCallback != NULL) {
context.stepCallback();
}
}
}
static void contentCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
{
UNUSED(stepCtx);
nbgl_stepPosition_t pos;
if (!buttonGenericCallback(event, &pos)) {
return;
}
displayContent(pos, false);
}
// callback used for timeout
static void statusTickerCallback(void)
{
if (context.stepCallback != NULL) {
context.stepCallback();
}
}
// this is the callback used when navigating in extension pages
static void extensionNavigate(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
{
nbgl_stepPosition_t pos;
UNUSED(stepCtx);
if (event == BUTTON_LEFT_PRESSED) {
// only decrement page if we are not at the first page
if (context.review.currentExtensionPage > 0) {
context.review.currentExtensionPage--;
}
pos = BACKWARD_DIRECTION;
}
else if (event == BUTTON_RIGHT_PRESSED) {
// only increment page if not at last page
if (context.review.currentExtensionPage < (context.review.nbExtensionPages - 1)) {
context.review.currentExtensionPage++;
}
pos = FORWARD_DIRECTION;
}
else if (event == BUTTON_BOTH_PRESSED) {
// if at last page, leave modal context
if (context.review.currentExtensionPage == (context.review.nbExtensionPages - 1)) {
nbgl_stepRelease(context.review.extensionStepCtx);
nbgl_screenRedraw();
nbgl_refresh();
}
return;
}
else {
return;
}
displayExtensionStep(pos);
}
// function used to display the extension pages
static void displayExtensionStep(nbgl_stepPosition_t pos)
{
nbgl_layoutCenteredInfo_t info = {0};
const nbgl_contentTagValueList_t *tagValueList = NULL;
const nbgl_contentInfoList_t *infoList = NULL;
const char *text = NULL;
const char *subText = NULL;
if (context.review.extensionStepCtx != NULL) {
nbgl_stepRelease(context.review.extensionStepCtx);
}
if (context.review.currentExtensionPage < (context.review.nbExtensionPages - 1)) {
if (context.review.currentExtensionPage == 0) {
pos |= FIRST_STEP;
}
else {
pos |= NEITHER_FIRST_NOR_LAST_STEP;
}
switch (context.review.extension->aliasType) {
case ENS_ALIAS:
text = context.review.extension->title;
subText = context.review.extension->fullValue;
break;
case INFO_LIST_ALIAS:
infoList = context.review.extension->infolist;
text = PIC(infoList->infoTypes[context.review.currentExtensionPage]);
subText = PIC(infoList->infoContents[context.review.currentExtensionPage]);
break;
case TAG_VALUE_LIST_ALIAS:
tagValueList = context.review.extension->tagValuelist;
text = PIC(tagValueList->pairs[context.review.currentExtensionPage].item);
subText = PIC(tagValueList->pairs[context.review.currentExtensionPage].value);
break;
default:
break;
}
if (text != NULL) {
context.review.extensionStepCtx = nbgl_stepDrawText(
pos, extensionNavigate, NULL, text, subText, BOLD_TEXT1_INFO, true);
}
}
else if (context.review.currentExtensionPage == (context.review.nbExtensionPages - 1)) {