removed buyer and adding in asset-swapper
This commit is contained in:
parent
c3c8ee7292
commit
64d25e6522
@ -44,7 +44,7 @@
|
|||||||
"homepage": "https://github.com/0xProject/0x-monorepo/packages/instant/README.md",
|
"homepage": "https://github.com/0xProject/0x-monorepo/packages/instant/README.md",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@0x/assert": "^2.2.0-beta.2",
|
"@0x/assert": "^2.2.0-beta.2",
|
||||||
"@0x/asset-buyer": "6.1.8",
|
"@0x/asset-swapper": "^2.1.0-beta.2",
|
||||||
"@0x/json-schemas": "^4.1.0-beta.2",
|
"@0x/json-schemas": "^4.1.0-beta.2",
|
||||||
"@0x/order-utils": "^8.5.0-beta.3",
|
"@0x/order-utils": "^8.5.0-beta.3",
|
||||||
"@0x/subproviders": "^5.1.0-beta.2",
|
"@0x/subproviders": "^5.1.0-beta.2",
|
||||||
|
@ -16,12 +16,12 @@ export const ONE_SECOND_MS = 1000;
|
|||||||
export const ONE_MINUTE_MS = ONE_SECOND_MS * 60;
|
export const ONE_MINUTE_MS = ONE_SECOND_MS * 60;
|
||||||
export const GIT_SHA = process.env.GIT_SHA;
|
export const GIT_SHA = process.env.GIT_SHA;
|
||||||
export const NODE_ENV = process.env.NODE_ENV;
|
export const NODE_ENV = process.env.NODE_ENV;
|
||||||
export const ERC20_BUY_QUOTE_SLIPPAGE_PERCENTAGE = 0.2;
|
export const ERC20_SWAP_QUOTE_SLIPPAGE_PERCENTAGE = 0.2;
|
||||||
export const ERC721_BUY_QUOTE_SLIPPAGE_PERCENTAGE = 0;
|
export const ERC721_SWAP_QUOTE_SLIPPAGE_PERCENTAGE = 0;
|
||||||
export const NPM_PACKAGE_VERSION = process.env.NPM_PACKAGE_VERSION;
|
export const NPM_PACKAGE_VERSION = process.env.NPM_PACKAGE_VERSION;
|
||||||
export const DEFAULT_UNKOWN_ASSET_NAME = '???';
|
export const DEFAULT_UNKOWN_ASSET_NAME = '???';
|
||||||
export const ACCOUNT_UPDATE_INTERVAL_TIME_MS = ONE_SECOND_MS * 5;
|
export const ACCOUNT_UPDATE_INTERVAL_TIME_MS = ONE_SECOND_MS * 5;
|
||||||
export const BUY_QUOTE_UPDATE_INTERVAL_TIME_MS = ONE_SECOND_MS * 15;
|
export const SWAP_QUOTE_UPDATE_INTERVAL_TIME_MS = ONE_SECOND_MS * 15;
|
||||||
export const DEFAULT_GAS_PRICE = GWEI_IN_WEI.multipliedBy(6);
|
export const DEFAULT_GAS_PRICE = GWEI_IN_WEI.multipliedBy(6);
|
||||||
export const DEFAULT_ESTIMATED_TRANSACTION_TIME_MS = ONE_MINUTE_MS * 2;
|
export const DEFAULT_ESTIMATED_TRANSACTION_TIME_MS = ONE_MINUTE_MS * 2;
|
||||||
export const MAGIC_TRIGGER_ERROR_INPUT = '0€';
|
export const MAGIC_TRIGGER_ERROR_INPUT = '0€';
|
||||||
|
@ -28,7 +28,7 @@ interface ConnectedState extends BuyOrderProgressOrPaymentMethodProps {}
|
|||||||
|
|
||||||
export interface ConnectedBuyOrderProgressOrPaymentMethodProps {}
|
export interface ConnectedBuyOrderProgressOrPaymentMethodProps {}
|
||||||
const mapStateToProps = (state: State, _ownProps: ConnectedBuyOrderProgressOrPaymentMethodProps): ConnectedState => ({
|
const mapStateToProps = (state: State, _ownProps: ConnectedBuyOrderProgressOrPaymentMethodProps): ConnectedState => ({
|
||||||
orderProcessState: state.buyOrderState.processState,
|
orderProcessState: state.swapOrderState.processState,
|
||||||
});
|
});
|
||||||
export const ConnectedBuyOrderProgressOrPaymentMethod: React.ComponentClass<
|
export const ConnectedBuyOrderProgressOrPaymentMethod: React.ComponentClass<
|
||||||
ConnectedBuyOrderProgressOrPaymentMethodProps
|
ConnectedBuyOrderProgressOrPaymentMethodProps
|
||||||
|
@ -16,7 +16,7 @@ type DispatchProperties = 'onBaseCurrencySwitchEth' | 'onBaseCurrencySwitchUsd';
|
|||||||
interface ConnectedState extends Omit<OrderDetailsProps, DispatchProperties> {}
|
interface ConnectedState extends Omit<OrderDetailsProps, DispatchProperties> {}
|
||||||
const mapStateToProps = (state: State, _ownProps: LatestBuyQuoteOrderDetailsProps): ConnectedState => ({
|
const mapStateToProps = (state: State, _ownProps: LatestBuyQuoteOrderDetailsProps): ConnectedState => ({
|
||||||
// use the worst case quote info
|
// use the worst case quote info
|
||||||
buyQuoteInfo: oc(state).latestBuyQuote.worstCaseQuoteInfo(),
|
buyQuoteInfo: oc(state).latestSwapQuote.worstCaseQuoteInfo(),
|
||||||
selectedAssetUnitAmount: state.selectedAssetUnitAmount,
|
selectedAssetUnitAmount: state.selectedAssetUnitAmount,
|
||||||
ethUsdPrice: state.ethUsdPrice,
|
ethUsdPrice: state.ethUsdPrice,
|
||||||
isLoading: state.quoteRequestState === AsyncProcessState.Pending,
|
isLoading: state.quoteRequestState === AsyncProcessState.Pending,
|
||||||
|
@ -5,9 +5,9 @@ import { State } from '../redux/reducer';
|
|||||||
import { OrderState } from '../types';
|
import { OrderState } from '../types';
|
||||||
|
|
||||||
interface ConnectedState {
|
interface ConnectedState {
|
||||||
buyOrderState: OrderState;
|
swapOrderState: OrderState;
|
||||||
}
|
}
|
||||||
const mapStateToProps = (state: State, _ownProps: {}): ConnectedState => ({
|
const mapStateToProps = (state: State, _ownProps: {}): ConnectedState => ({
|
||||||
buyOrderState: state.buyOrderState,
|
swapOrderState: state.swapOrderState,
|
||||||
});
|
});
|
||||||
export const SelectedAssetBuyOrderProgress = connect(mapStateToProps)(BuyOrderProgress);
|
export const SelectedAssetBuyOrderProgress = connect(mapStateToProps)(BuyOrderProgress);
|
||||||
|
@ -19,16 +19,16 @@ interface ConnectedState {
|
|||||||
totalEthBaseUnitAmount?: BigNumber;
|
totalEthBaseUnitAmount?: BigNumber;
|
||||||
ethUsdPrice?: BigNumber;
|
ethUsdPrice?: BigNumber;
|
||||||
quoteRequestState: AsyncProcessState;
|
quoteRequestState: AsyncProcessState;
|
||||||
buyOrderState: OrderState;
|
swapOrderState: OrderState;
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state: State, _ownProps: InstantHeadingProps): ConnectedState => ({
|
const mapStateToProps = (state: State, _ownProps: InstantHeadingProps): ConnectedState => ({
|
||||||
selectedAsset: state.selectedAsset,
|
selectedAsset: state.selectedAsset,
|
||||||
selectedAssetUnitAmount: state.selectedAssetUnitAmount,
|
selectedAssetUnitAmount: state.selectedAssetUnitAmount,
|
||||||
totalEthBaseUnitAmount: oc(state).latestBuyQuote.worstCaseQuoteInfo.totalEthAmount(),
|
totalEthBaseUnitAmount: oc(state).latestSwapQuote.worstCaseQuoteInfo.totalTakerAssetAmount(),
|
||||||
ethUsdPrice: state.ethUsdPrice,
|
ethUsdPrice: state.ethUsdPrice,
|
||||||
quoteRequestState: state.quoteRequestState,
|
quoteRequestState: state.quoteRequestState,
|
||||||
buyOrderState: state.buyOrderState,
|
swapOrderState: state.swapOrderState,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const SelectedAssetInstantHeading: React.ComponentClass<InstantHeadingProps> = connect(mapStateToProps)(
|
export const SelectedAssetInstantHeading: React.ComponentClass<InstantHeadingProps> = connect(mapStateToProps)(
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { AssetBuyer } from '@0x/asset-buyer';
|
import { SwapQuoter } from '@0x/asset-swapper';
|
||||||
import { AssetProxyId } from '@0x/types';
|
import { AssetProxyId } from '@0x/types';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
@ -11,7 +11,7 @@ import { Action, actions } from '../redux/actions';
|
|||||||
import { State } from '../redux/reducer';
|
import { State } from '../redux/reducer';
|
||||||
import { ColorOption } from '../style/theme';
|
import { ColorOption } from '../style/theme';
|
||||||
import { AffiliateInfo, ERC20Asset, Omit, OrderProcessState, QuoteFetchOrigin } from '../types';
|
import { AffiliateInfo, ERC20Asset, Omit, OrderProcessState, QuoteFetchOrigin } from '../types';
|
||||||
import { buyQuoteUpdater } from '../util/buy_quote_updater';
|
import { swapQuoteUpdater } from '../util/swap_quote_updater';
|
||||||
|
|
||||||
export interface SelectedERC20AssetAmountInputProps {
|
export interface SelectedERC20AssetAmountInputProps {
|
||||||
fontColor?: ColorOption;
|
fontColor?: ColorOption;
|
||||||
@ -20,7 +20,7 @@ export interface SelectedERC20AssetAmountInputProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ConnectedState {
|
interface ConnectedState {
|
||||||
assetBuyer: AssetBuyer;
|
swapQuoter: SwapQuoter;
|
||||||
value?: BigNumber;
|
value?: BigNumber;
|
||||||
asset?: ERC20Asset;
|
asset?: ERC20Asset;
|
||||||
isInputDisabled: boolean;
|
isInputDisabled: boolean;
|
||||||
@ -30,8 +30,8 @@ interface ConnectedState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ConnectedDispatch {
|
interface ConnectedDispatch {
|
||||||
updateBuyQuote: (
|
updateSwapQuote: (
|
||||||
assetBuyer: AssetBuyer,
|
swapQuoter: SwapQuoter,
|
||||||
value?: BigNumber,
|
value?: BigNumber,
|
||||||
asset?: ERC20Asset,
|
asset?: ERC20Asset,
|
||||||
affiliateInfo?: AffiliateInfo,
|
affiliateInfo?: AffiliateInfo,
|
||||||
@ -43,7 +43,7 @@ type ConnectedProps = Omit<ERC20AssetAmountInputProps, keyof SelectedERC20AssetA
|
|||||||
type FinalProps = ConnectedProps & SelectedERC20AssetAmountInputProps;
|
type FinalProps = ConnectedProps & SelectedERC20AssetAmountInputProps;
|
||||||
|
|
||||||
const mapStateToProps = (state: State, _ownProps: SelectedERC20AssetAmountInputProps): ConnectedState => {
|
const mapStateToProps = (state: State, _ownProps: SelectedERC20AssetAmountInputProps): ConnectedState => {
|
||||||
const processState = state.buyOrderState.processState;
|
const processState = state.swapOrderState.processState;
|
||||||
const isInputEnabled = processState === OrderProcessState.None || processState === OrderProcessState.Failure;
|
const isInputEnabled = processState === OrderProcessState.None || processState === OrderProcessState.Failure;
|
||||||
const isInputDisabled = !isInputEnabled;
|
const isInputDisabled = !isInputEnabled;
|
||||||
const selectedAsset =
|
const selectedAsset =
|
||||||
@ -56,9 +56,9 @@ const mapStateToProps = (state: State, _ownProps: SelectedERC20AssetAmountInputP
|
|||||||
? isInputEnabled || processState === OrderProcessState.Success
|
? isInputEnabled || processState === OrderProcessState.Success
|
||||||
: false;
|
: false;
|
||||||
|
|
||||||
const assetBuyer = state.providerState.assetBuyer;
|
const swapQuoter = state.providerState.swapQuoter;
|
||||||
return {
|
return {
|
||||||
assetBuyer,
|
swapQuoter,
|
||||||
value: state.selectedAssetUnitAmount,
|
value: state.selectedAssetUnitAmount,
|
||||||
asset: selectedAsset,
|
asset: selectedAsset,
|
||||||
isInputDisabled,
|
isInputDisabled,
|
||||||
@ -68,27 +68,27 @@ const mapStateToProps = (state: State, _ownProps: SelectedERC20AssetAmountInputP
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const debouncedUpdateBuyQuoteAsync = _.debounce(buyQuoteUpdater.updateBuyQuoteAsync.bind(buyQuoteUpdater), 200, {
|
const debouncedUpdateSwapQuoteAsync = _.debounce(swapQuoteUpdater.updateSwapQuoteAsync.bind(swapQuoteUpdater), 200, {
|
||||||
trailing: true,
|
trailing: true,
|
||||||
}) as typeof buyQuoteUpdater.updateBuyQuoteAsync;
|
}) as typeof swapQuoteUpdater.updateSwapQuoteAsync;
|
||||||
|
|
||||||
const mapDispatchToProps = (
|
const mapDispatchToProps = (
|
||||||
dispatch: Dispatch<Action>,
|
dispatch: Dispatch<Action>,
|
||||||
_ownProps: SelectedERC20AssetAmountInputProps,
|
_ownProps: SelectedERC20AssetAmountInputProps,
|
||||||
): ConnectedDispatch => ({
|
): ConnectedDispatch => ({
|
||||||
updateBuyQuote: (assetBuyer, value, asset, affiliateInfo) => {
|
updateSwapQuote: (swapQuoter, value, asset, affiliateInfo) => {
|
||||||
// Update the input
|
// Update the input
|
||||||
dispatch(actions.updateSelectedAssetAmount(value));
|
dispatch(actions.updateSelectedAssetAmount(value));
|
||||||
// invalidate the last buy quote.
|
// invalidate the last swap quote.
|
||||||
dispatch(actions.updateLatestBuyQuote(undefined));
|
dispatch(actions.updateLatestSwapQuote(undefined));
|
||||||
// reset our buy state
|
// reset our swap state
|
||||||
dispatch(actions.setBuyOrderStateNone());
|
dispatch(actions.setSwapOrderStateNone());
|
||||||
|
|
||||||
if (value !== undefined && value.isGreaterThan(0) && asset !== undefined) {
|
if (value !== undefined && value.isGreaterThan(0) && asset !== undefined) {
|
||||||
// even if it's debounced, give them the illusion it's loading
|
// even if it's debounced, give them the illusion it's loading
|
||||||
dispatch(actions.setQuoteRequestStatePending());
|
dispatch(actions.setQuoteRequestStatePending());
|
||||||
// tslint:disable-next-line:no-floating-promises
|
// tslint:disable-next-line:no-floating-promises
|
||||||
debouncedUpdateBuyQuoteAsync(assetBuyer, dispatch, asset, value, QuoteFetchOrigin.Manual, {
|
debouncedUpdateSwapQuoteAsync(swapQuoter, dispatch, asset, value, QuoteFetchOrigin.Manual, {
|
||||||
setPending: true,
|
setPending: true,
|
||||||
dispatchErrors: true,
|
dispatchErrors: true,
|
||||||
affiliateInfo,
|
affiliateInfo,
|
||||||
@ -107,7 +107,7 @@ const mergeProps = (
|
|||||||
asset: connectedState.asset,
|
asset: connectedState.asset,
|
||||||
value: connectedState.value,
|
value: connectedState.value,
|
||||||
onChange: (value, asset) => {
|
onChange: (value, asset) => {
|
||||||
connectedDispatch.updateBuyQuote(connectedState.assetBuyer, value, asset, connectedState.affiliateInfo);
|
connectedDispatch.updateSwapQuote(connectedState.swapQuoter, value, asset, connectedState.affiliateInfo);
|
||||||
},
|
},
|
||||||
isInputDisabled: connectedState.isInputDisabled,
|
isInputDisabled: connectedState.isInputDisabled,
|
||||||
numberOfAssetsAvailable: connectedState.numberOfAssetsAvailable,
|
numberOfAssetsAvailable: connectedState.numberOfAssetsAvailable,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BuyQuote } from '@0x/asset-buyer';
|
import { MarketBuySwapQuote } from '@0x/asset-swapper';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
|
|
||||||
import { ActionsUnion, AddressAndEthBalanceInWei, Asset, BaseCurrency, StandardSlidingPanelContent } from '../types';
|
import { ActionsUnion, AddressAndEthBalanceInWei, Asset, BaseCurrency, StandardSlidingPanelContent } from '../types';
|
||||||
@ -26,12 +26,12 @@ export enum ActionTypes {
|
|||||||
UpdateAccountEthBalance = 'UPDATE_ACCOUNT_ETH_BALANCE',
|
UpdateAccountEthBalance = 'UPDATE_ACCOUNT_ETH_BALANCE',
|
||||||
UpdateEthUsdPrice = 'UPDATE_ETH_USD_PRICE',
|
UpdateEthUsdPrice = 'UPDATE_ETH_USD_PRICE',
|
||||||
UpdateSelectedAssetUnitAmount = 'UPDATE_SELECTED_ASSET_UNIT_AMOUNT',
|
UpdateSelectedAssetUnitAmount = 'UPDATE_SELECTED_ASSET_UNIT_AMOUNT',
|
||||||
SetBuyOrderStateNone = 'SET_BUY_ORDER_STATE_NONE',
|
SetSwapOrderStateNone = 'SET_SWAP_ORDER_STATE_NONE',
|
||||||
SetBuyOrderStateValidating = 'SET_BUY_ORDER_STATE_VALIDATING',
|
SetSwapOrderStateValidating = 'SET_SWAP_ORDER_STATE_VALIDATING',
|
||||||
SetBuyOrderStateProcessing = 'SET_BUY_ORDER_STATE_PROCESSING',
|
SetSwapOrderStateProcessing = 'SET_SWAP_ORDER_STATE_PROCESSING',
|
||||||
SetBuyOrderStateFailure = 'SET_BUY_ORDER_STATE_FAILURE',
|
SetSwapOrderStateFailure = 'SET_SWAP_ORDER_STATE_FAILURE',
|
||||||
SetBuyOrderStateSuccess = 'SET_BUY_ORDER_STATE_SUCCESS',
|
SetSwapOrderStateSuccess = 'SET_SWAP_ORDER_STATE_SUCCESS',
|
||||||
UpdateLatestBuyQuote = 'UPDATE_LATEST_BUY_QUOTE',
|
UpdateLatestSwapQuote = 'UPDATE_LATEST_SWAP_QUOTE',
|
||||||
UpdateSelectedAsset = 'UPDATE_SELECTED_ASSET',
|
UpdateSelectedAsset = 'UPDATE_SELECTED_ASSET',
|
||||||
SetAvailableAssets = 'SET_AVAILABLE_ASSETS',
|
SetAvailableAssets = 'SET_AVAILABLE_ASSETS',
|
||||||
SetQuoteRequestStatePending = 'SET_QUOTE_REQUEST_STATE_PENDING',
|
SetQuoteRequestStatePending = 'SET_QUOTE_REQUEST_STATE_PENDING',
|
||||||
@ -53,13 +53,13 @@ export const actions = {
|
|||||||
createAction(ActionTypes.UpdateAccountEthBalance, addressAndBalance),
|
createAction(ActionTypes.UpdateAccountEthBalance, addressAndBalance),
|
||||||
updateEthUsdPrice: (price?: BigNumber) => createAction(ActionTypes.UpdateEthUsdPrice, price),
|
updateEthUsdPrice: (price?: BigNumber) => createAction(ActionTypes.UpdateEthUsdPrice, price),
|
||||||
updateSelectedAssetAmount: (amount?: BigNumber) => createAction(ActionTypes.UpdateSelectedAssetUnitAmount, amount),
|
updateSelectedAssetAmount: (amount?: BigNumber) => createAction(ActionTypes.UpdateSelectedAssetUnitAmount, amount),
|
||||||
setBuyOrderStateNone: () => createAction(ActionTypes.SetBuyOrderStateNone),
|
setSwapOrderStateNone: () => createAction(ActionTypes.SetSwapOrderStateNone),
|
||||||
setBuyOrderStateValidating: () => createAction(ActionTypes.SetBuyOrderStateValidating),
|
setSwapOrderStateValidating: () => createAction(ActionTypes.SetSwapOrderStateValidating),
|
||||||
setBuyOrderStateProcessing: (txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) =>
|
setSwapOrderStateProcessing: (txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) =>
|
||||||
createAction(ActionTypes.SetBuyOrderStateProcessing, { txHash, startTimeUnix, expectedEndTimeUnix }),
|
createAction(ActionTypes.SetSwapOrderStateProcessing, { txHash, startTimeUnix, expectedEndTimeUnix }),
|
||||||
setBuyOrderStateFailure: (txHash: string) => createAction(ActionTypes.SetBuyOrderStateFailure, txHash),
|
setSwapOrderStateFailure: (txHash: string) => createAction(ActionTypes.SetSwapOrderStateFailure, txHash),
|
||||||
setBuyOrderStateSuccess: (txHash: string) => createAction(ActionTypes.SetBuyOrderStateSuccess, txHash),
|
setSwapOrderStateSuccess: (txHash: string) => createAction(ActionTypes.SetSwapOrderStateSuccess, txHash),
|
||||||
updateLatestBuyQuote: (buyQuote?: BuyQuote) => createAction(ActionTypes.UpdateLatestBuyQuote, buyQuote),
|
updateLatestSwapQuote: (swapQuote?: MarketBuySwapQuote) => createAction(ActionTypes.UpdateLatestSwapQuote, swapQuote),
|
||||||
updateSelectedAsset: (asset: Asset) => createAction(ActionTypes.UpdateSelectedAsset, asset),
|
updateSelectedAsset: (asset: Asset) => createAction(ActionTypes.UpdateSelectedAsset, asset),
|
||||||
setAvailableAssets: (availableAssets: Asset[]) => createAction(ActionTypes.SetAvailableAssets, availableAssets),
|
setAvailableAssets: (availableAssets: Asset[]) => createAction(ActionTypes.SetAvailableAssets, availableAssets),
|
||||||
setQuoteRequestStatePending: () => createAction(ActionTypes.SetQuoteRequestStatePending),
|
setQuoteRequestStatePending: () => createAction(ActionTypes.SetQuoteRequestStatePending),
|
||||||
|
@ -6,10 +6,10 @@ import { BIG_NUMBER_ZERO } from '../constants';
|
|||||||
import { AccountState, BaseCurrency, OrderProcessState, ProviderState, QuoteFetchOrigin } from '../types';
|
import { AccountState, BaseCurrency, OrderProcessState, ProviderState, QuoteFetchOrigin } from '../types';
|
||||||
import { analytics } from '../util/analytics';
|
import { analytics } from '../util/analytics';
|
||||||
import { assetUtils } from '../util/asset';
|
import { assetUtils } from '../util/asset';
|
||||||
import { buyQuoteUpdater } from '../util/buy_quote_updater';
|
|
||||||
import { coinbaseApi } from '../util/coinbase_api';
|
import { coinbaseApi } from '../util/coinbase_api';
|
||||||
import { errorFlasher } from '../util/error_flasher';
|
import { errorFlasher } from '../util/error_flasher';
|
||||||
import { errorReporter } from '../util/error_reporter';
|
import { errorReporter } from '../util/error_reporter';
|
||||||
|
import { swapQuoteUpdater } from '../util/swap_quote_updater';
|
||||||
|
|
||||||
import { actions } from './actions';
|
import { actions } from './actions';
|
||||||
import { State } from './reducer';
|
import { State } from './reducer';
|
||||||
@ -30,9 +30,11 @@ export const asyncData = {
|
|||||||
},
|
},
|
||||||
fetchAvailableAssetDatasAndDispatchToStore: async (state: State, dispatch: Dispatch) => {
|
fetchAvailableAssetDatasAndDispatchToStore: async (state: State, dispatch: Dispatch) => {
|
||||||
const { providerState, assetMetaDataMap, network } = state;
|
const { providerState, assetMetaDataMap, network } = state;
|
||||||
const assetBuyer = providerState.assetBuyer;
|
const swapQuoter = providerState.swapQuoter;
|
||||||
try {
|
try {
|
||||||
const assetDatas = await assetBuyer.getAvailableAssetDatasAsync();
|
// TODO(dave4506)
|
||||||
|
const wethAssetData = '';
|
||||||
|
const assetDatas = await swapQuoter.getAvailableMakerAssetDatasAsync(wethAssetData);
|
||||||
const deduplicatedAssetDatas = _.uniq(assetDatas);
|
const deduplicatedAssetDatas = _.uniq(assetDatas);
|
||||||
const assets = assetUtils.createAssetsFromAssetDatas(deduplicatedAssetDatas, assetMetaDataMap, network);
|
const assets = assetUtils.createAssetsFromAssetDatas(deduplicatedAssetDatas, assetMetaDataMap, network);
|
||||||
dispatch(actions.setAvailableAssets(assets));
|
dispatch(actions.setAvailableAssets(assets));
|
||||||
@ -87,22 +89,22 @@ export const asyncData = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fetchCurrentBuyQuoteAndDispatchToStore: async (
|
fetchCurrentSwapQuoteAndDispatchToStore: async (
|
||||||
state: State,
|
state: State,
|
||||||
dispatch: Dispatch,
|
dispatch: Dispatch,
|
||||||
fetchOrigin: QuoteFetchOrigin,
|
fetchOrigin: QuoteFetchOrigin,
|
||||||
options: { updateSilently: boolean },
|
options: { updateSilently: boolean },
|
||||||
) => {
|
) => {
|
||||||
const { buyOrderState, providerState, selectedAsset, selectedAssetUnitAmount, affiliateInfo } = state;
|
const { swapOrderState, providerState, selectedAsset, selectedAssetUnitAmount, affiliateInfo } = state;
|
||||||
const assetBuyer = providerState.assetBuyer;
|
const swapQuoter = providerState.swapQuoter;
|
||||||
if (
|
if (
|
||||||
selectedAssetUnitAmount !== undefined &&
|
selectedAssetUnitAmount !== undefined &&
|
||||||
selectedAsset !== undefined &&
|
selectedAsset !== undefined &&
|
||||||
selectedAssetUnitAmount.isGreaterThan(BIG_NUMBER_ZERO) &&
|
selectedAssetUnitAmount.isGreaterThan(BIG_NUMBER_ZERO) &&
|
||||||
buyOrderState.processState === OrderProcessState.None
|
swapOrderState.processState === OrderProcessState.None
|
||||||
) {
|
) {
|
||||||
await buyQuoteUpdater.updateBuyQuoteAsync(
|
await swapQuoteUpdater.updateSwapQuoteAsync(
|
||||||
assetBuyer,
|
swapQuoter,
|
||||||
dispatch,
|
dispatch,
|
||||||
selectedAsset,
|
selectedAsset,
|
||||||
selectedAssetUnitAmount,
|
selectedAssetUnitAmount,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BuyQuote } from '@0x/asset-buyer';
|
import { MarketBuySwapQuote } from '@0x/asset-swapper';
|
||||||
import { AssetProxyId, ObjectMap } from '@0x/types';
|
import { AssetProxyId, ObjectMap } from '@0x/types';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||||
@ -30,7 +30,7 @@ import { Action, ActionTypes } from './actions';
|
|||||||
export interface DefaultState {
|
export interface DefaultState {
|
||||||
network: Network;
|
network: Network;
|
||||||
assetMetaDataMap: ObjectMap<AssetMetaData>;
|
assetMetaDataMap: ObjectMap<AssetMetaData>;
|
||||||
buyOrderState: OrderState;
|
swapOrderState: OrderState;
|
||||||
latestErrorDisplayStatus: DisplayStatus;
|
latestErrorDisplayStatus: DisplayStatus;
|
||||||
quoteRequestState: AsyncProcessState;
|
quoteRequestState: AsyncProcessState;
|
||||||
standardSlidingPanelSettings: StandardSlidingPanelSettings;
|
standardSlidingPanelSettings: StandardSlidingPanelSettings;
|
||||||
@ -48,7 +48,7 @@ interface OptionalState {
|
|||||||
availableAssets: Asset[];
|
availableAssets: Asset[];
|
||||||
selectedAssetUnitAmount: BigNumber;
|
selectedAssetUnitAmount: BigNumber;
|
||||||
ethUsdPrice: BigNumber;
|
ethUsdPrice: BigNumber;
|
||||||
latestBuyQuote: BuyQuote;
|
latestSwapQuote: MarketBuySwapQuote;
|
||||||
latestErrorMessage: string;
|
latestErrorMessage: string;
|
||||||
affiliateInfo: AffiliateInfo;
|
affiliateInfo: AffiliateInfo;
|
||||||
walletDisplayName: string;
|
walletDisplayName: string;
|
||||||
@ -60,7 +60,7 @@ export type State = DefaultState & PropsDerivedState & Partial<OptionalState>;
|
|||||||
export const DEFAULT_STATE: DefaultState = {
|
export const DEFAULT_STATE: DefaultState = {
|
||||||
network: Network.Mainnet,
|
network: Network.Mainnet,
|
||||||
assetMetaDataMap,
|
assetMetaDataMap,
|
||||||
buyOrderState: { processState: OrderProcessState.None },
|
swapOrderState: { processState: OrderProcessState.None },
|
||||||
latestErrorDisplayStatus: DisplayStatus.Hidden,
|
latestErrorDisplayStatus: DisplayStatus.Hidden,
|
||||||
quoteRequestState: AsyncProcessState.None,
|
quoteRequestState: AsyncProcessState.None,
|
||||||
standardSlidingPanelSettings: {
|
standardSlidingPanelSettings: {
|
||||||
@ -115,14 +115,14 @@ export const createReducer = (initialState: State) => {
|
|||||||
...state,
|
...state,
|
||||||
selectedAssetUnitAmount: action.data,
|
selectedAssetUnitAmount: action.data,
|
||||||
};
|
};
|
||||||
case ActionTypes.UpdateLatestBuyQuote:
|
case ActionTypes.UpdateLatestSwapQuote:
|
||||||
const newBuyQuoteIfExists = action.data;
|
const newSwapQuoteIfExists = action.data;
|
||||||
const shouldUpdate =
|
const shouldUpdate =
|
||||||
newBuyQuoteIfExists === undefined || doesBuyQuoteMatchState(newBuyQuoteIfExists, state);
|
newSwapQuoteIfExists === undefined || doesSwapQuoteMatchState(newSwapQuoteIfExists, state);
|
||||||
if (shouldUpdate) {
|
if (shouldUpdate) {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
latestBuyQuote: newBuyQuoteIfExists,
|
latestSwapQuote: newSwapQuoteIfExists,
|
||||||
quoteRequestState: AsyncProcessState.Success,
|
quoteRequestState: AsyncProcessState.Success,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
@ -131,31 +131,31 @@ export const createReducer = (initialState: State) => {
|
|||||||
case ActionTypes.SetQuoteRequestStatePending:
|
case ActionTypes.SetQuoteRequestStatePending:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
latestBuyQuote: undefined,
|
latestSwapQuote: undefined,
|
||||||
quoteRequestState: AsyncProcessState.Pending,
|
quoteRequestState: AsyncProcessState.Pending,
|
||||||
};
|
};
|
||||||
case ActionTypes.SetQuoteRequestStateFailure:
|
case ActionTypes.SetQuoteRequestStateFailure:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
latestBuyQuote: undefined,
|
latestSwapQuote: undefined,
|
||||||
quoteRequestState: AsyncProcessState.Failure,
|
quoteRequestState: AsyncProcessState.Failure,
|
||||||
};
|
};
|
||||||
case ActionTypes.SetBuyOrderStateNone:
|
case ActionTypes.SetSwapOrderStateNone:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
buyOrderState: { processState: OrderProcessState.None },
|
swapOrderState: { processState: OrderProcessState.None },
|
||||||
};
|
};
|
||||||
case ActionTypes.SetBuyOrderStateValidating:
|
case ActionTypes.SetSwapOrderStateValidating:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
buyOrderState: { processState: OrderProcessState.Validating },
|
swapOrderState: { processState: OrderProcessState.Validating },
|
||||||
};
|
};
|
||||||
case ActionTypes.SetBuyOrderStateProcessing:
|
case ActionTypes.SetSwapOrderStateProcessing:
|
||||||
const processingData = action.data;
|
const processingData = action.data;
|
||||||
const { startTimeUnix, expectedEndTimeUnix } = processingData;
|
const { startTimeUnix, expectedEndTimeUnix } = processingData;
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
buyOrderState: {
|
swapOrderState: {
|
||||||
processState: OrderProcessState.Processing,
|
processState: OrderProcessState.Processing,
|
||||||
txHash: processingData.txHash,
|
txHash: processingData.txHash,
|
||||||
progress: {
|
progress: {
|
||||||
@ -164,14 +164,14 @@ export const createReducer = (initialState: State) => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
case ActionTypes.SetBuyOrderStateFailure:
|
case ActionTypes.SetSwapOrderStateFailure:
|
||||||
const failureTxHash = action.data;
|
const failureTxHash = action.data;
|
||||||
if ('txHash' in state.buyOrderState) {
|
if ('txHash' in state.swapOrderState) {
|
||||||
if (state.buyOrderState.txHash === failureTxHash) {
|
if (state.swapOrderState.txHash === failureTxHash) {
|
||||||
const { txHash, progress } = state.buyOrderState;
|
const { txHash, progress } = state.swapOrderState;
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
buyOrderState: {
|
swapOrderState: {
|
||||||
processState: OrderProcessState.Failure,
|
processState: OrderProcessState.Failure,
|
||||||
txHash,
|
txHash,
|
||||||
progress,
|
progress,
|
||||||
@ -180,14 +180,14 @@ export const createReducer = (initialState: State) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
case ActionTypes.SetBuyOrderStateSuccess:
|
case ActionTypes.SetSwapOrderStateSuccess:
|
||||||
const successTxHash = action.data;
|
const successTxHash = action.data;
|
||||||
if ('txHash' in state.buyOrderState) {
|
if ('txHash' in state.swapOrderState) {
|
||||||
if (state.buyOrderState.txHash === successTxHash) {
|
if (state.swapOrderState.txHash === successTxHash) {
|
||||||
const { txHash, progress } = state.buyOrderState;
|
const { txHash, progress } = state.swapOrderState;
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
buyOrderState: {
|
swapOrderState: {
|
||||||
processState: OrderProcessState.Success,
|
processState: OrderProcessState.Success,
|
||||||
txHash,
|
txHash,
|
||||||
progress,
|
progress,
|
||||||
@ -221,9 +221,9 @@ export const createReducer = (initialState: State) => {
|
|||||||
case ActionTypes.ResetAmount:
|
case ActionTypes.ResetAmount:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
latestBuyQuote: undefined,
|
latestSwapQuote: undefined,
|
||||||
quoteRequestState: AsyncProcessState.None,
|
quoteRequestState: AsyncProcessState.None,
|
||||||
buyOrderState: { processState: OrderProcessState.None },
|
swapOrderState: { processState: OrderProcessState.None },
|
||||||
selectedAssetUnitAmount: undefined,
|
selectedAssetUnitAmount: undefined,
|
||||||
};
|
};
|
||||||
case ActionTypes.SetAvailableAssets:
|
case ActionTypes.SetAvailableAssets:
|
||||||
@ -271,18 +271,18 @@ const reduceStateWithAccount = (state: State, account: Account) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const doesBuyQuoteMatchState = (buyQuote: BuyQuote, state: State): boolean => {
|
const doesSwapQuoteMatchState = (swapQuote: MarketBuySwapQuote , state: State): boolean => {
|
||||||
const selectedAssetIfExists = state.selectedAsset;
|
const selectedAssetIfExists = state.selectedAsset;
|
||||||
const selectedAssetUnitAmountIfExists = state.selectedAssetUnitAmount;
|
const selectedAssetUnitAmountIfExists = state.selectedAssetUnitAmount;
|
||||||
// if no selectedAsset or selectedAssetAmount exists on the current state, return false
|
// if no selectedAsset or selectedAssetAmount exists on the current state, return false
|
||||||
if (selectedAssetIfExists === undefined || selectedAssetUnitAmountIfExists === undefined) {
|
if (selectedAssetIfExists === undefined || selectedAssetUnitAmountIfExists === undefined) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// if buyQuote's assetData does not match that of the current selected asset, return false
|
// if swapQuote's assetData does not match that of the current selected asset, return false
|
||||||
if (selectedAssetIfExists.assetData !== buyQuote.assetData) {
|
if (selectedAssetIfExists.assetData !== swapQuote.makerAssetData) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// if ERC20 and buyQuote's assetBuyAmount does not match selectedAssetAmount, return false
|
// if ERC20 and swapQuote's makerAssetFillAmount does not match selectedAssetAmount, return false
|
||||||
// if ERC721, return true
|
// if ERC721, return true
|
||||||
const selectedAssetMetaData = selectedAssetIfExists.metaData;
|
const selectedAssetMetaData = selectedAssetIfExists.metaData;
|
||||||
if (selectedAssetMetaData.assetProxyId === AssetProxyId.ERC20) {
|
if (selectedAssetMetaData.assetProxyId === AssetProxyId.ERC20) {
|
||||||
@ -290,7 +290,7 @@ const doesBuyQuoteMatchState = (buyQuote: BuyQuote, state: State): boolean => {
|
|||||||
selectedAssetUnitAmountIfExists,
|
selectedAssetUnitAmountIfExists,
|
||||||
selectedAssetMetaData.decimals,
|
selectedAssetMetaData.decimals,
|
||||||
);
|
);
|
||||||
const doesAssetAmountMatch = selectedAssetAmountBaseUnits.eq(buyQuote.assetBuyAmount);
|
const doesAssetAmountMatch = selectedAssetAmountBaseUnits.eq(swapQuote.makerAssetFillAmount);
|
||||||
return doesAssetAmountMatch;
|
return doesAssetAmountMatch;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { AssetBuyer, BigNumber } from '@0x/asset-buyer';
|
import { BigNumber, SwapQuoteConsumer, SwapQuoter } from '@0x/asset-swapper';
|
||||||
import { AssetProxyId, ObjectMap, SignedOrder } from '@0x/types';
|
import { AssetProxyId, ObjectMap, SignedOrder } from '@0x/types';
|
||||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||||
import { SupportedProvider, ZeroExProvider } from 'ethereum-types';
|
import { SupportedProvider, ZeroExProvider } from 'ethereum-types';
|
||||||
@ -110,7 +110,8 @@ export interface ProviderState {
|
|||||||
name: string;
|
name: string;
|
||||||
displayName: string;
|
displayName: string;
|
||||||
provider: ZeroExProvider;
|
provider: ZeroExProvider;
|
||||||
assetBuyer: AssetBuyer;
|
swapQuoter: SwapQuoter;
|
||||||
|
swapQuoteConsumer: SwapQuoteConsumer;
|
||||||
web3Wrapper: Web3Wrapper;
|
web3Wrapper: Web3Wrapper;
|
||||||
account: Account;
|
account: Account;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BuyQuote } from '@0x/asset-buyer';
|
import { MarketBuySwapQuote, SwapQuote } from '@0x/asset-swapper';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
@ -82,20 +82,17 @@ function trackingEventFnWithPayload(eventName: EventNames): (eventProperties: Ev
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const buyQuoteEventProperties = (buyQuote: BuyQuote) => {
|
const swapQuoteEventProperties = (swapQuote: MarketBuySwapQuote) => {
|
||||||
const assetBuyAmount = buyQuote.assetBuyAmount.toString();
|
const assetBuyAmount = swapQuote.makerAssetFillAmount.toString();
|
||||||
const assetEthAmount = buyQuote.worstCaseQuoteInfo.assetEthAmount.toString();
|
const assetEthAmount = swapQuote.worstCaseQuoteInfo.takerAssetAmount.toString();
|
||||||
const feeEthAmount = buyQuote.worstCaseQuoteInfo.feeEthAmount.toString();
|
const feeEthAmount = swapQuote.worstCaseQuoteInfo.protocolFeeInEthAmount.plus(swapQuote.worstCaseQuoteInfo.feeTakerAssetAmount).toString();
|
||||||
const totalEthAmount = buyQuote.worstCaseQuoteInfo.totalEthAmount.toString();
|
const totalEthAmount = swapQuote.worstCaseQuoteInfo.totalTakerAssetAmount.toString();
|
||||||
const feePercentage = buyQuote.feePercentage !== undefined ? buyQuote.feePercentage.toString() : 0;
|
// const feePercentage = swapQuote.feePercentage !== undefined ? buyQuote.feePercentage.toString() : 0;
|
||||||
const hasFeeOrders = !_.isEmpty(buyQuote.feeOrders) ? 'true' : 'false';
|
|
||||||
return {
|
return {
|
||||||
assetBuyAmount,
|
assetBuyAmount,
|
||||||
assetEthAmount,
|
assetEthAmount,
|
||||||
feeEthAmount,
|
feeEthAmount,
|
||||||
totalEthAmount,
|
totalEthAmount,
|
||||||
feePercentage,
|
|
||||||
hasFeeOrders,
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -182,35 +179,35 @@ export const analytics = {
|
|||||||
trackPaymentMethodDropdownOpened: trackingEventFnWithoutPayload(EventNames.PaymentMethodDropdownOpened),
|
trackPaymentMethodDropdownOpened: trackingEventFnWithoutPayload(EventNames.PaymentMethodDropdownOpened),
|
||||||
trackPaymentMethodOpenedEtherscan: trackingEventFnWithoutPayload(EventNames.PaymentMethodOpenedEtherscan),
|
trackPaymentMethodOpenedEtherscan: trackingEventFnWithoutPayload(EventNames.PaymentMethodOpenedEtherscan),
|
||||||
trackPaymentMethodCopiedAddress: trackingEventFnWithoutPayload(EventNames.PaymentMethodCopiedAddress),
|
trackPaymentMethodCopiedAddress: trackingEventFnWithoutPayload(EventNames.PaymentMethodCopiedAddress),
|
||||||
trackBuyNotEnoughEth: (buyQuote: BuyQuote) =>
|
trackBuyNotEnoughEth: (swapQuote: MarketBuySwapQuote) =>
|
||||||
trackingEventFnWithPayload(EventNames.BuyNotEnoughEth)(buyQuoteEventProperties(buyQuote)),
|
trackingEventFnWithPayload(EventNames.BuyNotEnoughEth)(swapQuoteEventProperties(swapQuote)),
|
||||||
trackBuyStarted: (buyQuote: BuyQuote) =>
|
trackBuyStarted: (swapQuote: MarketBuySwapQuote) =>
|
||||||
trackingEventFnWithPayload(EventNames.BuyStarted)(buyQuoteEventProperties(buyQuote)),
|
trackingEventFnWithPayload(EventNames.BuyStarted)(swapQuoteEventProperties(swapQuote)),
|
||||||
trackBuySignatureDenied: (buyQuote: BuyQuote) =>
|
trackBuySignatureDenied: (swapQuote: MarketBuySwapQuote) =>
|
||||||
trackingEventFnWithPayload(EventNames.BuySignatureDenied)(buyQuoteEventProperties(buyQuote)),
|
trackingEventFnWithPayload(EventNames.BuySignatureDenied)(swapQuoteEventProperties(swapQuote)),
|
||||||
trackBuySimulationFailed: (buyQuote: BuyQuote) =>
|
trackBuySimulationFailed: (swapQuote: MarketBuySwapQuote) =>
|
||||||
trackingEventFnWithPayload(EventNames.BuySimulationFailed)(buyQuoteEventProperties(buyQuote)),
|
trackingEventFnWithPayload(EventNames.BuySimulationFailed)(swapQuoteEventProperties(swapQuote)),
|
||||||
trackBuyUnknownError: (buyQuote: BuyQuote, errorMessage: string) =>
|
trackBuyUnknownError: (swapQuote: MarketBuySwapQuote, errorMessage: string) =>
|
||||||
trackingEventFnWithPayload(EventNames.BuyUnknownError)({
|
trackingEventFnWithPayload(EventNames.BuyUnknownError)({
|
||||||
...buyQuoteEventProperties(buyQuote),
|
...swapQuoteEventProperties(swapQuote),
|
||||||
errorMessage,
|
errorMessage,
|
||||||
}),
|
}),
|
||||||
trackBuyTxSubmitted: (buyQuote: BuyQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) =>
|
trackBuyTxSubmitted: (swapQuote: MarketBuySwapQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) =>
|
||||||
trackingEventFnWithPayload(EventNames.BuyTxSubmitted)({
|
trackingEventFnWithPayload(EventNames.BuyTxSubmitted)({
|
||||||
...buyQuoteEventProperties(buyQuote),
|
...swapQuoteEventProperties(swapQuote),
|
||||||
txHash,
|
txHash,
|
||||||
expectedTxTimeMs: expectedEndTimeUnix - startTimeUnix,
|
expectedTxTimeMs: expectedEndTimeUnix - startTimeUnix,
|
||||||
}),
|
}),
|
||||||
trackBuyTxSucceeded: (buyQuote: BuyQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) =>
|
trackBuyTxSucceeded: (swapQuote: MarketBuySwapQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) =>
|
||||||
trackingEventFnWithPayload(EventNames.BuyTxSucceeded)({
|
trackingEventFnWithPayload(EventNames.BuyTxSucceeded)({
|
||||||
...buyQuoteEventProperties(buyQuote),
|
...swapQuoteEventProperties(swapQuote),
|
||||||
txHash,
|
txHash,
|
||||||
expectedTxTimeMs: expectedEndTimeUnix - startTimeUnix,
|
expectedTxTimeMs: expectedEndTimeUnix - startTimeUnix,
|
||||||
actualTxTimeMs: new Date().getTime() - startTimeUnix,
|
actualTxTimeMs: new Date().getTime() - startTimeUnix,
|
||||||
}),
|
}),
|
||||||
trackBuyTxFailed: (buyQuote: BuyQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) =>
|
trackBuyTxFailed: (swapQuote: MarketBuySwapQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) =>
|
||||||
trackingEventFnWithPayload(EventNames.BuyTxFailed)({
|
trackingEventFnWithPayload(EventNames.BuyTxFailed)({
|
||||||
...buyQuoteEventProperties(buyQuote),
|
...swapQuoteEventProperties(swapQuote),
|
||||||
txHash,
|
txHash,
|
||||||
expectedTxTimeMs: expectedEndTimeUnix - startTimeUnix,
|
expectedTxTimeMs: expectedEndTimeUnix - startTimeUnix,
|
||||||
actualTxTimeMs: new Date().getTime() - startTimeUnix,
|
actualTxTimeMs: new Date().getTime() - startTimeUnix,
|
||||||
@ -232,9 +229,9 @@ export const analytics = {
|
|||||||
trackingEventFnWithPayload(EventNames.TokenSelectorSearched)({ searchText }),
|
trackingEventFnWithPayload(EventNames.TokenSelectorSearched)({ searchText }),
|
||||||
trackTransactionViewed: (orderProcesState: OrderProcessState) =>
|
trackTransactionViewed: (orderProcesState: OrderProcessState) =>
|
||||||
trackingEventFnWithPayload(EventNames.TransactionViewed)({ orderState: orderProcesState }),
|
trackingEventFnWithPayload(EventNames.TransactionViewed)({ orderState: orderProcesState }),
|
||||||
trackQuoteFetched: (buyQuote: BuyQuote, fetchOrigin: QuoteFetchOrigin) =>
|
trackQuoteFetched: (swapQuote: MarketBuySwapQuote, fetchOrigin: QuoteFetchOrigin) =>
|
||||||
trackingEventFnWithPayload(EventNames.QuoteFetched)({
|
trackingEventFnWithPayload(EventNames.QuoteFetched)({
|
||||||
...buyQuoteEventProperties(buyQuote),
|
...swapQuoteEventProperties(swapQuote),
|
||||||
fetchOrigin,
|
fetchOrigin,
|
||||||
}),
|
}),
|
||||||
trackQuoteError: (errorMessage: string, assetBuyAmount: BigNumber, fetchOrigin: QuoteFetchOrigin) => {
|
trackQuoteError: (errorMessage: string, assetBuyAmount: BigNumber, fetchOrigin: QuoteFetchOrigin) => {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { AssetBuyerError, InsufficientAssetLiquidityError } from '@0x/asset-buyer';
|
import { InsufficientAssetLiquidityError, SwapQuoterError } from '@0x/asset-swapper';
|
||||||
import { AssetProxyId, ObjectMap } from '@0x/types';
|
import { AssetProxyId, ObjectMap } from '@0x/types';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||||
@ -109,8 +109,8 @@ export const assetUtils = {
|
|||||||
);
|
);
|
||||||
return _.compact(erc20sOrUndefined);
|
return _.compact(erc20sOrUndefined);
|
||||||
},
|
},
|
||||||
assetBuyerErrorMessage: (asset: Asset, error: Error): string | undefined => {
|
swapQuoterErrorMessage: (asset: Asset, error: Error): string | undefined => {
|
||||||
if (error.message === AssetBuyerError.InsufficientAssetLiquidity) {
|
if (error.message === SwapQuoterError.InsufficientAssetLiquidity) {
|
||||||
const assetName = assetUtils.bestNameForAsset(asset, 'of this asset');
|
const assetName = assetUtils.bestNameForAsset(asset, 'of this asset');
|
||||||
if (
|
if (
|
||||||
error instanceof InsufficientAssetLiquidityError &&
|
error instanceof InsufficientAssetLiquidityError &&
|
||||||
@ -131,11 +131,9 @@ export const assetUtils = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return `Not enough ${assetName} available`;
|
return `Not enough ${assetName} available`;
|
||||||
} else if (error.message === AssetBuyerError.InsufficientZrxLiquidity) {
|
|
||||||
return 'Not enough ZRX available';
|
|
||||||
} else if (
|
} else if (
|
||||||
error.message === AssetBuyerError.StandardRelayerApiError ||
|
error.message === SwapQuoterError.StandardRelayerApiError ||
|
||||||
error.message.startsWith(AssetBuyerError.AssetUnavailable)
|
error.message.startsWith(SwapQuoterError.AssetUnavailable)
|
||||||
) {
|
) {
|
||||||
const assetName = assetUtils.bestNameForAsset(asset, 'This asset');
|
const assetName = assetUtils.bestNameForAsset(asset, 'This asset');
|
||||||
return `${assetName} is currently unavailable`;
|
return `${assetName} is currently unavailable`;
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
import { AssetBuyer, AssetBuyerOpts } from '@0x/asset-buyer';
|
|
||||||
import { SupportedProvider } from 'ethereum-types';
|
|
||||||
import * as _ from 'lodash';
|
|
||||||
|
|
||||||
import { Network, OrderSource } from '../types';
|
|
||||||
|
|
||||||
export const assetBuyerFactory = {
|
|
||||||
getAssetBuyer: (supportedProvider: SupportedProvider, orderSource: OrderSource, network: Network): AssetBuyer => {
|
|
||||||
const assetBuyerOptions: Partial<AssetBuyerOpts> = {
|
|
||||||
networkId: network,
|
|
||||||
};
|
|
||||||
const assetBuyer = _.isString(orderSource)
|
|
||||||
? AssetBuyer.getAssetBuyerForStandardRelayerAPIUrl(supportedProvider, orderSource, assetBuyerOptions)
|
|
||||||
: AssetBuyer.getAssetBuyerForProvidedOrders(supportedProvider, orderSource, assetBuyerOptions);
|
|
||||||
return assetBuyer;
|
|
||||||
},
|
|
||||||
};
|
|
23
packages/instant/src/util/asset_swapper_factory.ts
Normal file
23
packages/instant/src/util/asset_swapper_factory.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { SwapQuoteConsumer, SwapQuoter, SwapQuoteConsumerOpts, SwapQuoterOpts } from '@0x/asset-swapper';
|
||||||
|
import { SupportedProvider } from 'ethereum-types';
|
||||||
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
|
import { Network, OrderSource } from '../types';
|
||||||
|
|
||||||
|
export const assetSwapperFactory = {
|
||||||
|
getSwapQuoter: (supportedProvider: SupportedProvider, orderSource: OrderSource, network: Network): SwapQuoter => {
|
||||||
|
const swapQuoterOpts: Partial<SwapQuoterOpts> = {
|
||||||
|
chainId: network,
|
||||||
|
};
|
||||||
|
const swapQuoter = _.isString(orderSource)
|
||||||
|
? SwapQuoter.getSwapQuoterForStandardRelayerAPIUrl(supportedProvider, orderSource, swapQuoterOpts)
|
||||||
|
: SwapQuoter.getSwapQuoterForProvidedOrders(supportedProvider, orderSource, swapQuoterOpts);
|
||||||
|
return swapQuoter;
|
||||||
|
},
|
||||||
|
getSwapQuoteConsumer: (supportedProvider: SupportedProvider, network: Network): SwapQuoteConsumer => {
|
||||||
|
const swapQuoteConsumerOptions: Partial<SwapQuoterOpts> = {
|
||||||
|
chainId: network,
|
||||||
|
};
|
||||||
|
return new SwapQuoteConsumer(supportedProvider, swapQuoteConsumerOptions );
|
||||||
|
},
|
||||||
|
};
|
@ -15,10 +15,10 @@ export const generateAccountHeartbeater = (options: HeartbeatFactoryOptions): He
|
|||||||
}, shouldPerformImmediatelyOnStart);
|
}, shouldPerformImmediatelyOnStart);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const generateBuyQuoteHeartbeater = (options: HeartbeatFactoryOptions): Heartbeater => {
|
export const generateSwapQuoteHeartbeater = (options: HeartbeatFactoryOptions): Heartbeater => {
|
||||||
const { store, shouldPerformImmediatelyOnStart } = options;
|
const { store, shouldPerformImmediatelyOnStart } = options;
|
||||||
return new Heartbeater(async () => {
|
return new Heartbeater(async () => {
|
||||||
await asyncData.fetchCurrentBuyQuoteAndDispatchToStore(
|
await asyncData.fetchCurrentSwapQuoteAndDispatchToStore(
|
||||||
store.getState(),
|
store.getState(),
|
||||||
store.dispatch,
|
store.dispatch,
|
||||||
QuoteFetchOrigin.Heartbeat,
|
QuoteFetchOrigin.Heartbeat,
|
||||||
|
@ -7,7 +7,7 @@ import { LOADING_ACCOUNT, NO_ACCOUNT } from '../constants';
|
|||||||
import { Maybe, Network, OrderSource, ProviderState } from '../types';
|
import { Maybe, Network, OrderSource, ProviderState } from '../types';
|
||||||
import { envUtil } from '../util/env';
|
import { envUtil } from '../util/env';
|
||||||
|
|
||||||
import { assetBuyerFactory } from './asset_buyer_factory';
|
import { assetSwapperFactory } from './asset_swapper_factory';
|
||||||
import { providerFactory } from './provider_factory';
|
import { providerFactory } from './provider_factory';
|
||||||
|
|
||||||
export const providerStateFactory = {
|
export const providerStateFactory = {
|
||||||
@ -48,7 +48,8 @@ export const providerStateFactory = {
|
|||||||
displayName: walletDisplayName || envUtil.getProviderDisplayName(provider),
|
displayName: walletDisplayName || envUtil.getProviderDisplayName(provider),
|
||||||
provider,
|
provider,
|
||||||
web3Wrapper: new Web3Wrapper(provider),
|
web3Wrapper: new Web3Wrapper(provider),
|
||||||
assetBuyer: assetBuyerFactory.getAssetBuyer(provider, orderSource, network),
|
swapQuoter: assetSwapperFactory.getSwapQuoter(provider, orderSource, network),
|
||||||
|
swapQuoteConsumer: assetSwapperFactory.getSwapQuoteConsumer(provider, network),
|
||||||
account: LOADING_ACCOUNT,
|
account: LOADING_ACCOUNT,
|
||||||
};
|
};
|
||||||
return providerState;
|
return providerState;
|
||||||
@ -65,7 +66,8 @@ export const providerStateFactory = {
|
|||||||
displayName: walletDisplayName || envUtil.getProviderDisplayName(injectedProviderIfExists),
|
displayName: walletDisplayName || envUtil.getProviderDisplayName(injectedProviderIfExists),
|
||||||
provider: injectedProviderIfExists,
|
provider: injectedProviderIfExists,
|
||||||
web3Wrapper: new Web3Wrapper(injectedProviderIfExists),
|
web3Wrapper: new Web3Wrapper(injectedProviderIfExists),
|
||||||
assetBuyer: assetBuyerFactory.getAssetBuyer(injectedProviderIfExists, orderSource, network),
|
swapQuoter: assetSwapperFactory.getSwapQuoter(injectedProviderIfExists, orderSource, network),
|
||||||
|
swapQuoteConsumer: assetSwapperFactory.getSwapQuoteConsumer(injectedProviderIfExists, network),
|
||||||
account: LOADING_ACCOUNT,
|
account: LOADING_ACCOUNT,
|
||||||
};
|
};
|
||||||
return providerState;
|
return providerState;
|
||||||
@ -84,7 +86,8 @@ export const providerStateFactory = {
|
|||||||
displayName: walletDisplayName || envUtil.getProviderDisplayName(provider),
|
displayName: walletDisplayName || envUtil.getProviderDisplayName(provider),
|
||||||
provider,
|
provider,
|
||||||
web3Wrapper: new Web3Wrapper(provider),
|
web3Wrapper: new Web3Wrapper(provider),
|
||||||
assetBuyer: assetBuyerFactory.getAssetBuyer(provider, orderSource, network),
|
swapQuoter: assetSwapperFactory.getSwapQuoter(provider, orderSource, network),
|
||||||
|
swapQuoteConsumer: assetSwapperFactory.getSwapQuoteConsumer(provider, network),
|
||||||
account: NO_ACCOUNT,
|
account: NO_ACCOUNT,
|
||||||
};
|
};
|
||||||
return providerState;
|
return providerState;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { AssetBuyer, BuyQuote } from '@0x/asset-buyer';
|
import { SwapQuote, SwapQuoter } from '@0x/asset-swapper';
|
||||||
import { AssetProxyId } from '@0x/types';
|
import { AssetProxyId } from '@0x/types';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||||
@ -6,17 +6,17 @@ import * as _ from 'lodash';
|
|||||||
import { Dispatch } from 'redux';
|
import { Dispatch } from 'redux';
|
||||||
import { oc } from 'ts-optchain';
|
import { oc } from 'ts-optchain';
|
||||||
|
|
||||||
import { ERC20_BUY_QUOTE_SLIPPAGE_PERCENTAGE, ERC721_BUY_QUOTE_SLIPPAGE_PERCENTAGE } from '../constants';
|
import { ERC20_SWAP_QUOTE_SLIPPAGE_PERCENTAGE, ERC721_SWAP_QUOTE_SLIPPAGE_PERCENTAGE } from '../constants';
|
||||||
import { Action, actions } from '../redux/actions';
|
import { Action, actions } from '../redux/actions';
|
||||||
import { AffiliateInfo, Asset, QuoteFetchOrigin } from '../types';
|
import { AffiliateInfo, Asset, QuoteFetchOrigin } from '../types';
|
||||||
import { analytics } from '../util/analytics';
|
import { analytics } from './analytics';
|
||||||
import { assetUtils } from '../util/asset';
|
import { assetUtils } from './asset';
|
||||||
import { errorFlasher } from '../util/error_flasher';
|
import { errorFlasher } from './error_flasher';
|
||||||
import { errorReporter } from '../util/error_reporter';
|
import { errorReporter } from './error_reporter';
|
||||||
|
|
||||||
export const buyQuoteUpdater = {
|
export const swapQuoteUpdater = {
|
||||||
updateBuyQuoteAsync: async (
|
updateSwapQuoteAsync: async (
|
||||||
assetBuyer: AssetBuyer,
|
swapQuoter: SwapQuoter,
|
||||||
dispatch: Dispatch<Action>,
|
dispatch: Dispatch<Action>,
|
||||||
asset: Asset,
|
asset: Asset,
|
||||||
assetUnitAmount: BigNumber,
|
assetUnitAmount: BigNumber,
|
||||||
@ -27,7 +27,7 @@ export const buyQuoteUpdater = {
|
|||||||
affiliateInfo?: AffiliateInfo;
|
affiliateInfo?: AffiliateInfo;
|
||||||
},
|
},
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
// get a new buy quote.
|
// get a new swap quote.
|
||||||
const baseUnitValue =
|
const baseUnitValue =
|
||||||
asset.metaData.assetProxyId === AssetProxyId.ERC20
|
asset.metaData.assetProxyId === AssetProxyId.ERC20
|
||||||
? Web3Wrapper.toBaseUnitAmount(assetUnitAmount, asset.metaData.decimals)
|
? Web3Wrapper.toBaseUnitAmount(assetUnitAmount, asset.metaData.decimals)
|
||||||
@ -36,19 +36,20 @@ export const buyQuoteUpdater = {
|
|||||||
// mark quote as pending
|
// mark quote as pending
|
||||||
dispatch(actions.setQuoteRequestStatePending());
|
dispatch(actions.setQuoteRequestStatePending());
|
||||||
}
|
}
|
||||||
|
// TODO(dave4506) expose wethAssetData + feePercentage utils
|
||||||
|
const wethAssetData = '';
|
||||||
const feePercentage = oc(options.affiliateInfo).feePercentage();
|
const feePercentage = oc(options.affiliateInfo).feePercentage();
|
||||||
let newBuyQuote: BuyQuote | undefined;
|
let newSwapQuote: SwapQuote | undefined;
|
||||||
const slippagePercentage =
|
const slippagePercentage =
|
||||||
asset.metaData.assetProxyId === AssetProxyId.ERC20
|
asset.metaData.assetProxyId === AssetProxyId.ERC20
|
||||||
? ERC20_BUY_QUOTE_SLIPPAGE_PERCENTAGE
|
? ERC20_SWAP_QUOTE_SLIPPAGE_PERCENTAGE
|
||||||
: ERC721_BUY_QUOTE_SLIPPAGE_PERCENTAGE;
|
: ERC721_SWAP_QUOTE_SLIPPAGE_PERCENTAGE;
|
||||||
try {
|
try {
|
||||||
newBuyQuote = await assetBuyer.getBuyQuoteAsync(asset.assetData, baseUnitValue, {
|
newSwapQuote = await swapQuoter.getMarketBuySwapQuoteAsync(wethAssetData, asset.assetData, assetUnitAmount, {
|
||||||
feePercentage,
|
|
||||||
slippagePercentage,
|
slippagePercentage,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage = assetUtils.assetBuyerErrorMessage(asset, error);
|
const errorMessage = assetUtils.swapQuoterErrorMessage(asset, error);
|
||||||
|
|
||||||
errorReporter.report(error);
|
errorReporter.report(error);
|
||||||
analytics.trackQuoteError(error.message ? error.message : 'other', baseUnitValue, fetchOrigin);
|
analytics.trackQuoteError(error.message ? error.message : 'other', baseUnitValue, fetchOrigin);
|
||||||
@ -59,10 +60,10 @@ export const buyQuoteUpdater = {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// We have a successful new buy quote
|
// We have a successful new swap quote
|
||||||
errorFlasher.clearError(dispatch);
|
errorFlasher.clearError(dispatch);
|
||||||
// invalidate the last buy quote.
|
// invalidate the last swap quote.
|
||||||
dispatch(actions.updateLatestBuyQuote(newBuyQuote));
|
dispatch(actions.updateLatestSwapQuote(newSwapQuote));
|
||||||
analytics.trackQuoteFetched(newBuyQuote, fetchOrigin);
|
analytics.trackQuoteFetched(newSwapQuote, fetchOrigin);
|
||||||
},
|
},
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user