Skip to content

fix(frontend): respect asset precision for full loan repayment - #1

Open
freebuff-web[bot] wants to merge 1 commit into
mainfrom
fix/1488-loan-repayment-full-amount-precision
Open

fix(frontend): respect asset precision for full loan repayment#1
freebuff-web[bot] wants to merge 1 commit into
mainfrom
fix/1488-loan-repayment-full-amount-precision

Conversation

@freebuff-web

@freebuff-web freebuff-web Bot commented Aug 31, 2026

Copy link
Copy Markdown

Closes LabsCrypt#1488

Summary

Add regression tests for the handlePayFullAmount precision fix in LoanRepaymentForm.

What was wrong

handlePayFullAmount previously formatted totalOwed with a hardcoded .toFixed(7) regardless of asset. For a 2-decimal asset like USDC, this produced values with up to 7 fractional digits, which the form's own getPrecisionError validation rejected — disabling the submit button even after clicking "Pay Full Amount".

What changed

The code fix (already present on main) replaces the hardcoded 7 with getAssetDecimals("USDC"), so totalOwed is formatted to the asset's actual precision (2 decimals for USDC).

This PR adds 6 regression tests covering:

  1. totalOwed with >2 decimal places fills a value that satisfies USDC precision validation
  2. Formats to exactly 2 decimal places for USDC
  3. Strips trailing zeros after formatting
  4. Submit button stays enabled after clicking Pay Full Amount
  5. Previous validation errors are cleared when Pay Full Amount is clicked
  6. Many-decimal totalOwed is correctly truncated to 2 decimals

How the fix works

handlePayFullAmount now calls:

setAmount(totalOwed.toFixed(getAssetDecimals("USDC")).replace(/\.?0+$/, ""));

This ensures the formatted value never exceeds the asset's decimal limit, so getPrecisionError(amount, "USDC") returns null and the submit button remains enabled.

Tests added

  • frontend/src/app/components/borrower/LoanRepaymentForm.test.tsx (6 tests)

Validation

  • ✅ All 238 tests pass (including 6 new tests)
  • ✅ Prettier formatting check passes
  • ℹ️ Pre-existing TypeScript errors in useRepaymentOperation.ts (not related to this change)

Generated with Codebuff 🤖
Co-Authored-By: Codebuff noreply@codebuff.com

Add regression tests for LabsCrypt#1488 covering handlePayFullAmount behaviour:
- totalOwed with >2 decimals is formatted to USDC's 2-decimal precision
- trailing zeros are stripped after toFixed
- submit button stays enabled after Pay Full Amount click
- previous validation errors are cleared
- many-decimal totalOwed is truncated correctly

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
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.

[Frontend] LoanRepaymentForm 'Pay Full Amount' can produce a value the form then rejects

1 participant