-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements to #26 - replace context for explicit props, remove dupl…
…icate state, fix creation of a new proposal (#27) * Better naming around provider updating/namely: `addAction` and `replaceProposal` * Replace ProviderContext with explicit prop passing; remove duplicate `proposal` state and just have query string be source of truth * Fix some type failing issues * When there is no current proposal, and a user is to be added/removed from the safe, redirect to a `new` url so that the url can be properly shared
- Loading branch information
Showing
7 changed files
with
116 additions
and
92 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,27 +1,51 @@ | ||
import { useCallback } from "react"; | ||
import { useSearchParams } from "react-router-dom"; | ||
import { | ||
useLocation, | ||
useNavigate, | ||
useParams, | ||
useSearchParams, | ||
} from "react-router-dom"; | ||
import { Proposal } from "../schemas/proposal"; | ||
import { queryKeys } from "./useLoadProposalFromQuery"; | ||
|
||
export const useRedirectToProposalWithNewParams = () => { | ||
const [_, setParams] = useSearchParams(); | ||
const [, setParams] = useSearchParams(); | ||
const { networkId, safeAddress } = useParams(); | ||
const navigate = useNavigate(); | ||
const { pathname } = useLocation(); | ||
|
||
return useCallback( | ||
(proposal: Proposal) => { | ||
if (!proposal.actions?.length) { | ||
return; | ||
} | ||
setParams({ | ||
[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("|"), | ||
const params = { | ||
[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("|"), | ||
...(proposal.nonce | ||
? { | ||
[queryKeys.nonce]: proposal.nonce.toString(), | ||
} | ||
: {}), | ||
}); | ||
}; | ||
// if we are not in a new safe proposal, we need to redirect to new safe proposal | ||
// so that it shows up in the url, and renders correctly | ||
if (!pathname.includes("new")) { | ||
const newPath = `/safe/${networkId}/${safeAddress}/new`; | ||
|
||
navigate(newPath, { | ||
replace: true, | ||
}); | ||
} | ||
setParams(params); | ||
}, | ||
[setParams], | ||
[setParams, networkId, safeAddress, pathname, navigate] | ||
); | ||
}; |
Oops, something went wrong.