aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-07-13 09:11:25 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-07-13 09:11:25 +0800
commitb4747c3f85acb7d2909c5b7673d98055e8daaebe (patch)
tree7bc9fa4528c942d3588d74d901fa31533bccb5e7 /packages
parent254d30b8df4d04111458b639073dfbf9f82bf3d0 (diff)
downloaddexon-0x-contracts-b4747c3f85acb7d2909c5b7673d98055e8daaebe.tar.gz
dexon-0x-contracts-b4747c3f85acb7d2909c5b7673d98055e8daaebe.tar.zst
dexon-0x-contracts-b4747c3f85acb7d2909c5b7673d98055e8daaebe.zip
Refactor utils and add UNNKOWN environment type
Diffstat (limited to 'packages')
-rw-r--r--packages/website/ts/blockchain.ts1
-rw-r--r--packages/website/ts/types.ts1
-rw-r--r--packages/website/ts/utils/configs.ts2
-rw-r--r--packages/website/ts/utils/error_reporter.ts3
-rw-r--r--packages/website/ts/utils/utils.ts36
5 files changed, 16 insertions, 27 deletions
diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts
index 868ffad03..1003cbd06 100644
--- a/packages/website/ts/blockchain.ts
+++ b/packages/website/ts/blockchain.ts
@@ -682,7 +682,6 @@ export class Blockchain {
// Note: it's not entirely clear from the documentation which
// errors will be thrown by `watch`. For now, let's log the error
// to rollbar and stop watching when one occurs
- // tslint:disable-next-line:no-floating-promises
errorReporter.report(err); // fire and forget
return;
} else {
diff --git a/packages/website/ts/types.ts b/packages/website/ts/types.ts
index c2a0f9640..a473e50c3 100644
--- a/packages/website/ts/types.ts
+++ b/packages/website/ts/types.ts
@@ -247,6 +247,7 @@ export enum Environments {
DOGFOOD = 'DOGFOOD',
STAGING = 'STAGING',
PRODUCTION = 'PRODUCTION',
+ UNKNOWN = 'UNKNOWN',
}
export type ContractInstance = any; // TODO: add type definition for Contract
diff --git a/packages/website/ts/utils/configs.ts b/packages/website/ts/utils/configs.ts
index 9652a0925..a1c64f9cb 100644
--- a/packages/website/ts/utils/configs.ts
+++ b/packages/website/ts/utils/configs.ts
@@ -14,7 +14,7 @@ export const configs = {
DEFAULT_TRACKED_TOKEN_SYMBOLS: ['WETH', 'ZRX'],
DOMAIN_STAGING: 'staging-0xproject.s3-website-us-east-1.amazonaws.com',
DOMAIN_DOGFOOD: 'dogfood.0xproject.com',
- DOMAIN_DEVELOPMENT: '0xproject.localhost:3572',
+ DOMAINS_DEVELOPMENT: ['0xproject.localhost:3572', 'localhost:3572', '127.0.0.1'],
DOMAIN_PRODUCTION: '0xproject.com',
GOOGLE_ANALYTICS_ID: 'UA-98720122-1',
LAST_LOCAL_STORAGE_FILL_CLEARANCE_DATE: '2017-11-22',
diff --git a/packages/website/ts/utils/error_reporter.ts b/packages/website/ts/utils/error_reporter.ts
index d38269d92..6008fffed 100644
--- a/packages/website/ts/utils/error_reporter.ts
+++ b/packages/website/ts/utils/error_reporter.ts
@@ -1,5 +1,4 @@
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';
@@ -42,7 +41,7 @@ const rollbar = Rollbar.init(rollbarConfig);
export const errorReporter = {
report(err: Error): void {
- if (utils.getEnvironment() === Environments.DEVELOPMENT) {
+ if (utils.isDevelopment()) {
return; // Let's not log development errors to rollbar
}
rollbar.error(err, (rollbarErr: Error) => {
diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts
index e8152af87..77b0846a9 100644
--- a/packages/website/ts/utils/utils.ts
+++ b/packages/website/ts/utils/utils.ts
@@ -175,18 +175,6 @@ export const utils = {
_.includes(errMsg, ledgerDenialErrMsg);
return isUserDeniedErrMsg;
},
- getCurrentEnvironment(): string {
- switch (location.host) {
- case configs.DOMAIN_DEVELOPMENT:
- return 'development';
- case configs.DOMAIN_STAGING:
- return 'staging';
- case configs.DOMAIN_PRODUCTION:
- return 'production';
- default:
- return 'production';
- }
- },
getAddressBeginAndEnd(address: string): string {
const truncatedAddress = `${address.substring(0, 6)}...${address.substr(-4)}`; // 0x3d5a...b287
return truncatedAddress;
@@ -347,10 +335,7 @@ export const utils = {
return utils.isDogfood() ? configs.BACKEND_BASE_STAGING_URL : configs.BACKEND_BASE_PROD_URL;
},
isDevelopment(): boolean {
- return _.includes(
- ['https://0xproject.localhost:3572', 'https://localhost:3572', 'https://127.0.0.1'],
- window.location.origin,
- );
+ return _.includes(configs.DOMAINS_DEVELOPMENT, window.location.origin);
},
isStaging(): boolean {
return _.includes(window.location.href, configs.DOMAIN_STAGING);
@@ -377,7 +362,7 @@ export const utils = {
if (utils.isProduction()) {
return Environments.PRODUCTION;
}
- return undefined;
+ return Environments.UNKNOWN;
},
shouldShowJobsPage(): boolean {
return this.isDevelopment() || this.isStaging() || this.isDogfood();
@@ -405,21 +390,26 @@ export const utils = {
const unitAmount = Web3Wrapper.toUnitAmount(amount, decimals);
// if the unit amount is less than 1, show the natural number of decimal places with a max of 4
// if the unit amount is greater than or equal to 1, show only 2 decimal places
- const precision = unitAmount.lt(1)
- ? Math.min(constants.TOKEN_AMOUNT_DISPLAY_PRECISION, unitAmount.decimalPlaces())
- : 2;
+ const lessThanOnePrecision = Math.min(constants.TOKEN_AMOUNT_DISPLAY_PRECISION, unitAmount.decimalPlaces());
+ const greaterThanOnePrecision = 2;
+ const precision = unitAmount.lt(1) ? lessThanOnePrecision : greaterThanOnePrecision;
const format = `0,0.${_.repeat('0', precision)}`;
const formattedAmount = numeral(unitAmount).format(format);
if (_.isNaN(formattedAmount)) {
// https://github.com/adamwdraper/Numeral-js/issues/596
- return format;
+ return '0';
}
return formattedAmount;
},
getUsdValueFormattedAmount(amount: BigNumber, decimals: number, price: BigNumber): string {
const unitAmount = Web3Wrapper.toUnitAmount(amount, decimals);
const value = unitAmount.mul(price);
- return numeral(value).format(constants.NUMERAL_USD_FORMAT);
+ const formattedAmount = numeral(value).format(constants.NUMERAL_USD_FORMAT);
+ if (_.isNaN(formattedAmount)) {
+ // https://github.com/adamwdraper/Numeral-js/issues/596
+ return numeral(new BigNumber(0)).format(constants.NUMERAL_USD_FORMAT);
+ }
+ return formattedAmount;
},
openUrl(url: string): void {
window.open(url, '_blank');
@@ -500,4 +490,4 @@ export const utils = {
const result = `/images/token_icons/${symbol}.png`;
return result;
},
-}; // tslint:disable:max-file-line-count
+};