Skip to content

Commit

Permalink
timer issue resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
Aliyanishere committed Apr 1, 2024
1 parent 44a5eb4 commit 71e156b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
6 changes: 4 additions & 2 deletions components/common/nft-card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ const NftCard: React.FC<CardProps> = ({
btnClick,
loading,
}) => {
const [timeLeft, setTimeLeft] = useState(expIn ? expIn - Date.now() : 0);
const [timeLeft, setTimeLeft] = useState(
expIn > Date.now() ? expIn - Date.now() : 0
);

const cardStyle = {
width: imageWidth ? `${imageWidth}px` : "165px",
Expand All @@ -45,7 +47,7 @@ const NftCard: React.FC<CardProps> = ({
className={`flex flex-col justify-center items-center cursor-pointer ${divStyle}`}
style={{ width: width ? width : "max-content" }}
>
{expIn && (timeLeft > 0 || btnDisabled) && (
{expIn && timeLeft > 0 && btnDisabled && (
<MineExpiry exp={expIn} setTimeLeft={setTimeLeft} timeLeft={timeLeft} />
)}
{experience && (
Expand Down
9 changes: 4 additions & 5 deletions components/common/nft-card/mine-expiry.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import { useEffect } from "react";

import Utils from "@/lib/utils";

Expand All @@ -12,21 +12,20 @@ const MineExpiry = ({
timeLeft: number;
}) => {
const { formatTime } = Utils();
const [time, setTime] = useState<number>(timeLeft);

useEffect(() => {
const interval = setInterval(() => {
const newTimeLeft = exp - Date.now();
setTime(newTimeLeft);
setTimeLeft(newTimeLeft);
}, 1000);

return () => clearInterval(interval);
}, [exp, setTime, setTimeLeft]);
}, [exp, setTimeLeft]);

return (
<div className="text-center font-bold text-sm mb-1">
Re-activated In: <br />
<span className="font-normal">{formatTime(time)}</span>
<span className="font-normal">{formatTime(timeLeft)}</span>
</div>
);
};
Expand Down
7 changes: 4 additions & 3 deletions components/home/tabs/mine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const MineTab = () => {
},
resource: resourceId,
});
await fetchMineResourcesData(setDataLoader, true);
const data = await fetchMineResourcesData(setDataLoader, true);
setMineData(data);
setLoading({ name: "", status: false });
toast.success(result.data.message || "Resource mined successfully");
} catch (err: any) {
Expand Down Expand Up @@ -71,8 +72,8 @@ const MineTab = () => {
data?.expire - Date.now() > 0 ||
loading.name === data.metadata?.name
}
btnClick={() =>
mineResource(data?.addresses?.resource, data.metadata?.name)
btnClick={async () =>
await mineResource(data?.addresses?.resource, data.metadata?.name)
}
loading={loading}
/>
Expand Down
20 changes: 11 additions & 9 deletions lib/utils/index.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
import AllTab from "@/components/home/inventory/all";
import BarTab from "@/components/home/inventory/bar";
import OresTab from "@/components/home/inventory/ores";
import axios from "axios";
import { toast } from "react-toastify";
import { useWallet } from "@solana/wallet-adapter-react";

import CraftTab from "@/components/home/tabs/craft";
import AdamantiteTab from "@/components/home/tabs/craft/tabs/adamantite";
import BronzeTab from "@/components/home/tabs/craft/tabs/bronze";
import IronTab from "@/components/home/tabs/craft/tabs/iron";
import AdamantiteTab from "@/components/home/tabs/craft/tabs/adamantite";
import MithrilTab from "@/components/home/tabs/craft/tabs/mithril";
import RuniteTab from "@/components/home/tabs/craft/tabs/runite";
import SteelTab from "@/components/home/tabs/craft/tabs/steel";
import MineTab from "@/components/home/tabs/mine";
import RefineTab from "@/components/home/tabs/refine";
import ShopTab from "@/components/home/tabs/shop";
import { API_URL, LUT_ADDRESSES } from "@/config/config";
import OresTab from "@/components/home/inventory/ores";
import AllTab from "@/components/home/inventory/all";
import BarTab from "@/components/home/inventory/bar";

import { useHoneycomb } from "@/hooks";
import { Dataset, Resource } from "@/interfaces";
import { useWallet } from "@solana/wallet-adapter-react";
import axios from "axios";
import { toast } from "react-toastify";
import LevelsData from "../../data/level-data.json";
import { API_URL, LUT_ADDRESSES } from "@/config/config";
import { craftSymbols, inventorySymbols } from "./constants";

let cache = {
craftData: {},
inventoryData: {},
refineData: {},
mindeData: {},
mineData: {},
};

const setCache = (name: string, data: any) => {
Expand Down
3 changes: 2 additions & 1 deletion wrapper/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useWallet } from "@solana/wallet-adapter-react";
import { useRouter } from "next/router";
import { ReactNode, useEffect } from "react";
import { useWallet } from "@solana/wallet-adapter-react";

import { useHoneycomb } from "@/hooks";

interface AuthenticationWrapperProps {
Expand Down

0 comments on commit 71e156b

Please sign in to comment.