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 @@ -151,7 +151,7 @@ describe('PredictMarketOutcome', () => {
{ state: initialState },
);

expect(getByText('Unknown Market')).toBeOnTheScreen();
// The component now shows the groupItemTitle directly, even if it's null/undefined
expect(getByText('0%')).toBeOnTheScreen();
expect(getByText(/\$0.*Vol\./)).toBeOnTheScreen();
});
Expand Down Expand Up @@ -243,7 +243,7 @@ describe('PredictMarketOutcome', () => {
expect(getByText('No • 0.00¢')).toBeOnTheScreen();
});

it('displays Unknown Market when groupItemTitle is missing', () => {
it('displays empty title when groupItemTitle is missing', () => {
const outcomeWithNoTitle: PredictOutcome = {
...mockOutcome,
groupItemTitle: undefined as unknown as string,
Expand All @@ -254,6 +254,9 @@ describe('PredictMarketOutcome', () => {
{ state: initialState },
);

expect(getByText('Unknown Market')).toBeOnTheScreen();
// The component now shows the groupItemTitle directly, even if it's undefined
// We can verify the component renders without errors by checking other elements
expect(getByText('+65%')).toBeOnTheScreen();
expect(getByText(/\$1M.*Vol\./)).toBeOnTheScreen();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ import Text, {
TextColor,
TextVariant,
} from '../../../../../component-library/components/Texts/Text';
import Icon, {
IconName,
IconSize,
} from '../../../../../component-library/components/Icons/Icon';
import { useStyles } from '../../../../../component-library/hooks';
import Routes from '../../../../../constants/navigation/Routes';
import {
PredictMarket,
PredictOutcomeToken,
PredictOutcome as PredictOutcomeType,
} from '../../types';
import { PredictNavigationParamList } from '../../types/navigation';
Expand All @@ -30,13 +35,16 @@ import { usePredictBalance } from '../../hooks/usePredictBalance';
interface PredictMarketOutcomeProps {
market: PredictMarket;
outcome: PredictOutcomeType;
outcomeToken?: PredictOutcomeToken;
isClosed?: boolean;
}

const PredictMarketOutcome: React.FC<PredictMarketOutcomeProps> = ({
market,
outcome,
isClosed = false,
outcomeToken,
}) => {
// const outcome = market.outcomes[0];
const { styles } = useStyles(styleSheet, {});
const tw = useTailwind();
const navigation =
Expand All @@ -55,7 +63,13 @@ const PredictMarketOutcome: React.FC<PredictMarketOutcomeProps> = ({
return '0%';
};

const getTitle = (): string => outcome.groupItemTitle ?? 'Unknown Market';
const getTitle = (): string => {
if (isClosed && outcomeToken) {
return outcomeToken.title;
}
return outcome.groupItemTitle;

};

const getImageUrl = (): string => outcome.image;

Expand Down Expand Up @@ -117,48 +131,75 @@ const PredictMarketOutcome: React.FC<PredictMarketOutcomeProps> = ({
)}
</Box>
<View style={tw.style('flex-1')}>
<Text
variant={TextVariant.HeadingMD}
color={TextColor.Default}
style={tw.style('font-medium')}
<Box
flexDirection={BoxFlexDirection.Row}
alignItems={BoxAlignItems.Center}
twClassName="gap-2"
>
{getTitle()}
</Text>
<Text
variant={TextVariant.HeadingMD}
color={TextColor.Default}
style={tw.style('font-medium')}
>
{getTitle()}
</Text>
{isClosed && outcomeToken && (
<Text
variant={TextVariant.BodyXS}
color={TextColor.Success}
style={tw.style('bg-success-muted px-1 py-0.5 rounded-sm')}
>
Winner
</Text>
)}
</Box>
<Text variant={TextVariant.BodySM} color={TextColor.Alternative}>
${getVolumeDisplay()} {strings('predict.volume_abbreviated')}
</Text>
</View>
<Text>{getYesPercentage()}</Text>
<Text>
{isClosed && outcomeToken ? (
<Icon
name={IconName.CheckBold}
size={IconSize.Md}
color={TextColor.Success}
/>
) : (
<Text>{getYesPercentage()}</Text>
)}
</Text>
</Box>
</View>
<View style={styles.buttonContainer}>
<Button
variant={ButtonVariants.Secondary}
size={ButtonSize.Md}
width={ButtonWidthTypes.Full}
label={
<Text style={tw.style('font-medium')} color={TextColor.Success}>
{strings('predict.buy_yes')} •{' '}
{(outcome.tokens[0].price * 100).toFixed(2)}¢
</Text>
}
onPress={handleYes}
style={styles.buttonYes}
/>
<Button
variant={ButtonVariants.Secondary}
size={ButtonSize.Md}
width={ButtonWidthTypes.Full}
label={
<Text style={tw.style('font-medium')} color={TextColor.Error}>
{strings('predict.buy_no')} •{' '}
{(outcome.tokens[1].price * 100).toFixed(2)}¢
</Text>
}
onPress={handleNo}
style={styles.buttonNo}
/>
</View>
{!isClosed && (
<View style={styles.buttonContainer}>
<Button
variant={ButtonVariants.Secondary}
size={ButtonSize.Md}
width={ButtonWidthTypes.Full}
label={
<Text style={tw.style('font-medium')} color={TextColor.Success}>
{strings('predict.buy_yes')} •{' '}
{(outcome.tokens[0].price * 100).toFixed(2)}¢
</Text>
}
onPress={handleYes}
style={styles.buttonYes}
/>
<Button
variant={ButtonVariants.Secondary}
size={ButtonSize.Md}
width={ButtonWidthTypes.Full}
label={
<Text style={tw.style('font-medium')} color={TextColor.Error}>
{strings('predict.buy_no')} •{' '}
{(outcome.tokens[1].price * 100).toFixed(2)}¢
</Text>
}
onPress={handleNo}
style={styles.buttonNo}
/>
</View>
)}
</View>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { screen } from '@testing-library/react-native';
import { screen, act } from '@testing-library/react-native';
import React from 'react';
import renderWithProvider from '../../../../../util/test/renderWithProvider';
import { usePredictPositions } from '../../hooks/usePredictPositions';
Expand Down Expand Up @@ -91,11 +91,16 @@ describe('PredictPositions', () => {

it('renders loading state when isLoading is true', () => {
// Arrange
mockUsePredictPositions.mockReturnValue({
...defaultMockHookReturn,
isLoading: true,
positions: [],
});
mockUsePredictPositions
.mockReturnValueOnce({
...defaultMockHookReturn,
isLoading: true,
positions: [],
})
.mockReturnValueOnce({
...defaultMockHookReturn,
positions: [],
});

// Act
renderWithProvider(<PredictPositions />);
Expand All @@ -106,11 +111,16 @@ describe('PredictPositions', () => {

it('renders loading state when isRefreshing and no positions', () => {
// Arrange
mockUsePredictPositions.mockReturnValue({
...defaultMockHookReturn,
isRefreshing: true,
positions: [],
});
mockUsePredictPositions
.mockReturnValueOnce({
...defaultMockHookReturn,
isRefreshing: true,
positions: [],
})
.mockReturnValueOnce({
...defaultMockHookReturn,
positions: [],
});

// Act
renderWithProvider(<PredictPositions />);
Expand All @@ -121,10 +131,15 @@ describe('PredictPositions', () => {

it('renders FlashList when no positions and not loading', () => {
// Arrange
mockUsePredictPositions.mockReturnValue({
...defaultMockHookReturn,
positions: [],
});
mockUsePredictPositions
.mockReturnValueOnce({
...defaultMockHookReturn,
positions: [],
})
.mockReturnValueOnce({
...defaultMockHookReturn,
positions: [],
});

// Act
renderWithProvider(<PredictPositions />);
Expand Down Expand Up @@ -203,10 +218,13 @@ describe('PredictPositions', () => {
});

const ref = React.createRef<PredictPositionsHandle>();

renderWithProvider(<PredictPositions ref={ref} />);

// Act
ref.current?.refresh();
act(() => {
ref.current?.refresh();
});

// Assert
expect(mockLoadPositions).toHaveBeenCalledWith({ isRefresh: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const PredictPositions = forwardRef<PredictPositionsHandle>((_props, ref) => {
<FlashList
testID="active-positions-list"
ref={listRef}
data={positions.sort((a, b) => b.percentPnl - a.percentPnl)}
data={positions}
renderItem={renderPosition}
scrollEnabled={false}
keyExtractor={(item) => `${item.outcomeId}:${item.outcomeIndex}`}
Expand Down
Loading
Loading