Skip to content

Commit 7d44194

Browse files
committed
fix: upgrade wrapper bugs
1 parent 48c9e08 commit 7d44194

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

apps/frontend/src/components/ui/servers/ServersUpgradeModalWrapper.vue

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
:on-finalize-no-payment-change="finalizeDowngrade"
2121
@hide="
2222
() => {
23+
debug('modal hidden, resetting subscription')
2324
subscription = null
2425
}
2526
"
@@ -32,6 +33,7 @@ import {
3233
injectModrinthClient,
3334
injectNotificationManager,
3435
ModrinthServersPurchaseModal,
36+
useDebugLogger,
3537
} from '@modrinth/ui'
3638
import { useMutation, useQuery } from '@tanstack/vue-query'
3739
import { computed, ref, watch } from 'vue'
@@ -40,6 +42,7 @@ import { products } from '~/generated/state.json'
4042
4143
const { addNotification } = injectNotificationManager()
4244
const { labrinth, archon } = injectModrinthClient()
45+
const debug = useDebugLogger('ServersUpgradeModalWrapper')
4346
4447
const config = useRuntimeConfig()
4548
const purchaseModal = ref<InstanceType<typeof ModrinthServersPurchaseModal> | null>(null)
@@ -49,15 +52,15 @@ const selectedCurrency = ref<string>('USD')
4952
const regionPings = ref<any[]>([])
5053
5154
const pyroProducts = (products as Labrinth.Billing.Internal.Product[])
52-
.filter((p) => p?.metadata?.type === 'pyro')
55+
.filter((p) => p?.metadata?.type === 'pyro' || p?.metadata?.type === 'medal')
5356
.sort((a, b) => {
54-
const aRam = a?.metadata?.type === 'pyro' ? a.metadata.ram : 0
55-
const bRam = b?.metadata?.type === 'pyro' ? b.metadata.ram : 0
57+
const aRam = a?.metadata?.type === 'pyro' || a?.metadata?.type === 'medal' ? a.metadata.ram : 0
58+
const bRam = b?.metadata?.type === 'pyro' || b?.metadata?.type === 'medal' ? b.metadata.ram : 0
5659
return aRam - bRam
5760
})
5861
5962
function handleError(err: any) {
60-
console.error('Purchase modal error:', err)
63+
debug('Purchase modal error:', err)
6164
}
6265
6366
const { data: customerData } = useQuery({
@@ -176,6 +179,7 @@ const currentInterval = computed<'monthly' | 'quarterly'>(() => {
176179
if (interval === 'monthly' || interval === 'quarterly') {
177180
return interval
178181
}
182+
179183
return 'monthly'
180184
})
181185
@@ -196,6 +200,11 @@ const editSubscriptionMutation = useMutation({
196200
async function initiatePayment(
197201
body: Labrinth.Billing.Internal.InitiatePaymentRequest,
198202
): Promise<Labrinth.Billing.Internal.EditSubscriptionResponse | null> {
203+
debug('initiatePayment called', {
204+
hasSubscription: !!subscription.value,
205+
subscriptionId: subscription.value?.id,
206+
body,
207+
})
199208
if (subscription.value) {
200209
const transformedBody: Labrinth.Billing.Internal.EditSubscriptionRequest = {
201210
interval: body.charge.type === 'new' ? body.charge.interval : undefined,
@@ -227,10 +236,13 @@ async function initiatePayment(
227236
return await finalizeImmediate(transformedBody)
228237
}
229238
} catch (e) {
230-
console.error('Dry run failed, attempting immediate patch', e)
239+
debug('Dry run failed, attempting immediate patch', e)
231240
return await finalizeImmediate(transformedBody)
232241
}
233242
} else {
243+
debug('subscription.value is null/undefined', {
244+
subscriptionValue: subscription.value,
245+
})
234246
addNotification({
235247
title: 'Unable to determine subscription ID.',
236248
text: 'Please contact support.',
@@ -275,15 +287,34 @@ async function finalizeDowngrade() {
275287
}
276288
277289
async function open(id?: string) {
290+
debug('open called', { id })
278291
if (id) {
279292
const subscriptions = await labrinth.billing_internal.getSubscriptions()
293+
debug('fetched subscriptions', {
294+
count: subscriptions.length,
295+
subscriptions: subscriptions.map((s) => ({
296+
id: s.id,
297+
metadataType: s.metadata?.type,
298+
metadataId: s.metadata?.id,
299+
})),
300+
})
280301
for (const sub of subscriptions) {
281-
if (sub?.metadata?.type === 'pyro' && sub.metadata.id === id) {
302+
if (
303+
(sub?.metadata?.type === 'pyro' || sub?.metadata?.type === 'medal') &&
304+
sub.metadata.id === id
305+
) {
282306
subscription.value = sub
307+
debug('found matching subscription', {
308+
subscriptionId: sub.id,
309+
})
283310
break
284311
}
285312
}
313+
if (!subscription.value) {
314+
debug('no matching subscription found for id', id)
315+
}
286316
} else {
317+
debug('no id provided, resetting subscription')
287318
subscription.value = null
288319
}
289320

0 commit comments

Comments
 (0)