-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow setting name of FactorSources #305
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #305 +/- ##
=====================================
Coverage 93.3% 93.3%
=====================================
Files 1109 1109
Lines 23528 23547 +19
Branches 79 79
=====================================
+ Hits 21955 21974 +19
Misses 1558 1558
Partials 15 15
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@@ -112,6 +112,10 @@ impl BaseBaseIsFactorSource for OffDeviceMnemonicFactorSource { | |||
fn name(&self) -> String { | |||
self.hint.label.value.clone() | |||
} | |||
|
|||
fn set_name(&mut self, updated: String) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor improvement would be to change String
-> impl AsRef<str>
making it a bit easier to write unit tests, allowing you to pass string literals (&str) or String
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and inside this function you do updated.as_ref().to_owned()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did remember this suggestion from previous PR review 🙂
I decided not to include it in this case since tests are very simple anyway, and in the end we add one .as_ref().to_owned()
in production code, for each .to_owned()
removed in tests (being the relation 1-1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is unfortunate that Rust is not as great as Swift when it comes to method with same name but different types - in Swift we could have written such a method on the protocol - the trait - and allow str/String. here it would be a collision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - will approve on work phone tomorrow. anyone on work phone now can approve it for me :)
@@ -58,6 +58,16 @@ pub fn factor_source_name(factor_source: &FactorSource) -> String { | |||
factor_source.into_internal().name() | |||
} | |||
|
|||
#[uniffi::export] | |||
pub fn factor_source_set_name( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice, but I think we can go a step further and also make the update in the Profile itself, so maybe this API should have the factor source id to be updated.
Or your intention is different?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of handling it the same way we handle Account name updates, but guess we can directly do altogether. Will update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is more legacy :), we should migrate how we rename accounts sometime to be handled in Sargon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually I am not sure if it is better to have a function that updates the name: String
of a given factor_source_id: FactorSourceId
. Considering Hosts we will already have access to the actual FactorSource
and that we already have a function that updates a FactorSource
, seems pointless to send the id
just to have Sargon fetch it from the Profile.
Maybe instead the function should be like this
pub async fn update_factor_source_name(&self, factor_source: FactorSource, name: String) -> Result<()>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure that also works, the main idea is to have the Profile mutation in Sargon. You might want to return the update FactorSource as response of this function.
Exports a UniFFI function that allows setting name of any FactorSource.