-
Notifications
You must be signed in to change notification settings - Fork 26
feat: add send generic input #438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
163 changes: 163 additions & 0 deletions
163
apps/dave/src/components/transactions/GenericInputForm/AbiFields.tsx
This file contains hidden or 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,163 @@ | ||
| "use client"; | ||
| import { | ||
| Flex, | ||
| Group, | ||
| SegmentedControl, | ||
| Select, | ||
| Text, | ||
| Textarea, | ||
| Tooltip, | ||
| } from "@mantine/core"; | ||
| import type { FC } from "react"; | ||
| import { TbHelp } from "react-icons/tb"; | ||
| import { AbiFunctionName } from "./AbiFunctionName"; | ||
| import { AbiFunctionParams } from "./AbiFunctionParams"; | ||
| import { AbiParameter } from "./AbiParameter"; | ||
| import { useFormContext } from "./context"; | ||
| import type { | ||
| FormAbiMethod, | ||
| FormSpecification, | ||
| SpecificationMode, | ||
| } from "./types"; | ||
| import { resetAbiFunctionParams } from "./utils"; | ||
|
|
||
| export interface AbiFieldsProps { | ||
| specifications: FormSpecification[]; | ||
| } | ||
|
|
||
| export const AbiFields: FC<AbiFieldsProps> = ({ specifications }) => { | ||
| const form = useFormContext(); | ||
| const { abiMethod, specificationMode } = form.getTransformedValues(); | ||
| const specificationOptions = specifications.map((s) => ({ | ||
| value: s.id, | ||
| label: s.name, | ||
| })); | ||
| const hasSpecifications = specifications.length > 0; | ||
|
|
||
| return ( | ||
| <> | ||
| <Select | ||
| label="ABI method" | ||
| description="Select how to attach an ABI" | ||
| data-testid="abi-method-select" | ||
| allowDeselect={false} | ||
| withAsterisk | ||
| data={[ | ||
| { | ||
| value: "existing", | ||
| label: "ABI from an existing JSON_ABI specification", | ||
| disabled: !hasSpecifications, | ||
| }, | ||
| { value: "new", label: "New ABI" }, | ||
| ]} | ||
| {...form.getInputProps("abiMethod")} | ||
| onChange={(nextValue) => { | ||
| form.setFieldValue("abiMethod", nextValue as FormAbiMethod); | ||
| form.setFieldValue("specificationId", ""); | ||
| form.setFieldValue("abiFunctionName", ""); | ||
| form.setFieldValue("humanAbi", ""); | ||
| form.setFieldValue("abiParam", ""); | ||
| form.setFieldValue("savedAbiParam", ""); | ||
| form.setFieldValue("specificationMode", "json_abi"); | ||
| resetAbiFunctionParams(form, []); | ||
| }} | ||
| /> | ||
|
|
||
| {abiMethod === "new" ? ( | ||
| <> | ||
| <SegmentedControl | ||
| aria-label="Specification Mode" | ||
| data={[ | ||
| { | ||
| label: "JSON ABI", | ||
| value: "json_abi", | ||
| }, | ||
| { | ||
| label: "ABI Parameters", | ||
| value: "abi_params", | ||
| }, | ||
| ]} | ||
| {...form.getInputProps("specificationMode")} | ||
| onChange={(nextValue) => { | ||
| form.setFieldValue( | ||
| "specificationMode", | ||
| nextValue as SpecificationMode, | ||
| ); | ||
|
|
||
| form.setFieldValue("specificationId", ""); | ||
| form.setFieldValue("abiFunctionName", ""); | ||
| form.setFieldValue("humanAbi", ""); | ||
| form.setFieldValue("abiParam", ""); | ||
| form.setFieldValue("savedAbiParam", ""); | ||
| resetAbiFunctionParams(form, []); | ||
| }} | ||
| /> | ||
|
|
||
| {specificationMode === "json_abi" ? ( | ||
| <Textarea | ||
| data-testid="json-abi-textarea" | ||
| resize="vertical" | ||
| description="Define signatures in Human readable format" | ||
| placeholder="function balanceOf(address owner) view returns (uint256) event Transfer(address indexed from, address indexed to, uint256 amount)" | ||
| rows={5} | ||
| label={ | ||
| <Group justify="flex-start" gap="3"> | ||
| <Text size="sm">ABI</Text> | ||
| <Tooltip | ||
| multiline | ||
| label="Define the signature without wrapping it on quotes nor adding comma at the end to separate. Just hit enter and keep defining your signatures" | ||
| withArrow | ||
| w="300" | ||
| > | ||
| <Flex direction="column-reverse"> | ||
| <TbHelp /> | ||
| </Flex> | ||
| </Tooltip> | ||
| </Group> | ||
| } | ||
| {...form.getInputProps("humanAbi")} | ||
| onChange={(event) => { | ||
| const nextValue = event.target.value; | ||
| form.setFieldValue("humanAbi", nextValue); | ||
| form.validateField("humanAbi"); | ||
| form.setFieldValue("abiFunctionName", ""); | ||
| }} | ||
| /> | ||
| ) : ( | ||
| <AbiParameter /> | ||
| )} | ||
| </> | ||
| ) : ( | ||
| <Select | ||
| label="Specifications" | ||
| description="Available JSON_ABI specifications" | ||
| placeholder="Select specification" | ||
| data={specificationOptions} | ||
| allowDeselect={false} | ||
| withAsterisk | ||
| {...form.getInputProps("specificationId")} | ||
| onChange={(nextValue) => { | ||
| form.setFieldValue( | ||
| "specificationId", | ||
| nextValue as string, | ||
| ); | ||
| form.setFieldValue("abiFunctionName", ""); | ||
| resetAbiFunctionParams(form, []); | ||
| }} | ||
| /> | ||
| )} | ||
|
|
||
| <AbiFunctionName /> | ||
| <AbiFunctionParams /> | ||
|
|
||
| <Textarea | ||
| label="Hex value" | ||
| description="Encoded hex value for the application" | ||
| readOnly | ||
| value={ | ||
| form.isValid() ? form.getInputProps("rawInput").value : "0x" | ||
| } | ||
| /> | ||
| </> | ||
| ); | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.