-
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.
* refactor: remove temp directory use and use a random hash * refactor: revert directory naming to the merkle root, it just makes sense * feat: implement merkle proof generation * fix: merkle tree algorithm to correctly create trees when odd leafs are found * feat: add page to list files and fetch files and generate the proof for each file
- Loading branch information
1 parent
b68ec35
commit 0946c33
Showing
46 changed files
with
824 additions
and
312 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
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
// types | ||
import type { IUploadResponse } from '@app/types'; | ||
|
||
interface IProps { | ||
merkleTreeRootHash: string | null; | ||
onClose: () => void; | ||
uploadResponse: IUploadResponse | null; | ||
} | ||
|
||
export default IProps; |
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,3 @@ | ||
export const FILES_PATH: string = 'files'; | ||
export const UPLOAD_PATH: string = 'upload'; | ||
export const VERSIONS_PATH: string = 'versions'; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const FILES_ROUTE: string = '/files'; | ||
export const INDEX_ROUTE: string = '/'; | ||
export const UPLOAD_ROUTE: string = '/upload'; | ||
export const VERIFY_ROUTE: string = '/verify'; |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './Dimensions'; | ||
export * from './Links'; | ||
export * from './Paths'; | ||
export * from './Routes'; | ||
export * from './Styles'; |
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,6 @@ | ||
enum LeafPositionEnum { | ||
Left = 0, | ||
Right = 1, | ||
} | ||
|
||
export default LeafPositionEnum; |
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 @@ | ||
export { default as LeafPositionEnum } from './LeafPositionEnum'; |
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,179 @@ | ||
'use client'; | ||
import { | ||
Accordion, | ||
AccordionButton, | ||
AccordionIcon, | ||
AccordionItem, | ||
AccordionPanel, | ||
Code, | ||
Heading, | ||
HStack, | ||
IconButton, | ||
Skeleton, | ||
Spacer, | ||
Stack, | ||
Text, | ||
Tooltip, | ||
VStack, | ||
} from '@chakra-ui/react'; | ||
import { NextPage } from 'next'; | ||
import React from 'react'; | ||
import { IoDownloadOutline } from 'react-icons/io5'; | ||
|
||
// components | ||
import CopyIconButton from '@app/components/CopyIconButton'; | ||
|
||
// constants | ||
import { DEFAULT_GAP } from '@app/constants'; | ||
|
||
// hooks | ||
import useButtonHoverBackgroundColor from '@app/hooks/useButtonHoverBackgroundColor'; | ||
import useDefaultTextColor from '@app/hooks/useDefaultTextColor'; | ||
import useFiles from '@app/hooks/useFiles'; | ||
import useSubTextColor from '@app/hooks/useSubTextColor'; | ||
|
||
// types | ||
import type { IFileResponse } from '@app/types'; | ||
|
||
// utils | ||
import downloadJSONFile from '@app/utils/downloadJSONFile'; | ||
|
||
const FilesPage: NextPage = () => { | ||
// hooks | ||
const buttonHoverBackgroundColor: string = useButtonHoverBackgroundColor(); | ||
const defaultTextColor: string = useDefaultTextColor(); | ||
const subTextColor: string = useSubTextColor(); | ||
const { files, loading } = useFiles(); | ||
// handlers | ||
const handleDownloadProofClick = (file: IFileResponse) => () => | ||
downloadJSONFile(file.hash, file.proof); | ||
// renders | ||
const renderContent = () => { | ||
let fileKeys: string[]; | ||
|
||
if (loading) { | ||
return Array.from({ length: 3 }, (_, index) => ( | ||
<Skeleton h="20px" key={`files-page-skeleton-item-${index}`} w="full" /> | ||
)); | ||
} | ||
|
||
if (files) { | ||
fileKeys = Object.keys(files); | ||
|
||
if (fileKeys.length > 0) { | ||
return ( | ||
<Accordion allowMultiple={true} allowToggle={true} w="full"> | ||
{fileKeys.map((key, fileKeyIndex) => ( | ||
<AccordionItem key={`files-page-${key}-${fileKeyIndex}`}> | ||
{/*accordian button*/} | ||
<AccordionButton p={DEFAULT_GAP / 2}> | ||
<Code | ||
color={defaultTextColor} | ||
fontSize="md" | ||
maxW={650} | ||
noOfLines={1} | ||
textAlign="left" | ||
> | ||
{key} | ||
</Code> | ||
|
||
<Spacer /> | ||
|
||
<AccordionIcon /> | ||
</AccordionButton> | ||
|
||
{/*list of files*/} | ||
<AccordionPanel p={0}> | ||
{files[key].map((file, index) => ( | ||
<HStack | ||
alignItems="center" | ||
justifyContent="space-between" | ||
key={`files-page-${key}-item-${index}`} | ||
p={DEFAULT_GAP / 2} | ||
spacing={DEFAULT_GAP / 3} | ||
w="full" | ||
> | ||
{/*name*/} | ||
<Text | ||
color={subTextColor} | ||
fontSize="sm" | ||
maxW={500} | ||
noOfLines={1} | ||
textAlign="left" | ||
> | ||
{file.name} | ||
</Text> | ||
|
||
<Spacer /> | ||
|
||
{/*copy hash button*/} | ||
<CopyIconButton | ||
ariaLabel={`Copy Hash`} | ||
size="md" | ||
value={file.hash} | ||
/> | ||
|
||
{/*download proof button*/} | ||
<Tooltip label={`Download Proof`}> | ||
<IconButton | ||
_hover={{ bg: buttonHoverBackgroundColor }} | ||
aria-label="Download file proof" | ||
color={defaultTextColor} | ||
icon={<IoDownloadOutline />} | ||
onClick={handleDownloadProofClick(file)} | ||
size="md" | ||
variant="ghost" | ||
/> | ||
</Tooltip> | ||
</HStack> | ||
))} | ||
</AccordionPanel> | ||
</AccordionItem> | ||
))} | ||
</Accordion> | ||
); | ||
} | ||
} | ||
|
||
// when there are no files returned | ||
return ( | ||
<Stack alignItems="center" flexGrow={1} justify="center" w="full"> | ||
<Text color={defaultTextColor} textAlign="center"> | ||
{`No files found!`} | ||
</Text> | ||
</Stack> | ||
); | ||
}; | ||
|
||
return ( | ||
<VStack | ||
alignItems="center" | ||
justifyContent="flex-start" | ||
flexGrow={1} | ||
spacing={DEFAULT_GAP} | ||
w="full" | ||
> | ||
{/*heading*/} | ||
<Heading color={defaultTextColor} size="lg" textAlign="center" w="full"> | ||
{`Files`} | ||
</Heading> | ||
|
||
{/*description*/} | ||
<Text color={defaultTextColor} size="md" textAlign="center" w="full"> | ||
{`Below is a list of files, grouped by their merkle tree roots. You can download a file's proof and use the root you received to verify the file's integrity.`} | ||
</Text> | ||
|
||
<VStack | ||
alignItems="center" | ||
flexGrow={1} | ||
justify="flex-start" | ||
spacing={DEFAULT_GAP - 2} | ||
w="full" | ||
> | ||
{renderContent()} | ||
</VStack> | ||
</VStack> | ||
); | ||
}; | ||
|
||
export default FilesPage; |
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,2 @@ | ||
export { default } from './useFiles'; | ||
export * from './types'; |
Oops, something went wrong.