( options: ParsedOptions, tokenDisplay: string, inputTypeOverride: ValueInputType | undefined, quiet: boolean, )
| 466 | } |
| 467 | |
| 468 | function resolveNumericInput( |
| 469 | options: ParsedOptions, |
| 470 | tokenDisplay: string, |
| 471 | inputTypeOverride: ValueInputType | undefined, |
| 472 | quiet: boolean, |
| 473 | ): { |
| 474 | inputTypeOverride?: ValueInputType; |
| 475 | numericConfig?: NumericInputConfig; |
| 476 | sliderConfig?: SliderConfig; |
| 477 | } { |
| 478 | if (inputTypeOverride !== "number" && inputTypeOverride !== "slider") { |
| 479 | if (hasNumericConfig(options) && !quiet) { |
| 480 | log.logWarning( |
| 481 | `QuickAdd: Ignoring numeric range options in "${tokenDisplay}" because type is not number or slider.`, |
| 482 | ); |
| 483 | } |
| 484 | return { inputTypeOverride }; |
| 485 | } |
| 486 | |
| 487 | if (inputTypeOverride !== "slider") { |
| 488 | const numericConfig = buildNumericConfig(options, tokenDisplay, quiet); |
| 489 | return { inputTypeOverride, numericConfig }; |
| 490 | } |
| 491 | |
| 492 | const min = parseFiniteNumber(options.minRaw); |
| 493 | const max = parseFiniteNumber(options.maxRaw); |
| 494 | const step = options.stepRaw === undefined |
| 495 | ? 1 |
| 496 | : parseFiniteNumber(options.stepRaw); |
| 497 | const invalidReason = |
| 498 | min === undefined || max === undefined |
| 499 | ? "slider requires finite min and max values" |
| 500 | : max <= min |
| 501 | ? "max must be greater than min" |
| 502 | : step === undefined || step <= 0 |
| 503 | ? "step must be greater than 0" |
| 504 | : undefined; |
| 505 | |
| 506 | if (invalidReason) { |
| 507 | if (!quiet) { |
| 508 | log.logWarning( |
| 509 | `QuickAdd: Invalid slider configuration in "${tokenDisplay}" (${invalidReason}); falling back to type:number.`, |
| 510 | ); |
| 511 | } |
| 512 | const numericConfig = buildNumericConfig(options, tokenDisplay, true); |
| 513 | return { inputTypeOverride: "number", numericConfig }; |
| 514 | } |
| 515 | |
| 516 | const sliderConfig: SliderConfig = { |
| 517 | min: min as number, |
| 518 | max: max as number, |
| 519 | step: step as number, |
| 520 | }; |
| 521 | return { |
| 522 | inputTypeOverride, |
| 523 | numericConfig: sliderConfig, |
| 524 | sliderConfig, |
| 525 | }; |
no test coverage detected