Skip to content

Commit

Permalink
🧹 Fix types for prompts (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
janjakubnanista authored Jan 26, 2024
1 parent 05fa9fd commit e5d2583
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions packages/build-lz-options/src/utilities/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ const isValidBigInt = (str: string, max: bigint, min: bigint = BigInt(0)): boole
* @param {bigint} max defaults to MAX_UINT_128
* @param {bigint} min defaults to BigInt(0)
*/
const promptForBigInt = (
name: string,
const promptForBigInt = <T extends string = string>(
name: T,
message: string,
initial: bigint = DEFAULT_INITIAL_TEXT_NUMBER,
max: bigint = MAX_UINT_128,
min: bigint = BigInt(0)
): PromptObject<string> => {
): PromptObject<T> => {
// wrapper around prompts to handle bigint using string serialization
return {
onState: handlePromptState,
Expand All @@ -67,17 +67,17 @@ export const promptForOptionType = () =>
},
])

const promptForGasLimit: PromptObject<string> = promptForBigInt('gasLimit', 'What gas limit do you want to set?')
const promptForGasLimit: PromptObject<'gasLimit'> = promptForBigInt('gasLimit', 'What gas limit do you want to set?')

const promptForNativeDropAmount: PromptObject<string> = promptForBigInt(
const promptForNativeDropAmount: PromptObject<'nativeDropAmount'> = promptForBigInt(
'nativeDropAmount',
'What native gas drop do you want to set?'
)

/**
* Prompt for verifier / executor index.
*/
const promptForIndex: PromptObject<string> = {
const promptForIndex: PromptObject<'index'> = {
onState: handlePromptState,
type: 'number',
name: 'index',
Expand All @@ -87,7 +87,7 @@ const promptForIndex: PromptObject<string> = {
max: MAX_UINT_8,
}

const promptForNativeDropAddress: PromptObject<string> = {
const promptForNativeDropAddress: PromptObject<'nativeDropAddress'> = {
onState: handlePromptState,
type: 'text',
name: 'nativeDropAddress',
Expand Down Expand Up @@ -136,6 +136,7 @@ const promptExecutorComposeOption = async (options: Options): Promise<Options> =
promptForGasLimit,
promptForNativeDropAmount,
])

return options.addExecutorComposeOption(index, gasLimit, nativeDropAmount)
}

Expand Down Expand Up @@ -169,17 +170,13 @@ const promptVerifierPrecrimeOption = async (options: Options): Promise<Options>
/**
* Helper function to prompt for OptionType.TYPE_1.
*/
export const promptForOptionType1 = () => prompts([promptForGasLimit]) as never as Promise<OptionType1Summary>
export const promptForOptionType1 = (): Promise<OptionType1Summary> => prompts(promptForGasLimit)

/**
* Helper function to prompt for OptionType.TYPE_2.
*/
export const promptForOptionType2 = (): Promise<OptionType2Summary> =>
prompts([
promptForGasLimit,
promptForNativeDropAmount,
promptForNativeDropAddress,
]) as never as Promise<OptionType2Summary>
prompts([promptForGasLimit, promptForNativeDropAmount, promptForNativeDropAddress])

const determineWorkerType = async (options: Options): Promise<Options> => {
const workerType = await promptForWorkerType()
Expand Down

0 comments on commit e5d2583

Please sign in to comment.