Skip to content

Commit

Permalink
feat: encapsulate the copyToClipboard function
Browse files Browse the repository at this point in the history
  • Loading branch information
TwilightLogic committed Jun 6, 2024
1 parent f8848a9 commit 6e2454a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,13 @@ import { AlertCircle, Check, ChevronDown, ChevronUp, Copy } from 'lucide-react'
import { formatTimestamp } from '@/utils/format.ts'

import { SessionInfoResult } from '@roochnetwork/rooch-sdk'
import { copyToClipboard } from '@/utils/copyToClipboard.ts'

interface ExpandableRowProps {
session: SessionInfoResult
remove: (authKey: string) => void
}

const copyToClipboard = async (text: string, setCopied: (value: boolean) => void) => {
try {
await navigator.clipboard.writeText(text)
setCopied(true)
console.log('Copied to clipboard:', text)
setTimeout(() => setCopied(false), 2000) // Reset after 2 seconds
} catch (err) {
console.error('Could not copy text:', err)
}
}

export const ManageSessions: React.FC = () => {
const sessionKey = useCurrentSession()
const { mutateAsync: removeSession } = useRemoveSession()
Expand Down
12 changes: 12 additions & 0 deletions infra/rooch-portal/src/utils/copyToClipboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0
export async function copyToClipboard(text: string, setCopied: (value: boolean) => void) {
try {
await navigator.clipboard.writeText(text)
setCopied(true)
console.log('Copied to clipboard', text)
setTimeout(() => setCopied(false), 2000)
} catch (err) {
console.error('Could not copy text', err)
}
}

0 comments on commit 6e2454a

Please sign in to comment.