aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/util.js
diff options
context:
space:
mode:
authorAlexander Tseung <alextsg@gmail.com>2018-04-17 14:03:47 +0800
committerAlexander Tseung <alextsg@gmail.com>2018-04-17 23:58:37 +0800
commitb0a105ce809b8b7e5e4431bd1ddecc523586cad0 (patch)
treea1b0877175b6555dcded6bb61bc07e1ada81e12d /app/scripts/lib/util.js
parente4eb69dcc290a7e7eb27cab7ec57a8097345d81e (diff)
downloadtangerine-wallet-browser-b0a105ce809b8b7e5e4431bd1ddecc523586cad0.tar
tangerine-wallet-browser-b0a105ce809b8b7e5e4431bd1ddecc523586cad0.tar.gz
tangerine-wallet-browser-b0a105ce809b8b7e5e4431bd1ddecc523586cad0.tar.bz2
tangerine-wallet-browser-b0a105ce809b8b7e5e4431bd1ddecc523586cad0.tar.lz
tangerine-wallet-browser-b0a105ce809b8b7e5e4431bd1ddecc523586cad0.tar.xz
tangerine-wallet-browser-b0a105ce809b8b7e5e4431bd1ddecc523586cad0.tar.zst
tangerine-wallet-browser-b0a105ce809b8b7e5e4431bd1ddecc523586cad0.zip
Fix confirmation popup not always opening
Diffstat (limited to 'app/scripts/lib/util.js')
-rw-r--r--app/scripts/lib/util.js32
1 files changed, 24 insertions, 8 deletions
diff --git a/app/scripts/lib/util.js b/app/scripts/lib/util.js
index 6dee9edf0..df815906f 100644
--- a/app/scripts/lib/util.js
+++ b/app/scripts/lib/util.js
@@ -1,20 +1,27 @@
const ethUtil = require('ethereumjs-util')
const assert = require('assert')
const BN = require('bn.js')
-
-module.exports = {
- getStack,
- sufficientBalance,
- hexToBn,
- bnToHex,
- BnMultiplyByFraction,
-}
+const {
+ ENVIRONMENT_TYPE_POPUP,
+ ENVIRONMENT_TYPE_NOTIFICATION,
+ ENVIRONMENT_TYPE_FULLSCREEN,
+} = require('./enums')
function getStack () {
const stack = new Error('Stack trace generator - not an error').stack
return stack
}
+const getEnvironmentType = (url = window.location.href) => {
+ if (url.match(/popup.html(?:\?.+)*$/)) {
+ return ENVIRONMENT_TYPE_POPUP
+ } else if (url.match(/home.html(?:\?.+)*$/) || url.match(/home.html(?:#.*)*$/)) {
+ return ENVIRONMENT_TYPE_FULLSCREEN
+ } else {
+ return ENVIRONMENT_TYPE_NOTIFICATION
+ }
+}
+
function sufficientBalance (txParams, hexBalance) {
// validate hexBalance is a hex string
assert.equal(typeof hexBalance, 'string', 'sufficientBalance - hexBalance is not a hex string')
@@ -42,3 +49,12 @@ function BnMultiplyByFraction (targetBN, numerator, denominator) {
const denomBN = new BN(denominator)
return targetBN.mul(numBN).div(denomBN)
}
+
+module.exports = {
+ getStack,
+ getEnvironmentType,
+ sufficientBalance,
+ hexToBn,
+ bnToHex,
+ BnMultiplyByFraction,
+}