Skip to content

CP-14877: switch between Long and Short on the Place Order screen via native select - #4006

Open
bogdandobritoiu wants to merge 8 commits into
mainfrom
CP-14877
Open

CP-14877: switch between Long and Short on the Place Order screen via native select#4006
bogdandobritoiu wants to merge 8 commits into
mainfrom
CP-14877

Conversation

@bogdandobritoiu

@bogdandobritoiu bogdandobritoiu commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description

Ticket: CP-14877

Lets the user switch between Long and Short directly on the perps Place Order screen using our native select (zeego DropdownMenu), instead of backing out of the modal and re-entering from the market details screen.

  • PlaceOrderContext: side is now state (seeded from the renamed initialSide prop) with an atomic switchSide action. Flipping direction clears take-profit/stop-loss prices and toggles, since trigger prices are direction-specific — a long's TP sits on the wrong side of the price for a short. Switching to the current side is a no-op.
  • PositionPill: new optional onChangeSide prop. When set (Place Order screen only), the Long/Short label becomes a native dropdown trigger with a chevron affordance and the current side check-marked. Trigger/Close/Manage screens pass nothing and render exactly as before.
  • PerpetualsPlaceOrderScreen: wires switchSide into the pill. Subtitle, slide-button label, liquidation price, and buy-vs-sell position capacity all recompute from existing side derivations. When the flipped side's capacity is below the dialed amount, the caption under the dial now shows a danger-colored "Reduce your position to $X or less" warning (submit was already correctly disabled by the existing capacity guard; this makes the reason visible).

No new dependencies. No breaking changes.

Screenshots/Videos

Simulator.Screen.Recording.-.iPhone.17.Pro.-.2026-07-22.at.17.42.11.mov

Testing

iOS - 9393
Android - 9394

Dev Testing

Happy path:

  1. Open a perps market → tap Long → Place Order screen
  2. Tap the "Long ▲" label in the position pill → native menu opens with Long check-marked
  3. Pick Short → pill shows "Short ▼", subtitle flips to "will go down", slide button reads "Slide to buy Short", "Maximum position" updates to the sell-side cap
  4. Slide to confirm → order submits as a short

Edge cases:

  • Set a take profit and/or stop loss, then flip side → both toggles turn off and prices clear (re-enable requires entering a new price)
  • Pick the same side from the menu → nothing changes, TP/SL preserved
  • Dial to max on the higher-capacity side, flip to the lower-capacity side → slide button disabled and the caption shows "Reduce your position to $X or less" in red; lowering the dial re-enables
  • Manage flow (existing position) and Trigger/Close screens → side label unchanged, no chevron/menu

Bitrise build:

iOS - 9384
Android - 9385

QA Testing

  • Verify direction switching on the Place Order screen on both platforms (iOS native menu / Android dropdown)
  • Verify orders submit with the direction shown at submit time
  • Verify TP/SL are cleared on every direction change and preserved when re-selecting the same direction
  • Verify an existing position's direction cannot be changed from the Manage flow

Checklist

Please check all that apply (if applicable)

  • I have performed a self-review of my code
  • I have verified the code works
  • I have included screenshots / videos of android and ios
  • I have added testing steps
  • I have added/updated necessary unit tests
  • I have updated the documentation

🤖 Generated with Claude Code

bogdandobritoiu and others added 5 commits July 22, 2026 17:28
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…geSide is set

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…olish

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 22, 2026 15:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the perps Place Order flow by allowing users to switch Long/Short directly on the screen via the existing native DropdownMenu select, and by improving the UI feedback when the selected side’s max capacity is lower than the currently dialed amount.

Changes:

  • Converted PlaceOrderContext.side into internal state seeded from a renamed initialSide prop, and added a switchSide action that clears TP/SL toggles and prices when the side changes.
  • Updated PositionPill to optionally render the Long/Short label as a native dropdown trigger (when onChangeSide is provided), leaving other screens’ behavior unchanged.
  • Updated PerpetualsPlaceOrderScreen to wire side switching and to show a danger-styled “Reduce your position…” caption when the amount exceeds the current side’s capacity; added/updated unit tests accordingly.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/core-mobile/app/new/features/trade/perpetuals/screens/PerpetualsPlaceOrderScreen.tsx Wires switchSide into the UI and adds a capacity-aware caption under the amount dial.
packages/core-mobile/app/new/features/trade/perpetuals/screens/PerpetualsPlaceOrderScreen.test.tsx Extends screen tests to cover capacity warning caption and pill side-switch wiring/label derivations.
packages/core-mobile/app/new/features/trade/perpetuals/hooks/useSeededPlaceOrderProps.ts Renames seeded side to initialSide to reflect provider seeding semantics.
packages/core-mobile/app/new/features/trade/perpetuals/hooks/useSeededPlaceOrderProps.test.ts Updates resolver tests to assert initialSide.
packages/core-mobile/app/new/features/trade/perpetuals/contexts/PlaceOrderContext.tsx Introduces stateful side plus switchSide action that clears TP/SL on side change.
packages/core-mobile/app/new/features/trade/perpetuals/contexts/PlaceOrderContext.test.tsx Adds focused unit tests for switchSide behavior (clearing TP/SL, no-op, liquidation recompute).
packages/core-mobile/app/new/features/trade/perpetuals/components/PositionPill.tsx Adds optional dropdown side selector behavior via DropdownMenu when onChangeSide is provided.
packages/core-mobile/app/new/features/trade/perpetuals/components/PositionPill.test.tsx Adds component tests for dropdown rendering, selection state, and event handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown

Coverage report ✅

2/2 packages passed thresholds
Thresholds are shown inline against each package baseline.

🟢 @avalabs/core-mobile

St. Category Percentage Covered / Total
🟢 Statements 27.83% (+9.83% vs 18% ▲) 12293/44164
🟢 Branches 23.49% (+11.49% vs 12% ▲) 6034/25680
🟢 Functions 22.08% (+9.08% vs 13% ▲) 2252/10196
🟢 Lines 27.91% (+9.91% vs 18% ▲) 11773/42172

🟢 @avalabs/k2-alpine

St. Category Percentage Covered / Total
🟢 Statements 7.62% (+5.62% vs 2% ▲) 270/3539
🟢 Branches 7.02% (+6.02% vs 1% ▲) 151/2148
🟢 Functions 4.52% (+3.52% vs 1% ▲) 37/817
🟢 Lines 7.07% (+5.07% vs 2% ▲) 230/3251
Artifacts and threshold sources
  • @avalabs/core-mobile: summary core-mobile/coverage/coverage-summary.json, thresholds core-mobile/coverage-thresholds.json
  • @avalabs/k2-alpine: summary k2-alpine/coverage/coverage-summary.json, thresholds k2-alpine/coverage-thresholds.json

Source run: Mobile PR

Copilot AI review requested due to automatic review settings July 22, 2026 16:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Bogdan Dobritoiu <bogdan.dobri@gmail.com>
Copilot AI review requested due to automatic review settings July 22, 2026 16:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

ruijia1in
ruijia1in previously approved these changes Jul 22, 2026
# Conflicts:
#	packages/core-mobile/app/new/features/trade/perpetuals/contexts/PlaceOrderContext.test.tsx
#	packages/core-mobile/app/new/features/trade/perpetuals/screens/PerpetualsPlaceOrderScreen.test.tsx

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

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.

3 participants