aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/containers
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-10-27 06:32:04 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-10-27 06:45:17 +0800
commit4f5ab1a72d33dc6a7516d7b1d51f1aa15752a6b8 (patch)
treebf3766ecf6ea51c6dfcd1d286c572b3410088087 /packages/instant/src/containers
parent51da5311b54733540f44f938a0c953bb4ae42052 (diff)
downloaddexon-0x-contracts-4f5ab1a72d33dc6a7516d7b1d51f1aa15752a6b8.tar.gz
dexon-0x-contracts-4f5ab1a72d33dc6a7516d7b1d51f1aa15752a6b8.tar.zst
dexon-0x-contracts-4f5ab1a72d33dc6a7516d7b1d51f1aa15752a6b8.zip
Refactor error handling such that errorMessage lives on the top level state
Diffstat (limited to 'packages/instant/src/containers')
-rw-r--r--packages/instant/src/containers/latest_error.tsx14
-rw-r--r--packages/instant/src/containers/selected_asset_buy_button.ts8
-rw-r--r--packages/instant/src/containers/selected_erc20_asset_amount_input.ts22
3 files changed, 29 insertions, 15 deletions
diff --git a/packages/instant/src/containers/latest_error.tsx b/packages/instant/src/containers/latest_error.tsx
index b75ec00aa..45ca09673 100644
--- a/packages/instant/src/containers/latest_error.tsx
+++ b/packages/instant/src/containers/latest_error.tsx
@@ -5,32 +5,30 @@ import { connect } from 'react-redux';
import { SlidingError } from '../components/sliding_error';
import { State } from '../redux/reducer';
import { Asset, DisplayStatus } from '../types';
-import { errorUtil } from '../util/error';
export interface LatestErrorComponentProps {
asset?: Asset;
- latestError?: any;
+ latestErrorMessage?: string;
slidingDirection: 'down' | 'up';
}
export const LatestErrorComponent: React.StatelessComponent<LatestErrorComponentProps> = props => {
- if (!props.latestError) {
+ if (!props.latestErrorMessage) {
return <div />;
}
- const { icon, message } = errorUtil.errorDescription(props.latestError, props.asset);
- return <SlidingError direction={props.slidingDirection} icon={icon} message={message} />;
+ return <SlidingError direction={props.slidingDirection} icon="😢" message={props.latestErrorMessage} />;
};
interface ConnectedState {
asset?: Asset;
- latestError?: any;
+ latestErrorMessage?: string;
slidingDirection: 'down' | 'up';
}
export interface LatestErrorProps {}
const mapStateToProps = (state: State, _ownProps: LatestErrorProps): ConnectedState => ({
asset: state.selectedAsset,
- latestError: state.latestError,
- slidingDirection: state.latestErrorDisplay === DisplayStatus.Present ? 'up' : 'down',
+ latestErrorMessage: state.latestErrorMessage,
+ slidingDirection: state.latestErrorDisplayStatus === DisplayStatus.Present ? 'up' : 'down',
});
export const LatestError = connect(mapStateToProps)(LatestErrorComponent);
diff --git a/packages/instant/src/containers/selected_asset_buy_button.ts b/packages/instant/src/containers/selected_asset_buy_button.ts
index adcbd61bc..377831b43 100644
--- a/packages/instant/src/containers/selected_asset_buy_button.ts
+++ b/packages/instant/src/containers/selected_asset_buy_button.ts
@@ -7,6 +7,7 @@ import { Dispatch } from 'redux';
import { Action, actions } from '../redux/actions';
import { State } from '../redux/reducer';
import { OrderProcessState, OrderState } from '../types';
+import { errorFlasher } from '../util/error_flasher';
import { BuyButton } from '../components/buy_button';
@@ -19,7 +20,7 @@ interface ConnectedState {
interface ConnectedDispatch {
onAwaitingSignature: (buyQuote: BuyQuote) => void;
- onSignatureDenied: (buyQuote: BuyQuote, error: Error) => void;
+ onSignatureDenied: (buyQuote: BuyQuote) => void;
onBuyProcessing: (buyQuote: BuyQuote, txHash: string) => void;
onBuySuccess: (buyQuote: BuyQuote, txHash: string) => void;
onBuyFailure: (buyQuote: BuyQuote, txHash: string) => void;
@@ -43,9 +44,10 @@ const mapDispatchToProps = (dispatch: Dispatch<Action>, ownProps: SelectedAssetB
dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.SUCCESS, txHash })),
onBuyFailure: (buyQuote: BuyQuote, txHash: string) =>
dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.FAILURE, txHash })),
- onSignatureDenied: (buyQuote, error) => {
+ onSignatureDenied: () => {
dispatch(actions.resetAmount());
- dispatch(actions.setError(error));
+ const errorMessage = 'You denied this transaction';
+ errorFlasher.flashNewErrorMessage(dispatch, errorMessage);
},
});
diff --git a/packages/instant/src/containers/selected_erc20_asset_amount_input.ts b/packages/instant/src/containers/selected_erc20_asset_amount_input.ts
index ee76e9d66..8fcb430a7 100644
--- a/packages/instant/src/containers/selected_erc20_asset_amount_input.ts
+++ b/packages/instant/src/containers/selected_erc20_asset_amount_input.ts
@@ -1,4 +1,4 @@
-import { AssetBuyer, BuyQuote } from '@0x/asset-buyer';
+import { AssetBuyer, AssetBuyerError, BuyQuote } from '@0x/asset-buyer';
import { AssetProxyId } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
@@ -11,8 +11,9 @@ import { Action, actions } from '../redux/actions';
import { State } from '../redux/reducer';
import { ColorOption } from '../style/theme';
import { ERC20Asset, OrderProcessState } from '../types';
+import { assetUtils } from '../util/asset';
import { BigNumberInput } from '../util/big_number_input';
-import { errorUtil } from '../util/error';
+import { errorFlasher } from '../util/error_flasher';
import { ERC20AssetAmountInput } from '../components/erc20_asset_amount_input';
@@ -70,11 +71,24 @@ const updateBuyQuoteAsync = async (
newBuyQuote = await assetBuyer.getBuyQuoteAsync(asset.assetData, baseUnitValue);
} catch (error) {
dispatch(actions.setQuoteRequestStateFailure());
- errorUtil.errorFlasher.flashNewError(dispatch, error);
+ let errorMessage;
+ if (error.message === AssetBuyerError.InsufficientAssetLiquidity) {
+ const assetName = assetUtils.bestNameForAsset(asset, 'of this asset');
+ errorMessage = `Not enough ${assetName} available`;
+ } else if (error.message === AssetBuyerError.InsufficientZrxLiquidity) {
+ errorMessage = 'Not enough ZRX available';
+ } else if (
+ error.message === AssetBuyerError.StandardRelayerApiError ||
+ error.message.startsWith(AssetBuyerError.AssetUnavailable)
+ ) {
+ const assetName = assetUtils.bestNameForAsset(asset, 'This asset');
+ errorMessage = `${assetName} is currently unavailable`;
+ }
+ errorFlasher.flashNewErrorMessage(dispatch, errorMessage);
return;
}
// We have a successful new buy quote
- errorUtil.errorFlasher.clearError(dispatch);
+ errorFlasher.clearError(dispatch);
// invalidate the last buy quote.
dispatch(actions.updateLatestBuyQuote(newBuyQuote));
};