-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: resolve prop override in PerpsEmptyState component #20534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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. |
import { PerpsEmptyState } from './PerpsEmptyState'; | ||
|
||
describe('PerpsEmptyState', () => { | ||
const mockOnStartTrading = jest.fn(); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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}> |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating instance in PerpsTabView
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 ![]() ![]() |
There was a problem hiding this 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'); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding tests
const sizeValue = parseFloat(position.size); | ||
const directionSegment = Number.isFinite(sizeValue) | ||
? sizeValue > 0 | ||
? 'long' | ||
: sizeValue < 0 | ||
? 'short' | ||
: 'unknown' | ||
: 'unknown'; | ||
const directionSegment = getPositionDirection(position.size); |
There was a problem hiding this comment.
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.


There was a problem hiding this 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 ofonStartTrading
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.
8d426e5
to
be02486
Compare
be02486
to
0628e62
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Description
Updated the PerpsEmptyState component to use the
onAction
prop from TabEmptyStateProps instead of a customonStartTrading
prop. This fixes a prop spreading issue where anyonAction
prop passed to PerpsEmptyState would override the explicitly setonAction={onStartTrading}
due to the{...props}
spread coming after the explicit assignment.What was the issue?
The component had both a custom
onStartTrading
prop and inheritedonAction
from TabEmptyStateProps, causing conflicts when props were spread.What's the solution?
Removed the redundant
onStartTrading
prop and updated all usages to use the inheritedonAction
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
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
Note
Switches PerpsEmptyState to use
onAction
and introducesgetPositionDirection
, updating usages, mocks, and tests.onStartTrading
prop; use inheritedonAction
. Update story, tests, andPerpsTabView
to passonAction
.getPositionDirection(sizeString)
inutils/positionCalculations
and comprehensive unit tests.getPositionDirection
inPerpsPositionsView
andPerpsTabView
to buildtestID
s.Written by Cursor Bugbot for commit 0628e62. This will update automatically on new commits. Configure here.