Skip to content

Commit 1fafc65

Browse files
committed
restore/mnemonic: fix cancel dialog
d9029ff introduced a regression - it added the 'Do you really want to cancel?' dialog to all trinary input dialogs. The purpose was that the user could cancel the password entry when setting a password. The cancel dialog was accidentally introduced also when cancelling the 'restore from mnemonic' workflow, which had its own more complex cancellation logic where the user can choose to edit the previous word instead. This was accidentally buried behind the 'Do you really want to cancel' dialog. This commit fixes it by only asking the user if they want to cancel when entering a password only, not for all trinary inputs.
1 parent 88d48f9 commit 1fafc65

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

src/rust/bitbox02-rust/src/workflow/password.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ use bitbox02::input::SafeInputString;
1717

1818
pub use trinary_input_string::{CanCancel, Error};
1919

20+
async fn prompt_cancel() -> Result<(), confirm::UserAbort> {
21+
confirm::confirm(&confirm::Params {
22+
body: "Do you really\nwant to cancel?",
23+
..Default::default()
24+
})
25+
.await
26+
}
27+
2028
/// If `can_cancel` is `Yes`, the workflow can be cancelled.
2129
/// If it is no, the result is always `Ok(())`.
2230
///
@@ -37,7 +45,16 @@ pub async fn enter(
3745
longtouch: true,
3846
..Default::default()
3947
};
40-
trinary_input_string::enter(&params, can_cancel, "").await
48+
49+
loop {
50+
match trinary_input_string::enter(&params, can_cancel, "").await {
51+
o @ Ok(_) => return o,
52+
Err(Error::Cancelled) => match prompt_cancel().await {
53+
Ok(()) => return Err(Error::Cancelled),
54+
Err(confirm::UserAbort) => {}
55+
},
56+
}
57+
}
4158
}
4259

4360
pub enum EnterTwiceError {
@@ -79,12 +96,7 @@ pub async fn enter_twice() -> Result<SafeInputString, EnterTwiceError> {
7996
.await
8097
{
8198
Ok(()) => break,
82-
Err(confirm::UserAbort) => match confirm::confirm(&confirm::Params {
83-
body: "Do you really\nwant to cancel?",
84-
..Default::default()
85-
})
86-
.await
87-
{
99+
Err(confirm::UserAbort) => match prompt_cancel().await {
88100
Ok(()) => return Err(EnterTwiceError::Cancelled),
89101
Err(confirm::UserAbort) => {}
90102
},

src/rust/bitbox02-rust/src/workflow/trinary_input_string.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
pub use super::cancel::{cancel, set_result, with_cancel, Error};
15+
pub use super::cancel::{cancel, set_result, Error};
1616
pub use bitbox02::ui::TrinaryInputStringParams as Params;
1717

18+
use crate::bb02_async::option;
1819
use bitbox02::input::SafeInputString;
1920
use core::cell::RefCell;
2021

2122
use alloc::boxed::Box;
2223

24+
#[derive(Copy, Clone)]
2325
pub enum CanCancel {
2426
No,
2527
Yes,
@@ -46,5 +48,8 @@ pub async fn enter(
4648
if !preset.is_empty() {
4749
bitbox02::ui::trinary_input_string_set_input(&mut component, preset);
4850
}
49-
with_cancel("", &mut component, &result).await
51+
component.screen_stack_push();
52+
option(&result)
53+
.await
54+
.or(Err(super::cancel::Error::Cancelled))
5055
}

0 commit comments

Comments
 (0)