From db77cd10c550803c4f3fac585adc0a7f6ffa8999 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Tue, 16 Oct 2018 11:25:52 -0700 Subject: feat(instant): Handle AssetBuyer errors --- packages/instant/src/redux/reducer.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'packages/instant/src/redux/reducer.ts') diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts index adecf2ab7..4ff49c225 100644 --- a/packages/instant/src/redux/reducer.ts +++ b/packages/instant/src/redux/reducer.ts @@ -7,13 +7,22 @@ import { AsyncProcessState } from '../types'; import { Action, ActionTypes } from './actions'; -export interface State { +interface BaseState { selectedAssetData?: string; selectedAssetAmount?: BigNumber; selectedAssetBuyState: AsyncProcessState; ethUsdPrice?: BigNumber; latestBuyQuote?: BuyQuote; } +interface StateWithError extends BaseState { + latestError: any; + latestErrorDismissed: boolean; +} +interface StateWithoutError extends BaseState { + latestError: undefined; + latestErrorDismissed: undefined; +} +export type State = StateWithError | StateWithoutError; export const INITIAL_STATE: State = { // TODO: Remove hardcoded zrxAssetData @@ -22,6 +31,8 @@ export const INITIAL_STATE: State = { selectedAssetBuyState: AsyncProcessState.NONE, ethUsdPrice: undefined, latestBuyQuote: undefined, + latestError: undefined, + latestErrorDismissed: undefined, }; export const reducer = (state: State = INITIAL_STATE, action: Action): State => { @@ -46,6 +57,23 @@ export const reducer = (state: State = INITIAL_STATE, action: Action): State => ...state, selectedAssetBuyState: action.data, }; + case ActionTypes.SET_ERROR: + return { + ...state, + latestError: action.data, + latestErrorDismissed: false, + }; + case ActionTypes.HIDE_ERROR: + return { + ...state, + latestErrorDismissed: true, + }; + case ActionTypes.CLEAR_ERROR: + return { + ...state, + latestError: undefined, + latestErrorDismissed: undefined, + }; default: return state; } -- cgit From 187bbc7fc14ccc0385981a38602334de65e2506c Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Wed, 17 Oct 2018 13:26:18 -0700 Subject: latestErrorDismissed -> latestErrorDisplay enum --- packages/instant/src/redux/reducer.ts | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'packages/instant/src/redux/reducer.ts') diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts index 4ff49c225..d23064db7 100644 --- a/packages/instant/src/redux/reducer.ts +++ b/packages/instant/src/redux/reducer.ts @@ -7,22 +7,19 @@ import { AsyncProcessState } from '../types'; import { Action, ActionTypes } from './actions'; -interface BaseState { +export enum LatestErrorDisplay { + Present, + Hidden, +} +export interface State { selectedAssetData?: string; selectedAssetAmount?: BigNumber; selectedAssetBuyState: AsyncProcessState; ethUsdPrice?: BigNumber; latestBuyQuote?: BuyQuote; + latestError?: any; + latestErrorDisplay: LatestErrorDisplay; } -interface StateWithError extends BaseState { - latestError: any; - latestErrorDismissed: boolean; -} -interface StateWithoutError extends BaseState { - latestError: undefined; - latestErrorDismissed: undefined; -} -export type State = StateWithError | StateWithoutError; export const INITIAL_STATE: State = { // TODO: Remove hardcoded zrxAssetData @@ -32,7 +29,7 @@ export const INITIAL_STATE: State = { ethUsdPrice: undefined, latestBuyQuote: undefined, latestError: undefined, - latestErrorDismissed: undefined, + latestErrorDisplay: LatestErrorDisplay.Hidden, }; export const reducer = (state: State = INITIAL_STATE, action: Action): State => { @@ -61,18 +58,18 @@ export const reducer = (state: State = INITIAL_STATE, action: Action): State => return { ...state, latestError: action.data, - latestErrorDismissed: false, + latestErrorDisplay: LatestErrorDisplay.Present, }; case ActionTypes.HIDE_ERROR: return { ...state, - latestErrorDismissed: true, + latestErrorDisplay: LatestErrorDisplay.Hidden, }; case ActionTypes.CLEAR_ERROR: return { ...state, latestError: undefined, - latestErrorDismissed: undefined, + latestErrorDisplay: LatestErrorDisplay.Hidden, }; default: return state; -- cgit From 6cf8d57aee3ed332bd1109f8f39792894147d2dd Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Wed, 17 Oct 2018 16:41:35 -0700 Subject: add concept of quoteState --- packages/instant/src/redux/reducer.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'packages/instant/src/redux/reducer.ts') diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts index d23064db7..ed8d0f6cf 100644 --- a/packages/instant/src/redux/reducer.ts +++ b/packages/instant/src/redux/reducer.ts @@ -14,9 +14,10 @@ export enum LatestErrorDisplay { export interface State { selectedAssetData?: string; selectedAssetAmount?: BigNumber; - selectedAssetBuyState: AsyncProcessState; + selectedAssetBuyState: AsyncProcessState; // TODO: rename buyOrderState ethUsdPrice?: BigNumber; latestBuyQuote?: BuyQuote; + quoteState: AsyncProcessState; latestError?: any; latestErrorDisplay: LatestErrorDisplay; } @@ -30,6 +31,7 @@ export const INITIAL_STATE: State = { latestBuyQuote: undefined, latestError: undefined, latestErrorDisplay: LatestErrorDisplay.Hidden, + quoteState: AsyncProcessState.NONE, }; export const reducer = (state: State = INITIAL_STATE, action: Action): State => { @@ -48,6 +50,19 @@ export const reducer = (state: State = INITIAL_STATE, action: Action): State => return { ...state, latestBuyQuote: action.data, + quoteState: AsyncProcessState.SUCCESS, + }; + case ActionTypes.UPDATE_BUY_QUOTE_STATE_PENDING: + return { + ...state, + latestBuyQuote: undefined, + quoteState: AsyncProcessState.PENDING, + }; + case ActionTypes.UPDATE_BUY_QUOTE_STATE_FAILURE: + return { + ...state, + latestBuyQuote: undefined, + quoteState: AsyncProcessState.FAILURE, }; case ActionTypes.UPDATE_SELECTED_ASSET_BUY_STATE: return { -- cgit From 6ea386a7af89c1b8a4df94b656ae1772c29c1401 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Wed, 17 Oct 2018 16:50:21 -0700 Subject: selectedAssetBuyState -> buyOrderState --- packages/instant/src/redux/reducer.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/instant/src/redux/reducer.ts') diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts index ed8d0f6cf..54290483b 100644 --- a/packages/instant/src/redux/reducer.ts +++ b/packages/instant/src/redux/reducer.ts @@ -14,7 +14,7 @@ export enum LatestErrorDisplay { export interface State { selectedAssetData?: string; selectedAssetAmount?: BigNumber; - selectedAssetBuyState: AsyncProcessState; // TODO: rename buyOrderState + buyOrderState: AsyncProcessState; ethUsdPrice?: BigNumber; latestBuyQuote?: BuyQuote; quoteState: AsyncProcessState; @@ -26,7 +26,7 @@ export const INITIAL_STATE: State = { // TODO: Remove hardcoded zrxAssetData selectedAssetData: zrxAssetData, selectedAssetAmount: undefined, - selectedAssetBuyState: AsyncProcessState.NONE, + buyOrderState: AsyncProcessState.NONE, ethUsdPrice: undefined, latestBuyQuote: undefined, latestError: undefined, @@ -67,7 +67,7 @@ export const reducer = (state: State = INITIAL_STATE, action: Action): State => case ActionTypes.UPDATE_SELECTED_ASSET_BUY_STATE: return { ...state, - selectedAssetBuyState: action.data, + buyOrderState: action.data, }; case ActionTypes.SET_ERROR: return { -- cgit From 9f924e459c43c023e35ab7222cd9824cc0e67411 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Thu, 18 Oct 2018 21:51:56 +1100 Subject: chore: change package org from 0xproject to 0x --- packages/instant/src/redux/reducer.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/instant/src/redux/reducer.ts') diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts index 54290483b..05aa37420 100644 --- a/packages/instant/src/redux/reducer.ts +++ b/packages/instant/src/redux/reducer.ts @@ -1,5 +1,5 @@ -import { BuyQuote } from '@0xproject/asset-buyer'; -import { BigNumber } from '@0xproject/utils'; +import { BuyQuote } from '@0x/asset-buyer'; +import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; import { zrxAssetData } from '../constants'; -- cgit