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

fix: increase min-width of nonce field #2270

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Changes from 1 commit
Commits
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
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
Loading