Skip to content

Commit ebaae5f

Browse files
agrojean-ledgeryogh333
authored andcommitted
Add choice screen to ask user to confirm tx in generic review example.
1 parent a290ffe commit ebaae5f

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

ledger_device_sdk/examples/nbgl_generic_review.rs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ use include_gif::include_gif;
88
use ledger_device_sdk::io::*;
99
use ledger_device_sdk::nbgl::{
1010
init_comm, CenteredInfo, CenteredInfoStyle, Field, InfoButton, InfoLongPress, InfosList,
11-
NbglGenericReview, NbglGlyph, NbglPageContent, NbglStatus, TagValueConfirm, TagValueList,
11+
NbglGenericReview, NbglGlyph, NbglPageContent, NbglStatus, NbglChoice, TagValueConfirm, TagValueList,
1212
TuneIndex,
1313
};
1414
use ledger_secure_sdk_sys::*;
1515

16+
use core::ops::Not;
17+
1618
#[panic_handler]
1719
fn panic(_: &core::panic::PanicInfo) -> ! {
1820
exit_app(1);
@@ -87,11 +89,31 @@ extern "C" fn sample_main() {
8789
.add_content(NbglPageContent::TagValueConfirm(tag_value_confirm))
8890
.add_content(NbglPageContent::InfosList(infos_list));
8991

90-
let success = review.show("Reject Example");
91-
let status_text = if success {
92-
"Example confirmed"
93-
} else {
94-
"Example rejected"
95-
};
96-
NbglStatus::new().text(status_text).show(success);
92+
const IMPORTANT: NbglGlyph =
93+
NbglGlyph::from_include(include_gif!("icons/Important_Circle_64px.png", NBGL));
94+
95+
let mut show_tx = true;
96+
let mut status_text = "Example rejected";
97+
while show_tx {
98+
let confirm = review.show("Reject Example");
99+
if confirm {
100+
status_text = "Example confirmed";
101+
show_tx = false;
102+
} else {
103+
show_tx = NbglChoice::new()
104+
.glyph(&IMPORTANT)
105+
.show(
106+
"Reject transaction?",
107+
"",
108+
"Yes, reject",
109+
"Go back to transaction",
110+
)
111+
// not() is used to invert the boolean value returned
112+
// by the choice (since we want to return to showing the
113+
// transaction if the user selects "Go back to transaction"
114+
// which returns false).
115+
.not();
116+
}
117+
}
118+
NbglStatus::new().text(status_text).show(status_text == "Example confirmed");
97119
}
6.83 KB
Loading

0 commit comments

Comments
 (0)