Skip to content

Commit

Permalink
PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiupuhalschi-rdx committed Feb 20, 2025
1 parent e6af3bd commit cdf3635
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ pub struct DeviceMnemonicBuilder {
mnemonic_with_passphrase: RwLock<Option<MnemonicWithPassphrase>>,
}

/// The result of the `build` function from `DeviceMnemonicBuilder`.
/// The outcome of the `build` function from `DeviceMnemonicBuilder`.
#[derive(Debug, PartialEq)]
pub enum DeviceMnemonicBuildResult {
pub enum DeviceMnemonicBuildOutcome {
/// The mnemonic words were confirmed
Confirmed {
mnemonic_with_passphrase: MnemonicWithPassphrase,
Expand Down Expand Up @@ -190,11 +190,11 @@ impl DeviceMnemonicBuilder {
pub fn build(
&self,
words_to_confirm: &HashMap<usize, String>,
) -> DeviceMnemonicBuildResult {
) -> DeviceMnemonicBuildOutcome {
if words_to_confirm.len()
!= Self::NUMBER_OF_WORDS_OF_MNEMONIC_USER_NEED_TO_CONFIRM
{
return DeviceMnemonicBuildResult::ConfirmationWordCountMismatch;
return DeviceMnemonicBuildOutcome::ConfirmationWordCountMismatch;
}

let unconfirmed_indices_in_mnemonic = words_to_confirm
Expand All @@ -209,11 +209,11 @@ impl DeviceMnemonicBuilder {
.collect::<IndexSet<_>>();

if unconfirmed_indices_in_mnemonic.is_empty() {
DeviceMnemonicBuildResult::Confirmed {
DeviceMnemonicBuildOutcome::Confirmed {
mnemonic_with_passphrase: self.get_mnemonic_with_passphrase(),
}
} else {
DeviceMnemonicBuildResult::Unconfirmed {
DeviceMnemonicBuildOutcome::Unconfirmed {
indices_in_mnemonic: unconfirmed_indices_in_mnemonic,
}
}
Expand Down Expand Up @@ -378,7 +378,7 @@ mod tests {

pretty_assertions::assert_eq!(
sut.build(&words_to_confirm),
DeviceMnemonicBuildResult::ConfirmationWordCountMismatch
DeviceMnemonicBuildOutcome::ConfirmationWordCountMismatch
);
}

Expand All @@ -396,7 +396,7 @@ mod tests {

pretty_assertions::assert_eq!(
sut.build(&words_to_confirm),
DeviceMnemonicBuildResult::Unconfirmed {
DeviceMnemonicBuildOutcome::Unconfirmed {
indices_in_mnemonic: indexset![0, 1, 2, 3]
}
);
Expand All @@ -416,7 +416,7 @@ mod tests {

pretty_assertions::assert_eq!(
sut.build(&words_to_confirm),
DeviceMnemonicBuildResult::Unconfirmed {
DeviceMnemonicBuildOutcome::Unconfirmed {
indices_in_mnemonic: indexset![7, 13]
}
);
Expand All @@ -438,7 +438,7 @@ mod tests {

pretty_assertions::assert_eq!(
result,
DeviceMnemonicBuildResult::Confirmed {
DeviceMnemonicBuildOutcome::Confirmed {
mnemonic_with_passphrase: MnemonicWithPassphrase::sample()
}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::prelude::*;
use sargon::DeviceMnemonicBuildResult as InternalDeviceMnemonicBuildResult;
use sargon::DeviceMnemonicBuildOutcome as InternalDeviceMnemonicBuildOutcome;
use sargon::DeviceMnemonicBuilder as InternalDeviceMnemonicBuilder;

/// A builder of `MnemonicWithPassphrase` required for a new `DeviceFactorSource` creation.
Expand All @@ -10,9 +10,9 @@ pub struct DeviceMnemonicBuilder {
wrapped: Arc<InternalDeviceMnemonicBuilder>,
}

/// The result of the `build` function from `DeviceMnemonicBuilder`.
/// The outcome of the `build` function from `DeviceMnemonicBuilder`.
#[derive(Debug, PartialEq, uniffi::Enum)]
pub enum DeviceMnemonicBuildResult {
pub enum DeviceMnemonicBuildOutcome {
/// The mnemonic words were confirmed
Confirmed {
mnemonic_with_passphrase: MnemonicWithPassphrase,
Expand All @@ -23,18 +23,18 @@ pub enum DeviceMnemonicBuildResult {
Unconfirmed { indices_in_mnemonic: Vec<u8> },
}

impl From<InternalDeviceMnemonicBuildResult> for DeviceMnemonicBuildResult {
fn from(value: InternalDeviceMnemonicBuildResult) -> Self {
impl From<InternalDeviceMnemonicBuildOutcome> for DeviceMnemonicBuildOutcome {
fn from(value: InternalDeviceMnemonicBuildOutcome) -> Self {
match value {
InternalDeviceMnemonicBuildResult::Confirmed {
InternalDeviceMnemonicBuildOutcome::Confirmed {
mnemonic_with_passphrase,
} => DeviceMnemonicBuildResult::Confirmed {
} => DeviceMnemonicBuildOutcome::Confirmed {
mnemonic_with_passphrase: mnemonic_with_passphrase.into(),
},
InternalDeviceMnemonicBuildResult::ConfirmationWordCountMismatch => DeviceMnemonicBuildResult::ConfirmationWordCountMismatch,
InternalDeviceMnemonicBuildResult::Unconfirmed {
InternalDeviceMnemonicBuildOutcome::ConfirmationWordCountMismatch => DeviceMnemonicBuildOutcome::ConfirmationWordCountMismatch,
InternalDeviceMnemonicBuildOutcome::Unconfirmed {
indices_in_mnemonic,
} => DeviceMnemonicBuildResult::Unconfirmed {
} => DeviceMnemonicBuildOutcome::Unconfirmed {
indices_in_mnemonic: indices_in_mnemonic
.into_iter()
.map(|i| i as u8)
Expand Down Expand Up @@ -151,7 +151,7 @@ impl DeviceMnemonicBuilder {
pub fn build(
self: Arc<Self>,
words_to_confirm: HashMap<u8, String>,
) -> DeviceMnemonicBuildResult {
) -> DeviceMnemonicBuildOutcome {
self.wrapped
.build(
&words_to_confirm
Expand Down Expand Up @@ -208,7 +208,7 @@ mod tests {

pretty_assertions::assert_eq!(
r0,
DeviceMnemonicBuildResult::ConfirmationWordCountMismatch
DeviceMnemonicBuildOutcome::ConfirmationWordCountMismatch
);

let r1 = sut.clone().build(
Expand All @@ -224,7 +224,7 @@ mod tests {

pretty_assertions::assert_eq!(
r1,
DeviceMnemonicBuildResult::Unconfirmed {
DeviceMnemonicBuildOutcome::Unconfirmed {
indices_in_mnemonic: vec![5, 11, 17]
}
);
Expand All @@ -238,7 +238,7 @@ mod tests {

pretty_assertions::assert_eq!(
r2,
DeviceMnemonicBuildResult::Confirmed {
DeviceMnemonicBuildOutcome::Confirmed {
mnemonic_with_passphrase:
sargon::MnemonicWithPassphrase::sample_device().into(),
}
Expand Down

0 comments on commit cdf3635

Please sign in to comment.