Skip to content

Commit

Permalink
fix: custom receive address overlay on long addies (#8284)
Browse files Browse the repository at this point in the history
* fix: custom receive address overlay on long addies

* fix: textinputarea size and auto shrink text on longer size

* fix: make textarea a teeny tiny bit smaller for regular sends

* feat: teeny tiny bicicleta bit smaller fontSize for <= 42 chars in
shared component

* feat: mobile improvements

---------

Co-authored-by: NeOMakinG <[email protected]>
  • Loading branch information
gomesalexandre and NeOMakinG authored Dec 8, 2024
1 parent 4951e9c commit e9f4855
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/components/Modals/Send/AddressInput/AddressInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { SpaceProps } from '@chakra-ui/react'
import { IconButton, Input, InputGroup, InputRightElement } from '@chakra-ui/react'
import { useCallback } from 'react'
import { isMobile } from 'react-device-detect'
import type { ControllerProps, ControllerRenderProps, FieldValues } from 'react-hook-form'
import { Controller, useFormContext } from 'react-hook-form'
import { useTranslate } from 'react-polyglot'
Expand All @@ -13,11 +15,17 @@ type AddressInputProps = {
rules: ControllerProps['rules']
enableQr?: boolean
placeholder?: string
pe?: SpaceProps['pe']
}

const qrCodeIcon = <QRCodeIcon />

export const AddressInput = ({ rules, placeholder, enableQr = false }: AddressInputProps) => {
export const AddressInput = ({
rules,
placeholder,
enableQr = false,
pe = 10,
}: AddressInputProps) => {
const history = useHistory()
const translate = useTranslate()
const isValid = useFormContext<SendInput>().formState.isValid
Expand All @@ -43,11 +51,24 @@ export const AddressInput = ({ rules, placeholder, enableQr = false }: AddressIn
data-test='send-address-input'
data-1p-ignore
// Because the InputRightElement is hover the input, we need to let this space free
pe={10}
pe={pe}
isInvalid={!isValid}
// This is already a `useCallback()`
// eslint-disable-next-line react-memo/require-usememo
sx={
isMobile
? {
fontSize: value && value.length > 42 ? '9.8px' : '11px',
transition: 'font-size 0.2s ease-in-out',
}
: {
fontSize: value && value.length > 42 ? '12px' : '13.5px',
transition: 'font-size 0.2s ease-in-out',
}
}
/>
),
[isValid, placeholder],
[isValid, pe, placeholder],
)

return (
Expand Down
2 changes: 2 additions & 0 deletions src/components/Modals/Send/views/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Button, FormControl, FormLabel, Stack } from '@chakra-ui/react'
import { ethChainId } from '@shapeshiftoss/caip'
import get from 'lodash/get'
import { useCallback, useEffect, useMemo, useState } from 'react'
import { isMobile } from 'react-device-detect'
import { useFormContext, useWatch } from 'react-hook-form'
import { useTranslate } from 'react-polyglot'
import { useHistory } from 'react-router-dom'
Expand Down Expand Up @@ -108,6 +109,7 @@ export const Address = () => {
{translate('modals.send.sendForm.sendTo')}
</FormLabel>
<AddressInput
pe={isMobile ? 12 : 9.5}
rules={addressInputRules}
enableQr={true}
placeholder={translate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const editIcon = <EditIcon />
const checkIcon = <CheckIcon />
const closeIcon = <CloseIcon />

const iconButtonHoverSx = { bg: 'gray.600' }

type ManualRecipientAddressLabelsProps = {
buyAsset: Asset
manualAddressEntryDescription: string | undefined
Expand Down Expand Up @@ -266,6 +268,7 @@ export const SharedRecipientAddress = ({
<AddressInput
rules={rules}
placeholder={translate('trade.enterCustomRecipientAddress')}
pe={16}
/>
<InputRightElement
width='full'
Expand All @@ -286,6 +289,9 @@ export const SharedRecipientAddress = ({
onClick={handleFormSubmit}
icon={checkIcon}
isLoading={isValidating}
borderRadius='full'
bg='gray.700'
_hover={iconButtonHoverSx}
/>
<IconButton
pointerEvents='auto'
Expand All @@ -295,6 +301,9 @@ export const SharedRecipientAddress = ({
size='xs'
onClick={handleCancelClick}
isDisabled={isValidating}
borderRadius='full'
bg='gray.700'
_hover={iconButtonHoverSx}
/>
</InputRightElement>
</InputGroup>
Expand Down

0 comments on commit e9f4855

Please sign in to comment.