-
Notifications
You must be signed in to change notification settings - Fork 142
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
refactor: swaps routes, closes #4317 #5177
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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
51 changes: 26 additions & 25 deletions
51
...oose-asset/components/swap-asset-list.tsx → ...set-dialog/components/swap-asset-list.tsx
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
33 changes: 33 additions & 0 deletions
33
src/app/pages/swap/components/swap-asset-dialog/swap-asset-dialog-base.tsx
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { RouteUrls } from '@shared/route-urls'; | ||
pete-watters marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import { Dialog } from '@app/ui/components/containers/dialog/dialog'; | ||
import { Header } from '@app/ui/components/containers/headers/header'; | ||
|
||
import { useSwapNavigate } from '../../hooks/use-swap-navigate'; | ||
import { useSwapContext } from '../../swap.context'; | ||
import { SwapAssetList } from './components/swap-asset-list'; | ||
|
||
export function SwapAssetDialogBase() { | ||
const { swappableAssetsBase } = useSwapContext(); | ||
const navigate = useSwapNavigate(); | ||
|
||
return ( | ||
<Dialog | ||
isShowing | ||
onClose={() => navigate(RouteUrls.Swap)} | ||
header={ | ||
<Header | ||
title={ | ||
<> | ||
Choose asset <br /> to swap | ||
</> | ||
} | ||
variant="bigTitle" | ||
onGoBack={() => navigate(RouteUrls.Swap)} | ||
/> | ||
} | ||
> | ||
<SwapAssetList assets={swappableAssetsBase} type="base" /> | ||
</Dialog> | ||
); | ||
} |
33 changes: 33 additions & 0 deletions
33
src/app/pages/swap/components/swap-asset-dialog/swap-asset-dialog-quote.tsx
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { RouteUrls } from '@shared/route-urls'; | ||
|
||
import { Dialog } from '@app/ui/components/containers/dialog/dialog'; | ||
import { Header } from '@app/ui/components/containers/headers/header'; | ||
|
||
import { useSwapNavigate } from '../../hooks/use-swap-navigate'; | ||
import { useSwapContext } from '../../swap.context'; | ||
import { SwapAssetList } from './components/swap-asset-list'; | ||
|
||
export function SwapAssetDialogQuote() { | ||
const { swappableAssetsQuote } = useSwapContext(); | ||
const navigate = useSwapNavigate(); | ||
|
||
return ( | ||
<Dialog | ||
isShowing | ||
onClose={() => navigate(RouteUrls.Swap)} | ||
header={ | ||
<Header | ||
title={ | ||
<> | ||
Choose asset <br /> to receive | ||
</> | ||
} | ||
variant="bigTitle" | ||
onGoBack={() => navigate(RouteUrls.Swap)} | ||
/> | ||
} | ||
> | ||
<SwapAssetList assets={swappableAssetsQuote} type="quote" /> | ||
</Dialog> | ||
); | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, this isn't great. Before we were storing the whole header including callback in the state.
Maybe we could try using the location state to store where it should go back to?
For some of the other dynamic routes I was using
match
to get to more specific cases.If we use
includes
here it also means if you reach the/swap/review
page then you go all the way back to the homepage on back and not to the previous page where you are selecting what to swap.In those cases I think it should go back
navigate(-1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than trying to put all the go back logic in the container—which think we all agree isn't a scalable solution—can't we instead find a way to define this in each component tree where there is a back button?
What if the header back button simply publishes a "go back" event, e.g. with PubSub pattern, and components, via a hook listen for this event?
Perhaps not perfect. We'd need to be careful not to have double handlers, and ensure we define goback where necessary, but this demonstrates a way we can completely decouple the logic.
Any other ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened issue for this here #5181
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another idea I have is to have route props that specify it. So we can pass a call back either when loading the component in the routes file, or have it as part of the location state. I'll have a think about it.
Getting the headers out of state was a good start but this logic isn't great so I am open to a full overhaul. If you check in
route-helpers.ts
, I've had to use routes to apply other logic so it could be good to also improve thatThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make an issue to refactor this based on your understanding for what you wrote here and your implementation? I will likely not tackle this here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm, my comments hadn't refreshed, sorry that last comment was outdated.