mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 20:39:08 +01:00
Begin adding eth_watchToken
This commit is contained in:
parent
d910c35e90
commit
5d7c2810a7
@ -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…
Reference in New Issue
Block a user