Repository navigation
feat: add is user elibile for trial method - #10622
Conversation
mcmire
left a comment
There was a problem hiding this comment.
Just a few suggestions to the changelogs.
| - **BREAKING:** Add `SubscriptionController:isUserEligibleForTrial` to report whether a user can start a trial for a product ([#10622](https://github.com/MetaMask/core/pull/10622)) | ||
| - Shield is eligible when the user has not trialed Shield before. | ||
| - Money Account Plus is eligible when the user has not trialed it before and `SeedlessOnboardingController:getIsUserAuthenticated` is true. |
There was a problem hiding this comment.
Why is this a breaking change? Adding a new method to a class should not be breaking. It's also not common to provide implementation details in changelogs so perhaps we can simplify this a bit:
| - **BREAKING:** Add `SubscriptionController:isUserEligibleForTrial` to report whether a user can start a trial for a product ([#10622](https://github.com/MetaMask/core/pull/10622)) | |
| - Shield is eligible when the user has not trialed Shield before. | |
| - Money Account Plus is eligible when the user has not trialed it before and `SeedlessOnboardingController:getIsUserAuthenticated` is true. | |
| - Add `SubscriptionController:isUserEligibleForTrial` to report whether a user can start a trial for a product ([#10622](https://github.com/MetaMask/core/pull/10622)) |
There was a problem hiding this comment.
oh this is breaking because it requires adding new messenger action for this new method
There was a problem hiding this comment.
Are you saying that in order to call this method, SeedlessOnboardingController:getIsUserAuthenticated must be delegated? If so, we could combine this and the entry below. I've made a separate suggestion for that.
Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
mcmire
left a comment
There was a problem hiding this comment.
Everything looks good now! Thanks for your patience.
Explanation
Clients currently have no single place to ask whether a user can start a free trial for a subscription product. Each product has its own rule:
This PR adds
SubscriptionController:isUserEligibleForTrial(productType), which returns aPromise<boolean>:trialedProductsalready includesproductType, it returnsfalsestraight away.truewithout calling any other controller.SeedlessOnboardingController:getIsUserAuthenticated. That action returnsfalsefor SRP users and for locked wallets. Only unlocked users can subscribe, so this works as the social-login check.switchonproductType. Adding a new member toPRODUCT_TYPESfails compilation until the switch handles it.To call the seedless action,
@metamask/subscription-controllernow depends on@metamask/seedless-onboarding-controller. It's a type-only import, and the package is already a dependency ofprofile-sync-controller, so this adds no circular dependency.@metamask/walletnow delegatesSeedlessOnboardingController:getIsUserAuthenticatedto theSubscriptionControllermessenger, so the default wallet setup keeps working.References
Checklist
Note
Medium Risk
Breaking messenger wiring is required for all non-wallet hosts, and trial gating for Money Account Plus depends on seedless auth state being correct.
Overview
Adds
SubscriptionController:isUserEligibleForTrial, a single messenger-backed way for clients to ask whether a user can start a free trial for a product.Eligibility first checks
trialedProductsin controller state; if the product was already trialed, the method returnsfalse. Shield is eligible when that check passes. Money Account Plus also requiresSeedlessOnboardingController:getIsUserAuthenticated(used as the social-login gate). Unknown product types throw at runtime, and newPRODUCT_TYPESvalues must be handled in the switch or TypeScript fails to compile.This is a breaking integration change:
SubscriptionControllerMessengermust be allowed to callSeedlessOnboardingController:getIsUserAuthenticated.@metamask/subscription-controlleradds a dependency on@metamask/seedless-onboarding-controller, and@metamask/walletdelegates that action in its defaultSubscriptionControllersetup so trial checks work out of the box.Reviewed by Cursor Bugbot for commit 9670d93. Bugbot is set up for automated code reviews on this repo. Configure here.