import {
Box,
BoxProps,
Center,
HStack,
Icon,
Progress,
Spinner,
Stack,
Text,
TextProps,
Tooltip,
useColorModeValue,
useDisclosure,
VStack,
} from "@chakra-ui/react";
import { PublicKey } from "@solana/web3.js";
import {
useCapInfo,
useCurve,
useSolanaUnixTime,
useTokenSwapFromId,
useMetaplexTokenMetadata,
} from "@strata-foundation/react";
import React, { useEffect, useState } from "react";
import { buildStyles, CircularProgressbar } from "react-circular-progressbar";
import { useLivePrice } from "../..//hooks/useLivePrice";
import { numberWithCommas } from "../../utils/numberWithCommas";
import { RiInformationFill } from "react-icons/ri";
import ReactCountdown from "react-countdown";
export const BlackBox = ({ children, ...other }: BoxProps) => {
return (
{children}
);
};
export const BigText = ({ children, ...other }: TextProps) => {
return (
{children}
);
};
export const LbcInfo = ({
id,
useTokenOfferingCurve = false,
price: inputPrice,
}: {
id: PublicKey;
useTokenOfferingCurve?: boolean;
price?: number;
}) => {
const { isOpen, onToggle } = useDisclosure({
defaultIsOpen: false,
});
const {
tokenBonding,
numRemaining,
loading: loadingBonding,
} = useTokenSwapFromId(id);
const { price, loading: loadingPricing } = useLivePrice(
tokenBonding?.publicKey
);
const { mintCap } = useCapInfo(
tokenBonding?.publicKey,
useTokenOfferingCurve
);
const priceToUse = inputPrice || price;
const { info: curve } = useCurve(tokenBonding?.curve);
const maxTime =
// @ts-ignore
curve?.definition.timeV0.curves[0].curve.timeDecayExponentialCurveV0
.interval;
const unixTime = useSolanaUnixTime();
const [elapsedTime, setElapsedTime] = useState();
useEffect(() => {
setElapsedTime(
tokenBonding
? (unixTime || new Date().valueOf() / 1000) -
tokenBonding.goLiveUnixTime.toNumber()
: undefined
);
}, [unixTime]);
const endDate = new Date(0);
endDate.setUTCSeconds(
(tokenBonding?.goLiveUnixTime.toNumber() || 0) + (maxTime || 0)
);
const isLive =
tokenBonding && unixTime
? tokenBonding.goLiveUnixTime.toNumber() < unixTime
: false;
const { metadata } = useMetaplexTokenMetadata(tokenBonding?.baseMint);
const { metadata: targetMeta } = useMetaplexTokenMetadata(
tokenBonding?.targetMint
);
const renderer = ({
days,
hours,
minutes,
seconds,
completed,
}: {
days: number;
hours: number;
minutes: number;
seconds: number;
completed: boolean;
}) => {
if (completed) {
return Finished;
}
return (
{days ? `${days} Days, ` : ""}
{`${hours}`.padStart(2, "0")}:{`${minutes}`.padStart(2, "0")}:
{`${seconds}`.padStart(2, "0")}
);
};
return (
Time Remaining
{isLive ? (
// @ts-ignore
(unixTime ? unixTime * 1000 : new Date().valueOf())}
renderer={renderer}
/>
) : (
Not Started
)}
Price
{loadingPricing || typeof priceToUse == "undefined" ? (
) : (
{isNaN(priceToUse)
? "Not Started"
: metadata?.data.symbol === "USDC"
? `$${numberWithCommas(priceToUse, 2)}`
: `${numberWithCommas(priceToUse, 4)} ${
metadata?.data.symbol
}`}
)}
Remaining
{loadingBonding ? (
) : (
{numRemaining ? numberWithCommas(numRemaining, 4) : "0"}{" "}
{targetMeta?.data.symbol}
)}
);
};