Skip to content

Commit

Permalink
fix(console): rent gpu form for managed wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
baktun14 committed Aug 28, 2024
1 parent fb6b26a commit 8998d63
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions apps/deploy-web/src/components/sdl/RentGpusForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ import { RegionSelect } from "./RegionSelect";
import { StorageFormControl } from "./StorageFormControl";
import { TokenFormControl } from "./TokenFormControl";
import { useManagedDeploymentConfirm } from "@src/hooks/useManagedDeploymentConfirm";
import { useWhen } from "@src/hooks/useWhen";
import { useManagedWalletDenom } from "@src/hooks/useManagedWalletDenom";
import { useDepositParams } from "@src/queries/useSettings";
import { envConfig } from "@src/config/env.config";
import { DepositParams } from "@src/types/deployment";

export const RentGpusForm: React.FunctionComponent = () => {
const [error, setError] = useState<string | null>(null);
Expand Down Expand Up @@ -72,6 +77,14 @@ export const RentGpusForm: React.FunctionComponent = () => {
const { minDeposit } = useChainParam();
const router = useRouter();
const { createDeploymentConfirm } = useManagedDeploymentConfirm();
const managedDenom = useManagedWalletDenom();
const { data: depositParams } = useDepositParams();
const defaultDeposit = depositParams || defaultInitialDeposit;

useWhen(isManaged && sdlDenom === "uakt", () => {
setSdlDenom(managedDenom);
setValue("services.0.placement.pricing.denom", managedDenom);
});

useEffect(() => {
if (rentGpuSdl && rentGpuSdl.services) {
Expand Down Expand Up @@ -115,7 +128,12 @@ export const RentGpusForm: React.FunctionComponent = () => {
}
}, [searchParams, gpuModels, isQueryInit]);

async function createAndValidateDeploymentData(yamlStr: string, dseq = null, deposit = defaultInitialDeposit, depositorAddress: string | null = null) {
async function createAndValidateDeploymentData(
yamlStr: string,
dseq: string | null = null,
deposit = defaultDeposit,
depositorAddress: string | null = null
) {
try {
if (!yamlStr) return null;

Expand Down Expand Up @@ -170,6 +188,7 @@ export const RentGpusForm: React.FunctionComponent = () => {

setValue("services", result as ServiceType[]);
setValue("services.0.profile.gpuModels", _gpuModels);
setValue("services.0.placement.pricing.denom", managedDenom);
trigger();
};

Expand All @@ -180,23 +199,26 @@ export const RentGpusForm: React.FunctionComponent = () => {

const onDeploymentDeposit = async (deposit: number, depositorAddress: string) => {
setIsDepositingDeployment(false);
await handleCreateClick(deposit, depositorAddress);
};

const onSubmit = async (data: RentGpusFormValuesType) => {
setRentGpuSdl(data);

if (isManaged) {
const isConfirmed = await createDeploymentConfirm(rentGpuSdl?.services as ServiceType[]);

if (!isConfirmed) {
return;
}
}
await handleCreateClick(deposit, depositorAddress);
};

const onSubmit = async (data: RentGpusFormValuesType) => {
setRentGpuSdl(data);
setIsCheckingPrerequisites(true);
await handleCreateClick(defaultDeposit, envConfig.NEXT_PUBLIC_MASTER_WALLET_ADDRESS);
} else {
setIsCheckingPrerequisites(true);
}
};

async function handleCreateClick(deposit: number, depositorAddress: string) {
async function handleCreateClick(deposit: number | DepositParams[], depositorAddress: string) {
setError(null);

try {
Expand Down Expand Up @@ -319,9 +341,11 @@ export const RentGpusForm: React.FunctionComponent = () => {
<div>
<RegionSelect control={control} />
</div>
<div>
<TokenFormControl control={control} name="services.0.placement.pricing.denom" />
</div>
{!isManaged && (
<div>
<TokenFormControl control={control} name="services.0.placement.pricing.denom" />
</div>
)}
</div>
</FormPaper>

Expand Down

0 comments on commit 8998d63

Please sign in to comment.