Thomas Trompette 00b6d651f4 fix(front): preserve currency decimals when opening the field editor (#23874)
Fixes #23828

## Problem

Opening and closing a currency field editor corrupts the stored amount
when the value has more decimals than the field's `decimals` setting
(which defaults to 0). No keystroke is needed.

- With the `1.234,56` number format, `458.64` is persisted back as
`45864`.
- With the `1,234.56` number format, `458.64` is persisted back as
`458`.

## Root cause

The draft amount is serialized with a dot decimal separator
(`amountMicros / 1000000).toString()`), and `CurrencyInput` hands that
string to the IMask `Number` mask with `scale={decimals}` alongside the
workspace `thousandsSeparator` and `radix`. With `scale` 0 and a dot
thousands separator, imask reads `458.64` as `45864`; with a dot radix
it drops the fraction and yields `458`.

That misreading is only half of it. `react-imask` re-emits `accept`
while it formats the value it was given, so **merely mounting the
editor** pushed the mask's own reading of the amount into `internalText`
and into the draft value. From there every exit path persisted it,
escape included. That is why the corruption needs no keystroke.

## Fix

Two layers, smallest first:

1. `CurrencyInput` ignores `accept` events that carry no originating
input event. In imask, `_inputEvent` is set only inside `_onInput` and
deleted right after, so a user keystroke (including the reformat emitted
within the same turn) always carries it, while mount and programmatic
updates never do. The draft can now only change because someone typed.
2. The exit handlers pass `skipPersist` when the resulting value already
matches the stored one, so opening and closing a field writes nothing at
all - no redundant update, no timeline entry.

`getSafeScaleForCurrencyInput` is kept as well: the mask scale is what
makes the editor *display and edit* the right number. Without it, a
`458.64` amount still opens as `45.864`, and a genuine edit would then
build on the wrong base and persist legitimately.

## Tests

Unit tests on both utils, plus an imask round-trip of `458.64` with
`decimals` 0 across all four number formats, which fails on `main` for
both dot-separator formats.

Verified in a local instance against the reported case (`458.64`,
`decimals` 0):

| scenario | result |
|---|---|
| open + close, `1.234,56` | value unchanged, `updatedAt` untouched (no
write at all) |
| open + close, `1,234.56` | value unchanged |
| type a new amount | persists normally |
| type `12.5` on a `decimals` 0 field | yields `125`, separator still
rejected |
2026-08-07 08:48:32 +00:00
2026-06-11 11:02:28 +02:00

Twenty logo

The #1 Open-Source CRM

Website · Documentation · Roadmap · Discord · Figma

Twenty banner


Why Twenty

Twenty gives technical teams the building blocks for a custom CRM that meets complex business needs and quickly adapts as the business evolves. Twenty is the CRM you build, ship, and version like the rest of your stack.

Learn more about why we built Twenty


Installation

Cloud

The fastest way to get started. Sign up at twenty.com and spin up a workspace in under a minute, with no infrastructure to manage and always up to date.

Build an app

Scaffold a new app with the Twenty CLI:

npx create-twenty-app my-app

Define objects, fields, and views as code:

import { defineObject, FieldType } from 'twenty-sdk/define';

export default defineObject({
  nameSingular: 'deal',
  namePlural: 'deals',
  labelSingular: 'Deal',
  labelPlural: 'Deals',
  fields: [
    { name: 'name', label: 'Name', type: FieldType.TEXT },
    { name: 'amount', label: 'Amount', type: FieldType.CURRENCY },
    { name: 'closeDate', label: 'Close Date', type: FieldType.DATE_TIME },
  ],
});

Then ship it to your workspace:

npx twenty app:publish --private

See the app development guide for objects, views, agents, and logic functions.

Self-hosting

Run Twenty on your own infrastructure with Docker Compose, or contribute locally via the local setup guide.



Everything you need

Twenty gives you the building blocks of a modern CRM (objects, views, workflows, and agents) and lets you extend them as code. Here's a tour of what's in the box.

Want to go deeper? Read the User Guide for product walkthroughs, or the Documentation for developer reference.

Create your apps

Learn more about apps in doc

Stay on top with version control

Learn more about version control in doc

All the tools you need to build anything

Learn more about primitives in doc

Customize your layouts

Learn more about layouts in doc

AI agents and chats

Learn more about AI in doc

Plus all the tools of a good CRM

Learn more about CRM features in doc


Stack

Thanks

Greptile      Sentry      Crowdin

Thanks to these amazing services that we use and recommend for code review (Greptile), catching bugs (Sentry) and translating (Crowdin).

Join the Community

Star the repo · Discord · Feature requests · Releases · X · LinkedIn · Crowdin · Contribute

S
Description
The open alternative to Salesforce, designed for AI.
Readme AGPL-3.0 1.4 GiB
Languages
TypeScript 79.6%
MDX 17.3%
JavaScript 2.7%
Python 0.2%
SCSS 0.1%