-
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: allow WETH when adding liquidity to an existsing LP position
- Loading branch information
Josh DeCristi
authored and
Josh DeCristi
committed
Oct 11, 2023
1 parent
27ec2e0
commit 6d6f31d
Showing
2 changed files
with
86 additions
and
5 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,65 @@ | ||
import { Trans } from '@lingui/macro' | ||
import { useWeb3React } from '@web3-react/core' | ||
import { ToggleElement, ToggleWrapper } from 'components/Toggle/MultiToggle' | ||
import { useCurrency } from 'hooks/Tokens' | ||
|
||
import { WRAPPED_NATIVE_CURRENCY } from '../../constants/tokens' | ||
|
||
function isNative(currencyId?: string) { | ||
return currencyId === 'ETH' | ||
} | ||
|
||
function isWrappedNative(currencyId?: string, chainId?: number) { | ||
return chainId !== undefined && currencyId === WRAPPED_NATIVE_CURRENCY[chainId]?.address | ||
} | ||
|
||
type WrappedCurrencyToggleProps = { | ||
currencyIdA?: string | ||
currencyIdB?: string | ||
onChangeCurrencies: (CurrencyAId?: string, currencyBId?: string) => void | ||
} | ||
|
||
export function WrappedCurrencyToggle({ currencyIdA, currencyIdB, onChangeCurrencies }: WrappedCurrencyToggleProps) { | ||
const { chainId } = useWeb3React() | ||
|
||
// Get native and wrapped native Currencies | ||
const native = useCurrency('ETH', chainId) | ||
const wrappedNative = chainId ? WRAPPED_NATIVE_CURRENCY[chainId] : undefined | ||
|
||
// checking to see if currencyIdA of currencyIdB is native or wrapped native | ||
const currencyIsNative = isNative(currencyIdA) || isNative(currencyIdB) | ||
const currencyIsWrappedNative = isWrappedNative(currencyIdA, chainId) || isWrappedNative(currencyIdB, chainId) | ||
|
||
if (!currencyIsNative && !currencyIsWrappedNative) return null | ||
|
||
const handleToggle = () => { | ||
if (currencyIsNative) { | ||
if (isNative(currencyIdA)) onChangeCurrencies(wrappedNative?.address, currencyIdB) | ||
else onChangeCurrencies(currencyIdA, wrappedNative?.address) | ||
} | ||
|
||
if (currencyIsWrappedNative) { | ||
if (isWrappedNative(currencyIdA)) onChangeCurrencies('ETH', currencyIdA) | ||
else onChangeCurrencies(currencyIdA, 'ETH') | ||
} | ||
} | ||
|
||
if (!currencyIsNative && !currencyIsWrappedNative) return null | ||
|
||
return ( | ||
<> | ||
{native && wrappedNative ? ( | ||
<div style={{ width: 'fit-content', display: 'flex', alignItems: 'center' }} onClick={handleToggle}> | ||
<ToggleWrapper width="fit-content"> | ||
<ToggleElement isActive={currencyIsNative} fontSize="12px"> | ||
<Trans>{native.symbol}</Trans> | ||
</ToggleElement> | ||
<ToggleElement isActive={currencyIsWrappedNative} fontSize="12px"> | ||
<Trans>{wrappedNative.symbol}</Trans> | ||
</ToggleElement> | ||
</ToggleWrapper> | ||
</div> | ||
) : null} | ||
</> | ||
) | ||
} |
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