diff --git a/src/components/common/ConnectWalletButton.tsx b/src/components/common/ConnectWalletButton.tsx index 075f96dc..09f436fc 100644 --- a/src/components/common/ConnectWalletButton.tsx +++ b/src/components/common/ConnectWalletButton.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { useAccount, useConnect, useDisconnect } from 'wagmi'; import { Copy, Check } from 'lucide-react'; import { @@ -21,10 +21,12 @@ import { useCopySuccessAnnouncement } from '@/hooks/useCopySuccessAnnouncement'; import CopySuccessAnnouncement from '@/components/common/CopySuccessAnnouncement'; import showToast from '@/utils/toast.util'; import { copyTextToClipboard } from '@/utils/clipboard.utils'; +import { logWalletDisconnectSession } from '@/lib/walletSessionLog'; function ConnectWalletButton() { const [showDisconnectDialog, setShowDisconnectDialog] = useState(false); const [copied, setCopied] = useState(false); + const connectedAtRef = useRef(null); const { address, isConnected } = useAccount(); const { connect, connectors, error, isPending } = useConnect(); const { disconnect } = useDisconnect(); @@ -51,6 +53,17 @@ function ConnectWalletButton() { } }; + useEffect(() => { + if (isConnected && address && connectedAtRef.current == null) { + connectedAtRef.current = Date.now(); + return; + } + + if (!isConnected) { + connectedAtRef.current = null; + } + }, [address, isConnected]); + if (isConnected && address) { return ( <> @@ -84,7 +97,14 @@ function ConnectWalletButton() { type="button" variant="destructive" onClick={() => { + if (connectedAtRef.current != null) { + logWalletDisconnectSession( + address, + connectedAtRef.current + ); + } disconnect(); + connectedAtRef.current = null; setShowDisconnectDialog(false); }} > diff --git a/src/components/common/CreatorPageErrorBoundary.tsx b/src/components/common/CreatorPageErrorBoundary.tsx index 8dffcdfe..8b7edf45 100644 --- a/src/components/common/CreatorPageErrorBoundary.tsx +++ b/src/components/common/CreatorPageErrorBoundary.tsx @@ -2,6 +2,7 @@ import { Component, type ErrorInfo, type ReactNode } from 'react'; import { Link } from 'react-router'; import { AlertCircle, ArrowLeft } from 'lucide-react'; import { Button } from '@/components/ui/button'; +import { ApiError } from '@/services/api.service'; interface Props { children: ReactNode; @@ -9,6 +10,7 @@ interface Props { interface State { hasError: boolean; + error: Error | null; } /** @@ -19,10 +21,11 @@ interface State { class CreatorPageErrorBoundary extends Component { public state: State = { hasError: false, + error: null, }; - public static getDerivedStateFromError(): State { - return { hasError: true }; + public static getDerivedStateFromError(error: Error): State { + return { hasError: true, error }; } public componentDidCatch(error: Error, errorInfo: ErrorInfo) { @@ -33,6 +36,10 @@ class CreatorPageErrorBoundary extends Component { public render() { if (this.state.hasError) { + const isNotFound = + this.state.error instanceof ApiError && + this.state.error.status === 404; + return (
{