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