From 2712e380b8f5af0930abbdf9347a1dee3eb75f8a Mon Sep 17 00:00:00 2001 From: Maxime Beauchamp <15185355+baktun14@users.noreply.github.com> Date: Sat, 23 Nov 2024 16:15:33 -0500 Subject: [PATCH] feat(provider): new provider trial endpoint (#488) --- .../trial-validation.service.ts | 4 +--- .../src/deployment/config/config.provider.ts | 2 +- .../src/deployment/config/provider.config.ts | 2 ++ .../provider/provider.controller.ts | 12 +++++++++++ .../provider/provider.repository.ts | 21 +++++++++++++++++++ .../trial-providers.service.ts | 12 +++++++++++ apps/api/src/routes/v1/trialProviders.ts | 9 ++++---- .../src/services/external/githubService.ts | 14 ------------- .../components/new-deployment/CreateLease.tsx | 4 ++-- .../components/sdl/SimpleSdlBuilderForm.tsx | 2 +- .../src/components/templates/UserTemplate.tsx | 2 +- .../CustomChainProvider.tsx | 8 +++---- .../src/queries/useAnonymousUserQuery.ts | 2 +- apps/deploy-web/src/queries/useBidQuery.ts | 4 ++-- .../src/utils/deploymentData/v1beta3.ts | 5 +++-- config/trial-providers.json | 16 -------------- packages/ui/components/custom/file-button.tsx | 3 ++- 17 files changed, 70 insertions(+), 52 deletions(-) create mode 100644 apps/api/src/deployment/config/provider.config.ts create mode 100644 apps/api/src/deployment/controllers/provider/provider.controller.ts create mode 100644 apps/api/src/deployment/repositories/provider/provider.repository.ts create mode 100644 apps/api/src/deployment/services/trial-providers/trial-providers.service.ts delete mode 100644 config/trial-providers.json diff --git a/apps/api/src/billing/services/trial-validation/trial-validation.service.ts b/apps/api/src/billing/services/trial-validation/trial-validation.service.ts index 99f6d791d..0330ec043 100644 --- a/apps/api/src/billing/services/trial-validation/trial-validation.service.ts +++ b/apps/api/src/billing/services/trial-validation/trial-validation.service.ts @@ -3,9 +3,7 @@ import { EncodeObject } from "@cosmjs/proto-signing"; import { singleton } from "tsyringe"; import { UserWalletOutput } from "@src/billing/repositories"; - -const TRIAL_ATTRIBUTE = "console/trials"; -const AUDITOR = "akash1365yvmc4s7awdyj3n2sav7xfx76adc6dnmlx63"; +import { AUDITOR, TRIAL_ATTRIBUTE } from "@src/deployment/config/provider.config"; @singleton() export class TrialValidationService { diff --git a/apps/api/src/deployment/config/config.provider.ts b/apps/api/src/deployment/config/config.provider.ts index 96689da90..a25bc68ea 100644 --- a/apps/api/src/deployment/config/config.provider.ts +++ b/apps/api/src/deployment/config/config.provider.ts @@ -8,4 +8,4 @@ container.register(DEPLOYMENT_CONFIG, { useValue: config }); export type DeploymentConfig = typeof config; -export const InjectDeploymentConfig = () => inject(DEPLOYMENT_CONFIG); +export const InjectDeploymentConfig = () => inject(DEPLOYMENT_CONFIG); \ No newline at end of file diff --git a/apps/api/src/deployment/config/provider.config.ts b/apps/api/src/deployment/config/provider.config.ts new file mode 100644 index 000000000..244bf6e11 --- /dev/null +++ b/apps/api/src/deployment/config/provider.config.ts @@ -0,0 +1,2 @@ +export const TRIAL_ATTRIBUTE = "console/trials"; +export const AUDITOR = "akash1365yvmc4s7awdyj3n2sav7xfx76adc6dnmlx63"; diff --git a/apps/api/src/deployment/controllers/provider/provider.controller.ts b/apps/api/src/deployment/controllers/provider/provider.controller.ts new file mode 100644 index 000000000..d2c6261d8 --- /dev/null +++ b/apps/api/src/deployment/controllers/provider/provider.controller.ts @@ -0,0 +1,12 @@ +import { singleton } from "tsyringe"; + +import { TrialProvidersService } from "@src/deployment/services/trial-providers/trial-providers.service"; + +@singleton() +export class ProviderController { + constructor(private readonly trialProvidersService: TrialProvidersService) {} + + async getTrialProviders(): Promise { + return await this.trialProvidersService.getTrialProviders(); + } +} diff --git a/apps/api/src/deployment/repositories/provider/provider.repository.ts b/apps/api/src/deployment/repositories/provider/provider.repository.ts new file mode 100644 index 000000000..3fa9c18b9 --- /dev/null +++ b/apps/api/src/deployment/repositories/provider/provider.repository.ts @@ -0,0 +1,21 @@ +import { ProviderAttributeSignature } from "@akashnetwork/database/dbSchemas/akash"; +import { singleton } from "tsyringe"; + +import { AUDITOR, TRIAL_ATTRIBUTE } from "@src/deployment/config/provider.config"; + +@singleton() +export class ProviderRepository { + async getTrialProviders(): Promise { + const trialProviders = await ProviderAttributeSignature.findAll({ + attributes: ["provider"], + where: { + auditor: AUDITOR, + key: TRIAL_ATTRIBUTE, + value: "true" + }, + raw: true + }); + + return trialProviders.map(provider => provider.provider); + } +} diff --git a/apps/api/src/deployment/services/trial-providers/trial-providers.service.ts b/apps/api/src/deployment/services/trial-providers/trial-providers.service.ts new file mode 100644 index 000000000..7f44510c8 --- /dev/null +++ b/apps/api/src/deployment/services/trial-providers/trial-providers.service.ts @@ -0,0 +1,12 @@ +import { singleton } from "tsyringe"; + +import { ProviderRepository } from "@src/deployment/repositories/provider/provider.repository"; + +@singleton() +export class TrialProvidersService { + constructor(private readonly providerRepository: ProviderRepository) {} + + async getTrialProviders(): Promise { + return await this.providerRepository.getTrialProviders(); + } +} diff --git a/apps/api/src/routes/v1/trialProviders.ts b/apps/api/src/routes/v1/trialProviders.ts index e786757be..2f5f2650f 100644 --- a/apps/api/src/routes/v1/trialProviders.ts +++ b/apps/api/src/routes/v1/trialProviders.ts @@ -1,6 +1,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi"; +import { container } from "tsyringe"; -import { getTrialProviders } from "@src/services/external/githubService"; +import { ProviderController } from "@src/deployment/controllers/provider/provider.controller"; const route = createRoute({ method: "get", @@ -20,6 +21,6 @@ const route = createRoute({ }); export default new OpenAPIHono().openapi(route, async c => { - const response = await getTrialProviders(); - return c.json(response); -}); + const response = await container.resolve(ProviderController).getTrialProviders(); + return c.json(response, 200); +}); \ No newline at end of file diff --git a/apps/api/src/services/external/githubService.ts b/apps/api/src/services/external/githubService.ts index 3aee4018d..19728232e 100644 --- a/apps/api/src/services/external/githubService.ts +++ b/apps/api/src/services/external/githubService.ts @@ -45,17 +45,3 @@ export async function getAuditors() { return response; } - -export async function getTrialProviders() { - const response = await cacheResponse( - minutesToSeconds(5), - cacheKeys.getTrialProviders, - async () => { - const res = await axios.get("https://raw.githubusercontent.com/akash-network/console/main/config/trial-providers.json"); - return res.data; - }, - true - ); - - return response; -} diff --git a/apps/deploy-web/src/components/new-deployment/CreateLease.tsx b/apps/deploy-web/src/components/new-deployment/CreateLease.tsx index 73b7aa223..17aa23b72 100644 --- a/apps/deploy-web/src/components/new-deployment/CreateLease.tsx +++ b/apps/deploy-web/src/components/new-deployment/CreateLease.tsx @@ -14,14 +14,14 @@ import { Snackbar, Spinner } from "@akashnetwork/ui/components"; +import { useTheme as useMuiTheme } from "@mui/material/styles"; +import useMediaQuery from "@mui/material/useMediaQuery"; import { ArrowRight, BadgeCheck, Bin, InfoCircle, MoreHoriz, Xmark } from "iconoir-react"; import yaml from "js-yaml"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { event } from "nextjs-google-analytics"; -import { useTheme as useMuiTheme } from "@mui/material/styles"; import { useSnackbar } from "notistack"; -import useMediaQuery from "@mui/material/useMediaQuery"; import { LocalCert } from "@src/context/CertificateProvider/CertificateProviderContext"; import { useWallet } from "@src/context/WalletProvider"; diff --git a/apps/deploy-web/src/components/sdl/SimpleSdlBuilderForm.tsx b/apps/deploy-web/src/components/sdl/SimpleSdlBuilderForm.tsx index 2d9bc13fe..d3f5bfbf4 100644 --- a/apps/deploy-web/src/components/sdl/SimpleSdlBuilderForm.tsx +++ b/apps/deploy-web/src/components/sdl/SimpleSdlBuilderForm.tsx @@ -13,6 +13,7 @@ import { event } from "nextjs-google-analytics"; import { useSnackbar } from "notistack"; import { SimpleServiceFormControl } from "@src/components/sdl/SimpleServiceFormControl"; +import { USER_TEMPLATE_CODE } from "@src/config/deploy.config"; import useFormPersist from "@src/hooks/useFormPersist"; import { useGpuModels } from "@src/queries/useGpuQuery"; import sdlStore from "@src/store/sdlStore"; @@ -27,7 +28,6 @@ import { UrlService } from "@src/utils/urlUtils"; import { ImportSdlModal } from "./ImportSdlModal"; import { PreviewSdl } from "./PreviewSdl"; import { SaveTemplateModal } from "./SaveTemplateModal"; -import { USER_TEMPLATE_CODE } from "@src/config/deploy.config"; const DEFAULT_SERVICES = { services: [{ ...defaultService }] diff --git a/apps/deploy-web/src/components/templates/UserTemplate.tsx b/apps/deploy-web/src/components/templates/UserTemplate.tsx index d2629fecb..40b3f166f 100644 --- a/apps/deploy-web/src/components/templates/UserTemplate.tsx +++ b/apps/deploy-web/src/components/templates/UserTemplate.tsx @@ -12,6 +12,7 @@ import { EditDescriptionForm } from "@src/components/sdl/EditDescriptionForm"; import { LeaseSpecDetail } from "@src/components/shared/LeaseSpecDetail"; import { Title } from "@src/components/shared/Title"; import { UserFavoriteButton } from "@src/components/shared/UserFavoriteButton"; +import { USER_TEMPLATE_CODE } from "@src/config/deploy.config"; import { useCustomUser } from "@src/hooks/useCustomUser"; import { getShortText } from "@src/hooks/useShortText"; import { useDeleteTemplate } from "@src/queries/useTemplateQuery"; @@ -24,7 +25,6 @@ import { bytesToShrink } from "@src/utils/unitUtils"; import { domainName, UrlService } from "@src/utils/urlUtils"; import Layout from "../layout/Layout"; import { CustomNextSeo } from "../shared/CustomNextSeo"; -import { USER_TEMPLATE_CODE } from "@src/config/deploy.config"; type Props = { id: string; diff --git a/apps/deploy-web/src/context/CustomChainProvider/CustomChainProvider.tsx b/apps/deploy-web/src/context/CustomChainProvider/CustomChainProvider.tsx index 2bfe1c43b..a4db0d5da 100644 --- a/apps/deploy-web/src/context/CustomChainProvider/CustomChainProvider.tsx +++ b/apps/deploy-web/src/context/CustomChainProvider/CustomChainProvider.tsx @@ -2,21 +2,21 @@ import "@interchain-ui/react/styles"; import "@interchain-ui/react/globalStyles"; +import { useEffect } from "react"; import { GasPrice } from "@cosmjs/stargate"; +import { WalletModalProps } from "@cosmos-kit/core"; import { wallets as metamask } from "@cosmos-kit/cosmos-extension-metamask"; import { wallets as cosmostation } from "@cosmos-kit/cosmostation-extension"; import { wallets as keplr } from "@cosmos-kit/keplr"; import { wallets as leap } from "@cosmos-kit/leap"; import { ChainProvider, DefaultModal } from "@cosmos-kit/react"; import { useChain } from "@cosmos-kit/react"; +import { useAtom } from "jotai"; import { akash, akashSandbox, akashTestnet, assetLists } from "@src/chains"; import networkStore from "@src/store/networkStore"; -import { customRegistry } from "@src/utils/customRegistry"; -import { WalletModalProps } from "@cosmos-kit/core"; -import { useAtom } from "jotai"; import walletStore from "@src/store/walletStore"; -import { useEffect } from "react"; +import { customRegistry } from "@src/utils/customRegistry"; type Props = { children: React.ReactNode; diff --git a/apps/deploy-web/src/queries/useAnonymousUserQuery.ts b/apps/deploy-web/src/queries/useAnonymousUserQuery.ts index a50c08ffd..002d13596 100644 --- a/apps/deploy-web/src/queries/useAnonymousUserQuery.ts +++ b/apps/deploy-web/src/queries/useAnonymousUserQuery.ts @@ -1,8 +1,8 @@ import { useState } from "react"; +import * as Sentry from "@sentry/nextjs"; import { useWhen } from "@src/hooks/useWhen"; import { userHttpService } from "@src/services/http/http.service"; -import * as Sentry from "@sentry/nextjs"; export interface UserOutput { id: string; diff --git a/apps/deploy-web/src/queries/useBidQuery.ts b/apps/deploy-web/src/queries/useBidQuery.ts index 1508b997d..05cd115dd 100644 --- a/apps/deploy-web/src/queries/useBidQuery.ts +++ b/apps/deploy-web/src/queries/useBidQuery.ts @@ -10,8 +10,8 @@ import { QueryKeys } from "./queryKeys"; async function getBidList(apiEndpoint: string, address: string, dseq: string): Promise | null> { if (!address || !dseq) return null; - const response = await axios.get(ApiUrlService.bidList(apiEndpoint, address, dseq)); - let bids = response.data.bids as RpcBid[]; + const response = await axios.get<{ bids: RpcBid[] }>(ApiUrlService.bidList(apiEndpoint, address, dseq)); + const { bids } = response.data; return bids.map((b: RpcBid) => ({ id: b.bid.bid_id.provider + b.bid.bid_id.dseq + b.bid.bid_id.gseq + b.bid.bid_id.oseq, diff --git a/apps/deploy-web/src/utils/deploymentData/v1beta3.ts b/apps/deploy-web/src/utils/deploymentData/v1beta3.ts index c34d0b0c8..24cef1583 100644 --- a/apps/deploy-web/src/utils/deploymentData/v1beta3.ts +++ b/apps/deploy-web/src/utils/deploymentData/v1beta3.ts @@ -1,9 +1,10 @@ +import { Attribute } from "@akashnetwork/akash-api/akash/base/v1beta3"; +import yaml from "js-yaml"; + import { browserEnvConfig } from "@src/config/browser-env.config"; import networkStore from "@src/store/networkStore"; import type { DepositParams } from "@src/types/deployment"; import { CustomValidationError, getCurrentHeight, getSdl, Manifest, ManifestVersion } from "./helpers"; -import yaml from "js-yaml"; -import { Attribute } from "@akashnetwork/akash-api/akash/base/v1beta3"; export const ENDPOINT_NAME_VALIDATION_REGEX = /^[a-z]+[-_\da-z]+$/; const TRIAL_ATTRIBUTE = "console/trials"; diff --git a/config/trial-providers.json b/config/trial-providers.json deleted file mode 100644 index b49d0ce59..000000000 --- a/config/trial-providers.json +++ /dev/null @@ -1,16 +0,0 @@ -[ - "akash1g7az2pus6atgeufgttlcnl0wzlzwd0lrsy6d7s", - "akash1tfuvntkwt3cpxnhukdnsvvsumjnrvmvh244l3w", - "akash18mcffkg5jp9eqc36evlv67uqcj04fvk324ap54", - "akash1t0sk5nhc8n3xply5ft60x9det0s7jwplzzycnv", - "akash1cnzkdynwd4u6j7s8z5j0fg76h3g6yhsggmuqta", - "akash1wrrgd4jl75jjsnkea4eh3kxy0lhpsv8xysd67t", - "akash15tl6v6gd0nte0syyxnv57zmmspgju4c3xfmdhk", - "akash1rfqs6aajq2d4azhjj88wav2d6ra6vvuzn58dt5", - "akash16aflfteeg8c2j63sy0rlxj57pty98zzm5mvgfa", - "akash18ga02jzaq8cw52anyhzkwta5wygufgu6zsz6xc", - "akash175llqyjvxfle9qwt740vm46772dzaznpzgm576", - "akash18gewxdlc5llzgdr75x3ls4w4cte8hgfzsnr27s", - "akash1tweev0k42guyv3a2jtgphmgfrl2h5y2884vh9d", - "akash17l0f3kf7gv4kmgqjmgc0ksj3em6lqgcc4kl4dg" -] diff --git a/packages/ui/components/custom/file-button.tsx b/packages/ui/components/custom/file-button.tsx index c848ef941..f9afd2c5c 100644 --- a/packages/ui/components/custom/file-button.tsx +++ b/packages/ui/components/custom/file-button.tsx @@ -1,5 +1,6 @@ "use client"; -import React, { useRef, ChangeEvent } from "react"; +import React, { ChangeEvent,useRef } from "react"; + import { Button, ButtonProps } from "../button"; interface FileButtonProps extends Omit {