From 3faf7f2f3904aab76915fda3268773d02a436f76 Mon Sep 17 00:00:00 2001 From: urnotsam Date: Wed, 4 Dec 2024 15:37:20 -0500 Subject: [PATCH 1/3] Add notification for when unstake is available --- components/molecules/NodeStatus.tsx | 18 +++++++++++++++++- hooks/useNodeStatus.ts | 25 ++++++++++++++++++------- hooks/useNotificationsStore.ts | 3 ++- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/components/molecules/NodeStatus.tsx b/components/molecules/NodeStatus.tsx index d7e14e4..838d721 100644 --- a/components/molecules/NodeStatus.tsx +++ b/components/molecules/NodeStatus.tsx @@ -216,7 +216,8 @@ export const getDurationBreakdownString = (duration: number) => { }; export const NodeStatus = ({ isWalletConnected, address }: NodeStatusProps) => { - const { nodeStatus, isLoading, startNode, stopNode } = useNodeStatus(); + const { nodeStatus, isLoading, startNode, stopNode, notifyUnstake } = + useNodeStatus(); // const { nodeStatusHistory } = useNodeStatusHistory(address || ""); const state: NodeState = getNodeState(nodeStatus); @@ -402,6 +403,21 @@ export const NodeStatus = ({ isWalletConnected, address }: NodeStatusProps) => { } }, [nodeStatus?.state, currentStatus]); + useEffect(() => { + if (notifyUnstake) { + setCurrentToast({ + severity: ToastSeverity.SUCCESS, + title: "Node can be unstaked", + description: "Your node can now be unstaked.", + followupNotification: { + type: NotificationType.UNSTAKE_STATUS, + severity: NotificationSeverity.SUCCESS, + title: "Your node can now be unstaked.", + }, + }); + } + }, [notifyUnstake, setCurrentToast]); + const toggleShowMoreInfo = () => { setShowMoreInfo((prevState: boolean) => !prevState); }; diff --git a/hooks/useNodeStatus.ts b/hooks/useNodeStatus.ts index b35544e..619ad45 100644 --- a/hooks/useNodeStatus.ts +++ b/hooks/useNodeStatus.ts @@ -1,17 +1,18 @@ import useSWR from 'swr' import { fetcher } from './fetcher' import { NodeStatus } from '../model/node-status' -import { useContext, useState } from 'react' -import { useGlobals } from '../utils/globals' -import { FetcherContext } from '../components/FetcherContextProvider'; -import { showErrorMessage } from './useToastStore' +import { useContext, useEffect, useState } from "react"; +import { useGlobals } from "../utils/globals"; +import { FetcherContext } from "../components/FetcherContextProvider"; +import { showErrorMessage } from "./useToastStore"; type NodeStatusResponse = { nodeStatus: NodeStatus | undefined; startNode: Function; stopNode: Function; isLoading: boolean; -} + notifyUnstake: boolean; +}; export const useNodeStatus = (): NodeStatusResponse => { const { apiBase } = useGlobals() @@ -19,6 +20,16 @@ export const useNodeStatus = (): NodeStatusResponse => { const fetcherWithContext = useContext(FetcherContext); const { data, mutate } = useSWR(nodeStatusApi, fetcherWithContext, { refreshInterval: 1000 }) const [isLoading, setIsLoading] = useState(false) + const [hasShownUnstakeNotification, setHasShownUnstakeNotification] = + useState(false); + + useEffect(() => { + if (data?.stakeState?.canUnstake && !hasShownUnstakeNotification) { + setHasShownUnstakeNotification(true); + } else if (!data?.stakeState?.canUnstake && hasShownUnstakeNotification) { + setHasShownUnstakeNotification(false); + } + }, [data]); const startNode = async (): Promise => { setIsLoading(true) @@ -46,8 +57,8 @@ export const useNodeStatus = (): NodeStatusResponse => { nodeStatus: data, startNode, stopNode, - isLoading - } + isLoading, + notifyUnstake: hasShownUnstakeNotification, } diff --git a/hooks/useNotificationsStore.ts b/hooks/useNotificationsStore.ts index e7cb7aa..d66ae09 100644 --- a/hooks/useNotificationsStore.ts +++ b/hooks/useNotificationsStore.ts @@ -5,7 +5,8 @@ export enum NotificationType { NODE_STATUS = "NODE_STATUS", ERROR = "ERROR", REWARD = "REWARD", - VERSION_UPDATE = "VERSION_UPDATE" + VERSION_UPDATE = "VERSION_UPDATE", + UNSTAKE_STATUS = "UNSTAKE_STATUS", } export enum NotificationSeverity { From b2fb7a0edf1877d4ab7d0ec8d61af9a770772485 Mon Sep 17 00:00:00 2001 From: Sam Sweet Date: Wed, 4 Dec 2024 15:38:17 -0500 Subject: [PATCH 2/3] add missing closing brace --- hooks/useNodeStatus.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/hooks/useNodeStatus.ts b/hooks/useNodeStatus.ts index 619ad45..26951b8 100644 --- a/hooks/useNodeStatus.ts +++ b/hooks/useNodeStatus.ts @@ -59,6 +59,7 @@ export const useNodeStatus = (): NodeStatusResponse => { stopNode, isLoading, notifyUnstake: hasShownUnstakeNotification, + }; } From 7a297b4f91a7d0bb4812ab0f80ec8d90815c7d86 Mon Sep 17 00:00:00 2001 From: urnotsam Date: Wed, 4 Dec 2024 15:46:00 -0500 Subject: [PATCH 3/3] canUnstake renames to unlocked --- hooks/useNodeStatus.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hooks/useNodeStatus.ts b/hooks/useNodeStatus.ts index 26951b8..5bdaea2 100644 --- a/hooks/useNodeStatus.ts +++ b/hooks/useNodeStatus.ts @@ -24,9 +24,9 @@ export const useNodeStatus = (): NodeStatusResponse => { useState(false); useEffect(() => { - if (data?.stakeState?.canUnstake && !hasShownUnstakeNotification) { + if (data?.stakeState?.unlocked && !hasShownUnstakeNotification) { setHasShownUnstakeNotification(true); - } else if (!data?.stakeState?.canUnstake && hasShownUnstakeNotification) { + } else if (!data?.stakeState?.unlocked && hasShownUnstakeNotification) { setHasShownUnstakeNotification(false); } }, [data]);