-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
chore(predict): adds initial logic to handle a resolved market #21382
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
Changes from all commits
8e1bb29
c25d3bc
98025ed
821edff
336d37e
a9cd437
3e29395
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'; | ||
|
|
@@ -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 = | ||
|
|
@@ -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; | ||
|
|
||
|
|
@@ -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> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Invalid Child Nesting in React Native Text ComponentThe |
||
| </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> | ||
| ); | ||
| }; | ||
|
|
||
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.
Bug: Title Function Returns Undefined/Null
The
getTitle()function is typed asstringbut can returnundefinedornull. This occurs because the?? 'Unknown Market'fallback was removed, andoutcome.groupItemTitleoroutcomeToken.title(whenisClosed) can be undefined. This creates a type safety issue and can cause runtime errors when rendering text.