Use optional chaining for functions (#9799)

feature/default_network_editable
David Walsh 4 years ago committed by GitHub
commit 9df5be903b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      ui/app/components/app/account-list-item/account-list-item.js
  2. 2
      ui/app/components/app/confirm-page-container/confirm-detail-row/confirm-detail-row.component.js
  3. 2
      ui/app/components/app/modals/account-details-modal/account-details-modal.component.js
  4. 2
      ui/app/components/app/sidebars/sidebar.component.js
  5. 2
      ui/app/components/ui/button-group/button-group.component.js
  6. 4
      ui/app/ducks/confirm-transaction/confirm-transaction.duck.test.js
  7. 2
      ui/app/helpers/utils/token-util.js
  8. 2
      ui/app/pages/confirm-send-ether/confirm-send-ether.container.js
  9. 2
      ui/app/pages/confirm-send-token/confirm-send-token.container.js
  10. 3
      ui/app/pages/confirm-token-transaction-base/confirm-token-transaction-base.container.js
  11. 2
      ui/app/pages/confirm-transaction-switch/confirm-transaction-switch.container.js
  12. 2
      ui/app/pages/send/send.component.js
  13. 2
      ui/app/pages/settings/networks-tab/network-form/network-form.component.js
  14. 8
      ui/app/pages/swaps/dropdown-search-list/dropdown-search-list.js
  15. 4
      ui/app/pages/swaps/searchable-item-list/item-list/item-list.component.js

@ -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

@ -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>

@ -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?.type?.search('Hardware') !== -1) {
exportPrivateKeyFeatureEnabled = false exportPrivateKeyFeatureEnabled = false
} }

@ -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()
}} }}
/> />

@ -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}

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

@ -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:`,

@ -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(),
}), }),
) )

@ -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,

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

@ -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

@ -161,7 +161,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

@ -291,7 +291,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 })
} }
} }

@ -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?.()
}} }}
/> />
</> </>

@ -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,

Loading…
Cancel
Save