Skip to content

Commit

Permalink
Remove status screens at the end of reviews, add new structures
Browse files Browse the repository at this point in the history
so that developers may add such screens themselves in the apps.
  • Loading branch information
agrojean-ledger committed Jul 31, 2024
1 parent bd050f4 commit e9eb6d2
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 81 deletions.
17 changes: 15 additions & 2 deletions ledger_device_sdk/examples/nbgl_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ use ledger_device_sdk as _;

use include_gif::include_gif;
use ledger_device_sdk::io::*;
use ledger_device_sdk::nbgl::{init_comm, NbglAddressReview, NbglGlyph};
use ledger_device_sdk::nbgl::{
init_comm, NbglAddressReview, NbglGlyph, NbglReviewStatus, StatusType,
};
use ledger_secure_sdk_sys::*;

#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
exit_app(1);
}

#[no_mangle]
extern "C" fn sample_main() {
unsafe {
Expand All @@ -26,5 +33,11 @@ extern "C" fn sample_main() {
const FERRIS: NbglGlyph =
NbglGlyph::from_include(include_gif!("examples/crab_64x64.gif", NBGL));
// Display the address confirmation screen.
NbglAddressReview::new().glyph(&FERRIS).show(addr_hex);
let success = NbglAddressReview::new()
.glyph(&FERRIS)
.verify_str("Verify Address")
.show(addr_hex);
NbglReviewStatus::new()
.status_type(StatusType::Address)
.show(success);
}
23 changes: 15 additions & 8 deletions ledger_device_sdk/examples/nbgl_choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ledger_device_sdk as _;

use include_gif::include_gif;
use ledger_device_sdk::io::*;
use ledger_device_sdk::nbgl::{init_comm, NbglChoice, NbglGlyph};
use ledger_device_sdk::nbgl::{init_comm, NbglChoice, NbglGlyph, NbglStatus};
use ledger_secure_sdk_sys::*;

#[panic_handler]
Expand All @@ -29,23 +29,30 @@ extern "C" fn sample_main() {
const WARNING: NbglGlyph =
NbglGlyph::from_include(include_gif!("icons/Warning_64px.gif", NBGL));

let back_to_safety = NbglChoice::new().glyph(&WARNING)
.status_text(Some("Transaction rejected"),None)
.show(
let back_to_safety = NbglChoice::new().glyph(&WARNING).show(
"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",
);

if !back_to_safety {
NbglChoice::new()
.status_text(Some("Transaction confirmed"), Some("Transaction rejected"))
.show(
if back_to_safety {
NbglStatus::new().text("Transaction rejected").show(false);
} else {
let confirmed = NbglChoice::new()
.show(
"The transaction cannot be trusted",
"Your Ledger cannot decode this transaction. If you sign it, you could be authorizing malicious actions that can drain your wallet.\n\nLearn more: ledger.com/e8",
"I accept the risk",
"Reject transaction"
);

NbglStatus::new()
.text(if confirmed {
"Transaction confirmed"
} else {
"Transaction rejected"
})
.show(confirmed);
}
}
11 changes: 9 additions & 2 deletions ledger_device_sdk/examples/nbgl_generic_review.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ 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, TagValueConfirm, TagValueList, TuneIndex,
NbglGenericReview, NbglGlyph, NbglPageContent, NbglStatus, TagValueConfirm, TagValueList,
TuneIndex,
};
use ledger_secure_sdk_sys::*;

Expand Down Expand Up @@ -86,5 +87,11 @@ extern "C" fn sample_main() {
.add_content(NbglPageContent::TagValueConfirm(tag_value_confirm))
.add_content(NbglPageContent::InfosList(infos_list));

review.show("Reject Example", "Example Confirmed", "Example Rejected");
let success = review.show("Reject Example");
let status_text = if success {
"Example confirmed"
} else {
"Example rejected"
};
NbglStatus::new().text(status_text).show(success);
}
5 changes: 5 additions & 0 deletions ledger_device_sdk/examples/nbgl_home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ use ledger_device_sdk::nvm::*;
use ledger_device_sdk::NVMData;
use ledger_secure_sdk_sys::*;

#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
exit_app(1);
}

pub enum Instruction {
GetVersion,
GetAppName,
Expand Down
12 changes: 7 additions & 5 deletions ledger_device_sdk/examples/nbgl_review.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use ledger_device_sdk as _;

use include_gif::include_gif;
use ledger_device_sdk::io::*;
use ledger_device_sdk::nbgl::{init_comm, Field, NbglGlyph, NbglReview};
use ledger_device_sdk::nbgl::{
init_comm, Field, NbglGlyph, NbglReview, NbglReviewStatus, StatusType,
};
use ledger_secure_sdk_sys::*;

#[panic_handler]
Expand Down Expand Up @@ -45,14 +47,14 @@ extern "C" fn sample_main() {
NbglGlyph::from_include(include_gif!("examples/crab_64x64.gif", NBGL));
// Create NBGL review. Maximum number of fields and string buffer length can be customised
// with constant generic parameters of NbglReview. Default values are 32 and 1024 respectively.
let mut review: NbglReview = NbglReview::new()
let success = NbglReview::new()
.titles(
"Please review transaction",
"To send CRAB",
"Sign transaction\nto send CRAB",
)
.glyph(&FERRIS)
.blind();

review.show(&my_fields);
.blind()
.show(&my_fields);
NbglReviewStatus::new().show(success);
}
64 changes: 64 additions & 0 deletions ledger_device_sdk/examples/nbgl_spinner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#![no_std]
#![no_main]

// Force boot section to be embedded in
use ledger_device_sdk as _;

use include_gif::include_gif;
use ledger_device_sdk::io::*;
use ledger_device_sdk::nbgl::{
init_comm, Field, NbglGlyph, NbglReview, NbglReviewStatus, NbglSpinner, StatusType,
};
use ledger_device_sdk::testing::debug_print;
use ledger_secure_sdk_sys::*;

#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
exit_app(1);
}

// static spin_end: bool = false;

#[no_mangle]
extern "C" fn sample_main() {
unsafe {
nbgl_refreshReset();
}

let mut comm = Comm::new();
// Initialize reference to Comm instance for NBGL
// API calls.
init_comm(&mut comm);

let my_field = [Field {
name: "Amount",
value: "111 CRAB",
}];

// Load glyph from 64x64 4bpp gif file with include_gif macro. Creates an NBGL compatible glyph.
const FERRIS: NbglGlyph =
NbglGlyph::from_include(include_gif!("examples/crab_64x64.gif", NBGL));
// Create NBGL review. Maximum number of fields and string buffer length can be customised
// with constant generic parameters of NbglReview. Default values are 32 and 1024 respectively.
let success = NbglReview::new()
.titles(
"Please review transaction",
"To send CRAB",
"Sign transaction\nto send CRAB",
)
.glyph(&FERRIS)
.show(&my_field);

NbglSpinner::new().text("Please wait...").show();

// Simulate an idle state of the app where it just
// waits for some event to happen (such as APDU reception), going through
// the event loop to process TickerEvents so that the spinner can be animated
// every 800ms.
let mut loop_count = 50;
while loop_count > 0 {
comm.next_event::<ApduHeader>();
loop_count -= 1;
}
NbglReviewStatus::new().show(success);
}
17 changes: 13 additions & 4 deletions ledger_device_sdk/examples/nbgl_streaming_review.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use ledger_device_sdk as _;

use include_gif::include_gif;
use ledger_device_sdk::io::*;
use ledger_device_sdk::nbgl::{init_comm, Field, NbglGlyph, NbglStreamingReview, TransactionType};
use ledger_device_sdk::nbgl::{
init_comm, Field, NbglGlyph, NbglReviewStatus, NbglStreamingReview, StatusType, TransactionType,
};
use ledger_secure_sdk_sys::*;

#[panic_handler]
Expand All @@ -33,7 +35,10 @@ extern "C" fn sample_main() {
.glyph(&FERRIS)
.tx_type(TransactionType::Message);

review.start("Example Title", "Example Subtitle");
if !review.start("Streaming example", "Example Subtitle") {
NbglReviewStatus::new().show(false);
return;
}

let fields = [
Field {
Expand All @@ -59,8 +64,12 @@ extern "C" fn sample_main() {
];

for i in 0..fields.len() {
review.continue_review(&fields[i..i + 1]);
if !review.continue_review(&fields[i..i + 1]) {
NbglReviewStatus::new().show(false);
return;
}
}

review.finish("Sign to send token\n");
let success = review.finish("Sign to send token\n");
NbglReviewStatus::new().show(success);
}
Loading

0 comments on commit e9eb6d2

Please sign in to comment.