fix(frontend): respect asset precision for full loan repayment - #1
Open
freebuff-web[bot] wants to merge 1 commit into
Open
fix(frontend): respect asset precision for full loan repayment#1freebuff-web[bot] wants to merge 1 commit into
freebuff-web[bot] wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes LabsCrypt#1488
Summary
Add regression tests for the
handlePayFullAmountprecision fix inLoanRepaymentForm.What was wrong
handlePayFullAmountpreviously formattedtotalOwedwith 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 owngetPrecisionErrorvalidation rejected — disabling the submit button even after clicking "Pay Full Amount".What changed
The code fix (already present on
main) replaces the hardcoded7withgetAssetDecimals("USDC"), sototalOwedis formatted to the asset's actual precision (2 decimals for USDC).This PR adds 6 regression tests covering:
totalOwedwith >2 decimal places fills a value that satisfies USDC precision validationtotalOwedis correctly truncated to 2 decimalsHow the fix works
handlePayFullAmountnow calls:This ensures the formatted value never exceeds the asset's decimal limit, so
getPrecisionError(amount, "USDC")returnsnulland the submit button remains enabled.Tests added
frontend/src/app/components/borrower/LoanRepaymentForm.test.tsx(6 tests)Validation
useRepaymentOperation.ts(not related to this change)Generated with Codebuff 🤖
Co-Authored-By: Codebuff noreply@codebuff.com