W10-C4: Book leg amount input accepts invalid characters and surfaces raw BigInt conversion error #169

Closed
opened 2026-05-19 08:56:31 +00:00 by totdking · 6 comments
totdking commented 2026-05-19 08:56:31 +00:00 (Migrated from gitlab.com)
No description provided.
totdking commented 2026-05-19 08:58:56 +00:00 (Migrated from gitlab.com)

Issue Summary

In the Swap page's advanced routing panel, typing any non-numeric, non-period character (e.g. ,, ^) into the Book leg amount field triggers an unhandled JavaScript exception that is passed directly to the UI. The field performs no input-level validation and the error copy (Cannot convert 4^000000 to a BigInt) is a raw internal JS error with no user-actionable meaning.


Reproduction Steps

  1. Complete full local setup (LocalTerra running, contracts deployed, indexer running, frontend running)
  2. Connect a wallet configured for the local network
  3. Navigate to /swap and select any token pair
  4. Tick the "Route part of input through the limit book" checkbox in the ADVANCED panel
  5. In the Book leg amount (EMBER) field, type any non-period character : e.g. ,, ^, \
  6. Observe the error displayed in the UI

Expected Behavior

The input field should accept only valid numeric characters (digits and a single period as decimal separator). Any other character should be rejected at the field level with no error shown, or replaced silently. no toast, no modal, no exception. If validation must be deferred, the error copy should be human-readable (e.g. "Please enter a valid number").


Actual Behavior

Typing , or another invalid character is accepted by the field. The value is passed through to a BigInt() conversion without sanitisation. The browser surfaces the following error in a toast or error overlay:

Something went wrong
Cannot convert 4\000000 to a BigInt

The ^000 in the message is a null byte artefact of how the invalid character is transformed before the conversion is attempted. The error copy is an unhandled internal JS exception with no translation or user-actionable guidance.


Screen record

Screen Recording 2026-05-19 at 10.00.50.mov


Environment Details

Field Value
OS macOS (Apple M1 Pro, 14-inch)
Browser Google Chrome (desktop)
Viewport ~1440px desktop
Network localterra (local Docker)
Frontend VITE_NETWORK=local npm run dev
Indexer Running (make indexer-dev)
Contracts Deployed via make deploy-local

Wallet / Device Details

  • Wallet: Connected — localterra
  • Page: /swap — ADVANCED: DIRECT SWAP: LIMIT BOOK LEG panel

Severity / Impact

P2 Polish. No funds are at risk, the field value is rejected before any transaction is submitted. However two issues are present:

(1) the input accepts invalid characters that should be blocked at the field level;

(2) the resulting error is a raw JS exception (Cannot convert 4\000000 to a BigInt) with no human-readable fallback.

The comma case is also a practical locale issue; European traders naturally use , as a decimal separator and will trigger this error on normal input. Found under W10-C4 (Locale / number format — Interactivity and Trader use dimensions) and W11-C1 (Error copy quality).

cc: @PlasticDigits

### Issue Summary In the Swap page's advanced routing panel, typing any non-numeric, non-period character (e.g. `,`, `^`) into the **Book leg amount** field triggers an unhandled JavaScript exception that is passed directly to the UI. The field performs no input-level validation and the error copy (`Cannot convert 4^000000 to a BigInt`) is a raw internal JS error with no user-actionable meaning. --- ### Reproduction Steps 1. Complete full local setup (LocalTerra running, contracts deployed, indexer running, frontend running) 2. Connect a wallet configured for the local network 3. Navigate to `/swap` and select any token pair 4. Tick the **"Route part of input through the limit book"** checkbox in the ADVANCED panel 5. <span dir="">In the **Book leg amount (EMBER)** field, type any non-period character : e.g. `,`, `^`, </span>`\` 6. Observe the error displayed in the UI --- ### Expected Behavior The input field should accept only valid numeric characters (digits and a single period as decimal separator). Any other character should be rejected at the field level with no error shown, or replaced silently. no toast, no modal, no exception. If validation must be deferred, the error copy should be human-readable (e.g. _"Please enter a valid number"_). --- ### Actual Behavior Typing `,` or another invalid character is accepted by the field. The value is passed through to a `BigInt()` conversion without sanitisation. The browser surfaces the following error in a toast or error overlay: ``` Something went wrong Cannot convert 4\000000 to a BigInt ``` The `^000` in the message is a null byte artefact of how the invalid character is transformed before the conversion is attempted. The error copy is an unhandled internal JS exception with no translation or user-actionable guidance. --- ## Screen record ![Screen Recording 2026-05-19 at 10.00.50.mov](/uploads/ec08c18bbeb1f0330fd3dc4c15ad0a3b/Screen_Recording_2026-05-19_at_10.00.50.mov) --- ### Environment Details | Field | Value | |-------|-------| | OS | macOS (Apple M1 Pro, 14-inch) | | Browser | Google Chrome (desktop) | | Viewport | \~1440px desktop | | Network | `localterra` (local Docker) | | Frontend | `VITE_NETWORK=local npm run dev` | | Indexer | Running (`make indexer-dev`) | | Contracts | Deployed via `make deploy-local` | --- ### Wallet / Device Details - **Wallet:** Connected — localterra - **Page:** `/swap` — ADVANCED: DIRECT SWAP: LIMIT BOOK LEG panel --- ### Severity / Impact **P2 Polish.** No funds are at risk, the field value is rejected before any transaction is submitted. However two issues are present: (1) the input accepts invalid characters that should be blocked at the field level; (2) the resulting error is a raw JS exception (`Cannot convert 4\000000 to a BigInt`) with no human-readable fallback. The comma case is also a practical locale issue; European traders naturally use `,` as a decimal separator and will trigger this error on normal input. Found under **W10-C4** (Locale / number format — Interactivity and Trader use dimensions) and **W11-C1** (Error copy quality). cc: @PlasticDigits
PlasticDigits commented 2026-05-20 04:20:46 +00:00 (Migrated from gitlab.com)

mentioned in commit d177d8318e

mentioned in commit d177d8318e33a532bdeb48f543d99a7ff8c8237b
PlasticDigits commented 2026-05-20 04:20:52 +00:00 (Migrated from gitlab.com)

Fix shipped on main (d177d83)

Book leg amount fields now use the same controlled decimal draft validation as Swap You Pay: only digits and at most one . are accepted at onChange. Invalid keys (e.g. ,, ^, \) are rejected silently — no toast, modal, or raw Cannot convert … to a BigInt errors.

Changes

  • Shared helpers: frontend-dapp/src/utils/decimalAmountInput.ts (isDecimalAmountDraft, tryParseBigInt)
  • Swap Settings → Book leg amount (SwapPage.tsx)
  • Trade market → Book leg override (TradeMarketOrderPanel.tsx)
  • Defense in depth: getDirectHybridBookSplit / trade hybrid params return null instead of throwing on invalid drafts
  • Docs: frontend.md § Decimal amount inputs, limit-orders.md, agent skill skills/AGENTS_FRONTEND_DECIMAL_AMOUNT_INPUT.md
  • Unit tests: decimalAmountInput.test.ts, swapDisclosure.test.ts, SwapPage.test.tsx

Verification checklist

  • Local stack: LocalTerra + contracts + indexer + VITE_NETWORK=local npm run dev
  • /swap → Settings → enable Route part of input through the limit book
  • In Book leg amount, type ,, ^, \ — field must not accept them; no error overlay/toast
  • Type valid 0.01 with pay amount set — hybrid disclosure / quote still works
  • /trade → Market tab → hybrid book override field: same rejection for invalid chars
  • cd frontend-dapp && npm test -- --run src/utils/decimalAmountInput.test.ts src/utils/swapDisclosure.test.ts src/pages/SwapPage.test.tsx

@totdking — please verify on your M1 / Chrome local setup when convenient. Leaving the issue open until QA sign-off.

/cc @PlasticDigits

## Fix shipped on `main` (`d177d83`) **Book leg amount** fields now use the same controlled decimal draft validation as Swap **You Pay**: only digits and at most one `.` are accepted at `onChange`. Invalid keys (e.g. `,`, `^`, `\`) are rejected silently — no toast, modal, or raw `Cannot convert … to a BigInt` errors. ### Changes - Shared helpers: `frontend-dapp/src/utils/decimalAmountInput.ts` (`isDecimalAmountDraft`, `tryParseBigInt`) - **Swap** Settings → Book leg amount (`SwapPage.tsx`) - **Trade** market → Book leg override (`TradeMarketOrderPanel.tsx`) - Defense in depth: `getDirectHybridBookSplit` / trade hybrid params return `null` instead of throwing on invalid drafts - Docs: [frontend.md § Decimal amount inputs](docs/frontend.md#decimal-amount-inputs), [limit-orders.md](docs/limit-orders.md), agent skill [`skills/AGENTS_FRONTEND_DECIMAL_AMOUNT_INPUT.md`](skills/AGENTS_FRONTEND_DECIMAL_AMOUNT_INPUT.md) - Unit tests: `decimalAmountInput.test.ts`, `swapDisclosure.test.ts`, `SwapPage.test.tsx` ### Verification checklist - [ ] Local stack: LocalTerra + contracts + indexer + `VITE_NETWORK=local npm run dev` - [ ] `/swap` → Settings → enable **Route part of input through the limit book** - [ ] In **Book leg amount**, type `,`, `^`, `\` — field must not accept them; **no** error overlay/toast - [ ] Type valid `0.01` with pay amount set — hybrid disclosure / quote still works - [ ] `/trade` → Market tab → hybrid book override field: same rejection for invalid chars - [ ] `cd frontend-dapp && npm test -- --run src/utils/decimalAmountInput.test.ts src/utils/swapDisclosure.test.ts src/pages/SwapPage.test.tsx` @totdking — please verify on your M1 / Chrome local setup when convenient. Leaving the issue **open** until QA sign-off. /cc @PlasticDigits
totdking commented 2026-05-20 05:10:44 +00:00 (Migrated from gitlab.com)

mentioned in issue #116

mentioned in issue #116
PlasticDigits commented 2026-05-27 05:38:42 +00:00 (Migrated from gitlab.com)

QA verification complete (agent)

Verified fix already on main — no additional code changes required.

Environment

Verification checklist

  • Local stack running (LocalTerra + contracts + indexer + frontend)
  • /swap → Settings → Route part of input through the limit book enabled
  • Book leg amount: typed ,, ^, \ — invalid chars rejected silently; no error overlay/toast
  • Valid 0.01 with pay amount 1.0 — hybrid disclosure shows pool/book split correctly
  • /trade → Market tab → Book leg override: same silent rejection for ,
  • Unit tests: decimalAmountInput.test.ts, swapDisclosure.test.ts, SwapPage.test.tsx — 15/15 passed

Closing as verified.

## QA verification complete (agent) Verified fix already on `main` — no additional code changes required. ### Environment - LocalTerra: healthy (block ~36386) - Postgres: host service on `:5432` - Indexer: healthy at http://127.0.0.1:3001 - Frontend: http://127.0.0.1:3000 (`VITE_NETWORK=local`) - Bot swarm: 30/30 workers alive ### Verification checklist - [x] Local stack running (LocalTerra + contracts + indexer + frontend) - [x] `/swap` → Settings → **Route part of input through the limit book** enabled - [x] **Book leg amount**: typed `,`, `^`, `\` — invalid chars rejected silently; no error overlay/toast - [x] Valid `0.01` with pay amount `1.0` — hybrid disclosure shows pool/book split correctly - [x] `/trade` → Market tab → **Book leg override**: same silent rejection for `,` - [x] Unit tests: `decimalAmountInput.test.ts`, `swapDisclosure.test.ts`, `SwapPage.test.tsx` — 15/15 passed Closing as verified.
PlasticDigits (Migrated from gitlab.com) closed this issue 2026-05-27 05:38:47 +00:00
PlasticDigits commented 2026-05-29 03:15:18 +00:00 (Migrated from gitlab.com)

mentioned in issue #213

mentioned in issue #213
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
code/cl8y-dex-terraclassic#169
No description provided.