Add experimental RPC method support

feature/default_network_editable
bitpshr 6 years ago committed by Dan Finlay
parent 26ada8a828
commit 879997af51
  1. 1
      app/scripts/contentscript.js
  2. 8
      app/scripts/controllers/provider-approval.js
  3. 17
      app/scripts/inpage.js

@ -125,6 +125,7 @@ function listenForProviderRequest () {
case 'ETHEREUM_ENABLE_PROVIDER': case 'ETHEREUM_ENABLE_PROVIDER':
extension.runtime.sendMessage({ extension.runtime.sendMessage({
action: 'init-provider-request', action: 'init-provider-request',
force: data.force,
origin: source.location.hostname, origin: source.location.hostname,
siteImage: getSiteIcon(source), siteImage: getSiteIcon(source),
siteTitle: getSiteName(source), siteTitle: getSiteName(source),

@ -25,10 +25,10 @@ class ProviderApprovalController {
this.store = new ObservableStore() this.store = new ObservableStore()
if (platform && platform.addMessageListener) { if (platform && platform.addMessageListener) {
platform.addMessageListener(({ action = '', origin, siteTitle, siteImage }) => { platform.addMessageListener(({ action = '', force, origin, siteTitle, siteImage }) => {
switch (action) { switch (action) {
case 'init-provider-request': case 'init-provider-request':
this._handleProviderRequest(origin, siteTitle, siteImage) this._handleProviderRequest(origin, siteTitle, siteImage, force)
break break
case 'init-is-approved': case 'init-is-approved':
this._handleIsApproved(origin) this._handleIsApproved(origin)
@ -51,10 +51,10 @@ class ProviderApprovalController {
* @param {string} siteTitle - The title of the document requesting full provider access * @param {string} siteTitle - The title of the document requesting full provider access
* @param {string} siteImage - The icon of the window requesting full provider access * @param {string} siteImage - The icon of the window requesting full provider access
*/ */
_handleProviderRequest (origin, siteTitle, siteImage) { _handleProviderRequest (origin, siteTitle, siteImage, force) {
this.store.updateState({ providerRequests: [{ origin, siteTitle, siteImage }] }) this.store.updateState({ providerRequests: [{ origin, siteTitle, siteImage }] })
const isUnlocked = this.keyringController.memStore.getState().isUnlocked const isUnlocked = this.keyringController.memStore.getState().isUnlocked
if (this.isApproved(origin) && this.caching && isUnlocked) { if (!force && this.isApproved(origin) && this.caching && isUnlocked) {
this.approveProviderRequest(origin) this.approveProviderRequest(origin)
return return
} }

@ -44,7 +44,7 @@ window.addEventListener('metamasksetlocked', () => {
}) })
// augment the provider with its enable method // augment the provider with its enable method
inpageProvider.enable = function () { inpageProvider.enable = function ({ force } = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
window.removeEventListener('ethereumprovider', providerHandle) window.removeEventListener('ethereumprovider', providerHandle)
providerHandle = ({ detail }) => { providerHandle = ({ detail }) => {
@ -85,10 +85,23 @@ inpageProvider.enable = function () {
} }
} }
window.addEventListener('ethereumprovider', providerHandle) window.addEventListener('ethereumprovider', providerHandle)
window.postMessage({ type: 'ETHEREUM_ENABLE_PROVIDER' }, '*') window.postMessage({ type: 'ETHEREUM_ENABLE_PROVIDER', force }, '*')
}) })
} }
// detect eth_requestAccounts and pipe to enable for now
function detectAccountRequest(method) {
const originalMethod = inpageProvider[method]
inpageProvider[method] = function ({ method }) {
if (method === 'eth_requestAccounts') {
return ethereum.enable()
}
return originalMethod.apply(this, arguments)
}
}
detectAccountRequest('send')
detectAccountRequest('sendAsync')
// add metamask-specific convenience methods // add metamask-specific convenience methods
inpageProvider._metamask = new Proxy({ inpageProvider._metamask = new Proxy({
/** /**

Loading…
Cancel
Save