Skip to content

Commit a3ec1dc

Browse files
committed
fixup
1 parent ca9f82c commit a3ec1dc

5 files changed

Lines changed: 133 additions & 156 deletions

File tree

Synergism.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4238,7 +4238,7 @@ header #obtainiumDisplay { color: pink; }
42384238

42394239
.transcendedBallerGradient {
42404240
--gradient-start: orchid;
4241-
--gradient-end: rgb(167, 65, 167);
4241+
--gradient-end: #a741a7;
42424242
}
42434243

42444244
.reincarnatedBallerGradient {
@@ -5060,7 +5060,7 @@ form input:hover {
50605060
}
50615061

50625062
.subscriptionContainer > div > .pseudoCoinSubImage {
5063-
margin: 12px auto 4px auto;
5063+
margin: 12px auto 4px;
50645064
}
50655065

50665066
#pseudoCoins > #productContainer > section > * > .pseudoCoinImage {

src/Login.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import { updatePrestigeCount, updateReincarnationCount, updateTranscensionCount
1414
import { format, player, saveSynergy } from './Synergism'
1515
import { Alert, Notification } from './UpdateHTML'
1616
import { assert, btoa, isomorphicDecode } from './Utility'
17-
import { prod } from './Config'
18-
import { mockSubscription } from './mock/handlers/SubscriptionHandlers'
1917

2018
export type PseudoCoinConsumableNames = 'HAPPY_HOUR_BELL'
2119

@@ -78,7 +76,11 @@ const cloudSaves: Save[] = []
7876
export const isLoggedIn = () => loggedIn
7977
export const getTips = () => tips
8078
export const setTips = (newTips: number) => tips = newTips
81-
export const getSubMetadata = () => prod ? subscription : mockSubscription
79+
export const getSubMetadata = () => subscription
80+
// For testing purposes only
81+
export const setSubMetadata = (newSub: SubscriptionMetadata) => {
82+
subscription = newSub
83+
}
8284

8385
export const allDurableConsumables: Record<PseudoCoinConsumableNames, Consumable> = {
8486
HAPPY_HOUR_BELL: {
@@ -206,11 +208,10 @@ interface BonusTypes {
206208
}
207209

208210
export type SubscriptionProvider = 'paypal' | 'stripe' | 'patreon'
209-
export type SubscriptionTier = 1 | 2 | 3 | 4
210211

211212
export type SubscriptionMetadata = {
212213
provider: SubscriptionProvider
213-
tier: SubscriptionTier
214+
tier: number
214215
} | null
215216

216217
interface SynergismUserAPIResponse<T extends keyof AccountMetadata> {

src/mock/browser.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { setupWorker } from 'msw/browser'
33
import { cloudSaveHandlers } from './handlers/CloudSaveHandlers'
44
import { messageHandlers } from './handlers/MessageHandlers'
55
import { paymentHandlers } from './handlers/PaymentHandlers'
6-
import { consumeHandlers } from './websocket'
76
import { subscriptionHandlers } from './handlers/SubscriptionHandlers'
7+
import { consumeHandlers } from './websocket'
88

99
const GETHandlers = [
1010
http.get('https://synergism.cc/api/v1/quark-bonus', () => {
@@ -1210,7 +1210,10 @@ export const worker = setupWorker(
12101210
bonus: {
12111211
quarkBonus: 5
12121212
},
1213-
subscription: null,
1213+
subscription: {
1214+
provider: 'paypal',
1215+
tier: 3
1216+
}
12141217
})
12151218
}),
12161219
...GETHandlers,
Lines changed: 58 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,78 @@
1-
import { http, HttpHandler, HttpResponse } from 'msw'
1+
import { http, type HttpHandler, HttpResponse } from 'msw'
2+
import { getSubMetadata, setSubMetadata } from '../../Login'
23
import { subscriptionProducts } from '../../purchases/CartTab'
3-
import { updateSubscriptionPage } from '../../purchases/SubscriptionsSubtab'
44

5-
interface Subscription {
6-
provider: 'stripe' | 'patreon' | 'paypal'
7-
tier: 1 | 2 | 3 | 4
8-
}
9-
10-
export let mockSubscription: Subscription | null = null
11-
12-
function getSubscriptionTier(productId: string): number | null {
5+
function getSubscriptionTier (productId: string): number | null {
136
const product = subscriptionProducts.find((p) => p.id === productId)
147
return product?.tier ?? null
158
}
169

1710
export const subscriptionHandlers: HttpHandler[] = [
1811
http.post('https://synergism.cc/paypal/subscriptions/create', async ({ request }) => {
19-
try {
20-
const url = new URL(request.url)
21-
const productId = url.searchParams.get('product')
22-
if (!productId) {
23-
return HttpResponse.json({ error: 'Product ID is required' }, { status: 400 })
24-
}
25-
const tier = getSubscriptionTier(productId)
26-
if (tier === null) {
27-
return HttpResponse.json({ error: 'Invalid product ID' }, { status: 400 })
28-
}
29-
if (mockSubscription !== null) {
30-
return HttpResponse.json({ error: 'User already has an active subscription' }, { status: 409 })
31-
}
32-
33-
mockSubscription = {
34-
provider: 'paypal',
35-
tier: tier as 1 | 2 | 3 | 4
36-
}
37-
38-
// TODO: This should really be done somewhere in the frontend
39-
updateSubscriptionPage()
40-
return HttpResponse.json({}, { status: 204 })
41-
} catch (error) {
42-
console.error('Error creating subscription:', error)
43-
return HttpResponse.json({ error: 'Failed to create subscription' }, { status: 500 })
12+
const url = new URL(request.url)
13+
const productId = url.searchParams.get('product')
14+
if (!productId) {
15+
return HttpResponse.json({ error: 'Product ID is required' }, { status: 400 })
4416
}
17+
const tier = getSubscriptionTier(productId)
18+
if (tier === null) {
19+
return HttpResponse.json({ error: 'Invalid product ID' }, { status: 400 })
20+
}
21+
22+
const currentSub = getSubMetadata()
23+
24+
if (currentSub !== null) {
25+
return HttpResponse.json({ error: 'User already has an active subscription' }, { status: 409 })
26+
}
27+
28+
setSubMetadata({
29+
provider: 'paypal',
30+
tier
31+
})
32+
33+
return HttpResponse.json({ id: 'paypal-id' })
4534
}),
4635

4736
// Revise subscription
4837
http.post('https://synergism.cc/paypal/subscriptions/revise', async ({ request }) => {
49-
try {
50-
// Extract product ID from URL query parameter (?product=...)
51-
const url = new URL(request.url)
52-
const productId = url.searchParams.get('key')
53-
54-
if (!productId) {
55-
return HttpResponse.json({ error: 'Product ID is required' }, { status: 400 })
56-
}
57-
58-
const newTier = getSubscriptionTier(productId)
59-
if (newTier === null) {
60-
return HttpResponse.json({ error: 'Invalid product ID or tier' }, { status: 400 })
61-
}
62-
63-
if (mockSubscription === null) {
64-
return HttpResponse.json({ error: 'No active subscription found' }, { status: 404 })
65-
}
66-
67-
mockSubscription = {
68-
provider: 'paypal',
69-
tier: newTier as 1 | 2 | 3 | 4,
70-
}
71-
72-
return HttpResponse.json({ success: true, mockSubscription }, { status: 204 })
73-
} catch (error) {
74-
console.error('Error revising subscription:', error)
75-
return HttpResponse.json({ error: 'Failed to revise subscription' }, { status: 500 })
38+
// Extract product ID from URL query parameter (?product=...)
39+
const url = new URL(request.url)
40+
const productId = url.searchParams.get('product')
41+
42+
if (!productId) {
43+
return HttpResponse.json({ error: 'Product ID is required' }, { status: 400 })
7644
}
77-
}),
7845

79-
http.post('https://synergism.cc/paypal/subscriptions/cancel', async () => {
80-
try {
81-
if (mockSubscription === null) {
82-
return HttpResponse.json({ error: 'No active subscription found' }, { status: 404 })
83-
}
46+
const newTier = getSubscriptionTier(productId)
47+
if (newTier === null) {
48+
return HttpResponse.json({ error: 'Invalid product ID or tier' }, { status: 400 })
49+
}
8450

85-
mockSubscription = null
51+
const currentSub = getSubMetadata()
8652

87-
return HttpResponse.json({}, { status: 204 })
88-
} catch (error) {
89-
console.error('Error cancelling subscription:', error)
90-
return HttpResponse.json({ error: 'Failed to cancel subscription' }, { status: 500 })
53+
if (currentSub === null) {
54+
return HttpResponse.json({ error: 'No active subscription found' }, { status: 404 })
9155
}
56+
57+
setSubMetadata({
58+
provider: 'paypal',
59+
tier: newTier
60+
})
61+
62+
return HttpResponse.json({
63+
link: 'https://paypal.com/link/for/user/to/approve/change'
64+
})
9265
}),
66+
67+
http.post('https://synergism.cc/paypal/subscriptions/cancel', async () => {
68+
const currentSub = getSubMetadata()
69+
70+
if (currentSub === null) {
71+
return HttpResponse.json({ error: 'No active subscription found' }, { status: 404 })
72+
}
73+
74+
setSubMetadata(null)
75+
76+
return new HttpResponse(null, { status: 204 })
77+
})
9378
]

0 commit comments

Comments
 (0)