Skip to content

Commit e72629b

Browse files
committed
implement delay to progress cta button
extract common delay duration to a shared constant
1 parent 92899ab commit e72629b

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

src/components/Simulator/PulseAnimation.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import React from "react"
22
import { Box } from "@chakra-ui/react"
33
import { motion } from "framer-motion"
4-
import { CIRCLE, FULL_BUTTON, NARROW_BUTTON } from "./constants"
4+
import {
5+
BASE_ANIMATION_DELAY_SEC,
6+
CIRCLE,
7+
FULL_BUTTON,
8+
NARROW_BUTTON,
9+
} from "./constants"
510
import type { PulseOption } from "./types"
611

712
const MotionBox = motion(Box)
@@ -14,8 +19,7 @@ export const PulseAnimation: React.FC<IProps> = ({ type = CIRCLE }) => {
1419
const scaleY = type === FULL_BUTTON ? 1.7 : type === NARROW_BUTTON ? 1.5 : 1.5
1520
const inset = type === NARROW_BUTTON ? -1 : 0
1621
const borderRadius = type === FULL_BUTTON ? "base" : "full"
17-
const BASE_DURATION = 2.5
18-
const delay = type === NARROW_BUTTON ? 0 : BASE_DURATION
22+
const delay = type === NARROW_BUTTON ? 0 : BASE_ANIMATION_DELAY_SEC
1923
return (
2024
<MotionBox
2125
position="absolute"
@@ -26,7 +30,7 @@ export const PulseAnimation: React.FC<IProps> = ({ type = CIRCLE }) => {
2630
initial={{ scale: 1 }}
2731
animate={{ scaleX, scaleY, opacity: [0, 1, 0] }}
2832
transition={{
29-
duration: 2.5,
33+
duration: BASE_ANIMATION_DELAY_SEC,
3034
repeat: Infinity,
3135
ease: "easeOut",
3236
delay,

src/components/Simulator/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ export const defaultTokenBalances: Array<TokenBalance> = [
4343
export const FALLBACK_ETH_PRICE = 1000
4444
export const USD_RECEIVE_AMOUNT = 50
4545
export const ETH_TRANSFER_FEE = 0.00042 // 21_000gas * 20gwei
46+
47+
export const BASE_ANIMATION_DELAY_SEC = 2.5

src/components/Simulator/screens/ConnectWeb3/Browser.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { IoEllipsisHorizontalSharp } from "react-icons/io5"
77
import { motion } from "framer-motion"
88
import { NotificationPopover } from "../../NotificationPopover"
99
import { EXAMPLE_APP_URL } from "./constants"
10+
import { BASE_ANIMATION_DELAY_SEC } from "../../constants"
1011

1112
interface IProps extends FlexProps {
1213
progressStepper: () => void
@@ -16,7 +17,7 @@ export const Browser: React.FC<IProps> = ({ progressStepper, ...props }) => {
1617
useEffect(() => {
1718
const timeout = setTimeout(() => {
1819
setTyping(true)
19-
}, 3000)
20+
}, BASE_ANIMATION_DELAY_SEC * 1000)
2021
return () => clearTimeout(timeout)
2122
}, [])
2223

src/components/Simulator/screens/ConnectWeb3/index.tsx

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
import { Box, Button, Flex, Icon, Text } from "@chakra-ui/react"
2-
import React, { useMemo, useState } from "react"
2+
import React, { useEffect, useMemo, useState } from "react"
33
import {
44
RiPriceTag2Line,
55
RiAuctionLine,
66
RiFileTransferLine,
77
} from "react-icons/ri"
88
import { AnimatePresence, motion } from "framer-motion"
9-
import { Slider } from "./Slider"
10-
import { Web3App } from "./Web3App"
9+
import GatsbyImage from "../../../GatsbyImage"
10+
import { NotificationPopover } from "../../NotificationPopover"
1111
import { ProgressCta } from "../../ProgressCta"
1212
import { WalletHome } from "../../WalletHome"
13-
import type { PhoneScreenProps } from "../../interfaces"
1413
import type { TokenBalance } from "../../WalletHome/interfaces"
15-
import { defaultTokenBalances } from "../../constants"
16-
import { useEthPrice } from "../../../../hooks/useEthPrice"
1714
import { useNFT } from "../../WalletHome/hooks/useNFT"
18-
import GatsbyImage from "../../../GatsbyImage"
19-
import { FALLBACK_ETH_PRICE, USD_RECEIVE_AMOUNT } from "../../constants"
20-
import { EXAMPLE_APP_URL } from "./constants"
2115
import { Browser } from "./Browser"
22-
import { NotificationPopover } from "../../NotificationPopover"
16+
import { Slider } from "./Slider"
17+
import { Web3App } from "./Web3App"
18+
import {
19+
defaultTokenBalances,
20+
FALLBACK_ETH_PRICE,
21+
USD_RECEIVE_AMOUNT,
22+
BASE_ANIMATION_DELAY_SEC,
23+
} from "../../constants"
24+
import { EXAMPLE_APP_URL } from "./constants"
25+
import type { PhoneScreenProps } from "../../interfaces"
26+
import { useEthPrice } from "../../../../hooks/useEthPrice"
2327

2428
export const ConnectWeb3: React.FC<PhoneScreenProps> = ({ nav, ctaLabel }) => {
2529
const { progressStepper, step } = nav
@@ -45,6 +49,17 @@ export const ConnectWeb3: React.FC<PhoneScreenProps> = ({ nav, ctaLabel }) => {
4549
initial: { opacity: 0 },
4650
animate: { opacity: 1 },
4751
}
52+
53+
// Enable ProgressCta button after short delay for first step
54+
const [ctaDisabled, setCtaDisabled] = useState(step === 0)
55+
useEffect(() => {
56+
if (step !== 0) return
57+
const timeout = setTimeout(() => {
58+
setCtaDisabled(false)
59+
}, BASE_ANIMATION_DELAY_SEC * 1000)
60+
return () => clearTimeout(timeout)
61+
}, [])
62+
4863
return (
4964
<>
5065
{[0].includes(step) && <Browser progressStepper={progressStepper} />}
@@ -173,6 +188,7 @@ export const ConnectWeb3: React.FC<PhoneScreenProps> = ({ nav, ctaLabel }) => {
173188
{[0, 1, 2, 3, 4].includes(step) && (
174189
<ProgressCta
175190
isAnimated={step === 0}
191+
isDisabled={ctaDisabled}
176192
progressStepper={progressStepper}
177193
mb={step === 0 ? 16 : 0}
178194
>

0 commit comments

Comments
 (0)