-
Notifications
You must be signed in to change notification settings - Fork 5k
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: nonce increment/decrement functionality using arrow buttons #26569
Changes from 8 commits
8299329
965fbce
21a4e91
a93466b
05b1f86
b99a238
adcdc61
0b112a5
2698877
2e30805
8cbf8be
a9b1358
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,6 @@ import { | |
import UserPreferencedCurrencyDisplay from '../../../components/app/user-preferenced-currency-display'; | ||
|
||
import { PRIMARY, SECONDARY } from '../../../helpers/constants/common'; | ||
import TextField from '../../../components/ui/text-field'; | ||
import { MetaMetricsEventCategory } from '../../../../shared/constants/metametrics'; | ||
import { getMethodName } from '../../../helpers/utils/metrics'; | ||
import { | ||
|
@@ -42,7 +41,7 @@ import { | |
import { TransactionModalContextProvider } from '../../../contexts/transaction-modal'; | ||
import TransactionDetail from '../components/transaction-detail/transaction-detail.component'; | ||
import TransactionDetailItem from '../components/transaction-detail-item/transaction-detail-item.component'; | ||
import { Text } from '../../../components/component-library'; | ||
import { Text, TextField } from '../../../components/component-library'; | ||
import LoadingHeartBeat from '../../../components/ui/loading-heartbeat'; | ||
import LedgerInstructionField from '../components/ledger-instruction-field'; | ||
import { | ||
|
@@ -431,6 +430,19 @@ export default class ConfirmTransactionBase extends Component { | |
); | ||
}; | ||
|
||
const handleNonceChange = ({ target: { value } }) => { | ||
const inputValue = Number(value); | ||
|
||
if (inputValue < 0 || isNaN(inputValue)) { | ||
updateCustomNonce(''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be cleaner to set this to |
||
return; | ||
} | ||
|
||
updateCustomNonce(String(inputValue)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, no need to store it as a string, removed. |
||
|
||
getNextNonce(); | ||
}; | ||
|
||
const renderTotalMaxAmount = ({ | ||
useMaxFee, | ||
isBoldTextAndNotOverridden = false, | ||
|
@@ -496,6 +508,13 @@ export default class ConfirmTransactionBase extends Component { | |
: primaryTotalTextOverride; | ||
}; | ||
|
||
const nextNonceValue = | ||
typeof nextNonce === 'number' ? nextNonce.toString() : null; | ||
|
||
if (!customNonceValue && nextNonceValue) { | ||
updateCustomNonce(nextNonceValue); | ||
} | ||
|
||
const nonceField = | ||
useNonceField && !isSigningOrSubmitting ? ( | ||
<div> | ||
|
@@ -507,20 +526,11 @@ export default class ConfirmTransactionBase extends Component { | |
<TextField | ||
type="number" | ||
min={0} | ||
placeholder={ | ||
typeof nextNonce === 'number' ? nextNonce.toString() : null | ||
} | ||
onChange={({ target: { value } }) => { | ||
if (!value.length || Number(value) < 0) { | ||
updateCustomNonce(''); | ||
} else { | ||
updateCustomNonce(String(Math.floor(value))); | ||
} | ||
getNextNonce(); | ||
}} | ||
placeholder={nextNonceValue} | ||
onChange={handleNonceChange} | ||
fullWidth | ||
margin="dense" | ||
value={customNonceValue || ''} | ||
value={customNonceValue ?? ''} | ||
/> | ||
</div> | ||
</div> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, do we want a
useCallback
just in case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100% we need to use the
usaCallback
, but in this case, it is an old class component.