-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add hover states * don't change input opacity * disable hover when InputColumn is disabled * feat: consolidate Input/Output component (#255) * fix: disable hover states with no currency * feat: consolidate SwapInput * fix: use exact amount for wrap * fix: simplify InputWrapper Co-authored-by: Connor McEwen <connor.mcewen@gmail.com> * readability Co-authored-by: Zach Pomerantz <zzmp@uniswap.org>
- Loading branch information
Showing
4 changed files
with
119 additions
and
140 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,44 @@ | ||
import { useIsSwapFieldIndependent, useSwapAmount, useSwapCurrency, useSwapInfo } from 'hooks/swap' | ||
import { useSwapCurrency, useSwapInfo } from 'hooks/swap' | ||
import useCurrencyColor from 'hooks/useCurrencyColor' | ||
import { atom } from 'jotai' | ||
import { useAtomValue } from 'jotai/utils' | ||
import { TradeState } from 'state/routing/types' | ||
import { Field } from 'state/swap' | ||
import styled from 'styled-components/macro' | ||
import { DynamicThemeProvider, ThemedText } from 'theme' | ||
import { formatCurrencyAmount } from 'utils/formatCurrencyAmount' | ||
import { DynamicThemeProvider } from 'theme' | ||
|
||
import Row from '../Row' | ||
import { Balance, InputColumn, USDC, useFormattedFieldAmount } from './Input' | ||
import TokenInput from './TokenInput' | ||
import { InputWrapper } from './Input' | ||
|
||
export const colorAtom = atom<string | undefined>(undefined) | ||
|
||
const StyledInputColumn = styled(InputColumn)` | ||
const OutputWrapper = styled(InputWrapper)<{ hasColor?: boolean | null }>` | ||
border-bottom: 1px solid ${({ theme }) => theme.container}; | ||
border-bottom-left-radius: 0; | ||
border-bottom-right-radius: 0; | ||
margin-bottom: 0; | ||
padding: 24px 0 20px 0; | ||
// Set transitions to reduce color flashes when switching color/token. | ||
// When color loads, transition the background so that it transitions from the empty or last state, but not _to_ the empty state. | ||
transition: ${({ hasColor }) => (hasColor ? 'background-color 0.25s ease-out' : undefined)}; | ||
> { | ||
// When color is loading, delay the color/stroke so that it seems to transition from the last state. | ||
transition: ${({ hasColor }) => (hasColor === null ? 'color 0.25s ease-in, stroke 0.25s ease-in' : undefined)}; | ||
} | ||
` | ||
|
||
export default function Output() { | ||
const { | ||
[Field.OUTPUT]: { balance, amount: outputCurrencyAmount, usdc: outputUSDC }, | ||
error, | ||
trade: { state: tradeState }, | ||
impact, | ||
} = useSwapInfo() | ||
|
||
const [swapOutputAmount, updateSwapOutputAmount] = useSwapAmount(Field.OUTPUT) | ||
const [swapOutputCurrency, updateSwapOutputCurrency] = useSwapCurrency(Field.OUTPUT) | ||
|
||
const isDisabled = error !== undefined | ||
const isRouteLoading = isDisabled || tradeState === TradeState.LOADING | ||
const isDependentField = !useIsSwapFieldIndependent(Field.OUTPUT) | ||
const isLoading = isRouteLoading && isDependentField | ||
const { impact } = useSwapInfo() | ||
|
||
const [currency] = useSwapCurrency(Field.OUTPUT) | ||
const overrideColor = useAtomValue(colorAtom) | ||
const dynamicColor = useCurrencyColor(swapOutputCurrency) | ||
const dynamicColor = useCurrencyColor(currency) | ||
const color = overrideColor || dynamicColor | ||
|
||
// different state true/null/false allow smoother color transition | ||
const hasColor = swapOutputCurrency ? Boolean(color) || null : false | ||
|
||
const amount = useFormattedFieldAmount({ | ||
currencyAmount: outputCurrencyAmount, | ||
fieldAmount: swapOutputAmount, | ||
}) | ||
const hasColor = currency ? Boolean(color) || null : false | ||
|
||
return ( | ||
<DynamicThemeProvider color={color}> | ||
<StyledInputColumn hasColor={hasColor} gap={0.5}> | ||
<TokenInput | ||
amount={amount} | ||
currency={swapOutputCurrency} | ||
disabled={isDisabled} | ||
field={Field.OUTPUT} | ||
onChangeInput={updateSwapOutputAmount} | ||
onChangeCurrency={updateSwapOutputCurrency} | ||
loading={isLoading} | ||
> | ||
<ThemedText.Body2 color="secondary" userSelect> | ||
<Row> | ||
<USDC gap={0.5} isLoading={isRouteLoading}> | ||
{outputUSDC && `${formatCurrencyAmount({ amount: outputUSDC, isUsdPrice: true })} `} | ||
{impact && <ThemedText.Body2 color={impact.warning}>({impact.toString()})</ThemedText.Body2>} | ||
</USDC> | ||
{balance && ( | ||
<Balance color="secondary"> | ||
Balance: <span>{formatCurrencyAmount({ amount: balance })}</span> | ||
</Balance> | ||
)} | ||
</Row> | ||
</ThemedText.Body2> | ||
</TokenInput> | ||
</StyledInputColumn> | ||
<OutputWrapper field={Field.OUTPUT} impact={impact} hasColor={hasColor} /> | ||
</DynamicThemeProvider> | ||
) | ||
} |
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
3acf651
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 the following URLs:
widgets – ./
widgets-uniswap.vercel.app
widgets-seven-tau.vercel.app
widgets-git-main-uniswap.vercel.app