Skip to content

Conversation

@pasevin
Copy link
Collaborator

@pasevin pasevin commented Oct 10, 2025

Summary

Fixes #194

This PR introduces a new BigInt field type to safely handle large integers beyond JavaScript's Number.MAX_SAFE_INTEGER (2^53-1), preventing precision loss for values like uint256.

Changes

🆕 New Components

  • BigIntField.tsx (250 lines): Dedicated component for large integer handling with built-in validation
  • createBigIntTransform(): Transform function that keeps values as strings to avoid precision loss

🔧 Core Updates

  • Added 'bigint' to FieldType union
  • Registered in field registry and added to field type dropdown (Numeric category)
  • Updated getDefaultValueForType() to support bigint fields

🌐 Adapter Changes (EVM & Stellar)

  • EVM: Map 64-bit+ integers → bigint (uint64, uint128, uint256, int64, int128, int256)
  • Stellar: Map 64-bit+ integers → bigint (U64, U128, U256, I64, I128, I256)
  • Updated compatibility mappings to prioritize bigint as recommended type
  • Simplified field generation by removing redundant validation logic

🧪 Testing

  • Added 239 lines of new adapter tests
  • Updated integration tests for bigint transforms
  • All 940+ tests passing

Architecture Benefits

Chain-Agnostic Core - No blockchain-specific logic in core components
DRY Principle - Validation defined once in component
Type Safety - Proper TypeScript typing throughout
Separation of Concerns - Adapters map types, components handle UI/validation

Breaking Changes

⚠️ Large integer types (64-bit+) now map to 'bigint' field type instead of 'number'
⚠️ BigInt values stored/transmitted as strings to prevent precision loss

Changeset Included

✅ Comprehensive changeset documenting all package changes and version bumps

- Add new BigIntField component with integer-only validation
- Map 64-bit+ integers to bigint field type (EVM: uint64/128/256, Stellar: U64/128/256)
- Add createBigIntTransform() for string-based value handling
- Update field type dropdown to include bigint in numeric category
- Simplify adapter field generation by removing redundant validation
- Update all tests for new bigint mappings

Fixes #194
@pasevin pasevin requested a review from a team as a code owner October 10, 2025 13:21
@pasevin pasevin requested a review from Copilot October 10, 2025 13:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new BigInt field type to safely handle large integers beyond JavaScript's Number.MAX_SAFE_INTEGER (2^53-1), preventing precision loss for blockchain integer types like uint256.

  • Adds dedicated BigIntField component with built-in validation for large integer inputs
  • Updates EVM and Stellar adapters to map 64-bit+ integers to bigint field type
  • Implements string-based storage to avoid JavaScript Number precision limitations

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/types/src/forms/fields.ts Adds bigint to FieldType union and value mapping
packages/ui/src/components/fields/BigIntField.tsx New component for large integer input with validation
packages/ui/src/components/fields/index.ts Exports BigIntField component
packages/renderer/src/utils/formUtils.ts Adds createBigIntTransform for string-based transforms
packages/renderer/src/components/fieldRegistry.ts Registers BigIntField in component registry
packages/utils/src/fieldDefaults.ts Adds bigint case to getDefaultValueForType
packages/adapter-evm/src/mapping/constants.ts Maps 64-bit+ integer types to bigint
packages/adapter-stellar/src/mapping/constants.ts Maps 64-bit+ integer types to bigint
Multiple test files Updates tests to reflect bigint mapping changes
packages/builder/src/components/UIBuilder/StepFormCustomization/utils/fieldTypeUtils.ts Adds bigint to field type labels and groups

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

- Replace fragile pattern string comparison with direct value testing
  in validation.ts
- Remove duplicated integer validation logic in BigIntField by using
  pattern property instead
- Introduce consistent regex constants (INTEGER_PATTERN for validation,
  INTEGER_INPUT_PATTERN for input)
- Simplify validation flow by delegating pattern validation to
  validateField utility

All tests passing ✅
@pasevin pasevin requested a review from Copilot October 10, 2025 13:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

- Create integerValidation.ts with shared pattern constants
  (INTEGER_PATTERN, INTEGER_INPUT_PATTERN, INTEGER_HTML_PATTERN)
- Update validation.ts to use shared INTEGER_PATTERN constant
- Update BigIntField.tsx to use all shared constants
- Ensures consistency across validation logic and HTML attributes

Addresses Copilot review feedback about pattern duplication and
inconsistency between JavaScript patterns and HTML pattern attribute.

All tests passing ✅
@pasevin pasevin merged commit 68c0aed into main Oct 10, 2025
11 checks passed
@pasevin pasevin deleted the feat/bigint-field-type-for-large-integers branch October 10, 2025 13:50
@oz-release-app oz-release-app bot mentioned this pull request Oct 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] uint256 input truncation

2 participants