Skip to content

Commit

Permalink
fix: increase min-width of nonce field
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Jul 11, 2023
1 parent db76669 commit 3821808
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/components/tx-flow/common/TxNonce/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ const NonceFormOption = memo(function NonceFormOption({
)
})

const getFieldMinWidth = (value: string, showRecommendedNonceButton?: boolean): string => {
const MIN_CHARS = 4
const MAX_WIDTH = '200px'

const extraWidth = `${showRecommendedNonceButton ? 32 : 8}px`

return `clamp(calc(${MIN_CHARS}ch + ${extraWidth}), calc(${Math.max(
MIN_CHARS,
value.length,
)}ch + ${extraWidth}), ${MAX_WIDTH})`
}

enum TxNonceFormFieldNames {
NONCE = 'nonce',
}
Expand Down Expand Up @@ -114,8 +126,6 @@ const TxNonceForm = ({ nonce, recommendedNonce }: { nonce: string; recommendedNo

const showRecommendedNonceButton = recommendedNonce !== field.value

const extraWidth = showRecommendedNonceButton ? 32 : 8

return (
<Autocomplete
value={field.value}
Expand Down Expand Up @@ -172,9 +182,7 @@ const TxNonceForm = ({ nonce, recommendedNonce }: { nonce: string; recommendedNo
},
])}
sx={{
minWidth: `clamp(calc(1ch + ${extraWidth}px), calc(${
field.value.toString().length
}ch + ${extraWidth}px), 200px)`,
minWidth: getFieldMinWidth(field.value, showRecommendedNonceButton),
}}
/>
</Tooltip>
Expand All @@ -188,6 +196,8 @@ const TxNonceForm = ({ nonce, recommendedNonce }: { nonce: string; recommendedNo
)
}

const skeletonMinWidth = getFieldMinWidth('')

const TxNonce = () => {
const { nonce, recommendedNonce } = useContext(SafeTxContext)

Expand All @@ -198,7 +208,7 @@ const TxNonce = () => {
#
</Typography>
{nonce === undefined || recommendedNonce === undefined ? (
<Skeleton width="70px" height="38px" />
<Skeleton width={skeletonMinWidth} height="38px" />
) : (
<TxNonceForm nonce={nonce.toString()} recommendedNonce={recommendedNonce.toString()} />
)}
Expand Down

0 comments on commit 3821808

Please sign in to comment.