Skip to content

Load Contract step requires fields to be filled in specific order #235

@pasevin

Description

@pasevin

Problem Description

The "Load Contract" step in the UI Builder wizard has a field dependency issue that prevents users from progressing to the next step if they don't fill required fields in a specific top-down sequence.

Affected Adapter

This issue is most clearly manifested in the Midnight adapter, which requires three fields:

  1. Contract Address
  2. Private State ID
  3. Contract Artifacts ZIP file

Expected Behavior

Users should be able to fill these fields in any order and have the contract parsing trigger automatically once all required fields are present, enabling the Next button.

Actual Behavior

The Next button only enables (and parsing only triggers) if fields are filled in this exact sequence:

  1. Address → 2. Private State ID → 3. Artifacts ZIP

If fields are filled in a different order (e.g., Artifacts ZIP → Private State ID → Address), the parsing does not trigger and the Next button remains disabled, preventing progression.

Impact

  • User Experience: Users are forced to follow a specific field-filling order, which is unintuitive and frustrating
  • Scope: While most evident in the Midnight adapter, this may be a UI Builder-wide issue affecting any adapter with multiple required contract definition inputs

Technical Context

Key Components Involved

  • useAutoContractLoad hook - triggers automatic contract loading based on form state changes
  • useFormSync hook - synchronizes form values to the store and manages the needsContractDefinitionLoad flag
  • hasMissingRequiredContractInputs utility - validates that all adapter-declared required inputs are present
  • Form validation logic that checks formState.isValid and required field presence

Relevant Files

  • packages/builder/src/components/UIBuilder/StepContractDefinition/hooks/useAutoContractLoad.ts
  • packages/builder/src/components/UIBuilder/StepContractDefinition/hooks/useFormSync.ts
  • packages/builder/src/components/UIBuilder/StepContractDefinition/hooks/useContractForm.ts
  • packages/utils/src/contractInputs.ts

Requirements for Fix

The fix must work correctly in all scenarios:

  1. Fresh submission: User fills fields in any order → parsing triggers when all fields are complete
  2. Later amendments: User changes previously entered values → parsing re-triggers appropriately without breaking reactivity

Critical Constraints

  • Must not break existing reactivity when users modify already-entered values
  • Must maintain proper debouncing behavior to avoid excessive API calls
  • Must preserve the circuit breaker logic that prevents duplicate loads
  • Must handle edge cases like form resets, network changes, and configuration loading

Investigation Needed

A thorough analysis is required to understand:

  1. Why the needsContractDefinitionLoad flag is not being set correctly when fields are filled out of order
  2. How debounced values interact with the flag-setting logic
  3. Whether there are race conditions between different effects that sync form state
  4. How the validation logic determines when all required fields are present vs. when parsing should trigger

Notes

  • This is a delicate issue - a naive fix could break reactivity in amendment scenarios
  • The issue may affect other adapters beyond Midnight, so the fix should be chain-agnostic
  • No solution should be assumed until thorough analysis is complete

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingmidnightMidnight Ecosystem Related Issues

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions