aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/utils
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-07-13 06:50:13 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-07-13 06:56:01 +0800
commitac5588c7c436e2540f87e432446e103d35c9221a (patch)
tree75fb70ebf9cfb0aaa3450610f2072a43c3b2f1bc /packages/website/ts/utils
parentddb70a89ad99527e03844d23e7c0f3522e98a602 (diff)
downloaddexon-0x-contracts-ac5588c7c436e2540f87e432446e103d35c9221a.tar
dexon-0x-contracts-ac5588c7c436e2540f87e432446e103d35c9221a.tar.gz
dexon-0x-contracts-ac5588c7c436e2540f87e432446e103d35c9221a.tar.bz2
dexon-0x-contracts-ac5588c7c436e2540f87e432446e103d35c9221a.tar.lz
dexon-0x-contracts-ac5588c7c436e2540f87e432446e103d35c9221a.tar.xz
dexon-0x-contracts-ac5588c7c436e2540f87e432446e103d35c9221a.tar.zst
dexon-0x-contracts-ac5588c7c436e2540f87e432446e103d35c9221a.zip
Make error reporter not return a promise and add more environment possibilities
Diffstat (limited to 'packages/website/ts/utils')
-rw-r--r--packages/website/ts/utils/configs.ts5
-rw-r--r--packages/website/ts/utils/error_reporter.ts22
-rw-r--r--packages/website/ts/utils/fetch_utils.ts3
-rw-r--r--packages/website/ts/utils/utils.ts36
4 files changed, 36 insertions, 30 deletions
diff --git a/packages/website/ts/utils/configs.ts b/packages/website/ts/utils/configs.ts
index 97aabd13d..745328d0a 100644
--- a/packages/website/ts/utils/configs.ts
+++ b/packages/website/ts/utils/configs.ts
@@ -2,10 +2,6 @@ import * as _ from 'lodash';
import { Environments, OutdatedWrappedEtherByNetworkId, PublicNodeUrlsByNetworkId } from 'ts/types';
const BASE_URL = window.location.origin;
-const isDevelopment = _.includes(
- ['https://0xproject.localhost:3572', 'https://localhost:3572', 'https://127.0.0.1'],
- BASE_URL,
-);
const INFURA_API_KEY = 'T5WSC8cautR4KXyYgsRs';
export const configs = {
@@ -21,7 +17,6 @@ export const configs = {
DOMAIN_DOGFOOD: 'dogfood.0xproject.com',
DOMAIN_DEVELOPMENT: '0xproject.localhost:3572',
DOMAIN_PRODUCTION: '0xproject.com',
- ENVIRONMENT: isDevelopment ? Environments.DEVELOPMENT : Environments.PRODUCTION,
GOOGLE_ANALYTICS_ID: 'UA-98720122-1',
LAST_LOCAL_STORAGE_FILL_CLEARANCE_DATE: '2017-11-22',
LAST_LOCAL_STORAGE_TRACKED_TOKEN_CLEARANCE_DATE: '2018-7-5',
diff --git a/packages/website/ts/utils/error_reporter.ts b/packages/website/ts/utils/error_reporter.ts
index 2d0661b25..d38269d92 100644
--- a/packages/website/ts/utils/error_reporter.ts
+++ b/packages/website/ts/utils/error_reporter.ts
@@ -2,6 +2,7 @@ import { logUtils } from '@0xproject/utils';
import { Environments } from 'ts/types';
import { configs } from 'ts/utils/configs';
import { constants } from 'ts/utils/constants';
+import { utils } from 'ts/utils/utils';
// Suggested way to include Rollbar with Webpack
// https://github.com/rollbar/rollbar.js/tree/master/examples/webpack
@@ -12,7 +13,7 @@ const rollbarConfig = {
itemsPerMinute: 10,
maxItems: 500,
payload: {
- environment: configs.ENVIRONMENT,
+ environment: utils.getEnvironment(),
client: {
javascript: {
source_map_enabled: true,
@@ -40,21 +41,14 @@ import Rollbar = require('../../public/js/rollbar.umd.min.js');
const rollbar = Rollbar.init(rollbarConfig);
export const errorReporter = {
- async reportAsync(err: Error): Promise<any> {
- if (configs.ENVIRONMENT === Environments.DEVELOPMENT) {
+ report(err: Error): void {
+ if (utils.getEnvironment() === Environments.DEVELOPMENT) {
return; // Let's not log development errors to rollbar
}
-
- return new Promise((resolve, _reject) => {
- rollbar.error(err, (rollbarErr: Error) => {
- if (rollbarErr) {
- logUtils.log(`Error reporting to rollbar, ignoring: ${rollbarErr}`);
- // We never want to reject and cause the app to throw because of rollbar
- resolve();
- } else {
- resolve();
- }
- });
+ rollbar.error(err, (rollbarErr: Error) => {
+ if (rollbarErr) {
+ logUtils.log(`Error reporting to rollbar, ignoring: ${rollbarErr}`);
+ }
});
},
};
diff --git a/packages/website/ts/utils/fetch_utils.ts b/packages/website/ts/utils/fetch_utils.ts
index 513f7e479..a56d89262 100644
--- a/packages/website/ts/utils/fetch_utils.ts
+++ b/packages/website/ts/utils/fetch_utils.ts
@@ -9,8 +9,7 @@ const logErrorIfPresent = (response: Response, requestedURL: string) => {
const errorText = `Error requesting url: ${requestedURL}, ${response.status}: ${response.statusText}`;
logUtils.log(errorText);
const error = Error(errorText);
- // tslint:disable-next-line:no-floating-promises
- errorReporter.reportAsync(error);
+ errorReporter.report(error);
throw error;
}
};
diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts
index 1d669d8f0..240170113 100644
--- a/packages/website/ts/utils/utils.ts
+++ b/packages/website/ts/utils/utils.ts
@@ -31,8 +31,6 @@ import { constants } from 'ts/utils/constants';
import { errorReporter } from 'ts/utils/error_reporter';
import * as u2f from 'ts/vendor/u2f_api';
-const isDogfood = (): boolean => _.includes(window.location.href, configs.DOMAIN_DOGFOOD);
-
export const utils = {
assert(condition: boolean, message: string): void {
if (!condition) {
@@ -347,10 +345,13 @@ export const utils = {
return parsedProviderName;
},
getBackendBaseUrl(): string {
- return isDogfood() ? configs.BACKEND_BASE_STAGING_URL : configs.BACKEND_BASE_PROD_URL;
+ return utils.isDogfood() ? configs.BACKEND_BASE_STAGING_URL : configs.BACKEND_BASE_PROD_URL;
},
isDevelopment(): boolean {
- return configs.ENVIRONMENT === Environments.DEVELOPMENT;
+ return _.includes(
+ ['https://0xproject.localhost:3572', 'https://localhost:3572', 'https://127.0.0.1'],
+ window.location.origin,
+ );
},
isStaging(): boolean {
return _.includes(window.location.href, configs.DOMAIN_STAGING);
@@ -358,7 +359,27 @@ export const utils = {
isExternallyInjected(providerType: ProviderType, injectedProviderName: string): boolean {
return providerType === ProviderType.Injected && injectedProviderName !== constants.PROVIDER_NAME_PUBLIC;
},
- isDogfood,
+ isDogfood(): boolean {
+ return _.includes(window.location.href, configs.DOMAIN_DOGFOOD);
+ },
+ isProduction(): boolean {
+ return _.includes(window.location.href, configs.DOMAIN_PRODUCTION);
+ },
+ getEnvironment(): Environments {
+ if (utils.isDogfood()) {
+ return Environments.DOGFOOD;
+ }
+ if (utils.isDevelopment()) {
+ return Environments.DEVELOPMENT;
+ }
+ if (utils.isStaging()) {
+ return Environments.STAGING;
+ }
+ if (utils.isProduction()) {
+ return Environments.PRODUCTION;
+ }
+ return undefined;
+ },
shouldShowJobsPage(): boolean {
return this.isDevelopment() || this.isStaging() || this.isDogfood();
},
@@ -391,10 +412,7 @@ export const utils = {
const format = `0,0.${_.repeat('0', precision)}`;
const formattedAmount = numeral(unitAmount).format(format);
if (_.isNaN(formattedAmount)) {
- // tslint:disable-next-line:no-floating-promises
- errorReporter.reportAsync(
- new Error(`amount ${BigNumber}, decimals ${decimals} could not be formatted and returned NaN.`),
- );
+ // https://github.com/adamwdraper/Numeral-js/issues/596
return format;
}
return formattedAmount;