Skip to content

Commit f112621

Browse files
committed
Use single loop
1 parent 99b1f53 commit f112621

File tree

2 files changed

+27
-41
lines changed

2 files changed

+27
-41
lines changed

src/handlers/sign_tx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl TxContext {
5858
path: Default::default(),
5959
review_finished: false,
6060
#[cfg(any(target_os = "stax", target_os = "flex"))]
61-
home: NbglHomeAndSettings::new(),
61+
home: Default::default(),
6262
}
6363
}
6464
// Get review status

src/main.rs

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use handlers::{
3838
get_version::handler_get_version,
3939
sign_tx::{handler_sign_tx, TxContext},
4040
};
41-
use ledger_device_sdk::io::{ApduHeader, Comm, Reply, StatusWords};
41+
use ledger_device_sdk::io::{ApduHeader, Comm, Event, Reply, StatusWords};
4242
#[cfg(feature = "pending_review_screen")]
4343
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
4444
use ledger_device_sdk::ui::gadgets::display_pending_review;
@@ -167,49 +167,35 @@ extern "C" fn sample_main() {
167167
init_comm(&mut comm);
168168
tx_ctx.home = ui_menu_main(&mut comm);
169169
tx_ctx.home.show_and_return();
170-
171-
loop {
172-
let ins: Instruction = comm.next_command();
173-
let status = match handle_apdu(&mut comm, &ins, &mut tx_ctx) {
174-
Ok(()) => {
175-
comm.reply_ok();
176-
AppSW::Ok
177-
}
178-
Err(sw) => {
179-
comm.reply(sw);
180-
sw
181-
}
182-
};
183-
show_status_and_home_if_needed(&ins, &mut tx_ctx, &status);
184-
}
185170
}
186171

187172
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
188-
{
189-
use ledger_device_sdk::io::Event;
190-
191-
// Developer mode / pending review popup
192-
// must be cleared with user interaction
193-
#[cfg(feature = "pending_review_screen")]
194-
display_pending_review(&mut comm);
195-
196-
loop {
197-
// Wait for either a specific button push to exit the app
198-
// or an APDU command
199-
if let Event::Command(ins) = ui_menu_main(&mut comm) {
200-
let result = handle_apdu(&mut comm, &ins, &mut tx_ctx);
201-
let _status: AppSW = match result {
202-
Ok(()) => {
203-
comm.reply_ok();
204-
AppSW::Ok
205-
}
206-
Err(sw) => {
207-
comm.reply(sw);
208-
sw
209-
}
210-
};
173+
#[cfg(feature = "pending_review_screen")]
174+
display_pending_review(&mut comm);
175+
176+
loop {
177+
#[cfg(any(target_os = "stax", target_os = "flex"))]
178+
let ins: Instruction = comm.next_command();
179+
180+
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
181+
let ins = if let Event::Command(ins) = ui_menu_main(&mut comm) {
182+
ins
183+
} else {
184+
continue;
185+
};
186+
187+
let status = match handle_apdu(&mut comm, &ins, &mut tx_ctx) {
188+
Ok(()) => {
189+
comm.reply_ok();
190+
AppSW::Ok
211191
}
212-
}
192+
Err(sw) => {
193+
comm.reply(sw);
194+
sw
195+
}
196+
};
197+
#[cfg(any(target_os = "stax", target_os = "flex"))]
198+
show_status_and_home_if_needed(&ins, &mut tx_ctx, &status);
213199
}
214200
}
215201

0 commit comments

Comments
 (0)