-
Notifications
You must be signed in to change notification settings - Fork 9
feat(dashboard): import a proposal from JSON when creating one #2102
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
Open
brunod-e
wants to merge
42
commits into
dev
Choose a base branch
from
feat/import-proposal-json
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
7236413
feat(dashboard): import a proposal from JSON when creating one
brunod-e c8f5cb0
refactor(dashboard): slim down the Import JSON modal
brunod-e b0de3eb
fix(dashboard): validate imported calldata before accepting the action
brunod-e cb77457
fix(dashboard): validate ABI-backed custom actions before import
brunod-e fd7f6fd
fix(dashboard): settle imported values that only fail at publish
brunod-e 8e47afa
fix(dashboard): close four more paths where a paste fails after import
brunod-e fd943a7
fix(dashboard): carry the arg checks into composite values
brunod-e e30c9e9
fix(dashboard): reject amounts and abi types a paste can't carry
brunod-e 75ebadc
fix(dashboard): void a pending decimals read when the paste is edited
brunod-e 77d5930
fix(dashboard): require every imported figure to be quoted
brunod-e 31d14a8
feat(dashboard): accept a .json file in the import modal
brunod-e 86cf7b7
test(dashboard): collapse the import test boilerplate
brunod-e a883958
fix(dashboard): stop the import from storing what the editor can't hold
brunod-e 2886163
fix(dashboard): refuse a bare function name several overloads share
brunod-e 7ae1865
docs(changeset): trim the import entry to one line
brunod-e fcfceb3
fix(dashboard): stop accepting an ETH value the form can't show
brunod-e eccc01f
fix(dashboard): refuse a read-only function on import
brunod-e c6024de
fix(dashboard): reject a tuple filled past its declared fields
brunod-e a2b8c38
fix(dashboard): report a rejected upload beside the file button
brunod-e f9de508
fix(dashboard): trim scalar args, string excepted
brunod-e c6162dd
refactor(dashboard): one conversion from stored args to calldata
brunod-e 86aeddd
refactor(dashboard): validate an action once, in the form that holds it
brunod-e cbb9716
fix(dashboard): close the three findings left open
brunod-e 35707fd
feat(dashboard): rework the JSON proposal import per design review
brunod-e 318e06c
fix(dashboard): refuse a custom action that mixes calldata with an AB…
brunod-e ef23bc4
fix(dashboard): fail closed when encoding a malformed composite arg
brunod-e 1cf17b1
refactor(dashboard): reach create-proposal through its public entry p…
brunod-e 929d8a0
fix(dashboard): agree on the import key whatever case the slug arrive…
brunod-e 54b385b
fix(dashboard): keep the pasted proposal when the import handoff refu…
brunod-e f681113
fix(dashboard): refuse a composite arg leaf the ABI parameter cannot …
brunod-e 0540720
fix(dashboard): check an action with the converter that will encode it
brunod-e 8535f72
fix(dashboard): refuse a tuple arg that is short of its components
brunod-e 5f94add
refactor(dashboard): cut the import utils down to what the task needs
brunod-e 6e97745
fix(dashboard): refuse an arg count the ABI function doesn't take
brunod-e 8b7e4d2
docs(dashboard): name the converter that actually degrades a bad leaf
brunod-e b266d1f
fix(dashboard): clear a cancelled import from the handoff stash
brunod-e 96aecf5
fix(dashboard): carry the import handoff across browsing contexts
brunod-e a91ec72
Merge remote-tracking branch 'origin/dev' into feat/import-proposal-json
brunod-e 21ceb96
style(dashboard): bring comments and one helper in line with the hous…
brunod-e 9008276
refactor(dashboard): one validator for a proposal action, not three
brunod-e e853c5d
chore(dashboard): lock abitype and jsonc-parser
brunod-e 906fc44
docs(dashboard): cut the commentary down to the traps
brunod-e 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| "@anticapture/dashboard": minor | ||
| --- | ||
|
|
||
| Add an Import JSON button to the create proposal form. It opens a modal (drawer | ||
| on mobile) with a textarea for pasting a proposal document plus a description of | ||
| the expected format, and fills the title, discussion URL, description, and | ||
| actions from what the document provides. |
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
142 changes: 142 additions & 0 deletions
142
apps/dashboard/features/create-proposal/components/modals/ImportJsonModal.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,142 @@ | ||
| "use client"; | ||
|
|
||
| import { useEffect, useState } from "react"; | ||
|
|
||
| import { FormLabel } from "@/shared/components/design-system/form/fields/form-label/FormLabel"; | ||
| import { Textarea } from "@/shared/components/design-system/form/fields/textarea/Textarea"; | ||
| import { Modal } from "@/shared/components/design-system/modal/Modal"; | ||
| import { PROPOSAL_JSON_PLACEHOLDER } from "@/features/create-proposal/constants"; | ||
| import { | ||
| parseProposalJson, | ||
| type ParsedProposalJson, | ||
| } from "@/features/create-proposal/utils/parseProposalJson"; | ||
|
|
||
| interface ImportJsonModalProps { | ||
| open: boolean; | ||
| onOpenChange: (open: boolean) => void; | ||
| onImport: (values: ParsedProposalJson) => void; | ||
| } | ||
|
|
||
| const Code = ({ children }: { children: React.ReactNode }) => ( | ||
| <code className="text-primary font-mono">{children}</code> | ||
| ); | ||
|
|
||
| // Keep the prose short: a line break right after a <code> swallows the space | ||
| // that follows it, so each entry has to fit on one line. | ||
| const Field = ({ | ||
| name, | ||
| children, | ||
| }: { | ||
| name: string; | ||
| children: React.ReactNode; | ||
| }) => ( | ||
| <li> | ||
| <Code>{name}</Code> {children} | ||
| </li> | ||
| ); | ||
|
|
||
| export const ImportJsonModal = ({ | ||
| open, | ||
| onOpenChange, | ||
| onImport, | ||
| }: ImportJsonModalProps) => { | ||
| const [text, setText] = useState(""); | ||
| const [error, setError] = useState<string | null>(null); | ||
|
|
||
| // Start from a clean sheet on every open: a previous failed paste hanging | ||
| // around next to a stale error reads as if the import already ran. | ||
| useEffect(() => { | ||
| if (!open) return; | ||
| setText(""); | ||
| setError(null); | ||
| }, [open]); | ||
|
|
||
| const close = () => { | ||
| setText(""); | ||
| setError(null); | ||
| onOpenChange(false); | ||
| }; | ||
|
|
||
| const handleConfirm = () => { | ||
| const result = parseProposalJson(text); | ||
| if (!result.ok) { | ||
| setError(result.error); | ||
| return; | ||
| } | ||
| onImport(result.value); | ||
| close(); | ||
| }; | ||
|
|
||
| return ( | ||
| <Modal | ||
| open={open} | ||
| onOpenChange={(o) => { | ||
| if (!o) { | ||
| setText(""); | ||
| setError(null); | ||
| } | ||
| onOpenChange(o); | ||
| }} | ||
| title="Import JSON" | ||
| description="Paste a proposal document to fill the form fields." | ||
| cancelLabel="Cancel" | ||
| confirmLabel="Apply" | ||
| onCancel={close} | ||
| onConfirm={handleConfirm} | ||
| isConfirmDisabled={text.trim().length === 0} | ||
| > | ||
| <div className="flex flex-col gap-4"> | ||
| <div className="flex flex-col gap-1.5"> | ||
| <FormLabel isRequired>Proposal JSON</FormLabel> | ||
| <Textarea | ||
| value={text} | ||
| onChange={(e) => { | ||
| setText(e.target.value); | ||
| setError(null); | ||
| }} | ||
|
brunod-e marked this conversation as resolved.
Outdated
|
||
| placeholder={PROPOSAL_JSON_PLACEHOLDER} | ||
| // Capped so a long paste (or a drag on the native resize grip) | ||
| // can't push the footer off screen. | ||
| className="max-h-64 min-h-44 resize-y overflow-y-auto font-mono text-xs" | ||
| error={Boolean(error)} | ||
| spellCheck={false} | ||
| aria-label="Proposal JSON" | ||
| /> | ||
| {error ? ( | ||
| <span className="text-error text-xs">{error}</span> | ||
| ) : ( | ||
| <span className="text-secondary text-xs"> | ||
| Every field is optional, and only the ones present are replaced. | ||
| Recipients take an address or ENS, and amounts are human-readable | ||
| rather than wei. | ||
| </span> | ||
| )} | ||
| </div> | ||
|
|
||
| <ul className="text-secondary flex flex-col gap-1 text-xs"> | ||
| <Field name="title">the proposal title.</Field> | ||
| <Field name="discussionUrl"> | ||
| an http(s) link to the forum thread. | ||
| </Field> | ||
| <Field name="body">the description, in markdown.</Field> | ||
| <Field name="actions"> | ||
| one entry per action, keyed by <Code>type</Code>: | ||
| <ul className="mt-1 flex flex-col gap-1 pl-4"> | ||
| <Field name="eth-transfer"> | ||
| <Code>recipient</Code> and <Code>amount</Code> in ETH. | ||
| </Field> | ||
| <Field name="erc20-transfer"> | ||
| also <Code>tokenAddress</Code> and <Code>decimals</Code>. | ||
| </Field> | ||
| <Field name="custom"> | ||
| <Code>contractAddress</Code>, then either{" "} | ||
| <Code>functionName</Code> with <Code>abi</Code> and{" "} | ||
| <Code>args</Code>, or raw <Code>calldata</Code>. | ||
| </Field> | ||
| </ul> | ||
| </Field> | ||
| </ul> | ||
| </div> | ||
| </Modal> | ||
| ); | ||
| }; | ||
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
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.