@@ -84,115 +84,115 @@ const PlanChangeControls = React.memo(function PlanChangeControls({
8484 let currentBasePlan = 'unknown' ;
8585 let activeSub : ActiveSubscription | undefined = undefined ;
8686
87- if ( Platform . OS === 'ios' ) {
88- // On iOS, find the most recent subscription (in case both exist during transition)
89- // Sort by transaction date to get the most recent one
90- const sortedSubs = [ ...premiumSubs ] . sort ( ( a , b ) => {
91- const dateA = a . transactionDate ?? 0 ;
92- const dateB = b . transactionDate ?? 0 ;
93- return dateB - dateA ;
94- } ) ;
87+ if ( Platform . OS === 'ios' ) {
88+ // On iOS, find the most recent subscription (in case both exist during transition)
89+ // Sort by transaction date to get the most recent one
90+ const sortedSubs = [ ...premiumSubs ] . sort ( ( a , b ) => {
91+ const dateA = a . transactionDate ?? 0 ;
92+ const dateB = b . transactionDate ?? 0 ;
93+ return dateB - dateA ;
94+ } ) ;
9595
96- activeSub = sortedSubs [ 0 ] ;
96+ activeSub = sortedSubs [ 0 ] ;
9797
98- // Check for the most recent purchase to determine actual plan
99- // First, check if both products exist (transition state)
100- const hasYearly = premiumSubs . some (
101- ( s ) => s . productId === 'dev.hyo.martie.premium_year' ,
102- ) ;
103- const hasMonthly = premiumSubs . some (
104- ( s ) => s . productId === 'dev.hyo.martie.premium' ,
105- ) ;
98+ // Check for the most recent purchase to determine actual plan
99+ // First, check if both products exist (transition state)
100+ const hasYearly = premiumSubs . some (
101+ ( s ) => s . productId === 'dev.hyo.martie.premium_year' ,
102+ ) ;
103+ const hasMonthly = premiumSubs . some (
104+ ( s ) => s . productId === 'dev.hyo.martie.premium' ,
105+ ) ;
106106
107- if ( lastPurchasedPlan ) {
108- // If we have a recently purchased plan, use that
109- currentBasePlan = lastPurchasedPlan ;
110- console . log ( 'Using last purchased plan:' , lastPurchasedPlan ) ;
111- } else if ( hasYearly && ! hasMonthly ) {
112- // Only yearly exists - user has yearly
107+ if ( lastPurchasedPlan ) {
108+ // If we have a recently purchased plan, use that
109+ currentBasePlan = lastPurchasedPlan ;
110+ console . log ( 'Using last purchased plan:' , lastPurchasedPlan ) ;
111+ } else if ( hasYearly && ! hasMonthly ) {
112+ // Only yearly exists - user has yearly
113+ currentBasePlan = 'premium-year' ;
114+ } else if ( ! hasYearly && hasMonthly ) {
115+ // Only monthly exists - user has monthly
116+ currentBasePlan = 'premium' ;
117+ } else if ( activeSub ) {
118+ // Both exist or transition state - use the most recent one
119+ if ( activeSub . productId === 'dev.hyo.martie.premium_year' ) {
113120 currentBasePlan = 'premium-year' ;
114- } else if ( ! hasYearly && hasMonthly ) {
115- // Only monthly exists - user has monthly
121+ } else if ( activeSub . productId === 'dev.hyo.martie.premium' ) {
116122 currentBasePlan = 'premium' ;
117- } else if ( activeSub ) {
118- // Both exist or transition state - use the most recent one
119- if ( activeSub . productId === 'dev.hyo.martie.premium_year' ) {
120- currentBasePlan = 'premium-year' ;
121- } else if ( activeSub . productId === 'dev.hyo.martie.premium' ) {
122- currentBasePlan = 'premium' ;
123- }
124123 }
124+ }
125+ } else {
126+ // Android uses base plans within the same product
127+ activeSub = premiumSubs [ 0 ] ;
128+ const extendedSub = activeSub as ExtendedActiveSubscription ;
129+ if ( extendedSub . basePlanId ) {
130+ currentBasePlan = extendedSub . basePlanId ;
131+ } else if ( lastPurchasedPlan ) {
132+ currentBasePlan = lastPurchasedPlan ;
125133 } else {
126- // Android uses base plans within the same product
127- activeSub = premiumSubs [ 0 ] ;
128- const extendedSub = activeSub as ExtendedActiveSubscription ;
129- if ( extendedSub . basePlanId ) {
130- currentBasePlan = extendedSub . basePlanId ;
131- } else if ( lastPurchasedPlan ) {
132- currentBasePlan = lastPurchasedPlan ;
133- } else {
134- // Default to monthly if we can't detect
135- currentBasePlan = 'premium' ;
136- }
134+ // Default to monthly if we can't detect
135+ currentBasePlan = 'premium' ;
137136 }
137+ }
138138
139- console . log (
140- 'Button section - current base plan:' ,
141- currentBasePlan ,
142- 'Active sub:' ,
143- activeSub ?. productId ,
144- ) ;
139+ console . log (
140+ 'Button section - current base plan:' ,
141+ currentBasePlan ,
142+ 'Active sub:' ,
143+ activeSub ?. productId ,
144+ ) ;
145145
146- // iOS doesn't need upgrade/downgrade buttons as it's handled automatically by the App Store
147- if ( Platform . OS === 'ios' ) {
148- return null ;
149- }
146+ // iOS doesn't need upgrade/downgrade buttons as it's handled automatically by the App Store
147+ if ( Platform . OS === 'ios' ) {
148+ return null ;
149+ }
150150
151- return (
152- < View style = { styles . planChangeSection } >
153- { currentBasePlan === 'premium' && (
154- < TouchableOpacity
155- style = { [ styles . changePlanButton , styles . upgradeButton ] }
156- onPress = { ( ) =>
157- handlePlanChange (
158- activeSub ?. productId || 'dev.hyo.martie.premium' ,
159- 'upgrade' ,
160- 'premium' ,
161- )
162- }
163- disabled = { isProcessing }
164- >
165- < Text style = { styles . changePlanButtonText } >
166- ⬆️ Upgrade to Yearly Plan
167- </ Text >
168- < Text style = { styles . changePlanButtonSubtext } >
169- Save with annual billing
170- </ Text >
171- </ TouchableOpacity >
172- ) }
151+ return (
152+ < View style = { styles . planChangeSection } >
153+ { currentBasePlan === 'premium' && (
154+ < TouchableOpacity
155+ style = { [ styles . changePlanButton , styles . upgradeButton ] }
156+ onPress = { ( ) =>
157+ handlePlanChange (
158+ activeSub ?. productId || 'dev.hyo.martie.premium' ,
159+ 'upgrade' ,
160+ 'premium' ,
161+ )
162+ }
163+ disabled = { isProcessing }
164+ >
165+ < Text style = { styles . changePlanButtonText } >
166+ ⬆️ Upgrade to Yearly Plan
167+ </ Text >
168+ < Text style = { styles . changePlanButtonSubtext } >
169+ Save with annual billing
170+ </ Text >
171+ </ TouchableOpacity >
172+ ) }
173173
174- { currentBasePlan === 'premium-year' && (
175- < TouchableOpacity
176- style = { [ styles . changePlanButton , styles . downgradeButton ] }
177- onPress = { ( ) =>
178- handlePlanChange (
179- activeSub ?. productId || 'dev.hyo.martie.premium_year' ,
180- 'downgrade' ,
181- 'premium-year' ,
182- )
183- }
184- disabled = { isProcessing }
185- >
186- < Text style = { styles . changePlanButtonText } >
187- ⬇️ Downgrade to Monthly Plan
188- </ Text >
189- < Text style = { styles . changePlanButtonSubtext } >
190- More flexibility with monthly billing
191- </ Text >
192- </ TouchableOpacity >
193- ) }
194- </ View >
195- ) ;
174+ { currentBasePlan === 'premium-year' && (
175+ < TouchableOpacity
176+ style = { [ styles . changePlanButton , styles . downgradeButton ] }
177+ onPress = { ( ) =>
178+ handlePlanChange (
179+ activeSub ?. productId || 'dev.hyo.martie.premium_year' ,
180+ 'downgrade' ,
181+ 'premium-year' ,
182+ )
183+ }
184+ disabled = { isProcessing }
185+ >
186+ < Text style = { styles . changePlanButtonText } >
187+ ⬇️ Downgrade to Monthly Plan
188+ </ Text >
189+ < Text style = { styles . changePlanButtonSubtext } >
190+ More flexibility with monthly billing
191+ </ Text >
192+ </ TouchableOpacity >
193+ ) }
194+ </ View >
195+ ) ;
196196} ) ;
197197
198198/**
0 commit comments