-
Notifications
You must be signed in to change notification settings - Fork 5.4k
feat: link rewards to shield subscription #38489
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
Open
lwin-kyaw
wants to merge
10
commits into
main
Choose a base branch
from
feat/shield-rewards-link
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+951
−107
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4987a3c
chore: removed unused subscription actions
lwin-kyaw c67beb1
feat: get rewardsSubscriptionId for shield subscribed account
lwin-kyaw 0ee67f0
feat: link reward to subscription
lwin-kyaw 3380903
feat: link reward to crypto subs and refactor
lwin-kyaw 1e7fcf1
Merge remote-tracking branch 'origin/main' into feat/shield-rewards-link
lwin-kyaw 45fd45e
Update LavaMoat policies
metamaskbot b174e08
feat: updated privacy-snapshot for rewards APIs
lwin-kyaw b270f2c
fix: fixed lint
lwin-kyaw 943a3d1
chore: refactoring and error handling
lwin-kyaw c88a95d
Merge remote-tracking branch 'origin/main' into feat/shield-rewards-link
lwin-kyaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,7 +129,7 @@ import { | |
| SecretType, | ||
| RecoveryError, | ||
| } from '@metamask/seedless-onboarding-controller'; | ||
| import { COHORT_NAMES, PRODUCT_TYPES } from '@metamask/subscription-controller'; | ||
| import { PRODUCT_TYPES } from '@metamask/subscription-controller'; | ||
| import { isSnapId } from '@metamask/snaps-utils'; | ||
| import { | ||
| findAtomicBatchSupportForChain, | ||
|
|
@@ -911,11 +911,11 @@ export default class MetamaskController extends EventEmitter { | |
| this.controllerMessenger.subscribe( | ||
| 'TransactionController:transactionSubmitted', | ||
| ({ transactionMeta }) => { | ||
| this._onShieldSubscriptionApprovalTransaction(transactionMeta).catch( | ||
| (err) => { | ||
| this.subscriptionService | ||
| .handlePostTransaction(transactionMeta) | ||
| .catch((err) => { | ||
| console.error('Error onShieldSubscriptionApprovalTransaction', err); | ||
| }, | ||
| ); | ||
| }); | ||
| }, | ||
| ); | ||
|
|
||
|
|
@@ -2607,10 +2607,6 @@ export default class MetamaskController extends EventEmitter { | |
| this.subscriptionService.updateSubscriptionCardPaymentMethod.bind( | ||
| this.subscriptionService, | ||
| ), | ||
| startSubscriptionWithCrypto: | ||
| this.subscriptionController.startSubscriptionWithCrypto.bind( | ||
| this.subscriptionController, | ||
| ), | ||
| updateSubscriptionCryptoPaymentMethod: | ||
| this.subscriptionService.updateSubscriptionCryptoPaymentMethod.bind( | ||
| this.subscriptionService, | ||
|
|
@@ -2619,6 +2615,10 @@ export default class MetamaskController extends EventEmitter { | |
| this.subscriptionController.submitUserEvent.bind( | ||
| this.subscriptionController, | ||
| ), | ||
| linkRewardToShieldSubscription: | ||
| this.subscriptionService.linkRewardToExistingSubscription.bind( | ||
| this.subscriptionService, | ||
| ), | ||
|
|
||
| // rewards | ||
| getRewardsCandidateSubscriptionId: | ||
|
|
@@ -8643,66 +8643,6 @@ export default class MetamaskController extends EventEmitter { | |
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Handles the shield subscription approval transaction after confirm | ||
| * NOTE: This doesn't subscribe to messenger internally inside controller because we need more info from the client as params | ||
| * | ||
| * @param transactionMeta - The transaction metadata. | ||
| */ | ||
| async _onShieldSubscriptionApprovalTransaction(transactionMeta) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored this to |
||
| const { isGasFeeSponsored, chainId } = transactionMeta; | ||
| const bundlerSupported = await isSendBundleSupported(chainId); | ||
| const isSponsored = isGasFeeSponsored && bundlerSupported; | ||
|
|
||
| try { | ||
| this.subscriptionService.trackSubscriptionRequestEvent( | ||
| 'started', | ||
| transactionMeta, | ||
| { | ||
| has_sufficient_crypto_balance: true, | ||
| }, | ||
| ); | ||
|
|
||
| await this.subscriptionController.submitShieldSubscriptionCryptoApproval( | ||
| transactionMeta, | ||
| isSponsored, | ||
| ); | ||
|
|
||
| // Mark send/transfer/swap transactions for Shield post_tx cohort evaluation | ||
| const isPostTxTransaction = [ | ||
| TransactionType.simpleSend, | ||
| TransactionType.tokenMethodTransfer, | ||
| TransactionType.swap, | ||
| TransactionType.swapAndSend, | ||
| ].includes(transactionMeta.type); | ||
|
|
||
| const { pendingShieldCohort } = this.appStateController.state; | ||
| if (isPostTxTransaction && !pendingShieldCohort) { | ||
| this.appStateController.setPendingShieldCohort( | ||
| COHORT_NAMES.POST_TX, | ||
| transactionMeta.type, | ||
| ); | ||
| } | ||
| this.subscriptionService.trackSubscriptionRequestEvent( | ||
| 'completed', | ||
| transactionMeta, | ||
| { | ||
| gas_sponsored: isSponsored, | ||
| }, | ||
| ); | ||
| } catch (error) { | ||
| log.error('Error on Shield subscription approval transaction', error); | ||
| this.subscriptionService.trackSubscriptionRequestEvent( | ||
| 'failed', | ||
| transactionMeta, | ||
| { | ||
| error_message: error.message, | ||
| }, | ||
| ); | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @deprecated | ||
| * Controllers should subscribe to messenger events internally rather than relying on the client. | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Removing since, this API is not being used by JSON RPC Engine.