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

Fixed countdown visibility relied on the startdate #109

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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
18 changes: 10 additions & 8 deletions src/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import styled from "styled-components";
import Countdown from "react-countdown";
import { Button, CircularProgress, Snackbar } from "@material-ui/core";
Expand Down Expand Up @@ -38,10 +38,13 @@ export interface HomeProps {

const Home = (props: HomeProps) => {
const [balance, setBalance] = useState<number>();
const [isActive, setIsActive] = useState(false); // true when countdown completes
const [isSoldOut, setIsSoldOut] = useState(false); // true when items remaining is zero
const [isMinting, setIsMinting] = useState(false); // true when user got to press MINT

// compare start date and current date to decide display mint button or countdown
const [startDate, setStartDate] = useState(new Date(props.startDate));
const isLive = useMemo(() => startDate <= new Date(), [startDate]);

const [itemsAvailable, setItemsAvailable] = useState(0);
const [itemsRedeemed, setItemsRedeemed] = useState(0);
const [itemsRemaining, setItemsRemaining] = useState(0);
Expand All @@ -52,8 +55,6 @@ const Home = (props: HomeProps) => {
severity: undefined,
});

const [startDate, setStartDate] = useState(new Date(props.startDate));

const wallet = useAnchorWallet();
const [candyMachine, setCandyMachine] = useState<CandyMachine>();

Expand Down Expand Up @@ -179,18 +180,20 @@ const Home = (props: HomeProps) => {

{wallet && <p>Remaining: {itemsRemaining}</p>}

{wallet && <p>Live at: {startDate.toUTCString()}</p>}

<MintContainer>
{!wallet ? (
<ConnectButton>Connect Wallet</ConnectButton>
) : (
<MintButton
disabled={isSoldOut || isMinting || !isActive}
disabled={isSoldOut || isMinting || !isLive}
onClick={onMint}
variant="contained"
>
{isSoldOut ? (
"SOLD OUT"
) : isActive ? (
) : isLive ? (
isMinting ? (
<CircularProgress />
) : (
Expand All @@ -199,8 +202,7 @@ const Home = (props: HomeProps) => {
) : (
<Countdown
date={startDate}
onMount={({ completed }) => completed && setIsActive(true)}
onComplete={() => setIsActive(true)}
onComplete={() => refreshCandyMachineState()}
renderer={renderCounter}
/>
)}
Expand Down