Skip to content

fix(frontend): avoid float precision errors in liquidity dialog - #3989

Open
Gous0786 wants to merge 1 commit into
interledger:mainfrom
Gous0786:fix/liquidity-dialog-float-precision
Open

Gous0786 wants to merge 1 commit into
interledger:mainfrom
Gous0786:fix/liquidity-dialog-float-precision

Conversation

@Gous0786

@Gous0786 Gous0786 commented Oct 4, 2026

Copy link
Copy Markdown

Signed-off-by: Gous0786 gousalam0786@gmail.com

Changes proposed in this pull request

  • Add a parseAmount(input, scale) helper in app/shared/utils.ts that converts a user-entered decimal amount to asset base units with string arithmetic and BigInt, instead of parseFloat(input) * 10^scale.
  • Use parseAmount in LiquidityDialog, and keep the amount as a string so large values are no longer serialized as 5e+21.
  • Reject 0 in the dialog (it previously passed the client check and failed on the server).
  • Fix the "accomodate" typo in the validation message.

Context

fixes #3986

The liquidity dialog (used for asset and peer deposit/withdraw liquidity) rejected valid amounts because of floating-point error. For example, at scale 2, parseFloat('0.29') * 100 is 28.999999999999996, so 0.29 was rejected with "The asset scale cannot accomodate this value" while 1.29 was accepted. About 11% of 2-decimal amounts between 0.00 and 99.99 were affected. The backend accepts these amounts (amount: UInt64!), so only the frontend conversion was wrong.

The new helper parses the input as text, splits on ., rejects it if the fractional part is longer than asset.scale, and builds the amount from the digits:

How to test

  1. pnpm localenv:compose:psql up -d
  2. Open the Admin UI at http://localhost:3010 as the operator
  3. Go to Assets → USD → Deposit liquidity
  4. Enter 0.29: there is no error, and the deposit succeeds with exactly 29 base units
  5. Enter 0.291: the scale error is still shown

Before :
Screenshot 2026-10-03 130950

After
Screenshot 2026-10-04 141100

Checklist

  • Related issues linked using fixes #number
  • Tests added/updated
  • Make sure that all checks pass
  • Bruno collection updated (if necessary)
  • Documentation issue created with user-docs label (if necessary)
  • OpenAPI specs updated (if necessary)

Signed-off-by: Gous0786 <gousalam0786@gmail.com>
@netlify

netlify Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for brilliant-pasca-3e80ec canceled.

Name Link
🔨 Latest commit 183d7d9
🔍 Latest deploy log https://app.netlify.com/projects/brilliant-pasca-3e80ec/deploys/6ac215e6973e6b000743fb9f

@github-actions github-actions Bot added the pkg: frontend Changes in the frontend package. label Oct 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: frontend Changes in the frontend package.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Liquidity dialog rejects valid amounts (e.g. 0.29) due to floating-point conversion

1 participant