1- import * as _ from 'lodash' ;
21import { delay , doWhile } from '@httptoolkit/util' ;
32import { SKU , SubscriptionPricing } from './types' ;
43
@@ -44,9 +43,9 @@ async function loadPlanPrices() {
4443 const productPrices = data . response . products as Array < SubscriptionPricing > ;
4544
4645 productPrices . forEach ( ( productPrice ) => {
47- const plan = _ . find ( SubscriptionPlans ,
48- { paddleId : productPrice . product_id }
49- ) as SubscriptionPlan | undefined ;
46+ const plan = Object . values ( SubscriptionPlans ) . find (
47+ plan => plan . paddleId === productPrice . product_id
48+ ) ;
5049
5150 if ( ! plan ) return ;
5251
@@ -77,7 +76,7 @@ export async function loadPlanPricesUntilSuccess() {
7776 ] ) . then ( ( ) => delay ( 1000 ) ) , // Limit the frequency
7877
7978 // While: if any subs didn't successfully get data, try again:
80- ( ) => _ . some ( SubscriptionPlans , ( plan ) => ! plan . prices ) ,
79+ ( ) => Object . values ( SubscriptionPlans ) . some ( ( plan ) => ! plan . prices ) ,
8180 ) ;
8281
8382 return SubscriptionPlans ;
@@ -87,12 +86,14 @@ function formatPrice(currency: string, price: number) {
8786 return Number ( price ) . toLocaleString ( undefined , {
8887 style : "currency" ,
8988 currency : currency ,
90- minimumFractionDigits : _ . round ( price ) === price ? 0 : 2 ,
89+ minimumFractionDigits : Math . round ( price ) === price ? 0 : 2 ,
9190 maximumFractionDigits : 2
9291 } )
9392}
9493
9594export const getPlanByCode = ( sku : SKU ) => SubscriptionPlans [ sku ] ;
9695
9796export const getSKUForPaddleId = ( paddleId : number | undefined ) =>
98- _ . findKey ( SubscriptionPlans , { paddleId : paddleId } ) as SKU | undefined ;
97+ ( Object . keys ( SubscriptionPlans ) as SKU [ ] ) . find ( sku =>
98+ SubscriptionPlans [ sku ] . paddleId === paddleId
99+ ) ;
0 commit comments