-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add json schema functionality to migrate contract
- Loading branch information
Showing
44 changed files
with
725 additions
and
343 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,7 @@ | ||
import { chakra, shouldForwardProp } from "@chakra-ui/react"; | ||
import { motion, isValidMotionProp } from "framer-motion"; | ||
|
||
export const MotionBox = chakra(motion.div, { | ||
shouldForwardProp: (prop) => | ||
isValidMotionProp(prop) || shouldForwardProp(prop), | ||
}); |
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
79 changes: 79 additions & 0 deletions
79
src/lib/components/json-schema/common/AttachSchemaCard.tsx
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,79 @@ | ||
import { Button, Flex, IconButton, Text } from "@chakra-ui/react"; | ||
|
||
import { CustomIcon } from "lib/components/icon"; | ||
import { useSchemaStore } from "lib/providers/store"; | ||
import type { CodeSchema } from "lib/stores/schema"; | ||
import type { Option } from "lib/types"; | ||
|
||
import { ViewSchemaButton } from "./ViewSchemaButton"; | ||
|
||
interface AttachSchemaCardProps { | ||
attached: boolean; | ||
codeId: string; | ||
codeHash: string; | ||
schema: Option<CodeSchema>; | ||
openDrawer: () => void; | ||
} | ||
|
||
export const AttachSchemaCard = ({ | ||
attached, | ||
codeId, | ||
codeHash, | ||
schema, | ||
openDrawer, | ||
}: AttachSchemaCardProps) => { | ||
const { deleteSchema } = useSchemaStore(); | ||
|
||
return ( | ||
<Flex | ||
border="1px solid var(--chakra-colors-gray-700)" | ||
bg="gray.800" | ||
justify="space-between" | ||
align="center" | ||
p={4} | ||
w="full" | ||
borderRadius="4px" | ||
> | ||
{!attached ? ( | ||
<> | ||
<Text variant="body2">Attach JSON Schema</Text> | ||
<Button size="sm" variant="outline-primary" onClick={openDrawer}> | ||
Attach | ||
</Button> | ||
</> | ||
) : ( | ||
<> | ||
<Flex align="center" gap={1}> | ||
<CustomIcon | ||
name="check-circle-solid" | ||
color="success.main" | ||
boxSize={6} | ||
/> | ||
<Text variant="body2">JSON Schema attached</Text> | ||
</Flex> | ||
<Flex align="center"> | ||
<ViewSchemaButton codeId={codeId} schema={schema} mr={2} /> | ||
<IconButton | ||
size="sm" | ||
variant="gray" | ||
aria-label="edit_schema" | ||
onClick={openDrawer} | ||
icon={ | ||
<CustomIcon name="edit" color="gray.600" boxSize={4} m={0} /> | ||
} | ||
/> | ||
<IconButton | ||
size="sm" | ||
variant="gray" | ||
aria-label="delete_schema" | ||
onClick={() => deleteSchema(codeHash)} | ||
icon={ | ||
<CustomIcon name="delete" color="gray.600" boxSize={4} m={0} /> | ||
} | ||
/> | ||
</Flex> | ||
</> | ||
)} | ||
</Flex> | ||
); | ||
}; |
66 changes: 66 additions & 0 deletions
66
src/lib/components/json-schema/common/JsonSchemaDrawer.tsx
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,66 @@ | ||
import { | ||
Drawer, | ||
DrawerOverlay, | ||
DrawerContent, | ||
DrawerHeader, | ||
Flex, | ||
Heading, | ||
DrawerCloseButton, | ||
DrawerBody, | ||
Text, | ||
Box, | ||
} from "@chakra-ui/react"; | ||
|
||
import { CustomIcon } from "lib/components/icon"; | ||
|
||
import { UploadTemplate } from "./UploadTemplate"; | ||
|
||
interface JsonSchemaDrawerProps { | ||
codeId: string; | ||
codeHash: string; | ||
isOpen: boolean; | ||
onClose: () => void; | ||
} | ||
|
||
export const JsonSchemaDrawer = ({ | ||
codeId, | ||
codeHash, | ||
isOpen, | ||
onClose, | ||
}: JsonSchemaDrawerProps) => ( | ||
<Drawer isOpen={isOpen} onClose={onClose} placement="bottom"> | ||
<DrawerOverlay /> | ||
<DrawerContent h="80%"> | ||
<DrawerHeader> | ||
<Flex direction="column" gap={2}> | ||
<Flex align="center" gap={3}> | ||
<CustomIcon name="upload" boxSize={5} color="gray.600" /> | ||
<Heading as="h5" variant="h5"> | ||
Attach JSON Schema for code ID “{codeId}” | ||
</Heading> | ||
</Flex> | ||
<Text variant="body3" color="text.dark"> | ||
Your attached JSON schema will be stored locally on your device | ||
</Text> | ||
</Flex> | ||
</DrawerHeader> | ||
<DrawerCloseButton color="gray.600" /> | ||
<DrawerBody overflow="scroll" p={6}> | ||
<Box | ||
p="12px 16px" | ||
borderRadius="8px" | ||
border="1px solid var(--chakra-colors-gray-700)" | ||
bg="gray.800" | ||
mb={6} | ||
> | ||
<Text variant="body2" color="text.dark"> | ||
Please note that the JSON schema you upload on our website will only | ||
be stored locally on your device. For public projects with verified | ||
JSON schemas, they will be visible and accessible to others. | ||
</Text> | ||
</Box> | ||
<UploadTemplate closeDrawer={onClose} codeHash={codeHash} /> | ||
</DrawerBody> | ||
</DrawerContent> | ||
</Drawer> | ||
); |
File renamed without changes.
43 changes: 43 additions & 0 deletions
43
src/lib/components/json-schema/common/ViewSchemaButton.tsx
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,43 @@ | ||
import type { ButtonProps } from "@chakra-ui/react"; | ||
import { Button } from "@chakra-ui/react"; | ||
|
||
import type { CodeSchema } from "lib/stores/schema"; | ||
import type { Option } from "lib/types"; | ||
|
||
interface ViewSchemaButtonProps extends ButtonProps { | ||
codeId: string; | ||
schema: Option<CodeSchema>; | ||
} | ||
|
||
export const ViewSchemaButton = ({ | ||
codeId, | ||
schema, | ||
...buttonProps | ||
}: ViewSchemaButtonProps) => ( | ||
<Button | ||
variant="outline-gray" | ||
size="sm" | ||
onClick={() => { | ||
const jsonString = JSON.stringify(schema, null, 2); | ||
const jsonWindow = window.open(); | ||
if (jsonWindow) { | ||
// Modify styling later | ||
jsonWindow.document.write( | ||
`<html><head><title>JSON Schema | Code ID ${codeId}</title>` | ||
); | ||
|
||
// Add styling | ||
jsonWindow.document.write( | ||
"<style>body { background-color: #f0f0f0; color: #333; }</style>" | ||
); | ||
|
||
jsonWindow.document.write( | ||
`</head><body><pre>${jsonString}</pre></body></html>` | ||
); | ||
} | ||
}} | ||
{...buttonProps} | ||
> | ||
View JSON | ||
</Button> | ||
); |
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 * from "./ViewSchemaButton"; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.