Skip to content

Commit

Permalink
Improve vending
Browse files Browse the repository at this point in the history
  • Loading branch information
razzeee committed Nov 14, 2024
1 parent cb98c84 commit c2968ad
Show file tree
Hide file tree
Showing 18 changed files with 219 additions and 37 deletions.
27 changes: 20 additions & 7 deletions backend/app/vending/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
users so as to not need to pay money for access (e.g. beta testers)
"""

import datetime
from typing import Literal

import gi
Expand Down Expand Up @@ -103,7 +104,7 @@ class VendingConfig(BaseModel):
Global vending environment configuration values
"""

status: str
status: Literal["ok"]
platforms: dict[str, Platform]
fee_fixed_cost: int
fee_cost_percent: int
Expand Down Expand Up @@ -134,11 +135,23 @@ class VendingSplit(BaseModel):
splits: list[tuple[str, int]]


class VendingSetupRequest(BaseModel):
"""
Configuration for a vended application
"""

currency: str
appshare: int
recommended_donation: int
minimum_payment: int


class VendingSetup(BaseModel):
"""
Configuration for a vended application
"""

status: Literal["ok", "no-config"]
currency: str
appshare: int
recommended_donation: int
Expand Down Expand Up @@ -356,7 +369,7 @@ def get_app_vending_setup(

@router.post("app/{app_id}/setup", tags=["vending"])
def post_app_vending_setup(
setup: VendingSetup,
setup: VendingSetupRequest,
app_id: str = Path(
min_length=6,
max_length=255,
Expand Down Expand Up @@ -477,11 +490,11 @@ def post_app_vending_status(

class TokenModel(BaseModel):
id: str
state: str
state: Literal["unredeemed", "redeemed", "cancelled"]
name: str
token: str | None = None
created: str
changed: str
created: datetime.datetime
changed: datetime.datetime


class TokenList(BaseModel):
Expand Down Expand Up @@ -522,8 +535,8 @@ def get_redeemable_tokens(
id=str(token.id),
state=token.state,
name=token.name,
created=str(token.created),
changed=str(token.changed),
created=token.created,
changed=token.changed,
token=token.token,
)
)
Expand Down
16 changes: 13 additions & 3 deletions frontend/pages/apps/manage/[appId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
getInviteStatusInvitesAppIdGet,
UserInfo,
VendingConfig,
useGetAppVendingSetupVendingappAppIdSetupGet,
} from "src/codegen"

const SettingsDisclosure = ({ sectionTitle, children }) => {
Expand Down Expand Up @@ -80,6 +81,11 @@ export default function AppManagementPage({
const { t } = useTranslation()
const user = useUserContext()

const query = useGetAppVendingSetupVendingappAppIdSetupGet(app.id, {
query: { enabled: !!app.id },
axios: { withCredentials: true },
})

const pages = [
{ name: t("developer-portal"), current: false, href: "/developer-portal" },
{
Expand Down Expand Up @@ -135,9 +141,13 @@ export default function AppManagementPage({
vendingConfig={vendingConfig}
/>
</SettingsDisclosure>
<SettingsDisclosure sectionTitle={t("ownership-tokens")}>
<AppVendingControls.OwnershipTokens app={app} />
</SettingsDisclosure>
{query.isSuccess && query.data?.data?.status === "ok" && (
<SettingsDisclosure
sectionTitle={t("ownership-tokens")}
>
<AppVendingControls.OwnershipTokens app={app} />
</SettingsDisclosure>
)}
</>
)}
<SettingsDisclosure
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/codegen/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export * from "./submitReviewModerationRequestsIdReviewPost200"
export * from "./tokenCancellation"
export * from "./tokenList"
export * from "./tokenModel"
export * from "./tokenModelState"
export * from "./tokenModelToken"
export * from "./tokenResponse"
export * from "./tokenResponseIssuedTo"
Expand Down Expand Up @@ -239,10 +240,13 @@ export * from "./vendingApplicationInformation"
export * from "./vendingApplicationInformationKind"
export * from "./vendingConfig"
export * from "./vendingConfigPlatforms"
export * from "./vendingConfigStatus"
export * from "./vendingOnboardingRequest"
export * from "./vendingOutput"
export * from "./vendingRedirect"
export * from "./vendingSetup"
export * from "./vendingSetupRequest"
export * from "./vendingSetupStatus"
export * from "./vendingStatus"
export * from "./verificationMethod"
export * from "./verificationStatus"
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/codegen/model/tokenModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
* Flathub API
* OpenAPI spec version: 0.1.0
*/
import type { TokenModelState } from "./tokenModelState"
import type { TokenModelToken } from "./tokenModelToken"

export interface TokenModel {
changed: string
created: string
id: string
name: string
state: string
state: TokenModelState
token?: TokenModelToken
}
16 changes: 16 additions & 0 deletions frontend/src/codegen/model/tokenModelState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Generated by orval 🍺
* Do not edit manually.
* Flathub API
* OpenAPI spec version: 0.1.0
*/

export type TokenModelState =
(typeof TokenModelState)[keyof typeof TokenModelState]

// eslint-disable-next-line @typescript-eslint/no-redeclare
export const TokenModelState = {
unredeemed: "unredeemed",
redeemed: "redeemed",
cancelled: "cancelled",
} as const
3 changes: 2 additions & 1 deletion frontend/src/codegen/model/vendingConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* OpenAPI spec version: 0.1.0
*/
import type { VendingConfigPlatforms } from "./vendingConfigPlatforms"
import type { VendingConfigStatus } from "./vendingConfigStatus"

/**
* Global vending environment configuration values
Expand All @@ -14,5 +15,5 @@ export interface VendingConfig {
fee_fixed_cost: number
fee_prefer_percent: number
platforms: VendingConfigPlatforms
status: string
status: VendingConfigStatus
}
14 changes: 14 additions & 0 deletions frontend/src/codegen/model/vendingConfigStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Generated by orval 🍺
* Do not edit manually.
* Flathub API
* OpenAPI spec version: 0.1.0
*/

export type VendingConfigStatus =
(typeof VendingConfigStatus)[keyof typeof VendingConfigStatus]

// eslint-disable-next-line @typescript-eslint/no-redeclare
export const VendingConfigStatus = {
ok: "ok",
} as const
2 changes: 2 additions & 0 deletions frontend/src/codegen/model/vendingSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Flathub API
* OpenAPI spec version: 0.1.0
*/
import type { VendingSetupStatus } from "./vendingSetupStatus"

/**
* Configuration for a vended application
Expand All @@ -13,4 +14,5 @@ export interface VendingSetup {
currency: string
minimum_payment: number
recommended_donation: number
status: VendingSetupStatus
}
16 changes: 16 additions & 0 deletions frontend/src/codegen/model/vendingSetupRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Generated by orval 🍺
* Do not edit manually.
* Flathub API
* OpenAPI spec version: 0.1.0
*/

/**
* Configuration for a vended application
*/
export interface VendingSetupRequest {
appshare: number
currency: string
minimum_payment: number
recommended_donation: number
}
15 changes: 15 additions & 0 deletions frontend/src/codegen/model/vendingSetupStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Generated by orval 🍺
* Do not edit manually.
* Flathub API
* OpenAPI spec version: 0.1.0
*/

export type VendingSetupStatus =
(typeof VendingSetupStatus)[keyof typeof VendingSetupStatus]

// eslint-disable-next-line @typescript-eslint/no-redeclare
export const VendingSetupStatus = {
ok: "ok",
"no-config": "no-config",
} as const
24 changes: 17 additions & 7 deletions frontend/src/codegen/vending/vending.msw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const getGetGlobalVendingConfigVendingConfigGetResponseMock = (
]),
},
},
status: faker.word.sample(),
status: faker.helpers.arrayElement(["ok"] as const),
...overrideResponse,
})

Expand All @@ -79,6 +79,7 @@ export const getGetAppVendingSetupVendingappAppIdSetupGetResponseMock = (
currency: faker.word.sample(),
minimum_payment: faker.number.int({ min: undefined, max: undefined }),
recommended_donation: faker.number.int({ min: undefined, max: undefined }),
status: faker.helpers.arrayElement(["ok", "no-config"] as const),
...overrideResponse,
})

Expand All @@ -89,6 +90,7 @@ export const getPostAppVendingSetupVendingappAppIdSetupPostResponseMock = (
currency: faker.word.sample(),
minimum_payment: faker.number.int({ min: undefined, max: undefined }),
recommended_donation: faker.number.int({ min: undefined, max: undefined }),
status: faker.helpers.arrayElement(["ok", "no-config"] as const),
...overrideResponse,
})

Expand All @@ -108,11 +110,15 @@ export const getGetRedeemableTokensVendingappAppIdTokensGetResponseMock = (
{ length: faker.number.int({ min: 1, max: 10 }) },
(_, i) => i + 1,
).map(() => ({
changed: faker.word.sample(),
created: faker.word.sample(),
changed: `${faker.date.past().toISOString().split(".")[0]}Z`,
created: `${faker.date.past().toISOString().split(".")[0]}Z`,
id: faker.word.sample(),
name: faker.word.sample(),
state: faker.word.sample(),
state: faker.helpers.arrayElement([
"unredeemed",
"redeemed",
"cancelled",
] as const),
token: faker.helpers.arrayElement([
faker.helpers.arrayElement([faker.word.sample(), null]),
undefined,
Expand All @@ -128,11 +134,15 @@ export const getCreateTokensVendingappAppIdTokensPostResponseMock =
{ length: faker.number.int({ min: 1, max: 10 }) },
(_, i) => i + 1,
).map(() => ({
changed: faker.word.sample(),
created: faker.word.sample(),
changed: `${faker.date.past().toISOString().split(".")[0]}Z`,
created: `${faker.date.past().toISOString().split(".")[0]}Z`,
id: faker.word.sample(),
name: faker.word.sample(),
state: faker.word.sample(),
state: faker.helpers.arrayElement([
"unredeemed",
"redeemed",
"cancelled",
] as const),
token: faker.helpers.arrayElement([
faker.helpers.arrayElement([faker.word.sample(), null]),
undefined,
Expand Down
17 changes: 9 additions & 8 deletions frontend/src/codegen/vending/vending.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import type {
VendingOutput,
VendingRedirect,
VendingSetup,
VendingSetupRequest,
VendingStatus,
} from ".././model"

Expand Down Expand Up @@ -717,10 +718,10 @@ then you will get an error
*/
export const postAppVendingSetupVendingappAppIdSetupPost = (
appId: string,
vendingSetup: VendingSetup,
vendingSetupRequest: VendingSetupRequest,
options?: AxiosRequestConfig,
): Promise<AxiosResponse<VendingSetup>> => {
return axios.post(`/vendingapp/${appId}/setup`, vendingSetup, options)
return axios.post(`/vendingapp/${appId}/setup`, vendingSetupRequest, options)
}

export const getPostAppVendingSetupVendingappAppIdSetupPostMutationOptions = <
Expand All @@ -730,21 +731,21 @@ export const getPostAppVendingSetupVendingappAppIdSetupPostMutationOptions = <
mutation?: UseMutationOptions<
Awaited<ReturnType<typeof postAppVendingSetupVendingappAppIdSetupPost>>,
TError,
{ appId: string; data: VendingSetup },
{ appId: string; data: VendingSetupRequest },
TContext
>
axios?: AxiosRequestConfig
}): UseMutationOptions<
Awaited<ReturnType<typeof postAppVendingSetupVendingappAppIdSetupPost>>,
TError,
{ appId: string; data: VendingSetup },
{ appId: string; data: VendingSetupRequest },
TContext
> => {
const { mutation: mutationOptions, axios: axiosOptions } = options ?? {}

const mutationFn: MutationFunction<
Awaited<ReturnType<typeof postAppVendingSetupVendingappAppIdSetupPost>>,
{ appId: string; data: VendingSetup }
{ appId: string; data: VendingSetupRequest }
> = (props) => {
const { appId, data } = props ?? {}

Expand All @@ -763,7 +764,7 @@ export type PostAppVendingSetupVendingappAppIdSetupPostMutationResult =
Awaited<ReturnType<typeof postAppVendingSetupVendingappAppIdSetupPost>>
>
export type PostAppVendingSetupVendingappAppIdSetupPostMutationBody =
VendingSetup
VendingSetupRequest
export type PostAppVendingSetupVendingappAppIdSetupPostMutationError =
AxiosError<HTTPValidationError>

Expand All @@ -777,14 +778,14 @@ export const usePostAppVendingSetupVendingappAppIdSetupPost = <
mutation?: UseMutationOptions<
Awaited<ReturnType<typeof postAppVendingSetupVendingappAppIdSetupPost>>,
TError,
{ appId: string; data: VendingSetup },
{ appId: string; data: VendingSetupRequest },
TContext
>
axios?: AxiosRequestConfig
}): UseMutationResult<
Awaited<ReturnType<typeof postAppVendingSetupVendingappAppIdSetupPost>>,
TError,
{ appId: string; data: VendingSetup },
{ appId: string; data: VendingSetupRequest },
TContext
> => {
const mutationOptions =
Expand Down
Loading

0 comments on commit c2968ad

Please sign in to comment.