aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/util.js
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2018-04-19 02:45:48 +0800
committerDan <danjm.com@gmail.com>2018-04-19 02:45:48 +0800
commit649d2f8b229a6a749c0129dd5ef6dcf5b870e6c9 (patch)
treebc1e935331aa3678d18c2ffbcc04e791a711c0aa /app/scripts/lib/util.js
parente80bd230b9bb6ac9ff05d7095f74dd2fd7ebb3af (diff)
parent7e21fc2aa780ccb4ffb2f642156385db22c47a52 (diff)
downloadtangerine-wallet-browser-649d2f8b229a6a749c0129dd5ef6dcf5b870e6c9.tar
tangerine-wallet-browser-649d2f8b229a6a749c0129dd5ef6dcf5b870e6c9.tar.gz
tangerine-wallet-browser-649d2f8b229a6a749c0129dd5ef6dcf5b870e6c9.tar.bz2
tangerine-wallet-browser-649d2f8b229a6a749c0129dd5ef6dcf5b870e6c9.tar.lz
tangerine-wallet-browser-649d2f8b229a6a749c0129dd5ef6dcf5b870e6c9.tar.xz
tangerine-wallet-browser-649d2f8b229a6a749c0129dd5ef6dcf5b870e6c9.tar.zst
tangerine-wallet-browser-649d2f8b229a6a749c0129dd5ef6dcf5b870e6c9.zip
Merge branch 'master' into dm-docs-1
Diffstat (limited to 'app/scripts/lib/util.js')
-rw-r--r--app/scripts/lib/util.js41
1 files changed, 33 insertions, 8 deletions
diff --git a/app/scripts/lib/util.js b/app/scripts/lib/util.js
index cb0d7e5c1..431d1e59c 100644
--- a/app/scripts/lib/util.js
+++ b/app/scripts/lib/util.js
@@ -1,14 +1,11 @@
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')
/**
* Generates an example stack trace
@@ -22,6 +19,25 @@ function getStack () {
}
/**
+ * Used to determine the window type through which the app is being viewed.
+ * - 'popup' refers to the extension opened through the browser app icon (in top right corner in chrome and firefox)
+ * - 'responsive' refers to the main browser window
+ * - 'notification' refers to the popup that appears in its own window when taking action outside of metamask
+ *
+ * @returns {string} A single word label that represents the type of window through which the app is being viewed
+ *
+ */
+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
+ }
+}
+
+/**
* Checks whether a given balance of ETH, represented as a hex string, is sufficient to pay a value plus a gas fee
*
* @param {object} txParams Contains data about a transaction
@@ -82,3 +98,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,
+}