Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(provider): added missing types and added error handling #751

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { z } from "zod";

import { useControlMachine } from "@src/context/ControlMachineProvider";
import providerProcessStore from "@src/store/providerProcessStore";
import { ProviderDetails } from "@src/types/provider";
import restClient from "@src/utils/restClient";
import { sanitizeMachineAccess } from "@src/utils/sanityUtils";
import { ResetProviderForm } from "./ResetProviderProcess";
Expand All @@ -37,7 +38,7 @@ interface ProviderPricingProps {
editMode?: boolean;
existingPricing?: ProviderPricingValues;
disabled?: boolean;
providerDetails?: any;
providerDetails?: ProviderDetails;
onComplete?: () => void;
}

Expand Down Expand Up @@ -206,7 +207,7 @@ export const ProviderPricing: React.FC<ProviderPricingProps> = ({ onComplete, ed

const competitiveEarnings = calculateDefaultEarnings();

const updateProviderPricingAndProceed = async (data: any) => {
const updateProviderPricingAndProceed = async (data: ProviderPricingValues) => {
setIsLoading(true);
if (!editMode) {
setProviderProcess(prev => ({
Expand Down
3 changes: 1 addition & 2 deletions apps/provider-console/src/components/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const LayoutApp: React.FC<Props> = ({ children, isLoading, disableContainer, con
if (_isNavOpen !== null && !smallScreen) {
setIsNavOpen(_isNavOpen === "true");
}
});
}, [smallScreen]);

const onOpenMenuClick = () => {
setIsNavOpen(prev => {
Expand All @@ -69,7 +69,6 @@ const LayoutApp: React.FC<Props> = ({ children, isLoading, disableContainer, con
setIsMobileOpen(!isMobileOpen);
};

console.log(isLoading);
return (
<>
<div className="bg-card min-h-full">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const ActivityLogDetails: React.FC<{ actionId: string | null }> = ({ acti

useEffect(() => {
if (actionDetails) {
const initialAccordions = actionDetails.tasks.map(task => task.status === "in_progress");
setOpenAccordions(initialAccordions);
const initialAccordions = actionDetails.tasks?.map(task => task.status === "in_progress");
setOpenAccordions(initialAccordions ?? []);
}
}, [actionDetails]);

Expand Down Expand Up @@ -194,7 +194,7 @@ export const ActivityLogDetails: React.FC<{ actionId: string | null }> = ({ acti

<div className="space-y-4">
<div className="rounded-md border">
{actionDetails?.tasks.map((task, index) => (
{actionDetails?.tasks?.map((task, index) => (
<div key={index}>
<div
className="flex cursor-pointer items-center justify-between p-4 hover:bg-gray-50 dark:hover:bg-gray-600/50"
Expand Down Expand Up @@ -229,7 +229,7 @@ export const ActivityLogDetails: React.FC<{ actionId: string | null }> = ({ acti
{renderLogs(taskLogs[task.id], task.id)}
</div>
)}
{index < actionDetails?.tasks.length - 1 && <div className="border-t"></div>}
{index < (actionDetails?.tasks?.length ?? 0) - 1 && <div className="border-t"></div>}
</div>
))}
</div>
Expand Down
3 changes: 2 additions & 1 deletion apps/provider-console/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "@akashnetwork/ui/styles";
import "../styles/index.css";

import { QueryClientProvider } from "react-query";
import { TooltipProvider } from "@akashnetwork/ui/components";
import { Toaster, TooltipProvider } from "@akashnetwork/ui/components";
import { GeistSans } from "geist/font/sans";
import { Provider } from "jotai";
import type { AppProps } from "next/app";
Expand All @@ -23,6 +23,7 @@ export default function App({ Component, pageProps }: AppProps) {
<QueryClientProvider client={queryClient}>
<Provider>
<ThemeProvider attribute="class" defaultTheme="system" storageKey="theme" enableSystem disableTransitionOnChange>
<Toaster />
<ColorModeProvider>
<PricingProvider>
<TooltipProvider>
Expand Down
2 changes: 1 addition & 1 deletion apps/provider-console/src/pages/attributes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import consoleClient from "@src/utils/consoleClient";

const Attributes: React.FunctionComponent = () => {
const { address } = useSelectedChain();
const { data: providerDetails, isLoading: isLoadingProviderDetails }: { data: any; isLoading: boolean } = useQuery(
const { data: providerDetails, isLoading: isLoadingProviderDetails }: { data; isLoading: boolean } = useQuery(
"providerDetails",
() => consoleClient.get(`/v1/providers/${address}`),
{
Expand Down
13 changes: 7 additions & 6 deletions apps/provider-console/src/pages/pricing/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { useCallback, useEffect, useState } from "react";
import { Alert, AlertDescription, AlertTitle, Spinner } from "@akashnetwork/ui/components";

import { ProviderPricing } from "@src/components/become-provider/ProviderPricing";
Expand All @@ -7,6 +7,7 @@ import { withAuth } from "@src/components/shared/withAuth";
import { useControlMachine } from "@src/context/ControlMachineProvider";
import { useProvider } from "@src/context/ProviderContext";
import { ProviderPricingType } from "@src/types/provider";
import { ProviderPricingResponse } from "@src/types/providerPricing";
import restClient from "@src/utils/restClient";
import { convertFromPricingAPI, sanitizeMachineAccess } from "@src/utils/sanityUtils";

Expand All @@ -16,13 +17,13 @@ const Pricing: React.FunctionComponent = () => {
const [isLoading, setIsLoading] = useState(false);
const { providerDetails } = useProvider();

const fetchPricing = async () => {
const fetchPricing = useCallback(async () => {
try {
setIsLoading(true);
const request = {
control_machine: sanitizeMachineAccess(activeControlMachine)
};
const response: any = await restClient.post("/get-provider-pricing", request);
const response: ProviderPricingResponse = await restClient.post("/get-provider-pricing", request);
if (response) {
setExistingPricing(convertFromPricingAPI(response.pricing));
}
Expand All @@ -31,13 +32,13 @@ const Pricing: React.FunctionComponent = () => {
} finally {
setIsLoading(false);
}
};
}, [activeControlMachine]);

useEffect(() => {
if (activeControlMachine) {
fetchPricing();
}
}, [activeControlMachine]);
}, [activeControlMachine, fetchPricing]);

return (
<Layout>
Expand Down Expand Up @@ -84,7 +85,7 @@ const Pricing: React.FunctionComponent = () => {
existingPricing={existingPricing}
editMode={true}
disabled={activeControlMachine && existingPricing ? false : true}
providerDetails={providerDetails}
providerDetails={providerDetails ?? undefined}
/>
</div>
</div>
Expand Down
Loading