Skip to content

Commit

Permalink
feat: update NBGL ui
Browse files Browse the repository at this point in the history
  • Loading branch information
krigga committed Aug 12, 2024
1 parent 580feae commit 53bb567
Show file tree
Hide file tree
Showing 350 changed files with 182 additions and 230 deletions.
28 changes: 4 additions & 24 deletions src/ui/display_address_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,15 @@

static char g_address[G_ADDRESS_LEN];

static void confirm_address_rejection(void) {
// display a status page and go back to main
ui_action_validate_pubkey(false);
nbgl_useCaseStatus("Address verification\ncancelled", false, ui_menu_main);
}

static void confirm_address_approval(void) {
// display a success status page and go back to main
ui_action_validate_pubkey(true);
nbgl_useCaseStatus("ADDRESS\nVERIFIED", true, ui_menu_main);
}

static void review_choice(bool confirm) {
ui_action_validate_pubkey(confirm);
if (confirm) {
confirm_address_approval();
nbgl_useCaseReviewStatus(STATUS_TYPE_ADDRESS_VERIFIED, ui_menu_main);
} else {
confirm_address_rejection();
nbgl_useCaseReviewStatus(STATUS_TYPE_ADDRESS_REJECTED, ui_menu_main);
}
}

static void continue_review(void) {
nbgl_useCaseAddressConfirmation(g_address, review_choice);
}

int ui_display_address(uint8_t flags) {
if (G_context.req_type != CONFIRM_ADDRESS || G_context.state != STATE_NONE) {
G_context.state = STATE_NONE;
Expand All @@ -57,12 +42,7 @@ int ui_display_address(uint8_t flags) {
return -1;
}

nbgl_useCaseReviewStart(&C_ledger_stax_ton_64,
"Verify TON address",
NULL,
"Cancel",
continue_review,
confirm_address_rejection);
nbgl_useCaseAddressReview(g_address, NULL, &C_ledger_stax_ton_64, "Verify TON address", NULL, review_choice);

return 0;
}
Expand Down
46 changes: 13 additions & 33 deletions src/ui/display_proof_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,20 @@
#include "menu.h"
#include "helpers/display_proof.h"

static nbgl_layoutTagValue_t pair;
static nbgl_layoutTagValueList_t pairList;
static nbgl_contentTagValue_t pair;
static nbgl_contentTagValueList_t pairList;
static char g_address[G_ADDRESS_LEN];
static char g_domain[MAX_DOMAIN_LEN + 1];

static void confirm_address_rejection(void) {
// display a status page and go back to main
ui_action_validate_proof(false);
nbgl_useCaseStatus("Address verification\ncancelled", false, ui_menu_main);
}

static void confirm_address_approval(void) {
// display a success status page and go back to main
ui_action_validate_proof(true);
nbgl_useCaseStatus("ADDRESS\nVERIFIED", true, ui_menu_main);
}

static void review_choice(bool confirm) {
ui_action_validate_proof(confirm);
if (confirm) {
confirm_address_approval();
nbgl_useCaseReviewStatus(STATUS_TYPE_ADDRESS_VERIFIED, ui_menu_main);
} else {
confirm_address_rejection();
nbgl_useCaseReviewStatus(STATUS_TYPE_ADDRESS_REJECTED, ui_menu_main);
}
}

static void continue_review(void) {
pair.item = "App domain";
pair.value = g_domain;

pairList.nbPairs = 1;
pairList.nbMaxLinesForValue = 0;
pairList.pairs = &pair;

nbgl_useCaseAddressConfirmationExt(g_address, review_choice, &pairList);
}

int ui_display_proof(uint8_t flags) {
if (G_context.req_type != GET_PROOF || G_context.state != STATE_NONE) {
G_context.state = STATE_NONE;
Expand All @@ -68,12 +46,14 @@ int ui_display_proof(uint8_t flags) {
return -1;
}

nbgl_useCaseReviewStart(&C_ledger_stax_ton_64,
"Verify TON address\nto application",
NULL,
"Cancel",
continue_review,
confirm_address_rejection);
pair.item = "App domain";
pair.value = g_domain;

pairList.nbPairs = 1;
pairList.nbMaxLinesForValue = 0;
pairList.pairs = &pair;

nbgl_useCaseAddressReview(g_address, &pairList, &C_ledger_stax_ton_64, "Verify TON address\nto application", NULL, review_choice);

return 0;
}
Expand Down
47 changes: 12 additions & 35 deletions src/ui/display_sign_data_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,32 @@
#include "menu.h"
#include "hint_buffers_nbgl.h"

static nbgl_layoutTagValue_t pairs[MAX_HINTS];
static nbgl_layoutTagValueList_t pairList;

static nbgl_pageInfoLongPress_t infoLongPress;

static void confirm_sign_data_rejection(void) {
// display a status page and go back to main
ui_action_validate_sign_data(false);
nbgl_useCaseStatus("Data not signed", false, ui_menu_main);
}
static nbgl_contentTagValue_t pairs[MAX_HINTS];
static nbgl_contentTagValueList_t pairList;

// called when long press button on 3rd page is long-touched or when reject footer is touched
static void on_review_choice(bool confirm) {
ui_action_validate_sign_data(confirm);
if (confirm) {
// display a status page and go back to main
ui_action_validate_sign_data(true);
nbgl_useCaseStatus("DATA\nSIGNED", true, ui_menu_main);
nbgl_useCaseReviewStatus(STATUS_TYPE_MESSAGE_SIGNED, ui_menu_main);
} else {
confirm_sign_data_rejection();
nbgl_useCaseReviewStatus(STATUS_TYPE_MESSAGE_REJECTED, ui_menu_main);
}
}

static void start_regular_review(void) {
print_hints(&G_context.sign_data_info.hints, pairs);

pairList.pairs = pairs;
pairList.nbPairs = G_context.sign_data_info.hints.hints_count;
pairList.smallCaseForValue = false;

infoLongPress.icon = &C_ledger_stax_ton_64;
infoLongPress.text = "Sign custom data";
infoLongPress.longPressText = "Hold to sign";

nbgl_useCaseStaticReview(&pairList, &infoLongPress, "Cancel", on_review_choice);
}

int ui_display_sign_data() {
if (G_context.req_type != CONFIRM_SIGN_DATA || G_context.state != STATE_PARSED) {
G_context.state = STATE_NONE;
return io_send_sw(SW_BAD_STATE);
}

// Start review
nbgl_useCaseReviewStart(&C_ledger_stax_ton_64,
"Sign custom data",
NULL,
"Cancel",
start_regular_review,
confirm_sign_data_rejection);
print_hints(&G_context.sign_data_info.hints, pairs);

pairList.pairs = pairs;
pairList.nbPairs = G_context.sign_data_info.hints.hints_count;
pairList.smallCaseForValue = false;

nbgl_useCaseReview(TYPE_MESSAGE, &pairList, &C_ledger_stax_ton_64, "Sign custom data", NULL, "Sign custom data", on_review_choice);

return 0;
}
Expand Down
135 changes: 73 additions & 62 deletions src/ui/display_transaction_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,54 @@ static char g_payload[G_PAYLOAD_LEN];
static char g_address_title[G_ADDRESS_TITLE_LEN];

static char g_transaction_title[64];
static char g_transaction_finish_title[64];

static nbgl_layoutTagValue_t pairs[3 + MAX_HINTS];
static nbgl_layoutTagValueList_t pairList;
static nbgl_contentTagValue_t pairs[3 + MAX_HINTS];
static nbgl_contentTagValueList_t pairList;

static nbgl_pageInfoLongPress_t infoLongPress;

static void confirm_transaction_rejection(void) {
// display a status page and go back to main
ui_action_validate_transaction(false);
nbgl_useCaseStatus("Transaction rejected", false, ui_menu_main);
static void on_transaction_accepted() {
ui_action_validate_transaction(true);
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_SIGNED, ui_menu_main);
}

static void ask_rejection_confirmation(void) {
// display a choice to confirm/cancel rejection
nbgl_useCaseConfirm("Reject transaction?",
NULL,
"Yes, reject",
"Go back to transaction",
confirm_transaction_rejection);
static void on_transaction_rejected() {
ui_action_validate_transaction(false);
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, ui_menu_main);
}

// called when long press button on 3rd page is long-touched or when reject footer is touched
static void on_review_choice(bool confirm) {
if (confirm) {
// display a status page and go back to main
ui_action_validate_transaction(true);
nbgl_useCaseStatus("TRANSACTION\nSIGNED", true, ui_menu_main);
on_transaction_accepted();
} else {
ask_rejection_confirmation();
on_transaction_rejected();
}
}

static void start_regular_review(void) {
static void ui_start_review() {
if (!display_transaction(g_operation,
sizeof(g_operation),
g_amount,
sizeof(g_amount),
g_address,
sizeof(g_address),
g_payload,
sizeof(g_payload),
g_address_title,
sizeof(g_address_title))) {
io_send_sw(SW_BAD_STATE);
return;
}

snprintf(g_transaction_title,
sizeof(g_transaction_title),
"Review transaction\nto %s",
G_context.tx_info.transaction.action);

snprintf(g_transaction_finish_title,
sizeof(g_transaction_finish_title),
"Sign transaction\nto %s",
G_context.tx_info.transaction.action);

int pairIndex = 0;

pairs[pairIndex].item = "Transaction type";
Expand All @@ -89,33 +104,49 @@ static void start_regular_review(void) {
pairList.nbPairs = pairIndex + G_context.tx_info.transaction.hints.hints_count;
pairList.smallCaseForValue = false;

snprintf(g_transaction_title,
sizeof(g_transaction_title),
"Sign transaction\nto %s",
G_context.tx_info.transaction.action);
nbgl_opType_t op = TYPE_TRANSACTION;
if (G_context.tx_info.transaction.is_blind) {
op |= BLIND_OPERATION;
}

infoLongPress.icon = &C_ledger_stax_ton_64;
infoLongPress.text = g_transaction_title;
infoLongPress.longPressText = "Hold to sign";
nbgl_useCaseReview(op, &pairList, &C_ledger_stax_ton_64, g_transaction_title, NULL, g_transaction_finish_title, on_review_choice);
}

nbgl_useCaseStaticReview(&pairList, &infoLongPress, "Reject transaction", on_review_choice);
static void on_blind_choice2(bool proceed) {
if (proceed) {
ui_start_review();
} else {
on_transaction_rejected();
}
}

static void show_blind_warning_if_needed(void) {
if (G_context.tx_info.transaction.is_blind) {
nbgl_useCaseReviewStart(
&C_Important_Circle_64px,
static void on_blind_choice1(bool back_to_safety) {
if (back_to_safety) {
on_transaction_rejected();
} else {
nbgl_useCaseChoice(
NULL,
"Blind Signing",
"This transaction cannot be\nsecurely interpreted by Ledger\nStax. It might put "
"This transaction cannot be\nsecurely interpreted by Ledger. It might put "
"your assets\nat risk.",
"I accept the risk",
"Reject transaction",
start_regular_review,
ask_rejection_confirmation);
} else {
start_regular_review();
on_blind_choice2
);
}
}

static void ui_show_blind_warning() {
nbgl_useCaseChoice(
&C_Warning_64px,
"Security risk detected",
"It may not be safe to sign this transaction. To continue, you'll need to review the risk.",
"Back to safety",
"Review risk",
on_blind_choice1
);
}

// Public function to start the transaction review
// - Check if the app is in the right state for transaction review
// - Format the amount and address strings in g_amount and g_address buffers
Expand All @@ -126,32 +157,12 @@ int ui_display_transaction() {
return io_send_sw(SW_BAD_STATE);
}

if (!display_transaction(g_operation,
sizeof(g_operation),
g_amount,
sizeof(g_amount),
g_address,
sizeof(g_address),
g_payload,
sizeof(g_payload),
g_address_title,
sizeof(g_address_title))) {
return -1;
if (G_context.tx_info.transaction.is_blind) {
ui_show_blind_warning();
} else {
ui_start_review();
}

snprintf(g_transaction_title,
sizeof(g_transaction_title),
"Review transaction\nto %s",
G_context.tx_info.transaction.action);

// Start review
nbgl_useCaseReviewStart(&C_ledger_stax_ton_64,
g_transaction_title,
NULL,
"Reject transaction",
show_blind_warning_if_needed,
ask_rejection_confirmation);

return 0;
}

Expand Down
Loading

0 comments on commit 53bb567

Please sign in to comment.