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(limit-orders): redesign limit orders #5249

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
c427196
feat: modify layout
fairlighteth Dec 4, 2024
886c451
feat: add limit price usd price toggle
fairlighteth Dec 4, 2024
3c522cc
feat: add settings limit price position
fairlighteth Dec 4, 2024
51f9267
feat: toggle usd input skew style
fairlighteth Dec 5, 2024
745d0ae
feat: toggle usd input skew style
fairlighteth Dec 5, 2024
fcee643
feat: update limit order input layouti
fairlighteth Dec 5, 2024
feb5262
feat: style rate input and switch
fairlighteth Dec 5, 2024
09a817b
feat: add estimated fill price
fairlighteth Dec 5, 2024
369cf28
feat: add estimated fill price
fairlighteth Dec 5, 2024
d57f2d6
feat: add estimated fill price
fairlighteth Dec 5, 2024
f8c7c2a
feat: style limit settings menu
fairlighteth Dec 5, 2024
7364354
feat: add USD settings button
fairlighteth Dec 5, 2024
8ac8c99
feat: toggle token on click
fairlighteth Dec 6, 2024
6ea2c04
feat: add lock and unlock for limit price
fairlighteth Dec 6, 2024
b57aaca
feat: rate input tooltip styling
fairlighteth Dec 6, 2024
710f396
feat: update orders table layout
fairlighteth Dec 6, 2024
f21e9f4
feat: update orders table layout
fairlighteth Dec 6, 2024
02ab679
feat: modify search
fairlighteth Dec 6, 2024
2bc1428
feat: refactor table layout
fairlighteth Dec 9, 2024
6fb90d1
feat: add cosmos
fairlighteth Dec 9, 2024
5414db9
feat: modify open orders columns
fairlighteth Dec 9, 2024
3cb263a
feat: add columns order history
fairlighteth Dec 9, 2024
50ed049
fix: lint fixes
fairlighteth Dec 9, 2024
cacdfca
fix: add new tabs and proper filtering
fairlighteth Dec 9, 2024
d0f80ec
fix: remove debug
fairlighteth Dec 9, 2024
08648ee
feat: move tooltips
fairlighteth Dec 9, 2024
4b98d5d
feat: refactor table layout
fairlighteth Dec 10, 2024
73486b5
feat: add pending execution logic
fairlighteth Dec 10, 2024
3184856
feat: remove prop cosmos
fairlighteth Dec 10, 2024
385d6f1
feat: improve search
fairlighteth Dec 10, 2024
1282764
feat: row height change
fairlighteth Dec 10, 2024
080f1f0
feat: fix statusbox warning position
fairlighteth Dec 10, 2024
86a4b19
feat: style filled progressbar
fairlighteth Dec 10, 2024
9c33683
feat: add limit price to order history
fairlighteth Dec 10, 2024
46955a3
feat: correct execute soon tooltip
fairlighteth Dec 10, 2024
3c87f04
feat: order table layout and warning indicator styling
fairlighteth Dec 10, 2024
0657687
feat: modify table layout
fairlighteth Dec 10, 2024
544da0c
feat: improve token search
fairlighteth Dec 10, 2024
ceea64f
feat: restore table layout element
fairlighteth Dec 10, 2024
c6095e1
feat: add column layout options in settings
fairlighteth Dec 11, 2024
9ad73d5
feat: add enum for layout and lint fix
fairlighteth Dec 12, 2024
00ca9d9
feat: remove callback
fairlighteth Dec 12, 2024
5a3a0b9
feat: restyle limit order settings
fairlighteth Dec 12, 2024
94d24c1
feat: use same settings style for TWAP
fairlighteth Dec 12, 2024
7d4bca6
feat: position settings menu
fairlighteth Dec 12, 2024
b48173d
feat: fix lint issue
fairlighteth Dec 12, 2024
3902d26
feat: by default open all orders tab
fairlighteth Dec 12, 2024
955699f
feat: style table search for dark mode
fairlighteth Dec 12, 2024
310a56c
feat: progress bar width adust
fairlighteth Dec 12, 2024
1305eb4
feat: left aligned orders table settings
fairlighteth Dec 12, 2024
494f651
feat: orders table position setting
fairlighteth Dec 12, 2024
782aa32
feat: shared left aligned orders setting limit and TWAP
fairlighteth Dec 12, 2024
0d92de2
feat: shared limit and twap settings
fairlighteth Dec 12, 2024
cc705f3
feat: fix lint issue
fairlighteth Dec 12, 2024
b7a0aa7
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Dec 22, 2024
f0c9992
feat(limit-orders): bind rate USD value logic
shoom3301 Dec 22, 2024
d6c4e53
chore: simplify code
shoom3301 Dec 22, 2024
d8fc1fd
feat(limit-orders): display execution price in USD
shoom3301 Dec 22, 2024
596cb83
feat(limit-orders): add usd input mode for currency input
shoom3301 Dec 22, 2024
52c3368
chore: fix build
shoom3301 Dec 22, 2024
df4d446
fix: set USDC as a default buy token
shoom3301 Dec 22, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { TokenWithLogo, USDC } from '@cowprotocol/common-const'
import { getWrappedToken, tryParseCurrencyAmount } from '@cowprotocol/common-utils'
import { SupportedChainId } from '@cowprotocol/cow-sdk'
import { Currency, CurrencyAmount } from '@uniswap/sdk-core'

import { useUsdPrice } from 'modules/usdAmount'

export function useConvertUsdToTokenValue(
currency: Currency | null,
): (typedValue: string, isUsdMode: boolean) => string {
const currencyUsdcPrice = useUsdPrice(currency ? getWrappedToken(currency) : null)

return (typedValue: string, isUsdMode: boolean) => {
if (isUsdMode && currencyUsdcPrice?.price) {
const usdcToken = USDC[currencyUsdcPrice.currency.chainId as SupportedChainId]
const usdAmount = tryParseCurrencyAmount(typedValue, usdcToken)

const tokenAmount = currencyUsdcPrice.price.invert().quote(hackyAdjustAmountDust(usdAmount))

return tokenAmount.toExact()
}

return typedValue
}
}

/**
* TODO: this is a hacky way to adjust the amount to avoid dust
* For some reason, when you enter for example $366, price.quote() returns 365,9999999999
*/
function hackyAdjustAmountDust(amount: CurrencyAmount<TokenWithLogo>): typeof amount {
return amount.add(tryParseCurrencyAmount('0.000001', amount.currency))
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ import { SupportedChainId } from '@cowprotocol/cow-sdk'
import { TokenAmount, HoverTooltip } from '@cowprotocol/ui'
import { Currency, CurrencyAmount } from '@uniswap/sdk-core'

import { Trans } from '@lingui/macro'

import { BalanceAndSubsidy } from 'legacy/hooks/useCowBalanceAndSubsidy'
import { PriceImpact } from 'legacy/hooks/usePriceImpact'
import { Field } from 'legacy/state/types'

import { setMaxSellTokensAnalytics } from 'modules/analytics'
import { ReceiveAmount } from 'modules/swap/pure/ReceiveAmount'
import { useUsdAmount } from 'modules/usdAmount'

import { CurrencyInfo } from 'common/pure/CurrencyInputPanel/types'
import { CurrencySelectButton } from 'common/pure/CurrencySelectButton'
import { FiatValue } from 'common/pure/FiatValue'

import * as styledEl from './styled'

import { useConvertUsdToTokenValue } from '../../hooks/useConvertUsdToTokenValue'

interface BuiltItProps {
className: string
}
Expand Down Expand Up @@ -84,26 +85,47 @@ export function CurrencyInputPanel(props: CurrencyInputPanelProps) {
customSelectTokenButton,
} = props

const { field, currency, balance, fiatAmount, amount, isIndependent, receiveAmountInfo } = currencyInfo
const {
field,
currency,
balance,
fiatAmount,
amount,
isIndependent,
receiveAmountInfo,
isUsdValuesMode = false,
} = currencyInfo
const disabled = !!props.disabled || isChainIdUnsupported
const viewAmount = formatInputAmount(amount, balance, isIndependent)

const { value: usdAmount } = useUsdAmount(amount)
const { value: maxBalanceUsdAmount } = useUsdAmount(maxBalance)
const { value: balanceUsdAmount } = useUsdAmount(balance)
const viewAmount = isUsdValuesMode ? formatInputAmount(usdAmount) : formatInputAmount(amount, balance, isIndependent)
const [typedValue, setTypedValue] = useState(viewAmount)

const convertUsdToTokenValue = useConvertUsdToTokenValue(currency)

const onUserInputDispatch = useCallback(
(typedValue: string) => {
setTypedValue(typedValue)
onUserInput(field, typedValue)
const value = convertUsdToTokenValue(typedValue, isUsdValuesMode)

setTypedValue(value)
onUserInput(field, value)
},
[onUserInput, field],
[onUserInput, field, viewAmount, convertUsdToTokenValue, isUsdValuesMode],
)
const handleMaxInput = useCallback(() => {
if (!maxBalance) {
return
}

onUserInputDispatch(maxBalance.toExact())
setMaxSellTokensAnalytics()
}, [maxBalance, onUserInputDispatch])
const value = isUsdValuesMode ? maxBalanceUsdAmount : maxBalance

if (value) {
onUserInputDispatch(value.toExact())
setMaxSellTokensAnalytics()
}
}, [maxBalance, onUserInputDispatch, convertUsdToTokenValue, isUsdValuesMode, maxBalanceUsdAmount])

useEffect(() => {
const areValuesSame = parseFloat(viewAmount) === parseFloat(typedValue)
Expand All @@ -128,13 +150,31 @@ export function CurrencyInputPanel(props: CurrencyInputPanelProps) {
const numericalInput = (
<styledEl.NumericalInput
className="token-amount-input"
value={isChainIdUnsupported ? '' : typedValue}
prependSymbol={isUsdValuesMode ? '$' : ''}
value={isChainIdUnsupported ? '' : isUsdValuesMode ? viewAmount : typedValue}
readOnly={inputDisabled}
onUserInput={onUserInputDispatch}
$loading={areCurrenciesLoading}
/>
)

const balanceView = (
<div>
{balance && !disabled && (
<styledEl.BalanceText>
{isUsdValuesMode ? (
<FiatValue fiatValue={balanceUsdAmount} />
) : (
<TokenAmount amount={balance} defaultValue="0" tokenSymbol={currency} />
)}
{showSetMax && balance.greaterThan(0) && (
<styledEl.SetMaxBtn onClick={handleMaxInput}>Max</styledEl.SetMaxBtn>
)}
</styledEl.BalanceText>
)}
</div>
)

const priceImpactParams: typeof _priceImpactParams = useMemo(() => {
if (!_priceImpactParams) return undefined

Expand All @@ -159,10 +199,28 @@ export function CurrencyInputPanel(props: CurrencyInputPanelProps) {
pointerDisabled={disabled}
readOnly={inputDisabled}
>
{topLabel && <styledEl.CurrencyTopLabel>{topLabel}</styledEl.CurrencyTopLabel>}
<styledEl.TopRow>
{topLabel && (
<styledEl.CurrencyTopLabel>
{topLabel}{' '}
{isUsdValuesMode ? <TokenAmount amount={amount} defaultValue="0" tokenSymbol={currency} /> : ''}
</styledEl.CurrencyTopLabel>
)}

{isUsdValuesMode && balanceView}
</styledEl.TopRow>

{topContent}
<styledEl.CurrencyInputBox>
<div>
{inputTooltip ? (
<HoverTooltip wrapInContainer content={inputTooltip}>
{numericalInput}
</HoverTooltip>
) : (
numericalInput
)}
</div>
<div>
<CurrencySelectButton
onClick={onTokenSelectClick}
Expand All @@ -173,35 +231,17 @@ export function CurrencyInputPanel(props: CurrencyInputPanelProps) {
customSelectTokenButton={customSelectTokenButton}
/>
</div>
<div>
{inputTooltip ? (
<HoverTooltip wrapInContainer content={inputTooltip}>
{numericalInput}
</HoverTooltip>
) : (
numericalInput
)}
</div>
</styledEl.CurrencyInputBox>

<styledEl.CurrencyInputBox>
<div>
{balance && !disabled && (
<styledEl.BalanceText>
<Trans>Balance</Trans>: <TokenAmount amount={balance} defaultValue="0" tokenSymbol={currency} />
{showSetMax && balance.greaterThan(0) && (
<styledEl.SetMaxBtn onClick={handleMaxInput}>Max</styledEl.SetMaxBtn>
)}
</styledEl.BalanceText>
)}
</div>
<div>
{amount && (
{amount && !isUsdValuesMode && (
<styledEl.FiatAmountText>
<FiatValue priceImpactParams={priceImpactParams} fiatValue={fiatAmount} />
</styledEl.FiatAmountText>
)}
</div>
{!isUsdValuesMode && balanceView}
</styledEl.CurrencyInputBox>
</styledEl.Wrapper>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ export const CurrencyTopLabel = styled.div`
}
`

export const TopRow = styled.div`
display: flex;
flex-flow: row wrap;
align-items: center;
justify-content: space-between;
gap: 16px;
width: 100%;
`

export const NumericalInput = styled(Input)<{ $loading: boolean }>`
width: 100%;
height: 100%;
Expand All @@ -81,6 +90,7 @@ export const NumericalInput = styled(Input)<{ $loading: boolean }>`
font-size: 28px;
font-weight: 500;
color: inherit;
text-align: left;

&::placeholder {
opacity: 0.7;
Expand All @@ -106,7 +116,7 @@ export const TokenAmountStyled = styled(TokenAmount)`

export const BalanceText = styled.span`
font-weight: inherit;
font-size: inherit;
font-size: 13px;
gap: 5px;
display: flex;
align-items: center;
Expand Down Expand Up @@ -150,7 +160,9 @@ export const SetMaxBtn = styled.button`
border-radius: 6px;
padding: 3px 4px;
text-transform: uppercase;
transition: background var(${UI.ANIMATION_DURATION}) ease-in-out, color var(${UI.ANIMATION_DURATION}) ease-in-out;
transition:
background var(${UI.ANIMATION_DURATION}) ease-in-out,
color var(${UI.ANIMATION_DURATION}) ease-in-out;

&:hover {
background: var(${UI.COLOR_PRIMARY});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export interface CurrencyInfo {
balance: CurrencyAmount<Currency> | null
fiatAmount: CurrencyAmount<Currency> | null
topContent?: ReactNode
isUsdValuesMode?: boolean
}

This file was deleted.

This file was deleted.

Loading
Loading