Skip to content

Commit

Permalink
bip85: show checkmark instead of "Continue" at the end of the mnemonic
Browse files Browse the repository at this point in the history
So far it has been "Continue" as showing the mnemonic was always in
the middle of some other workflow.

With BIP-85, showing the BIP-39 mnemonic is at the end of a workflow,
so a checkmark is more appropriate.
  • Loading branch information
benma committed May 18, 2023
1 parent 3e967f8 commit ada8c8c
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/rust/bitbox02-rust/src/hww/api/bip85.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub async fn process(pb::Bip85Request {}: &pb::Bip85Request) -> Result<Response,

let mnemonic = keystore::bip85_bip39(num_words, index)?;
let words: Vec<&str> = mnemonic.split(' ').collect();
mnemonic::show_mnemonic(&words).await?;
mnemonic::show_mnemonic(&words, false).await?;

status::status("Finished", true).await;

Expand Down
6 changes: 4 additions & 2 deletions src/rust/bitbox02-rust/src/hww/api/show_mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub async fn process() -> Result<Response, Error> {
let words: Vec<&str> = mnemonic_sentence.split(' ').collect();

// Part 1) Scroll through words
mnemonic::show_mnemonic(&words).await?;
mnemonic::show_mnemonic(&words, true).await?;

confirm::confirm(&confirm::Params {
title: "",
Expand All @@ -109,7 +109,9 @@ pub async fn process() -> Result<Response, Error> {
loop {
match mnemonic::confirm_word(&choices, &title).await? {
selected_idx if selected_idx == correct_idx => break,
selected_idx if selected_idx == back_idx => mnemonic::show_mnemonic(&words).await?,
selected_idx if selected_idx == back_idx => {
mnemonic::show_mnemonic(&words, true).await?
}
_ => status::status("Incorrect word\nTry again", false).await,
}
}
Expand Down
1 change: 1 addition & 0 deletions src/rust/bitbox02-rust/src/workflow/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub async fn pick(words: &[&str], title: Option<&str>) -> Result<u8, CancelError
*result.borrow_mut() = Some(Ok(choice_idx));
})),
finish_on_last_cb: None,
continue_on_finish: false,
cancel_cb: Some(Box::new(|| {
*result.borrow_mut() = Some(Err(CancelError::Cancelled));
})),
Expand Down
7 changes: 6 additions & 1 deletion src/rust/bitbox02-rust/src/workflow/mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ fn as_str_vec(v: &[zeroize::Zeroizing<String>]) -> Vec<&str> {
}

/// Displays all mnemonic words in a scroll-through screen.
pub async fn show_mnemonic(words: &[&str]) -> Result<(), CancelError> {
///
/// If `continue_on_finish` is true, a "Continue" button appears when reaching the last
/// word. Otherwise, a checkmark appears.
pub async fn show_mnemonic(words: &[&str], continue_on_finish: bool) -> Result<(), CancelError> {
let result = RefCell::new(None);
let mut component = bitbox02::ui::menu_create(bitbox02::ui::MenuParams {
words,
Expand All @@ -41,6 +44,7 @@ pub async fn show_mnemonic(words: &[&str]) -> Result<(), CancelError> {
finish_on_last_cb: Some(Box::new(|| {
set_result(&result, ());
})),
continue_on_finish,
cancel_cb: Some(Box::new(|| {
cancel(&result);
})),
Expand All @@ -58,6 +62,7 @@ pub async fn confirm_word(choices: &[&str], title: &str) -> Result<u8, CancelErr
set_result(&result, idx);
})),
finish_on_last_cb: None,
continue_on_finish: false,
cancel_cb: Some(Box::new(|| {
cancel(&result);
})),
Expand Down
1 change: 1 addition & 0 deletions src/rust/bitbox02/src/ui/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ pub struct MenuParams<'a> {
pub title: Option<&'a str>,
pub select_word_cb: Option<SelectWordCb<'a>>,
pub finish_on_last_cb: Option<FinishCancelCb<'a>>,
pub continue_on_finish: bool,
pub cancel_cb: Option<FinishCancelCb<'a>>,
}

Expand Down
1 change: 1 addition & 0 deletions src/rust/bitbox02/src/ui/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ pub fn menu_create(params: MenuParams<'_>) -> Component<'_> {
.map_or_else(|| core::ptr::null(), |title| title.as_ptr()),
finish_on_last_cb,
finish_on_last_cb_param,
params.continue_on_finish,
cancel_cb,
cancel_cb_param,
core::ptr::null_mut(),
Expand Down
12 changes: 10 additions & 2 deletions src/ui/components/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ typedef struct {
component_t* finish_on_last_button;
void (*finish_on_last_cb)(void*);
void* finish_on_last_cb_param;
bool continue_on_finish;
void (*cancel_cb)(void*);
void* cancel_cb_param;
} menu_data_t;
Expand Down Expand Up @@ -107,8 +108,13 @@ static void _update_positions(component_t* menu, int32_t velocity)

if (data->index == data->length - 1 && data->finish_on_last_cb != NULL &&
data->finish_on_last_button == NULL) {
data->finish_on_last_button =
button_create("Continue", top_slider, SCREEN_WIDTH - 23, _finish, menu);
if (data->continue_on_finish) {
data->finish_on_last_button =
button_create("Continue", top_slider, SCREEN_WIDTH - 23, _finish, menu);
} else {
data->finish_on_last_button =
icon_button_create(top_slider, ICON_BUTTON_CHECK, _finish);
}
ui_util_add_sub_component(menu, data->finish_on_last_button);
}
}
Expand Down Expand Up @@ -238,6 +244,7 @@ component_t* menu_create(
const char* title,
void (*finish_on_last_cb)(void*),
void* finish_on_last_cb_param,
bool continue_on_finish,
void (*cancel_cb)(void*),
void* cancel_cb_param,
component_t* parent)
Expand Down Expand Up @@ -274,6 +281,7 @@ component_t* menu_create(
data->finish_on_last_cb = finish_on_last_cb;
data->finish_on_last_cb_param = finish_on_last_cb_param;
data->finish_on_last_button = NULL;
data->continue_on_finish = continue_on_finish;
data->cancel_cb = cancel_cb;
data->cancel_cb_param = cancel_cb_param;
menu->data = data;
Expand Down
9 changes: 6 additions & 3 deletions src/ui/components/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
* @param[in] words The words that are displayed on the screen, and through which you can slide
* through.
* @param[in] select_word_cb If specified, the callback will be called if the user selects a word.
* The parameter is the index of the selected word. Should not be used with show_index.
* The parameter is the index of the selected word.
* @param[in] length The word list length.
* @param[in] title Title for the window.
* If NULL, displays the index of the current word instead (starting at 1).
* For no title, set this to "".
* @param[in] finish_on_last_cb If set, a checkmark appears when reaching the last word, calling
* this callback.
* @param[in] finish_on_last_cb If set, a checkmark or continue button appears when reaching the
* last word, calling this callback.
* @param[in] continue_on_finish determines if the button at the last word is "Continue" or a
* checkmark.
* @param[in] cancel_cb Called when the cancel button is pressed.
* @param[in] parent The parent component.
*/
Expand All @@ -41,6 +43,7 @@ component_t* menu_create(
const char* title,
void (*finish_on_last_cb)(void*),
void* finish_on_last_cb_param,
bool continue_on_finish,
void (*cancel_cb)(void*),
void* cancel_cb_param,
component_t* parent);
Expand Down

0 comments on commit ada8c8c

Please sign in to comment.