Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hardcode timer (TO REVERT) #2425

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/src/hooks/useSeasonStart.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { configManager } from "@/dojo/setup";
//import { configManager } from "@/dojo/setup";
import { useMemo, useState } from "react";

export const useSeasonStart = () => {
const seasonStart = useMemo(() => BigInt(configManager.getSeasonConfig().startAt || 0), []);
const seasonStart = BigInt(new Date("2024-12-11T15:35:00Z").getTime() / 1000);/*useMemo(() => BigInt(configManager.getSeasonConfig().startAt || 0), []);*/
const nextBlockTimestamp = useMemo(() => BigInt(Math.floor(Date.now() / 1000)), []);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid hardcoding future dates and consider configuration-based approach

Several concerns with the current implementation:

  1. Hardcoding dates makes the code less maintainable and requires code changes for future seasons
  2. The date is set to December 2024, which means this code will need to be updated
  3. The inline comment with the old implementation should be removed

Consider these alternatives:

  1. Move the date to an environment variable or configuration file
  2. Implement a more flexible system that can handle multiple seasons without code changes
  3. Add validation for the date to ensure it's not in the past

Example implementation:

const seasonStart = useMemo(() => {
  const configuredDate = process.env.SEASON_START_DATE || "2024-12-11T15:35:00Z";
  const timestamp = new Date(configuredDate).getTime() / 1000;
  if (timestamp < Date.now() / 1000) {
    console.warn("Season start date is in the past");
  }
  return BigInt(timestamp);
}, []);


const [countdown, setCountdown] = useState<bigint>(0n);
Expand Down
2 changes: 1 addition & 1 deletion landing/src/components/modules/season-start-timer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const SeasonStartTimer = () => {

return (
<div className="text-3xl text-primary font-semibold">
{String(hours).padStart(2, "0")}:{String(minutes).padStart(2, "0")}:{String(seconds).padStart(2, "0")}
{"<"} {String(hours).padStart(2, "0")}:{String(minutes).padStart(2, "0")}:{String(seconds).padStart(2, "0")}
</div>
);
};
1 change: 1 addition & 0 deletions landing/src/components/ui/elements/CountdownTimer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function CountdownTimer() {

<TypeH1 className="tracking-wider">Eternum is Launching in</TypeH1>
<div className="flex gap-4 text-center mt-4 mx-auto">
<span className="text-4xl font-bold">{"<"}</span>
<TimeUnit value={days} label="Days" />
<TimeUnit value={hours} label="Hours" />
<TimeUnit value={minutes} label="Minutes" />
Expand Down
5 changes: 3 additions & 2 deletions landing/src/hooks/use-season-start.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { configManager } from "@/dojo/setup";
import { useEffect, useState } from "react";

export const useSeasonStart = () => {
const seasonStart = BigInt(configManager.getSeasonConfig().startAt || 0);
const seasonStart = BigInt(new Date("2024-12-11T15:35:00Z").getTime() / 1000);

/*BigInt(configManager.getSeasonConfig().startAt || 0);*/
const nextBlockTimestamp = BigInt(Math.floor(Date.now() / 1000));
Comment on lines +4 to +6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical: Reconsider hardcoding the season start date

The change from a configuration-based approach to a hardcoded date raises several concerns:

  1. Hardcoding dates makes the code less maintainable and requires code changes for future seasons
  2. The date is set to December 2024, which seems unusually far in the future
  3. The commented-out code should be removed rather than left in the codebase

Consider these alternatives:

  1. Keep using the configuration-based approach for flexibility
  2. If a fixed date is required, move it to a configuration file
  3. Add error handling for the date conversion
-  const seasonStart = BigInt(new Date("2024-12-11T15:35:00Z").getTime() / 1000);
-    
-  /*BigInt(configManager.getSeasonConfig().startAt || 0);*/
+  const seasonStart = BigInt(configManager.getSeasonConfig().startAt || 0);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const seasonStart = BigInt(new Date("2024-12-11T15:35:00Z").getTime() / 1000);
/*BigInt(configManager.getSeasonConfig().startAt || 0);*/
const seasonStart = BigInt(configManager.getSeasonConfig().startAt || 0);


const [countdown, setCountdown] = useState<bigint>(0n);
Expand Down
Loading