1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Use optional chaining for functions

This commit is contained in:
David Walsh 2020-11-05 09:35:58 -06:00
parent 314125e6fd
commit 8a3dabb230
15 changed files with 19 additions and 19 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,7 +9,7 @@ const mapStateToProps = (state, ownProps) => {
const { const {
match: { params = {}, url }, match: { params = {}, url },
} = ownProps } = 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 { id: paramsId } = params
const transactionId = paramsId || urlId const transactionId = paramsId || urlId

View File

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

View File

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

View File

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

View File

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