fix(trade): limit decimal places for trade inputs#6445
Open
SeniorZhai wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a decimal-place limiting mechanism across swap, limit order, and perps trade inputs to prevent users (and programmatic setters like “Max/percent”) from entering amounts with excessive precision.
Changes:
- Introduces shared helpers to cap/truncate decimal places and wires them into the shared
InputContent/InputAreacomponents. - Applies decimal limiting to swap + limit order amount flows (including reverse switch, max, and preset percent actions).
- Adds perps amount decimal limiting (2 dp) and normalizes the TP/SL initial price input before deriving the percent field.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| app/src/main/java/one/mixin/android/ui/home/web3/trade/SwapContent.kt | Limits swap amount input precision based on token and applies it to max/percent/reverse flows. |
| app/src/main/java/one/mixin/android/ui/home/web3/trade/perps/PerpsTpSlBottomSheetDialogFragment.kt | Normalizes initial TP/SL price input before initializing derived percent field. |
| app/src/main/java/one/mixin/android/ui/home/web3/trade/perps/PerpsFormat.kt | Adds a shared constant for perps amount max decimal places (2). |
| app/src/main/java/one/mixin/android/ui/home/web3/trade/perps/PerpsAddBottomSheetDialogFragment.kt | Applies perps amount decimal limiting to input, balance-fill, and percent actions. |
| app/src/main/java/one/mixin/android/ui/home/web3/trade/perps/OpenPositionPage.kt | Applies perps amount decimal limiting to input, balance-fill, and percent actions. |
| app/src/main/java/one/mixin/android/ui/home/web3/trade/LimitOrderContent.kt | Limits decimal places for limit order in/out amount inputs and derived calculations. |
| app/src/main/java/one/mixin/android/ui/home/web3/trade/InputTextField.kt | Adds decimal limiting/validation helpers and plumbs maxDecimalPlaces through the shared input component. |
| app/src/main/java/one/mixin/android/ui/home/web3/components/PriceInputArea.kt | Caps limit price input decimal places via the shared input. |
| app/src/main/java/one/mixin/android/ui/home/web3/components/InputArea.kt | Passes maxDecimalPlaces down into InputContent. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+71
to
+74
| internal fun SwapToken?.tradeInputMaxDecimalPlaces(): Int { | ||
| return this?.let { token -> | ||
| tradeInputMaxDecimalPlaces(token.walletId != null, token.decimals) | ||
| } ?: TRADE_INPUT_MAX_DECIMAL_PLACES |
Comment on lines
+186
to
+189
| onValueChange = { | ||
| if (!isTradeInputDecimalAllowed(it.text, maxDecimalPlaces)) { | ||
| return@BasicTextField | ||
| } |
…imal-limits # Conflicts: # app/src/main/java/one/mixin/android/ui/home/web3/components/PriceInputArea.kt # app/src/main/java/one/mixin/android/ui/home/web3/trade/InputTextField.kt # app/src/main/java/one/mixin/android/ui/home/web3/trade/LimitOrderContent.kt # app/src/main/java/one/mixin/android/ui/home/web3/trade/SwapContent.kt # app/src/test/java/one/mixin/android/ui/home/web3/trade/TradeInputTest.kt
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.
Summary
priceScale.Test Plan
./gradlew --console=plain -q :app:testGooglePlayDebugUnitTest --tests one.mixin.android.ui.home.web3.trade.TradeInputTest