Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fixed bug that when editing and then saving a transaction, resulting url was incorrect #20

Merged
merged 1 commit into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/app/NewSafeProposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
Proposal,
proposalSchema,
} from "../schemas/proposal";
import { useSetParamsFromQuery } from "../hooks/useSetParamsFromQuery";
import { useRedirectToProposalWithNewParams } from "../hooks/useSetParamsFromQuery";
import { useLoadProposalFromQuery } from "../hooks/useLoadProposalFromQuery";
import {
transformValuesFromWei,
Expand Down Expand Up @@ -329,23 +329,20 @@ const ViewProposal = ({

const EditProposal = ({
proposal,
setProposal: setProposal,
setIsEditing,
}: {
proposal: Proposal | undefined;
setProposal: (result: Proposal) => void;
setIsEditing: (editing: boolean) => void;
}) => {
const setProposalParams = useSetParamsFromQuery();
const redirectToEditedProposal = useRedirectToProposalWithNewParams();
const onSubmit = useCallback(
(result: Proposal) => {
setProposal(transformValuesToWei(result));
const proposal = transformValuesToWei(result);
if (proposal) {
setProposalParams(proposal);
redirectToEditedProposal(proposal);
}
setIsEditing(false);
},
[proposal, setIsEditing, setProposal, setProposalParams],
[redirectToEditedProposal]
);

const defaultActions = proposal || DEFAULT_PROPOSAL;
Expand Down
12 changes: 9 additions & 3 deletions src/hooks/useLoadProposalFromQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ import { useEffect, useState } from "react";
import { useSearchParams } from "react-router-dom";
import { Proposal } from "../schemas/proposal";

export const queryKeys = {
targets: "targets",
calldatas: "calldatas",
values: "values"
};

export const useLoadProposalFromQuery = () => {
const [proposal, setProposal] = useState<undefined | Proposal>();
const [params] = useSearchParams();

useEffect(() => {
const targets = params.get("targets")?.split("|");
const calldatas = params.get("calldatas")?.split("|");
const values = params.get("values")?.split("|");
const targets = params.get(queryKeys.targets)?.split("|");
const calldatas = params.get(queryKeys.calldatas)?.split("|");
const values = params.get(queryKeys.values)?.split("|");
if (targets && calldatas) {
// ensure the 3 lengths are the same. check if values also has the same length if its not empty
// check the inverse of the above, if inverse is true, return:
Expand Down
9 changes: 5 additions & 4 deletions src/hooks/useSetParamsFromQuery.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useCallback } from "react";
import { useSearchParams } from "react-router-dom";
import { Proposal } from "../schemas/proposal";
import { queryKeys } from "./useLoadProposalFromQuery";

export const useSetParamsFromQuery = () => {
export const useRedirectToProposalWithNewParams = () => {
const [_, setParams] = useSearchParams();

return useCallback(
Expand All @@ -12,9 +13,9 @@ export const useSetParamsFromQuery = () => {
}
console.log("setting params", proposal.actions);
setParams({
targets: proposal.actions!.map((action) => action.to).join("|"),
data: proposal.actions!.map((action) => action.data).join("|"),
value: proposal.actions!.map((action) => action.value).join("|"),
[queryKeys.targets]: proposal.actions!.map((action) => action.to).join("|"),
[queryKeys.calldatas]: proposal.actions!.map((action) => action.data).join("|"),
[queryKeys.values]: proposal.actions!.map((action) => action.value).join("|"),
});
},
[setParams],
Expand Down
Loading