aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/background.js17
-rw-r--r--app/scripts/lib/config-manager.js11
-rw-r--r--app/scripts/metamask-controller.js35
3 files changed, 61 insertions, 2 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 652acc113..92a76b31e 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -8,6 +8,9 @@ const messageManager = require('./lib/message-manager')
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
const MetamaskController = require('./metamask-controller')
const extension = require('./lib/extension')
+const fs = require('fs')
+const disclaimer = fs.readFileSync(path.join(__dirname, '..', '..', 'USER_AGREEMENT.md')).toString()
+const stringHash = require('string-hash')
const STORAGE_KEY = 'metamask-config'
var popupIsOpen = false
@@ -29,8 +32,20 @@ function triggerUi () {
// On first install, open a window to MetaMask website to how-it-works.
extension.runtime.onInstalled.addListener(function (details) {
+ const newTOSHash = stringHash(disclaimer)
if (details.reason === 'install') {
- extension.tabs.create({url: 'https://metamask.io/#how-it-works'})
+ controller.setTOSHash(newTOSHash, () => {
+ extension.tabs.create({url: 'https://metamask.io/#how-it-works'})
+ })
+ } else if (details.reason === 'update') {
+ controller.checkTOSChange(newTOSHash, (hasChanged) => {
+ if (hasChanged) {
+ controller.resetDisclaimer()
+ controller.setTOSHash(newTOSHash, () => {
+ extension.tabs.create({url: 'https://metamask.io/terms.html'})
+ })
+ }
+ })
}
})
diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js
index 715efb42e..8d37afd29 100644
--- a/app/scripts/lib/config-manager.js
+++ b/app/scripts/lib/config-manager.js
@@ -277,6 +277,17 @@ ConfigManager.prototype.getConfirmed = function () {
return ('isConfirmed' in data) && data.isConfirmed
}
+ConfigManager.prototype.setTOSHash = function (version) {
+ var data = this.getData()
+ data.TOSHash = version
+ this.setData(data)
+}
+
+ConfigManager.prototype.getTOSHash = function () {
+ var data = this.getData()
+ return ('TOSHash' in data) && data.TOSHash
+}
+
ConfigManager.prototype.setCurrentFiat = function (currency) {
var data = this.getData()
data.fiatCurrency = currency
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 03082013a..0a37bf292 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -25,6 +25,7 @@ module.exports = class MetamaskController {
var currentFiat = this.configManager.getCurrentFiat() || 'USD'
this.configManager.setCurrentFiat(currentFiat)
this.configManager.updateConversionRate()
+ this.configManager.setTOSHash(0)
this.scheduleConversionInterval()
}
@@ -45,8 +46,11 @@ module.exports = class MetamaskController {
setProviderType: this.setProviderType.bind(this),
useEtherscanProvider: this.useEtherscanProvider.bind(this),
agreeToDisclaimer: this.agreeToDisclaimer.bind(this),
+ resetDisclaimer: this.resetDisclaimer.bind(this),
setCurrentFiat: this.setCurrentFiat.bind(this),
agreeToEthWarning: this.agreeToEthWarning.bind(this),
+ setTOSHash: this.setTOSHash.bind(this),
+ checkTOSChange: this.checkTOSChange.bind(this),
// forward directly to idStore
createNewVault: idStore.createNewVault.bind(idStore),
@@ -261,6 +265,26 @@ module.exports = class MetamaskController {
// config
//
+ setTOSHash (hash, cb) {
+ try {
+ this.configManager.setTOSHash(hash)
+ cb(this.configManager.getTOSHash())
+ } catch (e) {
+ cb(null, e)
+ }
+ }
+
+ checkTOSChange (newHash, cb) {
+ try {
+ var currentHash = this.configManager.getTOSHash()
+ var change = !(currentHash === newHash)
+ cb(change)
+ } catch (e) {
+ cb(null, e)
+ }
+
+ }
+
agreeToDisclaimer (cb) {
try {
this.configManager.setConfirmed(true)
@@ -270,6 +294,14 @@ module.exports = class MetamaskController {
}
}
+ resetDisclaimer () {
+ try {
+ this.configManager.setConfirmed(false)
+ } catch (e) {
+ console.error(e)
+ }
+ }
+
setCurrentFiat (fiat, cb) {
try {
this.configManager.setCurrentFiat(fiat)
@@ -304,6 +336,8 @@ module.exports = class MetamaskController {
}
}
+
+
// called from popup
setRpcTarget (rpcTarget) {
this.configManager.setRpcTarget(rpcTarget)
@@ -341,4 +375,3 @@ module.exports = class MetamaskController {
this.configManager.createShapeShiftTx(depositAddress, depositType)
}
}
-