-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove Proposal context for explicit prop passing.
* Fix some typing issues
- Loading branch information
Showing
6 changed files
with
92 additions
and
82 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,19 +1,30 @@ | ||
import { useCallback, useContext } from "react"; | ||
import { useCallback } from "react"; | ||
import { Proposal } from "../schemas/proposal"; | ||
import { ProposalContext } from "../app/NewSafeProposal"; | ||
import { useRedirectToProposalWithNewParams } from "./useSetParamsFromQuery"; | ||
|
||
export const useUpdateProposalViaQuery = () => { | ||
export type UpdateProposal = { | ||
addAction: (newAction: NonNullable<Proposal["actions"]>[0]) => void; | ||
replace: (proposal: Proposal) => void; | ||
}; | ||
export const useUpdateProposal = ({ | ||
proposal, | ||
}: { | ||
proposal: Proposal | undefined; | ||
}): UpdateProposal => { | ||
const setParams = useRedirectToProposalWithNewParams(); | ||
const proposal = useContext(ProposalContext); | ||
|
||
return useCallback( | ||
const addAction = useCallback( | ||
(newAction: NonNullable<Proposal["actions"]>[0]) => { | ||
setParams({ | ||
actions: [...(proposal?.actions || []), newAction], | ||
nonce: proposal?.nonce, | ||
}); | ||
}, | ||
[proposal, setParams], | ||
[proposal, setParams] | ||
); | ||
|
||
return { | ||
addAction, | ||
replace: setParams, | ||
}; | ||
}; |