-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(v1-support): Enable executing swaps on v1 or v2 (#883)
* swap-v1 * toggle the version switch based on the search query parameter * rework some of the query parameter stuff in send/swap * hide the url when they click it * allow switching back to v2 via the toggle * represent the v1 trade in the UI if they toggle it on * show trade link in both directions (5% threshold for v1 link) * input amounts should reflect v1/v2 * perform the approve on v1 exchange for v1 trades * get swap on v1 working * move some code around to reduce duplication * fix ts error * correct input allowance * fix exact token to token on v1 * fix pending approvals to be specific to the spender * google analytics for swap version * disable the version switch on pages other than swap and send
- Loading branch information
1 parent
29db0a5
commit bafd3f3
Showing
24 changed files
with
656 additions
and
383 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { stringify } from 'qs' | ||
import React, { useCallback, useMemo } from 'react' | ||
import { Link, useLocation } from 'react-router-dom' | ||
import styled from 'styled-components' | ||
import useParsedQueryString from '../../hooks/useParsedQueryString' | ||
import useToggledVersion, { Version } from '../../hooks/useToggledVersion' | ||
|
||
const VersionLabel = styled.span<{ enabled: boolean }>` | ||
padding: ${({ enabled }) => (enabled ? '0.15rem 0.5rem 0.16rem 0.45rem' : '0.15rem 0.5rem 0.16rem 0.35rem')}; | ||
border-radius: 14px; | ||
background: ${({ theme, enabled }) => (enabled ? theme.primary1 : 'none')}; | ||
color: ${({ theme, enabled }) => (enabled ? theme.white : theme.primary1)}; | ||
font-size: 0.825rem; | ||
font-weight: 400; | ||
:hover { | ||
user-select: ${({ enabled }) => (enabled ? 'none' : 'initial')}; | ||
background: ${({ theme, enabled }) => (enabled ? theme.primary1 : 'none')}; | ||
color: ${({ theme, enabled }) => (enabled ? theme.white : theme.primary3)}; | ||
} | ||
` | ||
const VersionToggle = styled(Link)<{ enabled: boolean }>` | ||
border-radius: 16px; | ||
opacity: ${({ enabled }) => (enabled ? 1 : 0.5)}; | ||
cursor: ${({ enabled }) => (enabled ? 'pointer' : 'default')}; | ||
background: ${({ theme }) => theme.primary5}; | ||
border: 1px solid ${({ theme }) => theme.primary4}; | ||
color: ${({ theme }) => theme.primary1}; | ||
display: flex; | ||
width: fit-content; | ||
text-decoration: none; | ||
:hover { | ||
text-decoration: none; | ||
} | ||
` | ||
|
||
export function VersionSwitch() { | ||
const version = useToggledVersion() | ||
const location = useLocation() | ||
const query = useParsedQueryString() | ||
const versionSwitchAvailable = location.pathname === '/swap' || location.pathname === '/send' | ||
|
||
const toggleDest = useMemo(() => { | ||
return versionSwitchAvailable | ||
? { | ||
...location, | ||
search: `?${stringify({ ...query, use: version === Version.v1 ? undefined : Version.v1 })}` | ||
} | ||
: location | ||
}, [location, query, version, versionSwitchAvailable]) | ||
|
||
const handleClick = useCallback( | ||
e => { | ||
if (!versionSwitchAvailable) e.preventDefault() | ||
}, | ||
[versionSwitchAvailable] | ||
) | ||
|
||
return ( | ||
<VersionToggle enabled={versionSwitchAvailable} to={toggleDest} onClick={handleClick}> | ||
<VersionLabel enabled={version === Version.v2 || !versionSwitchAvailable}>V2</VersionLabel> | ||
<VersionLabel enabled={version === Version.v1 && versionSwitchAvailable}>V1</VersionLabel> | ||
</VersionToggle> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { stringify } from 'qs' | ||
import React, { useContext, useMemo } from 'react' | ||
import { useLocation } from 'react-router' | ||
import { Text } from 'rebass' | ||
import { ThemeContext } from 'styled-components' | ||
import useParsedQueryString from '../../hooks/useParsedQueryString' | ||
import { Version } from '../../hooks/useToggledVersion' | ||
|
||
import { StyledInternalLink } from '../../theme' | ||
import { YellowCard } from '../Card' | ||
import { AutoColumn } from '../Column' | ||
|
||
export default function BetterTradeLink({ version }: { version: Version }) { | ||
const theme = useContext(ThemeContext) | ||
const location = useLocation() | ||
const search = useParsedQueryString() | ||
|
||
const linkDestination = useMemo(() => { | ||
return { | ||
...location, | ||
search: `?${stringify({ | ||
...search, | ||
use: version | ||
})}` | ||
} | ||
}, [location, search, version]) | ||
|
||
return ( | ||
<YellowCard style={{ marginTop: '12px', padding: '8px 4px' }}> | ||
<AutoColumn gap="sm" justify="center" style={{ alignItems: 'center', textAlign: 'center' }}> | ||
<Text lineHeight="145.23%;" fontSize={14} fontWeight={400} color={theme.text1}> | ||
There is a better price for this trade on{' '} | ||
<StyledInternalLink to={linkDestination}> | ||
<b>Uniswap {version.toUpperCase()} ↗</b> | ||
</StyledInternalLink> | ||
</Text> | ||
</AutoColumn> | ||
</YellowCard> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
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.
bafd3f3
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.
Successfully deployed to following URLs: