Skip to content

Commit

Permalink
fix: use consts for thresholds
Browse files Browse the repository at this point in the history
  • Loading branch information
DiogoSoaress committed Jul 8, 2024
1 parent 9b07ddb commit 586e4fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
9 changes: 0 additions & 9 deletions src/components/DataRoom/CryptoPunks/utils.ts

This file was deleted.

11 changes: 8 additions & 3 deletions src/components/DataRoom/TransactionsOnChain/useCounterScroll.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import type { MotionValue } from 'framer-motion'
import { useEffect, useState } from 'react'

// Thresholds for scroll progress
const SCROLL_THRESHOLD_UPPER = 0.21
const SCROLL_THRESHOLD_LOWER = 0.2
const INITIAL_VALUE = 0

// Custom hook for managing counter based on scroll
export function useCounterScroll(scrollYProgress: MotionValue<number>, percentage: number): number {
const [value, setValue] = useState(0)

useEffect(() => {
const checkScrollProgress = () => {
const latest = scrollYProgress.get()
if (latest >= 0.21) {
if (latest >= SCROLL_THRESHOLD_UPPER) {
setValue(percentage)
} else if (latest <= 0.2) {
setValue(0)
} else if (latest <= SCROLL_THRESHOLD_LOWER) {
setValue(INITIAL_VALUE)
}
}

Expand Down

0 comments on commit 586e4fe

Please sign in to comment.