diff --git a/infra/rooch-portal/src/pages/settings/components/manage-sessions.tsx b/infra/rooch-portal/src/pages/settings/components/manage-sessions.tsx index a4d6933c42..172ee7d8c5 100644 --- a/infra/rooch-portal/src/pages/settings/components/manage-sessions.tsx +++ b/infra/rooch-portal/src/pages/settings/components/manage-sessions.tsx @@ -1,5 +1,3 @@ -// Copyright (c) RoochNetwork -// SPDX-License-Identifier: Apache-2.0 import React, { useCallback, useState } from 'react' import { Table, @@ -16,7 +14,7 @@ import { useRemoveSession, useRoochClientQuery, } from '@roochnetwork/rooch-sdk-kit' -import { AlertCircle, Check, ChevronDown, ChevronUp, Copy } from 'lucide-react' +import { AlertCircle, Check, ChevronDown, ChevronUp, Copy, Loader } from 'lucide-react' import { formatTimestamp } from '@/utils/format.ts' @@ -26,6 +24,13 @@ import { copyToClipboard } from '@/utils/copyToClipboard.ts' interface ExpandableRowProps { session: SessionInfoResult remove: (authKey: string) => void + loading: boolean +} + +const isSessionExpired = (createTime: number, maxInactiveInterval: number) => { + const currentTime = Date.now() + const expirationTime = createTime + maxInactiveInterval * 1000 + return currentTime > expirationTime } export const ManageSessions: React.FC = () => { @@ -40,12 +45,19 @@ export const ManageSessions: React.FC = () => { address: sessionKey?.getAddress() || '', }) + const [loading, setLoading] = useState(null) + const remove = useCallback( async (authKey: string) => { - await removeSession({ - authKey: authKey, - }) - await refetch() + setLoading(authKey) + try { + await removeSession({ + authKey: authKey, + }) + await refetch() + } finally { + setLoading(null) + } }, [removeSession, refetch], ) @@ -84,10 +96,6 @@ export const ManageSessions: React.FC = () => { ) } - const sortedSessionKeys = sessionKeys?.data.sort((a: SessionInfoResult, b: SessionInfoResult) => { - return new Date(b.createTime).getTime() - new Date(a.createTime).getTime() - }) - return (
@@ -103,8 +111,13 @@ export const ManageSessions: React.FC = () => { - {sortedSessionKeys?.map((session) => ( - + {sessionKeys?.data.map((session) => ( + ))}
@@ -112,7 +125,7 @@ export const ManageSessions: React.FC = () => { ) } -const ExpandableRow: React.FC = ({ session, remove }) => { +const ExpandableRow: React.FC = ({ session, remove, loading }) => { const [isExpanded, setIsExpanded] = useState(false) const [copiedKeys, setCopiedKeys] = useState([]) @@ -126,6 +139,8 @@ const ExpandableRow: React.FC = ({ session, remove }) => { }) } + const expired = isSessionExpired(Number(session.createTime), session.maxInactiveInterval) + return ( <> @@ -150,14 +165,24 @@ const ExpandableRow: React.FC = ({ session, remove }) => { {session.maxInactiveInterval} - + {loading ? ( +
+ +
+ ) : ( + + )}
{isExpanded && (