import { useEffect } from "react";
import { usePublicKey } from "../providers/AccountProvider/usePublicKey";
import { APP_VERSION, RELEASE_NOTICE } from "../version";
import { useSendSystemMessage } from "../providers/SystemAccountsProvider/useSendSystemMessage";

export function useUpdateMessage() {
    const publicKey = usePublicKey();
    const lastNoticeVersion = localStorage.getItem("lastNoticeVersion") || "0.0.0";
    const send = useSendSystemMessage("updates");

    useEffect(() => {
        if(publicKey == ""){
            return;
        }
        if(lastNoticeVersion !== APP_VERSION){
            send(RELEASE_NOTICE);
            localStorage.setItem("lastNoticeVersion", APP_VERSION);
        }
    }, [lastNoticeVersion, publicKey]);
}