aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/website/package.json9
-rw-r--r--packages/website/ts/blockchain.ts7
-rw-r--r--packages/website/ts/components/eth_weth_conversion_button.tsx2
-rw-r--r--packages/website/ts/components/fill_order.tsx4
-rw-r--r--packages/website/ts/components/generate_order/generate_order_form.tsx2
-rw-r--r--packages/website/ts/components/inputs/allowance_toggle.tsx2
-rw-r--r--packages/website/ts/components/order_json.tsx2
-rw-r--r--packages/website/ts/components/send_button.tsx2
-rw-r--r--packages/website/ts/components/token_balances.tsx4
-rw-r--r--packages/website/ts/components/wallet/wrap_ether_item.tsx2
-rw-r--r--packages/website/ts/types.ts3
-rw-r--r--packages/website/ts/utils/configs.ts10
-rw-r--r--packages/website/ts/utils/error_reporter.ts23
-rw-r--r--packages/website/ts/utils/fetch_utils.ts3
-rw-r--r--packages/website/ts/utils/utils.ts59
-rw-r--r--packages/website/webpack.config.js68
16 files changed, 107 insertions, 95 deletions
diff --git a/packages/website/package.json b/packages/website/package.json
index 39743cb44..ef314ba2d 100644
--- a/packages/website/package.json
+++ b/packages/website/package.json
@@ -11,9 +11,12 @@
"clean": "shx rm -f public/bundle*",
"lint": "tslint --project . 'ts/**/*.ts' 'ts/**/*.tsx'",
"watch_without_deps": "webpack-dev-server --content-base public --https",
- "deploy_dogfood": "npm run build; aws s3 sync ./public/. s3://dogfood.0xproject.com --profile 0xproject --region us-east-1 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers",
- "deploy_staging": "npm run build; aws s3 sync ./public/. s3://staging-0xproject --profile 0xproject --region us-east-1 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers",
- "deploy_live": "npm run build; aws s3 sync ./public/. s3://0xproject.com --profile 0xproject --region us-east-1 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --exclude *.map.js"
+ "deploy_dogfood":
+ "npm run build; aws s3 sync ./public/. s3://dogfood.0xproject.com --profile 0xproject --region us-east-1 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers",
+ "deploy_staging":
+ "npm run build; aws s3 sync ./public/. s3://staging-0xproject --profile 0xproject --region us-east-1 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers",
+ "deploy_live":
+ "DEPLOY_ROLLBAR_SOURCEMAPS=true npm run build; aws s3 sync ./public/. s3://0xproject.com --profile 0xproject --region us-east-1 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --exclude *.map.js"
},
"author": "Fabio Berger",
"license": "Apache-2.0",
diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts
index 93534e143..e8168d975 100644
--- a/packages/website/ts/blockchain.ts
+++ b/packages/website/ts/blockchain.ts
@@ -564,7 +564,7 @@ export class Blockchain {
configs.DEFAULT_TRACKED_TOKEN_SYMBOLS,
)}) not found in tokenRegistry: ${JSON.stringify(tokenRegistryTokens)}`,
);
- await errorReporter.reportAsync(err);
+ errorReporter.report(err);
return;
}
if (_.isEmpty(trackedTokensByAddress)) {
@@ -675,8 +675,7 @@ 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.reportAsync(err); // fire and forget
+ errorReporter.report(err); // fire and forget
return;
} else {
const decodedLog = decodedLogEvent.log;
@@ -908,7 +907,7 @@ export class Blockchain {
if (_.includes(errMsg, 'not been deployed to detected network')) {
throw new Error(BlockchainCallErrs.ContractDoesNotExist);
} else {
- await errorReporter.reportAsync(err);
+ errorReporter.report(err);
throw new Error(BlockchainCallErrs.UnhandledError);
}
}
diff --git a/packages/website/ts/components/eth_weth_conversion_button.tsx b/packages/website/ts/components/eth_weth_conversion_button.tsx
index 4b91a2ebd..d547a4e6a 100644
--- a/packages/website/ts/components/eth_weth_conversion_button.tsx
+++ b/packages/website/ts/components/eth_weth_conversion_button.tsx
@@ -118,7 +118,7 @@ export class EthWethConversionButton extends React.Component<
? 'Failed to wrap your ETH. Please try again.'
: 'Failed to unwrap your WETH. Please try again.';
this.props.dispatcher.showFlashMessage(errorMsg);
- await errorReporter.reportAsync(err);
+ errorReporter.report(err);
}
}
this.setState({
diff --git a/packages/website/ts/components/fill_order.tsx b/packages/website/ts/components/fill_order.tsx
index ff63410c3..7da2e0870 100644
--- a/packages/website/ts/components/fill_order.tsx
+++ b/packages/website/ts/components/fill_order.tsx
@@ -585,7 +585,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
this.setState({
globalErrMsg,
});
- await errorReporter.reportAsync(err);
+ errorReporter.report(err);
return;
}
}
@@ -654,7 +654,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
this.setState({
globalErrMsg,
});
- await errorReporter.reportAsync(err);
+ errorReporter.report(err);
return;
}
}
diff --git a/packages/website/ts/components/generate_order/generate_order_form.tsx b/packages/website/ts/components/generate_order/generate_order_form.tsx
index c14ee8659..72efab033 100644
--- a/packages/website/ts/components/generate_order/generate_order_form.tsx
+++ b/packages/website/ts/components/generate_order/generate_order_form.tsx
@@ -355,7 +355,7 @@ export class GenerateOrderForm extends React.Component<GenerateOrderFormProps, G
globalErrMsg = 'An unexpected error occured. Please try refreshing the page';
logUtils.log(`Unexpected error occured: ${err}`);
logUtils.log(err.stack);
- await errorReporter.reportAsync(err);
+ errorReporter.report(err);
}
}
this.setState({
diff --git a/packages/website/ts/components/inputs/allowance_toggle.tsx b/packages/website/ts/components/inputs/allowance_toggle.tsx
index c444d79b7..297617bef 100644
--- a/packages/website/ts/components/inputs/allowance_toggle.tsx
+++ b/packages/website/ts/components/inputs/allowance_toggle.tsx
@@ -131,7 +131,7 @@ export class AllowanceToggle extends React.Component<AllowanceToggleProps, Allow
logUtils.log(`Unexpected error encountered: ${err}`);
logUtils.log(err.stack);
this.props.onErrorOccurred(BalanceErrs.allowanceSettingFailed);
- await errorReporter.reportAsync(err);
+ errorReporter.report(err);
}
}
private _isAllowanceSet(): boolean {
diff --git a/packages/website/ts/components/order_json.tsx b/packages/website/ts/components/order_json.tsx
index 7a732de6a..c2606bd56 100644
--- a/packages/website/ts/components/order_json.tsx
+++ b/packages/website/ts/components/order_json.tsx
@@ -154,7 +154,7 @@ You can see and fill it here: ${this.state.shareLink}`);
if (response.status !== 200 || bodyObj.status_code !== 200) {
// TODO: Show error message in UI
logUtils.log(`Unexpected status code: ${response.status} -> ${responseBody}`);
- await errorReporter.reportAsync(new Error(`Bitly returned non-200: ${JSON.stringify(response)}`));
+ errorReporter.report(new Error(`Bitly returned non-200: ${JSON.stringify(response)}`));
return '';
}
return bodyObj.data.url;
diff --git a/packages/website/ts/components/send_button.tsx b/packages/website/ts/components/send_button.tsx
index 8486dbd8b..ac55d430b 100644
--- a/packages/website/ts/components/send_button.tsx
+++ b/packages/website/ts/components/send_button.tsx
@@ -80,7 +80,7 @@ export class SendButton extends React.Component<SendButtonProps, SendButtonState
logUtils.log(`Unexpected error encountered: ${err}`);
logUtils.log(err.stack);
this.props.onError();
- await errorReporter.reportAsync(err);
+ errorReporter.report(err);
}
}
this.setState({
diff --git a/packages/website/ts/components/token_balances.tsx b/packages/website/ts/components/token_balances.tsx
index 1f2dfccb0..c8d80702b 100644
--- a/packages/website/ts/components/token_balances.tsx
+++ b/packages/website/ts/components/token_balances.tsx
@@ -526,7 +526,7 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala
this.setState({
errorType: BalanceErrs.mintingFailed,
});
- await errorReporter.reportAsync(err);
+ errorReporter.report(err);
return false;
}
}
@@ -561,7 +561,7 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala
this.setState({
errorType,
});
- await errorReporter.reportAsync(new Error(`Faucet returned non-200: ${JSON.stringify(response)}`));
+ errorReporter.report(new Error(`Faucet returned non-200: ${JSON.stringify(response)}`));
return false;
}
diff --git a/packages/website/ts/components/wallet/wrap_ether_item.tsx b/packages/website/ts/components/wallet/wrap_ether_item.tsx
index 2b85b69be..fcab5d1dd 100644
--- a/packages/website/ts/components/wallet/wrap_ether_item.tsx
+++ b/packages/website/ts/components/wallet/wrap_ether_item.tsx
@@ -226,7 +226,7 @@ export class WrapEtherItem extends React.Component<WrapEtherItemProps, WrapEther
amount: tokenAmount,
});
}
- await errorReporter.reportAsync(err);
+ errorReporter.report(err);
}
}
this.setState({
diff --git a/packages/website/ts/types.ts b/packages/website/ts/types.ts
index f107b3b5e..4d0496f6c 100644
--- a/packages/website/ts/types.ts
+++ b/packages/website/ts/types.ts
@@ -244,7 +244,10 @@ export enum BlockchainCallErrs {
export enum Environments {
DEVELOPMENT = 'DEVELOPMENT',
+ 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 97aabd13d..a1c64f9cb 100644
--- a/packages/website/ts/utils/configs.ts
+++ b/packages/website/ts/utils/configs.ts
@@ -1,11 +1,6 @@
-import * as _ from 'lodash';
-import { Environments, OutdatedWrappedEtherByNetworkId, PublicNodeUrlsByNetworkId } from 'ts/types';
+import { 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 = {
@@ -19,9 +14,8 @@ 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',
- 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..6008fffed 100644
--- a/packages/website/ts/utils/error_reporter.ts
+++ b/packages/website/ts/utils/error_reporter.ts
@@ -1,7 +1,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 +12,7 @@ const rollbarConfig = {
itemsPerMinute: 10,
maxItems: 500,
payload: {
- environment: configs.ENVIRONMENT,
+ environment: utils.getEnvironment(),
client: {
javascript: {
source_map_enabled: true,
@@ -40,21 +40,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.isDevelopment()) {
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 f159e3180..e9a88b6b3 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 f18459598..739bb7b66 100644
--- a/packages/website/ts/utils/utils.ts
+++ b/packages/website/ts/utils/utils.ts
@@ -30,8 +30,6 @@ import { configs } from 'ts/utils/configs';
import { constants } from 'ts/utils/constants';
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) {
@@ -177,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;
@@ -345,10 +331,10 @@ 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(configs.DOMAINS_DEVELOPMENT, window.location.origin);
},
isStaging(): boolean {
return _.includes(window.location.href, configs.DOMAIN_STAGING);
@@ -356,7 +342,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 Environments.UNKNOWN;
+ },
shouldShowJobsPage(): boolean {
return this.isDevelopment() || this.isStaging() || this.isDogfood();
},
@@ -379,21 +385,28 @@ export const utils = {
getFormattedAmountFromToken(token: Token, tokenState: TokenState): string {
return utils.getFormattedAmount(tokenState.balance, token.decimals);
},
+ format(value: BigNumber, format: string): string {
+ const formattedAmount = numeral(value).format(format);
+ if (_.isNaN(formattedAmount)) {
+ // https://github.com/adamwdraper/Numeral-js/issues/596
+ return numeral(new BigNumber(0)).format(format);
+ }
+ return formattedAmount;
+ },
getFormattedAmount(amount: BigNumber, decimals: number): string {
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);
- return formattedAmount;
+ return utils.format(unitAmount, format);
},
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);
+ return utils.format(value, constants.NUMERAL_USD_FORMAT);
},
openUrl(url: string): void {
window.open(url, '_blank');
diff --git a/packages/website/webpack.config.js b/packages/website/webpack.config.js
index 5647b4f93..8653196a6 100644
--- a/packages/website/webpack.config.js
+++ b/packages/website/webpack.config.js
@@ -9,6 +9,43 @@ const GIT_SHA = childProcess
.toString()
.trim();
+const generatePlugins = () => {
+ let plugins = [];
+ if (process.env.NODE_ENV === 'production') {
+ plugins = plugins.concat([
+ // Since we do not use moment's locale feature, we exclude them from the bundle.
+ // This reduces the bundle size by 0.4MB.
+ new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
+ new webpack.DefinePlugin({
+ 'process.env': {
+ NODE_ENV: JSON.stringify(process.env.NODE_ENV),
+ GIT_SHA: JSON.stringify(GIT_SHA),
+ },
+ }),
+ // TODO: Revert to webpack bundled version with webpack v4.
+ // The v3 series bundled version does not support ES6 and
+ // fails to build.
+ new UglifyJsPlugin({
+ sourceMap: true,
+ uglifyOptions: {
+ mangle: {
+ reserved: ['BigNumber'],
+ },
+ },
+ }),
+ ]);
+ if (process.env.DEPLOY_ROLLBAR_SOURCEMAPS === 'true') {
+ plugins = plugins.concat([
+ new RollbarSourceMapPlugin({
+ accessToken: '32c39bfa4bb6440faedc1612a9c13d28',
+ version: GIT_SHA,
+ publicPath: 'https://0xproject.com/',
+ }),
+ ]);
+ }
+ }
+ return plugins;
+};
module.exports = {
entry: ['./ts/index.tsx'],
output: {
@@ -78,34 +115,5 @@ module.exports = {
},
disableHostCheck: true,
},
- plugins:
- process.env.NODE_ENV === 'production'
- ? [
- // Since we do not use moment's locale feature, we exclude them from the bundle.
- // This reduces the bundle size by 0.4MB.
- new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
- new webpack.DefinePlugin({
- 'process.env': {
- NODE_ENV: JSON.stringify(process.env.NODE_ENV),
- GIT_SHA: JSON.stringify(GIT_SHA),
- },
- }),
- // TODO: Revert to webpack bundled version with webpack v4.
- // The v3 series bundled version does not support ES6 and
- // fails to build.
- new UglifyJsPlugin({
- sourceMap: true,
- uglifyOptions: {
- mangle: {
- reserved: ['BigNumber'],
- },
- },
- }),
- new RollbarSourceMapPlugin({
- accessToken: '32c39bfa4bb6440faedc1612a9c13d28',
- version: GIT_SHA,
- publicPath: 'https://0xproject.com/',
- }),
- ]
- : [],
+ plugins: generatePlugins(),
};