@@ -14,26 +14,18 @@ const formatter = Intl.NumberFormat('en-US', {
1414 currency : 'USD'
1515} )
1616
17- const tierCosts = [ 0 , 300 , 600 , 1000 , 2000 ]
18-
1917async function changeSubscription ( productId : string , type : 'upgrade' | 'downgrade' ) {
20- const tier = upgradeResponse . tier
21- const existingCosts = tierCosts [ tier ] ?? 0
2218 const newSub = subscriptionProducts . find ( ( v ) => v . id === productId )
2319 const newSubPrice = newSub ! . price
2420 const newSubName = newSub ! . name
2521 const confirm = ( type === 'downgrade' )
2622 ? await Confirm (
2723 `You are downgrading to ${ newSubName } , which costs ${
28- formatter . format ( ( existingCosts - newSubPrice ) / 100 )
29- } less per month. New cost: ${
3024 formatter . format ( newSubPrice / 100 )
3125 } per month. Downgrading takes effect immediately!`
3226 )
3327 : await Confirm (
34- `You are upgrading to ${ newSubName } , which costs ${
35- formatter . format ( ( newSubPrice - existingCosts ) / 100 )
36- } more per month. New cost: ${ formatter . format ( newSubPrice / 100 ) } per month`
28+ `You are upgrading to ${ newSubName } , which costs ${ formatter . format ( newSubPrice / 100 ) } per month`
3729 )
3830
3931 if ( ! confirm ) {
@@ -93,11 +85,11 @@ const constructDescriptions = ({ description, quarkBonus }: SubscriptionProduct)
9385 `
9486}
9587
96- export const createIndividualSubscriptionHTML = ( product : SubscriptionProduct , existingCosts : number ) => {
97- if ( product . price < existingCosts ) {
88+ export const createIndividualSubscriptionHTML = ( product : SubscriptionProduct , currentSubTier : number ) => {
89+ if ( product . tier < currentSubTier ) {
9890 return `
9991 <section class="subscriptionContainer" key="${ product . id } ">
100- <div>
92+ <div>
10193 <img class="pseudoCoinSubImage" alt="${ product . name } " src="./Pictures/${ product . id } .png" />
10294 <p class="pseudoCoinText">
10395 ${ product . name . split ( ' - ' ) . join ( '<br>' ) }
@@ -109,13 +101,13 @@ export const createIndividualSubscriptionHTML = (product: SubscriptionProduct, e
109101 Downgrade!
110102 </button>
111103 <div class="checkout-paypal" data-id="${ product . id } "></div>
112- </div>
104+ </div>
113105 </section>
114106 `
115- } else if ( product . price === existingCosts ) {
107+ } else if ( product . tier === currentSubTier ) {
116108 return `
117109 <section class="subscriptionContainer" key="${ product . id } ">
118- <div>
110+ <div>
119111 <img class="pseudoCoinSubImage" alt="${ product . name } " src="./Pictures/${ product . id } .png" />
120112 <p class="pseudoCoinText">
121113 ${ product . name . split ( ' - ' ) . join ( '<br>' ) }
@@ -127,13 +119,13 @@ export const createIndividualSubscriptionHTML = (product: SubscriptionProduct, e
127119 You are here!
128120 </button>
129121 <div class="checkout-paypal" data-id="${ product . id } "></div>
130- </div>
122+ </div>
131123 </section>
132124 `
133125 } else {
134126 return `
135127 <section class="subscriptionContainer" key="${ product . id } ">
136- <div>
128+ <div>
137129 <img class="pseudoCoinSubImage" alt="${ product . name } " src="./Pictures/${ product . id } .png" />
138130 <p class="pseudoCoinText">
139131 ${ product . name . split ( ' - ' ) . join ( '<br>' ) }
@@ -142,10 +134,10 @@ export const createIndividualSubscriptionHTML = (product: SubscriptionProduct, e
142134 ${ constructDescriptions ( product ) }
143135 </p>
144136 <button data-id="${ product . id } " data-name="${ product . name } " data-upgrade class="pseudoCoinButton">
145- Upgrade for ${ formatter . format ( ( product . price - existingCosts ) / 100 ) } USD / mo
137+ Upgrade for ${ formatter . format ( product . price / 100 ) } USD / mo
146138 </button>
147139 <!--<div class="checkout-paypal" data-id="${ product . id } "></div>-->
148- </div>
140+ </div>
149141 </section>
150142 `
151143 }
@@ -168,10 +160,9 @@ export const initializeSubscriptionPage = memoize(() => {
168160 }
169161
170162 const tier = upgradeResponse . tier
171- const existingCosts = tierCosts [ tier ] ?? 0
172163
173164 subscriptionSectionHolder . innerHTML = subscriptionProducts . map ( ( product ) =>
174- createIndividualSubscriptionHTML ( product , existingCosts )
165+ createIndividualSubscriptionHTML ( product , tier )
175166 ) . join ( '' )
176167
177168 subscriptionSectionHolder ! . style . display = 'grid'
0 commit comments