1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Begin adding eth_watchToken

This commit is contained in:
Dan Finlay 2018-06-18 15:05:41 -07:00
parent d910c35e90
commit 5d7c2810a7
3 changed files with 28 additions and 0 deletions

View File

@ -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'})
}
})

View File

@ -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
*

View File

@ -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