aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2018-03-07 06:59:09 +0800
committerDan Finlay <dan@danfinlay.com>2018-03-07 06:59:09 +0800
commit423f084cb47d84e2e9063a6567454f83592f424b (patch)
treebc2f3040cd76765fa27bbfc0e3913cf5e466c063 /app/scripts/lib
parent8ba64c657ff801425c06db166e2c9a06289047de (diff)
parent303801d2768a264a27a51916e5debf778739ee0c (diff)
downloadtangerine-wallet-browser-423f084cb47d84e2e9063a6567454f83592f424b.tar
tangerine-wallet-browser-423f084cb47d84e2e9063a6567454f83592f424b.tar.gz
tangerine-wallet-browser-423f084cb47d84e2e9063a6567454f83592f424b.tar.bz2
tangerine-wallet-browser-423f084cb47d84e2e9063a6567454f83592f424b.tar.lz
tangerine-wallet-browser-423f084cb47d84e2e9063a6567454f83592f424b.tar.xz
tangerine-wallet-browser-423f084cb47d84e2e9063a6567454f83592f424b.tar.zst
tangerine-wallet-browser-423f084cb47d84e2e9063a6567454f83592f424b.zip
Merge branch 'master' into i3076-UseStorageLocalInstead
Diffstat (limited to 'app/scripts/lib')
-rw-r--r--app/scripts/lib/config-manager.js11
-rw-r--r--app/scripts/lib/environment-type.js10
-rw-r--r--app/scripts/lib/is-popup-or-notification.js5
-rw-r--r--app/scripts/lib/nonce-tracker.js2
-rw-r--r--app/scripts/lib/notification-manager.js2
-rw-r--r--app/scripts/lib/reportFailedTxToSentry.js38
-rw-r--r--app/scripts/lib/setupMetamaskMeshMetrics.js9
-rw-r--r--app/scripts/lib/setupRaven.js26
-rw-r--r--app/scripts/lib/tx-gas-utils.js5
-rw-r--r--app/scripts/lib/tx-state-manager.js11
10 files changed, 114 insertions, 5 deletions
diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js
index 9c0dffe9c..34b603b96 100644
--- a/app/scripts/lib/config-manager.js
+++ b/app/scripts/lib/config-manager.js
@@ -42,6 +42,17 @@ ConfigManager.prototype.getData = function () {
return this.store.getState()
}
+ConfigManager.prototype.setPasswordForgotten = function (passwordForgottenState) {
+ const data = this.getData()
+ data.forgottenPassword = passwordForgottenState
+ this.setData(data)
+}
+
+ConfigManager.prototype.getPasswordForgotten = function (passwordForgottenState) {
+ const data = this.getData()
+ return data.forgottenPassword
+}
+
ConfigManager.prototype.setWallet = function (wallet) {
var data = this.getData()
data.wallet = wallet
diff --git a/app/scripts/lib/environment-type.js b/app/scripts/lib/environment-type.js
new file mode 100644
index 000000000..7966926eb
--- /dev/null
+++ b/app/scripts/lib/environment-type.js
@@ -0,0 +1,10 @@
+module.exports = function environmentType () {
+ const url = window.location.href
+ if (url.match(/popup.html$/)) {
+ return 'popup'
+ } else if (url.match(/home.html$/)) {
+ return 'responsive'
+ } else {
+ return 'notification'
+ }
+}
diff --git a/app/scripts/lib/is-popup-or-notification.js b/app/scripts/lib/is-popup-or-notification.js
index 693fa8751..e2999411f 100644
--- a/app/scripts/lib/is-popup-or-notification.js
+++ b/app/scripts/lib/is-popup-or-notification.js
@@ -1,6 +1,9 @@
module.exports = function isPopupOrNotification () {
const url = window.location.href
- if (url.match(/popup.html$/)) {
+ // if (url.match(/popup.html$/) || url.match(/home.html$/)) {
+ // Below regexes needed for feature toggles (e.g. see line ~340 in ui/app/app.js)
+ // Revert below regexes to above commented out regexes before merge to master
+ if (url.match(/popup.html(?:\?.+)*$/) || url.match(/home.html(?:\?.+)*$/)) {
return 'popup'
} else {
return 'notification'
diff --git a/app/scripts/lib/nonce-tracker.js b/app/scripts/lib/nonce-tracker.js
index 0029ac953..ed9dd3f11 100644
--- a/app/scripts/lib/nonce-tracker.js
+++ b/app/scripts/lib/nonce-tracker.js
@@ -56,7 +56,7 @@ class NonceTracker {
const blockTracker = this._getBlockTracker()
const currentBlock = blockTracker.getCurrentBlock()
if (currentBlock) return currentBlock
- return await Promise((reject, resolve) => {
+ return await new Promise((reject, resolve) => {
blockTracker.once('latest', resolve)
})
}
diff --git a/app/scripts/lib/notification-manager.js b/app/scripts/lib/notification-manager.js
index 7846ef7f0..adaf60c65 100644
--- a/app/scripts/lib/notification-manager.js
+++ b/app/scripts/lib/notification-manager.js
@@ -1,5 +1,5 @@
const extension = require('extensionizer')
-const height = 520
+const height = 620
const width = 360
diff --git a/app/scripts/lib/reportFailedTxToSentry.js b/app/scripts/lib/reportFailedTxToSentry.js
new file mode 100644
index 000000000..ee73f6845
--- /dev/null
+++ b/app/scripts/lib/reportFailedTxToSentry.js
@@ -0,0 +1,38 @@
+const ethJsRpcSlug = 'Error: [ethjs-rpc] rpc error with payload '
+const errorLabelPrefix = 'Error: '
+
+module.exports = reportFailedTxToSentry
+
+//
+// utility for formatting failed transaction messages
+// for sending to sentry
+//
+
+function reportFailedTxToSentry({ raven, txMeta }) {
+ const errorMessage = extractErrorMessage(txMeta.err.message)
+ raven.captureMessage(errorMessage, {
+ // "extra" key is required by Sentry
+ extra: txMeta,
+ })
+}
+
+//
+// ethjs-rpc provides overly verbose error messages
+// if we detect this type of message, we extract the important part
+// Below is an example input and output
+//
+// Error: [ethjs-rpc] rpc error with payload {"id":3947817945380,"jsonrpc":"2.0","params":["0xf8eb8208708477359400830398539406012c8cf97bead5deae237070f9587f8e7a266d80b8843d7d3f5a0000000000000000000000000000000000000000000000000000000000081d1a000000000000000000000000000000000000000000000000001ff973cafa800000000000000000000000000000000000000000000000000000038d7ea4c68000000000000000000000000000000000000000000000000000000000000003f48025a04c32a9b630e0d9e7ff361562d850c86b7a884908135956a7e4a336fa0300d19ca06830776423f25218e8d19b267161db526e66895567147015b1f3fc47aef9a3c7"],"method":"eth_sendRawTransaction"} Error: replacement transaction underpriced
+//
+// Transaction Failed: replacement transaction underpriced
+//
+
+function extractErrorMessage(errorMessage) {
+ const isEthjsRpcError = errorMessage.includes(ethJsRpcSlug)
+ if (isEthjsRpcError) {
+ const payloadAndError = errorMessage.slice(ethJsRpcSlug.length)
+ const originalError = payloadAndError.slice(payloadAndError.indexOf(errorLabelPrefix) + errorLabelPrefix.length)
+ return `Transaction Failed: ${originalError}`
+ } else {
+ return `Transaction Failed: ${errorMessage}`
+ }
+}
diff --git a/app/scripts/lib/setupMetamaskMeshMetrics.js b/app/scripts/lib/setupMetamaskMeshMetrics.js
new file mode 100644
index 000000000..40343f017
--- /dev/null
+++ b/app/scripts/lib/setupMetamaskMeshMetrics.js
@@ -0,0 +1,9 @@
+
+module.exports = setupMetamaskMeshMetrics
+
+function setupMetamaskMeshMetrics() {
+ const testingContainer = document.createElement('iframe')
+ testingContainer.src = 'https://metamask.github.io/mesh-testing/'
+ console.log('Injecting MetaMask Mesh testing client')
+ document.head.appendChild(testingContainer)
+}
diff --git a/app/scripts/lib/setupRaven.js b/app/scripts/lib/setupRaven.js
new file mode 100644
index 000000000..42e48cb90
--- /dev/null
+++ b/app/scripts/lib/setupRaven.js
@@ -0,0 +1,26 @@
+const Raven = require('../vendor/raven.min.js')
+const METAMASK_DEBUG = 'GULP_METAMASK_DEBUG'
+const PROD = 'https://3567c198f8a8412082d32655da2961d0@sentry.io/273505'
+const DEV = 'https://f59f3dd640d2429d9d0e2445a87ea8e1@sentry.io/273496'
+
+module.exports = setupRaven
+
+// Setup raven / sentry remote error reporting
+function setupRaven(opts) {
+ const { release } = opts
+ let ravenTarget
+
+ if (METAMASK_DEBUG) {
+ console.log('Setting up Sentry Remote Error Reporting: DEV')
+ ravenTarget = DEV
+ } else {
+ console.log('Setting up Sentry Remote Error Reporting: PROD')
+ ravenTarget = PROD
+ }
+
+ Raven.config(ravenTarget, {
+ release,
+ }).install()
+
+ return Raven
+}
diff --git a/app/scripts/lib/tx-gas-utils.js b/app/scripts/lib/tx-gas-utils.js
index f68f3a9e2..6f6ff7852 100644
--- a/app/scripts/lib/tx-gas-utils.js
+++ b/app/scripts/lib/tx-gas-utils.js
@@ -4,6 +4,7 @@ const {
BnMultiplyByFraction,
bnToHex,
} = require('./util')
+const addHexPrefix = require('ethereumjs-util').addHexPrefix
const SIMPLE_GAS_COST = '0x5208' // Hex for 21000, cost of a simple send.
/*
@@ -13,7 +14,7 @@ and used to do things like calculate gas of a tx.
*/
module.exports = class TxGasUtil {
-
+
constructor (provider) {
this.query = new EthQuery(provider)
}
@@ -68,7 +69,7 @@ module.exports = class TxGasUtil {
}
setTxGas (txMeta, blockGasLimitHex, estimatedGasHex) {
- txMeta.estimatedGas = estimatedGasHex
+ txMeta.estimatedGas = addHexPrefix(estimatedGasHex)
const txParams = txMeta.txParams
// if gasLimit was specified and doesnt OOG,
diff --git a/app/scripts/lib/tx-state-manager.js b/app/scripts/lib/tx-state-manager.js
index a8ef39891..051efd247 100644
--- a/app/scripts/lib/tx-state-manager.js
+++ b/app/scripts/lib/tx-state-manager.js
@@ -221,6 +221,17 @@ module.exports = class TransactionStateManger extends EventEmitter {
this._setTxStatus(txId, 'failed')
}
+ wipeTransactions (address) {
+ // network only tx
+ const txs = this.getFullTxList()
+ const network = this.getNetwork()
+
+ // Filter out the ones from the current account and network
+ const otherAccountTxs = txs.filter((txMeta) => !(txMeta.txParams.from === address && txMeta.metamaskNetworkId === network))
+
+ // Update state
+ this._saveTxList(otherAccountTxs)
+ }
//
// PRIVATE METHODS
//