-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(renterd): typescript strict mode for config feature
- Loading branch information
1 parent
d710788
commit 93b720f
Showing
28 changed files
with
785 additions
and
547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import { | ||
AutopilotSubmitValues, | ||
AutopilotFieldValues, | ||
UploadFieldValues, | ||
PinnedFieldValues, | ||
GougingFieldValues, | ||
AllFieldValues, | ||
UploadSubmitValues, | ||
PinnedSubmitValues, | ||
GougingSubmitValues, | ||
AllSubmitValues, | ||
} from './types' | ||
|
||
export function assertSubmitValuesAutopilot( | ||
values: AutopilotFieldValues | ||
): AutopilotSubmitValues { | ||
if (values.allowanceMonth === undefined) { | ||
throw new Error('allowanceMonth is required') | ||
} | ||
if (values.downloadTBMonth === undefined) { | ||
throw new Error('downloadTBMonth is required') | ||
} | ||
if (values.storageTB === undefined) { | ||
throw new Error('storageTB is required') | ||
} | ||
if (values.uploadTBMonth === undefined) { | ||
throw new Error('uploadTBMonth is required') | ||
} | ||
|
||
return { | ||
...values, | ||
amountHosts: values.amountHosts, | ||
periodWeeks: values.periodWeeks, | ||
allowanceMonth: values.allowanceMonth, | ||
downloadTBMonth: values.downloadTBMonth, | ||
maxConsecutiveScanFailures: values.maxConsecutiveScanFailures, | ||
maxDowntimeHours: values.maxDowntimeHours, | ||
renewWindowWeeks: values.renewWindowWeeks, | ||
storageTB: values.storageTB, | ||
uploadTBMonth: values.uploadTBMonth, | ||
} | ||
} | ||
|
||
export function assertSubmitValuesUpload( | ||
values: UploadFieldValues | ||
): UploadSubmitValues { | ||
return { | ||
...values, | ||
defaultContractSet: values.defaultContractSet, | ||
minShards: values.minShards, | ||
totalShards: values.totalShards, | ||
} | ||
} | ||
|
||
export function assertSubmitValuesPinned( | ||
values: PinnedFieldValues | ||
): PinnedSubmitValues { | ||
if (values.pinnedThreshold === undefined) { | ||
throw new Error('pinnedThreshold is required') | ||
} | ||
if (values.allowanceMonthPinned === undefined) { | ||
throw new Error('allowanceMonthPinned is required') | ||
} | ||
if (values.maxStoragePriceTBMonthPinned === undefined) { | ||
throw new Error('maxStoragePriceTBMonthPinned is required') | ||
} | ||
if (values.maxUploadPriceTBPinned === undefined) { | ||
throw new Error('maxUploadPriceTBPinned is required') | ||
} | ||
if (values.maxDownloadPriceTBPinned === undefined) { | ||
throw new Error('maxDownloadPriceTBPinned is required') | ||
} | ||
return { | ||
...values, | ||
pinnedThreshold: values.pinnedThreshold, | ||
allowanceMonthPinned: values.allowanceMonthPinned, | ||
maxStoragePriceTBMonthPinned: values.maxStoragePriceTBMonthPinned, | ||
maxUploadPriceTBPinned: values.maxUploadPriceTBPinned, | ||
maxDownloadPriceTBPinned: values.maxDownloadPriceTBPinned, | ||
} | ||
} | ||
|
||
export function assertSubmitValuesGouging( | ||
values: GougingFieldValues | ||
): GougingSubmitValues { | ||
if (values.maxRPCPriceMillion === undefined) { | ||
throw new Error('maxRPCPriceMillion is required') | ||
} | ||
if (values.maxStoragePriceTBMonth === undefined) { | ||
throw new Error('maxStoragePriceTBMonth is required') | ||
} | ||
if (values.maxContractPrice === undefined) { | ||
throw new Error('maxContractPrice is required') | ||
} | ||
if (values.maxDownloadPriceTB === undefined) { | ||
throw new Error('maxDownloadPriceTB is required') | ||
} | ||
if (values.maxUploadPriceTB === undefined) { | ||
throw new Error('maxUploadPriceTB is required') | ||
} | ||
if (values.hostBlockHeightLeeway === undefined) { | ||
throw new Error('hostBlockHeightLeeway is required') | ||
} | ||
if (values.minPriceTableValidityMinutes === undefined) { | ||
throw new Error('minPriceTableValidityMinutes is required') | ||
} | ||
if (values.minAccountExpiryDays === undefined) { | ||
throw new Error('minAccountExpiryDays is required') | ||
} | ||
if (values.minMaxEphemeralAccountBalance === undefined) { | ||
throw new Error('minMaxEphemeralAccountBalance is required') | ||
} | ||
if (values.migrationSurchargeMultiplier === undefined) { | ||
throw new Error('migrationSurchargeMultiplier is required') | ||
} | ||
return { | ||
...values, | ||
maxRPCPriceMillion: values.maxRPCPriceMillion, | ||
maxStoragePriceTBMonth: values.maxStoragePriceTBMonth, | ||
maxContractPrice: values.maxContractPrice, | ||
maxDownloadPriceTB: values.maxDownloadPriceTB, | ||
maxUploadPriceTB: values.maxUploadPriceTB, | ||
hostBlockHeightLeeway: values.hostBlockHeightLeeway, | ||
minPriceTableValidityMinutes: values.minPriceTableValidityMinutes, | ||
minAccountExpiryDays: values.minAccountExpiryDays, | ||
minMaxEphemeralAccountBalance: values.minMaxEphemeralAccountBalance, | ||
migrationSurchargeMultiplier: values.migrationSurchargeMultiplier, | ||
} | ||
} | ||
|
||
export function assertSubmitValuesAll(values: AllFieldValues): AllSubmitValues { | ||
return { | ||
...assertSubmitValuesAutopilot(values), | ||
...assertSubmitValuesUpload(values), | ||
...assertSubmitValuesPinned(values), | ||
...assertSubmitValuesGouging(values), | ||
} | ||
} |
Oops, something went wrong.