forked from fedimint/fedimint-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backup file after dkg (fedimint#587)
* feat: trim whitespace in verification codes * feat: trim leading/trailing whitespace in verification codes * feat: trim leading/trailing whitespace in verification codes/rebase * feat: update backup modal * feat: improve backup modal UI and download flow * fix: use correct setup action type in modal close * fix: update hook usrTrimmedInput * Update apps/router/src/hooks/custom/useTrimmedInput.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * feat: enhance BackupModal functionality * refactor: remove redundant BackupModal from FederationSetup * feat: update downloaded translations for multiple languages * refactor: move @chakra-ui/icons to apps/router/package.json * chore: revert registry change to yarn.lock --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Alex Lewin <[email protected]>
- Loading branch information
1 parent
6e3c4c1
commit b3e188a
Showing
18 changed files
with
214 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import React, { useState, useEffect, useCallback } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { | ||
Modal, | ||
ModalOverlay, | ||
ModalContent, | ||
ModalHeader, | ||
ModalBody, | ||
Button, | ||
Flex, | ||
Alert, | ||
AlertIcon, | ||
AlertTitle, | ||
Text, | ||
} from '@chakra-ui/react'; | ||
import { useGuardianAdminApi, useGuardianDispatch } from '../../hooks'; | ||
import { hexToBlob } from '../utils/api'; | ||
import { GUARDIAN_APP_ACTION_TYPE, GuardianStatus } from '../../types/guardian'; | ||
|
||
interface BackupModalProps { | ||
isOpen: boolean; | ||
onClose: () => void; | ||
} | ||
|
||
export const BackupModal: React.FC<BackupModalProps> = ({ | ||
isOpen, | ||
onClose, | ||
}) => { | ||
const { t } = useTranslation(); | ||
const [hasDownloaded, setHasDownloaded] = useState(false); | ||
const [isDownloading, setIsDownloading] = useState(false); | ||
const [downloadError, setDownloadError] = useState<string | null>(null); | ||
const api = useGuardianAdminApi(); | ||
const dispatch = useGuardianDispatch(); | ||
|
||
useEffect(() => { | ||
if (isOpen) { | ||
setHasDownloaded(false); | ||
setDownloadError(null); | ||
} | ||
}, [isOpen]); | ||
|
||
const handleDownload = useCallback(async () => { | ||
setIsDownloading(true); | ||
setDownloadError(null); | ||
|
||
try { | ||
const response = await api.downloadGuardianBackup(); | ||
const blob = hexToBlob(response.tar_archive_bytes, 'application/x-tar'); | ||
const url = window.URL.createObjectURL(blob); | ||
const link = document.createElement('a'); | ||
link.href = url; | ||
link.download = 'guardianBackup.tar'; | ||
link.click(); | ||
|
||
setTimeout(() => URL.revokeObjectURL(url), 100); | ||
setHasDownloaded(true); | ||
} catch (error) { | ||
console.error('Error in handleDownload:', error); | ||
setDownloadError( | ||
t('federation-dashboard.danger-zone.backup.error-download') | ||
); | ||
} finally { | ||
setIsDownloading(false); | ||
} | ||
}, [api, t]); | ||
|
||
const handleContinue = useCallback(() => { | ||
if (hasDownloaded) { | ||
dispatch({ | ||
type: GUARDIAN_APP_ACTION_TYPE.SET_STATUS, | ||
payload: GuardianStatus.Admin, | ||
}); | ||
onClose(); | ||
} | ||
}, [dispatch, hasDownloaded, onClose]); | ||
|
||
return ( | ||
<Modal | ||
isOpen={isOpen} | ||
onClose={onClose} | ||
closeOnOverlayClick={false} | ||
isCentered | ||
> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalHeader alignSelf='center'> | ||
{t('federation-dashboard.danger-zone.backup.title')} | ||
</ModalHeader> | ||
<ModalBody pb={6}> | ||
<Flex direction='column' gap={4}> | ||
<Alert status='warning'> | ||
<AlertIcon /> | ||
<AlertTitle> | ||
{t('federation-dashboard.danger-zone.backup.warning-title')} | ||
</AlertTitle> | ||
</Alert> | ||
<Text mb={4}> | ||
{t('federation-dashboard.danger-zone.backup.warning-text')} | ||
</Text> | ||
{downloadError && ( | ||
<Alert status='error'> | ||
<AlertIcon /> | ||
<AlertTitle>{downloadError}</AlertTitle> | ||
</Alert> | ||
)} | ||
<Flex justifyContent='center' gap={4} direction={['column', 'row']}> | ||
<Button | ||
variant='ghost' | ||
size={['sm', 'md']} | ||
onClick={handleDownload} | ||
isDisabled={hasDownloaded || isDownloading} | ||
isLoading={isDownloading} | ||
bg='red.500' | ||
color='white' | ||
_hover={{ bg: 'red.600' }} | ||
_active={{ bg: 'red.700' }} | ||
> | ||
{hasDownloaded | ||
? t('federation-dashboard.danger-zone.backup.downloaded') + | ||
' ✓' | ||
: t( | ||
'federation-dashboard.danger-zone.acknowledge-and-download' | ||
)} | ||
</Button> | ||
<Button | ||
colorScheme='blue' | ||
size={['sm', 'md']} | ||
onClick={handleContinue} | ||
isDisabled={!hasDownloaded} | ||
> | ||
{t('common.close')} | ||
</Button> | ||
</Flex> | ||
</Flex> | ||
</ModalBody> | ||
</ModalContent> | ||
</Modal> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1296,6 +1296,11 @@ | |
dependencies: | ||
"@chakra-ui/shared-utils" "2.0.5" | ||
|
||
"@chakra-ui/icons@^2.2.4": | ||
version "2.2.4" | ||
resolved "https://registry.yarnpkg.com/@chakra-ui/icons/-/icons-2.2.4.tgz#fc3f59a7e377d6e4efdbe8ee0a3aec7f29a4ab32" | ||
integrity sha512-l5QdBgwrAg3Sc2BRqtNkJpfuLw/pWRDwwT58J6c4PqQT6wzXxyNa8Q0PForu1ltB5qEiFb1kxr/F/HO1EwNa6g== | ||
|
||
"@chakra-ui/[email protected]": | ||
version "2.0.16" | ||
resolved "https://registry.yarnpkg.com/@chakra-ui/image/-/image-2.0.16.tgz#0e3a48c3caa6dc1d340502ea96766d9ef31e27e8" | ||
|