|
8 | 8 | BigHeading,
|
9 | 9 | styled,
|
10 | 10 | AnimatePresence,
|
| 11 | + View, |
| 12 | + type XStackProps, |
11 | 13 | } from '@my/ui'
|
12 | 14 | import { EyeOff, Eye } from '@tamagui/lucide-icons'
|
13 | 15 | import formatAmount from 'app/utils/formatAmount'
|
@@ -37,32 +39,48 @@ export const TokenBalanceCard = () => {
|
37 | 39 | const formattedBalance = formatAmount(totalBalance, 9, 0)
|
38 | 40 |
|
39 | 41 | const { isPriceHidden, toggleIsPriceHidden } = useIsPriceHidden()
|
| 42 | + const { isGameVisible, presses, increaseScore, time } = useShowHideGame() |
| 43 | + |
| 44 | + const onShowHidePress = () => { |
| 45 | + toggleIsPriceHidden() |
| 46 | + increaseScore() |
| 47 | + } |
40 | 48 |
|
41 | 49 | return (
|
42 | 50 | <XStack w={'100%'} zIndex={4}>
|
43 | 51 | <YStack jc={'center'} gap={'$4'} w={'100%'}>
|
44 |
| - <XStack ai={'center'} gap="$2.5" width={'100%'} onPress={toggleIsPriceHidden}> |
45 |
| - <XStack ai={'center'} gap="$2.5"> |
46 |
| - <AnimatePresence exitBeforeEnter> |
47 |
| - {isPriceHidden ? <HiddenSquare /> : <GreenSquare />} |
48 |
| - </AnimatePresence> |
49 |
| - <Label |
50 |
| - fontSize={'$4'} |
51 |
| - zIndex={1} |
52 |
| - fontWeight={'500'} |
53 |
| - textTransform={'uppercase'} |
54 |
| - lineHeight={0} |
55 |
| - col={'$color10'} |
56 |
| - > |
57 |
| - Total Balance |
58 |
| - </Label> |
| 52 | + <YStack w="fit-content" gap={'$2.5'}> |
| 53 | + <XStack ai={'center'} gap="$2.5" width={'100%'} onPress={onShowHidePress}> |
| 54 | + <XStack ai={'center'} gap="$2.5"> |
| 55 | + <AnimatePresence exitBeforeEnter> |
| 56 | + {isPriceHidden ? <HiddenSquare /> : <GreenSquare />} |
| 57 | + </AnimatePresence> |
| 58 | + <Label |
| 59 | + fontSize={'$4'} |
| 60 | + zIndex={1} |
| 61 | + fontWeight={'500'} |
| 62 | + textTransform={'uppercase'} |
| 63 | + lineHeight={0} |
| 64 | + col={'$color10'} |
| 65 | + > |
| 66 | + Total Balance |
| 67 | + </Label> |
| 68 | + </XStack> |
| 69 | + {isPriceHidden ? ( |
| 70 | + <EyeOff color={'$color9'} size={'$1'} /> |
| 71 | + ) : ( |
| 72 | + <Eye color={'$color11'} size={'$1'} /> |
| 73 | + )} |
59 | 74 | </XStack>
|
60 |
| - {isPriceHidden ? ( |
61 |
| - <EyeOff color={'$color9'} size={'$1'} /> |
62 |
| - ) : ( |
63 |
| - <Eye color={'$color11'} size={'$1'} /> |
| 75 | + {isGameVisible && ( |
| 76 | + <XStack w="100%" gap={'$2'} jc={'space-between'} ai={'center'} my="auto"> |
| 77 | + <Paragraph fontSize={'$6'} fontWeight={'500'} zIndex={1} color={'$color10'}> |
| 78 | + {presses} |
| 79 | + </Paragraph> |
| 80 | + <ShowHideGameStopwatch time={time} /> |
| 81 | + </XStack> |
64 | 82 | )}
|
65 |
| - </XStack> |
| 83 | + </YStack> |
66 | 84 | <XStack style={{ color: 'white' }} gap={'$2.5'} mt={'$3'}>
|
67 | 85 | {(() => {
|
68 | 86 | switch (true) {
|
@@ -152,3 +170,80 @@ const useIsPriceHidden = () => {
|
152 | 170 |
|
153 | 171 | return { isPriceHidden, toggleIsPriceHidden }
|
154 | 172 | }
|
| 173 | + |
| 174 | +const useShowHideGame = () => { |
| 175 | + const countToStop = 100 |
| 176 | + const countToVisible = 10 |
| 177 | + |
| 178 | + const [isGameVisible, setIsGameVisible] = useState<boolean>(false) |
| 179 | + const [presses, setPresses] = useState<number>(0) |
| 180 | + |
| 181 | + const [isPaused, setIsPaused] = useState(false) |
| 182 | + const [time, setTime] = useState(0) |
| 183 | + |
| 184 | + useEffect(() => { |
| 185 | + if (presses >= countToVisible) { |
| 186 | + setIsGameVisible(true) |
| 187 | + } |
| 188 | + if (presses >= countToStop) { |
| 189 | + setIsPaused(true) |
| 190 | + } |
| 191 | + |
| 192 | + let interval: NodeJS.Timeout | undefined = undefined |
| 193 | + if (isPaused === false) { |
| 194 | + interval = setInterval(() => { |
| 195 | + setTime((time) => time + 10) |
| 196 | + }, 10) |
| 197 | + } else { |
| 198 | + clearInterval(interval) |
| 199 | + } |
| 200 | + return () => { |
| 201 | + clearInterval(interval) |
| 202 | + } |
| 203 | + }, [presses, isPaused]) |
| 204 | + |
| 205 | + const onPress = () => { |
| 206 | + if (isPaused === false) { |
| 207 | + setPresses(presses + 1) |
| 208 | + } |
| 209 | + } |
| 210 | + |
| 211 | + return { isGameVisible, presses, increaseScore: onPress, time } |
| 212 | +} |
| 213 | + |
| 214 | +const ShowHideGameStopwatch = ({ time, ...props }: XStackProps & { time: number }) => { |
| 215 | + return ( |
| 216 | + <XStack {...props}> |
| 217 | + <Paragraph |
| 218 | + fontSize={'$4'} |
| 219 | + zIndex={1} |
| 220 | + fontWeight={'500'} |
| 221 | + textTransform={'uppercase'} |
| 222 | + lineHeight={0} |
| 223 | + col={'$color10'} |
| 224 | + > |
| 225 | + {`0 + ${Math.floor((time / 60000) % 60)}`.slice(-2)}: |
| 226 | + </Paragraph> |
| 227 | + <Paragraph |
| 228 | + fontSize={'$4'} |
| 229 | + zIndex={1} |
| 230 | + fontWeight={'500'} |
| 231 | + textTransform={'uppercase'} |
| 232 | + lineHeight={0} |
| 233 | + col={'$color10'} |
| 234 | + > |
| 235 | + {`0 + ${Math.floor((time / 1000) % 60)}`.slice(-2)}. |
| 236 | + </Paragraph> |
| 237 | + <Paragraph |
| 238 | + fontSize={'$4'} |
| 239 | + zIndex={1} |
| 240 | + fontWeight={'500'} |
| 241 | + textTransform={'uppercase'} |
| 242 | + lineHeight={0} |
| 243 | + col={'$color10'} |
| 244 | + > |
| 245 | + {`0 + ${Math.floor((time / 10) % 100)}`.slice(-2)} |
| 246 | + </Paragraph> |
| 247 | + </XStack> |
| 248 | + ) |
| 249 | +} |
0 commit comments