aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/util/error.ts
diff options
context:
space:
mode:
authorBrandon Millman <brandon@0xproject.com>2018-10-30 01:58:11 +0800
committerGitHub <noreply@github.com>2018-10-30 01:58:11 +0800
commitfdf9e860dedf5dbe7840951f304a33ac2d7b1b51 (patch)
tree2acfc843dce83d5f8643980f9c74af25d12a18df /packages/instant/src/util/error.ts
parent4e4291eccdd6c837bbec70603aa6eb64d3aa8d85 (diff)
parent3f35239b27653da898218e53909982203fad6d17 (diff)
downloaddexon-0x-contracts-fdf9e860dedf5dbe7840951f304a33ac2d7b1b51.tar.gz
dexon-0x-contracts-fdf9e860dedf5dbe7840951f304a33ac2d7b1b51.tar.zst
dexon-0x-contracts-fdf9e860dedf5dbe7840951f304a33ac2d7b1b51.zip
Merge pull request #1187 from 0xProject/feature/instant/fixed-orders-in-render-method
[instant] Add ability to toggle render settings through URL, flash error on incorrect network, provided liquidity
Diffstat (limited to 'packages/instant/src/util/error.ts')
-rw-r--r--packages/instant/src/util/error.ts71
1 files changed, 0 insertions, 71 deletions
diff --git a/packages/instant/src/util/error.ts b/packages/instant/src/util/error.ts
deleted file mode 100644
index 39c563c75..000000000
--- a/packages/instant/src/util/error.ts
+++ /dev/null
@@ -1,71 +0,0 @@
-import { AssetBuyerError } from '@0x/asset-buyer';
-import { Dispatch } from 'redux';
-
-import { Action, actions } from '../redux/actions';
-import { Asset, ZeroExInstantError } from '../types';
-
-import { assetUtils } from './asset';
-
-class ErrorFlasher {
- private _timeoutId?: number;
- public flashNewError(dispatch: Dispatch<Action>, error: any, delayMs: number = 7000): void {
- this._clearTimeout();
-
- // dispatch new message
- dispatch(actions.setError(error));
-
- this._timeoutId = window.setTimeout(() => {
- dispatch(actions.hideError());
- }, delayMs);
- }
- public clearError(dispatch: Dispatch<Action>): void {
- this._clearTimeout();
- dispatch(actions.hideError());
- }
- private _clearTimeout(): void {
- if (this._timeoutId) {
- window.clearTimeout(this._timeoutId);
- }
- }
-}
-
-const humanReadableMessageForError = (error: Error, asset?: Asset): string | undefined => {
- const hasInsufficientLiquidity =
- error.message === AssetBuyerError.InsufficientAssetLiquidity ||
- error.message === AssetBuyerError.InsufficientZrxLiquidity;
- if (hasInsufficientLiquidity) {
- const assetName = assetUtils.bestNameForAsset(asset, 'of this asset');
- return `Not enough ${assetName} available`;
- }
-
- if (
- error.message === AssetBuyerError.StandardRelayerApiError ||
- error.message.startsWith(AssetBuyerError.AssetUnavailable)
- ) {
- const assetName = assetUtils.bestNameForAsset(asset, 'This asset');
- return `${assetName} is currently unavailable`;
- }
-
- if (error.message === AssetBuyerError.SignatureRequestDenied) {
- return 'You denied this transaction';
- }
- if (error.message === ZeroExInstantError.InsufficientETH) {
- return "You don't have enough ETH";
- }
-
- return undefined;
-};
-
-export const errorUtil = {
- errorFlasher: new ErrorFlasher(),
- errorDescription: (error?: any, asset?: Asset): { icon: string; message: string } => {
- let bestMessage: string | undefined;
- if (error instanceof Error) {
- bestMessage = humanReadableMessageForError(error, asset);
- }
- return {
- icon: '😢',
- message: bestMessage || 'Something went wrong...',
- };
- },
-};