diff --git a/deploy-web/src/hooks/useWalletBalance.ts b/deploy-web/src/hooks/useWalletBalance.ts index 671b8e90e..02fc9cc5e 100644 --- a/deploy-web/src/hooks/useWalletBalance.ts +++ b/deploy-web/src/hooks/useWalletBalance.ts @@ -5,6 +5,7 @@ import { udenomToDenom } from "@src/utils/mathHelpers"; import { uaktToAKT } from "@src/utils/priceUtils"; import { useEffect, useState } from "react"; import { useUsdcDenom } from "./useDenom"; +import { useDepositParams } from "@src/queries/useSettings"; export const useTotalWalletBalance = () => { const { isLoaded, price } = usePricing(); @@ -24,6 +25,7 @@ export const useTotalWalletBalance = () => { }; type DenomData = { + min: number; label: string; balance: number; inputMax: number; @@ -34,20 +36,26 @@ export const useDenomData = (denom: string) => { const { walletBalances } = useWallet(); const [depositData, setDepositData] = useState(null); const usdcIbcDenom = useUsdcDenom(); + const { data: depositParams } = useDepositParams(); useEffect(() => { - if (isLoaded && walletBalances) { - let depositData: DenomData = null; + if (isLoaded && walletBalances && depositParams) { + let depositData: DenomData = null, + params = null; switch (denom) { case uAktDenom: + params = depositParams.find(p => p.denom === uAktDenom); depositData = { + min: parseInt(params?.amount || 0), label: "AKT", balance: uaktToAKT(walletBalances.uakt, 6), inputMax: uaktToAKT(Math.max(walletBalances.uakt - txFeeBuffer, 0), 6) }; break; case usdcIbcDenom: + params = depositParams.find(p => p.denom === usdcIbcDenom); depositData = { + min: parseInt(params?.amount || 0), label: "USDC", balance: udenomToDenom(walletBalances.usdc, 6), inputMax: udenomToDenom(Math.max(walletBalances.usdc - txFeeBuffer, 0), 6) @@ -59,8 +67,7 @@ export const useDenomData = (denom: string) => { setDepositData(depositData); } - }, [denom, isLoaded, price, walletBalances, usdcIbcDenom]); + }, [denom, isLoaded, price, walletBalances, usdcIbcDenom, depositParams]); return depositData; }; - diff --git a/deploy-web/src/queries/queryKeys.ts b/deploy-web/src/queries/queryKeys.ts index 6d1c84a5b..1f7bf54ad 100644 --- a/deploy-web/src/queries/queryKeys.ts +++ b/deploy-web/src/queries/queryKeys.ts @@ -43,4 +43,5 @@ export class QueryKeys { static getBalancesKey = (address: string) => ["BALANCES", address]; static getTemplatesKey = () => ["TEMPLATES"]; static getProviderAttributesSchema = () => ["PROVIDER_ATTRIBUTES_SCHEMA"]; + static getDepositParamsKey = () => ["DEPOSIT_PARAMS"]; } diff --git a/deploy-web/src/queries/useSettings.ts b/deploy-web/src/queries/useSettings.ts index b19559a5c..dd3da565e 100644 --- a/deploy-web/src/queries/useSettings.ts +++ b/deploy-web/src/queries/useSettings.ts @@ -1,8 +1,12 @@ +import { useSettings } from "@src/context/SettingsProvider"; import { useCustomUser } from "@src/hooks/useCustomUser"; import { UserSettings } from "@src/types/user"; +import { ApiUrlService } from "@src/utils/apiUtils"; import axios, { AxiosResponse } from "axios"; import { useSnackbar } from "notistack"; -import { useMutation } from "react-query"; +import { useMutation, useQuery } from "react-query"; +import { QueryKeys } from "./queryKeys"; +import { DepositParams, RpcDeposiParams } from "@src/types/deployment"; export function useSaveSettings() { const { enqueueSnackbar } = useSnackbar(); @@ -19,3 +23,18 @@ export function useSaveSettings() { } }); } + +async function getDepositParams(apiEndpoint: string) { + const depositParamsQuery = await axios.get(ApiUrlService.depositParams(apiEndpoint)); + const depositParams = depositParamsQuery.data as RpcDeposiParams; + const params = JSON.parse(depositParams.params.value) as DepositParams[]; + + console.log(depositParams, params); + + return params; +} + +export function useDepositParams(options = {}) { + const { settings } = useSettings(); + return useQuery(QueryKeys.getDepositParamsKey(), () => getDepositParams(settings.apiEndpoint), options); +} diff --git a/deploy-web/src/types/deployment.ts b/deploy-web/src/types/deployment.ts index d7d105218..2448f6538 100644 --- a/deploy-web/src/types/deployment.ts +++ b/deploy-web/src/types/deployment.ts @@ -63,26 +63,26 @@ interface DeploymentResource_V2 { units: { val: string; }; - attributes: {key: string, value: string}[]; + attributes: { key: string; value: string }[]; }; gpu: { units: { val: string; }; - attributes: {key: string, value: string}[]; + attributes: { key: string; value: string }[]; }; memory: { quantity: { val: string; }; - attributes: {key: string, value: string}[]; + attributes: { key: string; value: string }[]; }; storage: Array<{ name: string; quantity: { val: string; }; - attributes: {key: string, value: string}[]; + attributes: { key: string; value: string }[]; }>; endpoints: Array<{ kind: string; @@ -319,3 +319,17 @@ export interface BidDto { count: number; }>; } + +export interface RpcDeposiParams { + params: { + subspace: string; + key: string; + // Array of { denom: string, amount: string } + value: string; + }; +} + +export interface DepositParams { + denom: string; + amount: string; +} diff --git a/deploy-web/src/types/network.ts b/deploy-web/src/types/network.ts index fb151485f..8347bc5b4 100644 --- a/deploy-web/src/types/network.ts +++ b/deploy-web/src/types/network.ts @@ -9,4 +9,4 @@ export type Network = { rpcEndpoint?: string; version: string; enabled: boolean; -}; +}; \ No newline at end of file diff --git a/deploy-web/src/utils/apiUtils.ts b/deploy-web/src/utils/apiUtils.ts index 18b2cb78e..b01626dc3 100644 --- a/deploy-web/src/utils/apiUtils.ts +++ b/deploy-web/src/utils/apiUtils.ts @@ -3,6 +3,9 @@ import axios from "axios"; import { appendSearchParams } from "./urlUtils"; export class ApiUrlService { + static depositParams(apiEndpoint: string) { + return `${apiEndpoint}/cosmos/params/v1beta1/params?subspace=deployment&key=MinDeposits`; + } static deploymentList(apiEndpoint: string, address: string) { return `${apiEndpoint}/akash/deployment/${networkVersion}/deployments/list?filters.owner=${address}`; } diff --git a/deploy-web/src/utils/deploymentDetailUtils.ts b/deploy-web/src/utils/deploymentDetailUtils.ts index 7321470c9..3bd38345c 100644 --- a/deploy-web/src/utils/deploymentDetailUtils.ts +++ b/deploy-web/src/utils/deploymentDetailUtils.ts @@ -1,4 +1,4 @@ -import { DeploymentDto, LeaseDto, RpcDeployment, RpcLease } from "@src/types/deployment"; +import { DeploymentDto, DepositParams, LeaseDto, RpcDeployment, RpcDeposiParams, RpcLease } from "@src/types/deployment"; import { coinToUDenom } from "./priceUtils"; export function deploymentResourceSum(deployment: RpcDeployment, resourceSelector) {