Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,13 @@ jest.mock('@react-navigation/native', () => {
};
});

const mockUseScreenTransitionComplete = jest.fn(() => true);
jest.mock('../../../../hooks/useScreenTransitionComplete', () => ({
__esModule: true,
default: () => mockUseScreenTransitionComplete(),
useScreenTransitionComplete: () => mockUseScreenTransitionComplete(),
}));

jest.mock('../../hooks/useHasExistingPosition', () => ({
useHasExistingPosition: () => mockUseHasExistingPosition(),
}));
Expand Down Expand Up @@ -968,6 +975,7 @@ describe('PerpsMarketDetailsView', () => {
// Set up default mock return values before each test
beforeEach(() => {
jest.clearAllMocks();
mockUseScreenTransitionComplete.mockReturnValue(true);
mockPerpsModeValue = 'lite';
mockMarketContextKey = 'testnet|hyperliquid|1';
mockMarketContextReady = true;
Expand Down Expand Up @@ -1481,6 +1489,23 @@ describe('PerpsMarketDetailsView', () => {
expect(queryByTestId(PerpsModeToggleSelectorsIDs.LITE_SEGMENT)).toBeNull();
});

it('holds the statistics card back until the opening transition completes', () => {
mockUseScreenTransitionComplete.mockReturnValue(false);

const { queryByTestId } = renderWithProvider(
<PerpsConnectionProvider>
<PerpsMarketDetailsView />
</PerpsConnectionProvider>,
{
state: initialState,
},
);

expect(
queryByTestId(PerpsMarketDetailsViewSelectorsIDs.STATISTICS_HIGH_24H),
).toBeNull();
});

it('renders statistics items', () => {
const { getByTestId, queryByTestId } = renderWithProvider(
<PerpsConnectionProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import { ImpactMoment, playImpact } from '../../../../../util/haptics';
import { isNotificationsFeatureEnabled } from '../../../../../util/notifications';
import { trace, TraceName, TraceOperation } from '../../../../../util/trace';
import { useScreenTransitionComplete } from '../../../../hooks/useScreenTransitionComplete';
import { MetaMetricsEvents } from '../../../../../core/Analytics';
import ComponentErrorBoundary from '../../../ComponentErrorBoundary';
import PerpsBottomSheetTooltip from '../../components/PerpsBottomSheetTooltip/PerpsBottomSheetTooltip';
Expand Down Expand Up @@ -360,6 +361,9 @@

// Keep direct navigation for configuration methods (setOptions, setParams)
const navigation = useNavigation<AppNavigationProp>();

// Hold the heavy sections out of the opening transition.
const isDeferredReady = useScreenTransitionComplete();
const { sharePosition, findSocialPosition } = usePerpsSharePosition();
const route =
useRoute<RouteProp<{ params: MarketDetailsRouteParams }, 'params'>>();
Expand Down Expand Up @@ -1858,7 +1862,7 @@
() => [
{
key: 'stats',
visible: true,
visible: isDeferredReady,
content: (
<PerpsMarketStatisticsCard
symbol={market?.symbol || ''}
Expand Down Expand Up @@ -1896,14 +1900,14 @@
},
{
key: 'recent-trades',
visible: Boolean(market?.symbol),
visible: Boolean(market?.symbol) && isDeferredReady,
content: market?.symbol ? (
<PerpsMarketTradesList symbol={market.symbol} />
) : null,
},
{
key: 'more',
visible: moreItems.length > 0,
visible: moreItems.length > 0 && isDeferredReady,
content: (
<PerpsMoreSection
items={moreItems}
Expand All @@ -1922,6 +1926,7 @@
moreItems,
hasAboutDescription,
handleAboutLayout,
isDeferredReady,
],
);

Expand Down Expand Up @@ -2239,38 +2244,40 @@
<Box twClassName="mb-4">{marketInsightsCard}</Box>
) : null}

{isPerpsSocialEnabled ? (
<>
<PerpsHomeSectionList sections={positionSections} />
<PerpsMarketSocialTabs
symbol={market.symbol}
onOverviewLayout={handleAboutContainerLayout}
onOverviewVisibilityChange={setAboutTrackingEnabled}
onTabChange={setActiveSocialTab}
footer={isFeedScroller ? riskDisclaimer : undefined}
overview={
<PerpsHomeSectionList
sections={[
{
key: 'market-insights',
visible: shouldShowPerpsMarketInsightsSection,
content: (
<Box twClassName="pt-3 pb-6">{marketInsightsCard}</Box>
),
},
...overviewSections,
]}
hideLeadingDivider
/>
}
/>
</>
) : (
<>
<PerpsHomeSectionList sections={preMarketInsightsSections} />
<PerpsHomeSectionList sections={postMarketInsightsSections} />
</>
)}
{isDeferredReady ? (
isPerpsSocialEnabled ? (
<>
<PerpsHomeSectionList sections={positionSections} />
<PerpsMarketSocialTabs
symbol={market.symbol}
onOverviewLayout={handleAboutContainerLayout}
onOverviewVisibilityChange={setAboutTrackingEnabled}
onTabChange={setActiveSocialTab}
footer={isFeedScroller ? riskDisclaimer : undefined}
overview={
<PerpsHomeSectionList
sections={[
{
key: 'market-insights',
visible: shouldShowPerpsMarketInsightsSection,
content: (
<Box twClassName="pt-3 pb-6">{marketInsightsCard}</Box>
),
},
...overviewSections,
]}
hideLeadingDivider
/>
}
/>
</>
) : (
<>
<PerpsHomeSectionList sections={preMarketInsightsSections} />
<PerpsHomeSectionList sections={postMarketInsightsSections} />
</>
)

Check warning on line 2279 in app/components/UI/Perps/Views/PerpsMarketDetailsView/PerpsMarketDetailsView.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested ternary operation into an independent statement.

See more on https://sonarcloud.io/project/issues?id=MetaMask_metamask-mobile&issues=AaHulqkf2lgfTEJTgWCP&open=AaHulqkf2lgfTEJTgWCP&pullRequest=40026
) : null}

{isFeedScroller ? null : riskDisclaimer}
</>
Expand Down
Loading