diff --git a/apps/renterd/contexts/config/index.tsx b/apps/renterd/contexts/config/index.tsx index bb6156129..8dbbcf716 100644 --- a/apps/renterd/contexts/config/index.tsx +++ b/apps/renterd/contexts/config/index.tsx @@ -24,7 +24,7 @@ export function useConfigMain() { isAutopilotEnabled, autopilot, contractSet, - configApp, + display, gouging, redundancy, uploadPacking, @@ -110,22 +110,22 @@ export function useConfigMain() { ) const remoteValues: SettingsData = useMemo(() => { - const gougingData = buildGougingData(gouging.data) + const g = buildGougingData(gouging.data) if ( (!isAutopilotEnabled || autopilot.data || autopilot.error) && - gougingData && + g && redundancy.data && uploadPacking.data && (contractSet.data || contractSet.error) && - (configApp.data || configApp.error) + (display.data || display.error) ) { return transformDown({ - autopilotData: autopilot.data, - contractSetData: contractSet.data, - uploadPackingData: uploadPacking.data, - gougingData, - redundancyData: redundancy.data, - configAppData: configApp.data, + autopilot: autopilot.data, + contractSet: contractSet.data, + uploadPacking: uploadPacking.data, + gouging: g, + redundancy: redundancy.data, + display: display.data, }) } return null @@ -139,34 +139,32 @@ export function useConfigMain() { gouging.data, buildGougingData, redundancy.data, - configApp.data, - configApp.error, + display.data, + display.error, ]) const revalidate = useCallback(async (): Promise => { - const autopilotData = isAutopilotEnabled - ? await autopilot.mutate() - : undefined - const contractSetData = await contractSet.mutate() - const _gougingData = await gouging.mutate() - const redundancyData = await redundancy.mutate() - const uploadPackingData = await uploadPacking.mutate() - const configAppData = await configApp.mutate() - if (!_gougingData || !redundancyData) { + const a = isAutopilotEnabled ? await autopilot.mutate() : undefined + const cs = await contractSet.mutate() + const _g = await gouging.mutate() + const r = await redundancy.mutate() + const up = await uploadPacking.mutate() + const d = await display.mutate() + if (!_g || !r) { triggerErrorToast('Error fetching settings.') return null } else { - const gougingData = buildGougingData(_gougingData) - if (!gougingData) { + const g = buildGougingData(_g) + if (!g) { return null } return transformDown({ - autopilotData, - contractSetData, - gougingData, - redundancyData, - uploadPackingData, - configAppData, + autopilot: a, + contractSet: cs, + gouging: g, + redundancy: r, + uploadPacking: up, + display: d, }) } }, [ @@ -177,7 +175,7 @@ export function useConfigMain() { buildGougingData, uploadPacking, redundancy, - configApp, + display, ]) const { isUnlockedAndAuthedRoute } = useAppSettings() @@ -258,7 +256,7 @@ export function useConfigMain() { uploadPacking, redundancy, gouging, - configApp, + display, }) const onInvalid = useOnInvalid(fields) diff --git a/apps/renterd/contexts/config/transform.spec.ts b/apps/renterd/contexts/config/transform.spec.ts index a4db7f24d..20109f0ae 100644 --- a/apps/renterd/contexts/config/transform.spec.ts +++ b/apps/renterd/contexts/config/transform.spec.ts @@ -20,8 +20,8 @@ describe('tansforms', () => { describe('down', () => { it('default works', () => { expect( - transformDown( - { + transformDown({ + autopilot: { wallet: { defragThreshold: 1000, }, @@ -43,9 +43,9 @@ describe('tansforms', () => { prune: true, }, }, - { default: 'myset' }, - { enabled: true }, - { + contractSet: { default: 'myset' }, + uploadPacking: { enabled: true }, + gouging: { hostBlockHeightLeeway: 4, maxContractPrice: '20000000000000000000000000', maxDownloadPrice: '1004310000000000000000000000', @@ -58,15 +58,15 @@ describe('tansforms', () => { minPriceTableValidity: 300000000000, migrationSurchargeMultiplier: 10, }, - { + redundancy: { minShards: 10, totalShards: 30, }, - { + display: { includeRedundancyMaxStoragePrice: false, includeRedundancyMaxUploadPrice: false, - } - ) + }, + }) ).toEqual({ autopilotContractSet: 'autopilot', allowanceMonth: new BigNumber('500'), @@ -103,8 +103,8 @@ describe('tansforms', () => { it('with include redundancy for storage and upload', () => { expect( - transformDown( - { + transformDown({ + autopilot: { wallet: { defragThreshold: 1000, }, @@ -126,9 +126,9 @@ describe('tansforms', () => { prune: true, }, }, - { default: 'myset' }, - { enabled: true }, - { + contractSet: { default: 'myset' }, + uploadPacking: { enabled: true }, + gouging: { hostBlockHeightLeeway: 4, maxContractPrice: '20000000000000000000000000', maxDownloadPrice: '1004310000000000000000000000', @@ -141,15 +141,15 @@ describe('tansforms', () => { minPriceTableValidity: 300000000000, migrationSurchargeMultiplier: 10, }, - { + redundancy: { minShards: 10, totalShards: 30, }, - { + display: { includeRedundancyMaxStoragePrice: true, includeRedundancyMaxUploadPrice: true, - } - ) + }, + }) ).toEqual({ autopilotContractSet: 'autopilot', allowanceMonth: new BigNumber('6006'), @@ -506,8 +506,8 @@ describe('tansforms', () => { redundancy, display, } = buildAllResponses() - let settings = transformDown( - { + let settings = transformDown({ + autopilot: { ...autopilot, contracts: { ...autopilot.contracts, @@ -519,16 +519,16 @@ describe('tansforms', () => { uploadPacking, gouging, redundancy, - display - ) + display, + }) expect(settings.downloadTBMonth).toEqual(new BigNumber('92.72')) // a little different due to rounding expect( transformUpAutopilot('Mainnet', settings, autopilot).contracts.download ).toEqual(91088814814815) - settings = transformDown( - { + settings = transformDown({ + autopilot: { ...autopilot, contracts: { ...autopilot.contracts, @@ -540,8 +540,8 @@ describe('tansforms', () => { uploadPacking, gouging, redundancy, - display - ) + display, + }) expect(settings.downloadTBMonth).toEqual(new BigNumber('92.72')) // using the rounded value results in same value expect( diff --git a/apps/renterd/contexts/config/transform.ts b/apps/renterd/contexts/config/transform.ts index 8ffdebdae..69c8ce786 100644 --- a/apps/renterd/contexts/config/transform.ts +++ b/apps/renterd/contexts/config/transform.ts @@ -27,9 +27,9 @@ import { scDecimalPlaces, SettingsData, getAdvancedDefaultAutopilot, - ConfigAppData, + DisplayData, ContractSetData, - defaultConfigApp, + defaultDisplay, defaultContractSet, GougingData, RedundancyData, @@ -184,8 +184,8 @@ export function transformUpRedundancy( } } -export function transformUpConfigApp( - values: ConfigAppData, +export function transformUpDisplay( + values: DisplayData, existingValues: Record | undefined ): ConfigDisplayOptions { return { @@ -276,11 +276,9 @@ export function transformDownUploadPacking( } } -export function transformDownConfigApp( - ca?: ConfigDisplayOptions -): ConfigAppData { +export function transformDownConfigApp(ca?: ConfigDisplayOptions): DisplayData { if (!ca) { - return defaultConfigApp + return defaultDisplay } return { includeRedundancyMaxStoragePrice: ca.includeRedundancyMaxStoragePrice, @@ -291,7 +289,7 @@ export function transformDownConfigApp( export function transformDownGouging( g: GougingSettings, r: RedundancyData, - ca: ConfigAppData + ca: DisplayData ): GougingData { return { maxStoragePriceTBMonth: toSiacoins( @@ -344,37 +342,37 @@ export function transformDownRedundancy(r: RedundancySettings): RedundancyData { } export type RemoteData = { - autopilotData: AutopilotConfig | undefined - contractSetData: ContractSetSettings | undefined - uploadPackingData: UploadPackingSettings - gougingData: GougingSettings - redundancyData: RedundancySettings - configAppData: ConfigDisplayOptions | undefined + autopilot: AutopilotConfig | undefined + contractSet: ContractSetSettings | undefined + uploadPacking: UploadPackingSettings + gouging: GougingSettings + redundancy: RedundancySettings + display: ConfigDisplayOptions | undefined } export function transformDown({ - autopilotData, - contractSetData, - uploadPackingData, - gougingData, - redundancyData, - configAppData, + autopilot, + contractSet, + uploadPacking, + gouging, + redundancy, + display, }: RemoteData): SettingsData { - const configApp = transformDownConfigApp(configAppData) - const redundancy = transformDownRedundancy(redundancyData) + const d = transformDownConfigApp(display) + const r = transformDownRedundancy(redundancy) return { // autopilot - ...transformDownAutopilot(autopilotData), + ...transformDownAutopilot(autopilot), // contractset - ...transformDownContractSet(contractSetData), + ...transformDownContractSet(contractSet), // uploadpacking - ...transformDownUploadPacking(uploadPackingData), + ...transformDownUploadPacking(uploadPacking), // gouging - ...transformDownGouging(gougingData, redundancy, configApp), + ...transformDownGouging(gouging, r, d), // redundancy - ...redundancy, + ...r, // config app - ...configApp, + ...d, } } diff --git a/apps/renterd/contexts/config/types.ts b/apps/renterd/contexts/config/types.ts index 3ab769a94..92a5a6a71 100644 --- a/apps/renterd/contexts/config/types.ts +++ b/apps/renterd/contexts/config/types.ts @@ -30,7 +30,7 @@ export const defaultUploadPacking = { uploadPackingEnabled: true, } -export const defaultConfigApp = { +export const defaultDisplay = { includeRedundancyMaxStoragePrice: true, includeRedundancyMaxUploadPrice: true, } @@ -65,14 +65,14 @@ export const defaultValues = { ...defaultGouging, // redundancy ...defaultRedundancy, - // config app - ...defaultConfigApp, + // config display + ...defaultDisplay, } export type AutopilotData = typeof defaultAutopilot export type ContractSetData = typeof defaultContractSet export type UploadPackingData = typeof defaultUploadPacking -export type ConfigAppData = typeof defaultConfigApp +export type DisplayData = typeof defaultDisplay export type GougingData = typeof defaultGouging export type RedundancyData = typeof defaultRedundancy export type SettingsData = typeof defaultValues @@ -120,8 +120,8 @@ export const advancedDefaultContractSet: ContractSetData = { defaultContractSet: 'autopilot', } -export const advancedDefaultConfigApp: ConfigAppData = { - ...defaultConfigApp, +export const advancedDefaultDisplay: DisplayData = { + ...defaultDisplay, } export const advancedDefaultUploadPacking: UploadPackingData = { @@ -152,7 +152,7 @@ export function getAdvancedDefaults( return { ...getAdvancedDefaultAutopilot(network), ...advancedDefaultContractSet, - ...advancedDefaultConfigApp, + ...advancedDefaultDisplay, ...advancedDefaultUploadPacking, ...advancedDefaultGouging, ...getAdvancedDefaultRedundancy(network), diff --git a/apps/renterd/contexts/config/useOnValid.tsx b/apps/renterd/contexts/config/useOnValid.tsx index 95d1a6b7d..b0c2d40ea 100644 --- a/apps/renterd/contexts/config/useOnValid.tsx +++ b/apps/renterd/contexts/config/useOnValid.tsx @@ -10,7 +10,7 @@ import { import { SettingsData, defaultValues } from './types' import { transformUpAutopilot, - transformUpConfigApp, + transformUpDisplay, transformUpContractSet, transformUpGouging, transformUpRedundancy, @@ -31,7 +31,7 @@ export function useOnValid({ settingUpdate, contractSet, uploadPacking, - configApp, + display, autopilot, autopilotUpdate, }) { @@ -99,7 +99,7 @@ export function useOnValid({ params: { key: configDisplayOptionsKey, }, - payload: transformUpConfigApp(finalValues, configApp.data), + payload: transformUpDisplay(finalValues, display.data), }), ]) @@ -174,7 +174,7 @@ export function useOnValid({ uploadPacking, redundancy, gouging, - configApp, + display, autopilotTrigger, ] ) diff --git a/apps/renterd/contexts/config/useResources.tsx b/apps/renterd/contexts/config/useResources.tsx index 8f6e7a0a4..517b71823 100644 --- a/apps/renterd/contexts/config/useResources.tsx +++ b/apps/renterd/contexts/config/useResources.tsx @@ -39,7 +39,7 @@ export function useResources() { }, }, }) - const configApp = useConfigDisplayOptions({ + const display = useConfigDisplayOptions({ standalone: 'configFormConfigApp', config: { swr: { @@ -105,7 +105,7 @@ export function useResources() { isAutopilotEnabled, autopilot, contractSet, - configApp, + display, gouging, redundancy, uploadPacking,