Skip to content

Commit

Permalink
refactor: refactor the hash signing page using nbgl_useCaseReview. (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat authored Jul 23, 2024
1 parent a526178 commit ad84633
Show file tree
Hide file tree
Showing 18 changed files with 22 additions and 44 deletions.
56 changes: 17 additions & 39 deletions src/ui/nbgl_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,12 @@ static void ui_action_validate_transaction(bool choice) {

// Globals
static char str_values[TAG_VAL_LST_PAIR_NB][DETAIL_VALUE_MAX_LENGTH];
static nbgl_pageInfoLongPress_t info_long_press;
static nbgl_layoutTagValue_t caption_value_pairs[TAG_VAL_LST_PAIR_NB];
static nbgl_layoutTagValueList_t pair_list;

// Static functions declarations
static void review_start(void);
static void review_continue(void);
static void reject_confirmation(void);
static void reject_choice(void);
static void review_choice(bool confirm);
static void warning_choice2(bool confirm);
static void warning_choice1(bool confirm);

Expand All @@ -63,50 +60,31 @@ static void prepare_page(void) {
return;
}
caption_value_pairs[0].value = str_values[0];
}

static void reject_confirmation(void) {
nbgl_useCaseStatus("Hash rejected", false, ui_menu_main);
ui_action_validate_transaction(false);
}

static void reject_choice(void) {
nbgl_useCaseConfirm("Reject hash?",
NULL,
"Yes, reject",
"Go back to hash",
reject_confirmation);
pair_list.pairs = caption_value_pairs;
pair_list.nbPairs = TAG_VAL_LST_PAIR_NB;
}

static void review_choice(bool confirm) {
// Answer, display a status page and go back to main
if (confirm) {
nbgl_useCaseStatus("Hash signed", true, ui_menu_main);
ui_action_validate_transaction(true);
} else {
reject_choice();
nbgl_useCaseStatus("Hash rejected", false, ui_menu_main);
}
validate_transaction(confirm);
}

static void review_start(void) {
nbgl_useCaseReviewStart(&C_icon_stellar_64px,
"Review hash signing",
NULL,
"Reject hash",
review_continue,
reject_choice);
}

static void review_continue(void) {
pair_list.pairs = caption_value_pairs;
pair_list.nbPairs = TAG_VAL_LST_PAIR_NB;

info_long_press.text = "Sign hash?";
info_long_press.icon = &C_icon_stellar_64px;
info_long_press.longPressText = "Hold to sign";
info_long_press.longPressToken = 0;
info_long_press.tuneId = TUNE_TAP_CASUAL;

nbgl_useCaseStaticReview(&pair_list, &info_long_press, "Reject hash", review_choice);
nbgl_operationType_t op_type = TYPE_TRANSACTION;
op_type |= BLIND_OPERATION;
nbgl_useCaseReview(op_type,
&pair_list,
&C_icon_stellar_64px,
"Review hash signing",
NULL,
"Sign hash?",
review_choice);
}

static void warning_choice2(bool confirm) {
Expand All @@ -125,10 +103,10 @@ static void warning_choice1(bool confirm) {
NULL,
"The hash cannot be trusted",
"Your Ledger cannot verify the integrity of this hash. If you sign it, you could be "
"authorizing malicious actions that can drain your wallet.\n\nLearn more: "
"authorizing malicious actions that can drain your wallet.\nLearn more: "
"ledger.com/e8",
"I accept the risk",
"Reject transaction",
"Reject hash",
warning_choice2);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/ui/nbgl_transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ static void warning_choice_tx1(bool confirm) {
NULL,
"The transaction cannot be trusted",
"Unverified contracts may not be displayed in a readable form on your Ledger, so you "
"need to examine them very carefully before sign them.",
"need to examine them very carefully before sign them.\nLearn more: ledger.com/e8",
"I accept the risk",
"Reject transaction",
warning_choice_tx2);
Expand All @@ -398,9 +398,9 @@ static void warning_choice_auth1(bool confirm) {
NULL,
"The Soroban Authorization cannot be trusted",
"Unverified contracts may not be displayed in a readable form on your Ledger, so you "
"need to examine them very carefully before sign them.",
"need to examine them very carefully before sign them.\nLearn more: ledger.com/e8",
"I accept the risk",
"Reject transaction",
"Reject Soroban Auth",
warning_choice_auth2);
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/stax-hash-signing-approve/00000.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 modified tests_zemu/snapshots/stax-hash-signing-approve/00001.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 modified tests_zemu/snapshots/stax-hash-signing-approve/00002.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 modified tests_zemu/snapshots/stax-hash-signing-reject/00000.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 modified tests_zemu/snapshots/stax-hash-signing-reject/00001.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 modified tests_zemu/snapshots/stax-hash-signing-reject/00002.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 modified tests_zemu/snapshots/stax-hash-signing-reject/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests_zemu/tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe("get public key", () => {

describe("hash signing", () => {
// TODO: skip for now, see https://github.com/LedgerHQ/ledger-secure-sdk/issues/737
test.concurrent.each(models.filter(({ dev }) => dev.name !== "flex" && dev.name !== "stax"))("approve ($dev.name)", async ({ dev, startText }) => {
test.concurrent.each(models)("approve ($dev.name)", async ({ dev, startText }) => {
const sim = new Zemu(dev.path);
const testCaseName = `${dev.prefix.toLowerCase()}-hash-signing-approve`;
try {
Expand All @@ -115,7 +115,7 @@ describe("hash signing", () => {
});

// TODO: skip for now, see https://github.com/LedgerHQ/ledger-secure-sdk/issues/737
test.concurrent.each(models.filter(({ dev }) => dev.name !== "flex" && dev.name !== "stax"))("reject ($dev.name)", async ({ dev, startText }) => {
test.concurrent.each(models)("reject ($dev.name)", async ({ dev, startText }) => {
const sim = new Zemu(dev.path);
const testCaseName = `${dev.prefix.toLowerCase()}-hash-signing-reject`;
try {
Expand Down

0 comments on commit ad84633

Please sign in to comment.