Skip to content

Commit

Permalink
fix: restore blocked selector when single token list
Browse files Browse the repository at this point in the history
  • Loading branch information
sraver committed Jul 4, 2023
1 parent ff6d262 commit 1cc21ea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/components/Swap/TokenInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const TokenInput = forwardRef<TokenInputHandle, PropsWithChildren<TokenIn
onSelect={onSelect}
chainIdsAllowed={chainIdsAllowed}
tokenList={tokenList}
hasPresetValue={tokenList.length === 1}
/>
<ThemedText.H2>
<ValueInput
Expand Down
19 changes: 15 additions & 4 deletions src/components/TokenSelect/TokenButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@ import { Currency } from '@uniswap/sdk-core'
import { getChainInfo } from 'constants/chainInfo'
import { getNativeLogoURI } from 'hooks/useCurrencyLogoURIs'
import { ChevronDown } from 'icons'
import styled from 'styled-components/macro'
import styled, { css } from 'styled-components/macro'
import { ThemedText } from 'theme'

import Button from '../Button'
import Row from '../Row'
import TokenImg, { ChainImgBadge, TokenGroup } from '../TokenImg'

const presetValueCss = css`
cursor: initial;
:hover:enabled {
background-color: ${({ theme }) => theme['interactive']};
}
`

const StyledTokenButton = styled(Button)<{ approved?: boolean; presetValue?: boolean }>`
border-radius: ${({ theme }) => theme.borderRadius.medium}em;
min-height: 2em;
padding: 0.25em 0.5em 0.25em 0.25em;
${({ presetValue }) => presetValue && presetValueCss};
:enabled {
transition: none;
}
Expand Down Expand Up @@ -54,19 +63,21 @@ interface TokenButtonProps {
approved?: boolean
disabled?: boolean
onClick: () => void
hasPresetValue?: boolean
}

export default function TokenButton({ value, approved, disabled, onClick }: TokenButtonProps) {
export default function TokenButton({ value, approved, disabled, onClick, hasPresetValue }: TokenButtonProps) {
const chainInfo = getChainInfo(value?.chainId)
const chainSrc = getNativeLogoURI(value?.chainId)

return (
<StyledTokenButton
onClick={onClick}
onClick={hasPresetValue ? undefined : onClick}
color={value ? 'interactive' : 'accent'}
approved={approved}
disabled={disabled}
data-testid="token-select"
presetValue={hasPresetValue}
>
<TokenButtonRow empty={!value} flex gap={0.4}>
{value ? (
Expand All @@ -85,7 +96,7 @@ export default function TokenButton({ value, approved, disabled, onClick }: Toke
<Trans>Select token</Trans>
</ThemedText.ButtonLarge>
)}
<DropDownIcon strokeWidth={2} color={value ? 'primary' : 'onAccent'} />
{!hasPresetValue && <DropDownIcon strokeWidth={2} color={value ? 'primary' : 'onAccent'} />}
</TokenButtonRow>
</StyledTokenButton>
)
Expand Down
10 changes: 9 additions & 1 deletion src/components/TokenSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ interface TokenSelectProps {
onSelect: (value: Currency) => void
chainIdsAllowed: number[]
tokenList: TokenListItem[]
hasPresetValue?: boolean
}

export default memo(function TokenSelect({
Expand All @@ -174,6 +175,7 @@ export default memo(function TokenSelect({
onSelect,
chainIdsAllowed,
tokenList,
hasPresetValue,
}: TokenSelectProps) {
usePrefetchBalances()

Expand All @@ -191,7 +193,13 @@ export default memo(function TokenSelect({
)
return (
<>
<TokenButton value={value} approved={approved} disabled={disabled} onClick={onOpen} />
<TokenButton
value={value}
approved={approved}
disabled={disabled}
onClick={onOpen}
hasPresetValue={hasPresetValue}
/>
{open && (
<TokenSelectDialog
value={value}
Expand Down

1 comment on commit 1cc21ea

@vercel
Copy link

@vercel vercel bot commented on 1cc21ea Jul 4, 2023

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:

wido-widget – ./

wido-widget.vercel.app
wido-widget-wido.vercel.app
wido-widget-git-main-wido.vercel.app

Please sign in to comment.