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':
extension.runtime.sendMessage({
action: 'init-provider-request',
force: data.force,
origin: source.location.hostname,
siteImage: getSiteIcon(source),
siteTitle: getSiteName(source),

@ -25,10 +25,10 @@ class ProviderApprovalController {
this.store = new ObservableStore()
if (platform && platform.addMessageListener) {
platform.addMessageListener(({ action = '', origin, siteTitle, siteImage }) => {
platform.addMessageListener(({ action = '', force, origin, siteTitle, siteImage }) => {
switch (action) {
case 'init-provider-request':
this._handleProviderRequest(origin, siteTitle, siteImage)
this._handleProviderRequest(origin, siteTitle, siteImage, force)
break
case 'init-is-approved':
this._handleIsApproved(origin)
@ -51,10 +51,10 @@ class ProviderApprovalController {
* @param {string} siteTitle - The title of the document 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 }] })
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)
return
}

@ -44,7 +44,7 @@ window.addEventListener('metamasksetlocked', () => {
})
// augment the provider with its enable method
inpageProvider.enable = function () {
inpageProvider.enable = function ({ force } = {}) {
return new Promise((resolve, reject) => {
window.removeEventListener('ethereumprovider', providerHandle)
providerHandle = ({ detail }) => {
@ -85,10 +85,23 @@ inpageProvider.enable = function () {
}
}
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
inpageProvider._metamask = new Proxy({
/**

Loading…
Cancel
Save