aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorbitpshr <mail@bitpshr.net>2018-10-02 08:52:31 +0800
committerDan Finlay <542863+danfinlay@users.noreply.github.com>2018-11-06 07:07:09 +0800
commit89b4aa5d62237f36fac9dcce9c546005ec18968b (patch)
tree38bb13f74680cff733c330b2009eddbf4770a098 /app/scripts
parentc76c9ca2c86317f902f443db2c5704d4bf6311c0 (diff)
downloadtangerine-wallet-browser-89b4aa5d62237f36fac9dcce9c546005ec18968b.tar
tangerine-wallet-browser-89b4aa5d62237f36fac9dcce9c546005ec18968b.tar.gz
tangerine-wallet-browser-89b4aa5d62237f36fac9dcce9c546005ec18968b.tar.bz2
tangerine-wallet-browser-89b4aa5d62237f36fac9dcce9c546005ec18968b.tar.lz
tangerine-wallet-browser-89b4aa5d62237f36fac9dcce9c546005ec18968b.tar.xz
tangerine-wallet-browser-89b4aa5d62237f36fac9dcce9c546005ec18968b.tar.zst
tangerine-wallet-browser-89b4aa5d62237f36fac9dcce9c546005ec18968b.zip
EIP-1102: Add option to force-enable provider
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/contentscript.js19
-rw-r--r--app/scripts/controllers/provider-approval.js19
-rw-r--r--app/scripts/inpage.js8
-rw-r--r--app/scripts/metamask-controller.js4
4 files changed, 44 insertions, 6 deletions
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js
index 060343031..1788cfc36 100644
--- a/app/scripts/contentscript.js
+++ b/app/scripts/contentscript.js
@@ -24,6 +24,7 @@ if (shouldInjectWeb3()) {
injectScript(inpageBundle)
setupStreams()
listenForProviderRequest()
+ checkForcedInjection()
}
/**
@@ -134,10 +135,28 @@ function listenForProviderRequest () {
case 'reject-provider-request':
injectScript(`window.dispatchEvent(new CustomEvent('ethereumprovider', { detail: { error: 'User rejected provider access' }}))`)
break
+ case 'force-injection':
+ extension.storage.local.get(['forcedOrigins'], ({ forcedOrigins = [] }) => {
+ extension.storage.local.set({ forcedOrigins: [ ...forcedOrigins, window.location.hostname ] }, () => {
+ injectScript(`window.location.reload()`)
+ })
+ })
+ break
}
})
}
+/**
+ * Checks the current origin to see if it exists in the extension's locally-stored list
+ * off user-whitelisted dapp origins. If it is, this origin will be marked as approved,
+ * meaning the publicConfig stream will be enabled. This is only meant to ease the transition
+ * to 1102 and will be removed in the future.
+ */
+function checkForcedInjection () {
+ extension.storage.local.get(['forcedOrigins'], ({ forcedOrigins = [] }) => {
+ originApproved = forcedOrigins.indexOf(window.location.hostname) > -1
+ })
+}
/**
* Error handler for page to plugin stream disconnections
diff --git a/app/scripts/controllers/provider-approval.js b/app/scripts/controllers/provider-approval.js
index e9b1b8e16..8c7520d59 100644
--- a/app/scripts/controllers/provider-approval.js
+++ b/app/scripts/controllers/provider-approval.js
@@ -1,4 +1,5 @@
const ObservableStore = require('obs-store')
+const extension = require('extensionizer')
/**
* A controller that services user-approved requests for a full Ethereum provider API
@@ -26,9 +27,9 @@ class ProviderApprovalController {
*
* @param {string} origin - Origin of the window requesting full provider access
*/
- handleProviderRequest (origin) {
+ async handleProviderRequest (origin) {
this.store.updateState({ providerRequests: [{ origin }] })
- if (this.approvedOrigins[origin]) {
+ if (await this.isApproved(origin)) {
this.approveProviderRequest(origin)
return
}
@@ -68,6 +69,7 @@ class ProviderApprovalController {
*/
clearApprovedOrigins () {
this.approvedOrigins = {}
+ extension.storage.local.set({ forcedOrigins: [] })
}
/**
@@ -77,7 +79,18 @@ class ProviderApprovalController {
* @returns {boolean} - True if the origin has been approved
*/
isApproved (origin) {
- return this.approvedOrigins[origin]
+ return new Promise(resolve => {
+ extension.storage.local.get(['forcedOrigins'], ({ forcedOrigins = [] }) => {
+ resolve(this.approvedOrigins[origin] || forcedOrigins.indexOf(origin) > -1)
+ })
+ })
+ }
+
+ /**
+ * Called when a user forces the exposure of a full Ethereum provider API
+ */
+ forceInjection () {
+ this.platform.sendMessage({ action: 'force-injection' }, { active: true })
}
}
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js
index 25bfe1416..5b5c02c26 100644
--- a/app/scripts/inpage.js
+++ b/app/scripts/inpage.js
@@ -37,8 +37,12 @@ inpageProvider.enable = function () {
if (typeof detail.error !== 'undefined') {
reject(detail.error)
} else {
- inpageProvider.publicConfigStore.once('update', () => {
- resolve(inpageProvider.send({ method: 'eth_accounts' }).result)
+ inpageProvider.sendAsync({ method: 'eth_accounts', params: [] }, (error, response) => {
+ if (error) {
+ reject(error)
+ } else {
+ resolve(response.result)
+ }
})
}
})
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index cffc5797b..d8f8a4602 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -275,7 +275,8 @@ module.exports = class MetamaskController extends EventEmitter {
getAccounts: async ({ origin }) => {
// Expose no accounts if this origin has not been approved, preventing
// account-requring RPC methods from completing successfully
- if (origin !== 'MetaMask' && !this.providerApprovalController.isApproved(origin)) { return [] }
+ const isApproved = await this.providerApprovalController.isApproved(origin)
+ if (origin !== 'MetaMask' && !isApproved) { return [] }
const isUnlocked = this.keyringController.memStore.getState().isUnlocked
const selectedAddress = this.preferencesController.getSelectedAddress()
// only show address if account is unlocked
@@ -454,6 +455,7 @@ module.exports = class MetamaskController extends EventEmitter {
approveProviderRequest: providerApprovalController.approveProviderRequest.bind(providerApprovalController),
clearApprovedOrigins: providerApprovalController.clearApprovedOrigins.bind(providerApprovalController),
rejectProviderRequest: providerApprovalController.rejectProviderRequest.bind(providerApprovalController),
+ forceInjection: providerApprovalController.forceInjection.bind(providerApprovalController),
}
}