|
1 | | -import React, { useMemo } from 'react'; |
| 1 | +import React, { useCallback, useMemo } from 'react'; |
2 | 2 | import { Box } from '@metamask/design-system-react-native'; |
3 | 3 | import PredictBetButtons from './PredictBetButtons'; |
4 | 4 | import PredictClaimButton from './PredictClaimButton'; |
@@ -166,30 +166,60 @@ const PredictActionButtons: React.FC<PredictActionButtonsProps> = ({ |
166 | 166 | } |
167 | 167 |
|
168 | 168 | if (market.status === PredictMarketStatus.OPEN && buttonConfig) { |
169 | | - const drawToken = buttonConfig.drawToken; |
170 | | - |
171 | 169 | return ( |
172 | | - <Box twClassName="w-full mt-4"> |
173 | | - <PredictBetButtons |
174 | | - yesLabel={buttonConfig.yesLabel} |
175 | | - yesPrice={buttonConfig.yesPrice} |
176 | | - onYesPress={() => onBetPress(buttonConfig.yesToken)} |
177 | | - drawLabel={buttonConfig.drawLabel} |
178 | | - drawPrice={buttonConfig.drawPrice} |
179 | | - onDrawPress={drawToken ? () => onBetPress(drawToken) : undefined} |
180 | | - noLabel={buttonConfig.noLabel} |
181 | | - noPrice={buttonConfig.noPrice} |
182 | | - onNoPress={() => onBetPress(buttonConfig.noToken)} |
183 | | - yesTeamColor={buttonConfig.yesTeamColor} |
184 | | - noTeamColor={buttonConfig.noTeamColor} |
185 | | - testID={`${testID}${PREDICT_ACTION_BUTTONS_TEST_IDS.PREDICT_BET_BUTTON}`} |
186 | | - isCarousel={isCarousel} |
187 | | - /> |
188 | | - </Box> |
| 170 | + <PredictBetButtonsContainer |
| 171 | + buttonConfig={buttonConfig} |
| 172 | + onBetPress={onBetPress} |
| 173 | + testID={testID} |
| 174 | + isCarousel={isCarousel} |
| 175 | + /> |
189 | 176 | ); |
190 | 177 | } |
191 | 178 |
|
192 | 179 | return null; |
193 | 180 | }; |
194 | 181 |
|
| 182 | +function PredictBetButtonsContainer(props: { |
| 183 | + buttonConfig: ButtonConfig; |
| 184 | + onBetPress: (token: PredictOutcomeToken) => void; |
| 185 | + testID: string; |
| 186 | + isCarousel?: boolean; |
| 187 | +}) { |
| 188 | + const { buttonConfig, onBetPress, testID, isCarousel } = props; |
| 189 | + const { yesToken, drawToken, noToken } = buttonConfig; |
| 190 | + |
| 191 | + const onYesPress = useCallback( |
| 192 | + () => onBetPress(yesToken), |
| 193 | + [onBetPress, yesToken], |
| 194 | + ); |
| 195 | + const onDrawPress = useMemo( |
| 196 | + () => (drawToken ? () => onBetPress(drawToken) : undefined), |
| 197 | + [onBetPress, drawToken], |
| 198 | + ); |
| 199 | + const onNoPress = useCallback( |
| 200 | + () => onBetPress(noToken), |
| 201 | + [onBetPress, noToken], |
| 202 | + ); |
| 203 | + |
| 204 | + return ( |
| 205 | + <Box twClassName="w-full mt-4"> |
| 206 | + <PredictBetButtons |
| 207 | + yesLabel={buttonConfig.yesLabel} |
| 208 | + yesPrice={buttonConfig.yesPrice} |
| 209 | + onYesPress={onYesPress} |
| 210 | + drawLabel={buttonConfig.drawLabel} |
| 211 | + drawPrice={buttonConfig.drawPrice} |
| 212 | + onDrawPress={onDrawPress} |
| 213 | + noLabel={buttonConfig.noLabel} |
| 214 | + noPrice={buttonConfig.noPrice} |
| 215 | + onNoPress={onNoPress} |
| 216 | + yesTeamColor={buttonConfig.yesTeamColor} |
| 217 | + noTeamColor={buttonConfig.noTeamColor} |
| 218 | + testID={`${testID}${PREDICT_ACTION_BUTTONS_TEST_IDS.PREDICT_BET_BUTTON}`} |
| 219 | + isCarousel={isCarousel} |
| 220 | + /> |
| 221 | + </Box> |
| 222 | + ); |
| 223 | +} |
| 224 | + |
195 | 225 | export default PredictActionButtons; |
0 commit comments