Skip to content
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

Feat/lp zapping #1596

Open
wants to merge 61 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
899a683
wip: add zap component
karczuRF Aug 17, 2022
5871156
feat: add zap state
karczuRF Aug 17, 2022
c1d23c7
Merge branch 'develop' into feat/lp-zapping
karczuRF Sep 16, 2022
1efd846
Merge branch 'develop' into feat/lp-zapping
karczuRF Sep 19, 2022
499e57b
refactor: add zap abi & use contract
karczuRF Sep 26, 2022
0c0fb8b
WIP
karczuRF Oct 26, 2022
7bae265
WIP store refactor
karczuRF Oct 26, 2022
86be5b3
WIP
karczuRF Oct 26, 2022
3920f3c
WIP - best trade
karczuRF Oct 26, 2022
7776def
WIP: refactor hooks
karczuRF Oct 26, 2022
80d7d35
WIP - test refactor hook
mix1o Oct 27, 2022
fd63274
WIP: default zap currency
karczuRF Oct 28, 2022
a07f0c1
WIP: refactor zap approve flow
karczuRF Oct 28, 2022
9f90937
WIP: refactor state & hooks
karczuRF Nov 11, 2022
e94590f
wip: refactor callback
karczuRF Nov 15, 2022
95f8bba
wip: use zap contract
karczuRF Nov 16, 2022
2e4af38
remove unused files
mwiniarsk Nov 17, 2022
20c477a
Merge branch 'develop' into feat/lp-zapping
mwiniarsk Nov 17, 2022
1e4e054
fix after merge
mwiniarsk Nov 17, 2022
4d4afd3
wip: refactor amounts calculations
karczuRF Nov 18, 2022
7609cb2
update zap index with new develop
mwiniarsk Nov 18, 2022
2416158
wip: slice path
karczuRF Nov 18, 2022
07ac11c
Merge branch 'feat/lp-zapping' of github.com:levelkdev/swapr-dapp int…
karczuRF Nov 18, 2022
e9fb16e
wip: refactor zap callback
karczuRF Nov 19, 2022
b669a7b
wip: add useZapParams
karczuRF Nov 21, 2022
32bdb85
wip: refactor fetching trades
karczuRF Nov 21, 2022
999a5d2
display pair and token for currency view, set loading for TradeDetails
mwiniarsk Nov 21, 2022
4b1ce0e
set separate TradeDetails for Zap, handle update tabs when user chang…
mwiniarsk Nov 21, 2022
3575d2e
wip: refactor hook & get trade for uniV2
karczuRF Nov 21, 2022
3c10c14
wip: refactor hooks & contract abi
karczuRF Nov 22, 2022
d982732
update disabled output
mwiniarsk Nov 22, 2022
71e3acb
fix - return amountLpFrom as string not BigNumber
mwiniarsk Nov 22, 2022
e8acb7d
refactor: min zap amounts
karczuRF Nov 22, 2022
bdadabb
Merge branch 'feat/lp-zapping' of github.com:levelkdev/swapr-dapp int…
karczuRF Nov 22, 2022
a931b58
fix callback bugs
karczuRF Nov 22, 2022
bc8beda
fix allowance bug
karczuRF Nov 22, 2022
3125c3b
code cleanup
karczuRF Nov 23, 2022
9734f01
enable zap when user is not on expert mode
mwiniarsk Nov 25, 2022
ad751d0
refactor pair selector
karczuRF Dec 7, 2022
4bfe96c
refactor input panel props
karczuRF Dec 7, 2022
5c2ee07
add gas estimation
karczuRF Dec 7, 2022
f8ce147
add zapOut output estimation
karczuRF Dec 8, 2022
c4adec5
refactor get trades from ecorouter
karczuRF Dec 8, 2022
4963529
refactor zap trade details
karczuRF Dec 9, 2022
8bf8b1b
refactor & cleanup zap hooks
karczuRF Dec 9, 2022
8550c88
cleanup code & remove unused files
karczuRF Dec 9, 2022
50e5c2f
refactor types names & cleanup
karczuRF Dec 9, 2022
ad80fc2
Merge branch 'develop' into feat/lp-zapping
karczuRF Dec 9, 2022
2ebc7bb
fix bugs after merge
karczuRF Dec 9, 2022
42ac8cc
fix: zap out state & summary
karczuRF Dec 12, 2022
9891e4a
fix: estimate usd price for zap out
karczuRF Dec 13, 2022
9acae00
fix: swapr crashes if zap out from no-lp pool
karczuRF Dec 13, 2022
7bcbf9d
fix: gas estimation
karczuRF Dec 14, 2022
34db3ec
fix: gas limit error
karczuRF Dec 14, 2022
227a0ac
fix zap calculations & set error if zap not available
karczuRF Dec 14, 2022
8744684
fix: zap params error
karczuRF Dec 14, 2022
fde95d0
cleanup & comments
karczuRF Dec 14, 2022
6d14db8
refactor zap button
karczuRF Dec 14, 2022
963df67
refactor: button text zap in & zap out
karczuRF Dec 15, 2022
bd5b1f1
feat: add zap tx to account history
karczuRF Dec 16, 2022
0b6d9dc
update contract address
karczuRF Dec 16, 2022
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
1 change: 1 addition & 0 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"liquidity": "Liquidity",
"rewards": "Rewards",
"connectWallet": "Connect wallet",
"zap": "Zap",
"chart": "chart",
"off": "off"
}
3 changes: 2 additions & 1 deletion public/locales/en/pool.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
"pairsList.pair": "Pair",
"pairsList.farming": "Farming",
"pairsList.myPairs": "My Pairs",
"pairsList.accountAnalyticsAndAccruedFees": "Account analytics and accrued fees"
"pairsList.accountAnalyticsAndAccruedFees": "Account analytics and accrued fees",
"pair.zap": "Zap"
}
9 changes: 9 additions & 0 deletions public/locales/en/swap.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"settings.MEVProtection": "MEV Protection",
"tabs.limit": "Limit",
"tabs.bridgeSwap": "Bridge Swap",
"tabs.zap": "Zap",
"button.priceImpactTooHigh": "Price Impact Too High",
"button.swapWith": "Swap with",
"button.anyway": "Anyway",
Expand All @@ -32,6 +33,14 @@
"button.enterCurrencyAmount": "Enter {{ currency }} amount",
"tradeDetails.bestPriceFoundOn": "Best price found on <0>{{platform}}</0>.",
"tradeDetails.swapWithNoAdditionalFees": "Swap with <0>no additional fees</0>.",
"tradeDetails.priceImpact": "Price impact: <0>{{priceImpact}} %</0>.",
"button.selectPair": "Select pair",
"button.tradeNotFound": "Trade not found",
"button.zap": "Zap",
"button.zapInTo": "Zap in to",
"button.zapOutFrom": "Zap out from",
"button.zapAnyway": "Zap anyway",
"button.zapNotAvailable": "Zap not available",
"advancedTradingView.column.trades": "Trades",
"advancedTradingView.column.openOrders": "Open orders",
"advancedTradingView.column.orderHistory": "Order history",
Expand Down
55 changes: 40 additions & 15 deletions src/components/CurrencyInputPanel/CurrencyInputPanel.component.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Currency } from '@swapr/sdk'
import { Currency, Pair } from '@swapr/sdk'

import { useCallback, useEffect, useMemo, useState } from 'react'

Expand All @@ -13,6 +13,7 @@ import { NumericalInput } from '../Input/NumericalInput'
import { Loader } from '../Loader'
import { RowBetween } from '../Row'
import { CurrencySearchModalComponent } from '../SearchModal/CurrencySearchModal'
import { PairSearchModal } from '../SearchModal/PairSearchModal'
import {
Aligner,
Container,
Expand All @@ -23,7 +24,7 @@ import {
LabelRow,
UppercaseHelper,
} from './CurrencyInputPanel.styles'
import { CurrencyInputPanelProps } from './CurrencyInputPanel.types'
import { CurrencyInputPanelProps, InputType } from './CurrencyInputPanel.types'
import { CurrencyUserBalance } from './CurrencyUserBalance'
import { CurrencyView } from './CurrencyView'

Expand All @@ -36,6 +37,7 @@ export const CurrencyInputPanelComponent = ({
balance,
currency,
disabled,
isDisabledStyled = false,
hideInput = false,
isLoading = false,
fiatValue,
Expand All @@ -52,6 +54,10 @@ export const CurrencyInputPanelComponent = ({
currencyWrapperSource = CurrencyWrapperSource.SWAP,
disableCurrencySelect = false,
isOutputPanel,
inputType = InputType.currency,
onPairSelect,
filterPairs,
inputTitle,
}: CurrencyInputPanelProps) => {
const [isOpen, setIsOpen] = useState(false)
const [focused, setFocused] = useState(false)
Expand Down Expand Up @@ -93,12 +99,19 @@ export const CurrencyInputPanelComponent = ({
[isMaxAmount, onCurrencySelect]
)

const handleOnPairSelect = useCallback(
(pair: Pair) => {
if (onPairSelect) onPairSelect(pair)
},
[onPairSelect]
)

const handleOnUserInput = useCallback(
(value: string) => {
if (maxAmount?.toExact() === value) setIsMaxAmount(true)
else setIsMaxAmount(false)

onUserInput(value)
if (onUserInput) onUserInput(value)
},
[maxAmount, onUserInput]
)
Expand All @@ -116,7 +129,7 @@ export const CurrencyInputPanelComponent = ({

return (
<InputPanel id={id}>
<Container focused={focused}>
<Container disabled={isDisabledStyled} focused={focused}>
<Content>
{!hideInput && label && (
<LabelRow>
Expand All @@ -141,6 +154,7 @@ export const CurrencyInputPanelComponent = ({
}}
disabled={disabled}
data-testid={'transaction-value-input'}
title={inputTitle}
/>
</>
)}
Expand All @@ -160,6 +174,7 @@ export const CurrencyInputPanelComponent = ({
currency={currency}
chainIdOverride={chainIdOverride}
currencyWrapperSource={currencyWrapperSource}
inputType={inputType}
/>
)}
</Aligner>
Expand All @@ -181,17 +196,27 @@ export const CurrencyInputPanelComponent = ({
</div>
</Content>
</Container>
{!disableCurrencySelect && onCurrencySelect && (
<CurrencySearchModalComponent
isOpen={isOpen}
onDismiss={onDismiss}
onCurrencySelect={handleOnCurrencySelect}
selectedCurrency={currency}
otherSelectedCurrency={new Array(1).fill(otherCurrency)}
showCommonBases={showCommonBases}
isOutputPanel={isOutputPanel}
/>
)}
{!disableCurrencySelect &&
(onCurrencySelect && inputType === InputType.currency ? (
<CurrencySearchModalComponent
isOpen={isOpen}
onDismiss={onDismiss}
onCurrencySelect={handleOnCurrencySelect}
selectedCurrency={currency}
otherSelectedCurrency={new Array(1).fill(otherCurrency)}
showCommonBases={showCommonBases}
isOutputPanel={isOutputPanel}
/>
) : (
onPairSelect && (
<PairSearchModal
isOpen={isOpen}
onDismiss={onDismiss}
onPairSelect={handleOnPairSelect}
filterPairs={filterPairs}
/>
)
))}
</InputPanel>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ export const InputPanel = styled.div`
z-index: 1;
`

export const Container = styled.div<{ focused: boolean }>`
background-color: ${({ theme }) => theme.bg1And2};
export const Container = styled.div<{ focused: boolean; disabled?: boolean }>`
background-color: ${({ theme, disabled }) =>
disabled ? 'linear-gradient(90deg,#4c4c76 19.74%,#292942 120.26%)' : theme.bg1And2};
border: solid 1px ${({ focused, theme }) => (focused ? theme.bg3 : theme.bg1And2)};
border-radius: 12px;
transition: border 0.3s ease;
Expand Down
14 changes: 12 additions & 2 deletions src/components/CurrencyInputPanel/CurrencyInputPanel.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ export interface CurrencyInputPanelProps {
balance?: CurrencyAmount
currency?: Currency | null
disabled?: boolean
isDisabledStyled?: boolean
hideInput?: boolean
fiatValue?: CurrencyAmount | null
isLoading?: boolean
onUserInput: (value: string) => void
onUserInput?: (value: string) => void
hideBalance?: boolean
priceImpact?: Percent
otherCurrency?: Currency | null
Expand All @@ -29,15 +30,24 @@ export interface CurrencyInputPanelProps {
setDisplayedValue?: (val: string) => void
maxAmount?: CurrencyAmount
isOutputPanel?: boolean
inputType?: InputType
onPairSelect?: (pair: Pair) => void
filterPairs?: (pair: Pair) => boolean
inputTitle?: string
}

export type CurrencyViewProps = Pick<
CurrencyInputPanelProps,
'currency' | 'currency' | 'chainIdOverride' | 'currencyWrapperSource' | 'disableCurrencySelect' | 'pair'
'currency' | 'currency' | 'chainIdOverride' | 'currencyWrapperSource' | 'disableCurrencySelect' | 'pair' | 'inputType'
>
export type CurrencyUserBalanceProps = Pick<
CurrencyInputPanelProps,
'hideBalance' | 'currency' | 'pair' | 'balance' | 'customBalanceText' | 'onMax'
> & {
selectedCurrencyBalance: CurrencyAmount | undefined
}

export enum InputType {
currency,
pair,
}
12 changes: 9 additions & 3 deletions src/components/CurrencyInputPanel/CurrencyView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ import { useTranslation } from 'react-i18next'
import { CurrencyLogo } from '../CurrencyLogo'
import { DoubleCurrencyLogo } from '../DoubleCurrencyLogo'
import { StyledDropDown, StyledTokenName } from './CurrencyInputPanel.styles'
import { CurrencyViewProps } from './CurrencyInputPanel.types'
import { CurrencyViewProps, InputType } from './CurrencyInputPanel.types'

export const CurrencyView = ({
pair,
currency,
chainIdOverride,
currencyWrapperSource,
disableCurrencySelect,
inputType,
}: CurrencyViewProps) => {
const { t } = useTranslation('swap')

if (pair) {
if (pair && (currency?.symbol === 'DXS' || !currency)) {
return (
<>
<DoubleCurrencyLogo marginRight={4} currency0={pair.token0} currency1={pair.token1} size={20} />
Expand Down Expand Up @@ -45,7 +46,12 @@ export const CurrencyView = ({
? currency.symbol.slice(0, 4) +
'...' +
currency.symbol.slice(currency.symbol.length - 5, currency.symbol.length)
: currency?.symbol) || <div data-testid="select-token-button"> {t('currencyView.selectToken')}</div>}
: currency?.symbol) || (
<div data-testid="select-token-button">
{' '}
{inputType === InputType.currency ? t('button.selectToken') : t('button.selectPair')}
</div>
)}
</StyledTokenName>
{!disableCurrencySelect && (pair || currency) && <StyledDropDown selected={!!currency} />}
</>
Expand Down
4 changes: 4 additions & 0 deletions src/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ function Header() {
</Text>
</HeaderLink>
<HeaderLink data-testid="zap-nav-link" id="zap-nav-link" to="/zap">
{t('zap')}
<HeaderLinkBadge label="BETA" />
</HeaderLink>
</HeaderLinks>
</HeaderRow>
<AdditionalDataWrap>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Input/NumericalInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const NumericalInput = memo(function InnerInput({
value,
onUserInput,
placeholder,
title,
...rest
}: {
value: string | number
Expand All @@ -34,7 +35,7 @@ export const NumericalInput = memo(function InnerInput({
}}
// universal input options
inputMode="decimal"
title="Token Amount"
title={title ?? 'Token Amount'}
autoComplete="off"
autoCorrect="off"
// text-specific options
Expand Down
14 changes: 10 additions & 4 deletions src/components/RecipientField/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ActionCreatorWithPayload } from '@reduxjs/toolkit'
import { ChangeEvent, useCallback, useEffect, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import { useDispatch } from 'react-redux'
import styled from 'styled-components'

import useENS from '../../hooks/useENS'
import { setRecipient } from '../../state/swap/actions'
import { TYPE } from '../../theme'
import { SearchInput } from '../SearchModal/shared'

Expand All @@ -20,9 +20,15 @@ const SearchInputStyled = styled(SearchInput)<{ error: boolean }>`

export interface RecipientFieldProps {
recipient: string | null
setRecipient: ActionCreatorWithPayload<
{
recipient: string | null
},
string
>
}

export const RecipientField = ({ recipient }: RecipientFieldProps) => {
export const RecipientField = ({ recipient, setRecipient }: RecipientFieldProps) => {
const { t } = useTranslation('swap')
const dispatch = useDispatch()
const { address, loading } = useENS(recipient)
Expand All @@ -36,15 +42,15 @@ export const RecipientField = ({ recipient }: RecipientFieldProps) => {
const input = event.target.value
dispatch(setRecipient({ recipient: input }))
},
[dispatch]
[dispatch] // eslint-disable-line react-hooks/exhaustive-deps
)

// Unset recipient on unmount
useEffect(() => {
return () => {
dispatch(setRecipient({ recipient: null }))
}
}, [dispatch])
}, [dispatch]) // eslint-disable-line react-hooks/exhaustive-deps

return (
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const PairSearch = ({ selectedPair, onPairSelect, onDismiss, isOpen, filt

const filteredPairs: Pair[] = useMemo(() => {
let pairs = allPairs
// TODO add loading indicator during filtering
if (filterPairs) pairs = allPairs.filter(filterPairs)
if (isAddressSearch) return searchPair ? [searchPair] : []
return filterPairsBySearchQuery(pairs, searchQuery)
Expand Down
7 changes: 6 additions & 1 deletion src/components/SearchModal/utils/filtering.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Currency, Pair, Token } from '@swapr/sdk'
import { ChainId, Currency, Pair, Token } from '@swapr/sdk'

import { TokenInfo } from '@uniswap/token-lists'
import { useMemo } from 'react'

import { SUPPORTED_ZAP_PAIRS } from '../../../constants'
import { isAddress } from '../../../utils'

const alwaysTrue = () => true
Expand Down Expand Up @@ -143,3 +144,7 @@ export const useSortedTokensByQuery = (tokens: Token[] | undefined, searchQuery:
return [...exactMatches, ...symbolSubtrings, ...rest]
}, [tokens, searchQuery])
}

export const filterPairsForZap = (pair: Pair, chainId: ChainId): boolean => {
return SUPPORTED_ZAP_PAIRS[chainId].includes(pair.liquidityToken.address)
}
Loading