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: replacement nonce dropdown style #2318

Merged
merged 3 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
50 changes: 39 additions & 11 deletions src/components/tx-flow/common/TxNonce/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
type MenuItemProps,
MenuItem,
Typography,
ListSubheader,
type ListSubheaderProps,
} from '@mui/material'
import { Controller, useForm } from 'react-hook-form'

Expand All @@ -28,10 +30,25 @@ import { isRejectionTx } from '@/utils/transactions'
import css from './styles.module.css'
import classNames from 'classnames'

const CustomPopper = function (props: PopperProps) {
return <Popper {...props} sx={{ width: '300px !important' }} placement="bottom-start" />
const CustomPopper = function ({
// Don't set width of Popper to that of the field
style: _,
className,
...props
}: PopperProps) {
return <Popper {...props} className={classNames(className, css.popper)} placement="bottom-start" />
}

const NonceFormHeader = memo(function NonceFormSubheader({ children, ...props }: ListSubheaderProps) {
return (
<ListSubheader {...props} disableSticky>
<Typography variant="caption" fontWeight={700} color="text.secondary">
{children}
</Typography>
</ListSubheader>
)
})

const NonceFormOption = memo(function NonceFormOption({
nonce,
menuItemProps,
Expand All @@ -43,13 +60,21 @@ const NonceFormOption = memo(function NonceFormOption({
const transactions = useQueuedTxByNonce(Number(nonce))

const label = useMemo(() => {
const [{ transaction }] = getLatestTransactions(transactions)
const latestTransactions = getLatestTransactions(transactions)

if (latestTransactions.length === 0) {
return
}

const [{ transaction }] = latestTransactions
return getTransactionType(transaction, addressBook).text
}, [addressBook, transactions])

return (
<MenuItem {...menuItemProps}>
{nonce} ({label} transaction)
<Typography variant="body2">
<b>{nonce}</b>&nbsp;- {`${label || 'New'} transaction`}
</Typography>
</MenuItem>
)
})
Expand Down Expand Up @@ -113,7 +138,7 @@ const TxNonceForm = ({ nonce, recommendedNonce }: { nonce: string; recommendedNo
render={({ field, fieldState }) => {
if (readOnly) {
return (
<Typography fontWeight={700} ml={-1}>
<Typography variant="body2" fontWeight={700} ml={-1}>
{nonce}
</Typography>
)
Expand All @@ -137,12 +162,15 @@ const TxNonceForm = ({ nonce, recommendedNonce }: { nonce: string; recommendedNo
options={[recommendedNonce, ...previousNonces]}
getOptionLabel={(option) => option.toString()}
renderOption={(props, option) => {
return option === recommendedNonce ? (
<MenuItem key={option} {...props}>
{option} (recommended nonce)
</MenuItem>
) : (
<NonceFormOption key={option} menuItemProps={props} nonce={option} />
const isRecommendedNonce = option === recommendedNonce
const isInitialPreviousNonce = option === previousNonces[0]

return (
<>
{isRecommendedNonce && <NonceFormHeader>Recommended nonce</NonceFormHeader>}
{isInitialPreviousNonce && <NonceFormHeader sx={{ pt: 3 }}>Already in queue</NonceFormHeader>}
<NonceFormOption key={option} menuItemProps={props} nonce={option} />
</>
)
}}
disableClearable
Expand Down
22 changes: 22 additions & 0 deletions src/components/tx-flow/common/TxNonce/styles.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
.popper :global .MuiAutocomplete-paper {
margin-top: calc(var(--space-1) / 2);
padding-top: var(--space-1);
padding-bottom: var(--space-1);
border: 1px solid var(--color-border-light);
}

.popper :global .MuiAutocomplete-listbox {
max-height: unset;
}

.popper :global .MuiListSubheader-root {
line-height: 22px;
margin-bottom: var(--space-1);
}

.popper :global .MuiAutocomplete-option,
.popper :global .MuiListSubheader-root {
padding-left: var(--space-3);
padding-right: var(--space-3);
}

.input :global .MuiOutlinedInput-root {
padding: 0;
}
Expand Down
Loading