diff --git a/components/molecules/RewardsCard.tsx b/components/molecules/RewardsCard.tsx index 22ad910..041d32c 100644 --- a/components/molecules/RewardsCard.tsx +++ b/components/molecules/RewardsCard.tsx @@ -8,6 +8,7 @@ import useModalStore from "../../hooks/useModalStore"; import { ConfirmRedemptionModal } from "./ConfirmRedemptionModal"; import { MobileModalWrapper } from "../layouts/MobileModalWrapper"; import { BgImage } from "../atoms/BgImage"; +import {useAccountStakeInfo} from '../../hooks/useAccountStakeInfo'; function formatDate(date: Date) { // Format date and time separately @@ -37,13 +38,14 @@ export const RewardsCard = () => { ); const { nodeStatus } = useNodeStatus(); const { address, isConnected } = useAccount(); + const { stakeInfo } = useAccountStakeInfo(address); const { chain } = useNetwork(); const [canRedeem, setCanRedeem] = useState( isConnected && chain?.id === CHAIN_ID && nodeStatus?.state === "stopped" && parseFloat(nodeStatus?.lockedStake || "0") > 0 && - nodeStatus?.unstakable?.canUnstake + nodeStatus?.stakeState?.canUnstake ); useEffect(() => { setCanRedeem( @@ -63,7 +65,7 @@ export const RewardsCard = () => {
- {parseFloat(nodeStatus?.currentRewards || "0").toFixed(2)}{" "} + {parseFloat(stakeInfo?.rewards ?? nodeStatus?.currentRewards ?? "0").toFixed(2)}{" "} SHM {/* (~0.00$) */} @@ -107,10 +109,8 @@ export const RewardsCard = () => { > diff --git a/components/molecules/StakeDisplay.tsx b/components/molecules/StakeDisplay.tsx index a7e5242..f3dd804 100644 --- a/components/molecules/StakeDisplay.tsx +++ b/components/molecules/StakeDisplay.tsx @@ -26,13 +26,7 @@ export const StakeDisplay = () => { ); const [hasNodeStopped, setHasNodeStopped] = useState(false); - const minimumStakeRequirement = useMemo(() => { - return Math.max( - parseFloat(nodeStatus?.stakeRequirement || "10") - - parseFloat(nodeStatus?.lockedStake || "0"), - 0 - ); - }, [nodeStatus?.stakeRequirement, nodeStatus?.lockedStake]); + const minimumStakeRequirement = parseFloat(nodeStatus?.stakeRequirement || "10") useEffect(() => { if (nodeStatus?.state === "stopped") { @@ -48,130 +42,141 @@ export const StakeDisplay = () => { return `${minutes}m ${seconds}s`; }; + const stakeForConnectedAddressOrNode = parseFloat((stakeInfo?.stake?.trim() || nodeStatus?.lockedStake || "0")); + const hasStakeOnDifferentNode = (stakeInfo?.stake ?? "0.0") > "0.0" && + nodeStatus?.nomineeAddress != null && + stakeInfo?.nominee !== nodeStatus?.nomineeAddress; + + const isRemoveButtonDisabled = !hasStakeOnDifferentNode && ( + !hasNodeStopped || + !nodeStatus?.stakeState) || + stakeForConnectedAddressOrNode === 0; + return ( -
-
- - {parseFloat( - nodeStatus?.lockedStake ? nodeStatus?.lockedStake : "0" - ).toFixed(2)}{" "} - SHM - -
- Min. requirement: - {minimumStakeRequirement} SHM -
-
-
-
- Stake Address -
-
- - {address} - + <> +
+
+ + {stakeForConnectedAddressOrNode.toFixed(2)}{" "} + SHM + +
+ Min. requirement: + {minimumStakeRequirement} SHM
-
-
-
- {isConnected && chain?.id === CHAIN_ID ? ( -
- +
+
+
+ {isConnected && chain?.id === CHAIN_ID ? ( +
+ + - -
- ) : ( - - )} + disabled={hasNodeStopped || !nodeStatus?.nomineeAddress} + onClick={() => { + resetModal(); + setContent( + + + + ); + setShowModal(true); + }} + > + Add Stake + +
+ ) : ( + + )} +
-
+ {(hasStakeOnDifferentNode && +
+ + This wallet already has an active stake on a different + node. Remove your stake first if you wish to stake for + the current node. + +
+ )} + ); }; diff --git a/components/organisms/SettingsDisplay.tsx b/components/organisms/SettingsDisplay.tsx index 6b43f7a..924aede 100644 --- a/components/organisms/SettingsDisplay.tsx +++ b/components/organisms/SettingsDisplay.tsx @@ -56,7 +56,7 @@ export const SettingsDisplay = () => { } nominator={address?.toString() || ""} nominee={stakeInfo?.nominee || ""} - currentRewards={parseFloat(nodeStatus?.currentRewards || "0")} + currentRewards={parseFloat(stakeInfo?.rewards ?? nodeStatus?.currentRewards ?? "0")} currentStake={parseFloat(stakeInfo?.stake || "0")} /> )} diff --git a/model/account-stake-info.ts b/model/account-stake-info.ts index 4a5f4f6..524d48d 100644 --- a/model/account-stake-info.ts +++ b/model/account-stake-info.ts @@ -1,4 +1,5 @@ export interface AccountStakeInfo { stake: string, - nominee: string + nominee: string, + rewards: string } diff --git a/model/node-status.ts b/model/node-status.ts index 9f31593..489afa8 100644 --- a/model/node-status.ts +++ b/model/node-status.ts @@ -16,7 +16,7 @@ export interface NodeStatus { totalTimeValidating: number; lastActive: string; lockedStake: string; - unstakable: { + stakeState: { canUnstake: boolean; reason: string, remainingTime: number, diff --git a/pages/dashboard/index.tsx b/pages/dashboard/index.tsx index 4ffbc9c..424c5f6 100644 --- a/pages/dashboard/index.tsx +++ b/pages/dashboard/index.tsx @@ -20,7 +20,6 @@ import useNotificationsStore from "../../hooks/useNotificationsStore"; import { ToastWindow } from "../../components/molecules/ToastWindow"; import { useDevice } from "../../context/device"; import { NodeStatusRibbon } from "../../components/molecules/NodeStatusRibbon"; -import { useAccount } from "wagmi"; import { MobileModalWrapper } from "../../components/layouts/MobileModalWrapper"; import useModalStore from "../../hooks/useModalStore"; import { MobileMenu } from "../../components/molecules/MobileMenu"; @@ -53,7 +52,6 @@ const Dashboard = () => { setContentPane(Content.LOGS); }; const { isMobile } = useDevice(); - const { isConnected } = useAccount(); const { setShowModal, setContent } = useModalStore((state: any) => ({ setShowModal: state.setShowModal, setContent: state.setContent,