-
Notifications
You must be signed in to change notification settings - Fork 14
/
ExportNostrKeysModal.tsx
118 lines (108 loc) · 3.41 KB
/
ExportNostrKeysModal.tsx
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import {
Button,
Checkbox,
HStack,
useDisclosure,
VStack,
} from '@chakra-ui/react'
import { PDFDownloadLink } from '@react-pdf/renderer'
import { ChangeEvent, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { BiErrorCircle } from 'react-icons/bi'
import { Modal } from '../../../components/layouts'
import { Body2, Caption } from '../../../components/typography'
import { ProjectFragment, useProjectNostrKeysQuery } from '../../../types'
import { useCustomTheme } from '../../../utils'
import { ExportNostrKeysPDF } from '../components'
interface ExportNostrKeysModalProps {
projectId: ProjectFragment['id']
projectTitle: ProjectFragment['title']
}
export const ExportNostrKeysModal = ({
projectId,
projectTitle,
}: ExportNostrKeysModalProps) => {
const { t } = useTranslation()
const { isOpen, onClose, onOpen } = useDisclosure()
const { colors } = useCustomTheme()
const { loading, data } = useProjectNostrKeysQuery({
variables: { where: { id: projectId } },
skip: !projectId || !isOpen,
})
const projectNostrKeys = data?.projectGet?.keys.nostrKeys
const [isChecked, setIsChecked] = useState(false)
const handleCheckBox = (event: ChangeEvent<HTMLInputElement>) => {
setIsChecked(event.target.checked)
}
return (
<>
<Button width="full" variant="secondary" onClick={onOpen}>
{' '}
{t('Export Private key (nsec)')}
</Button>
<Modal
size="sm"
title={t('Export Private Key (nsec)')}
isOpen={isOpen}
onClose={onClose}
>
<VStack spacing="20px">
<Body2 semiBold color="neutral.600">
{t('Are you sure you want to export your private keys?')}
</Body2>
<HStack
padding="6px 12px"
backgroundColor="rgba(223, 54, 52, 0.10)"
borderRadius="8px"
>
<BiErrorCircle color={colors.secondary.red} fontSize="30px" />
<Caption color="secondary.red" xBold>
{t(
'Warning: your project risks being compromised if you leak your private key.',
)}
</Caption>
</HStack>
<Checkbox
colorScheme="teal"
isChecked={isChecked}
onChange={handleCheckBox}
>
{t('I understand the risks of exporting my private key')}
</Checkbox>
{isChecked && !loading ? (
<PDFDownloadLink
document={
<ExportNostrKeysPDF
projectTitle={projectTitle}
publicKey={projectNostrKeys?.publicKey.npub || ''}
privateKey={projectNostrKeys?.privateKey?.nsec || ''}
/>
}
style={{
padding: '6px',
backgroundColor: colors.primary[400],
width: '100%',
borderRadius: '8px',
display: 'flex',
justifyContent: 'center',
color: 'black',
}}
onClick={onClose}
>
{t('Export Private key (nsec)')}
</PDFDownloadLink>
) : (
<Button
width="full"
variant="secondary"
isLoading={loading}
isDisabled
>
{t('Export Private key (nsec)')}
</Button>
)}
</VStack>
</Modal>
</>
)
}