This repository was archived by the owner on May 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashDemo.tsx
More file actions
70 lines (60 loc) · 1.77 KB
/
HashDemo.tsx
File metadata and controls
70 lines (60 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import type { FC } from 'react'
import styled from 'styled-components'
import { Toast } from '@bootnodedev/db-ui-toolkit'
import { toast } from 'react-hot-toast'
import type { Address, Chain } from 'viem'
import Hash from '@/src/components/sharedComponents/Hash'
import { getExplorerLink } from '@/src/utils/getExplorerLink'
const Wrapper = styled(Hash)`
[data-theme='light'] & {
--theme-hash-background-color: #fff;
--theme-hash-border-color: #c5c2cb;
--theme-hash-color: #2e3048;
}
[data-theme='dark'] & {
--theme-hash-background-color: #2e3047;
--theme-hash-border-color: #5f6178;
--theme-hash-color: #fff;
}
background-color: var(--theme-hash-background-color);
border-radius: var(--base-border-radius);
border: 1px solid var(--theme-hash-border-color);
color: var(--theme-hash-color);
cursor: default;
font-size: 1.6rem;
height: 34px;
min-width: 0;
padding: 0 calc(var(--base-common-padding) * 2);
`
interface Props {
chain: Chain
hash: Address | undefined
truncatedHashLength?: number | 'disabled'
}
/**
* Hash component demo.
*
* Some styles were added. Also we show a toast when the copy button is clicked
* to let the user know that something has happened.
*/
const HashDemo: FC<Props> = ({ chain, hash, ...restProps }) => {
const onCopy = (message: string) => {
const timeDelay = 2500
navigator.clipboard.writeText(message)
toast.custom(<Toast>Copied to the clipboard!</Toast>, {
duration: timeDelay,
position: 'top-center',
id: 'copy-to-clipboard',
})
}
return hash ? (
<Wrapper
explorerURL={getExplorerLink({ chain, hashOrAddress: hash })}
hash={hash}
onCopy={() => onCopy(hash)}
showCopyButton
{...restProps}
/>
) : null
}
export default HashDemo