diff options
Diffstat (limited to 'app/scripts/lib')
-rw-r--r-- | app/scripts/lib/auto-reload.js | 5 | ||||
-rw-r--r-- | app/scripts/lib/config-manager.js | 11 | ||||
-rw-r--r-- | app/scripts/lib/encryptor.js | 12 | ||||
-rw-r--r-- | app/scripts/lib/idStore-migrator.js | 6 | ||||
-rw-r--r-- | app/scripts/lib/idStore.js | 32 | ||||
-rw-r--r-- | app/scripts/lib/inpage-provider.js | 4 | ||||
-rw-r--r-- | app/scripts/lib/is-popup-or-notification.js | 2 | ||||
-rw-r--r-- | app/scripts/lib/notifications.js | 12 | ||||
-rw-r--r-- | app/scripts/lib/sig-util.js | 5 |
9 files changed, 52 insertions, 37 deletions
diff --git a/app/scripts/lib/auto-reload.js b/app/scripts/lib/auto-reload.js index 3c90905db..1302df35f 100644 --- a/app/scripts/lib/auto-reload.js +++ b/app/scripts/lib/auto-reload.js @@ -18,17 +18,16 @@ function setupDappAutoReload (web3) { return handleResetRequest - function handleResetRequest() { + function handleResetRequest () { resetWasRequested = true // ignore if web3 was not used if (!pageIsUsingWeb3) return // reload after short timeout setTimeout(triggerReset, 500) } - } // reload the page function triggerReset () { global.location.reload() -}
\ No newline at end of file +} diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index f50d95c12..faf64bfdc 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -290,7 +290,7 @@ ConfigManager.prototype.getSalt = function () { return ('salt' in data) && data.salt } -ConfigManager.prototype.setSalt = function(salt) { +ConfigManager.prototype.setSalt = function (salt) { var data = this.getData() data.salt = salt this.setData(data) @@ -313,15 +313,15 @@ ConfigManager.prototype._emitUpdates = function (state) { }) } -ConfigManager.prototype.setConfirmed = function (confirmed) { +ConfigManager.prototype.setConfirmedDisclaimer = function (confirmed) { var data = this.getData() - data.isConfirmed = confirmed + data.isDisclaimerConfirmed = confirmed this.setData(data) } -ConfigManager.prototype.getConfirmed = function () { +ConfigManager.prototype.getConfirmedDisclaimer = function () { var data = this.getData() - return ('isConfirmed' in data) && data.isConfirmed + return ('isDisclaimerConfirmed' in data) && data.isDisclaimerConfirmed } ConfigManager.prototype.setTOSHash = function (hash) { @@ -358,7 +358,6 @@ ConfigManager.prototype.updateConversionRate = function () { this.setConversionPrice(0) this.setConversionDate('N/A') }) - } ConfigManager.prototype.setConversionPrice = function (price) { diff --git a/app/scripts/lib/encryptor.js b/app/scripts/lib/encryptor.js index fe83b86dd..2af2a1d2b 100644 --- a/app/scripts/lib/encryptor.js +++ b/app/scripts/lib/encryptor.js @@ -26,7 +26,7 @@ module.exports = { generateSalt, } -// Takes a Pojo, returns encrypted text. +// Takes a Pojo, returns cypher text. function encrypt (password, dataObj) { return keyFromPassword(password) .then(function (passwordDerivedKey) { @@ -42,7 +42,7 @@ function encryptWithKey (key, dataObj) { return global.crypto.subtle.encrypt({ name: 'AES-GCM', iv: vector, - }, key, dataBuffer).then(function(buf){ + }, key, dataBuffer).then(function (buf) { var buffer = new Uint8Array(buf) var vectorStr = encodeBufferToBase64(vector) var vaultStr = encodeBufferToBase64(buffer) @@ -63,13 +63,13 @@ function decryptWithKey (key, text) { const encryptedData = decodeBase64ToBuffer(parts[0]) const vector = decodeBase64ToBuffer(parts[1]) return crypto.subtle.decrypt({name: 'AES-GCM', iv: vector}, key, encryptedData) - .then(function(result){ + .then(function (result) { const decryptedData = new Uint8Array(result) const decryptedStr = convertArrayBufferViewtoString(decryptedData) const decryptedObj = JSON.parse(decryptedStr) return decryptedObj }) - .catch(function(reason) { + .catch(function (reason) { throw new Error('Incorrect password') }) } @@ -95,7 +95,7 @@ function convertArrayBufferViewtoString (buffer) { function keyFromPassword (password) { var passBuffer = convertStringToArrayBufferView(password) return global.crypto.subtle.digest('SHA-256', passBuffer) - .then(function (passHash){ + .then(function (passHash) { return global.crypto.subtle.importKey('raw', passHash, {name: 'AES-GCM'}, false, ['encrypt', 'decrypt']) }) } @@ -135,7 +135,7 @@ function encodeBufferToBase64 (buf) { function decodeBase64ToBuffer (base64) { var buf = new Uint8Array(atob(base64).split('') - .map(function(c) { + .map(function (c) { return c.charCodeAt(0) })) return buf diff --git a/app/scripts/lib/idStore-migrator.js b/app/scripts/lib/idStore-migrator.js index 2d1826641..818364720 100644 --- a/app/scripts/lib/idStore-migrator.js +++ b/app/scripts/lib/idStore-migrator.js @@ -11,7 +11,7 @@ module.exports = class IdentityStoreMigrator { } } - oldSeedForPassword( password ) { + oldSeedForPassword (password) { const hasOldVault = this.hasOldVault() const configManager = this.configManager @@ -35,7 +35,7 @@ module.exports = class IdentityStoreMigrator { }) } - serializeVault() { + serializeVault () { const mnemonic = this.idStore._idmgmt.getSeed() const n = this.idStore._getAddresses().length @@ -45,7 +45,7 @@ module.exports = class IdentityStoreMigrator { } } - hasOldVault() { + hasOldVault () { const wallet = this.configManager.getWallet() return wallet } diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js index ef2416cdf..d11c38be1 100644 --- a/app/scripts/lib/idStore.js +++ b/app/scripts/lib/idStore.js @@ -102,7 +102,7 @@ IdentityStore.prototype.getState = function () { isInitialized: !!configManager.getWallet() && !seedWords, isUnlocked: this._isUnlocked(), seedWords: seedWords, - isConfirmed: configManager.getConfirmed(), + isDisclaimerConfirmed: configManager.getConfirmedDisclaimer(), unconfTxs: configManager.unconfirmedTxs(), transactions: configManager.getTxList(), unconfMsgs: messageManager.unconfirmedMsgs(), @@ -243,10 +243,10 @@ IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDone ], didComplete) // perform static analyis on the target contract code - function analyzeForDelegateCall(cb){ + function analyzeForDelegateCall (cb) { if (txParams.to) { query.getCode(txParams.to, (err, result) => { - if (err) return cb(err) + if (err) return cb(err.message || err) var containsDelegateCall = self.checkForDelegateCall(result) txData.containsDelegateCall = containsDelegateCall cb() @@ -256,16 +256,31 @@ IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDone } } - function estimateGas(cb){ - query.estimateGas(txParams, function(err, result){ - if (err) return cb(err) + function estimateGas (cb) { + var estimationParams = extend(txParams) + // 1 billion gas for estimation + var gasLimit = '0x3b9aca00' + estimationParams.gas = gasLimit + query.estimateGas(estimationParams, function (err, result) { + if (err) return cb(err.message || err) + if (result === estimationParams.gas) { + txData.simulationFails = true + query.getBlockByNumber('latest', true, function (err, block) { + if (err) return cb(err) + txData.estimatedGas = block.gasLimit + txData.txParams.gas = block.gasLimit + cb() + }) + return + } txData.estimatedGas = self.addGasBuffer(result) + txData.txParams.gas = txData.estimatedGas cb() }) } function didComplete (err) { - if (err) return cb(err) + if (err) return cb(err.message || err) configManager.addTx(txData) // signal update self._didUpdate() @@ -285,9 +300,10 @@ IdentityStore.prototype.checkForDelegateCall = function (codeHex) { } } -const gasBuffer = new BN('100000', 10) IdentityStore.prototype.addGasBuffer = function (gas) { const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16) + const five = new BN('5', 10) + const gasBuffer = bnGas.div(five) const correct = bnGas.add(gasBuffer) return ethUtil.addHexPrefix(correct.toString(16)) } diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index f1ba2e0ed..c9d617996 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -40,7 +40,7 @@ function MetamaskInpageProvider (connectionStream) { self.idMap = {} // handle sendAsync requests via asyncProvider - self.sendAsync = function(payload, cb){ + self.sendAsync = function (payload, cb) { // rewrite request ids var request = eachJsonMessage(payload, (message) => { var newId = createRandomId() @@ -49,7 +49,7 @@ function MetamaskInpageProvider (connectionStream) { return message }) // forward to asyncProvider - asyncProvider.sendAsync(request, function(err, res){ + asyncProvider.sendAsync(request, function (err, res) { if (err) return cb(err) // transform messages to original ids eachJsonMessage(res, (message) => { diff --git a/app/scripts/lib/is-popup-or-notification.js b/app/scripts/lib/is-popup-or-notification.js index 5c38ac823..693fa8751 100644 --- a/app/scripts/lib/is-popup-or-notification.js +++ b/app/scripts/lib/is-popup-or-notification.js @@ -1,4 +1,4 @@ -module.exports = function isPopupOrNotification() { +module.exports = function isPopupOrNotification () { const url = window.location.href if (url.match(/popup.html$/)) { return 'popup' diff --git a/app/scripts/lib/notifications.js b/app/scripts/lib/notifications.js index cd7535232..3db1ac6b5 100644 --- a/app/scripts/lib/notifications.js +++ b/app/scripts/lib/notifications.js @@ -15,12 +15,9 @@ function show () { if (err) throw err if (popup) { - // bring focus to existing popup extension.windows.update(popup.id, { focused: true }) - } else { - // create new popup extension.windows.create({ url: 'notification.html', @@ -29,12 +26,11 @@ function show () { width, height, }) - } }) } -function getWindows(cb) { +function getWindows (cb) { // Ignore in test environment if (!extension.windows) { return cb() @@ -45,14 +41,14 @@ function getWindows(cb) { }) } -function getPopup(cb) { +function getPopup (cb) { getWindows((err, windows) => { if (err) throw err cb(null, getPopupIn(windows)) }) } -function getPopupIn(windows) { +function getPopupIn (windows) { return windows ? windows.find((win) => { return (win && win.type === 'popup' && win.height === height && @@ -60,7 +56,7 @@ function getPopupIn(windows) { }) : null } -function closePopup() { +function closePopup () { getPopup((err, popup) => { if (err) throw err if (!popup) return diff --git a/app/scripts/lib/sig-util.js b/app/scripts/lib/sig-util.js index f8748f535..193dda381 100644 --- a/app/scripts/lib/sig-util.js +++ b/app/scripts/lib/sig-util.js @@ -12,6 +12,11 @@ module.exports = { return ethUtil.addHexPrefix(rStr.concat(sStr, vStr)).toString('hex') }, + normalize: function (address) { + if (!address) return + return ethUtil.addHexPrefix(address.toLowerCase()) + }, + } function padWithZeroes (number, length) { |