Skip to content

Commit

Permalink
Portal 240617 (#1902)
Browse files Browse the repository at this point in the history
* chore: fix time

* chore: expired session key
  • Loading branch information
TwilightLogic authored Jun 17, 2024
1 parent 054710c commit c63a38d
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 252 deletions.
1 change: 0 additions & 1 deletion infra/rooch-portal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"cmdk": "^0.2.1",
"dayjs": "^1.11.11",
"i18next": "^23.8.2",
"lucide-react": "^0.321.0",
"react": "^18.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ interface ExpandableRowProps {
}

const isSessionExpired = (createTime: number, maxInactiveInterval: number) => {
const currentTime = Date.now()
const expirationTime = createTime + maxInactiveInterval * 1000
return currentTime > expirationTime
const expirationTime = new Date(createTime).getTime() + maxInactiveInterval * 1000
return Date.now() > expirationTime
}

export const ManageSessions: React.FC = () => {
Expand All @@ -51,9 +50,7 @@ export const ManageSessions: React.FC = () => {
async (authKey: string) => {
setLoading(authKey)
try {
await removeSession({
authKey: authKey,
})
await removeSession({ authKey })
await refetch()
} catch (error) {
console.error(error)
Expand Down Expand Up @@ -98,8 +95,6 @@ export const ManageSessions: React.FC = () => {
)
}

console.log(sessionKeys)

return (
<div className="rounded-lg border w-full">
<Table>
Expand Down Expand Up @@ -135,11 +130,7 @@ const ExpandableRow: React.FC<ExpandableRowProps> = ({ session, remove, loading

const handleCopy = (key: string) => {
copyToClipboard(key, (value) => {
if (value) {
setCopiedKeys((prev) => [...prev, key])
} else {
setCopiedKeys((prev) => prev.filter((item) => item !== key))
}
setCopiedKeys((prev) => (value ? [...prev, key] : prev.filter((item) => item !== key)))
})
}

Expand All @@ -163,11 +154,9 @@ const ExpandableRow: React.FC<ExpandableRowProps> = ({ session, remove, loading
</TableCell>
<TableCell className="text-muted-foreground">
{formatTimestamp(session.createTime)}
{/*{session.createTime}*/}
</TableCell>
<TableCell className="text-muted-foreground">
{formatTimestamp(session.lastActiveTime)}
{/*{session.lastActiveTime}*/}
</TableCell>
<TableCell className="text-muted-foreground">{session.maxInactiveInterval}</TableCell>
<TableCell className="text-center">
Expand Down Expand Up @@ -221,3 +210,5 @@ const ExpandableRow: React.FC<ExpandableRowProps> = ({ session, remove, loading
</>
)
}

export default ManageSessions
12 changes: 6 additions & 6 deletions infra/rooch-portal/src/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// SPDX-License-Identifier: Apache-2.0

import { PaymentTypes } from '@/common/interface'
import dayjs from 'dayjs'

export const formatTimestamp = (timestamp: number) => {
console.log('Raw Timestamp:', timestamp)
const formatted = dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')
console.log('Formatted Timestamp:', formatted)
return formatted
export const formatTimestamp = (timestamp: number): string => {
if (timestamp < 1e10) {
timestamp *= 1000
}
const date = new Date(timestamp)
return date.toLocaleString('en-US')
}

export const formatCoin = (balance: number, decimals: number, precision = 2) => {
Expand Down
Loading

0 comments on commit c63a38d

Please sign in to comment.