Skip to content

Commit

Permalink
fix(provider): added types for known props
Browse files Browse the repository at this point in the history
  • Loading branch information
jigar-arc10 committed Dec 10, 2024
1 parent 499722c commit 312aca5
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ const providerPricingSchema = z.object({
type ProviderPricingValues = z.infer<typeof providerPricingSchema>;

export const ProviderPricing: React.FC<ProviderPricingProps> = ({ onComplete, editMode = false, existingPricing, disabled = false, providerDetails }) => {
console.log(existingPricing)
const [providerProcess, setProviderProcess] = useAtom(providerProcessStore.providerProcessAtom);
const { activeControlMachine } = useControlMachine();
const [showSuccess, setShowSuccess] = React.useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import React from "react";
import { useQuery } from "react-query";

import { ProviderDashoard, ProviderDetails } from "@src/types/provider";
import consoleClient from "@src/utils/consoleClient";
import { useWallet } from "../WalletProvider";

type ContextType = {
providerDetails: any;
providerDashboard: any;
providerDetails: ProviderDetails | undefined;
providerDashboard: ProviderDashoard | undefined;
isLoadingProviderDetails: boolean;
isLoadingProviderDashboard: boolean;
};
Expand All @@ -17,19 +18,22 @@ const ProviderContext = React.createContext<ContextType>({} as ContextType);
export const ProviderContextProvider = ({ children }) => {
const { address } = useWallet();

const { data: providerDetails, isLoading: isLoadingProviderDetails } = useQuery(
"providerDetails",
() => consoleClient.get(`/v1/providers/${address}`),
const {
data: providerDetails,
isLoading: isLoadingProviderDetails
} = useQuery<ProviderDetails>(
"providerDetails",
async () => (await consoleClient.get(`/v1/providers/${address}`)).data,
{
refetchOnWindowFocus: false,
retry: 3,
enabled: !!address
}
);

const { data: providerDashboard, isLoading: isLoadingProviderDashboard } = useQuery(
const { data: providerDashboard, isLoading: isLoadingProviderDashboard } = useQuery<ProviderDashoard>(
"providerDashboard",
() => consoleClient.get(`/internal/provider-dashboard/${address}`),
async () => (await consoleClient.get(`/internal/provider-dashboard/${address}`)),
{
refetchOnWindowFocus: false,
retry: 3,
Expand Down
7 changes: 4 additions & 3 deletions apps/provider-console/src/pages/pricing/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { ProviderPricing } from "@src/components/become-provider/ProviderPricing
import { Layout } from "@src/components/layout/Layout";
import { useControlMachine } from "@src/context/ControlMachineProvider";
import { useProvider } from "@src/context/ProviderContext";
import { ProviderPricingType } from "@src/types/provider";
import restClient from "@src/utils/restClient";
import { convertFromPricingAPI, sanitizeMachineAccess } from "@src/utils/sanityUtils";

const Pricing: React.FunctionComponent = () => {
const { activeControlMachine, controlMachineLoading } = useControlMachine();
const [existingPricing, setExistingPricing] = useState<any>(null);
const [existingPricing, setExistingPricing] = useState<ProviderPricingType | undefined>(undefined);
const [isLoading, setIsLoading] = useState(false);
const { providerDetails } = useProvider();

Expand Down Expand Up @@ -48,8 +49,8 @@ const Pricing: React.FunctionComponent = () => {
</div>
</div>
)}
<div className={isLoading ? 'pointer-events-none' : ''}>

<div className={isLoading ? "pointer-events-none" : ""}>
{!activeControlMachine && !controlMachineLoading && (
<Alert variant="destructive">
<AlertTitle>Control Machine Required</AlertTitle>
Expand Down
111 changes: 111 additions & 0 deletions apps/provider-console/src/types/provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
export interface ProviderDetails {
owner: string;
name: string | null;
hostUri: string;
createdHeight: number;
email: string | null;
website: string;
lastCheckDate: string;
deploymentCount: number;
leaseCount: number;
cosmosSdkVersion: string | null;
akashVersion: string | null;
ipRegion: string;
ipRegionCode: string;
ipCountry: string;
ipCountryCode: string;
ipLat: string;
ipLon: string;
activeStats: Stats;
pendingStats: Stats;
availableStats: Stats;
gpuModels: string[];
uptime1d: number;
uptime7d: number;
uptime30d: number;
isValidVersion: boolean;
isOnline: boolean;
lastOnlineDate: string;
isAudited: boolean;
attributes: Attribute[];
host: string | null;
organization: string | null;
statusPage: string | null;
locationRegion: string[];
country: string | null;
city: string | null;
timezone: string[];
locationType: string[];
hostingProvider: string | null;
hardwareCpu: string[];
hardwareCpuArch: string[];
hardwareGpuVendor: string[];
hardwareGpuModels: string[];
hardwareDisk: string[];
featPersistentStorage: boolean;
featPersistentStorageType: string[];
hardwareMemory: string[];
networkProvider: string | null;
networkSpeedDown: number;
networkSpeedUp: number;
tier: string[];
featEndpointCustomDomain: boolean;
workloadSupportChia: boolean;
workloadSupportChiaCapabilities: string[];
featEndpointIp: boolean;
uptime: Uptime[];
}

interface Stats {
cpu: number;
gpu: number;
memory: number;
storage: number;
}

interface Attribute {
key: string;
value: string;
auditedBy: string[];
}

interface Uptime {
id: string;
isOnline: boolean;
checkDate: string;
}

interface LeaseStats {
date: string;
height: number;
activeLeaseCount: number;
totalLeaseCount: number;
dailyLeaseCount: number;
totalUAktEarned: number;
dailyUAktEarned: number;
totalUUsdcEarned: number;
dailyUUsdcEarned: number;
totalUUsdEarned: number;
dailyUUsdEarned: number;
activeCPU: number;
activeGPU: number;
activeMemory: string;
activeEphemeralStorage: string;
activePersistentStorage: string;
activeStorage: string;
}

export interface ProviderDashoard {
current: LeaseStats;
previous: LeaseStats;
}

export interface ProviderPricingType {
cpu: number;
memory: number;
storage: number;
persistentStorage: number;
gpu: number;
ipScalePrice: number;
endpointBidPrice: number;
}

0 comments on commit 312aca5

Please sign in to comment.