Skip to content

Commit

Permalink
Rephrase env variable, add landing page progress
Browse files Browse the repository at this point in the history
  • Loading branch information
kpyszkowski committed Aug 21, 2024
1 parent 5d476c5 commit 7b2d220
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 56 deletions.
2 changes: 1 addition & 1 deletion dapp/.env
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ VITE_FEATURE_FLAG_WITHDRAWALS_ENABLED="false"
VITE_FEATURE_FLAG_OKX_WALLET_ENABLED="false"
VITE_FEATURE_FLAG_XVERSE_WALLET_ENABLED="false"
VITE_FEATURE_FLAG_BEEHIVE_COMPONENT_ENABLED="false"
VITE_FEATURE_FLAG_SEASON_CARD_COMPONENT_ENABLED="false"
VITE_FEATURE_FLAG_TVL_ENABLED="false"

128 changes: 128 additions & 0 deletions dapp/src/components/AcrePointsClaimModal/ArrowAnimatedBackground.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import React, { useEffect, useRef } from "react"
import { BoxProps, Box } from "@chakra-ui/react"

type Point = {
x: number
y: number
}
type Arrow = Point & {
opacity: number
direction: number
}

class ArrowBackgroundAnimation {
readonly ctx: CanvasRenderingContext2D

readonly arrows: Arrow[]

readonly points: Point[]

readonly cols: number

readonly rows: number

constructor(
ctx: CanvasRenderingContext2D,
options: { speedFactor: number; maxDeviation: number } = {
speedFactor: 0.05,
maxDeviation: 50,
},
) {
this.ctx = ctx

// const arrowPath = new Path2D("M8 2V16M8 2L14 8M8 2L2 8")
const gridWidth = 24
const gridHeight = 27

this.cols = Math.floor(this.ctx.canvas.width / gridWidth)
this.rows = Math.floor(this.ctx.canvas.height / gridHeight)

this.arrows = []
for (let i = 0; i < this.cols; i + 1) {
for (let j = 0; j < this.rows; j + 1) {
this.arrows.push({
x: i * gridWidth,
y: j * gridHeight,
opacity: Math.random(),
direction: Math.random() > 0.5 ? 1 : -1,
})
}
}

this.points = []
let lastY = this.ctx.canvas.height / 3
for (let k = 0; k <= this.cols; k + 1) {
const nextY = lastY + (Math.random() - 0.5) * options.maxDeviation
this.points.push({
x: k * gridWidth,
y: Math.min(this.ctx.canvas.height / 2, Math.max(50, nextY)),
})
lastY = nextY
}
}

clearFrame() {
this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height)
}

private updateCurve() {
this.points.forEach((point) => {
point.y += (Math.random() - 0.5) * 2

Check failure on line 70 in dapp/src/components/AcrePointsClaimModal/ArrowAnimatedBackground.tsx

View workflow job for this annotation

GitHub Actions / dapp-format

Assignment to property of function parameter 'point'
})
}

private drawCurve() {
this.ctx.beginPath()
this.ctx.moveTo(this.points[0].x, this.points[0].y)
for (let i = 1; i < this.points.length - 2; i + 1) {
const xc = (this.points[i].x + this.points[i + 1].x) / 2
const yc = (this.points[i].y + this.points[i + 1].y) / 2
this.ctx.quadraticCurveTo(this.points[i].x, this.points[i].y, xc, yc)
}
this.ctx.quadraticCurveTo(
this.points[this.points.length - 2].x,
this.points[this.points.length - 2].y,
this.points[this.points.length - 1].x,
this.points[this.points.length - 1].y,
)
this.ctx.lineTo(this.ctx.canvas.width, this.ctx.canvas.height)
this.ctx.lineTo(0, this.ctx.canvas.height)
this.ctx.closePath()
this.ctx.fillStyle = "rgba(255, 255, 255, 0.1)"
this.ctx.fill()
}

private updateArrows() {}

Check failure on line 95 in dapp/src/components/AcrePointsClaimModal/ArrowAnimatedBackground.tsx

View workflow job for this annotation

GitHub Actions / dapp-format

Expected 'this' to be used by class method 'updateArrows'

private drawArrows() {}

Check failure on line 97 in dapp/src/components/AcrePointsClaimModal/ArrowAnimatedBackground.tsx

View workflow job for this annotation

GitHub Actions / dapp-format

Expected 'this' to be used by class method 'drawArrows'

animate() {
this.clearFrame()
this.updateCurve()
this.drawCurve()
this.updateArrows()
this.drawArrows()
requestAnimationFrame(this.animate.bind(this))
}
}

type ArrowAnimatedBackgroundProps = BoxProps

function ArrowAnimatedBackground(props: ArrowAnimatedBackgroundProps) {
const canvasRef = useRef<HTMLCanvasElement>(null)

useEffect(() => {
const canvasElement = canvasRef.current
const ctx = canvasElement?.getContext("2d")

if (!ctx) return

const animation = new ArrowBackgroundAnimation(ctx)

animation.animate()
}, [])

return <Box as="canvas" ref={canvasRef} {...props} />
}

export default ArrowAnimatedBackground
5 changes: 2 additions & 3 deletions dapp/src/constants/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ const WITHDRAWALS_ENABLED =
const BEEHIVE_COMPONENT_ENABLED =
import.meta.env.VITE_FEATURE_FLAG_BEEHIVE_COMPONENT_ENABLED === "true"

const SEASON_CARD_COMPONENT_ENABLED =
import.meta.env.VITE_FEATURE_FLAG_SEASON_CARD_COMPONENT_ENABLED === "true"
const TVL_ENABLED = import.meta.env.VITE_FEATURE_FLAG_TVL_ENABLED === "true"

const featureFlags = {
GAMIFICATION_ENABLED,
OKX_WALLET_ENABLED,
XVERSE_WALLET_ENABLED,
WITHDRAWALS_ENABLED,
BEEHIVE_COMPONENT_ENABLED,
SEASON_CARD_COMPONENT_ENABLED,
TVL_ENABLED,
}

export default featureFlags
2 changes: 1 addition & 1 deletion dapp/src/pages/DashboardPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function DashboardPage() {
</PageLayoutColumn>

<PageLayoutColumn>
{featureFlags.SEASON_CARD_COMPONENT_ENABLED && (
{featureFlags.TVL_ENABLED && (
<CurrentSeasonCard showSeasonStats={false} />
)}
{/* TODO: Uncomment in post-launch phases */}
Expand Down
103 changes: 53 additions & 50 deletions dapp/src/pages/LandingPage/components/CurrentSeasonSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import {
CardBody,
Image,
} from "@chakra-ui/react"
// import ProgressBar from "#/components/shared/ProgressBar"
// import { CurrencyBalance } from "#/components/shared/CurrencyBalance"
import ProgressBar from "#/components/shared/ProgressBar"
import { CurrencyBalance } from "#/components/shared/CurrencyBalance"
import { H3, TextMd } from "#/components/shared/Typography"
// import { SEASON_CAP } from "#/constants"
import { featureFlags, SEASON_CAP } from "#/constants"
import { LiveTag } from "#/components/shared/LiveTag"
import { SeasonSectionBackground } from "#/components/shared/SeasonSectionBackground"
// import { useSeasonProgress } from "#/hooks"
import { useSeasonProgress } from "#/hooks"
import { mezoLogoColor } from "#/assets/images/partner-logos"

export default function CurrentSeasonSection() {
// const { progress: seasonProgress, value: seasonTotalAssets } =
// useSeasonProgress()
const { progress: seasonProgress, value: seasonTotalAssets } =
useSeasonProgress()

return (
<Box position="relative" mb={5}>
Expand Down Expand Up @@ -78,52 +78,55 @@ export default function CurrentSeasonSection() {
Season 1 stakers will soon be able to earn Acre and Mezo points.
</TextMd>

{/* TODO: Uncomment when TVL is higher */}
{/* <TextMd fontWeight="semibold" mb={4}>
Total value locked
</TextMd>
{featureFlags.TVL_ENABLED && (
<>
<TextMd fontWeight="semibold" mb={4}>
Total value locked
</TextMd>

<ProgressBar
size={{
base: "xl",
md: "2xl",
}}
value={seasonProgress}
maxW="50rem" // 800px
>
<CurrencyBalance
amount={seasonTotalAssets}
currency="bitcoin"
variant={{
base: "greater-balance-md",
md: "greater-balance-xl",
}}
symbolFontWeight="black"
desiredDecimals={2}
// TODO: Refactor `CurrencyBalance` to make font styles truely adjustable
/>
</ProgressBar>
<ProgressBar
size={{
base: "xl",
md: "2xl",
}}
value={seasonProgress}
maxW="50rem" // 800px
>
<CurrencyBalance
amount={seasonTotalAssets}
currency="bitcoin"
variant={{
base: "greater-balance-md",
md: "greater-balance-xl",
}}
symbolFontWeight="black"
desiredDecimals={2}
// TODO: Refactor `CurrencyBalance` to make font styles truely adjustable
/>
</ProgressBar>

<TextMd
fontSize={{ md: "xl" }}
lineHeight={{ md: "xl" }}
display="flex"
whiteSpace="pre"
mt={2}
mb={{
base: 10,
md: "7.5rem", // 120px
}}
>
Season 1 cap{" "}
<CurrencyBalance
as="span"
size={{ base: "", md: "xl" }}
amount={SEASON_CAP}
currency="bitcoin"
desiredDecimals={0}
/>
</TextMd> */}
<TextMd
fontSize={{ md: "xl" }}
lineHeight={{ md: "xl" }}
display="flex"
whiteSpace="pre"
mt={2}
mb={{
base: 10,
md: "7.5rem", // 120px
}}
>
Season 1 cap{" "}
<CurrencyBalance
as="span"
size={{ base: "", md: "xl" }}
amount={SEASON_CAP}
currency="bitcoin"
desiredDecimals={0}
/>
</TextMd>
</>
)}

{/* TODO: Uncomment in post-launch phases */}
{/* <Flex
Expand Down
2 changes: 1 addition & 1 deletion dapp/src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface ImportMetaEnv {
readonly VITE_FEATURE_FLAG_OKX_WALLET_ENABLED: string
readonly VITE_FEATURE_FLAG_XVERSE_WALLET_ENABLED: string
readonly VITE_FEATURE_FLAG_BEEHIVE_COMPONENT_ENABLED: string
readonly VITE_FEATURE_FLAG_SEASON_CARD_COMPONENT_ENABLED: string
readonly VITE_FEATURE_FLAG_TVL_ENABLED: string
readonly VITE_SUBGRAPH_API_KEY: string
readonly VITE_MEZO_PORTAL_API_KEY: string
readonly VITE_LATEST_COMMIT_HASH: string
Expand Down

0 comments on commit 7b2d220

Please sign in to comment.