Skip to content

Conversation

georgewrmarshall
Copy link
Contributor

@georgewrmarshall georgewrmarshall commented Sep 29, 2025

Description

Updated the PerpsEmptyState component to use the onAction prop from TabEmptyStateProps instead of a custom onStartTrading prop. This fixes a prop spreading issue where any onAction prop passed to PerpsEmptyState would override the explicitly set onAction={onStartTrading} due to the {...props} spread coming after the explicit assignment.

What was the issue?
The component had both a custom onStartTrading prop and inherited onAction from TabEmptyStateProps, causing conflicts when props were spread.

What's the solution?
Removed the redundant onStartTrading prop and updated all usages to use the inherited onAction prop, maintaining consistency with the parent TabEmptyState component.

Changelog

CHANGELOG entry: null

Related issues

Fixes: Internal code improvement to resolve prop override issue

Manual testing steps

Feature: PerpsEmptyState component functionality

  Scenario: user interacts with empty state action button
    Given the app is running with no perp positions or orders
    And I navigate to the Perps tab
    When I see the empty state with "Start trading" button
    And I tap the "Start trading" button
    Then the onAction callback should be triggered correctly
    And I should navigate to the expected trading interface

Screenshots/Recordings

Before

No visual changes - this is an internal prop structure fix

After

No visual changes - this is an internal prop structure fix. Smoke test to show button still works

after720.mov

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Switches PerpsEmptyState to use onAction and introduces getPositionDirection, updating usages, mocks, and tests.

  • Perps UI:
    • PerpsEmptyState: Remove custom onStartTrading prop; use inherited onAction. Update story, tests, and PerpsTabView to pass onAction.
  • Refactor:
    • Add getPositionDirection(sizeString) in utils/positionCalculations and comprehensive unit tests.
    • Replace inline direction parsing with getPositionDirection in PerpsPositionsView and PerpsTabView to build testIDs.

Written by Cursor Bugbot for commit 0628e62. This will update automatically on new commits. Configure here.

@georgewrmarshall georgewrmarshall self-assigned this Sep 29, 2025
@github-actions
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-design-system All issues relating to design system in Mobile label Sep 29, 2025
@georgewrmarshall georgewrmarshall added No QA Needed Apply this label when your PR does not need any QA effort. No E2E Smoke Needed If the PR does not need E2E smoke test run labels Sep 29, 2025
import { PerpsEmptyState } from './PerpsEmptyState';

describe('PerpsEmptyState', () => {
const mockOnStartTrading = jest.fn();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updating tests

import emptyStatePerpsDark from '../../../../../images/empty-state-perps-dark.png';

export interface PerpsEmptyStateProps extends TabEmptyStateProps {
onStartTrading: () => void;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing onStartTrading and using the provided onAction prop from TabEmptyState component. Also changing it from a required prop.

<View testID={testID}>
<Text>Bet on price movements with up to 40x leverage.</Text>
<TouchableOpacity onPress={onStartTrading}>
<TouchableOpacity onPress={onAction}>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updating mock

{!isInitialLoading && hasNoPositionsOrOrders ? (
<PerpsEmptyState
onStartTrading={handleNewTrade}
onAction={handleNewTrade}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updating instance in PerpsTabView

@georgewrmarshall georgewrmarshall added the no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed label Sep 29, 2025
@georgewrmarshall
Copy link
Contributor Author

Quality Gate Failed Quality Gate failed

Failed conditions D Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

These issues already existed and are not related to the changes in this PR https://sonarcloud.io/project/issues?sinceLeakPeriod=true&issueStatuses=OPEN%2CCONFIRMED&pullRequest=20534&id=metamask-mobile&open=AZmWdBouHRaSraV4LiXl

Screenshot 2025-09-29 at 11 21 26 AM Screenshot 2025-09-29 at 11 21 30 AM

@georgewrmarshall georgewrmarshall marked this pull request as ready for review September 29, 2025 18:22
@georgewrmarshall georgewrmarshall requested a review from a team as a code owner September 29, 2025 18:22
cursor[bot]

This comment was marked as outdated.

Matt561
Matt561 previously approved these changes Sep 29, 2025
Copy link
Contributor

@Matt561 Matt561 left a comment

Choose a reason for hiding this comment

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

Tests well on iOS 👍

expect(getPositionDirection(' -10.5 ')).toBe('short');
expect(getPositionDirection(' 0 ')).toBe('unknown');
});
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding tests

Comment on lines -128 to +129
const sizeValue = parseFloat(position.size);
const directionSegment = Number.isFinite(sizeValue)
? sizeValue > 0
? 'long'
: sizeValue < 0
? 'short'
: 'unknown'
: 'unknown';
const directionSegment = getPositionDirection(position.size);
Copy link
Contributor Author

@georgewrmarshall georgewrmarshall Sep 29, 2025

Choose a reason for hiding this comment

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

I was getting SonarCloud code quality errors in this PR due to these ternary operators, which were unrelated to my changes. I moved the logic into a getPositionDirection util. This could likely be reused in other places where we get the position, but for now I only updated it here to reduce unrelated changes.

https://sonarcloud.io/project/issues?sinceLeakPeriod=true&issueStatuses=OPEN%2CCONFIRMED&pullRequest=20534&id=metamask-mobile&open=AZmWdBouHRaSraV4LiXl

Screenshot 2025-09-29 at 11 21 26 AM Screenshot 2025-09-29 at 11 21 30 AM

cursor[bot]

This comment was marked as outdated.

Copy link
Contributor

@Copilot Copilot AI left a comment

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 fixes a prop override issue in the PerpsEmptyState component by removing the custom onStartTrading prop and using the inherited onAction prop from TabEmptyStateProps. Additionally, it introduces a new utility function getPositionDirection to standardize how position directions are calculated across components.

  • Removed redundant onStartTrading prop from PerpsEmptyState to prevent prop spreading conflicts
  • Added getPositionDirection utility function to centralize position direction logic
  • Updated all usages of PerpsEmptyState to use onAction instead of onStartTrading

Reviewed Changes

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

Show a summary per file
File Description
app/components/UI/Perps/utils/positionCalculations.ts Added new getPositionDirection utility function
app/components/UI/Perps/utils/positionCalculations.test.ts Added comprehensive tests for the new utility function
app/components/UI/Perps/Views/PerpsTabView/PerpsTabView.tsx Updated to use getPositionDirection utility and onAction prop
app/components/UI/Perps/Views/PerpsTabView/PerpsTabView.test.tsx Updated mock to use onAction instead of onStartTrading
app/components/UI/Perps/Views/PerpsPositionsView/PerpsPositionsView.tsx Refactored to use getPositionDirection utility
app/components/UI/Perps/Views/PerpsEmptyState/PerpsEmptyState.tsx Removed onStartTrading prop, now uses inherited onAction
app/components/UI/Perps/Views/PerpsEmptyState/PerpsEmptyState.test.tsx Updated test to use onAction prop
app/components/UI/Perps/Views/PerpsEmptyState/PerpsEmptyState.stories.tsx Updated Storybook story to use onAction

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@georgewrmarshall georgewrmarshall force-pushed the perp-empty-tab-prop-name-fix branch from 8d426e5 to be02486 Compare October 1, 2025 16:20
@georgewrmarshall georgewrmarshall force-pushed the perp-empty-tab-prop-name-fix branch from be02486 to 0628e62 Compare October 1, 2025 16:22
@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 1, 2025

Copy link
Contributor

@gambinish gambinish left a comment

Choose a reason for hiding this comment

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

lgtm

@georgewrmarshall georgewrmarshall added this pull request to the merge queue Oct 1, 2025
Merged via the queue into main with commit 4f32864 Oct 1, 2025
208 of 213 checks passed
@georgewrmarshall georgewrmarshall deleted the perp-empty-tab-prop-name-fix branch October 1, 2025 20:10
@github-actions github-actions bot locked and limited conversation to collaborators Oct 1, 2025
@metamaskbot metamaskbot added the release-7.57.0 Issue or pull request that will be included in release 7.57.0 label Oct 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

No E2E Smoke Needed If the PR does not need E2E smoke test run No QA Needed Apply this label when your PR does not need any QA effort. no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed release-7.57.0 Issue or pull request that will be included in release 7.57.0 size-M team-design-system All issues relating to design system in Mobile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants