Skip to content

Commit ccb493e

Browse files
authored
feat: make getCryptoApproveTransactionParams synchronous (#6930)
## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> - Make `getCryptoApproveTransactionParams` synchronous ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [x] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Convert `getCryptoApproveTransactionParams` to a synchronous method and update tests and changelog accordingly. > > - **Subscription Controller** > - Change `getCryptoApproveTransactionParams` in `src/SubscriptionController.ts` from `async` to synchronous (`Promise` -> direct return). > - **Tests** > - Update `src/SubscriptionController.test.ts` to call `getCryptoApproveTransactionParams` without `await`. > - **Changelog** > - Add entry under `Unreleased` noting `getCryptoApproveTransactionParams` is now synchronous in `packages/subscription-controller/CHANGELOG.md`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 013399d. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 796d640 commit ccb493e

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

packages/subscription-controller/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Changed
1111

12+
- Make `getCryptoApproveTransactionParams` synchronous ([#6930](https://github.com/MetaMask/core/pull/6930))
1213
- Bump `@metamask/base-controller` from `^8.4.1` to `^8.4.2` ([#6917](https://github.com/MetaMask/core/pull/6917))
1314

1415
## [2.0.0]

packages/subscription-controller/src/SubscriptionController.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ describe('SubscriptionController', () => {
962962
},
963963
},
964964
async ({ controller }) => {
965-
const result = await controller.getCryptoApproveTransactionParams({
965+
const result = controller.getCryptoApproveTransactionParams({
966966
chainId: '0x1',
967967
paymentTokenAddress: '0xtoken',
968968
productType: PRODUCT_TYPES.SHIELD,
@@ -981,14 +981,14 @@ describe('SubscriptionController', () => {
981981

982982
it('throws when pricing not found', async () => {
983983
await withController(async ({ controller }) => {
984-
await expect(
984+
expect(() =>
985985
controller.getCryptoApproveTransactionParams({
986986
chainId: '0x1',
987987
paymentTokenAddress: '0xtoken',
988988
productType: PRODUCT_TYPES.SHIELD,
989989
interval: RECURRING_INTERVALS.month,
990990
}),
991-
).rejects.toThrow('Subscription pricing not found');
991+
).toThrow('Subscription pricing not found');
992992
});
993993
});
994994

@@ -1003,14 +1003,14 @@ describe('SubscriptionController', () => {
10031003
},
10041004
},
10051005
async ({ controller }) => {
1006-
await expect(
1006+
expect(() =>
10071007
controller.getCryptoApproveTransactionParams({
10081008
chainId: '0x1',
10091009
paymentTokenAddress: '0xtoken',
10101010
productType: PRODUCT_TYPES.SHIELD,
10111011
interval: RECURRING_INTERVALS.month,
10121012
}),
1013-
).rejects.toThrow('Product price not found');
1013+
).toThrow('Product price not found');
10141014
},
10151015
);
10161016
});
@@ -1040,14 +1040,14 @@ describe('SubscriptionController', () => {
10401040
},
10411041
},
10421042
async ({ controller }) => {
1043-
await expect(
1043+
expect(() =>
10441044
controller.getCryptoApproveTransactionParams({
10451045
chainId: '0x1',
10461046
paymentTokenAddress: '0xtoken',
10471047
productType: PRODUCT_TYPES.SHIELD,
10481048
interval: RECURRING_INTERVALS.month,
10491049
}),
1050-
).rejects.toThrow('Price not found');
1050+
).toThrow('Price not found');
10511051
},
10521052
);
10531053
});
@@ -1067,14 +1067,14 @@ describe('SubscriptionController', () => {
10671067
},
10681068
},
10691069
async ({ controller }) => {
1070-
await expect(
1070+
expect(() =>
10711071
controller.getCryptoApproveTransactionParams({
10721072
chainId: '0x1',
10731073
paymentTokenAddress: '0xtoken',
10741074
productType: PRODUCT_TYPES.SHIELD,
10751075
interval: RECURRING_INTERVALS.month,
10761076
}),
1077-
).rejects.toThrow('Chains payment info not found');
1077+
).toThrow('Chains payment info not found');
10781078
},
10791079
);
10801080
});
@@ -1101,14 +1101,14 @@ describe('SubscriptionController', () => {
11011101
},
11021102
},
11031103
async ({ controller }) => {
1104-
await expect(
1104+
expect(() =>
11051105
controller.getCryptoApproveTransactionParams({
11061106
chainId: '0x1',
11071107
paymentTokenAddress: '0xtoken',
11081108
productType: PRODUCT_TYPES.SHIELD,
11091109
interval: RECURRING_INTERVALS.month,
11101110
}),
1111-
).rejects.toThrow('Invalid chain id');
1111+
).toThrow('Invalid chain id');
11121112
},
11131113
);
11141114
});
@@ -1121,14 +1121,14 @@ describe('SubscriptionController', () => {
11211121
},
11221122
},
11231123
async ({ controller }) => {
1124-
await expect(
1124+
expect(() =>
11251125
controller.getCryptoApproveTransactionParams({
11261126
chainId: '0x1',
11271127
paymentTokenAddress: '0xtoken-invalid',
11281128
productType: PRODUCT_TYPES.SHIELD,
11291129
interval: RECURRING_INTERVALS.month,
11301130
}),
1131-
).rejects.toThrow('Invalid token address');
1131+
).toThrow('Invalid token address');
11321132
},
11331133
);
11341134
});
@@ -1162,14 +1162,14 @@ describe('SubscriptionController', () => {
11621162
},
11631163
},
11641164
async ({ controller }) => {
1165-
await expect(
1165+
expect(() =>
11661166
controller.getCryptoApproveTransactionParams({
11671167
chainId: '0x1',
11681168
paymentTokenAddress: '0xtoken',
11691169
productType: PRODUCT_TYPES.SHIELD,
11701170
interval: RECURRING_INTERVALS.month,
11711171
}),
1172-
).rejects.toThrow('Conversion rate not found');
1172+
).toThrow('Conversion rate not found');
11731173
},
11741174
);
11751175
});

packages/subscription-controller/src/SubscriptionController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,9 @@ export class SubscriptionController extends StaticIntervalPollingController()<
421421
* @param request.interval - The interval
422422
* @returns The crypto approve transaction params
423423
*/
424-
async getCryptoApproveTransactionParams(
424+
getCryptoApproveTransactionParams(
425425
request: GetCryptoApproveTransactionRequest,
426-
): Promise<GetCryptoApproveTransactionResponse> {
426+
): GetCryptoApproveTransactionResponse {
427427
const { pricing } = this.state;
428428
if (!pricing) {
429429
throw new Error('Subscription pricing not found');

0 commit comments

Comments
 (0)