-
Notifications
You must be signed in to change notification settings - Fork 199
feat(yields): mini swapper modal #11730
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d265d3b
fix: improve yield UI terminology, button states, and add Get Asset f…
gomesalexandre 178f053
Merge origin/develop into feat_yield_final_polish
gomesalexandre 8a55116
feat(yields): add "Get Asset" button to redirect users to trade page
gomesalexandre 8768bc8
feat(yields): add SwapperModal for in-context asset acquisition
gomesalexandre b07d740
Merge remote-tracking branch 'origin/develop' into feat_yield_final_p…
gomesalexandre 578950d
chore: remove diff files
gomesalexandre dcceb87
fix: show My Position card with Connect Wallet when no wallet connected
gomesalexandre cd8661d
fix: add missing yieldXYZ.getAsset translation
gomesalexandre b1c7bf2
docs: add i18n workflow note to CLAUDE.md
gomesalexandre 9d13a59
fix: use useTradeNavigation for Get Asset button to properly set buy …
gomesalexandre 8ac3cbd
Merge remote-tracking branch 'origin/feat_yield_final_polish' into fe…
gomesalexandre bd8e0d9
fix: simplify SwapperModal - remove header on desktop, keep on mobile
gomesalexandre ce56a1b
fix: use isCompact mode for SwapperModal to show single-column view
gomesalexandre 3523ced
chore: remove unnecessary barrel file
gomesalexandre b7d68cb
chore: resolve merge conflicts from develop squash merge
gomesalexandre 1775843
feat(swapper-modal): add onSuccess callback for auto-close on trade c…
gomesalexandre 6443150
feat(swapper-modal): add modal styling and fire callback on swap broa…
gomesalexandre 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 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
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
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,74 @@ | ||
| import type { AssetId } from '@shapeshiftoss/caip' | ||
| import { memo, useCallback } from 'react' | ||
| import { MemoryRouter } from 'react-router-dom' | ||
|
|
||
| import { SwapperModalContent } from './SwapperModalContent' | ||
|
|
||
| import { Display } from '@/components/Display' | ||
| import { Dialog } from '@/components/Modal/components/Dialog' | ||
| import { DialogBody } from '@/components/Modal/components/DialogBody' | ||
| import { DialogCloseButton } from '@/components/Modal/components/DialogCloseButton' | ||
| import { DialogHeader } from '@/components/Modal/components/DialogHeader' | ||
| import { DialogTitle } from '@/components/Modal/components/DialogTitle' | ||
| import { TradeRoutePaths } from '@/components/MultiHopTrade/types' | ||
| import { tradeInput } from '@/state/slices/tradeInputSlice/tradeInputSlice' | ||
| import { useAppDispatch } from '@/state/store' | ||
|
|
||
| type SwapperModalProps = { | ||
| isOpen: boolean | ||
| onClose: () => void | ||
| defaultBuyAssetId?: AssetId | ||
| defaultSellAssetId?: AssetId | ||
| } | ||
|
|
||
| const initialEntries = [ | ||
| { pathname: TradeRoutePaths.Input }, | ||
| { pathname: TradeRoutePaths.Confirm }, | ||
| { pathname: TradeRoutePaths.VerifyAddresses }, | ||
| { pathname: TradeRoutePaths.QuoteList }, | ||
| ] | ||
|
|
||
| export const SwapperModal = memo( | ||
| ({ isOpen, onClose, defaultBuyAssetId, defaultSellAssetId }: SwapperModalProps) => { | ||
| const dispatch = useAppDispatch() | ||
|
|
||
| const handleClose = useCallback(() => { | ||
| dispatch(tradeInput.actions.clear()) | ||
| onClose() | ||
| }, [dispatch, onClose]) | ||
|
|
||
| return ( | ||
| <Dialog | ||
| isOpen={isOpen} | ||
| onClose={handleClose} | ||
| height='auto' | ||
| modalProps={{ | ||
| closeOnOverlayClick: true, | ||
| size: { base: 'full', md: 'md' }, | ||
| }} | ||
| > | ||
| <Display.Mobile> | ||
| <DialogHeader> | ||
| <DialogHeader.Left>{null}</DialogHeader.Left> | ||
| <DialogHeader.Middle> | ||
| <DialogTitle>Trade</DialogTitle> | ||
| </DialogHeader.Middle> | ||
| <DialogHeader.Right> | ||
| <DialogCloseButton /> | ||
| </DialogHeader.Right> | ||
| </DialogHeader> | ||
| </Display.Mobile> | ||
| <DialogBody py={0} px={{ base: 4, md: 0 }} flex={1} display='flex' flexDirection='column'> | ||
| {isOpen && ( | ||
| <MemoryRouter initialEntries={initialEntries} initialIndex={0}> | ||
| <SwapperModalContent | ||
| defaultBuyAssetId={defaultBuyAssetId} | ||
| defaultSellAssetId={defaultSellAssetId} | ||
| /> | ||
| </MemoryRouter> | ||
| )} | ||
| </DialogBody> | ||
| </Dialog> | ||
| ) | ||
| }, | ||
| ) |
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,65 @@ | ||
| import type { AssetId } from '@shapeshiftoss/caip' | ||
| import { memo, useCallback, useLayoutEffect, useRef } from 'react' | ||
| import { FormProvider, useForm } from 'react-hook-form' | ||
| import { useNavigate } from 'react-router-dom' | ||
|
|
||
| import { TradingErrorBoundary } from '@/components/ErrorBoundary' | ||
| import { StandaloneMultiHopTrade } from '@/components/MultiHopTrade/StandaloneMultiHopTrade' | ||
| import { TradeInputTab, TradeRoutePaths } from '@/components/MultiHopTrade/types' | ||
| import { selectAssetById } from '@/state/slices/assetsSlice/selectors' | ||
| import { tradeInput } from '@/state/slices/tradeInputSlice/tradeInputSlice' | ||
| import { useAppDispatch, useAppSelector } from '@/state/store' | ||
|
|
||
| type SwapperModalContentProps = { | ||
| defaultBuyAssetId?: AssetId | ||
| defaultSellAssetId?: AssetId | ||
| } | ||
|
|
||
| export const SwapperModalContent = memo(function SwapperModalContent({ | ||
| defaultBuyAssetId, | ||
| defaultSellAssetId, | ||
| }: SwapperModalContentProps) { | ||
| const methods = useForm({ mode: 'onChange' }) | ||
| const navigate = useNavigate() | ||
| const dispatch = useAppDispatch() | ||
| const hasInitialized = useRef(false) | ||
|
|
||
| const defaultBuyAsset = useAppSelector(state => selectAssetById(state, defaultBuyAssetId ?? '')) | ||
| const defaultSellAsset = useAppSelector(state => selectAssetById(state, defaultSellAssetId ?? '')) | ||
|
|
||
| useLayoutEffect(() => { | ||
| if (hasInitialized.current) return | ||
| hasInitialized.current = true | ||
|
|
||
| dispatch(tradeInput.actions.clear()) | ||
| if (defaultBuyAsset) { | ||
| dispatch(tradeInput.actions.setBuyAsset(defaultBuyAsset)) | ||
| } | ||
| if (defaultSellAsset) { | ||
| dispatch(tradeInput.actions.setSellAsset(defaultSellAsset)) | ||
| } | ||
| }, [dispatch, defaultBuyAsset, defaultSellAsset]) | ||
|
|
||
| const handleChangeTab = useCallback( | ||
| (newTab: TradeInputTab) => { | ||
| if (newTab === TradeInputTab.Trade) { | ||
| navigate(TradeRoutePaths.Input) | ||
| } | ||
| }, | ||
| [navigate], | ||
| ) | ||
|
|
||
| return ( | ||
| <FormProvider {...methods}> | ||
| <TradingErrorBoundary> | ||
| <StandaloneMultiHopTrade | ||
| defaultBuyAssetId={defaultBuyAssetId} | ||
| defaultSellAssetId={defaultSellAssetId} | ||
| onChangeTab={handleChangeTab} | ||
| isCompact | ||
| isStandalone | ||
| /> | ||
| </TradingErrorBoundary> | ||
| </FormProvider> | ||
| ) | ||
| }) |
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
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
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
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.