Repository navigation
feat(perps): add copy trading entry points - #6844
SeniorZhai wants to merge 13 commits into
Conversation
942f2b3 to
fb84fe0
Compare
Show publish copy trade entry on position share sheet, copy trade tag on market detail, and support maximum margin reduction limit.
fb84fe0 to
2f08904
Compare
|
AI review done for Quality: The change has several confirmed correctness issues in the reduction flow, including a test-source compilation failure, stale state after success, an unsafe retry path, and a mismatch between displayed and submitted amounts. I verified the relevant call paths and helper behavior against the PR diff, but the Gradle test task could not start because the wrapper cache directory was unavailable in this environment.
|
Percentage and slider fills were writing eight-decimal values into the amount field, so the visible text scrolled to the trailing digits.
Switching the reduce-margin field only changes what is shown. The stored percentage stays intact, and the amount text scales down to fit.
There was a problem hiding this comment.
AI review · Grok + Codex · cf4aac6
Needs fixes before merge. I compared confirmMargin() with the merge-base submit() path and searched the repo for the removed result constants. Gradle unit tests were not compiled or run because Gradle 9.9.0 is not available offline.
| AnalyticsTracker.trackPerpsReduceMarginEnd() | ||
| RxBus.publish(PerpsTradeCompletedEvent) | ||
| toast(R.string.perps_margin_submitted) | ||
| } else { |
There was a problem hiding this comment.
A decrease rejected with code 10653 is submitted again unchanged. This branch toasts getMixinErrorStringByCode and sets Step.Error, and Retry calls showVerifyPinThenClose(), which runs confirmMargin() with the same reduceMarginAmount. The previous submit() in PerpsMarginBottomSheetDialogFragment handled !increase && response.errorCode == 10653 by setting availableMargin = availableMarginFromError(response.error?.extra) and showing the max removable amount, so that amount could not be sent again. The liquidation estimate still stores available_margin via onMarginExceeded; this adjust response does not. On 10653, parse available_margin, show the max removable amount, and return that limit to the margin sheet instead of retrying the rejected amount.
| amount = requireNotNull(reduceMarginAmount).toBigDecimal().stripTrailingZeros().toPlainString(), | ||
| ), | ||
| ) | ||
| if (response.isSuccess && response.data != null) { |
There was a problem hiding this comment.
A successful decrease does not reload the position or its orders. This branch only sets Step.Done, tracks trackPerpsReduceMarginEnd, publishes PerpsTradeCompletedEvent, and toasts. The only listener for that event dismisses the market list. The previous success path called refreshSinglePosition and refreshOrders before dismiss, and closePerpsOrder still refreshes the position immediately. The open position keeps the previous margin and max_decrease_margin until the next poll (3s on the perps screens, 10s on position detail). After success, call refreshSinglePosition(positionId) and refreshOrders with the position wallet id.
| const val RESULT_MARGIN_CONFIRMED = "perps_margin_confirmed" | ||
| const val RESULT_POSITION_ID = "position_id" | ||
| const val RESULT_AMOUNT = "amount" | ||
| private const val ARGS_POSITION_ID = "args_position_id" |
There was a problem hiding this comment.
Removing RESULT_MARGIN_CONFIRMED, RESULT_POSITION_ID, and RESULT_AMOUNT breaks PerpsDialogResultTest. restoredReductionReturnsTheApprovedAmountOnce still reads those constants at lines 49, 56, and 57, and nothing in this companion declares them anymore. confirmMargin() also no longer delivers that fragment result after PIN success; it calls adjustPerpsMargin directly. Update the test for the new adjust path so the unit-test source set compiles.
…ntry # Conflicts: # app/src/main/java/one/mixin/android/ui/home/web3/trade/perps/PerpsMarginBottomSheetDialogFragment.kt # app/src/main/res/layout/fragment_perps_position_share_bottom.xml # app/src/main/res/values-ko/strings.xml # app/src/main/res/values-zh-rCN/strings.xml # app/src/main/res/values-zh-rTW/strings.xml # app/src/main/res/values/strings.xml
There was a problem hiding this comment.
AI review · GPT + Grok · e4467c3
Needs fixes before merge. git diff --check passed, and static inspection confirmed all four findings. The focused Gradle unit-test command was blocked before compilation by the environment’s inability to create the Gradle wrapper cache.
app/src/test/java/one/mixin/android/ui/home/web3/trade/perps/PerpsDialogResultTest.kt:49
The reduction result test still targets the removed fragment-result contract. RESULT_MARGIN_CONFIRMED, RESULT_POSITION_ID, and RESULT_AMOUNT are no longer declared, and PIN success now submits through adjustPerpsMargin instead of publishing that result, so the unit-test source set cannot compile. Rewrite this test around the new adjustment path or remove the obsolete result assertions.
app/src/main/java/one/mixin/android/ui/home/web3/trade/perps/PerpsCloseBottomSheetDialogFragment.kt:589
When error 10653 means the removable margin changed, this generic error branch leaves the original amount in reduceMarginAmount, so Retry calls confirmMargin() and submits the same rejected amount again. Parse response.error?.extra with availableMarginFromError, update the reduction flow with that limit, and make Retry use the resulting valid amount.
app/src/main/java/one/mixin/android/ui/home/web3/trade/perps/PerpsMarginBottomSheetDialogFragment.kt:489
The mode switch only flips reduceByPercent, while inputIsPercentage remains true until the user edits the field. For example, a 100% reduction of a $0.005 margin renders $0.00 after switching modes, but amountValue and the submission still use the underlying 0.005. Convert the input mode and value together so the displayed dollar amount matches the amount submitted, including sub-cent values.
app/src/main/java/one/mixin/android/ui/home/web3/trade/perps/PerpsCloseBottomSheetDialogFragment.kt:583
After a successful decrease, this branch only marks the sheet done and publishes the completion event. It does not refresh the position or its orders, so reopening the reduction flow can use the old margin and maxDecreaseMargin until polling runs. Refresh the position with its wallet ID and refresh its orders before dismissing or completing the flow.
No description provided.