|
|
@ -4,6 +4,11 @@ const ObservableStore = require('obs-store') |
|
|
|
* A controller that services user-approved requests for a full Ethereum provider API |
|
|
|
* A controller that services user-approved requests for a full Ethereum provider API |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class ProviderApprovalController { |
|
|
|
class ProviderApprovalController { |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Determines if caching is enabled |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
caching = false |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a ProviderApprovalController |
|
|
|
* Creates a ProviderApprovalController |
|
|
|
* |
|
|
|
* |
|
|
@ -44,7 +49,7 @@ class ProviderApprovalController { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
_handleProviderRequest (origin) { |
|
|
|
_handleProviderRequest (origin) { |
|
|
|
this.store.updateState({ providerRequests: [{ origin }] }) |
|
|
|
this.store.updateState({ providerRequests: [{ origin }] }) |
|
|
|
if (this.isApproved(origin)) { |
|
|
|
if (this.isApproved(origin) && this.caching) { |
|
|
|
this.approveProviderRequest(origin) |
|
|
|
this.approveProviderRequest(origin) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -57,8 +62,9 @@ class ProviderApprovalController { |
|
|
|
* @param {string} origin - Origin of the window |
|
|
|
* @param {string} origin - Origin of the window |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
_handleIsApproved (origin) { |
|
|
|
_handleIsApproved (origin) { |
|
|
|
const isApproved = this.isApproved(origin) |
|
|
|
const isApproved = this.isApproved(origin) && this.caching |
|
|
|
this.platform && this.platform.sendMessage({ action: 'answer-is-approved', isApproved }, { active: true }) |
|
|
|
const caching = this.caching |
|
|
|
|
|
|
|
this.platform && this.platform.sendMessage({ action: 'answer-is-approved', isApproved, caching }, { active: true }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -125,6 +131,14 @@ class ProviderApprovalController { |
|
|
|
const privacyMode = this.preferencesController.getFeatureFlags().privacyMode |
|
|
|
const privacyMode = this.preferencesController.getFeatureFlags().privacyMode |
|
|
|
return !privacyMode || this.approvedOrigins[origin] |
|
|
|
return !privacyMode || this.approvedOrigins[origin] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Tells all tabs that MetaMask is now locked. This is primarily used to set |
|
|
|
|
|
|
|
* internal flags in the contentscript and inpage script. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
setLocked () { |
|
|
|
|
|
|
|
this.platform.sendMessage({ action: 'metamask-set-locked' }) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = ProviderApprovalController |
|
|
|
module.exports = ProviderApprovalController |
|
|
|