You've already forked AstralRinth
* Provide more specific payout method names on frontend Been getting a lot of confused tickets recently of people withdrawing to PayPal but then not recognizing what "Tremendous" means. This should clarify things. * feat: improve icons + names for withdrawals * Update apps/frontend/src/components/ui/dashboard/RevenueTransaction.vue Co-authored-by: Emma Alexia <emma@modrinth.com> Signed-off-by: Calum H. <hendersoncal117@gmail.com> * fix: icons * fix: object cover * feat: icons for crypto + bank * fix: remove empty null * fix: qa --------- Signed-off-by: Calum H. <hendersoncal117@gmail.com> Co-authored-by: Calum H. <contact@cal.engineer>
153 lines
4.2 KiB
TypeScript
153 lines
4.2 KiB
TypeScript
import { AbstractModule } from '../../../core/abstract-module'
|
|
import type { Labrinth } from '../types'
|
|
|
|
export class LabrinthStateModule extends AbstractModule {
|
|
public getModuleID(): string {
|
|
return 'labrinth_state'
|
|
}
|
|
|
|
/**
|
|
* Build the complete generated state by fetching from multiple endpoints
|
|
*
|
|
* @returns Promise resolving to the generated state containing categories, loaders, products, etc.
|
|
*
|
|
* @example
|
|
* ```typescript
|
|
* const state = await client.labrinth.state.build()
|
|
* console.log(state.products) // Available billing products
|
|
* ```
|
|
*/
|
|
public async build(): Promise<Labrinth.State.GeneratedState> {
|
|
const errors: unknown[] = []
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
const handleError = (err: any, defaultValue: any) => {
|
|
console.error('Error fetching state data:', err)
|
|
errors.push(err)
|
|
return defaultValue
|
|
}
|
|
|
|
// TODO: as we add new modules, move these raw requests to actual
|
|
// abstractions
|
|
const [
|
|
categories,
|
|
loaders,
|
|
gameVersions,
|
|
donationPlatforms,
|
|
reportTypes,
|
|
homePageProjects,
|
|
homePageSearch,
|
|
homePageNotifs,
|
|
products,
|
|
muralBankDetails,
|
|
iso3166Data,
|
|
payoutMethods,
|
|
] = await Promise.all([
|
|
// Tag endpoints
|
|
this.client
|
|
.request<Labrinth.Tags.v2.Category[]>('/tag/category', {
|
|
api: 'labrinth',
|
|
version: 2,
|
|
method: 'GET',
|
|
})
|
|
.catch((err) => handleError(err, [])),
|
|
this.client
|
|
.request<Labrinth.Tags.v2.Loader[]>('/tag/loader', {
|
|
api: 'labrinth',
|
|
version: 2,
|
|
method: 'GET',
|
|
})
|
|
.catch((err) => handleError(err, [])),
|
|
this.client
|
|
.request<Labrinth.Tags.v2.GameVersion[]>('/tag/game_version', {
|
|
api: 'labrinth',
|
|
version: 2,
|
|
method: 'GET',
|
|
})
|
|
.catch((err) => handleError(err, [])),
|
|
this.client
|
|
.request<Labrinth.Tags.v2.DonationPlatform[]>('/tag/donation_platform', {
|
|
api: 'labrinth',
|
|
version: 2,
|
|
method: 'GET',
|
|
})
|
|
.catch((err) => handleError(err, [])),
|
|
this.client
|
|
.request<string[]>('/tag/report_type', { api: 'labrinth', version: 2, method: 'GET' })
|
|
.catch((err) => handleError(err, [])),
|
|
|
|
// Homepage data
|
|
this.client
|
|
.request<Labrinth.Projects.v2.Project[]>('/projects_random', {
|
|
api: 'labrinth',
|
|
version: 2,
|
|
method: 'GET',
|
|
params: { count: '60' },
|
|
})
|
|
.catch((err) => handleError(err, [])),
|
|
this.client
|
|
.request<Labrinth.Search.v2.SearchResults>('/search', {
|
|
api: 'labrinth',
|
|
version: 2,
|
|
method: 'GET',
|
|
params: { limit: '3', query: 'leave', index: 'relevance' },
|
|
})
|
|
.catch((err) => handleError(err, {} as Labrinth.Search.v2.SearchResults)),
|
|
this.client
|
|
.request<Labrinth.Search.v2.SearchResults>('/search', {
|
|
api: 'labrinth',
|
|
version: 2,
|
|
method: 'GET',
|
|
params: { limit: '3', query: '', index: 'updated' },
|
|
})
|
|
.catch((err) => handleError(err, {} as Labrinth.Search.v2.SearchResults)),
|
|
|
|
// Internal billing/mural endpoints
|
|
this.client.labrinth.billing_internal.getProducts().catch((err) => handleError(err, [])),
|
|
this.client
|
|
.request<{ bankDetails: Record<string, { bankNames: string[] }> }>('/mural/bank-details', {
|
|
api: 'labrinth',
|
|
version: 'internal',
|
|
method: 'GET',
|
|
})
|
|
.catch((err) => handleError(err, null)),
|
|
|
|
// ISO3166 country and subdivision data
|
|
this.client.iso3166.data
|
|
.build()
|
|
.catch((err) => handleError(err, { countries: [], subdivisions: {} })),
|
|
|
|
// Payout methods for tremendous ID mapping
|
|
this.client
|
|
.request<Labrinth.State.PayoutMethodInfo[]>('/payout/methods', {
|
|
api: 'labrinth',
|
|
version: 3,
|
|
method: 'GET',
|
|
})
|
|
.catch((err) => handleError(err, [])),
|
|
])
|
|
|
|
const tremendousIdMap = Object.fromEntries(
|
|
(payoutMethods as Labrinth.State.PayoutMethodInfo[])
|
|
.filter((m) => m.type === 'tremendous')
|
|
.map((m) => [m.id, { name: m.name, image_url: m.image_logo_url }]),
|
|
)
|
|
|
|
return {
|
|
categories,
|
|
loaders,
|
|
gameVersions,
|
|
donationPlatforms,
|
|
reportTypes,
|
|
homePageProjects,
|
|
homePageSearch,
|
|
homePageNotifs,
|
|
products,
|
|
muralBankDetails: muralBankDetails?.bankDetails,
|
|
tremendousIdMap,
|
|
countries: iso3166Data.countries,
|
|
subdivisions: iso3166Data.subdivisions,
|
|
errors,
|
|
}
|
|
}
|
|
}
|