aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/utils/utils.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-05-16 22:18:47 +0800
committerFabio Berger <me@fabioberger.com>2018-05-16 22:18:47 +0800
commit78623ae3bdba39b629a22aa2d15d8aee5e6225ab (patch)
treef44871dc1b081669c83cf041cebe559ecb57bace /packages/website/ts/utils/utils.ts
parent136c6d01b3f01e6db8aab01c4b4b7315abadba24 (diff)
parent4de6221825447e77d7b1ee6bab28ce3407939301 (diff)
downloaddexon-sol-tools-78623ae3bdba39b629a22aa2d15d8aee5e6225ab.tar
dexon-sol-tools-78623ae3bdba39b629a22aa2d15d8aee5e6225ab.tar.gz
dexon-sol-tools-78623ae3bdba39b629a22aa2d15d8aee5e6225ab.tar.bz2
dexon-sol-tools-78623ae3bdba39b629a22aa2d15d8aee5e6225ab.tar.lz
dexon-sol-tools-78623ae3bdba39b629a22aa2d15d8aee5e6225ab.tar.xz
dexon-sol-tools-78623ae3bdba39b629a22aa2d15d8aee5e6225ab.tar.zst
dexon-sol-tools-78623ae3bdba39b629a22aa2d15d8aee5e6225ab.zip
Merge branch 'development' into v2-prototype
* development: (29 commits) Do not remove artifacts when running `clean` fix style errors Fix circular dependency Add my profile image to images Add myself to about page Add dogfood configs to website Revert to lerna:run lint Do lint sequentially Exclude monorepo-scripts from tslint as test Fix prettier Add hover state to top tokens Change to weekly txn volume Change minimum Node version to 6.12 Document Node.js version requirement and add it to package.json Apply prettier to some files which were not formatted correctly Fix TSLint issues Fix TSLint issues Update ethereeumjs-testrpc to ganache-cli Fix infinite loop Add changelog entries for packages where executable binary exporting fixed ... # Conflicts: # packages/contracts/package.json # packages/contracts/util/formatters.ts # packages/contracts/util/signed_order_utils.ts # packages/migrations/package.json # yarn.lock
Diffstat (limited to 'packages/website/ts/utils/utils.ts')
-rw-r--r--packages/website/ts/utils/utils.ts34
1 files changed, 20 insertions, 14 deletions
diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts
index 472870f31..3c99bd2fe 100644
--- a/packages/website/ts/utils/utils.ts
+++ b/packages/website/ts/utils/utils.ts
@@ -24,16 +24,18 @@ import * as u2f from 'ts/vendor/u2f_api';
const LG_MIN_EM = 64;
const MD_MIN_EM = 52;
+const isDogfood = (): boolean => _.includes(window.location.href, configs.DOMAIN_DOGFOOD);
+
export const utils = {
- assert(condition: boolean, message: string) {
+ assert(condition: boolean, message: string): void {
if (!condition) {
throw new Error(message);
}
},
- spawnSwitchErr(name: string, value: any) {
+ spawnSwitchErr(name: string, value: any): Error {
return new Error(`Unexpected switch value: ${value} encountered for ${name}`);
},
- isNumeric(n: string) {
+ isNumeric(n: string): boolean {
return !isNaN(parseFloat(n)) && isFinite(Number(n));
},
// This default unix timestamp is used for orders where the user does not specify an expiry date.
@@ -106,13 +108,13 @@ export const utils = {
};
return order;
},
- async sleepAsync(ms: number) {
- return new Promise(resolve => setTimeout(resolve, ms));
+ async sleepAsync(ms: number): Promise<NodeJS.Timer> {
+ return new Promise<NodeJS.Timer>(resolve => setTimeout(resolve, ms));
},
- deepEqual(actual: any, expected: any, opts?: { strict: boolean }) {
+ deepEqual(actual: any, expected: any, opts?: { strict: boolean }): boolean {
return deepEqual(actual, expected, opts);
},
- getColSize(items: number) {
+ getColSize(items: number): number {
const bassCssGridSize = 12; // Source: http://basscss.com/#basscss-grid
const colSize = bassCssGridSize / items;
if (!_.isInteger(colSize)) {
@@ -120,7 +122,7 @@ export const utils = {
}
return colSize;
},
- getScreenWidth() {
+ getScreenWidth(): ScreenWidths {
const documentEl = document.documentElement;
const body = document.getElementsByTagName('body')[0];
const widthInPx = window.innerWidth || documentEl.clientWidth || body.clientWidth;
@@ -162,7 +164,7 @@ export const utils = {
// This checks the error message returned from an injected Web3 instance on the page
// after a user was prompted to sign a message or send a transaction and decided to
// reject the request.
- didUserDenyWeb3Request(errMsg: string) {
+ didUserDenyWeb3Request(errMsg: string): boolean {
const metamaskDenialErrMsg = 'User denied';
const paritySignerDenialErrMsg = 'Request has been rejected';
const ledgerDenialErrMsg = 'Invalid status 6985';
@@ -172,7 +174,7 @@ export const utils = {
_.includes(errMsg, ledgerDenialErrMsg);
return isUserDeniedErrMsg;
},
- getCurrentEnvironment() {
+ getCurrentEnvironment(): string {
switch (location.host) {
case configs.DOMAIN_DEVELOPMENT:
return 'development';
@@ -188,7 +190,7 @@ export const utils = {
const truncatedAddress = `${address.substring(0, 6)}...${address.substr(-4)}`; // 0x3d5a...b287
return truncatedAddress;
},
- hasUniqueNameAndSymbol(tokens: Token[], token: Token) {
+ hasUniqueNameAndSymbol(tokens: Token[], token: Token): boolean {
if (token.isRegistered) {
return true; // Since it's registered, it is the canonical token
}
@@ -269,7 +271,7 @@ export const utils = {
);
return isTestNetwork;
},
- getCurrentBaseUrl() {
+ getCurrentBaseUrl(): string {
const port = window.location.port;
const hasPort = !_.isUndefined(port);
const baseUrl = `https://${window.location.hostname}${hasPort ? `:${port}` : ''}`;
@@ -302,10 +304,14 @@ export const utils = {
}
return parsedProviderName;
},
- isDevelopment() {
+ getBackendBaseUrl(): string {
+ return isDogfood() ? configs.BACKEND_BASE_STAGING_URL : configs.BACKEND_BASE_PROD_URL;
+ },
+ isDevelopment(): boolean {
return configs.ENVIRONMENT === Environments.DEVELOPMENT;
},
- isStaging() {
+ isStaging(): boolean {
return _.includes(window.location.href, configs.DOMAIN_STAGING);
},
+ isDogfood,
};