Skip to content

Commit

Permalink
feat: UX improvement for signing with Ledger - automatically open a n…
Browse files Browse the repository at this point in the history
…ear-app on Ledger device before calling methods (#403)
  • Loading branch information
akorchyn authored Sep 2, 2024
1 parent be314cc commit 5d68476
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 10 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/commands/account/add_key/use_ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ impl AddLedgerKeyActionContext {
scope: &<AddLedgerKeyAction as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
let seed_phrase_hd_path = scope.seed_phrase_hd_path.clone();
eprintln!("Opening the NEAR application... Please approve opening the application");
near_ledger::open_near_application().map_err(|ledger_error| {
color_eyre::Report::msg(format!("An error happened while trying to open the NEAR application on the ledger: {ledger_error:?}"))
})?;

std::thread::sleep(std::time::Duration::from_secs(1));

eprintln!(
"Please allow getting the PublicKey on Ledger device (HD Path: {})",
seed_phrase_hd_path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ impl SaveWithLedgerContext {
std::sync::Arc::new({
let seed_phrase_hd_path = scope.seed_phrase_hd_path.clone();
move |folder_path| {
eprintln!(
"Opening the NEAR application... Please approve opening the application"
);
near_ledger::open_near_application().map_err(|ledger_error| {
color_eyre::Report::msg(format!("An error happened while trying to open the NEAR application on the ledger: {ledger_error:?}"))
})?;
std::thread::sleep(std::time::Duration::from_secs(1));

eprintln!(
"Please allow getting the PublicKey on Ledger device (HD Path: {})",
seed_phrase_hd_path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ impl AddAccessWithLedgerContext {
scope: &<AddAccessWithLedger as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
let seed_phrase_hd_path = scope.seed_phrase_hd_path.clone();
eprintln!("Opening the NEAR application... Please approve opening the application");
near_ledger::open_near_application().map_err(|ledger_error| {
color_eyre::Report::msg(format!("An error happened while trying to open the NEAR application on the ledger: {ledger_error:?}"))
})?;

std::thread::sleep(std::time::Duration::from_secs(1));

eprintln!(
"Please allow getting the PublicKey on Ledger device (HD Path: {})",
seed_phrase_hd_path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ impl AddAccessWithLedgerContext {
previous_context: super::super::NewAccountContext,
scope: &<AddAccessWithLedger as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
eprintln!("Opening the NEAR application... Please approve opening the application");
near_ledger::open_near_application().map_err(|ledger_error| {
color_eyre::Report::msg(format!("An error happened while trying to open the NEAR application on the ledger: {ledger_error:?}"))
})?;

std::thread::sleep(std::time::Duration::from_secs(1));

let seed_phrase_hd_path = scope.seed_phrase_hd_path.clone();
eprintln!(
"Please allow getting the PublicKey on Ledger device (HD Path: {})",
Expand Down
9 changes: 9 additions & 0 deletions src/transaction_signature_options/sign_with_ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,15 @@ impl interactive_clap::FromCli for SignLedger {
.clone()
.expect("Unexpected error");

eprintln!("Opening the NEAR application... Please approve opening the application");
if let Err(err) = near_ledger::open_near_application().map_err(|ledger_error| {
color_eyre::Report::msg(format!("An error happened while trying to open the NEAR application on the ledger: {ledger_error:?}"))
}) {
return interactive_clap::ResultFromCli::Err(Some(clap_variant), err);
}

std::thread::sleep(std::time::Duration::from_secs(1));

eprintln!(
"Please allow getting the PublicKey on Ledger device (HD Path: {})",
seed_phrase_hd_path
Expand Down

0 comments on commit 5d68476

Please sign in to comment.