Skip to content

Commit

Permalink
Add choice screen to ask user to confirm tx in generic review example.
Browse files Browse the repository at this point in the history
  • Loading branch information
agrojean-ledger committed Aug 22, 2024
1 parent e18d34f commit ae60be2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions ledger_device_sdk/examples/nbgl_generic_review.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ use include_gif::include_gif;
use ledger_device_sdk::io::*;
use ledger_device_sdk::nbgl::{
init_comm, CenteredInfo, CenteredInfoStyle, Field, InfoButton, InfoLongPress, InfosList,
NbglGenericReview, NbglGlyph, NbglPageContent, NbglStatus, TagValueConfirm, TagValueList,
NbglGenericReview, NbglGlyph, NbglPageContent, NbglStatus, NbglChoice, TagValueConfirm, TagValueList,
TuneIndex,
};
use ledger_secure_sdk_sys::*;

use core::ops::Not;

#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
exit_app(1);
Expand Down Expand Up @@ -87,11 +89,31 @@ extern "C" fn sample_main() {
.add_content(NbglPageContent::TagValueConfirm(tag_value_confirm))
.add_content(NbglPageContent::InfosList(infos_list));

let success = review.show("Reject Example");
let status_text = if success {
"Example confirmed"
} else {
"Example rejected"
};
NbglStatus::new().text(status_text).show(success);
const IMPORTANT: NbglGlyph =
NbglGlyph::from_include(include_gif!("icons/Important_Circle_64px.png", NBGL));

let mut show_tx = true;
let mut status_text = "Example rejected";
while show_tx {
let confirm = review.show("Reject Example");
if confirm {
status_text = "Example confirmed";
show_tx = false;
} else {
show_tx = NbglChoice::new()
.glyph(&IMPORTANT)
.show(
"Reject transaction?",
"",
"Yes, reject",
"Go back to transaction",
)
// not() is used to invert the boolean value returned
// by the choice (since we want to return to showing the
// transaction if the user selects "Go back to transaction"
// which returns false).
.not();
}
}
NbglStatus::new().text(status_text).show(status_text == "Example confirmed");
}
Binary file added ledger_device_sdk/icons/Important_Circle_64px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ae60be2

Please sign in to comment.