diff options
Diffstat (limited to 'app/scripts/inpage.js')
-rw-r--r-- | app/scripts/inpage.js | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index 83392761e..f8c6cf573 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -29,7 +29,7 @@ console.warn('ATTENTION: In an effort to improve user privacy, MetaMask ' + * @param {Function} handler - event handler * @param {boolean} remove - removes this handler after being triggered */ -function onMessage(messageType, handler, remove) { +function onMessage (messageType, handler, remove) { window.addEventListener('message', function ({ data }) { if (!data || data.type !== messageType) { return } remove && window.removeEventListener('message', handler) @@ -59,7 +59,9 @@ onMessage('metamasksetlocked', () => { isEnabled = false }) // set up a listener for privacy mode responses onMessage('ethereumproviderlegacy', ({ data: { selectedAddress } }) => { isEnabled = true - inpageProvider.publicConfigStore.updateState({ selectedAddress }) + setTimeout(() => { + inpageProvider.publicConfigStore.updateState({ selectedAddress }) + }, 0) }, true) // augment the provider with its enable method @@ -70,7 +72,9 @@ inpageProvider.enable = function ({ force } = {}) { reject(error) } else { window.removeEventListener('message', providerHandle) - inpageProvider.publicConfigStore.updateState({ selectedAddress }) + setTimeout(() => { + inpageProvider.publicConfigStore.updateState({ selectedAddress }) + }, 0) // wait for the background to update with an account inpageProvider.sendAsync({ method: 'eth_accounts', params: [] }, (error, response) => { @@ -104,7 +108,7 @@ inpageProvider._metamask = new Proxy({ * * @returns {Promise<boolean>} - Promise resolving to true if this domain has been previously approved */ - isApproved: function() { + isApproved: function () { return new Promise((resolve) => { isApprovedHandle = ({ data: { caching, isApproved } }) => { if (caching) { @@ -133,7 +137,7 @@ inpageProvider._metamask = new Proxy({ }) }, }, { - get: function(obj, prop) { + get: function (obj, prop) { !warned && console.warn('Heads up! ethereum._metamask exposes methods that have ' + 'not been standardized yet. This means that these methods may not be implemented ' + 'in other dapp browsers and may be removed from MetaMask in the future.') @@ -153,7 +157,7 @@ const proxiedInpageProvider = new Proxy(inpageProvider, { window.ethereum = proxiedInpageProvider // detect eth_requestAccounts and pipe to enable for now -function detectAccountRequest(method) { +function detectAccountRequest (method) { const originalMethod = inpageProvider[method] inpageProvider[method] = function ({ method }) { if (method === 'eth_requestAccounts') { |