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

feat: add a canSync check for account syncing #4690

Merged
merged 2 commits into from
Sep 11, 2024

Conversation

mathieuartu
Copy link
Contributor

@mathieuartu mathieuartu commented Sep 11, 2024

Explanation

This PR ensures we don't fire account syncing if the conditions are not entirely met.

References

Changelog

@metamask/profile-sync-controller

  • ADDED: Add a canSync check to account syncing

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

Sorry, something went wrong.

Verified

This commit was signed with the committer’s verified signature.
mathieuartu Mathieu Artu

Verified

This commit was signed with the committer’s verified signature.
mathieuartu Mathieu Artu
@mathieuartu mathieuartu added the team-notifications Notification Team changes. https://github.com/orgs/MetaMask/teams/notifications label Sep 11, 2024
@mathieuartu mathieuartu marked this pull request as ready for review September 11, 2024 17:02
@mathieuartu mathieuartu requested a review from a team as a code owner September 11, 2024 17:03
Comment on lines +270 to +278
try {
this.#assertProfileSyncingEnabled();

return (
this.#accounts.isAccountSyncingEnabled && this.#auth.isAuthEnabled()
);
} catch {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Yep fair.

The assert seems to just check state

#assertProfileSyncingEnabled(): void {
if (!this.state.isProfileSyncingEnabled) {
throw new Error(
`${controllerName}: Unable to call method, user is not authenticated`,
);
}
}

We might be able just create a safe one of these or copy the line.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the try/catch is still valid, since not sure what this.#auth.isAuthEnabled would call under the hood or in the future (if it changes)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this.#auth.isAuthEnabled checks the state of AuthenticationController in order to get isSignedIn.

I agree, I don't think it's 100% ideal to be honest, and we're again going to be checking UI-side if all of this is enabled. I'll look into it when I have a bit less on my plate to kind of centralize these checks.

@mathieuartu mathieuartu merged commit 6f716b6 into main Sep 11, 2024
117 checks passed
@mathieuartu mathieuartu deleted the feat/prevent_account_sync_throw branch September 11, 2024 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-notifications Notification Team changes. https://github.com/orgs/MetaMask/teams/notifications
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants