From 9a1548368f99918633307a88f21153a002713f6e Mon Sep 17 00:00:00 2001 From: David Walsh Date: Mon, 14 Dec 2020 11:03:59 -0600 Subject: [PATCH] Use Boolean for filters (#10066) --- app/scripts/controllers/incoming-transactions.js | 4 +--- .../gas-modal-page-container.container.js | 2 +- .../multiple-notifications.component.js | 2 +- .../components/ui/page-container/page-container.component.js | 2 +- ui/app/helpers/utils/conversions.util.js | 2 +- ui/app/hooks/useTokensToSearch.js | 4 +--- .../swaps-gas-customization-modal.container.js | 2 +- 7 files changed, 7 insertions(+), 11 deletions(-) diff --git a/app/scripts/controllers/incoming-transactions.js b/app/scripts/controllers/incoming-transactions.js index 2f70d63cd..3cb942826 100644 --- a/app/scripts/controllers/incoming-transactions.js +++ b/app/scripts/controllers/incoming-transactions.js @@ -249,9 +249,7 @@ export default class IncomingTransactionsController { }) const incomingTxs = remoteTxs.filter( - (tx) => - tx.txParams.to && - tx.txParams.to.toLowerCase() === address.toLowerCase(), + (tx) => tx.txParams?.to?.toLowerCase() === address.toLowerCase(), ) incomingTxs.sort((a, b) => (a.time < b.time ? -1 : 1)) diff --git a/ui/app/components/app/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js b/ui/app/components/app/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js index bdf987c8a..cacb39b09 100644 --- a/ui/app/components/app/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js +++ b/ui/app/components/app/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js @@ -321,7 +321,7 @@ function calcCustomGasLimit(customGasLimitInHex) { } function sumHexWEIsToRenderableEth(hexWEIs) { - const hexWEIsSum = hexWEIs.filter((n) => n).reduce(addHexes) + const hexWEIsSum = hexWEIs.filter(Boolean).reduce(addHexes) return formatETHFee( getValueFromWeiHex({ value: hexWEIsSum, diff --git a/ui/app/components/app/multiple-notifications/multiple-notifications.component.js b/ui/app/components/app/multiple-notifications/multiple-notifications.component.js index e8dcebf13..9d16d1dfe 100644 --- a/ui/app/components/app/multiple-notifications/multiple-notifications.component.js +++ b/ui/app/components/app/multiple-notifications/multiple-notifications.component.js @@ -21,7 +21,7 @@ export default class MultipleNotifications extends PureComponent { const { showAll } = this.state const { children, classNames } = this.props - const childrenToRender = children.filter((child) => child) + const childrenToRender = children.filter(Boolean) if (childrenToRender.length === 0) { return null } diff --git a/ui/app/components/ui/page-container/page-container.component.js b/ui/app/components/ui/page-container/page-container.component.js index eb1280b3b..79126e454 100644 --- a/ui/app/components/ui/page-container/page-container.component.js +++ b/ui/app/components/ui/page-container/page-container.component.js @@ -67,7 +67,7 @@ export default class PageContainer extends PureComponent { renderActiveTabContent() { const { tabsComponent } = this.props let { children } = tabsComponent.props - children = children.filter((child) => child) + children = children.filter(Boolean) const { activeTabIndex } = this.state return children[activeTabIndex] diff --git a/ui/app/helpers/utils/conversions.util.js b/ui/app/helpers/utils/conversions.util.js index a61043dbc..b46dff744 100644 --- a/ui/app/helpers/utils/conversions.util.js +++ b/ui/app/helpers/utils/conversions.util.js @@ -183,7 +183,7 @@ export function addHexes(aHexWEI, bHexWEI) { } export function sumHexWEIs(hexWEIs) { - return hexWEIs.filter((n) => n).reduce(addHexes) + return hexWEIs.filter(Boolean).reduce(addHexes) } export function sumHexWEIsToUnformattedFiat( diff --git a/ui/app/hooks/useTokensToSearch.js b/ui/app/hooks/useTokensToSearch.js index 8df33e55e..a4e0e94f4 100644 --- a/ui/app/hooks/useTokensToSearch.js +++ b/ui/app/hooks/useTokensToSearch.js @@ -145,9 +145,7 @@ export function useTokensToSearch({ return new BigNumber(rawFiat || 0).gt(secondRawFiat || 0) ? -1 : 1 }, ) - tokensToSearchBuckets.top = tokensToSearchBuckets.top.filter( - (token) => token, - ) + tokensToSearchBuckets.top = tokensToSearchBuckets.top.filter(Boolean) return [ ...tokensToSearchBuckets.owned, ...tokensToSearchBuckets.top, diff --git a/ui/app/pages/swaps/swaps-gas-customization-modal/swaps-gas-customization-modal.container.js b/ui/app/pages/swaps/swaps-gas-customization-modal/swaps-gas-customization-modal.container.js index d123eb3d6..deea5c4b0 100644 --- a/ui/app/pages/swaps/swaps-gas-customization-modal/swaps-gas-customization-modal.container.js +++ b/ui/app/pages/swaps/swaps-gas-customization-modal/swaps-gas-customization-modal.container.js @@ -159,7 +159,7 @@ export default connect( )(SwapsGasCustomizationModalComponent) function sumHexWEIsToRenderableEth(hexWEIs) { - const hexWEIsSum = hexWEIs.filter((n) => n).reduce(addHexes) + const hexWEIsSum = hexWEIs.filter(Boolean).reduce(addHexes) return formatETHFee( getValueFromWeiHex({ value: hexWEIsSum,