-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
283 additions
and
107 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
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,34 @@ | ||
import { Currency, Price } from '@pancakeswap/ton-v2-sdk' | ||
import { useModal } from '@pancakeswap/uikit' | ||
import { useUserSlippage } from '@pancakeswap/utils/user' | ||
import { SwapUIV2 } from '@pancakeswap/widgets-internal' | ||
import { SettingsModal } from 'components/Modals/SettingsModal' | ||
|
||
interface Props { | ||
showSlippage?: boolean | ||
priceLoading?: boolean | ||
price?: Price<Currency, Currency> | ||
} | ||
|
||
export const PricingAndSlippage = ({ priceLoading, price, showSlippage = true }: Props) => { | ||
const [allowedSlippage] = useUserSlippage() | ||
const [onPresentSettingsModal] = useModal(<SettingsModal isOpen={false} />) | ||
|
||
if (!price) { | ||
return null | ||
} | ||
|
||
const priceNode = price ? ( | ||
<> | ||
<SwapUIV2.TradePrice price={price as any} loading={priceLoading} /> | ||
</> | ||
) : null | ||
|
||
return ( | ||
<SwapUIV2.SwapInfo | ||
price={priceNode} | ||
allowedSlippage={showSlippage ? allowedSlippage : undefined} | ||
onSlippageClick={onPresentSettingsModal} | ||
/> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,24 +1,38 @@ | ||
import { useTranslation } from '@pancakeswap/localization' | ||
import { Button, ButtonProps } from '@pancakeswap/uikit' | ||
import { toNano } from '@ton/ton' | ||
import { inputCurrencyAtom, typedValueAtom } from 'atoms/swap/swapStateAtom' | ||
import { useAtomValue } from 'jotai' | ||
import { isConnectedAtom } from 'ton/atom/isConnectedAtom' | ||
import { balanceAtom } from 'ton/logic/balanceAtom' | ||
import { tryParseAmount } from 'utils/tryParseAmount' | ||
|
||
interface SwapCommitButtonProps extends ButtonProps {} | ||
interface SwapCommitButtonProps extends ButtonProps { | ||
isLoading?: boolean | ||
} | ||
|
||
export const SwapCommitButton = (props: SwapCommitButtonProps) => { | ||
export const SwapCommitButton = ({ isLoading = false, ...props }: SwapCommitButtonProps) => { | ||
const { t } = useTranslation() | ||
const isConnected = useAtomValue(isConnectedAtom) | ||
|
||
const inputCurrency = useAtomValue(inputCurrencyAtom) | ||
|
||
const typedValue = useAtomValue(typedValueAtom) | ||
const typedAmount = tryParseAmount(typedValue, inputCurrency) | ||
const { data: balance0 } = useAtomValue(balanceAtom(inputCurrency)) | ||
|
||
const isInsufficientBalance0 = balance0 < toNano(typedValue) // TODO: decimals | ||
const isInsufficientBalance0 = inputCurrency && typedAmount ? typedAmount.greaterThan(balance0) : false | ||
|
||
return ( | ||
<Button disabled={isInsufficientBalance0} {...props}> | ||
{t('Swap')} | ||
<Button disabled={isInsufficientBalance0 || !isConnected || isLoading} {...props}> | ||
{!isConnected | ||
? t('Connect Wallet') | ||
: !typedValue | ||
? t('Enter an amount') | ||
: isLoading | ||
? t('Updating the quote') | ||
: isInsufficientBalance0 | ||
? t('Insufficient %symbol% balance', { symbol: inputCurrency?.symbol }) | ||
: t('Swap')} | ||
</Button> | ||
) | ||
} |
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,42 @@ | ||
import { useCallback } from 'react' | ||
import { Currency, CurrencyAmount } from '@pancakeswap/ton-v2-sdk' | ||
import { useTradeExactIn } from './useTradeExactIn' | ||
import { useTradeExactOut } from './useTradeExactOut' | ||
|
||
export const useBestTrade = ({ | ||
isExactIn, | ||
amount, | ||
inputCurrency, | ||
outputCurrency, | ||
}: { | ||
isExactIn: boolean | ||
amount: CurrencyAmount<Currency> | undefined | ||
inputCurrency: Currency | undefined | ||
outputCurrency: Currency | undefined | ||
}) => { | ||
const { | ||
isLoading: isTradeExactInLoading, | ||
data: bestTradeExactIn, | ||
refresh: refreshTradeExactIn, | ||
} = useTradeExactIn(isExactIn ? amount : undefined, outputCurrency ?? undefined) | ||
|
||
const { | ||
isLoading: isTradeExactOutLoading, | ||
data: bestTradeExactOut, | ||
refresh: refreshTradeExactOut, | ||
} = useTradeExactOut(isExactIn ? undefined : amount, inputCurrency ?? undefined) | ||
|
||
const trade = isExactIn ? bestTradeExactIn : bestTradeExactOut | ||
|
||
const refreshTrade = useCallback(() => { | ||
refreshTradeExactIn() | ||
refreshTradeExactOut() | ||
}, [refreshTradeExactIn, refreshTradeExactOut]) | ||
|
||
return { | ||
isTradeExactInLoading, | ||
isTradeExactOutLoading, | ||
trade, | ||
refreshTrade, | ||
} | ||
} |
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
Oops, something went wrong.