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

feat(provider): provider pricing feature #475

Draft
wants to merge 65 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
ebe6471
added server-access and server-form files
jigar-arc10 Aug 22, 2024
6342ed9
added wallet import page - wip, fixed issue with file upload in serve…
jigar-arc10 Aug 23, 2024
7f89ed8
added become-provider steps ui
jigar-arc10 Aug 29, 2024
58055d7
server access step added with state support
jigar-arc10 Sep 18, 2024
192d116
added provider config and provider attribute screen
jigar-arc10 Sep 19, 2024
da07743
added provider process with hoc to prevent access to pages
jigar-arc10 Oct 7, 2024
329e06c
added progress for becoming prvider for final stage
jigar-arc10 Oct 8, 2024
51e5ef0
Code clean up and added navigation logic to homecontainer
jigar-arc10 Oct 10, 2024
c977e2e
package lock updated
jigar-arc10 Oct 10, 2024
66d0f11
fixed package-lock.json merge issue
jigar-arc10 Oct 10, 2024
25ed729
more cleanup and remove general warnings
jigar-arc10 Oct 10, 2024
897066e
removed unused npm package
jigar-arc10 Oct 10, 2024
aefe70b
fix minor error on api
jigar-arc10 Oct 11, 2024
8e5eb6a
Added dashboard and actions page
jigar-arc10 Oct 11, 2024
ea30723
change status api endpoint
jigar-arc10 Oct 11, 2024
d024c0d
Merge branch 'feature/provider-console/become-provider-process' into …
jigar-arc10 Oct 11, 2024
ead4eac
added stat line and pie charts
jigar-arc10 Oct 11, 2024
f5c243f
Added console apis to get dashboard data and show appropriate details
jigar-arc10 Oct 11, 2024
4472dbd
fixed actions and changed home component
jigar-arc10 Oct 12, 2024
8df762a
token varification and refresh token fix
jigar-arc10 Oct 15, 2024
d4288b3
changed wallet connect from wallet status to wallet provider
jigar-arc10 Oct 15, 2024
6e8b289
fixed issue in loading provider status
jigar-arc10 Oct 16, 2024
44934ae
fixed home loading issue
jigar-arc10 Oct 16, 2024
d91d340
fixed refresh token, added disabled menu items
jigar-arc10 Oct 16, 2024
fd62ae2
fixed build process
jigar-arc10 Oct 16, 2024
3276a95
feat(provider): added sentry and docker
jigar-arc10 Oct 17, 2024
8f123e1
fix(provider): fixed wallet switching and getting status
jigar-arc10 Oct 18, 2024
5fa9f63
feat(provider): reduced number of events in dashboard
jigar-arc10 Oct 18, 2024
2b0d5e0
feat(provider): added docker compose changes for provider-console
jigar-arc10 Oct 18, 2024
781a99c
feat(provider): added deployments and deployment detail page
jigar-arc10 Oct 18, 2024
ee5d564
fix(provider): change hours to seconds for calculation purpose)
jigar-arc10 Oct 18, 2024
7057434
feat(provider): added auth for deployments and deployment details page
jigar-arc10 Oct 18, 2024
8648e13
feat(provider): added env and removed settingsprovider
jigar-arc10 Oct 29, 2024
f1637fd
fix(provider): fix lint errors and removed console.logs
jigar-arc10 Oct 29, 2024
614c4ba
fix(provider): become-provider looped, fixed it
jigar-arc10 Oct 30, 2024
5d08b82
fix(provider): router and reset process fixed
jigar-arc10 Oct 30, 2024
1110b35
fix(provider): removed Get Started button for now
jigar-arc10 Oct 30, 2024
f2696bf
fix(provider): removed unused import in nav
jigar-arc10 Oct 30, 2024
7344be9
fix(provider): change functions to react fc component
jigar-arc10 Oct 30, 2024
7f9da2b
fix(provider): fix lint issues
jigar-arc10 Oct 30, 2024
c9df37a
fix(provider): change functions to react fc component
jigar-arc10 Oct 31, 2024
1f2d277
fix(provider): rebased main
jigar-arc10 Oct 31, 2024
a97c913
fix(provider): added docker build and fix build related issues
jigar-arc10 Nov 5, 2024
91e8bcd
feat(provider): control machine edit, add from sidebar
jigar-arc10 Nov 5, 2024
c2bb251
feat(provider): added attributes screen
jigar-arc10 Nov 5, 2024
f4629af
fix(provider): control machine auto connect on page load
jigar-arc10 Nov 5, 2024
aa5009a
Merge branch 'feature/provider/control-machine' into feature/provider…
jigar-arc10 Nov 5, 2024
3811d55
fix(provider): fix loading not showing while connecting provider cont…
jigar-arc10 Nov 6, 2024
2df1f61
Merge branch 'feature/provider/control-machine' into feature/provider…
jigar-arc10 Nov 6, 2024
226e744
fix(provider): close drawer on successfull connection
jigar-arc10 Nov 6, 2024
4927267
feat(provider): change favicon to akash favicon
jigar-arc10 Nov 6, 2024
799001a
Merge branch 'feature/provider/control-machine' into feature/provider…
jigar-arc10 Nov 6, 2024
38ec68e
feat(provider): provider add, edit and remove and show acitons list page
jigar-arc10 Nov 6, 2024
e587c32
fix(provider): fix url when provider process finish
jigar-arc10 Nov 6, 2024
a1505e0
feat(provider): provider pricing feature added
jigar-arc10 Nov 6, 2024
d0a552d
feat(provider): added pricing update and extracted provider context
jigar-arc10 Nov 7, 2024
55e1e7f
fix(provider): auto import and lint issues fixed
jigar-arc10 Nov 7, 2024
81aa543
fix(provider): pricing loading screen fix
jigar-arc10 Nov 7, 2024
13c537b
Merge branch 'main' into feature/provider/control-machine
jigar-arc10 Nov 14, 2024
eeb82b8
fix(provider): merge issues with main
jigar-arc10 Nov 14, 2024
1303c66
Merge branch 'feature/provider/control-machine' into feature/provider…
jigar-arc10 Nov 14, 2024
f519f09
Merge branch 'feature/provider/attributes-actions' into feature/provi…
jigar-arc10 Nov 14, 2024
b26c45d
fix(provider): pricing update fix
jigar-arc10 Dec 2, 2024
6f06164
Merge branch 'main' into feature/provider/pricing
jigar-arc10 Dec 2, 2024
8dec5aa
chore: package-lock modified
jigar-arc10 Dec 2, 2024
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

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions apps/provider-console/src/components/layout/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ export const Sidebar: React.FC<Props> = ({ isMobileOpen, handleDrawerToggle, isN
{
title: "Pricing",
icon: props => <Calculator {...props} />,
url: "#",
activeRoutes: ["#"],
disabled: true
url: UrlService.pricing(),
activeRoutes: [UrlService.pricing()],
disabled: false
},
{
title: "Attributes",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"use client";
import React from "react";
import { useQuery } from "react-query";

import consoleClient from "@src/utils/consoleClient";
import { useWallet } from "../WalletProvider";

type ContextType = {
providerDetails: any;
providerDashboard: any;
isLoadingProviderDetails: boolean;
isLoadingProviderDashboard: boolean;
};

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}`),
{
refetchOnWindowFocus: false,
retry: 3,
enabled: !!address
}
);

const { data: providerDashboard, isLoading: isLoadingProviderDashboard } = useQuery(
"providerDashboard",
() => consoleClient.get(`/internal/provider-dashboard/${address}`),
{
refetchOnWindowFocus: false,
retry: 3,
enabled: !!address
}
);

return (
<ProviderContext.Provider
value={{
providerDetails,
providerDashboard,
isLoadingProviderDetails,
isLoadingProviderDashboard
}}
>
{children}
</ProviderContext.Provider>
);
};

export const useProvider = () => {
return { ...React.useContext(ProviderContext) };
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ProviderContextProvider as ProviderContext, useProvider } from "./ProviderContext";
5 changes: 4 additions & 1 deletion apps/provider-console/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ControlMachineProvider } from "@src/context/ControlMachineProvider";
import { CustomChainProvider } from "@src/context/CustomChainProvider";
import { ColorModeProvider } from "@src/context/CustomThemeContext";
import { PricingProvider } from "@src/context/PricingProvider";
import { ProviderContextProvider } from "@src/context/ProviderContext/ProviderContext";
import { WalletProvider } from "@src/context/WalletProvider";
import { queryClient } from "@src/queries";
import { cn } from "@src/utils/styleUtils";
Expand All @@ -28,7 +29,9 @@ export default function App({ Component, pageProps }: AppProps) {
<CustomChainProvider>
<WalletProvider>
<ControlMachineProvider>
<Component {...pageProps} />
<ProviderContextProvider>
<Component {...pageProps} />
</ProviderContextProvider>
</ControlMachineProvider>
</WalletProvider>
</CustomChainProvider>
Expand Down
34 changes: 15 additions & 19 deletions apps/provider-console/src/pages/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import { Layout } from "@src/components/layout/Layout";
import { ProviderActionList } from "@src/components/shared/ProviderActionList";
import { Title } from "@src/components/shared/Title";
import { withAuth } from "@src/components/shared/withAuth";
import { useSelectedChain } from "@src/context/CustomChainProvider";
import { useWallet } from "@src/context/WalletProvider";
import { useAKTData } from "@src/queries";
import { useProviderActions, useProviderDashboard, useProviderDetails } from "@src/queries/useProviderQuery";
import { formatUUsd } from "@src/utils/formatUsd";
import { useSelectedChain } from "@src/context/CustomChainProvider";

const OfflineWarningBanner: React.FC = () => (
<div className="mb-4 rounded-md bg-yellow-100 p-4 text-yellow-700">
Expand Down Expand Up @@ -145,25 +145,21 @@ const Dashboard: React.FC = () => {
)}
</div>
</div>
{isOnline && providerDetails && (
<>
<div className="mt-8">
<div className="text-sm font-semibold">Resources Leased Summary</div>
<div className="mt-2">
{isLoadingProviderDetails ? (
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
<DashboardCardSkeleton />
<DashboardCardSkeleton />
<DashboardCardSkeleton />
<DashboardCardSkeleton />
</div>
) : (
<ResourceCards providerDetails={providerDetails} />
)}
<div className="mt-8">
<div className="text-sm font-semibold">Resources Leased Summary</div>
<div className="mt-2">
{isLoadingProviderDetails ? (
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
<DashboardCardSkeleton />
<DashboardCardSkeleton />
<DashboardCardSkeleton />
<DashboardCardSkeleton />
</div>
</div>
</>
)}
) : (
<ResourceCards providerDetails={providerDetails} />
)}
</div>
</div>

<Separator className="mt-10" />
<div className="mt-8">
Expand Down
94 changes: 94 additions & 0 deletions apps/provider-console/src/pages/pricing/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import React, { useEffect, useState } from "react";
import { Alert, AlertDescription, AlertTitle, Spinner } from "@akashnetwork/ui/components";

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 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 [isLoading, setIsLoading] = useState(false);
const { providerDetails } = useProvider();

const fetchPricing = async () => {
try {
setIsLoading(true);
const request = {
control_machine: sanitizeMachineAccess(activeControlMachine)
};
const response: any = await restClient.post("/get-provider-pricing", request);
if (response) {
setExistingPricing(convertFromPricingAPI(response.pricing));
}
} catch (error) {
console.error(error);
} finally {
setIsLoading(false);
}
};

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

return (
<Layout>
<div className="relative">
{isLoading && (
<div className="absolute inset-0 z-50 flex items-center justify-center bg-white/80">
<div className="flex items-center gap-2">
<Spinner />
<span className="text-sm text-gray-600">Loading provider pricing...</span>
</div>
</div>
)}

<div className={isLoading ? 'pointer-events-none' : ''}>
{!activeControlMachine && !controlMachineLoading && (
<Alert variant="destructive">
<AlertTitle>Control Machine Required</AlertTitle>
<AlertDescription>Please connect your control machine first to start updating pricing settings.</AlertDescription>
</Alert>
)}
{controlMachineLoading && (
<Alert>
<AlertTitle>Connecting to Control Machine</AlertTitle>
<AlertDescription className="flex items-center gap-2">
<div className="flex items-center gap-2">
<Spinner className="h-4 w-4" />
<span>Please wait while we check control machine access...</span>
</div>
</AlertDescription>
</Alert>
)}
{activeControlMachine && !existingPricing && (
<Alert variant="destructive">
<AlertTitle>Unable to fetch pricing</AlertTitle>
<AlertDescription className="flex items-center justify-between">
Please try again later.
<button onClick={fetchPricing} className="rounded bg-red-100 px-3 py-1 text-sm text-red-900 hover:bg-red-200">
Try Again
</button>
</AlertDescription>
</Alert>
)}
<ProviderPricing
existingPricing={existingPricing}
editMode={true}
stepChange={() => {}}
disabled={activeControlMachine && existingPricing ? false : true}
providerDetails={providerDetails}
/>
</div>
</div>
</Layout>
);
};

export default Pricing;
12 changes: 12 additions & 0 deletions apps/provider-console/src/utils/sanityUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@ export function sanitizeMachineAccess(machine: ControlMachineWithAddress | null)
passphrase: machine.access.passphrase || null
};
}

export function convertFromPricingAPI(pricing: any) {
return {
cpu: pricing.price_target_cpu,
memory: pricing.price_target_memory,
storage: pricing.price_target_hd_ephemeral,
persistentStorage: pricing.price_target_hd_pers_ssd,
gpu: Number(pricing.price_target_gpu_mappings.split('=')[1]),
ipScalePrice: pricing.price_target_ip,
endpointBidPrice: pricing.price_target_endpoint
};
}
1 change: 1 addition & 0 deletions apps/provider-console/src/utils/urlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export class UrlService {
static privacyPolicy = () => "/privacy-policy";
static termsOfService = () => "/terms-of-service";
static actions = () => "/actions";
static pricing = () => "/pricing";
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/ui/components/alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const alertVariants = cva(
variants: {
variant: {
default: "bg-background text-foreground",
success: "border-success/50 text-success dark:border-success [&>svg]:text-success",
destructive: "border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive",
warning: "border-warning/50 text-warning dark:border-warning-500 [&>svg]:text-warning"
}
Expand Down
Loading