mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
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.
This commit is contained in:
parent
885125ad03
commit
a8863a3446
@ -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',
|
||||
|
@ -327,7 +327,7 @@ function setupController (initState, initLangCode) {
|
||||
const isMetaMaskInternalProcess = metamaskInternalProcessHash[processName]
|
||||
|
||||
if (metamaskBlockedPorts.includes(remotePort.name)) {
|
||||
return false
|
||||
return
|
||||
}
|
||||
|
||||
if (isMetaMaskInternalProcess) {
|
||||
|
@ -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 }))
|
||||
|
@ -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)
|
||||
})
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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<string>} The default gas price
|
||||
* @returns {Promise<string|undefined>} The default gas price
|
||||
*/
|
||||
async _getDefaultGasPrice (txMeta) {
|
||||
if (txMeta.txParams.gasPrice) {
|
||||
return
|
||||
return undefined
|
||||
}
|
||||
const gasPrice = await this.query.gasPrice()
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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])
|
||||
|
@ -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
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -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
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -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
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -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`)
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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({
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
})
|
||||
|
@ -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()
|
||||
|
@ -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')
|
||||
|
@ -37,6 +37,7 @@ export default class ConnectedAccountsList extends PureComponent {
|
||||
`Warning: Failed prop type: '${propName}' of component '${componentName}' requires prop 'removePermittedAccount'.`,
|
||||
)
|
||||
}
|
||||
return undefined
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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 () {
|
||||
|
@ -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)
|
||||
|
@ -80,6 +80,8 @@ export function MetaMetricsProvider ({ children }) {
|
||||
...overrides,
|
||||
})
|
||||
}
|
||||
|
||||
return undefined
|
||||
}, [
|
||||
network,
|
||||
environmentType,
|
||||
|
@ -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<void>}
|
||||
*/
|
||||
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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) => {
|
||||
|
@ -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
|
||||
|
@ -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(() => {
|
||||
|
@ -85,6 +85,7 @@ export function useTransactionTimeRemaining (
|
||||
}, 10000)
|
||||
return () => clearInterval(interval.current)
|
||||
}
|
||||
return undefined
|
||||
}, [
|
||||
isMainNet,
|
||||
transactionTimeFeatureActive,
|
||||
|
@ -46,7 +46,7 @@ class ConnectHardwareForm extends Component {
|
||||
|
||||
connectToHardwareWallet = (device) => {
|
||||
if (this.state.accounts.length) {
|
||||
return null
|
||||
return
|
||||
}
|
||||
|
||||
// Default values
|
||||
|
@ -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
|
||||
|
@ -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 })
|
||||
|
@ -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()
|
||||
|
@ -233,6 +233,8 @@ export default class AddRecipient extends Component {
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ export default class SendContent extends Component {
|
||||
const { isOwnedAccount, showAddToAddressBookModal, contact = {} } = this.props
|
||||
|
||||
if (isOwnedAccount || contact.name) {
|
||||
return
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -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)
|
||||
|
@ -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)]),
|
||||
|
@ -121,6 +121,7 @@ export default class ContactListTab extends Component {
|
||||
} else if (!hideAddressBook && showingMyAccounts) {
|
||||
return (<MyAccounts />)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
render () {
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user