-
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.
- Loading branch information
Showing
37 changed files
with
922 additions
and
717 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import type { AxiosError } from "axios"; | ||
import { useState } from "react"; | ||
|
||
import { useEndpoint } from "lib/hooks"; | ||
import { queryData } from "lib/services/contract"; | ||
import type { ContractAddr, RpcQueryError } from "lib/types"; | ||
|
||
interface UseQueryCmdsProps { | ||
contractAddress: ContractAddr; | ||
} | ||
export const useQueryCmds = ({ contractAddress }: UseQueryCmdsProps) => { | ||
const [queryCmds, setQueryCmds] = useState<[string, string][]>([]); | ||
const endpoint = useEndpoint(); | ||
|
||
const { isFetching } = useQuery( | ||
["query", "cmds", endpoint, contractAddress, '{"": {}}'], | ||
async () => | ||
queryData(endpoint, contractAddress as ContractAddr, '{"": {}}'), | ||
{ | ||
enabled: !!contractAddress, | ||
retry: false, | ||
cacheTime: 0, | ||
refetchOnWindowFocus: false, | ||
onError: (e: AxiosError<RpcQueryError>) => { | ||
const cmds: string[] = []; | ||
Array.from(e.response?.data.message?.matchAll(/`(.*?)`/g) || []) | ||
.slice(1) | ||
.forEach((match) => cmds.push(match[1])); | ||
setQueryCmds(cmds.map((cmd) => [cmd, `{"${cmd}": {}}`])); | ||
}, | ||
} | ||
); | ||
return { isFetching, queryCmds }; | ||
}; |
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,3 +1,4 @@ | ||
export * from "./hooks"; | ||
export * from "./tx"; | ||
export * from "./contexts"; | ||
export * from "./queries"; |
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { VStack } from "@chakra-ui/react"; | ||
import type { Control, FieldErrorsImpl, FieldPath } from "react-hook-form"; | ||
|
||
import { | ||
ControllerInput, | ||
ListSelection, | ||
TagSelection, | ||
ControllerTextarea, | ||
} from "lib/components/forms"; | ||
import { | ||
getMaxContractDescriptionLengthError, | ||
getMaxContractNameLengthError, | ||
MAX_CONTRACT_DESCRIPTION_LENGTH, | ||
MAX_CONTRACT_NAME_LENGTH, | ||
} from "lib/data"; | ||
import type { Option } from "lib/types"; | ||
|
||
export interface OffchainDetail { | ||
name: string; | ||
description: string; | ||
tags: string[]; | ||
lists: Option[]; | ||
} | ||
|
||
interface OffChainFormProps<T extends OffchainDetail> { | ||
// TODO: find a way to remove nameField and descriptionField | ||
nameField: FieldPath<T>; | ||
descriptionField: FieldPath<T>; | ||
state: OffchainDetail; | ||
control: Control<T>; | ||
setTagsValue: (options: string[]) => void; | ||
setContractListsValue: (options: Option[]) => void; | ||
errors: Partial<FieldErrorsImpl<T>>; | ||
labelBgColor?: string; | ||
} | ||
|
||
export const OffChainForm = <T extends OffchainDetail>({ | ||
nameField, | ||
descriptionField, | ||
state, | ||
control, | ||
setTagsValue, | ||
setContractListsValue, | ||
errors, | ||
labelBgColor = "background.main", | ||
}: OffChainFormProps<T>) => { | ||
return ( | ||
<VStack gap="16px" w="full"> | ||
<ControllerInput | ||
name={nameField} | ||
control={control} | ||
label="Name" | ||
helperText="Set name for your contract" | ||
variant="floating" | ||
rules={{ | ||
maxLength: MAX_CONTRACT_NAME_LENGTH, | ||
}} | ||
error={errors.name && getMaxContractNameLengthError(state.name.length)} | ||
labelBgColor={labelBgColor} | ||
/> | ||
<ControllerTextarea | ||
name={descriptionField} | ||
control={control} | ||
label="Description" | ||
helperText="Help understanding what this contract do and how it works" | ||
variant="floating" | ||
rules={{ | ||
maxLength: MAX_CONTRACT_DESCRIPTION_LENGTH, | ||
}} | ||
error={ | ||
errors.description && | ||
getMaxContractDescriptionLengthError(state.description.length) | ||
} | ||
labelBgColor={labelBgColor} | ||
/> | ||
<TagSelection | ||
result={state.tags} | ||
placeholder="Tags" | ||
helperText="Add tag to organize and manage your contracts" | ||
setResult={setTagsValue} | ||
labelBgColor={labelBgColor} | ||
/> | ||
<ListSelection | ||
result={state.lists} | ||
placeholder="Add to contract lists" | ||
helperText="Grouping your contracts by adding to your existing list or create | ||
a new list" | ||
setResult={setContractListsValue} | ||
labelBgColor={labelBgColor} | ||
/> | ||
</VStack> | ||
); | ||
}; |
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
Oops, something went wrong.