diff options
author | bitpshr <mail@bitpshr.net> | 2018-11-05 22:03:30 +0800 |
---|---|---|
committer | Dan Finlay <542863+danfinlay@users.noreply.github.com> | 2018-11-06 07:07:09 +0800 |
commit | 879997af517b36cf701ec74c08ec4293a2206baa (patch) | |
tree | fdbea02d5c263dd7b3096a1aec35e4f0cdf0b968 /app | |
parent | 26ada8a828ab684c310080a18115a8ef3234aaee (diff) | |
download | tangerine-wallet-browser-879997af517b36cf701ec74c08ec4293a2206baa.tar tangerine-wallet-browser-879997af517b36cf701ec74c08ec4293a2206baa.tar.gz tangerine-wallet-browser-879997af517b36cf701ec74c08ec4293a2206baa.tar.bz2 tangerine-wallet-browser-879997af517b36cf701ec74c08ec4293a2206baa.tar.lz tangerine-wallet-browser-879997af517b36cf701ec74c08ec4293a2206baa.tar.xz tangerine-wallet-browser-879997af517b36cf701ec74c08ec4293a2206baa.tar.zst tangerine-wallet-browser-879997af517b36cf701ec74c08ec4293a2206baa.zip |
Add experimental RPC method support
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/contentscript.js | 1 | ||||
-rw-r--r-- | app/scripts/controllers/provider-approval.js | 8 | ||||
-rw-r--r-- | app/scripts/inpage.js | 17 |
3 files changed, 20 insertions, 6 deletions
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 1cdc85945..2327dc4ac 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.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), diff --git a/app/scripts/controllers/provider-approval.js b/app/scripts/controllers/provider-approval.js index f2d40e67d..f17220cb9 100644 --- a/app/scripts/controllers/provider-approval.js +++ b/app/scripts/controllers/provider-approval.js @@ -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 } diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index 2ca3abde2..e1948a522 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -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({ /** |