Skip to content

Commit

Permalink
Add report provider name in warning structure and support streaming r…
Browse files Browse the repository at this point in the history
…eview
  • Loading branch information
nroggeman-ledger committed Jan 14, 2025
1 parent 4b804f0 commit ee526e9
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 23 deletions.
Binary file added lib_nbgl/glyphs/32px/Exclamation_32px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib_nbgl/glyphs/40px/Exclamation_40px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions lib_nbgl/include/nbgl_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ extern "C" {
#define WARNING_ICON C_Warning_32px
#define ROUND_WARN_ICON C_Important_Circle_32px
#define PRIVACY_ICON C_Privacy_32px
#define EXCLAMATION_ICON C_Exclamation_32px
#else // TARGET_STAX
#define SPACE_ICON C_Space_40px
#define BACKSPACE_ICON C_Erase_40px
Expand All @@ -150,6 +151,7 @@ extern "C" {
#define WARNING_ICON C_Warning_40px
#define ROUND_WARN_ICON C_Important_Circle_40px
#define PRIVACY_ICON C_Privacy_40px
#define EXCLAMATION_ICON C_Exclamation_40px
#endif // TARGET_STAX

// For backward compatibility, to be remove later
Expand Down
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 @@ -254,6 +254,7 @@ typedef enum {
typedef struct {
uint32_t predefinedSet; ///< bitfield of pre-defined warnings, to be taken in @ref
///< nbgl_warningType_t set it to 0 if not using pre-defined warnings
const char *reportProvider; ///< name of the security report provider, used in some strings
const nbgl_warningDetails_t
*introDetails; ///< details displayed when top-right button is touched in intro page
///< (before review) if using pre-defined configuration, set to NULL,
Expand Down Expand Up @@ -393,6 +394,13 @@ void nbgl_useCaseReviewStreamingBlindSigningStart(nbgl_operationType_t ope
const char *reviewSubTitle,
nbgl_choiceCallback_t choiceCallback);

void nbgl_useCaseReviewStreamingWithWarningStart(nbgl_operationType_t operationType,
const nbgl_icon_details_t *icon,
const char *reviewTitle,
const char *reviewSubTitle,
const nbgl_warning_t *warning,
nbgl_choiceCallback_t choiceCallback);

void nbgl_useCaseReviewStreamingContinueExt(const nbgl_contentTagValueList_t *tagValueList,
nbgl_choiceCallback_t choiceCallback,
nbgl_callback_t skipCallback);
Expand Down
94 changes: 71 additions & 23 deletions lib_nbgl/src/nbgl_use_case.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
#define keypadContext sharedContext.keypad
#define reviewWithWarnCtx sharedContext.reviewWithWarning

/* max length of the string displaying the description of the Web3 Checks report */
#define W3C_DESCRIPTION_MAX_LEN 128

/**
* @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
Expand Down Expand Up @@ -202,7 +205,7 @@ typedef struct {
**********************/

// char buffers to build some strings
static char appDescription[APP_DESCRIPTION_MAX_LEN];
static char tmpString[W3C_DESCRIPTION_MAX_LEN];

// multi-purposes callbacks
static nbgl_callback_t onQuit;
Expand Down Expand Up @@ -1040,7 +1043,15 @@ static bool genericContextPreparePageContent(const nbgl_content_t *p_content,

// if first or last page of review and blind/risky operation, add the warning top-right button
if (isFirstOrLastPage && (operationType & (BLIND_OPERATION | RISKY_OPERATION))) {
pageContent->topRightIcon = &WARNING_ICON;
// if issue is only Web3Checks issue, use '!' icon
if ((operationType & RISKY_OPERATION)
&& (reviewWithWarnCtx.warning->predefinedSet == (1 << W3C_ISSUE_WARN))) {
pageContent->topRightIcon = &EXCLAMATION_ICON;
}
else {
pageContent->topRightIcon = &WARNING_ICON;
}

pageContent->topRightToken
= (operationType & BLIND_OPERATION) ? BLIND_WARNING_TOKEN : WARNING_BUTTON_TOKEN;
}
Expand Down Expand Up @@ -1937,13 +1948,19 @@ static void displaySecurityReport(uint32_t set)
}
else {
// display a centered if in review
nbgl_contentCenter_t info = {0};
info.icon = &C_Warning_64px;
info.title = "Threat detected";
info.smallTitle = "Known drainer contract";
info.description
= "This transaction was scanned as malicious by Web3 Checks.\n\n"
"View full Blockaid report:\nurl.com/od24xz";
nbgl_contentCenter_t info = {0};
const char *provider = reviewWithWarnCtx.warning->reportProvider
? reviewWithWarnCtx.warning->reportProvider
: "[unknown]";
info.icon = &C_Warning_64px;
info.title = "Threat detected";
info.smallTitle = "Known drainer contract";
info.description = tmpString;
snprintf(tmpString,
W3C_DESCRIPTION_MAX_LEN,
"This transaction was scanned as malicious by Web3 Checks.\n\nView full %s "
"report:\nurl.com/od24xz",
provider);
nbgl_layoutAddContentCenter(reviewWithWarnCtx.modalLayout, &info);
headerDesc.separationLine = false;
}
Expand All @@ -1963,13 +1980,19 @@ static void displaySecurityReport(uint32_t set)
}
else {
// display a centered if in review
nbgl_contentCenter_t info = {0};
info.icon = &C_Warning_64px;
info.title = "Risk detected";
info.smallTitle = "Losing swap";
info.description
= "This transaction was scanned as risky by Web3 Checks.\n\n"
"View full Blockaid report:\\nurl.com/od24xz";
nbgl_contentCenter_t info = {0};
const char *provider = reviewWithWarnCtx.warning->reportProvider
? reviewWithWarnCtx.warning->reportProvider
: "[unknown]";
info.icon = &C_Warning_64px;
info.title = "Risk detected";
info.smallTitle = "Losing swap";
info.description = tmpString;
snprintf(tmpString,
W3C_DESCRIPTION_MAX_LEN,
"This transaction was scanned as risky by Web3 Checks.\n\n"
"View full %s report:\\nurl.com/od24xz",
provider);
nbgl_layoutAddContentCenter(reviewWithWarnCtx.modalLayout, &info);
headerDesc.separationLine = false;
}
Expand Down Expand Up @@ -2295,12 +2318,12 @@ static void useCaseHomeExt(const char *appName,
}
if (tagline == NULL) {
if (strlen(appName) > MAX_APP_NAME_FOR_SDK_TAGLINE) {
snprintf(appDescription,
snprintf(tmpString,
APP_DESCRIPTION_MAX_LEN,
"This app enables signing\ntransactions on its network.");
}
else {
snprintf(appDescription,
snprintf(tmpString,
APP_DESCRIPTION_MAX_LEN,
"%s %s\n%s",
TAGLINE_PART1,
Expand All @@ -2310,16 +2333,15 @@ static void useCaseHomeExt(const char *appName,

// If there is more than 3 lines, it means the appName was split, so we put it on the next
// line
if (nbgl_getTextNbLinesInWidth(SMALL_REGULAR_FONT, appDescription, AVAILABLE_WIDTH, false)
> 3) {
snprintf(appDescription,
if (nbgl_getTextNbLinesInWidth(SMALL_REGULAR_FONT, tmpString, AVAILABLE_WIDTH, false) > 3) {
snprintf(tmpString,
APP_DESCRIPTION_MAX_LEN,
"%s\n%s %s",
TAGLINE_PART1,
appName,
TAGLINE_PART2);
}
info.centeredInfo.text2 = appDescription;
info.centeredInfo.text2 = tmpString;
}
else {
info.centeredInfo.text2 = tagline;
Expand Down Expand Up @@ -3560,6 +3582,32 @@ void nbgl_useCaseReviewStreamingBlindSigningStart(nbgl_operationType_t ope
const char *reviewTitle,
const char *reviewSubTitle,
nbgl_choiceCallback_t choiceCallback)
{
nbgl_useCaseReviewStreamingWithWarningStart(
operationType, icon, reviewTitle, reviewSubTitle, &blindSigningWarning, choiceCallback);
}

/**
* @brief Start drawing the flow of pages of a blind-signing review. The review is preceded by a
* warning page
* @note This should be followed by calls to @ref nbgl_useCaseReviewStreamingContinue and finally
* to
* @ref nbgl_useCaseReviewStreamingFinish.
*
* @param operationType type of operation (Operation, Transaction, Message)
* @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 warning structure to build the initial warning page (cannot be NULL)
* @param choiceCallback callback called when more operation data are needed (param is true) or
* operation is rejected (param is false)
*/
void nbgl_useCaseReviewStreamingWithWarningStart(nbgl_operationType_t operationType,
const nbgl_icon_details_t *icon,
const char *reviewTitle,
const char *reviewSubTitle,
const nbgl_warning_t *warning,
nbgl_choiceCallback_t choiceCallback)
{
memset(&reviewWithWarnCtx, 0, sizeof(reviewWithWarnCtx));

Expand All @@ -3569,7 +3617,7 @@ void nbgl_useCaseReviewStreamingBlindSigningStart(nbgl_operationType_t ope
reviewWithWarnCtx.reviewTitle = reviewTitle;
reviewWithWarnCtx.reviewSubTitle = reviewSubTitle;
reviewWithWarnCtx.choiceCallback = choiceCallback;
reviewWithWarnCtx.warning = &blindSigningWarning;
reviewWithWarnCtx.warning = warning;

displayInitialWarning();
}
Expand Down

0 comments on commit ee526e9

Please sign in to comment.