@ -303,7 +303,9 @@ class PreferencesController {
const accountTokens = this . store . getState ( ) . accountTokens
addresses . forEach ( ( address ) => {
// skip if already exists
if ( identities [ address ] ) return
if ( identities [ address ] ) {
return
}
// add missing identity
const identityCount = Object . keys ( identities ) . length
@ -335,7 +337,9 @@ class PreferencesController {
if ( Object . keys ( newlyLost ) . length > 0 ) {
// Notify our servers:
if ( this . diagnostics ) this . diagnostics . reportOrphans ( newlyLost )
if ( this . diagnostics ) {
this . diagnostics . reportOrphans ( newlyLost )
}
// store lost accounts
for ( const key in newlyLost ) {
@ -463,7 +467,9 @@ class PreferencesController {
* @ return { Promise < string > }
* /
setAccountLabel ( account , label ) {
if ( ! account ) throw new Error ( 'setAccountLabel requires a valid address, got ' + String ( account ) )
if ( ! account ) {
throw new Error ( 'setAccountLabel requires a valid address, got ' + String ( account ) )
}
const address = normalizeAddress ( account )
const { identities } = this . store . getState ( )
identities [ address ] = identities [ address ] || { }
@ -500,7 +506,9 @@ class PreferencesController {
updateRpc ( newRpcDetails ) {
const rpcList = this . getFrequentRpcListDetail ( )
const index = rpcList . findIndex ( ( element ) => { return element . rpcUrl === newRpcDetails . rpcUrl } )
const index = rpcList . findIndex ( ( element ) => {
return element . rpcUrl === newRpcDetails . rpcUrl
} )
if ( index > - 1 ) {
const rpcDetail = rpcList [ index ]
const updatedRpc = extend ( rpcDetail , newRpcDetails )
@ -524,7 +532,9 @@ class PreferencesController {
* /
addToFrequentRpcList ( url , chainId , ticker = 'ETH' , nickname = '' , rpcPrefs = { } ) {
const rpcList = this . getFrequentRpcListDetail ( )
const index = rpcList . findIndex ( ( element ) => { return element . rpcUrl === url } )
const index = rpcList . findIndex ( ( element ) => {
return element . rpcUrl === url
} )
if ( index !== - 1 ) {
rpcList . splice ( index , 1 )
}
@ -548,7 +558,9 @@ class PreferencesController {
* /
removeFromFrequentRpcList ( url ) {
const rpcList = this . getFrequentRpcListDetail ( )
const index = rpcList . findIndex ( ( element ) => { return element . rpcUrl === url } )
const index = rpcList . findIndex ( ( element ) => {
return element . rpcUrl === url
} )
if ( index !== - 1 ) {
rpcList . splice ( index , 1 )
}
@ -687,10 +699,16 @@ class PreferencesController {
* /
_getTokenRelatedStates ( selectedAddress ) {
const accountTokens = this . store . getState ( ) . accountTokens
if ( ! selectedAddress ) selectedAddress = this . store . getState ( ) . selectedAddress
if ( ! selectedAddress ) {
selectedAddress = this . store . getState ( ) . selectedAddress
}
const providerType = this . network . providerStore . getState ( ) . type
if ( ! ( selectedAddress in accountTokens ) ) accountTokens [ selectedAddress ] = { }
if ( ! ( providerType in accountTokens [ selectedAddress ] ) ) accountTokens [ selectedAddress ] [ providerType ] = [ ]
if ( ! ( selectedAddress in accountTokens ) ) {
accountTokens [ selectedAddress ] = { }
}
if ( ! ( providerType in accountTokens [ selectedAddress ] ) ) {
accountTokens [ selectedAddress ] [ providerType ] = [ ]
}
const tokens = accountTokens [ selectedAddress ] [ providerType ]
return { tokens , accountTokens , providerType , selectedAddress }
}
@ -727,13 +745,19 @@ class PreferencesController {
* /
_validateERC20AssetParams ( opts ) {
const { rawAddress , symbol , decimals } = opts
if ( ! rawAddress || ! symbol || typeof decimals === 'undefined' ) throw new Error ( ` Cannot suggest token without address, symbol, and decimals ` )
if ( ! ( symbol . length < 7 ) ) throw new Error ( ` Invalid symbol ${ symbol } more than six characters ` )
if ( ! rawAddress || ! symbol || typeof decimals === 'undefined' ) {
throw new Error ( ` Cannot suggest token without address, symbol, and decimals ` )
}
if ( ! ( symbol . length < 7 ) ) {
throw new Error ( ` Invalid symbol ${ symbol } more than six characters ` )
}
const numDecimals = parseInt ( decimals , 10 )
if ( isNaN ( numDecimals ) || numDecimals > 36 || numDecimals < 0 ) {
throw new Error ( ` Invalid decimals ${ decimals } must be at least 0, and not over 36 ` )
}
if ( ! isValidAddress ( rawAddress ) ) throw new Error ( ` Invalid address ${ rawAddress } ` )
if ( ! isValidAddress ( rawAddress ) ) {
throw new Error ( ` Invalid address ${ rawAddress } ` )
}
}
}