1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 02:10:12 +01:00

Use optional chaining for functions (#9799)

This commit is contained in:
David Walsh 2020-11-12 11:13:21 -06:00 committed by GitHub
commit 9df5be903b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 19 additions and 22 deletions

View File

@ -16,7 +16,7 @@ export default function AccountListItem({
return (
<div
className={`account-list-item ${className}`}
onClick={() => handleClick && handleClick({ name, address, balance })}
onClick={() => handleClick?.({ name, address, balance })}
>
<div className="account-list-item__top-row">
<Identicon

View File

@ -26,7 +26,7 @@ const ConfirmDetailRow = (props) => {
'confirm-detail-row__header-text',
headerTextClassName,
)}
onClick={() => onHeaderClick && onHeaderClick()}
onClick={() => onHeaderClick?.()}
>
{headerText}
</div>

View File

@ -37,7 +37,7 @@ export default class AccountDetailsModal extends Component {
let exportPrivateKeyFeatureEnabled = true
// This feature is disabled for hardware wallets
if (keyring && keyring.type.search('Hardware') !== -1) {
if (keyring?.type?.search('Hardware') !== -1) {
exportPrivateKeyFeatureEnabled = false
}

View File

@ -21,7 +21,7 @@ export default class Sidebar extends Component {
<div
className="sidebar-overlay"
onClick={() => {
onOverlayClose && onOverlayClose()
onOverlayClose?.()
this.props.hideSidebar()
}}
/>

View File

@ -63,7 +63,7 @@ export default class ButtonGroup extends PureComponent {
)}
onClick={() => {
this.handleButtonClick(index)
child.props.onClick && child.props.onClick()
child.props.onClick?.()
}}
disabled={disabled || child.props.disabled}
key={index}

View File

@ -468,9 +468,7 @@ describe('Confirm Transaction Duck', function () {
getCode: sinon
.stub()
.callsFake((address) =>
Promise.resolve(
address && address.match(/isContract/u) ? 'not-0x' : '0x',
),
Promise.resolve(address?.match(/isContract/u) ? 'not-0x' : '0x'),
),
}
})

View File

@ -36,7 +36,7 @@ async function getDecimalsFromContract(tokenAddress) {
try {
const result = await token.decimals()
const decimalsBN = result[0]
return decimalsBN && decimalsBN.toString()
return decimalsBN?.toString()
} catch (error) {
log.warn(
`decimals() call for token at address ${tokenAddress} resulted in error:`,

View File

@ -30,7 +30,7 @@ const mapDispatchToProps = (dispatch) => {
to,
amount,
errors: { to: null, amount: null },
editingTransactionId: id && id.toString(),
editingTransactionId: id?.toString(),
}),
)

View File

@ -44,7 +44,7 @@ const mapDispatchToProps = (dispatch) => {
to,
amount: tokenAmountInHex,
errors: { to: null, amount: null },
editingTransactionId: id && id.toString(),
editingTransactionId: id?.toString(),
token: {
...tokenProps,
address: tokenAddress,

View File

@ -41,8 +41,7 @@ const mapStateToProps = (state, ownProps) => {
transaction,
)
const tokens = getTokens(state)
const currentToken =
tokens && tokens.find(({ address }) => tokenAddress === address)
const currentToken = tokens?.find(({ address }) => tokenAddress === address)
const { decimals, symbol: tokenSymbol } = currentToken || {}
const tokenData = getTokenData(data)

View File

@ -9,7 +9,7 @@ const mapStateToProps = (state, ownProps) => {
const {
match: { params = {}, url },
} = ownProps
const urlId = url && url.match(/\d+/u) && url.match(/\d+/u)[0]
const urlId = url?.match(/\d+/u) && url?.match(/\d+/u)[0]
const { id: paramsId } = params
const transactionId = paramsId || urlId

View File

@ -161,7 +161,7 @@ export default class SendTransactionScreen extends Component {
if (qrCodeData) {
if (qrCodeData.type === 'address') {
scannedAddress = qrCodeData.values.address.toLowerCase()
const currentAddress = prevTo && prevTo.toLowerCase()
const currentAddress = prevTo?.toLowerCase()
if (currentAddress !== scannedAddress) {
updateSendTo(scannedAddress)
updateGas = true

View File

@ -291,7 +291,7 @@ export default class NetworkForm extends PureComponent {
setStateWithValue = (stateKey, validator) => {
return (e) => {
validator && validator(e.target.value, stateKey)
validator?.(e.target.value, stateKey)
this.setState({ [stateKey]: e.target.value })
}
}

View File

@ -37,12 +37,12 @@ export default function DropdownSearchList({
const [selectedItem, setSelectedItem] = useState(startingItem)
const close = useCallback(() => {
setIsOpen(false)
onClose && onClose()
onClose?.()
}, [onClose])
const onClickItem = useCallback(
(item) => {
onSelect && onSelect(item)
onSelect?.(item)
setSelectedItem(item)
close()
},
@ -52,7 +52,7 @@ export default function DropdownSearchList({
const onClickSelector = useCallback(() => {
if (!isOpen) {
setIsOpen(true)
onOpen && onOpen()
onOpen?.()
}
}, [isOpen, onOpen])
@ -165,7 +165,7 @@ export default function DropdownSearchList({
onClick={(event) => {
event.stopPropagation()
setIsOpen(false)
onClose && onClose()
onClose?.()
}}
/>
</>

View File

@ -31,11 +31,11 @@ export default function ItemList({
ref={containerRef}
>
{results.slice(0, maxListItems).map((result, i) => {
if (hideItemIf && hideItemIf(result)) {
if (hideItemIf?.(result)) {
return null
}
const onClick = () => onClickItem && onClickItem(result)
const onClick = () => onClickItem?.(result)
const {
iconUrl,
identiconAddress,