aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-08-23 11:06:59 +0800
committerDan Finlay <dan@danfinlay.com>2016-08-23 11:06:59 +0800
commit49ab51d8251a403e242de179541fddaa0d76031e (patch)
tree1657397d981c0def2bf8980bc365853f2b1be3a6 /app
parenta9b53530b64cbe33f85d62c8042a72dd41353f26 (diff)
parent9dad3a5917308cb6d9ee56aa183298b8eaad1c5f (diff)
downloadtangerine-wallet-browser-49ab51d8251a403e242de179541fddaa0d76031e.tar
tangerine-wallet-browser-49ab51d8251a403e242de179541fddaa0d76031e.tar.gz
tangerine-wallet-browser-49ab51d8251a403e242de179541fddaa0d76031e.tar.bz2
tangerine-wallet-browser-49ab51d8251a403e242de179541fddaa0d76031e.tar.lz
tangerine-wallet-browser-49ab51d8251a403e242de179541fddaa0d76031e.tar.xz
tangerine-wallet-browser-49ab51d8251a403e242de179541fddaa0d76031e.tar.zst
tangerine-wallet-browser-49ab51d8251a403e242de179541fddaa0d76031e.zip
Merge branch 'master' into PopupNotifications
Diffstat (limited to 'app')
-rw-r--r--app/scripts/inpage.js2
-rw-r--r--app/scripts/lib/config-manager.js6
-rw-r--r--app/scripts/lib/inpage-provider.js30
3 files changed, 35 insertions, 3 deletions
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js
index 7c508c66f..28a1223ac 100644
--- a/app/scripts/inpage.js
+++ b/app/scripts/inpage.js
@@ -54,7 +54,7 @@ var __define
function cleanContextForImports () {
__define = global.define
try {
- delete global.define
+ global.define = undefined
} catch (_) {
console.warn('MetaMask - global.define could not be deleted.')
}
diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js
index 6f5cb3a4a..4d270bcdb 100644
--- a/app/scripts/lib/config-manager.js
+++ b/app/scripts/lib/config-manager.js
@@ -5,6 +5,7 @@ const rp = require('request-promise')
const TESTNET_RPC = MetamaskConfig.network.testnet
const MAINNET_RPC = MetamaskConfig.network.mainnet
+const txLimit = 40
/* The config-manager is a convenience object
* wrapping a pojo-migrator.
@@ -15,6 +16,8 @@ const MAINNET_RPC = MetamaskConfig.network.mainnet
*/
module.exports = ConfigManager
function ConfigManager (opts) {
+ this.txLimit = txLimit
+
// ConfigManager is observable and will emit updates
this._subs = []
@@ -181,6 +184,9 @@ ConfigManager.prototype._saveTxList = function (txList) {
ConfigManager.prototype.addTx = function (tx) {
var transactions = this.getTxList()
+ while (transactions.length > this.txLimit - 1) {
+ transactions.shift()
+ }
transactions.push(tx)
this._saveTxList(transactions)
}
diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js
index b3ed3d9e2..65354cd3d 100644
--- a/app/scripts/lib/inpage-provider.js
+++ b/app/scripts/lib/inpage-provider.js
@@ -33,8 +33,16 @@ function MetamaskInpageProvider (connectionStream) {
})
asyncProvider.on('error', console.error.bind(console))
self.asyncProvider = asyncProvider
- // overwrite own sendAsync method
- self.sendAsync = asyncProvider.sendAsync.bind(asyncProvider)
+ // handle sendAsync requests via asyncProvider
+ self.sendAsync = function(payload, cb){
+ // rewrite request ids
+ var request = jsonrpcMessageTransform(payload, (message) => {
+ message.id = createRandomId()
+ return message
+ })
+ // forward to asyncProvider
+ asyncProvider.sendAsync(request, cb)
+ }
}
MetamaskInpageProvider.prototype.send = function (payload) {
@@ -92,3 +100,21 @@ function remoteStoreWithLocalStorageCache (storageKey) {
return store
}
+
+function createRandomId(){
+ const extraDigits = 3
+ // 13 time digits
+ const datePart = new Date().getTime() * Math.pow(10, extraDigits)
+ // 3 random digits
+ const extraPart = Math.floor(Math.random() * Math.pow(10, extraDigits))
+ // 16 digits
+ return datePart + extraPart
+}
+
+function jsonrpcMessageTransform(payload, transformFn){
+ if (Array.isArray(payload)) {
+ return payload.map(transformFn)
+ } else {
+ return transformFn(payload)
+ }
+} \ No newline at end of file