Begin adding eth_watchToken

feature/default_network_editable
Dan Finlay 7 years ago
parent d910c35e90
commit 5d7c2810a7
  1. 2
      app/scripts/background.js
  2. 25
      app/scripts/controllers/preferences.js
  3. 1
      app/scripts/metamask-controller.js

@ -248,6 +248,7 @@ function setupController (initState, initLangCode) {
showUnconfirmedMessage: triggerUi,
unlockAccountMessage: triggerUi,
showUnapprovedTx: triggerUi,
showAddTokenUi: triggerUi,
// initial state
initState,
// initial locale code
@ -436,3 +437,4 @@ extension.runtime.onInstalled.addListener(function (details) {
extension.tabs.create({url: 'https://metamask.io/#how-it-works'})
}
})

@ -25,6 +25,7 @@ class PreferencesController {
frequentRpcList: [],
currentAccountTab: 'history',
tokens: [],
suggestedTokens: [],
useBlockie: false,
featureFlags: {},
currentLocale: opts.initLangCode,
@ -48,6 +49,30 @@ class PreferencesController {
this.store.updateState({ useBlockie: val })
}
getSuggestedTokens () {
return this.store.getState().suggestedTokens
}
/**
* RPC engine middleware for requesting new token added
*
* @param req
* @param res
* @param {Function} - next
* @param {Function} - end
*/
requestAddToken(req, res, next, end) {
if (req.method === 'eth_watchToken') {
// Validate params!
// this.suggestedTokens.push(req.params)
const [ rawAddress, symbol, decimals ] = req.params
this.addToken(rawAddress, symbol, decimals)
end(null, rawAddress)
} else {
next()
}
}
/**
* Getter for the `useBlockie` property
*

@ -1077,6 +1077,7 @@ module.exports = class MetamaskController extends EventEmitter {
engine.push(createOriginMiddleware({ origin }))
engine.push(createLoggerMiddleware({ origin }))
engine.push(filterMiddleware)
engine.push(this.preferencesController.requestAddToken.bind(this.preferencesController))
engine.push(createProviderMiddleware({ provider: this.provider }))
// setup connection

Loading…
Cancel
Save