-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: mv Toolbar to a directory * refactor: clean up Toolbar * refactor: simplify Toolbar Caption * feat: warn on price impact in Summary * refactor: add computeRealizedPriceImpact util
- Loading branch information
Showing
7 changed files
with
195 additions
and
184 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { Trans } from '@lingui/macro' | ||
import { Currency, TradeType } from '@uniswap/sdk-core' | ||
import useUSDCPrice from 'hooks/useUSDCPrice' | ||
import { AlertTriangle, Icon, Info, Spinner } from 'lib/icons' | ||
import { ThemedText } from 'lib/theme' | ||
import { ReactNode, useMemo, useState } from 'react' | ||
import { InterfaceTrade } from 'state/routing/types' | ||
|
||
import { TextButton } from '../../Button' | ||
import Row from '../../Row' | ||
import RoutingTooltip from './RoutingTooltip' | ||
|
||
interface CaptionProps { | ||
icon?: Icon | ||
caption: ReactNode | ||
} | ||
|
||
function Caption({ icon: Icon = AlertTriangle, caption }: CaptionProps) { | ||
return ( | ||
<> | ||
<Icon color="secondary" /> | ||
{caption} | ||
</> | ||
) | ||
} | ||
|
||
export function ConnectWallet() { | ||
return <Caption caption={<Trans>Connect wallet to swap</Trans>} /> | ||
} | ||
export function UnsupportedNetwork() { | ||
return <Caption caption={<Trans>Unsupported network - switch to another network to swap</Trans>} /> | ||
} | ||
export function InsufficientBalance({ currency }: { currency: Currency }) { | ||
return <Caption caption={<Trans>Insufficient {currency?.symbol} balance</Trans>} /> | ||
} | ||
export function InsufficientLiquidity() { | ||
return <Caption caption={<Trans>Insufficient liquidity in the pool for your trade</Trans>} /> | ||
} | ||
export function Empty() { | ||
return <Caption icon={Info} caption={<Trans>Enter an amount</Trans>} /> | ||
} | ||
export function LoadingTrade() { | ||
return <Caption icon={Spinner} caption={<Trans>Fetching best price…</Trans>} /> | ||
} | ||
|
||
export function Trade({ trade }: { trade: InterfaceTrade<Currency, Currency, TradeType> }) { | ||
const [flip, setFlip] = useState(true) | ||
const { inputAmount, outputAmount, executionPrice } = trade | ||
const fiatValueInput = useUSDCPrice(inputAmount.currency) | ||
const fiatValueOutput = useUSDCPrice(outputAmount.currency) | ||
|
||
const ratio = useMemo(() => { | ||
const [a, b] = flip ? [outputAmount, inputAmount] : [inputAmount, outputAmount] | ||
const priceString = (!flip ? executionPrice : executionPrice?.invert())?.toSignificant(6) | ||
|
||
const ratio = `1 ${a.currency.symbol} = ${priceString}} ${b.currency.symbol}` | ||
const usdc = !flip | ||
? fiatValueInput | ||
? ` ($${fiatValueInput.toSignificant(2)})` | ||
: null | ||
: fiatValueOutput | ||
? ` ($${fiatValueOutput.toSignificant(2)})` | ||
: null | ||
|
||
return ( | ||
<Row gap={0.25} style={{ userSelect: 'text' }}> | ||
{ratio} | ||
{usdc && <ThemedText.Caption color="secondary">{usdc}</ThemedText.Caption>} | ||
</Row> | ||
) | ||
}, [executionPrice, fiatValueInput, fiatValueOutput, flip, inputAmount, outputAmount]) | ||
|
||
return ( | ||
<> | ||
<RoutingTooltip /> | ||
<TextButton color="primary" onClick={() => setFlip(!flip)}> | ||
{ratio} | ||
</TextButton> | ||
</> | ||
) | ||
} |
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,14 @@ | ||
import { Info } from 'lib/icons' | ||
|
||
export default function RoutingTooltip() { | ||
return <Info color="secondary" /> | ||
/* TODO(zzmp): Implement post-beta launch. | ||
return ( | ||
<Tooltip icon={Info} placement="bottom"> | ||
<ThemeProvider> | ||
<ThemedText.Subhead2>TODO: Routing Tooltip</ThemedText.Subhead2> | ||
</ThemeProvider> | ||
</Tooltip> | ||
) | ||
*/ | ||
} |
Oops, something went wrong.