diff --git a/apps/renterd/contexts/config/derivePricesFromAllowance.spec.ts b/apps/renterd/contexts/config/derivePricesFromAllowance.spec.ts new file mode 100644 index 000000000..09ba1f453 --- /dev/null +++ b/apps/renterd/contexts/config/derivePricesFromAllowance.spec.ts @@ -0,0 +1,281 @@ +import BigNumber from 'bignumber.js' +import { derivePricingFromAllowance } from './derivePricesFromAllowance' + +test('with estimates of 1 TB, standard weights, 1x redundancy, 1x allowance factor', () => { + const allowanceMonth = new BigNumber(1000) + const allowanceFactor = 1 + const storageTB = new BigNumber(1) + const downloadTBMonth = new BigNumber(1) + const uploadTBMonth = new BigNumber(1) + const redundancyMultiplier = new BigNumber(1) + const storageWeight = 4 + const downloadWeight = 5 + const uploadWeight = 1 + + const prices = derivePricingFromAllowance({ + allowanceMonth, + allowanceFactor, + storageTB, + downloadTBMonth, + uploadTBMonth, + redundancyMultiplier, + storageWeight, + downloadWeight, + uploadWeight, + }) + + expect(prices).not.toBeNull() + expect(prices.maxStoragePriceTBMonth.toFixed(2)).toBe('400.00') + expect(prices.maxDownloadPriceTB.toFixed(2)).toBe('500.00') + expect(prices.maxUploadPriceTB.toFixed(2)).toBe('100.00') +}) + +test('with estimates of 1 TB, standard weights, 2x redundancy, 1x allowance factor', () => { + const allowanceMonth = new BigNumber(1000) + const allowanceFactor = 1 + const storageTB = new BigNumber(1) + const downloadTBMonth = new BigNumber(1) + const uploadTBMonth = new BigNumber(1) + const redundancyMultiplier = new BigNumber(2) + const storageWeight = 4 + const downloadWeight = 5 + const uploadWeight = 1 + + const prices = derivePricingFromAllowance({ + allowanceMonth, + allowanceFactor, + storageTB, + downloadTBMonth, + uploadTBMonth, + redundancyMultiplier, + storageWeight, + downloadWeight, + uploadWeight, + }) + + expect(prices).not.toBeNull() + expect(prices.maxStoragePriceTBMonth.toFixed(2)).toBe('266.67') + expect(prices.maxDownloadPriceTB.toFixed(2)).toBe('333.33') + expect(prices.maxUploadPriceTB.toFixed(2)).toBe('66.67') +}) + +test('with estimates of 1 TB, standard weights, 3x redunancy, 1x allowance factor', () => { + const allowanceMonth = new BigNumber(1000) + const allowanceFactor = 1 + const storageTB = new BigNumber(1) + const downloadTBMonth = new BigNumber(1) + const uploadTBMonth = new BigNumber(1) + const redundancyMultiplier = new BigNumber(3) + const storageWeight = 4 + const downloadWeight = 5 + const uploadWeight = 1 + + const prices = derivePricingFromAllowance({ + allowanceMonth, + allowanceFactor, + storageTB, + downloadTBMonth, + uploadTBMonth, + redundancyMultiplier, + storageWeight, + downloadWeight, + uploadWeight, + }) + + expect(prices).not.toBeNull() + expect(prices.maxStoragePriceTBMonth.toFixed(2)).toBe('200.00') + expect(prices.maxDownloadPriceTB.toFixed(2)).toBe('250.00') + expect(prices.maxUploadPriceTB.toFixed(2)).toBe('50.00') +}) + +test('with estimates of 1 TB, standard weights, 1x redundancy, 2x allowance factor', () => { + const allowanceMonth = new BigNumber(1000) + const allowanceFactor = 2 + const storageTB = new BigNumber(1) + const downloadTBMonth = new BigNumber(1) + const uploadTBMonth = new BigNumber(1) + const redundancyMultiplier = new BigNumber(1) + const storageWeight = 4 + const downloadWeight = 5 + const uploadWeight = 1 + + const prices = derivePricingFromAllowance({ + allowanceMonth, + allowanceFactor, + storageTB, + downloadTBMonth, + uploadTBMonth, + redundancyMultiplier, + storageWeight, + downloadWeight, + uploadWeight, + }) + + expect(prices).not.toBeNull() + expect(prices.maxStoragePriceTBMonth.toFixed(2)).toBe('800.00') + expect(prices.maxDownloadPriceTB.toFixed(2)).toBe('1000.00') + expect(prices.maxUploadPriceTB.toFixed(2)).toBe('200.00') +}) + +test('with estimates of 1 TB, standard weights, 2x redundancy, 2x allowance factor', () => { + const allowanceMonth = new BigNumber(1000) + const allowanceFactor = 2 + const storageTB = new BigNumber(1) + const downloadTBMonth = new BigNumber(1) + const uploadTBMonth = new BigNumber(1) + const redundancyMultiplier = new BigNumber(2) + const storageWeight = 4 + const downloadWeight = 5 + const uploadWeight = 1 + + const prices = derivePricingFromAllowance({ + allowanceMonth, + allowanceFactor, + storageTB, + downloadTBMonth, + uploadTBMonth, + redundancyMultiplier, + storageWeight, + downloadWeight, + uploadWeight, + }) + + expect(prices).not.toBeNull() + expect(prices.maxStoragePriceTBMonth.toFixed(2)).toBe('533.33') + expect(prices.maxDownloadPriceTB.toFixed(2)).toBe('666.67') + expect(prices.maxUploadPriceTB.toFixed(2)).toBe('133.33') +}) + +test('with estimates of 1 TB, standard weights, 3x redunancy, 2x allowance factor', () => { + const allowanceMonth = new BigNumber(1000) + const allowanceFactor = 2 + const storageTB = new BigNumber(1) + const downloadTBMonth = new BigNumber(1) + const uploadTBMonth = new BigNumber(1) + const redundancyMultiplier = new BigNumber(3) + const storageWeight = 4 + const downloadWeight = 5 + const uploadWeight = 1 + + const prices = derivePricingFromAllowance({ + allowanceMonth, + allowanceFactor, + storageTB, + downloadTBMonth, + uploadTBMonth, + redundancyMultiplier, + storageWeight, + downloadWeight, + uploadWeight, + }) + + expect(prices).not.toBeNull() + expect(prices.maxStoragePriceTBMonth.toFixed(2)).toBe('400.00') + expect(prices.maxDownloadPriceTB.toFixed(2)).toBe('500.00') + expect(prices.maxUploadPriceTB.toFixed(2)).toBe('100.00') +}) + +test('with varied estimates, standard weights, 1x redunancy, 2x allowance factor', () => { + const allowanceMonth = new BigNumber(1000) + const allowanceFactor = 2 + const storageTB = new BigNumber(8) + const downloadTBMonth = new BigNumber(15) + const uploadTBMonth = new BigNumber(3) + const redundancyMultiplier = new BigNumber(1) + const storageWeight = 4 + const downloadWeight = 5 + const uploadWeight = 1 + + const prices = derivePricingFromAllowance({ + allowanceMonth, + allowanceFactor, + storageTB, + downloadTBMonth, + uploadTBMonth, + redundancyMultiplier, + storageWeight, + downloadWeight, + uploadWeight, + }) + + expect(prices).not.toBeNull() + expect(prices.maxStoragePriceTBMonth.toFixed(2)).toBe('72.73') + expect(prices.maxDownloadPriceTB.toFixed(2)).toBe('90.91') + expect(prices.maxUploadPriceTB.toFixed(2)).toBe('18.18') +}) + +test('with estimates of 1 TB, standard weights, 1x redundancy, 1.5x allowance factor', () => { + const allowanceMonth = new BigNumber(1000) + const storageTB = new BigNumber(1) + const downloadTBMonth = new BigNumber(1) + const uploadTBMonth = new BigNumber(1) + const redundancyMultiplier = new BigNumber(1) + const storageWeight = 4 + const downloadWeight = 5 + const uploadWeight = 1 + const allowanceFactor = 1.5 + + const prices = derivePricingFromAllowance({ + allowanceMonth, + allowanceFactor, + storageTB, + downloadTBMonth, + uploadTBMonth, + redundancyMultiplier, + storageWeight, + downloadWeight, + uploadWeight, + }) + + expect(prices).not.toBeNull() + expect(prices.maxStoragePriceTBMonth.toFixed(2)).toBe('600.00') + expect(prices.maxDownloadPriceTB.toFixed(2)).toBe('750.00') + expect(prices.maxUploadPriceTB.toFixed(2)).toBe('150.00') +}) + +test('with varied estimates, standard weights, 1x redundancy, 1.5x allowance factor', () => { + const allowanceMonth = new BigNumber(1000) + const storageTB = new BigNumber(8) + const downloadTBMonth = new BigNumber(15) + const uploadTBMonth = new BigNumber(3) + const redundancyMultiplier = new BigNumber(1) + const storageWeight = 4 + const downloadWeight = 5 + const uploadWeight = 1 + const allowanceFactor = 1.5 + + const prices = derivePricingFromAllowance({ + allowanceMonth, + allowanceFactor, + storageTB, + downloadTBMonth, + uploadTBMonth, + redundancyMultiplier, + storageWeight, + downloadWeight, + uploadWeight, + }) + + expect(prices).not.toBeNull() + expect(prices.maxStoragePriceTBMonth.toFixed(2)).toBe('54.55') + expect(prices.maxDownloadPriceTB.toFixed(2)).toBe('68.18') + expect(prices.maxUploadPriceTB.toFixed(2)).toBe('13.64') +}) + +test('with zero allowance returns null', () => { + const allowanceMonth = new BigNumber(0) + const storageTB = new BigNumber(8) + const downloadTBMonth = new BigNumber(15) + const uploadTBMonth = new BigNumber(3) + const redundancyMultiplier = new BigNumber(1) + + const prices = derivePricingFromAllowance({ + allowanceMonth, + storageTB, + downloadTBMonth, + uploadTBMonth, + redundancyMultiplier, + }) + + expect(prices).toBeNull() +}) diff --git a/apps/renterd/contexts/config/derivePricesFromAllowance.ts b/apps/renterd/contexts/config/derivePricesFromAllowance.ts new file mode 100644 index 000000000..fed6ff266 --- /dev/null +++ b/apps/renterd/contexts/config/derivePricesFromAllowance.ts @@ -0,0 +1,95 @@ +import BigNumber from 'bignumber.js' + +/** + * This function calculates the price per TB for storage, download, and upload + * given a total spending allowance and estimated usage in TB for each type. The + * prices are fixed relative to each other using weight factors provided as + * parameters. Storage and upload are also scaled to the amount of storage + * required by the redundancy multiplier. + * + * The total cost equation is: A = S * storageWeight * unitCost + D * + * downloadWeight * unitCost + U * uploadWeight * unitCost Solving for unitCost: + * unitCost = A / (S * storageWeight + D * downloadWeight + U * uploadWeight) + * + * Once the unit cost is determined, the individual prices can be calculated: + * - P_u = unitCost * uploadWeight + * - P_d = unitCost * downloadWeight + * - P_s = unitCost * storageWeight + * + * The function also includes an allowance scaling factor to account for + * potential contract variations. For example, if a user expects to pay $2 per + * TB, they should set the max value to $4 per TB because the optimal contracts + * may vary, eg: one contract at $1 and another at $3 which average to $2. The + * scaling factor helps avoid unnecessary churn. + * + * @param params - The parameters for the function. + * @param params.allowanceMonth - The total spending allowance per month. + * @param params.allowanceFactor - The scaling factor to apply to the allowance. + * @param params.storageTB - The estimated amount of storage in TB. + * @param params.downloadTBMonth - The estimated amount of download in TB per + * month. + * @param params.uploadTBMonth - The estimated amount of upload in TB per month. + * @param params.redundancyMultiplier - The redundancy multiplier. + * @param params.storageWeight - The weight factor for storage. + * @param params.downloadWeight - The weight factor for download. + * @param params.uploadWeight - The weight factor for upload. + * @returns An object containing the price per TB for storage, download, and + * upload. + */ +export function derivePricingFromAllowance({ + allowanceMonth, + allowanceFactor = 2, + storageTB, + downloadTBMonth, + uploadTBMonth, + redundancyMultiplier, + storageWeight = 4, + downloadWeight = 5, + uploadWeight = 1, +}: { + allowanceMonth: BigNumber + allowanceFactor?: number + storageTB: BigNumber + downloadTBMonth: BigNumber + uploadTBMonth: BigNumber + redundancyMultiplier: BigNumber + storageWeight?: number + downloadWeight?: number + uploadWeight?: number +}) { + // Return null if zero values are provided. + if ( + !allowanceMonth?.gt(0) || + allowanceFactor <= 0 || + !redundancyMultiplier?.gt(0) || + !storageTB?.gt(0) || + !downloadTBMonth?.gt(0) || + !uploadTBMonth?.gt(0) + ) { + return null + } + // Apply scaling factor to allowance. + const scaledAllowance = allowanceMonth.times(allowanceFactor) + + const storageTBWithRedundancy = storageTB.times(redundancyMultiplier) + const uploadTBMonthWithRedundancy = uploadTBMonth.times(redundancyMultiplier) + + // Calculate the unit cost based on the provided allowance and usage estimates. + const unitCost = scaledAllowance.div( + storageTBWithRedundancy + .times(storageWeight) + .plus(downloadTBMonth.times(downloadWeight)) + .plus(uploadTBMonthWithRedundancy.times(uploadWeight)) + ) + + // Calculate the price per TB for each type of usage. + const maxUploadPriceTB = unitCost.times(uploadWeight) + const maxDownloadPriceTB = unitCost.times(downloadWeight) + const maxStoragePriceTBMonth = unitCost.times(storageWeight) + + return { + maxUploadPriceTB, + maxDownloadPriceTB, + maxStoragePriceTBMonth, + } +} diff --git a/apps/renterd/contexts/config/fields.tsx b/apps/renterd/contexts/config/fields.tsx index e61c7edee..7de8bf121 100644 --- a/apps/renterd/contexts/config/fields.tsx +++ b/apps/renterd/contexts/config/fields.tsx @@ -41,8 +41,8 @@ type GetFields = { isAutopilotEnabled: boolean configViewMode: ConfigViewMode recommendations: Partial> - autoAllowance: boolean - setAutoAllowance: (value: boolean) => void + allowanceDerivedPricing: boolean + setAllowanceDerivedPricing: (value: boolean) => void validationContext: { isAutopilotEnabled: boolean configViewMode: ConfigViewMode @@ -66,8 +66,8 @@ export function getFields({ isAutopilotEnabled, configViewMode, validationContext, - autoAllowance, - setAutoAllowance, + allowanceDerivedPricing, + setAllowanceDerivedPricing, }: GetFields): ConfigFields { return { // storage @@ -125,23 +125,22 @@ export function getFields({
- Calculate + Calculate prices
), - readOnly: autoAllowance, units: 'SC/month', decimalsLimitSc: scDecimalPlaces, hidden: !isAutopilotEnabled, @@ -402,6 +401,7 @@ export function getFields({ of data per month. ), + readOnly: allowanceDerivedPricing, units: 'SC/TB/month', average: storageAverage, averageTip: 'Averages provided by Sia Central.', @@ -461,6 +461,7 @@ export function getFields({ ), units: 'SC/TB', + readOnly: allowanceDerivedPricing, average: uploadAverage, averageTip: 'Averages provided by Sia Central.', suggestion: recommendations.maxUploadPriceTB?.targetValue, @@ -512,6 +513,7 @@ export function getFields({ title: 'Max download price', description: <>The max allowed price to download 1 TB., units: 'SC/TB', + readOnly: allowanceDerivedPricing, average: downloadAverage, averageTip: `Averages provided by Sia Central.`, suggestion: recommendations.maxDownloadPriceTB?.targetValue, diff --git a/apps/renterd/contexts/config/index.tsx b/apps/renterd/contexts/config/index.tsx index abd32ad93..59102e6d8 100644 --- a/apps/renterd/contexts/config/index.tsx +++ b/apps/renterd/contexts/config/index.tsx @@ -98,8 +98,8 @@ export function useConfigMain() { fields, configViewMode, setConfigViewMode, - autoAllowance, - setAutoAllowance, + allowanceDerivedPricing, + setAllowanceDerivedPricing, } = useForm({ resources }) const remoteValues: SettingsData = useMemo(() => { @@ -211,8 +211,8 @@ export function useConfigMain() { configRef, takeScreenshot, evaluation, - autoAllowance, - setAutoAllowance, + allowanceDerivedPricing, + setAllowanceDerivedPricing, } } diff --git a/apps/renterd/contexts/config/transformUp.ts b/apps/renterd/contexts/config/transformUp.ts index fe5b34c85..39b1ff6fa 100644 --- a/apps/renterd/contexts/config/transformUp.ts +++ b/apps/renterd/contexts/config/transformUp.ts @@ -28,6 +28,7 @@ import { import { valuePerMonthToPerPeriod } from './utils' import { Resources } from './resources' import BigNumber from 'bignumber.js' +import { derivePricingFromAllowance } from './derivePricesFromAllowance' // up export function transformUpAutopilot( @@ -197,17 +198,35 @@ function filterUndefinedKeys(obj: Record) { } export function getCalculatedValues({ - estimatedSpendingPerMonth, isAutopilotEnabled, - autoAllowance, + allowanceDerivedPricing, + allowanceMonth, + storageTB, + downloadTBMonth, + uploadTBMonth, + redundancyMultiplier, }: { - estimatedSpendingPerMonth: BigNumber + allowanceMonth: BigNumber + storageTB: BigNumber + downloadTBMonth: BigNumber + uploadTBMonth: BigNumber + redundancyMultiplier: BigNumber isAutopilotEnabled: boolean - autoAllowance: boolean + allowanceDerivedPricing: boolean }) { - const calculatedValues: Partial = {} - if (isAutopilotEnabled && autoAllowance && estimatedSpendingPerMonth?.gt(0)) { - calculatedValues.allowanceMonth = estimatedSpendingPerMonth + let calculatedValues: Partial = {} + if (isAutopilotEnabled && allowanceDerivedPricing) { + const derivedPricing = derivePricingFromAllowance({ + allowanceMonth, + storageTB, + downloadTBMonth, + uploadTBMonth, + redundancyMultiplier, + }) + calculatedValues = { + ...calculatedValues, + ...derivedPricing, + } } return calculatedValues } diff --git a/apps/renterd/contexts/config/useAutoCalculatedFields.tsx b/apps/renterd/contexts/config/useAutoCalculatedFields.tsx index a03804546..7b65793bb 100644 --- a/apps/renterd/contexts/config/useAutoCalculatedFields.tsx +++ b/apps/renterd/contexts/config/useAutoCalculatedFields.tsx @@ -7,29 +7,47 @@ import BigNumber from 'bignumber.js' export function useAutoCalculatedFields({ form, - estimatedSpendingPerMonth, + allowanceMonth, + storageTB, + downloadTBMonth, + uploadTBMonth, + redundancyMultiplier, isAutopilotEnabled, }: { form: UseFormReturn - estimatedSpendingPerMonth: BigNumber + allowanceMonth: BigNumber + storageTB: BigNumber + downloadTBMonth: BigNumber + uploadTBMonth: BigNumber + redundancyMultiplier: BigNumber isAutopilotEnabled: boolean }) { - const [autoAllowance, setAutoAllowance] = useLocalStorageState( - 'v0/config/auto/allowance', - { + const [allowanceDerivedPricing, setAllowanceDerivedPricing] = + useLocalStorageState('v0/config/auto/allowance', { defaultValue: true, - } - ) + }) // Sync calculated values if applicable. const calculatedValues = useMemo( () => getCalculatedValues({ - estimatedSpendingPerMonth, isAutopilotEnabled, - autoAllowance, + allowanceDerivedPricing, + allowanceMonth, + storageTB, + downloadTBMonth, + uploadTBMonth, + redundancyMultiplier, }), - [estimatedSpendingPerMonth, isAutopilotEnabled, autoAllowance] + [ + isAutopilotEnabled, + allowanceDerivedPricing, + allowanceMonth, + storageTB, + downloadTBMonth, + uploadTBMonth, + redundancyMultiplier, + ] ) useEffect(() => { @@ -43,7 +61,7 @@ export function useAutoCalculatedFields({ }, [form, calculatedValues]) return { - autoAllowance, - setAutoAllowance, + allowanceDerivedPricing, + setAllowanceDerivedPricing, } } diff --git a/apps/renterd/contexts/config/useAutopilotEvaluations.tsx b/apps/renterd/contexts/config/useAutopilotEvaluations.tsx index ac5d03483..016c46d3e 100644 --- a/apps/renterd/contexts/config/useAutopilotEvaluations.tsx +++ b/apps/renterd/contexts/config/useAutopilotEvaluations.tsx @@ -298,8 +298,8 @@ const fields = getFields({ minShards: new BigNumber(0), totalShards: new BigNumber(0), redundancyMultiplier: new BigNumber(0), - autoAllowance: false, - setAutoAllowance: () => null, + allowanceDerivedPricing: false, + setAllowanceDerivedPricing: () => null, recommendations: {}, }) diff --git a/apps/renterd/contexts/config/useEstimates.tsx b/apps/renterd/contexts/config/useEstimates.tsx index 2c3f00213..1f9536b15 100644 --- a/apps/renterd/contexts/config/useEstimates.tsx +++ b/apps/renterd/contexts/config/useEstimates.tsx @@ -3,84 +3,28 @@ import { useMemo } from 'react' export function useEstimates({ isAutopilotEnabled, - redundancyMultiplier, - maxStoragePriceTBMonth, + allowanceMonth, storageTB, - maxDownloadPriceTB, - downloadTBMonth, - maxUploadPriceTB, - uploadTBMonth, }: { isAutopilotEnabled: boolean - redundancyMultiplier: BigNumber - maxStoragePriceTBMonth: BigNumber + allowanceMonth: BigNumber storageTB: BigNumber - maxDownloadPriceTB: BigNumber - downloadTBMonth: BigNumber - maxUploadPriceTB: BigNumber - uploadTBMonth: BigNumber }) { const canEstimate = useMemo(() => { if (!isAutopilotEnabled) { return false } - return ( - maxStoragePriceTBMonth?.gt(0) && - storageTB?.gt(0) && - maxDownloadPriceTB?.gt(0) && - maxUploadPriceTB?.gt(0) - ) - }, [ - isAutopilotEnabled, - maxStoragePriceTBMonth, - storageTB, - maxDownloadPriceTB, - maxUploadPriceTB, - ]) + return !!allowanceMonth?.gt(0) + }, [isAutopilotEnabled, allowanceMonth]) + + console.log('canEstimate', canEstimate) const estimatedSpendingPerMonth = useMemo(() => { if (!canEstimate) { return new BigNumber(0) } - const _storageTB = storageTB?.gt(0) ? storageTB : new BigNumber(0) - const _downloadTBMonth = downloadTBMonth?.gt(0) - ? downloadTBMonth - : new BigNumber(0) - const _uploadTBMonth = uploadTBMonth?.gt(0) - ? uploadTBMonth - : new BigNumber(0) - const _maxStoragePriceTBMonth = maxStoragePriceTBMonth?.gt(0) - ? maxStoragePriceTBMonth - : new BigNumber(0) - const _maxUploadPriceTB = maxUploadPriceTB?.gt(0) - ? maxUploadPriceTB - : new BigNumber(0) - const _maxDownloadPriceTB = maxDownloadPriceTB?.gt(0) - ? maxDownloadPriceTB - : new BigNumber(0) - - const storageCostPerMonth = _maxStoragePriceTBMonth - .times(redundancyMultiplier) - .times(_storageTB) - const downloadCostPerMonth = _maxDownloadPriceTB.times(_downloadTBMonth) - const uploadCostPerMonth = _maxUploadPriceTB - .times(redundancyMultiplier) - .times(_uploadTBMonth) - - const totalCostPerMonth = storageCostPerMonth - .plus(downloadCostPerMonth) - .plus(uploadCostPerMonth) - return totalCostPerMonth - }, [ - canEstimate, - redundancyMultiplier, - maxStoragePriceTBMonth, - storageTB, - maxDownloadPriceTB, - downloadTBMonth, - maxUploadPriceTB, - uploadTBMonth, - ]) + return allowanceMonth + }, [canEstimate, allowanceMonth]) const estimatedSpendingPerTB = useMemo(() => { if (!canEstimate) { diff --git a/apps/renterd/contexts/config/useForm.tsx b/apps/renterd/contexts/config/useForm.tsx index 7ce9c30b5..668aa5c51 100644 --- a/apps/renterd/contexts/config/useForm.tsx +++ b/apps/renterd/contexts/config/useForm.tsx @@ -17,6 +17,7 @@ export function useForm({ resources }: { resources: Resources }) { mode: 'all', defaultValues, }) + const allowanceMonth = form.watch('allowanceMonth') const maxStoragePriceTBMonth = form.watch('maxStoragePriceTBMonth') const maxDownloadPriceTB = form.watch('maxDownloadPriceTB') const maxUploadPriceTB = form.watch('maxUploadPriceTB') @@ -54,13 +55,8 @@ export function useForm({ resources }: { resources: Resources }) { const estimates = useEstimates({ isAutopilotEnabled, - redundancyMultiplier, - maxStoragePriceTBMonth, + allowanceMonth, storageTB, - maxDownloadPriceTB, - downloadTBMonth, - maxUploadPriceTB, - uploadTBMonth, }) const { estimatedSpendingPerMonth } = estimates @@ -71,11 +67,16 @@ export function useForm({ resources }: { resources: Resources }) { estimatedSpendingPerMonth, }) - const { autoAllowance, setAutoAllowance } = useAutoCalculatedFields({ - form, - estimatedSpendingPerMonth, - isAutopilotEnabled, - }) + const { allowanceDerivedPricing, setAllowanceDerivedPricing } = + useAutoCalculatedFields({ + form, + allowanceMonth, + storageTB, + downloadTBMonth, + uploadTBMonth, + redundancyMultiplier, + isAutopilotEnabled, + }) const renterdState = useBusState() @@ -116,8 +117,8 @@ export function useForm({ resources }: { resources: Resources }) { minShards, totalShards, recommendations, - autoAllowance, - setAutoAllowance, + allowanceDerivedPricing, + setAllowanceDerivedPricing, }) } return getFields({ @@ -131,8 +132,8 @@ export function useForm({ resources }: { resources: Resources }) { minShards, totalShards, recommendations, - autoAllowance, - setAutoAllowance, + allowanceDerivedPricing, + setAllowanceDerivedPricing, }) }, [ isAutopilotEnabled, @@ -149,8 +150,8 @@ export function useForm({ resources }: { resources: Resources }) { minShards, totalShards, evaluation, - autoAllowance, - setAutoAllowance, + allowanceDerivedPricing, + setAllowanceDerivedPricing, ]) return { @@ -169,7 +170,7 @@ export function useForm({ resources }: { resources: Resources }) { redundancyMultiplier, configViewMode, setConfigViewMode, - autoAllowance, - setAutoAllowance, + allowanceDerivedPricing, + setAllowanceDerivedPricing, } }