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

Mobile status.go: getRandomMnemonic #4712

Merged
merged 10 commits into from
Feb 19, 2024
Merged

Mobile status.go: getRandomMnemonic #4712

merged 10 commits into from
Feb 19, 2024

Conversation

OmarBasem
Copy link
Contributor

@OmarBasem OmarBasem commented Feb 12, 2024

fixes: #4711

This PR adds the function getRandomMnemonic to mobile/status.go

@OmarBasem OmarBasem self-assigned this Feb 12, 2024
@status-im-auto
Copy link
Member

status-im-auto commented Feb 12, 2024

Jenkins Builds

Click to see older builds (41)
Commit #️⃣ Finished (UTC) Duration Platform Result
✖️ 43f6ab6 #1 2024-02-12 04:24:18 ~2 min tests 📄log
✔️ 43f6ab6 #1 2024-02-12 04:25:07 ~3 min linux 📦zip
✔️ 43f6ab6 #1 2024-02-12 04:26:58 ~5 min android 📦aar
✔️ 43f6ab6 #1 2024-02-12 04:27:40 ~6 min ios 📦zip
✔️ b1da689 #2 2024-02-12 04:44:02 ~1 min linux 📦zip
✔️ b1da689 #2 2024-02-12 04:44:22 ~1 min android 📦aar
✔️ b1da689 #2 2024-02-12 04:46:53 ~4 min ios 📦zip
✖️ b1da689 #2 2024-02-12 05:13:07 ~30 min tests 📄log
✔️ 3726d71 #3 2024-02-16 03:32:08 ~3 min linux 📦zip
✔️ 3726d71 #3 2024-02-16 03:33:30 ~4 min ios 📦zip
✔️ 3726d71 #3 2024-02-16 03:34:16 ~5 min android 📦aar
✖️ 3726d71 #3 2024-02-16 04:00:41 ~31 min tests 📄log
✖️ 3726d71 #4 2024-02-16 04:27:32 ~23 min tests 📄log
✖️ 3726d71 #5 2024-02-16 05:42:17 ~19 min tests 📄log
✖️ 3726d71 #6 2024-02-16 06:39:24 ~30 min tests 📄log
✔️ 85784e9 #4 2024-02-16 08:02:25 ~1 min android 📦aar
✔️ 85784e9 #4 2024-02-16 08:03:52 ~2 min ios 📦zip
✔️ 85784e9 #4 2024-02-16 08:04:18 ~3 min linux 📦zip
✖️ 85784e9 #7 2024-02-16 08:32:12 ~31 min tests 📄log
✖️ 85784e9 #8 2024-02-16 13:14:41 ~30 min tests 📄log
✔️ d924aeb #5 2024-02-19 03:38:10 ~1 min linux 📦zip
✔️ d924aeb #5 2024-02-19 03:38:37 ~2 min android 📦aar
✔️ d924aeb #5 2024-02-19 03:39:40 ~3 min ios 📦zip
✔️ d924aeb #9 2024-02-19 04:16:13 ~39 min tests 📄log
2d91cba #6 2024-02-19 08:56:45 ~15 sec linux 📄log
✔️ 2d91cba #6 2024-02-19 08:59:44 ~3 min ios 📦zip
✔️ 2d91cba #6 2024-02-19 09:00:47 ~4 min android 📦aar
✔️ 2d91cba #10 2024-02-19 09:35:53 ~39 min tests 📄log
✔️ fc434d4 #7 2024-02-19 09:01:27 ~1 min linux 📦zip
✔️ fc434d4 #7 2024-02-19 09:02:23 ~1 min android 📦aar
✔️ fc434d4 #7 2024-02-19 09:02:55 ~2 min ios 📦zip
✔️ fc434d4 #11 2024-02-19 10:15:32 ~39 min tests 📄log
✔️ 4bd753f #8 2024-02-19 11:35:14 ~1 min linux 📦zip
✔️ 4bd753f #8 2024-02-19 11:35:36 ~1 min android 📦aar
✖️ 4bd753f #12 2024-02-19 11:36:05 ~2 min tests 📄log
✔️ 4bd753f #8 2024-02-19 11:36:34 ~2 min ios 📦zip
✔️ 2014cce #9 2024-02-19 11:36:43 ~1 min linux 📦zip
✖️ 2014cce #13 2024-02-19 11:37:12 ~1 min tests 📄log
✔️ 2014cce #9 2024-02-19 11:37:24 ~1 min android 📦aar
✔️ 2014cce #9 2024-02-19 11:39:15 ~2 min ios 📦zip
✖️ 2014cce #14 2024-02-19 11:45:41 ~1 min tests 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
✖️ 238c620 #15 2024-02-19 11:59:22 ~47 sec tests 📄log
✔️ 238c620 #10 2024-02-19 11:59:47 ~1 min linux 📦zip
✔️ 238c620 #10 2024-02-19 12:01:05 ~2 min android 📦aar
✔️ 238c620 #10 2024-02-19 12:01:46 ~3 min ios 📦zip
✔️ cba3ac5 #11 2024-02-19 12:02:24 ~1 min linux 📦zip
✔️ cba3ac5 #11 2024-02-19 12:03:17 ~2 min android 📦aar
✔️ cba3ac5 #11 2024-02-19 12:05:05 ~3 min ios 📦zip
✔️ cba3ac5 #16 2024-02-19 12:37:34 ~36 min tests 📄log

Copy link
Contributor

@siddarthkay siddarthkay left a comment

Choose a reason for hiding this comment

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

Looks good.

mobile/status.go Outdated
@@ -1327,3 +1327,11 @@ func InitLogging(logSettingsJSON string) string {

return makeJSONResponse(err)
}

func GetRandomMnemonic() string {
resp, err := statusBackend.AccountManager().GetRandomMnemonic()
Copy link
Contributor

@qfrank qfrank Feb 18, 2024

Choose a reason for hiding this comment

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

Hi @OmarBasem , sorry for the delay, just back from public holiday, overall LGTM. However, I'm confused about why GetRandomMnemonic was attached to DefaultManager, as it doesn't seem to relate to the DefaultManager instance. We don't use anything related to DefaultManager within GetRandomMnemonic.

Something like following would be more clearer for me:

func GetRandomMnemonic() (string, error) {
	// generate mnemonic phrase
	mn := extkeys.NewMnemonic()
	mnemonic, err := mn.MnemonicPhrase(extkeys.EntropyStrength128, extkeys.EnglishLanguage)
	if err != nil {
		return "", fmt.Errorf("can not create mnemonic seed: %v", err)
	}
	return mnemonic, nil
}

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@qfrank why reimplement the method? I am calling GetRandomMnemonic from AccountManager similar for example to VerifyAccountPassword in the same file

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @OmarBasem,

This is not relate to your PR, it's about refactor. The reason for the suggested change is to enhance code clarity and maintainability. By directly implementing GetRandomMnemonic without routing it through DefaultManager, we make the function's operation more transparent and reduce the dependency on external structures where it's not necessary.

The goal is to have GetRandomMnemonic as a standalone function that can be used independently of the AccountManager context. This can be beneficial for future use cases where we might need a mnemonic that doesn't rely on the account management logic, and also makes the function more testable in isolation.

The reference to VerifyAccountPassword seems to follow a similar context where it didn't use any fields or context with m (DefaultManager). If we find that this pattern doesn't serve a practical purpose or complicates the code unnecessarily, we should consider refactoring it as well.

Looking forward to your thoughts on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @qfrank, thanks for the clarification. I have updated the function 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for the effort! But now there're repeat code(sorry for the confusion). Actually, what i expected was something like following in status.go 🙂:

func GetRandomMnemonic() string {
...
   mnemonic, err := account.GetRandomMnemonic()
...

@OmarBasem

Copy link
Contributor Author

@OmarBasem OmarBasem Feb 19, 2024

Choose a reason for hiding this comment

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

@qfrank Btw, I don't think there was something wrong with my initial approach. We already have access to accountManager in that file, and it is used in multiple places in that file. So why not simply statusBackend.AccountManager().GetRandomMnemonic()? Cause right now using the suggested approach we are duplicating code.

If you are suggesting not to use accountManager at all in that file (I am not sure why) then that would be a different issue. A refactor for the whole file wherever AccountManager is being used.

Copy link
Contributor

Choose a reason for hiding this comment

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

just made a branch to demo my thoughts:
9401093

maybe using program language to express would be more clearer @OmarBasem

Copy link
Contributor

Choose a reason for hiding this comment

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

@qfrank we don't have access to account here. I am using your suggested function:

mn := extkeys.NewMnemonic()
mnemonic, err := mn.MnemonicPhrase(extkeys.EntropyStrength128, extkeys.EnglishLanguage)

we have in my demo branch

Copy link
Contributor

Choose a reason for hiding this comment

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

Btw, I don't think there was something wrong with my initial approach.

You're right, that's why i mentioned not relate to your PR, it's about refactor. The old implementation(not yours) for GetRandomMnemonic confused me, it's more like a util function, should not bind to AccountManager instance IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is more clear now @qfrank, thank you! I have updated it 👍

@OmarBasem OmarBasem merged commit 54d0cf2 into develop Feb 19, 2024
7 checks passed
@OmarBasem OmarBasem deleted the feat/mobile-mnemonic branch February 19, 2024 12:53
cammellos pushed a commit that referenced this pull request Feb 20, 2024
* feat: mobile status.go - getRandomMnemonic (#4712)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add function getRandomMnemonic to mobile/status.go
4 participants