Skip to content
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

[ABW-2744] Access factor sources refactoring - create accounts #761

Conversation

giannis-rdx
Copy link
Contributor

Description

This PR:

  • introduces a new CreateAccountUseCase that accepts only factor sources that are able to create account, see FactorSource.CreatingEntity interface. Removed CreateAccountWithBabylonDeviceFactorSourceUseCase and CreateAccountWithLedgerFactorSourceUseCase
  • refactors creating account extensions/functions in the profile module to support the above use case
  • adds a AccessFactorSourceProvider in the profile module that access the MnemonicRepository and the ProfileRepository in order to calculate the derivation path and to derive the public key
  • adds a AccessFactorSourceProxy that works as a mediator between the UI (bottomsheet), and the "clients" who request access to factor sources, e.g. CreateAccountViewModel requires a public key of the factor source to create an account
  • refactors the ChooseLedgerScreen to return the selected ledger device and to not derive the public key

This PR is a chained PR of the #750

How to test

Please test it not only by creating accounts with device and ledger but also by switching networks and creating accounts during the flows that creation is possible (e.g. when login to a dapp)

Video

Screen.Recording.2024-01-23.at.11.38.59.AM.mov

PR submission checklist

  • I have tested account creation in different flows
  • I have written one unit test

Comment on lines 101 to 111
// if main babylon factor source is not present, it will be created during the public key derivation
val publicKeyAndDerivationPath = accessFactorSourceProxy.getPublicKeyAndDerivationPathForFactorSource(
accessFactorSourceInput = AccessFactorSourceInput.ToCreateAccount(
forNetworkId = onNetworkId,
factorSource = if (isWithLedger && selectedFactorSource != null) {
selectedFactorSource
} else {
null
}
)
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually here is the part that I don't like and we discussed about it in the chapter meeting.
What it should be ideal here is to pass an already created babylon device factor source and not to pass the null.

import rdx.works.profile.derivation.model.NetworkId
import javax.inject.Inject

class AccessFactorSourceProvider @Inject constructor(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit confused with the purpose of this class. It does not access any factor sources, it looks like to me a wrapper of methods that will get increasingly bigger in the future like a utils class. Both methods below have no connection together.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my initial idea is to push all the related to access factor sources (either derive public key or signing) logic in the profile module and keep the viewmodel of the bottomsheet with the minimum logic. And then this "provider" would return the result (public key, signers) to the UI.
However, that's not really possible because some factor sources e.g. ledger are off device.

But I still think to proceed with this way and see how this will escalate. Maybe this provider can be a "AccessOnDeviceFactorSourcesWhatever".

This refactoring is definitely not in the final version( in this PR) and it's in my mind that design can change later when implementing the rest of factor sources.

Copy link
Contributor Author

@giannis-rdx giannis-rdx Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also keep in mind that this class would go away with the shared lib 😄 and this is one more reason to keep the view with the minimum access factor sources logic 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, I get your point

Comment on lines 64 to 66
isAccessingFactorSourceInProgress: Boolean,
isAccessingFactorSourceCompleted: Boolean,
showContentForFactorSource: AccessFactorSourceUiState.ShowContentFor,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this content is only for deriving public keys, correct? If so we should separate each case on its own composable or have different dialogs for different cases. Like

Instead of naming this AccessFactorSourceBottomSheet we could name it like DerivePublicKeysDialog. Then we can create other dialogs that do other things with factor sources and let the app event decide what dialog to open.

Copy link
Contributor Author

@giannis-rdx giannis-rdx Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it seems that one dialog might be too much to handle all the factor sources., and that's also in my mind for a future change. But my answer here is similar to the above. Let's see how it will really escalate and proceed step by step.

Btw I am not gonna merge this PR, it needs testing from us and Umair, and if all looks fine then I will merge.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

@giannis-rdx giannis-rdx force-pushed the feature/ABW-2743-create-basic-ui-for-bottom-sheet branch from af736ef to 688feb7 Compare January 24, 2024 17:42
@giannis-rdx giannis-rdx force-pushed the feature/ABW-2744-access-factor-sources-create-accounts branch from 3eee9f8 to fe9fcec Compare January 24, 2024 17:58
Copy link
Contributor

@jakub-rdx jakub-rdx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good and works fine. Nice work. One thing that might be a bug is scenario when you create first time account with ledger. Please see attached video and let me know if doing biometrics twice is expected here:

screen-20240129-124527.mp4

@giannis-rdx
Copy link
Contributor Author

Overall looks good and works fine. Nice work. One thing that might be a bug is scenario when you create first time account with ledger. Please see attached video and let me know if doing biometrics twice is expected here:

yeah right, I also spotted this last week and am aware of it. Thanks for clarifying it!
Once I am back to access factor sources refactoring I will investigate.

@giannis-rdx giannis-rdx force-pushed the feature/ABW-2743-create-basic-ui-for-bottom-sheet branch from 688feb7 to 4825e52 Compare February 5, 2024 08:42
@giannis-rdx giannis-rdx force-pushed the feature/ABW-2744-access-factor-sources-create-accounts branch from e3a2419 to 3431b7c Compare February 5, 2024 10:02
@giannis-rdx giannis-rdx force-pushed the feature/ABW-2743-create-basic-ui-for-bottom-sheet branch from 5376eb4 to e525b75 Compare February 6, 2024 13:32
@giannis-rdx giannis-rdx force-pushed the feature/ABW-2744-access-factor-sources-create-accounts branch from b9c754d to 2110b4e Compare February 6, 2024 13:36
@giannis-rdx giannis-rdx force-pushed the feature/ABW-2743-create-basic-ui-for-bottom-sheet branch from e525b75 to feed700 Compare February 9, 2024 16:24
@giannis-rdx giannis-rdx force-pushed the feature/ABW-2744-access-factor-sources-create-accounts branch from ff8318e to fb12bc4 Compare February 9, 2024 16:25
Copy link
Contributor

@raf-rdx raf-rdx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested works fine 👍

Copy link

sonarcloud bot commented Feb 13, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 40%)

See analysis details on SonarCloud

@giannis-rdx giannis-rdx merged commit 115fc02 into feature/ABW-2743-create-basic-ui-for-bottom-sheet Feb 13, 2024
8 of 9 checks passed
@giannis-rdx giannis-rdx deleted the feature/ABW-2744-access-factor-sources-create-accounts branch February 13, 2024 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants