Skip to content

Commit 55ca951

Browse files
committed
fix: remove redundant value
1 parent 1d16552 commit 55ca951

File tree

2 files changed

+10
-73
lines changed

2 files changed

+10
-73
lines changed

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

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,50 +1889,6 @@ describe('SubscriptionController', () => {
18891889
);
18901890
});
18911891

1892-
it('should throw error when selected token price is not found', async () => {
1893-
await withController(
1894-
{
1895-
state: {
1896-
pricing: MOCK_PRICE_INFO_RESPONSE,
1897-
trialedProducts: [],
1898-
subscriptions: [],
1899-
lastSelectedPaymentMethod: {
1900-
[PRODUCT_TYPES.SHIELD]: {
1901-
type: PAYMENT_TYPES.byCrypto,
1902-
paymentTokenAddress: '0x123',
1903-
paymentTokenSymbol: 'USDT',
1904-
plan: RECURRING_INTERVALS.month,
1905-
},
1906-
},
1907-
},
1908-
},
1909-
async ({ controller, mockService }) => {
1910-
// Create a shield subscription approval transaction with token address that doesn't exist
1911-
const txMeta = {
1912-
...generateMockTxMeta(),
1913-
type: TransactionType.shieldSubscriptionApprove,
1914-
chainId: '0x1' as Hex,
1915-
rawTx: '0x123',
1916-
txParams: {
1917-
data: '0x456',
1918-
from: '0x1234567890123456789012345678901234567890',
1919-
to: '0xnonexistent',
1920-
},
1921-
status: TransactionStatus.submitted,
1922-
hash: '0x123',
1923-
};
1924-
1925-
await expect(
1926-
controller.submitShieldSubscriptionCryptoApproval(txMeta),
1927-
).rejects.toThrow('Selected token price not found');
1928-
1929-
expect(
1930-
mockService.startSubscriptionWithCrypto,
1931-
).not.toHaveBeenCalled();
1932-
},
1933-
);
1934-
});
1935-
19361892
it('should throw error when product price is not found', async () => {
19371893
await withController(
19381894
{
@@ -1968,7 +1924,9 @@ describe('SubscriptionController', () => {
19681924

19691925
await expect(
19701926
controller.submitShieldSubscriptionCryptoApproval(txMeta),
1971-
).rejects.toThrow('Product price not found');
1927+
).rejects.toThrow(
1928+
SubscriptionControllerErrorMessage.ProductPriceNotFound,
1929+
);
19721930

19731931
expect(
19741932
mockService.startSubscriptionWithCrypto,

packages/subscription-controller/src/SubscriptionController.ts

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -856,37 +856,16 @@ export class SubscriptionController extends StaticIntervalPollingController()<
856856
if (!lastSelectedPaymentMethod) {
857857
throw new Error('Last selected payment method not found');
858858
}
859-
this.#assertIsPaymentMethodCrypto(
860-
lastSelectedPaymentMethod[PRODUCT_TYPES.SHIELD],
861-
);
859+
const lastSelectedPaymentMethodShield =
860+
lastSelectedPaymentMethod[PRODUCT_TYPES.SHIELD];
861+
this.#assertIsPaymentMethodCrypto(lastSelectedPaymentMethodShield);
862862

863863
const isTrialed = trialedProducts?.includes(PRODUCT_TYPES.SHIELD);
864-
const pricingPlans = pricing?.products.find(
865-
(product) => product.name === PRODUCT_TYPES.SHIELD,
866-
)?.prices;
867-
const cryptoPaymentMethod = pricing?.paymentMethods.find(
868-
(paymentMethod) => paymentMethod.type === PAYMENT_TYPES.byCrypto,
869-
);
870-
const selectedTokenPrice = cryptoPaymentMethod?.chains
871-
?.find(
872-
(chain) =>
873-
chain.chainId.toLowerCase() === txMeta?.chainId.toLowerCase(),
874-
)
875-
?.tokens.find(
876-
(token) =>
877-
token.address.toLowerCase() === txMeta?.txParams?.to?.toLowerCase(),
878-
);
879-
if (!selectedTokenPrice) {
880-
throw new Error('Selected token price not found');
881-
}
882864

883-
const productPrice = pricingPlans?.find(
884-
(plan) =>
885-
plan.interval === lastSelectedPaymentMethod[PRODUCT_TYPES.SHIELD]?.plan,
865+
const productPrice = this.#getProductPriceByProductAndPlan(
866+
PRODUCT_TYPES.SHIELD,
867+
lastSelectedPaymentMethodShield.plan,
886868
);
887-
if (!productPrice) {
888-
throw new Error('Product price not found');
889-
}
890869

891870
const params = {
892871
products: [PRODUCT_TYPES.SHIELD],
@@ -895,7 +874,7 @@ export class SubscriptionController extends StaticIntervalPollingController()<
895874
billingCycles: productPrice.minBillingCycles,
896875
chainId,
897876
payerAddress: txMeta.txParams.from as Hex,
898-
tokenSymbol: selectedTokenPrice.symbol,
877+
tokenSymbol: lastSelectedPaymentMethodShield.paymentTokenSymbol,
899878
rawTransaction: rawTx as Hex,
900879
isSponsored,
901880
};

0 commit comments

Comments
 (0)