Skip to content

Commit

Permalink
feat(provider): new provider trial endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
baktun14 authored Nov 23, 2024
1 parent aff5663 commit 2712e38
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/deployment/config/config.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 2 additions & 0 deletions apps/api/src/deployment/config/provider.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const TRIAL_ATTRIBUTE = "console/trials";
export const AUDITOR = "akash1365yvmc4s7awdyj3n2sav7xfx76adc6dnmlx63";
Original file line number Diff line number Diff line change
@@ -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<string[]> {
return await this.trialProvidersService.getTrialProviders();
}
}
Original file line number Diff line number Diff line change
@@ -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<string[]> {
const trialProviders = await ProviderAttributeSignature.findAll({
attributes: ["provider"],
where: {
auditor: AUDITOR,
key: TRIAL_ATTRIBUTE,
value: "true"
},
raw: true
});

return trialProviders.map(provider => provider.provider);
}
}
Original file line number Diff line number Diff line change
@@ -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<string[]> {
return await this.providerRepository.getTrialProviders();
}
}
9 changes: 5 additions & 4 deletions apps/api/src/routes/v1/trialProviders.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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);
});
14 changes: 0 additions & 14 deletions apps/api/src/services/external/githubService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]>("https://raw.githubusercontent.com/akash-network/console/main/config/trial-providers.json");
return res.data;
},
true
);

return response;
}
4 changes: 2 additions & 2 deletions apps/deploy-web/src/components/new-deployment/CreateLease.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 }]
Expand Down
2 changes: 1 addition & 1 deletion apps/deploy-web/src/components/templates/UserTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion apps/deploy-web/src/queries/useAnonymousUserQuery.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions apps/deploy-web/src/queries/useBidQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { QueryKeys } from "./queryKeys";
async function getBidList(apiEndpoint: string, address: string, dseq: string): Promise<Array<BidDto> | 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,
Expand Down
5 changes: 3 additions & 2 deletions apps/deploy-web/src/utils/deploymentData/v1beta3.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
16 changes: 0 additions & 16 deletions config/trial-providers.json

This file was deleted.

3 changes: 2 additions & 1 deletion packages/ui/components/custom/file-button.tsx
Original file line number Diff line number Diff line change
@@ -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<ButtonProps, "onChange"> {
Expand Down

0 comments on commit 2712e38

Please sign in to comment.