From a8863a34462a12c6883e5a00ec96692bc038f2e0 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Wed, 12 Aug 2020 16:36:57 -0230 Subject: [PATCH] Fix consistent-return issues (#9192) See [`consistent-return`](https://eslint.org/docs/rules/consistent-return) for more information. This change enables `consistent-return` and fixes the issues raised by the rule. --- .eslintrc.js | 1 + app/scripts/background.js | 2 +- app/scripts/contentscript.js | 2 +- .../controllers/network/middleware/pending.js | 12 +- app/scripts/controllers/network/network.js | 11 +- .../controllers/permissions/permissionsLog.js | 3 +- app/scripts/controllers/transactions/index.js | 4 +- .../transactions/pending-tx-tracker.js | 2 +- app/scripts/lib/account-tracker.js | 3 +- app/scripts/lib/decrypt-message-manager.js | 15 +- .../lib/encryption-public-key-manager.js | 12 +- app/scripts/lib/personal-message-manager.js | 12 +- app/scripts/lib/setupSentry.js | 2 +- app/scripts/lib/util.js | 4 +- app/scripts/metamask-controller.js | 3 +- app/scripts/ui.js | 6 +- development/verify-locale-strings.js | 4 + test/e2e/fixture-server.js | 2 +- test/e2e/mock-3box/server.js | 3 +- .../controllers/metamask-controller-test.js | 3 +- test/unit/app/nodeify-test.js | 6 +- .../connected-accounts-list.component.js | 1 + .../edit-approval-permission.component.js | 4 +- .../page-container.component.js | 2 +- ui/app/contexts/metametrics.js | 2 + ui/app/helpers/utils/switch-direction.js | 3 + ui/app/helpers/utils/token-util.js | 2 + .../hooks/tests/useCancelTransaction.test.js | 2 + ui/app/hooks/tests/useCurrencyDisplay.test.js | 1 + ui/app/hooks/useTimeout.js | 4 +- ui/app/hooks/useTransactionTimeRemaining.js | 1 + .../create-account/connect-hardware/index.js | 2 +- .../create-account/import-account/json.js | 3 +- .../mobile-sync/mobile-sync.component.js | 4 +- .../permissions-connect.component.js | 3 +- .../add-recipient/add-recipient.component.js | 2 + .../add-recipient/ens-input.component.js | 4 +- .../send-content/send-content.component.js | 2 +- ui/app/pages/send/send.component.js | 3 +- ui/app/pages/send/send.utils.js | 2 +- .../contact-list-tab.component.js | 1 + ui/app/store/actions.js | 189 ++++++++++++------ ui/index.js | 6 +- 43 files changed, 237 insertions(+), 118 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index c5dabe2e2..11460c5f5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -44,6 +44,7 @@ module.exports = { /* TODO: Remove these when upgrading to `@metamask/eslint-config@2` */ 'array-callback-return': 'error', 'callback-return': 'error', + 'consistent-return': 'error', 'global-require': 'error', 'guard-for-in': 'error', 'no-case-declarations': 'error', diff --git a/app/scripts/background.js b/app/scripts/background.js index adbd1e40e..0ff4c1775 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -327,7 +327,7 @@ function setupController (initState, initLangCode) { const isMetaMaskInternalProcess = metamaskInternalProcessHash[processName] if (metamaskBlockedPorts.includes(remotePort.name)) { - return false + return } if (isMetaMaskInternalProcess) { diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index de3066ca8..57e95fa63 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -228,7 +228,7 @@ function redirectToPhishingWarning () { async function domIsReady () { // already loaded if (['interactive', 'complete'].includes(document.readyState)) { - return + return undefined } // wait for load return new Promise((resolve) => window.addEventListener('DOMContentLoaded', resolve, { once: true })) diff --git a/app/scripts/controllers/network/middleware/pending.js b/app/scripts/controllers/network/middleware/pending.js index c869389e7..95e86f3c9 100644 --- a/app/scripts/controllers/network/middleware/pending.js +++ b/app/scripts/controllers/network/middleware/pending.js @@ -5,11 +5,13 @@ export function createPendingNonceMiddleware ({ getPendingNonce }) { return createAsyncMiddleware(async (req, res, next) => { const { method, params } = req if (method !== 'eth_getTransactionCount') { - return next() + next() + return } const [param, blockRef] = params if (blockRef !== 'pending') { - return next() + next() + return } res.result = await getPendingNonce(param) }) @@ -19,12 +21,14 @@ export function createPendingTxMiddleware ({ getPendingTransactionByHash }) { return createAsyncMiddleware(async (req, res, next) => { const { method, params } = req if (method !== 'eth_getTransactionByHash') { - return next() + next() + return } const [hash] = params const txMeta = getPendingTransactionByHash(hash) if (!txMeta) { - return next() + next() + return } res.result = formatTxMetaForRpcResult(txMeta) }) diff --git a/app/scripts/controllers/network/network.js b/app/scripts/controllers/network/network.js index f5efc58bd..f22dbc323 100644 --- a/app/scripts/controllers/network/network.js +++ b/app/scripts/controllers/network/network.js @@ -93,7 +93,8 @@ export default class NetworkController extends EventEmitter { setNetworkState (network, type) { if (network === 'loading') { - return this.networkStore.putState(network) + this.networkStore.putState(network) + return } // type must be defined @@ -101,7 +102,7 @@ export default class NetworkController extends EventEmitter { return } network = networks.networkList[type]?.chainId || network - return this.networkStore.putState(network) + this.networkStore.putState(network) } isNetworkLoading () { @@ -111,7 +112,8 @@ export default class NetworkController extends EventEmitter { lookupNetwork () { // Prevent firing when provider is not defined. if (!this._provider) { - return log.warn('NetworkController - lookupNetwork aborted due to missing provider') + log.warn('NetworkController - lookupNetwork aborted due to missing provider') + return } const { type } = this.providerStore.getState() const ethQuery = new EthQuery(this._provider) @@ -120,7 +122,8 @@ export default class NetworkController extends EventEmitter { const currentNetwork = this.getNetworkState() if (initialNetwork === currentNetwork) { if (err) { - return this.setNetworkState('loading') + this.setNetworkState('loading') + return } log.info('web3.getNetwork returned ' + network) this.setNetworkState(network, type) diff --git a/app/scripts/controllers/permissions/permissionsLog.js b/app/scripts/controllers/permissions/permissionsLog.js index f7997f085..3a6f02537 100644 --- a/app/scripts/controllers/permissions/permissionsLog.js +++ b/app/scripts/controllers/permissions/permissionsLog.js @@ -116,7 +116,8 @@ export default class PermissionsLogController { requestedMethods = [ 'eth_accounts' ] } else { // no-op - return next() + next() + return } // call next with a return handler for capturing the response diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js index fd9856705..cc0f48af6 100644 --- a/app/scripts/controllers/transactions/index.js +++ b/app/scripts/controllers/transactions/index.js @@ -287,11 +287,11 @@ export default class TransactionController extends EventEmitter { /** * Gets default gas price, or returns `undefined` if gas price is already set * @param {Object} txMeta - The txMeta object - * @returns {Promise} The default gas price + * @returns {Promise} The default gas price */ async _getDefaultGasPrice (txMeta) { if (txMeta.txParams.gasPrice) { - return + return undefined } const gasPrice = await this.query.gasPrice() diff --git a/app/scripts/controllers/transactions/pending-tx-tracker.js b/app/scripts/controllers/transactions/pending-tx-tracker.js index a901707a8..ed2d782fe 100644 --- a/app/scripts/controllers/transactions/pending-tx-tracker.js +++ b/app/scripts/controllers/transactions/pending-tx-tracker.js @@ -129,7 +129,7 @@ export default class PendingTransactionTracker extends EventEmitter { // Exponential backoff to limit retries at publishing if (txBlockDistance <= Math.pow(2, retryCount) - 1) { - return + return undefined } // Only auto-submit already-signed txs: diff --git a/app/scripts/lib/account-tracker.js b/app/scripts/lib/account-tracker.js index 974920ee4..4ce0d692e 100644 --- a/app/scripts/lib/account-tracker.js +++ b/app/scripts/lib/account-tracker.js @@ -256,7 +256,8 @@ export default class AccountTracker { ethContract.balances(addresses, ethBalance, (error, result) => { if (error) { log.warn(`MetaMask - Account Tracker single call balance fetch failed`, error) - return Promise.all(addresses.map(this._updateAccount.bind(this))) + Promise.all(addresses.map(this._updateAccount.bind(this))) + return } addresses.forEach((address, index) => { const balance = bnToHex(result[index]) diff --git a/app/scripts/lib/decrypt-message-manager.js b/app/scripts/lib/decrypt-message-manager.js index ca308090f..89aa259b6 100644 --- a/app/scripts/lib/decrypt-message-manager.js +++ b/app/scripts/lib/decrypt-message-manager.js @@ -82,19 +82,24 @@ export default class DecryptMessageManager extends EventEmitter { addUnapprovedMessageAsync (msgParams, req) { return new Promise((resolve, reject) => { if (!msgParams.from) { - return reject(new Error('MetaMask Decryption: from field is required.')) + reject(new Error('MetaMask Decryption: from field is required.')) + return } const msgId = this.addUnapprovedMessage(msgParams, req) this.once(`${msgId}:finished`, (data) => { switch (data.status) { case 'decrypted': - return resolve(data.rawData) + resolve(data.rawData) + return case 'rejected': - return reject(ethErrors.provider.userRejectedRequest('MetaMask Decryption: User denied message decryption.')) + reject(ethErrors.provider.userRejectedRequest('MetaMask Decryption: User denied message decryption.')) + return case 'errored': - return reject(new Error('This message cannot be decrypted')) + reject(new Error('This message cannot be decrypted')) + return default: - return reject(new Error(`MetaMask Decryption: Unknown problem: ${JSON.stringify(msgParams)}`)) + reject(new Error(`MetaMask Decryption: Unknown problem: ${JSON.stringify(msgParams)}`)) + return } }) }) diff --git a/app/scripts/lib/encryption-public-key-manager.js b/app/scripts/lib/encryption-public-key-manager.js index 92f09057c..b927b161a 100644 --- a/app/scripts/lib/encryption-public-key-manager.js +++ b/app/scripts/lib/encryption-public-key-manager.js @@ -79,17 +79,21 @@ export default class EncryptionPublicKeyManager extends EventEmitter { addUnapprovedMessageAsync (address, req) { return new Promise((resolve, reject) => { if (!address) { - return reject(new Error('MetaMask Message: address field is required.')) + reject(new Error('MetaMask Message: address field is required.')) + return } const msgId = this.addUnapprovedMessage(address, req) this.once(`${msgId}:finished`, (data) => { switch (data.status) { case 'received': - return resolve(data.rawData) + resolve(data.rawData) + return case 'rejected': - return reject(ethErrors.provider.userRejectedRequest('MetaMask EncryptionPublicKey: User denied message EncryptionPublicKey.')) + reject(ethErrors.provider.userRejectedRequest('MetaMask EncryptionPublicKey: User denied message EncryptionPublicKey.')) + return default: - return reject(new Error(`MetaMask EncryptionPublicKey: Unknown problem: ${JSON.stringify(address)}`)) + reject(new Error(`MetaMask EncryptionPublicKey: Unknown problem: ${JSON.stringify(address)}`)) + return } }) }) diff --git a/app/scripts/lib/personal-message-manager.js b/app/scripts/lib/personal-message-manager.js index 067c696bd..3cf7564ba 100644 --- a/app/scripts/lib/personal-message-manager.js +++ b/app/scripts/lib/personal-message-manager.js @@ -85,17 +85,21 @@ export default class PersonalMessageManager extends EventEmitter { addUnapprovedMessageAsync (msgParams, req) { return new Promise((resolve, reject) => { if (!msgParams.from) { - return reject(new Error('MetaMask Message Signature: from field is required.')) + reject(new Error('MetaMask Message Signature: from field is required.')) + return } const msgId = this.addUnapprovedMessage(msgParams, req) this.once(`${msgId}:finished`, (data) => { switch (data.status) { case 'signed': - return resolve(data.rawSig) + resolve(data.rawSig) + return case 'rejected': - return reject(ethErrors.provider.userRejectedRequest('MetaMask Message Signature: User denied message signature.')) + reject(ethErrors.provider.userRejectedRequest('MetaMask Message Signature: User denied message signature.')) + return default: - return reject(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)) + reject(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)) + return } }) }) diff --git a/app/scripts/lib/setupSentry.js b/app/scripts/lib/setupSentry.js index a6d1bb9b2..c974aafd8 100644 --- a/app/scripts/lib/setupSentry.js +++ b/app/scripts/lib/setupSentry.js @@ -72,7 +72,7 @@ export default function setupSentry ({ release, getState }) { let sentryTarget if (METAMASK_DEBUG) { - return + return undefined } else if (METAMASK_ENVIRONMENT === 'production') { if (!process.env.SENTRY_DSN) { throw new Error(`Missing SENTRY_DSN environment variable in production environment`) diff --git a/app/scripts/lib/util.js b/app/scripts/lib/util.js index dfd3bc54c..e52058a86 100644 --- a/app/scripts/lib/util.js +++ b/app/scripts/lib/util.js @@ -135,12 +135,12 @@ function BnMultiplyByFraction (targetBN, numerator, denominator) { /** * Returns an Error if extension.runtime.lastError is present * this is a workaround for the non-standard error object that's used - * @returns {Error} + * @returns {Error|undefined} */ function checkForError () { const lastError = extension.runtime.lastError if (!lastError) { - return + return undefined } // if it quacks like an Error, its an Error if (lastError.stack && lastError.message) { diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 2b32a8a42..9c11d8142 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -1349,7 +1349,7 @@ export default class MetamaskController extends EventEmitter { * Triggers the callback in newUnsignedTypedMessage. * * @param {Object} msgParams - The params passed to eth_signTypedData. - * @returns {Object} - Full state update. + * @returns {Object|undefined} - Full state update. */ async signTypedMessage (msgParams) { log.info('MetaMaskController - eth_signTypedData') @@ -1372,6 +1372,7 @@ export default class MetamaskController extends EventEmitter { } catch (error) { log.info('MetaMaskController - eth_signTypedData failed.', error) this.typedMessageManager.errorMessage(msgId, error) + return undefined } } diff --git a/app/scripts/ui.js b/app/scripts/ui.js index 3a76a5f4e..decb002cf 100644 --- a/app/scripts/ui.js +++ b/app/scripts/ui.js @@ -62,7 +62,8 @@ async function start () { const container = document.getElementById('app-content') initializeUi(tab, container, connectionStream, (err, store) => { if (err) { - return displayCriticalError(container, err) + displayCriticalError(container, err) + return } const state = store.getState() @@ -102,7 +103,8 @@ async function queryCurrentActiveTab (windowType) { function initializeUi (activeTab, container, connectionStream, cb) { connectToAccountManager(connectionStream, (err, backgroundConnection) => { if (err) { - return cb(err) + cb(err) + return } launchMetaMaskUi({ diff --git a/development/verify-locale-strings.js b/development/verify-locale-strings.js index 990ed95f4..cef27f6a0 100644 --- a/development/verify-locale-strings.js +++ b/development/verify-locale-strings.js @@ -97,6 +97,7 @@ async function getLocale (code) { log.error(`Error opening your locale ("${code}") file: `, e) } process.exit(1) + return undefined } } @@ -111,6 +112,7 @@ async function writeLocale (code, locale) { log.error(`Error writing your locale ("${code}") file: `, e) } process.exit(1) + return undefined } } @@ -156,6 +158,8 @@ async function verifyLocale (code, fix = false) { } return true } + + return false } async function verifyEnglishLocale (fix = false) { diff --git a/test/e2e/fixture-server.js b/test/e2e/fixture-server.js index 608955f76..f923c0a26 100644 --- a/test/e2e/fixture-server.js +++ b/test/e2e/fixture-server.js @@ -44,7 +44,7 @@ class FixtureServer { return } - return new Promise((resolve, reject) => { + await new Promise((resolve, reject) => { this._server.close() this._server.once('error', reject) this._server.once('close', resolve) diff --git a/test/e2e/mock-3box/server.js b/test/e2e/mock-3box/server.js index 9d6bc7372..c4fe9d9c7 100644 --- a/test/e2e/mock-3box/server.js +++ b/test/e2e/mock-3box/server.js @@ -32,6 +32,7 @@ const server = http.createServer(requestHandler) server.listen(port, (err) => { if (err) { - return console.log('mock 3box server error: ', err) + console.log('mock 3box server error: ', err) + return } }) diff --git a/test/unit/app/controllers/metamask-controller-test.js b/test/unit/app/controllers/metamask-controller-test.js index 746b098d3..6f6ac0a34 100644 --- a/test/unit/app/controllers/metamask-controller-test.js +++ b/test/unit/app/controllers/metamask-controller-test.js @@ -819,7 +819,8 @@ describe('MetaMaskController', function () { const { promise, resolve } = deferredPromise() const streamTest = createThoughStream((chunk, _, cb) => { if (chunk.name !== 'phishing') { - return cb() + cb() + return } assert.equal(chunk.data.hostname, (new URL(phishingMessageSender.url)).hostname) resolve() diff --git a/test/unit/app/nodeify-test.js b/test/unit/app/nodeify-test.js index a70446ef0..400830914 100644 --- a/test/unit/app/nodeify-test.js +++ b/test/unit/app/nodeify-test.js @@ -37,7 +37,8 @@ describe('nodeify', function () { try { nodified((err, result) => { if (err) { - return done(new Error(`should not have thrown any error: ${err.message}`)) + done(new Error(`should not have thrown any error: ${err.message}`)) + return } assert.equal(42, result, 'got expected result') }) @@ -54,7 +55,8 @@ describe('nodeify', function () { try { nodified((err, result) => { if (result) { - return done(new Error('should not have returned any result')) + done(new Error('should not have returned any result')) + return } assert.ok(err, 'got expected error') assert.ok(err.message.includes('boom!'), 'got expected error message') diff --git a/ui/app/components/app/connected-accounts-list/connected-accounts-list.component.js b/ui/app/components/app/connected-accounts-list/connected-accounts-list.component.js index 898af901e..567af6b72 100644 --- a/ui/app/components/app/connected-accounts-list/connected-accounts-list.component.js +++ b/ui/app/components/app/connected-accounts-list/connected-accounts-list.component.js @@ -37,6 +37,7 @@ export default class ConnectedAccountsList extends PureComponent { `Warning: Failed prop type: '${propName}' of component '${componentName}' requires prop 'removePermittedAccount'.`, ) } + return undefined }, } diff --git a/ui/app/components/app/modals/edit-approval-permission/edit-approval-permission.component.js b/ui/app/components/app/modals/edit-approval-permission/edit-approval-permission.component.js index 3d134d9b8..9e1dafced 100644 --- a/ui/app/components/app/modals/edit-approval-permission/edit-approval-permission.component.js +++ b/ui/app/components/app/modals/edit-approval-permission/edit-approval-permission.component.js @@ -167,7 +167,7 @@ export default class EditApprovalPermission extends PureComponent { const { selectedOptionIsUnlimited, customSpendLimit } = this.state if (selectedOptionIsUnlimited || !customSpendLimit) { - return + return undefined } let customSpendLimitNumber @@ -186,6 +186,8 @@ export default class EditApprovalPermission extends PureComponent { if (customSpendLimitNumber.greaterThan(maxTokenAmount)) { return t('spendLimitTooLarge') } + + return undefined } render () { 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 a35524121..b4af4e719 100644 --- a/ui/app/components/ui/page-container/page-container.component.js +++ b/ui/app/components/ui/page-container/page-container.component.js @@ -41,7 +41,7 @@ export default class PageContainer extends PureComponent { const { tabsComponent } = this.props if (!tabsComponent) { - return + return null } const numberOfTabs = React.Children.count(tabsComponent.props.children) diff --git a/ui/app/contexts/metametrics.js b/ui/app/contexts/metametrics.js index b1440429e..920691509 100644 --- a/ui/app/contexts/metametrics.js +++ b/ui/app/contexts/metametrics.js @@ -80,6 +80,8 @@ export function MetaMetricsProvider ({ children }) { ...overrides, }) } + + return undefined }, [ network, environmentType, diff --git a/ui/app/helpers/utils/switch-direction.js b/ui/app/helpers/utils/switch-direction.js index 2ccbfbaf0..f0ed42bf1 100644 --- a/ui/app/helpers/utils/switch-direction.js +++ b/ui/app/helpers/utils/switch-direction.js @@ -1,6 +1,7 @@ /** * Switch the CSS stylesheet used between 'rtl' and 'ltr' * @param {('ltr' | 'rtl')} direction - Text direction, either left-to-right (ltr) or right-to-left (rtl) + * @return {Promise} */ const switchDirection = async (direction) => { if (direction === 'auto') { @@ -25,6 +26,8 @@ const switchDirection = async (direction) => { updatedLink.onerror = () => reject(new Error(`Failed to load '${direction}' stylesheet`)) }) } + + return undefined } export default switchDirection diff --git a/ui/app/helpers/utils/token-util.js b/ui/app/helpers/utils/token-util.js index eb427fe0b..bc091292a 100644 --- a/ui/app/helpers/utils/token-util.js +++ b/ui/app/helpers/utils/token-util.js @@ -23,6 +23,7 @@ async function getSymbolFromContract (tokenAddress) { return result[0] } catch (error) { log.warn(`symbol() call for token at address ${tokenAddress} resulted in error:`, error) + return undefined } } @@ -35,6 +36,7 @@ async function getDecimalsFromContract (tokenAddress) { return decimalsBN && decimalsBN.toString() } catch (error) { log.warn(`decimals() call for token at address ${tokenAddress} resulted in error:`, error) + return undefined } } diff --git a/ui/app/hooks/tests/useCancelTransaction.test.js b/ui/app/hooks/tests/useCancelTransaction.test.js index 7e887486e..be2256cd9 100644 --- a/ui/app/hooks/tests/useCancelTransaction.test.js +++ b/ui/app/hooks/tests/useCancelTransaction.test.js @@ -32,6 +32,7 @@ describe('useCancelTransaction', function () { balance: '0x3', } } + return undefined }) }) transactions.forEach((transactionGroup) => { @@ -75,6 +76,7 @@ describe('useCancelTransaction', function () { balance: '0x9C2007651B2500000', } } + return undefined }) }) transactions.forEach((transactionGroup) => { diff --git a/ui/app/hooks/tests/useCurrencyDisplay.test.js b/ui/app/hooks/tests/useCurrencyDisplay.test.js index 793af907f..850a08960 100644 --- a/ui/app/hooks/tests/useCurrencyDisplay.test.js +++ b/ui/app/hooks/tests/useCurrencyDisplay.test.js @@ -108,6 +108,7 @@ describe('useCurrencyDisplay', function () { } else if (selector === getConversionRate) { return 280.45 } + return undefined }) const hookReturn = renderHook(() => useCurrencyDisplay(value, restProps)) const [ displayValue, parts ] = hookReturn.result.current diff --git a/ui/app/hooks/useTimeout.js b/ui/app/hooks/useTimeout.js index 534c68216..244e9a34c 100644 --- a/ui/app/hooks/useTimeout.js +++ b/ui/app/hooks/useTimeout.js @@ -7,7 +7,7 @@ import { useState, useEffect, useRef, useCallback } from 'react' * @param {number} delay - delay in ms * @param {boolean} [immediate] - determines whether the timeout is invoked immediately * - * @return {Function} + * @return {Function|undefined} */ export function useTimeout (cb, delay, immediate = true) { const saveCb = useRef() @@ -19,7 +19,7 @@ export function useTimeout (cb, delay, immediate = true) { useEffect(() => { if (timeoutId !== 'start') { - return + return undefined } const id = setTimeout(() => { diff --git a/ui/app/hooks/useTransactionTimeRemaining.js b/ui/app/hooks/useTransactionTimeRemaining.js index a37a29ae6..f7834ead1 100644 --- a/ui/app/hooks/useTransactionTimeRemaining.js +++ b/ui/app/hooks/useTransactionTimeRemaining.js @@ -85,6 +85,7 @@ export function useTransactionTimeRemaining ( }, 10000) return () => clearInterval(interval.current) } + return undefined }, [ isMainNet, transactionTimeFeatureActive, diff --git a/ui/app/pages/create-account/connect-hardware/index.js b/ui/app/pages/create-account/connect-hardware/index.js index 8e172bba1..4bae249e6 100644 --- a/ui/app/pages/create-account/connect-hardware/index.js +++ b/ui/app/pages/create-account/connect-hardware/index.js @@ -46,7 +46,7 @@ class ConnectHardwareForm extends Component { connectToHardwareWallet = (device) => { if (this.state.accounts.length) { - return null + return } // Default values diff --git a/ui/app/pages/create-account/import-account/json.js b/ui/app/pages/create-account/import-account/json.js index 304e52c50..55a77cb4e 100644 --- a/ui/app/pages/create-account/import-account/json.js +++ b/ui/app/pages/create-account/import-account/json.js @@ -101,7 +101,8 @@ class JsonImportSubview extends Component { if (!fileContents) { const message = this.context.t('needImportFile') - return displayWarning(message) + displayWarning(message) + return } const password = this.inputRef.current.value diff --git a/ui/app/pages/mobile-sync/mobile-sync.component.js b/ui/app/pages/mobile-sync/mobile-sync.component.js index e0da0074c..1a0d0355f 100644 --- a/ui/app/pages/mobile-sync/mobile-sync.component.js +++ b/ui/app/pages/mobile-sync/mobile-sync.component.js @@ -131,7 +131,7 @@ export default class MobileSyncPage extends Component { const { channel, message } = data // handle message if (channel !== this.channelName || !message) { - return false + return } if (message.event === 'start-sync') { @@ -203,7 +203,7 @@ export default class MobileSyncPage extends Component { async startSyncing () { if (this.syncing) { - return false + return } this.syncing = true this.setState({ syncing: true }) diff --git a/ui/app/pages/permissions-connect/permissions-connect.component.js b/ui/app/pages/permissions-connect/permissions-connect.component.js index 6bef21f37..abb5709d5 100644 --- a/ui/app/pages/permissions-connect/permissions-connect.component.js +++ b/ui/app/pages/permissions-connect/permissions-connect.component.js @@ -85,7 +85,8 @@ export default class PermissionConnect extends Component { getRequestAccountTabIds() if (!permissionsRequest) { - return history.push(DEFAULT_ROUTE) + history.push(DEFAULT_ROUTE) + return } const environmentType = getEnvironmentType() diff --git a/ui/app/pages/send/send-content/add-recipient/add-recipient.component.js b/ui/app/pages/send/send-content/add-recipient/add-recipient.component.js index de4e3a89e..76b6a5570 100644 --- a/ui/app/pages/send/send-content/add-recipient/add-recipient.component.js +++ b/ui/app/pages/send/send-content/add-recipient/add-recipient.component.js @@ -233,6 +233,8 @@ export default class AddRecipient extends Component { ) } + + return null } } diff --git a/ui/app/pages/send/send-content/add-recipient/ens-input.component.js b/ui/app/pages/send/send-content/add-recipient/ens-input.component.js index 8e9d10425..d25243a15 100644 --- a/ui/app/pages/send/send-content/add-recipient/ens-input.component.js +++ b/ui/app/pages/send/send-content/add-recipient/ens-input.component.js @@ -236,7 +236,7 @@ export default class EnsInput extends Component { const { loadingEns, ensFailure, ensResolution, toError } = this.state if (toError) { - return + return null } if (loadingEns) { @@ -269,6 +269,8 @@ export default class EnsInput extends Component { /> ) } + + return null } } diff --git a/ui/app/pages/send/send-content/send-content.component.js b/ui/app/pages/send/send-content/send-content.component.js index 6ae20f19e..9188140f9 100644 --- a/ui/app/pages/send/send-content/send-content.component.js +++ b/ui/app/pages/send/send-content/send-content.component.js @@ -48,7 +48,7 @@ export default class SendContent extends Component { const { isOwnedAccount, showAddToAddressBookModal, contact = {} } = this.props if (isOwnedAccount || contact.name) { - return + return null } return ( diff --git a/ui/app/pages/send/send.component.js b/ui/app/pages/send/send.component.js index e73aa8bf7..0c7f7804a 100644 --- a/ui/app/pages/send/send.component.js +++ b/ui/app/pages/send/send.component.js @@ -225,7 +225,8 @@ export default class SendTransactionScreen extends Component { } = this.props if (!query) { - return this.setState({ toError: '', toWarning: '' }) + this.setState({ toError: '', toWarning: '' }) + return } const toErrorObject = getToErrorObject(query, hasHexData, network) diff --git a/ui/app/pages/send/send.utils.js b/ui/app/pages/send/send.utils.js index 7ffc5dcdb..ff3b5295a 100644 --- a/ui/app/pages/send/send.utils.js +++ b/ui/app/pages/send/send.utils.js @@ -301,7 +301,7 @@ function addGasBuffer (initialGasLimitHex, blockGasLimitHex, bufferMultiplier = function generateTokenTransferData ({ toAddress = '0x0', amount = '0x0', sendToken }) { if (!sendToken) { - return + return undefined } return TOKEN_TRANSFER_FUNCTION_SIGNATURE + Array.prototype.map.call( abi.rawEncode(['address', 'uint256'], [toAddress, ethUtil.addHexPrefix(amount)]), diff --git a/ui/app/pages/settings/contact-list-tab/contact-list-tab.component.js b/ui/app/pages/settings/contact-list-tab/contact-list-tab.component.js index 835963a83..dfcb35c19 100644 --- a/ui/app/pages/settings/contact-list-tab/contact-list-tab.component.js +++ b/ui/app/pages/settings/contact-list-tab/contact-list-tab.component.js @@ -121,6 +121,7 @@ export default class ContactListTab extends Component { } else if (!hideAddressBook && showingMyAccounts) { return () } + return null } render () { diff --git a/ui/app/store/actions.js b/ui/app/store/actions.js index 49a43da24..fb7825e62 100644 --- a/ui/app/store/actions.js +++ b/ui/app/store/actions.js @@ -46,7 +46,8 @@ export function tryUnlockMetamask (password) { return new Promise((resolve, reject) => { background.submitPassword(password, (error) => { if (error) { - return reject(error) + reject(error) + return } resolve() @@ -61,7 +62,8 @@ export function tryUnlockMetamask (password) { background.verifySeedPhrase((err) => { if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } resolve() @@ -87,7 +89,8 @@ export function createNewVaultAndRestore (password, seed) { return new Promise((resolve, reject) => { background.createNewVaultAndRestore(password, seed, (err, _vault) => { if (err) { - return reject(err) + reject(err) + return } vault = _vault resolve() @@ -146,7 +149,8 @@ export function submitPassword (password) { return new Promise((resolve, reject) => { background.submitPassword(password, (error) => { if (error) { - return reject(error) + reject(error) + return } resolve() @@ -158,7 +162,8 @@ export function createNewVault (password) { return new Promise((resolve, reject) => { background.createNewVaultAndKeychain(password, (error) => { if (error) { - return reject(error) + reject(error) + return } resolve(true) @@ -170,7 +175,8 @@ export function verifyPassword (password) { return new Promise((resolve, reject) => { background.verifyPassword(password, (error) => { if (error) { - return reject(error) + reject(error) + return } resolve(true) @@ -182,7 +188,8 @@ export function verifySeedPhrase () { return new Promise((resolve, reject) => { background.verifySeedPhrase((error, seedWords) => { if (error) { - return reject(error) + reject(error) + return } resolve(seedWords) @@ -228,7 +235,8 @@ export function fetchInfoToSync () { background.fetchInfoToSync((err, result) => { if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } resolve(result) }) @@ -245,7 +253,8 @@ export function resetAccount () { dispatch(hideLoadingIndication()) if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } log.info('Transaction history reset for ' + account) @@ -264,9 +273,11 @@ export function removeAccount (address) { await new Promise((resolve, reject) => { background.removeAccount(address, (error, account) => { if (error) { - return reject(error) + reject(error) + return } - return resolve(account) + resolve(account) + return }) }) await forceUpdateMetamaskState(dispatch) @@ -395,11 +406,13 @@ export function unlockHardwareWalletAccount (index, deviceName, hdPath) { if (err) { log.error(err) dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } dispatch(hideLoadingIndication()) - return resolve() + resolve() + return }) }) } @@ -576,7 +589,8 @@ export function signTx (txData) { return (dispatch) => { global.ethQuery.sendTransaction(txData, (err) => { if (err) { - return dispatch(displayWarning(err.message)) + dispatch(displayWarning(err.message)) + return } }) dispatch(showConfTxPage()) @@ -776,7 +790,8 @@ const updateMetamaskStateFromBackground = () => { return new Promise((resolve, reject) => { background.getState((error, newState) => { if (error) { - return reject(error) + reject(error) + return } resolve(newState) @@ -795,7 +810,8 @@ export function updateTransaction (txData) { dispatch(txError(err)) dispatch(goHome()) log.error(err.message) - return reject(err) + reject(err) + return } resolve(txData) @@ -823,7 +839,8 @@ export function updateAndApproveTx (txData) { dispatch(txError(err)) dispatch(goHome()) log.error(err.message) - return reject(err) + reject(err) + return } resolve(txData) @@ -975,7 +992,8 @@ export function cancelTx (txData) { return new Promise((resolve, reject) => { background.cancelTransaction(txData.id, (err) => { if (err) { - return reject(err) + reject(err) + return } resolve() @@ -1006,7 +1024,8 @@ export function cancelTxs (txDataList) { const cancellations = txIds.map((id) => new Promise((resolve, reject) => { background.cancelTransaction(id, (err) => { if (err) { - return reject(err) + reject(err) + return } resolve() @@ -1025,7 +1044,8 @@ export function cancelTxs (txDataList) { dispatch(hideLoadingIndication()) if (getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION) { - return global.platform.closeCurrentWindow() + global.platform.closeCurrentWindow() + return } } } @@ -1036,9 +1056,11 @@ export function markPasswordForgotten () { await new Promise((resolve, reject) => { return background.markPasswordForgotten((error) => { if (error) { - return reject(error) + reject(error) + return } - return resolve() + resolve() + return }) }) } finally { @@ -1130,7 +1152,8 @@ const backgroundSetLocked = () => { return new Promise((resolve, reject) => { background.setLocked((error) => { if (error) { - return reject(error) + reject(error) + return } resolve() }) @@ -1220,7 +1243,8 @@ export function addPermittedAccount (origin, address) { await new Promise((resolve, reject) => { background.addPermittedAccount(origin, address, (error) => { if (error) { - return reject(error) + reject(error) + return } resolve() }) @@ -1234,7 +1258,8 @@ export function removePermittedAccount (origin, address) { await new Promise((resolve, reject) => { background.removePermittedAccount(origin, address, (error) => { if (error) { - return reject(error) + reject(error) + return } resolve() }) @@ -1264,7 +1289,8 @@ export function addToken (address, symbol, decimals, image) { dispatch(hideLoadingIndication()) if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } dispatch(updateTokens(tokens)) resolve(tokens) @@ -1281,7 +1307,8 @@ export function removeToken (address) { dispatch(hideLoadingIndication()) if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } dispatch(updateTokens(tokens)) resolve(tokens) @@ -1319,7 +1346,8 @@ export function removeSuggestedTokens () { } dispatch(clearPendingTokens()) if (getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION) { - return global.platform.closeCurrentWindow() + global.platform.closeCurrentWindow() + return } resolve(suggestedTokens) }) @@ -1357,7 +1385,8 @@ export function createCancelTransaction (txId, customGasPrice) { background.createCancelTransaction(txId, customGasPrice, (err, newState) => { if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } const { currentNetworkTxList } = newState @@ -1380,7 +1409,8 @@ export function createSpeedUpTransaction (txId, customGasPrice, customGasLimit) background.createSpeedUpTransaction(txId, customGasPrice, customGasLimit, (err, newState) => { if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } const { currentNetworkTxList } = newState @@ -1402,7 +1432,8 @@ export function createRetryTransaction (txId, customGasPrice, customGasLimit) { background.createSpeedUpTransaction(txId, customGasPrice, customGasLimit, (err, newState) => { if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } const { currentNetworkTxList } = newState @@ -1517,7 +1548,8 @@ export function delRpcTarget (oldRpc) { if (err) { log.error(err) dispatch(displayWarning('Had a problem removing network!')) - return reject(err) + reject(err) + return } resolve() }) @@ -1541,7 +1573,8 @@ export function addToAddressBook (recipient, nickname = '', memo = '') { throw error } if (!set) { - return dispatch(displayWarning('Address book failed to update')) + dispatch(displayWarning('Address book failed to update')) + return } } } @@ -1688,21 +1721,24 @@ export function exportAccount (password, address) { log.error('Error in submitting password.') dispatch(hideLoadingIndication()) dispatch(displayWarning('Incorrect Password.')) - return reject(err) + reject(err) + return } log.debug(`background.exportAccount`) - return background.exportAccount(address, function (err, result) { + background.exportAccount(address, function (err, result) { dispatch(hideLoadingIndication()) if (err) { log.error(err) dispatch(displayWarning('Had a problem exporting the account.')) - return reject(err) + reject(err) + return } dispatch(showPrivateKey(result)) - return resolve(result) + resolve(result) + return }) }) }) @@ -1716,7 +1752,8 @@ export function exportAccounts (password, addresses) { background.submitPassword(password, function (err) { if (err) { log.error('Error in submitting password.') - return reject(err) + reject(err) + return } log.debug(`background.exportAccounts`) const accountPromises = addresses.map((address) => @@ -1725,13 +1762,16 @@ export function exportAccounts (password, addresses) { if (err) { log.error(err) dispatch(displayWarning('Had a problem exporting the account.')) - return reject(err) + reject(err) + return } - return resolve(result) + resolve(result) + return }), ), ) - return resolve(Promise.all(accountPromises)) + resolve(Promise.all(accountPromises)) + return }) }) } @@ -1755,7 +1795,8 @@ export function setAccountLabel (account, label) { if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } dispatch({ @@ -1793,7 +1834,8 @@ export function setFeatureFlag (feature, activated, notificationType) { dispatch(hideLoadingIndication()) if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } dispatch(updateFeatureFlags(updatedFeatureFlags)) notificationType && dispatch(showModal({ name: notificationType })) @@ -1819,7 +1861,8 @@ export function setPreference (preference, value) { if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } dispatch(updatePreferences(updatedPreferences)) @@ -1912,7 +1955,8 @@ export function setParticipateInMetaMetrics (val) { log.debug(err) if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } dispatch({ @@ -1933,7 +1977,8 @@ export function setMetaMetricsSendCount (val) { background.setMetaMetricsSendCount(val, (err) => { if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } dispatch({ @@ -1954,7 +1999,8 @@ export function setUseBlockie (val) { background.setUseBlockie(val, (err) => { dispatch(hideLoadingIndication()) if (err) { - return dispatch(displayWarning(err.message)) + dispatch(displayWarning(err.message)) + return } }) dispatch({ @@ -1971,7 +2017,8 @@ export function setUseNonceField (val) { background.setUseNonceField(val, (err) => { dispatch(hideLoadingIndication()) if (err) { - return dispatch(displayWarning(err.message)) + dispatch(displayWarning(err.message)) + return } }) dispatch({ @@ -1988,7 +2035,8 @@ export function setUsePhishDetect (val) { background.setUsePhishDetect(val, (err) => { dispatch(hideLoadingIndication()) if (err) { - return dispatch(displayWarning(err.message)) + dispatch(displayWarning(err.message)) + return } }) } @@ -2001,7 +2049,8 @@ export function setIpfsGateway (val) { background.setIpfsGateway(val, (err) => { dispatch(hideLoadingIndication()) if (err) { - return dispatch(displayWarning(err.message)) + dispatch(displayWarning(err.message)) + return } else { dispatch({ type: actionConstants.SET_IPFS_GATEWAY, @@ -2022,7 +2071,8 @@ export function updateCurrentLocale (key) { background.setCurrentLocale(key, (err, textDirection) => { if (err) { dispatch(hideLoadingIndication()) - return dispatch(displayWarning(err.message)) + dispatch(displayWarning(err.message)) + return } switchDirection(textDirection) dispatch(setCurrentLocale(key, localeMessages)) @@ -2086,9 +2136,10 @@ export function rejectPermissionsRequest (requestId) { background.rejectPermissionsRequest(requestId, (err) => { if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } - return forceUpdateMetamaskState(dispatch) + forceUpdateMetamaskState(dispatch) .then(resolve) .catch(reject) }) @@ -2119,7 +2170,8 @@ export function setFirstTimeFlowType (type) { log.debug(`background.setFirstTimeFlowType`) background.setFirstTimeFlowType(type, (err) => { if (err) { - return dispatch(displayWarning(err.message)) + dispatch(displayWarning(err.message)) + return } }) dispatch({ @@ -2147,7 +2199,8 @@ export function setLastActiveTime () { return (dispatch) => { background.setLastActiveTime((err) => { if (err) { - return dispatch(displayWarning(err.message)) + dispatch(displayWarning(err.message)) + return } }) } @@ -2252,9 +2305,10 @@ export function setSeedPhraseBackedUp (seedPhraseBackupState) { background.setSeedPhraseBackedUp(seedPhraseBackupState, (err) => { if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } - return forceUpdateMetamaskState(dispatch) + forceUpdateMetamaskState(dispatch) .then(resolve) .catch(reject) }) @@ -2268,7 +2322,8 @@ export function initializeThreeBox () { background.initializeThreeBox((err) => { if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } resolve() }) @@ -2282,7 +2337,8 @@ export function setShowRestorePromptToFalse () { background.setShowRestorePromptToFalse((err) => { if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } resolve() }) @@ -2296,7 +2352,8 @@ export function turnThreeBoxSyncingOn () { background.turnThreeBoxSyncingOn((err) => { if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } resolve() }) @@ -2310,7 +2367,8 @@ export function restoreFromThreeBox (accountAddress) { background.restoreFromThreeBox(accountAddress, (err) => { if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } resolve() }) @@ -2324,7 +2382,8 @@ export function getThreeBoxLastUpdated () { background.getThreeBoxLastUpdated((err, lastUpdated) => { if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } resolve(lastUpdated) }) @@ -2338,7 +2397,8 @@ export function setThreeBoxSyncingPermission (threeBoxSyncingAllowed) { background.setThreeBoxSyncingPermission(threeBoxSyncingAllowed, (err) => { if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } resolve() }) @@ -2368,7 +2428,8 @@ export function getNextNonce () { background.getNextNonce(address, (err, nextNonce) => { if (err) { dispatch(displayWarning(err.message)) - return reject(err) + reject(err) + return } dispatch(setNextNonce(nextNonce)) resolve(nextNonce) diff --git a/ui/index.js b/ui/index.js index bc61913b2..e771624be 100644 --- a/ui/index.js +++ b/ui/index.js @@ -28,7 +28,8 @@ export default function launchMetamaskUi (opts, cb) { // check if we are unlocked first backgroundConnection.getState(function (err, metamaskState) { if (err) { - return cb(err) + cb(err) + return } startApp(metamaskState, backgroundConnection, opts) .then((store) => { @@ -188,7 +189,8 @@ window.logStateString = function (cb) { const state = window.getCleanAppState() global.platform.getPlatformInfo((err, platform) => { if (err) { - return cb(err) + cb(err) + return } state.platform = platform const stateString = JSON.stringify(state, null, 2)