Skip to content

Commit c0160bc

Browse files
committed
workflows: add insert_sdcard() to workflows
1 parent ad08af0 commit c0160bc

File tree

5 files changed

+48
-20
lines changed

5 files changed

+48
-20
lines changed

src/rust/bitbox02-rust/src/hww/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ async fn process_api<W: Workflows>(
172172
Request::SetMnemonicPassphraseEnabled(ref request) => {
173173
set_mnemonic_passphrase_enabled::process(workflows, request).await
174174
}
175-
Request::InsertRemoveSdcard(ref request) => sdcard::process(request).await,
175+
Request::InsertRemoveSdcard(ref request) => sdcard::process(workflows, request).await,
176176
Request::ListBackups(_) => backup::list(),
177177
Request::CheckSdcard(_) => Ok(Response::CheckSdcard(pb::CheckSdCardResponse {
178178
inserted: bitbox02::sd::sdcard_inserted(),

src/rust/bitbox02-rust/src/hww/api/backup.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,12 @@ pub async fn create<W: Workflows>(
8989
.await?;
9090

9191
// Wait for sd card
92-
super::sdcard::process(&pb::InsertRemoveSdCardRequest {
93-
action: pb::insert_remove_sd_card_request::SdCardAction::InsertCard as _,
94-
})
92+
super::sdcard::process(
93+
workflows,
94+
&pb::InsertRemoveSdCardRequest {
95+
action: pb::insert_remove_sd_card_request::SdCardAction::InsertCard as _,
96+
},
97+
)
9598
.await?;
9699

97100
let is_initialized = bitbox02::memory::is_initialized();

src/rust/bitbox02-rust/src/hww/api/sdcard.rs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ use crate::pb::insert_remove_sd_card_request::SdCardAction;
1818

1919
use pb::response::Response;
2020

21-
use crate::workflow::sdcard;
21+
use crate::workflow::Workflows;
2222

23-
pub async fn process(
23+
pub async fn process<W: Workflows>(
24+
workflows: &mut W,
2425
&pb::InsertRemoveSdCardRequest { action }: &pb::InsertRemoveSdCardRequest,
2526
) -> Result<Response, Error> {
2627
let inserted = bitbox02::sd::sdcard_inserted();
@@ -31,7 +32,7 @@ pub async fn process(
3132
if inserted {
3233
return Ok(Response::Success(pb::Success {}));
3334
}
34-
sdcard::sdcard().await?;
35+
workflows.insert_sdcard().await?;
3536
Ok(Response::Success(pb::Success {}))
3637
}
3738

@@ -40,6 +41,7 @@ mod tests {
4041
use super::*;
4142

4243
use crate::bb02_async::block_on;
44+
use crate::workflow::testing::TestingWorkflows;
4345
use alloc::boxed::Box;
4446
use bitbox02::testing::{mock, Data};
4547

@@ -51,9 +53,12 @@ mod tests {
5153
..Default::default()
5254
});
5355
assert_eq!(
54-
block_on(process(&pb::InsertRemoveSdCardRequest {
55-
action: SdCardAction::InsertCard as _,
56-
})),
56+
block_on(process(
57+
&mut TestingWorkflows::new(),
58+
&pb::InsertRemoveSdCardRequest {
59+
action: SdCardAction::InsertCard as _,
60+
}
61+
)),
5762
Ok(Response::Success(pb::Success {}))
5863
);
5964

@@ -63,9 +68,12 @@ mod tests {
6368
..Default::default()
6469
});
6570
assert_eq!(
66-
block_on(process(&pb::InsertRemoveSdCardRequest {
67-
action: SdCardAction::RemoveCard as _,
68-
})),
71+
block_on(process(
72+
&mut TestingWorkflows::new(),
73+
&pb::InsertRemoveSdCardRequest {
74+
action: SdCardAction::RemoveCard as _,
75+
}
76+
)),
6977
Ok(Response::Success(pb::Success {}))
7078
);
7179

@@ -75,9 +83,12 @@ mod tests {
7583
..Default::default()
7684
});
7785
assert_eq!(
78-
block_on(process(&pb::InsertRemoveSdCardRequest {
79-
action: SdCardAction::InsertCard as _,
80-
})),
86+
block_on(process(
87+
&mut TestingWorkflows::new(),
88+
&pb::InsertRemoveSdCardRequest {
89+
action: SdCardAction::InsertCard as _,
90+
}
91+
)),
8192
Ok(Response::Success(pb::Success {}))
8293
);
8394

@@ -87,9 +98,12 @@ mod tests {
8798
..Default::default()
8899
});
89100
assert_eq!(
90-
block_on(process(&pb::InsertRemoveSdCardRequest {
91-
action: SdCardAction::RemoveCard as _,
92-
})),
101+
block_on(process(
102+
&mut TestingWorkflows::new(),
103+
&pb::InsertRemoveSdCardRequest {
104+
action: SdCardAction::RemoveCard as _,
105+
}
106+
)),
93107
Ok(Response::Success(pb::Success {}))
94108
);
95109
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub trait Workflows {
5656
can_cancel: trinary_input_string::CanCancel,
5757
preset: &str,
5858
) -> Result<zeroize::Zeroizing<String>, trinary_input_string::Error>;
59+
60+
async fn insert_sdcard(&mut self) -> Result<(), sdcard::UserAbort>;
5961
}
6062

6163
pub struct RealWorkflows;
@@ -99,4 +101,9 @@ impl Workflows for RealWorkflows {
99101
) -> Result<zeroize::Zeroizing<String>, trinary_input_string::Error> {
100102
trinary_input_string::enter(params, can_cancel, preset).await
101103
}
104+
105+
#[inline(always)]
106+
async fn insert_sdcard(&mut self) -> Result<(), sdcard::UserAbort> {
107+
sdcard::sdcard().await
108+
}
102109
}

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

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

15-
use super::{confirm, transaction, trinary_input_string, Workflows};
15+
use super::{confirm, sdcard, transaction, trinary_input_string, Workflows};
1616

1717
use alloc::boxed::Box;
1818
use alloc::string::String;
@@ -133,6 +133,10 @@ impl Workflows for TestingWorkflows<'_> {
133133
) -> Result<zeroize::Zeroizing<String>, trinary_input_string::Error> {
134134
self._enter_string.as_mut().unwrap()(params).map(zeroize::Zeroizing::new)
135135
}
136+
137+
async fn insert_sdcard(&mut self) -> Result<(), sdcard::UserAbort> {
138+
Ok(())
139+
}
136140
}
137141

138142
impl<'a> TestingWorkflows<'a> {

0 commit comments

Comments
 (0)