Skip to content

Commit 2de8f9a

Browse files
Support some extra pair with address to fit in 1 page
1 parent 2d34c12 commit 2de8f9a

File tree

1 file changed

+72
-30
lines changed

1 file changed

+72
-30
lines changed

lib_nbgl/src/nbgl_use_case.c

Lines changed: 72 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
/* max number of char for reduced QR Code address */
4949
#define QRCODE_REDUCED_ADDR_LEN 128
5050

51+
/* maximum number of pairs in a page of address confirm */
52+
#define ADDR_VERIF_NB_PAIRS 3
53+
5154
// macros to ease access to shared contexts
5255
#define keypadContext sharedContext.keypad
5356
#define reviewWithWarnCtx sharedContext.reviewWithWarning
@@ -116,8 +119,9 @@ typedef struct DetailsContext_s {
116119
} DetailsContext_t;
117120

118121
typedef struct AddressConfirmationContext_s {
119-
nbgl_layoutTagValue_t tagValuePair;
122+
nbgl_layoutTagValue_t tagValuePairs[ADDR_VERIF_NB_PAIRS];
120123
nbgl_layout_t *modalLayout;
124+
uint8_t nbPairs;
121125
} AddressConfirmationContext_t;
122126

123127
#ifdef NBGL_KEYPAD
@@ -1420,7 +1424,7 @@ static void displayAddressQRCode(void)
14201424
.tapActionText = NULL};
14211425
nbgl_layoutHeader_t headerDesc = {
14221426
.type = HEADER_EMPTY, .separationLine = false, .emptySpace.height = SMALL_CENTERING_HEADER};
1423-
nbgl_layoutQRCode_t qrCode = {.url = addressConfirmationContext.tagValuePair.value,
1427+
nbgl_layoutQRCode_t qrCode = {.url = addressConfirmationContext.tagValuePairs[0].value,
14241428
.text1 = NULL,
14251429
.centered = true,
14261430
.offsetY = 0};
@@ -1429,16 +1433,18 @@ static void displayAddressQRCode(void)
14291433
// add empty header for better look
14301434
nbgl_layoutAddHeader(addressConfirmationContext.modalLayout, &headerDesc);
14311435
// compute nb lines to check whether it shall be shorten (max is 3 lines)
1432-
uint16_t nbLines = nbgl_getTextNbLinesInWidth(
1433-
SMALL_REGULAR_FONT, addressConfirmationContext.tagValuePair.value, AVAILABLE_WIDTH, false);
1436+
uint16_t nbLines = nbgl_getTextNbLinesInWidth(SMALL_REGULAR_FONT,
1437+
addressConfirmationContext.tagValuePairs[0].value,
1438+
AVAILABLE_WIDTH,
1439+
false);
14341440

14351441
if (nbLines <= QRCODE_NB_MAX_LINES) {
1436-
qrCode.text2 = addressConfirmationContext.tagValuePair.value; // in gray
1442+
qrCode.text2 = addressConfirmationContext.tagValuePairs[0].value; // in gray
14371443
}
14381444
else {
14391445
// only keep beginning and end of text, and add ... in the middle
14401446
nbgl_textReduceOnNbLines(SMALL_REGULAR_FONT,
1441-
addressConfirmationContext.tagValuePair.value,
1447+
addressConfirmationContext.tagValuePairs[0].value,
14421448
AVAILABLE_WIDTH,
14431449
QRCODE_NB_MAX_LINES,
14441450
reducedAddress,
@@ -1757,6 +1763,7 @@ static uint8_t getNbTagValuesInPage(uint8_t nbPairs,
17571763
uint8_t startIndex,
17581764
bool isSkippable,
17591765
bool hasConfirmationButton,
1766+
bool hasDetailsButton,
17601767
bool *requireSpecificDisplay)
17611768
{
17621769
uint8_t nbPairsInPage = 0;
@@ -1844,6 +1851,13 @@ static uint8_t getNbTagValuesInPage(uint8_t nbPairs,
18441851
nbPairsInPage--;
18451852
}
18461853
}
1854+
// do the same with just a details button
1855+
else if (hasDetailsButton) {
1856+
maxUsableHeight -= (SMALL_BUTTON_RADIUS * 2);
1857+
if (currentHeight > maxUsableHeight) {
1858+
nbPairsInPage--;
1859+
}
1860+
}
18471861
return nbPairsInPage;
18481862
}
18491863

@@ -1865,15 +1879,21 @@ static uint8_t getNbPagesForContent(const nbgl_content_t *content,
18651879
// if the current page is not the first one (or last), a navigation bar exists
18661880
bool hasNav = !isLast || (pageIdxStart > 0) || (elemIdx > 0);
18671881
if (content->type == TAG_VALUE_LIST) {
1868-
nbElementsInPage = getNbTagValuesInPage(
1869-
nbElements, &content->content.tagValueList, elemIdx, isSkippable, false, &flag);
1882+
nbElementsInPage = getNbTagValuesInPage(nbElements,
1883+
&content->content.tagValueList,
1884+
elemIdx,
1885+
isSkippable,
1886+
false,
1887+
false,
1888+
&flag);
18701889
}
18711890
else if (content->type == TAG_VALUE_CONFIRM) {
18721891
nbElementsInPage = getNbTagValuesInPage(nbElements,
18731892
&content->content.tagValueConfirm.tagValueList,
18741893
elemIdx,
18751894
isSkippable,
1876-
true,
1895+
isLast,
1896+
!isLast,
18771897
&flag);
18781898
}
18791899
else if (content->type == INFOS_LIST) {
@@ -1934,18 +1954,37 @@ static void prepareAddressConfirmationPages(const char *ad
19341954
{
19351955
nbgl_contentTagValueConfirm_t *tagValueConfirm;
19361956

1937-
addressConfirmationContext.tagValuePair.item = "Address";
1938-
addressConfirmationContext.tagValuePair.value = address;
1957+
addressConfirmationContext.tagValuePairs[0].item = "Address";
1958+
addressConfirmationContext.tagValuePairs[0].value = address;
1959+
addressConfirmationContext.nbPairs = 1;
19391960

19401961
// First page
19411962
firstPageContent->type = TAG_VALUE_CONFIRM;
19421963
tagValueConfirm = &firstPageContent->content.tagValueConfirm;
19431964

19441965
#ifdef NBGL_QRCODE
19451966
tagValueConfirm->detailsButtonIcon = &QRCODE_ICON;
1946-
// only use "Show as QR" when it's not the last page
1947-
if (tagValueList != NULL) {
1948-
tagValueConfirm->detailsButtonText = "Show as QR";
1967+
// only use "Show as QR" when address & pairs are not fitting in a single page
1968+
if ((tagValueList != NULL) && (tagValueList->nbPairs < ADDR_VERIF_NB_PAIRS)) {
1969+
nbgl_contentTagValueList_t tmpList;
1970+
bool flag;
1971+
// copy in intermediate structure
1972+
for (uint8_t i = 0; i < tagValueList->nbPairs; i++) {
1973+
memcpy(&addressConfirmationContext.tagValuePairs[1 + i],
1974+
&tagValueList->pairs[i],
1975+
sizeof(nbgl_contentTagValue_t));
1976+
addressConfirmationContext.nbPairs++;
1977+
}
1978+
// check how many can fit in a page
1979+
memcpy(&tmpList, tagValueList, sizeof(nbgl_contentTagValueList_t));
1980+
tmpList.nbPairs = addressConfirmationContext.nbPairs;
1981+
tmpList.pairs = addressConfirmationContext.tagValuePairs;
1982+
addressConfirmationContext.nbPairs = getNbTagValuesInPage(
1983+
addressConfirmationContext.nbPairs, &tmpList, 0, false, true, true, &flag);
1984+
// if they don't all fit, keep only the address
1985+
if (tmpList.nbPairs > addressConfirmationContext.nbPairs) {
1986+
addressConfirmationContext.nbPairs = 1;
1987+
}
19491988
}
19501989
else {
19511990
tagValueConfirm->detailsButtonText = NULL;
@@ -1956,24 +1995,17 @@ static void prepareAddressConfirmationPages(const char *ad
19561995
tagValueConfirm->detailsButtonIcon = NULL;
19571996
#endif // NBGL_QRCODE
19581997
tagValueConfirm->tuneId = TUNE_TAP_CASUAL;
1959-
tagValueConfirm->tagValueList.nbPairs = 1;
1960-
tagValueConfirm->tagValueList.pairs = &addressConfirmationContext.tagValuePair;
1998+
tagValueConfirm->tagValueList.nbPairs = addressConfirmationContext.nbPairs;
1999+
tagValueConfirm->tagValueList.pairs = addressConfirmationContext.tagValuePairs;
19612000
tagValueConfirm->tagValueList.smallCaseForValue = false;
19622001
tagValueConfirm->tagValueList.nbMaxLinesForValue = 0;
19632002
tagValueConfirm->tagValueList.wrapping = false;
19642003
// if it's an extended address verif, it takes 2 pages, so display a "Tap to continue", and
19652004
// no confirmation button
1966-
if (tagValueList != NULL) {
1967-
tagValueConfirm->confirmationText = NULL;
1968-
}
1969-
else {
1970-
// otherwise no tap to continue but a confirmation button
1971-
tagValueConfirm->confirmationText = "Confirm";
1972-
tagValueConfirm->confirmationToken = CONFIRM_TOKEN;
1973-
}
1974-
1975-
// Second page if any:
1976-
if (tagValueList != NULL) {
2005+
if ((tagValueList != NULL)
2006+
&& (tagValueList->nbPairs > (addressConfirmationContext.nbPairs - 1))) {
2007+
tagValueConfirm->detailsButtonText = "Show as QR";
2008+
tagValueConfirm->confirmationText = NULL;
19772009
// the second page is dedicated to the extended tag/value pairs
19782010
secondPageContent->type = TAG_VALUE_CONFIRM;
19792011
tagValueConfirm = &secondPageContent->content.tagValueConfirm;
@@ -1983,6 +2015,15 @@ static void prepareAddressConfirmationPages(const char *ad
19832015
tagValueConfirm->detailsButtonIcon = NULL;
19842016
tagValueConfirm->tuneId = TUNE_TAP_CASUAL;
19852017
memcpy(&tagValueConfirm->tagValueList, tagValueList, sizeof(nbgl_contentTagValueList_t));
2018+
tagValueConfirm->tagValueList.nbPairs
2019+
= tagValueList->nbPairs - (addressConfirmationContext.nbPairs - 1);
2020+
tagValueConfirm->tagValueList.pairs
2021+
= &tagValueList->pairs[addressConfirmationContext.nbPairs - 1];
2022+
}
2023+
else {
2024+
// otherwise no tap to continue but a confirmation button
2025+
tagValueConfirm->confirmationText = "Confirm";
2026+
tagValueConfirm->confirmationToken = CONFIRM_TOKEN;
19862027
}
19872028
}
19882029

@@ -2710,7 +2751,7 @@ uint8_t nbgl_useCaseGetNbTagValuesInPage(uint8_t nbPai
27102751
bool *requireSpecificDisplay)
27112752
{
27122753
return getNbTagValuesInPage(
2713-
nbPairs, tagValueList, startIndex, false, false, requireSpecificDisplay);
2754+
nbPairs, tagValueList, startIndex, false, false, false, requireSpecificDisplay);
27142755
}
27152756

27162757
/**
@@ -2733,7 +2774,7 @@ uint8_t nbgl_useCaseGetNbTagValuesInPageExt(uint8_t nb
27332774
bool *requireSpecificDisplay)
27342775
{
27352776
return getNbTagValuesInPage(
2736-
nbPairs, tagValueList, startIndex, isSkippable, false, requireSpecificDisplay);
2777+
nbPairs, tagValueList, startIndex, isSkippable, false, false, requireSpecificDisplay);
27372778
}
27382779

27392780
/**
@@ -4072,7 +4113,6 @@ void nbgl_useCaseAddressReview(const char *address,
40724113
bundleNavContext.review.operationType = TYPE_OPERATION;
40734114

40744115
genericContext.genericContents.contentsList = localContentsList;
4075-
genericContext.genericContents.nbContents = (additionalTagValueList == NULL) ? 2 : 3;
40764116
memset(localContentsList, 0, 3 * sizeof(nbgl_content_t));
40774117

40784118
// First a centered info
@@ -4086,6 +4126,8 @@ void nbgl_useCaseAddressReview(const char *address,
40864126
address, additionalTagValueList, &localContentsList[1], &localContentsList[2]);
40874127

40884128
// fill navigation structure, common to all pages
4129+
genericContext.genericContents.nbContents
4130+
= (localContentsList[2].type == TAG_VALUE_CONFIRM) ? 3 : 2;
40894131
uint8_t nbPages = getNbPagesForGenericContents(&genericContext.genericContents, 0, false);
40904132

40914133
prepareNavInfo(true, nbPages, "Cancel");

0 commit comments

Comments
 (0)