From 879997af517b36cf701ec74c08ec4293a2206baa Mon Sep 17 00:00:00 2001 From: bitpshr Date: Mon, 5 Nov 2018 09:03:30 -0500 Subject: Add experimental RPC method support --- app/scripts/inpage.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'app/scripts/inpage.js') 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({ /** -- cgit v1.2.3