fixed bugs preventing build

This commit is contained in:
David Sun
2019-11-14 18:09:03 -05:00
committed by Jacob Evans
parent 6498d385ee
commit 9a552012f2
15 changed files with 141 additions and 123 deletions

View File

@@ -31,6 +31,7 @@ export { InsufficientAssetLiquidityError } from './errors';
export {
SwapQuoterError,
SwapQuoteConsumerError,
SwapQuoterOpts,
SwapQuote,
SwapQuoteConsumerOpts,

View File

@@ -226,7 +226,7 @@ export class SwapQuoter {
takerTokenAddress: string,
makerAssetBuyAmount: BigNumber,
options: Partial<SwapQuoteRequestOpts> = {},
): Promise<SwapQuote> {
): Promise<MarketBuySwapQuote> {
assert.isETHAddressHex('makerTokenAddress', makerTokenAddress);
assert.isETHAddressHex('takerTokenAddress', takerTokenAddress);
assert.isBigNumber('makerAssetBuyAmount', makerAssetBuyAmount);
@@ -256,7 +256,7 @@ export class SwapQuoter {
takerTokenAddress: string,
takerAssetSellAmount: BigNumber,
options: Partial<SwapQuoteRequestOpts> = {},
): Promise<SwapQuote> {
): Promise<MarketSellSwapQuote> {
assert.isETHAddressHex('makerTokenAddress', makerTokenAddress);
assert.isETHAddressHex('takerTokenAddress', takerTokenAddress);
assert.isBigNumber('takerAssetSellAmount', takerAssetSellAmount);

View File

@@ -1,4 +1,4 @@
import { AssetBuyer, AssetBuyerError, BuyQuote } from '@0x/asset-buyer';
import { affiliateFeeUtils, ExtensionContractType, MarketBuySwapQuote, SwapQuoteConsumer, SwapQuoteConsumerError, SwapQuoter } from '@0x/asset-swapper';
import { AssetProxyId } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
@@ -19,17 +19,18 @@ import { Button } from './ui/button';
export interface BuyButtonProps {
accountAddress?: string;
accountEthBalanceInWei?: BigNumber;
buyQuote?: BuyQuote;
assetBuyer: AssetBuyer;
swapQuote?: MarketBuySwapQuote;
swapQuoter: SwapQuoter;
swapQuoteConsumer: SwapQuoteConsumer;
web3Wrapper: Web3Wrapper;
affiliateInfo?: AffiliateInfo;
selectedAsset?: Asset;
onValidationPending: (buyQuote: BuyQuote) => void;
onValidationFail: (buyQuote: BuyQuote, errorMessage: AssetBuyerError | ZeroExInstantError) => void;
onSignatureDenied: (buyQuote: BuyQuote) => void;
onBuyProcessing: (buyQuote: BuyQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => void;
onBuySuccess: (buyQuote: BuyQuote, txHash: string) => void;
onBuyFailure: (buyQuote: BuyQuote, txHash: string) => void;
onValidationPending: (swapQuote: MarketBuySwapQuote) => void;
onValidationFail: (swapQuote: MarketBuySwapQuote, errorMessage: SwapQuoteConsumerError | ZeroExInstantError) => void;
onSignatureDenied: (swapQuote: MarketBuySwapQuote) => void;
onBuyProcessing: (swapQuote: MarketBuySwapQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => void;
onBuySuccess: (swapQuote: MarketBuySwapQuote, txHash: string) => void;
onBuyFailure: (swapQuote: MarketBuySwapQuote, txHash: string) => void;
}
export class BuyButton extends React.PureComponent<BuyButtonProps> {
@@ -39,8 +40,8 @@ export class BuyButton extends React.PureComponent<BuyButtonProps> {
onBuyFailure: util.boundNoop,
};
public render(): React.ReactNode {
const { buyQuote, accountAddress, selectedAsset } = this.props;
const shouldDisableButton = buyQuote === undefined || accountAddress === undefined;
const { swapQuote, accountAddress, selectedAsset } = this.props;
const shouldDisableButton = swapQuote === undefined || accountAddress === undefined;
const buttonText =
selectedAsset !== undefined && selectedAsset.metaData.assetProxyId === AssetProxyId.ERC20
? `Buy ${selectedAsset.metaData.symbol.toUpperCase()}`
@@ -58,43 +59,45 @@ export class BuyButton extends React.PureComponent<BuyButtonProps> {
}
private readonly _handleClick = async () => {
// The button is disabled when there is no buy quote anyway.
const { buyQuote, assetBuyer, affiliateInfo, accountAddress, accountEthBalanceInWei, web3Wrapper } = this.props;
if (buyQuote === undefined || accountAddress === undefined) {
const { swapQuote, swapQuoteConsumer, affiliateInfo, accountAddress, accountEthBalanceInWei, web3Wrapper } = this.props;
if (swapQuote === undefined || accountAddress === undefined) {
return;
}
this.props.onValidationPending(buyQuote);
const ethNeededForBuy = buyQuote.worstCaseQuoteInfo.totalEthAmount;
this.props.onValidationPending(swapQuote);
// TODO(dave4506)
const ethNeededForBuy = affiliateFeeUtils.getTotalEthAmountWithAffiliateFee(swapQuote.worstCaseQuoteInfo, 0);
// if we don't have a balance for the user, let the transaction through, it will be handled by the wallet
const hasSufficientEth = accountEthBalanceInWei === undefined || accountEthBalanceInWei.gte(ethNeededForBuy);
if (!hasSufficientEth) {
analytics.trackBuyNotEnoughEth(buyQuote);
this.props.onValidationFail(buyQuote, ZeroExInstantError.InsufficientETH);
analytics.trackBuyNotEnoughEth(swapQuote);
this.props.onValidationFail(swapQuote, ZeroExInstantError.InsufficientETH);
return;
}
let txHash: string | undefined;
const gasInfo = await gasPriceEstimator.getGasInfoAsync();
const feeRecipient = oc(affiliateInfo).feeRecipient();
try {
analytics.trackBuyStarted(buyQuote);
txHash = await assetBuyer.executeBuyQuoteAsync(buyQuote, {
feeRecipient,
analytics.trackBuyStarted(swapQuote);
// TODO(dave4506)
txHash = await swapQuoteConsumer.executeSwapQuoteOrThrowAsync(swapQuote, {
useExtensionContract: ExtensionContractType.Forwarder,
takerAddress: accountAddress,
gasPrice: gasInfo.gasPriceInWei,
});
} catch (e) {
if (e instanceof Error) {
if (e.message === AssetBuyerError.TransactionValueTooLow) {
analytics.trackBuySimulationFailed(buyQuote);
this.props.onValidationFail(buyQuote, AssetBuyerError.TransactionValueTooLow);
if (e.message === SwapQuoteConsumerError.TransactionValueTooLow) {
analytics.trackBuySimulationFailed(swapQuote);
this.props.onValidationFail(swapQuote, SwapQuoteConsumerError.TransactionValueTooLow);
return;
} else if (e.message === AssetBuyerError.SignatureRequestDenied) {
analytics.trackBuySignatureDenied(buyQuote);
this.props.onSignatureDenied(buyQuote);
} else if (e.message === SwapQuoteConsumerError.SignatureRequestDenied) {
analytics.trackBuySignatureDenied(swapQuote);
this.props.onSignatureDenied(swapQuote);
return;
} else {
errorReporter.report(e);
analytics.trackBuyUnknownError(buyQuote, e.message);
this.props.onValidationFail(buyQuote, ZeroExInstantError.CouldNotSubmitTransaction);
analytics.trackBuyUnknownError(swapQuote, e.message);
this.props.onValidationFail(swapQuote, ZeroExInstantError.CouldNotSubmitTransaction);
return;
}
}
@@ -102,19 +105,19 @@ export class BuyButton extends React.PureComponent<BuyButtonProps> {
}
const startTimeUnix = new Date().getTime();
const expectedEndTimeUnix = startTimeUnix + gasInfo.estimatedTimeMs;
this.props.onBuyProcessing(buyQuote, txHash, startTimeUnix, expectedEndTimeUnix);
this.props.onBuyProcessing(swapQuote, txHash, startTimeUnix, expectedEndTimeUnix);
try {
analytics.trackBuyTxSubmitted(buyQuote, txHash, startTimeUnix, expectedEndTimeUnix);
analytics.trackBuyTxSubmitted(swapQuote, txHash, startTimeUnix, expectedEndTimeUnix);
await web3Wrapper.awaitTransactionSuccessAsync(txHash);
} catch (e) {
if (e instanceof Error && e.message.startsWith(WEB_3_WRAPPER_TRANSACTION_FAILED_ERROR_MSG_PREFIX)) {
analytics.trackBuyTxFailed(buyQuote, txHash, startTimeUnix, expectedEndTimeUnix);
this.props.onBuyFailure(buyQuote, txHash);
analytics.trackBuyTxFailed(swapQuote, txHash, startTimeUnix, expectedEndTimeUnix);
this.props.onBuyFailure(swapQuote, txHash);
return;
}
throw e;
}
analytics.trackBuyTxSucceeded(buyQuote, txHash, startTimeUnix, expectedEndTimeUnix);
this.props.onBuySuccess(buyQuote, txHash);
analytics.trackBuyTxSucceeded(swapQuote, txHash, startTimeUnix, expectedEndTimeUnix);
this.props.onBuySuccess(swapQuote, txHash);
};
}

View File

@@ -7,18 +7,18 @@ import { Container } from '../components/ui/container';
import { OrderProcessState, OrderState } from '../types';
export interface BuyOrderProgressProps {
buyOrderState: OrderState;
swapOrderState: OrderState;
}
export const BuyOrderProgress: React.StatelessComponent<BuyOrderProgressProps> = props => {
const { buyOrderState } = props;
const { swapOrderState } = props;
if (
buyOrderState.processState === OrderProcessState.Processing ||
buyOrderState.processState === OrderProcessState.Success ||
buyOrderState.processState === OrderProcessState.Failure
swapOrderState.processState === OrderProcessState.Processing ||
swapOrderState.processState === OrderProcessState.Success ||
swapOrderState.processState === OrderProcessState.Failure
) {
const progress = buyOrderState.progress;
const hasEnded = buyOrderState.processState !== OrderProcessState.Processing;
const progress = swapOrderState.progress;
const hasEnded = swapOrderState.processState !== OrderProcessState.Processing;
const expectedTimeMs = progress.expectedEndTimeUnix - progress.startTimeUnix;
return (
<Container width="100%" padding="20px 20px 0px 20px">

View File

@@ -1,4 +1,4 @@
import { AssetBuyer, AssetBuyerError, BuyQuote } from '@0x/asset-buyer';
import { MarketBuySwapQuote, SwapQuoteConsumer, SwapQuoter, SwapQuoterError, SwapQuoteConsumerError } from '@0x/asset-swapper';
import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as React from 'react';
@@ -16,19 +16,20 @@ import { Flex } from './ui/flex';
export interface BuyOrderStateButtonProps {
accountAddress?: string;
accountEthBalanceInWei?: BigNumber;
buyQuote?: BuyQuote;
swapQuote?: MarketBuySwapQuote;
buyOrderProcessingState: OrderProcessState;
assetBuyer: AssetBuyer;
swapQuoter: SwapQuoter;
swapQuoteConsumer: SwapQuoteConsumer;
web3Wrapper: Web3Wrapper;
affiliateInfo?: AffiliateInfo;
selectedAsset?: Asset;
onViewTransaction: () => void;
onValidationPending: (buyQuote: BuyQuote) => void;
onValidationFail: (buyQuote: BuyQuote, errorMessage: AssetBuyerError | ZeroExInstantError) => void;
onSignatureDenied: (buyQuote: BuyQuote) => void;
onBuyProcessing: (buyQuote: BuyQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => void;
onBuySuccess: (buyQuote: BuyQuote, txHash: string) => void;
onBuyFailure: (buyQuote: BuyQuote, txHash: string) => void;
onValidationPending: (swapQuote: MarketBuySwapQuote) => void;
onValidationFail: (swapQuote: MarketBuySwapQuote, errorMessage: SwapQuoteConsumerError | ZeroExInstantError) => void;
onSignatureDenied: (swapQuote: MarketBuySwapQuote) => void;
onBuyProcessing: (swapQuote: MarketBuySwapQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => void;
onBuySuccess: (swapQuote: MarketBuySwapQuote, txHash: string) => void;
onBuyFailure: (swapQuote: MarketBuySwapQuote, txHash: string) => void;
onRetry: () => void;
}
@@ -57,8 +58,9 @@ export const BuyOrderStateButtons: React.StatelessComponent<BuyOrderStateButtonP
<BuyButton
accountAddress={props.accountAddress}
accountEthBalanceInWei={props.accountEthBalanceInWei}
buyQuote={props.buyQuote}
assetBuyer={props.assetBuyer}
swapQuote={props.swapQuote}
swapQuoter={props.swapQuoter}
swapQuoteConsumer={props.swapQuoteConsumer}
web3Wrapper={props.web3Wrapper}
affiliateInfo={props.affiliateInfo}
selectedAsset={props.selectedAsset}

View File

@@ -22,7 +22,7 @@ export interface InstantHeadingProps {
totalEthBaseUnitAmount?: BigNumber;
ethUsdPrice?: BigNumber;
quoteRequestState: AsyncProcessState;
buyOrderState: OrderState;
swapOrderState: OrderState;
onSelectAssetClick?: (asset?: ERC20Asset) => void;
}
@@ -127,7 +127,7 @@ export class InstantHeading extends React.PureComponent<InstantHeadingProps, {}>
}
private _renderIcon(): React.ReactNode {
const processState = this.props.buyOrderState.processState;
const processState = this.props.swapOrderState.processState;
if (processState === OrderProcessState.Failure) {
return <Icon icon="failed" width={ICON_WIDTH} height={ICON_HEIGHT} color={ICON_COLOR} />;
@@ -140,7 +140,7 @@ export class InstantHeading extends React.PureComponent<InstantHeadingProps, {}>
}
private _renderTopText(): React.ReactNode {
const processState = this.props.buyOrderState.processState;
const processState = this.props.swapOrderState.processState;
if (processState === OrderProcessState.Failure) {
return 'Order failed';
} else if (processState === OrderProcessState.Processing) {

View File

@@ -1,4 +1,4 @@
import { BuyQuoteInfo } from '@0x/asset-buyer';
import { SwapQuoteInfo } from '@0x/asset-swapper';
import { BigNumber } from '@0x/utils';
import * as _ from 'lodash';
import * as React from 'react';
@@ -17,7 +17,7 @@ import { Flex } from './ui/flex';
import { Text, TextProps } from './ui/text';
export interface OrderDetailsProps {
buyQuoteInfo?: BuyQuoteInfo;
swapQuoteInfo?: SwapQuoteInfo;
selectedAssetUnitAmount?: BigNumber;
ethUsdPrice?: BigNumber;
isLoading: boolean;
@@ -37,22 +37,23 @@ export class OrderDetails extends React.PureComponent<OrderDetailsProps> {
);
}
// TODO(dave4506) adjust fees for the new system (add affiliate fees)
private _renderRows(): React.ReactNode {
const { buyQuoteInfo } = this.props;
const { swapQuoteInfo } = this.props;
return (
<React.Fragment>
<OrderDetailsRow
labelText={this._assetAmountLabel()}
primaryValue={this._displayAmountOrPlaceholder(buyQuoteInfo && buyQuoteInfo.assetEthAmount)}
primaryValue={this._displayAmountOrPlaceholder(swapQuoteInfo && swapQuoteInfo.takerAssetAmount)}
/>
<OrderDetailsRow
labelText="Fee"
primaryValue={this._displayAmountOrPlaceholder(buyQuoteInfo && buyQuoteInfo.feeEthAmount)}
primaryValue={this._displayAmountOrPlaceholder(swapQuoteInfo && swapQuoteInfo.feeTakerAssetAmount.plus(swapQuoteInfo.protocolFeeInEthAmount))}
/>
<OrderDetailsRow
labelText="Total Cost"
isLabelBold={true}
primaryValue={this._displayAmountOrPlaceholder(buyQuoteInfo && buyQuoteInfo.totalEthAmount)}
primaryValue={this._displayAmountOrPlaceholder(swapQuoteInfo && swapQuoteInfo.totalTakerAssetAmount.plus(swapQuoteInfo.protocolFeeInEthAmount))}
isPrimaryValueBold={true}
secondaryValue={this._totalCostSecondaryValue()}
/>
@@ -87,8 +88,8 @@ export class OrderDetails extends React.PureComponent<OrderDetailsProps> {
secondaryCurrency === BaseCurrency.ETH ||
(secondaryCurrency === BaseCurrency.USD && this.props.ethUsdPrice && !this._hadErrorFetchingUsdPrice());
if (this.props.buyQuoteInfo && canDisplayCurrency) {
return this._displayAmount(secondaryCurrency, this.props.buyQuoteInfo.totalEthAmount);
if (this.props.swapQuoteInfo && canDisplayCurrency) {
return this._displayAmount(secondaryCurrency, this.props.swapQuoteInfo.totalTakerAssetAmount.plus(this.props.swapQuoteInfo.protocolFeeInEthAmount));
} else {
return undefined;
}
@@ -150,8 +151,8 @@ export class OrderDetails extends React.PureComponent<OrderDetailsProps> {
}
private _pricePerTokenWei(): BigNumber | undefined {
const buyQuoteAccessor = oc(this.props.buyQuoteInfo);
const assetTotalInWei = buyQuoteAccessor.assetEthAmount();
const swapQuoteAccessor = oc(this.props.swapQuoteInfo);
const assetTotalInWei = swapQuoteAccessor.totalTakerAssetAmount();
const selectedAssetUnitAmount = this.props.selectedAssetUnitAmount;
return assetTotalInWei !== undefined &&
selectedAssetUnitAmount !== undefined &&

View File

@@ -4,7 +4,7 @@ import * as _ from 'lodash';
import * as React from 'react';
import { Provider as ReduxProvider } from 'react-redux';
import { ACCOUNT_UPDATE_INTERVAL_TIME_MS, BUY_QUOTE_UPDATE_INTERVAL_TIME_MS } from '../constants';
import { ACCOUNT_UPDATE_INTERVAL_TIME_MS, SWAP_QUOTE_UPDATE_INTERVAL_TIME_MS } from '../constants';
import { SelectedAssetThemeProvider } from '../containers/selected_asset_theme_provider';
import { asyncData } from '../redux/async_data';
import { DEFAULT_STATE, DefaultState, State } from '../redux/reducer';
@@ -17,7 +17,7 @@ import { errorFlasher } from '../util/error_flasher';
import { setupRollbar } from '../util/error_reporter';
import { gasPriceEstimator } from '../util/gas_price_estimator';
import { Heartbeater } from '../util/heartbeater';
import { generateAccountHeartbeater, generateBuyQuoteHeartbeater } from '../util/heartbeater_factory';
import { generateAccountHeartbeater, generateSwapQuoteHeartbeater } from '../util/heartbeater_factory';
import { providerStateFactory } from '../util/provider_state_factory';
export type ZeroExInstantProviderProps = ZeroExInstantBaseConfig;
@@ -25,7 +25,7 @@ export type ZeroExInstantProviderProps = ZeroExInstantBaseConfig;
export class ZeroExInstantProvider extends React.PureComponent<ZeroExInstantProviderProps> {
private readonly _store: Store;
private _accountUpdateHeartbeat?: Heartbeater;
private _buyQuoteHeartbeat?: Heartbeater;
private _swapQuoteHeartbeat?: Heartbeater;
// TODO(fragosti): Write tests for this beast once we inject a provider.
private static _mergeDefaultStateWithProps(
@@ -114,14 +114,14 @@ export class ZeroExInstantProvider extends React.PureComponent<ZeroExInstantProv
this._accountUpdateHeartbeat.start(ACCOUNT_UPDATE_INTERVAL_TIME_MS);
}
this._buyQuoteHeartbeat = generateBuyQuoteHeartbeater({
this._swapQuoteHeartbeat = generateSwapQuoteHeartbeater({
store: this._store,
shouldPerformImmediatelyOnStart: false,
});
this._buyQuoteHeartbeat.start(BUY_QUOTE_UPDATE_INTERVAL_TIME_MS);
this._swapQuoteHeartbeat.start(SWAP_QUOTE_UPDATE_INTERVAL_TIME_MS);
// Trigger first buyquote fetch
// tslint:disable-next-line:no-floating-promises
asyncData.fetchCurrentBuyQuoteAndDispatchToStore(state, dispatch, QuoteFetchOrigin.Manual, {
asyncData.fetchCurrentSwapQuoteAndDispatchToStore(state, dispatch, QuoteFetchOrigin.Manual, {
updateSilently: false,
});
// warm up the gas price estimator cache just in case we can't
@@ -150,8 +150,8 @@ export class ZeroExInstantProvider extends React.PureComponent<ZeroExInstantProv
if (this._accountUpdateHeartbeat) {
this._accountUpdateHeartbeat.stop();
}
if (this._buyQuoteHeartbeat) {
this._buyQuoteHeartbeat.stop();
if (this._swapQuoteHeartbeat) {
this._swapQuoteHeartbeat.stop();
}
}
public render(): React.ReactNode {

View File

@@ -16,7 +16,7 @@ type DispatchProperties = 'onBaseCurrencySwitchEth' | 'onBaseCurrencySwitchUsd';
interface ConnectedState extends Omit<OrderDetailsProps, DispatchProperties> {}
const mapStateToProps = (state: State, _ownProps: LatestBuyQuoteOrderDetailsProps): ConnectedState => ({
// use the worst case quote info
buyQuoteInfo: oc(state).latestSwapQuote.worstCaseQuoteInfo(),
swapQuoteInfo: oc(state).latestSwapQuote.worstCaseQuoteInfo(),
selectedAssetUnitAmount: state.selectedAssetUnitAmount,
ethUsdPrice: state.ethUsdPrice,
isLoading: state.quoteRequestState === AsyncProcessState.Pending,

View File

@@ -1,4 +1,4 @@
import { AssetBuyer, AssetBuyerError, BuyQuote } from '@0x/asset-buyer';
import { SwapQuoter, SwapQuoterError, MarketBuySwapQuote, SwapQuoteConsumer, SwapQuote } from '@0x/asset-swapper';
import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as _ from 'lodash';
@@ -16,9 +16,10 @@ import { etherscanUtil } from '../util/etherscan';
interface ConnectedState {
accountAddress?: string;
accountEthBalanceInWei?: BigNumber;
buyQuote?: BuyQuote;
buyOrderProcessingState: OrderProcessState;
assetBuyer: AssetBuyer;
swapQuote?: MarketBuySwapQuote;
swapOrderProcessingState: OrderProcessState;
swapQuoter: SwapQuoter;
swapQuoteConsumer: SwapQuoteConsumer;
web3Wrapper: Web3Wrapper;
affiliateInfo?: AffiliateInfo;
selectedAsset?: Asset;
@@ -27,17 +28,19 @@ interface ConnectedState {
}
interface ConnectedDispatch {
onValidationPending: (buyQuote: BuyQuote) => void;
onSignatureDenied: (buyQuote: BuyQuote) => void;
onBuyProcessing: (buyQuote: BuyQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => void;
onBuySuccess: (buyQuote: BuyQuote, txHash: string) => void;
onBuyFailure: (buyQuote: BuyQuote, txHash: string) => void;
onValidationPending: (swapQuote: MarketBuySwapQuote) => void;
onSignatureDenied: (swapQuote: MarketBuySwapQuote) => void;
onBuyProcessing: (swapQuote: MarketBuySwapQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => void;
onBuySuccess: (swapQuote: MarketBuySwapQuote, txHash: string) => void;
onBuyFailure: (swapQuote: MarketBuySwapQuote, txHash: string) => void;
onRetry: () => void;
onValidationFail: (buyQuote: BuyQuote, errorMessage: AssetBuyerError | ZeroExInstantError) => void;
onValidationFail: (swapQuote: MarketBuySwapQuote, errorMessage: SwapQuoterError | ZeroExInstantError) => void;
}
export interface SelectedAssetBuyOrderStateButtons {}
const mapStateToProps = (state: State, _ownProps: SelectedAssetBuyOrderStateButtons): ConnectedState => {
const assetBuyer = state.providerState.assetBuyer;
const swapQuoter = state.providerState.swapQuoter;
const swapQuoteConsumer = state.providerState.swapQuoteConsumer;
const chainId = swapQuoteConsumer.chainId;
const web3Wrapper = state.providerState.web3Wrapper;
const account = state.providerState.account;
const accountAddress = account.state === AccountState.Ready ? account.address : undefined;
@@ -46,25 +49,26 @@ const mapStateToProps = (state: State, _ownProps: SelectedAssetBuyOrderStateButt
return {
accountAddress,
accountEthBalanceInWei,
buyOrderProcessingState: state.buyOrderState.processState,
assetBuyer,
swapOrderProcessingState: state.swapOrderState.processState,
swapQuoter,
swapQuoteConsumer,
web3Wrapper,
buyQuote: state.latestBuyQuote,
swapQuote: state.latestSwapQuote,
affiliateInfo: state.affiliateInfo,
selectedAsset,
onSuccess: state.onSuccess,
onViewTransaction: () => {
if (
state.buyOrderState.processState === OrderProcessState.Processing ||
state.buyOrderState.processState === OrderProcessState.Success ||
state.buyOrderState.processState === OrderProcessState.Failure
state.swapOrderState.processState === OrderProcessState.Processing ||
state.swapOrderState.processState === OrderProcessState.Success ||
state.swapOrderState.processState === OrderProcessState.Failure
) {
const etherscanUrl = etherscanUtil.getEtherScanTxnAddressIfExists(
state.buyOrderState.txHash,
assetBuyer.networkId,
state.swapOrderState.txHash,
chainId,
);
if (etherscanUrl) {
analytics.trackTransactionViewed(state.buyOrderState.processState);
analytics.trackTransactionViewed(state.swapOrderState.processState);
window.open(etherscanUrl, '_blank');
return;
@@ -78,21 +82,21 @@ const mapDispatchToProps = (
dispatch: Dispatch<Action>,
ownProps: SelectedAssetBuyOrderStateButtons,
): ConnectedDispatch => ({
onValidationPending: (buyQuote: BuyQuote) => {
dispatch(actions.setBuyOrderStateValidating());
onValidationPending: (swapQuote: MarketBuySwapQuote) => {
dispatch(actions.setSwapOrderStateValidating());
},
onBuyProcessing: (buyQuote: BuyQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => {
dispatch(actions.setBuyOrderStateProcessing(txHash, startTimeUnix, expectedEndTimeUnix));
onBuyProcessing: (swapQuote: MarketBuySwapQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => {
dispatch(actions.setSwapOrderStateProcessing(txHash, startTimeUnix, expectedEndTimeUnix));
},
onBuySuccess: (buyQuote: BuyQuote, txHash: string) => dispatch(actions.setBuyOrderStateSuccess(txHash)),
onBuyFailure: (buyQuote: BuyQuote, txHash: string) => dispatch(actions.setBuyOrderStateFailure(txHash)),
onBuySuccess: (swapQuote: MarketBuySwapQuote, txHash: string) => dispatch(actions.setSwapOrderStateSuccess(txHash)),
onBuyFailure: (swapQuote: MarketBuySwapQuote, txHash: string) => dispatch(actions.setSwapOrderStateFailure(txHash)),
onSignatureDenied: () => {
dispatch(actions.resetAmount());
const errorMessage = 'You denied this transaction';
errorFlasher.flashNewErrorMessage(dispatch, errorMessage);
},
onValidationFail: (buyQuote, error) => {
dispatch(actions.setBuyOrderStateNone());
onValidationFail: (swapQuote, error) => {
dispatch(actions.setSwapOrderStateNone());
if (error === ZeroExInstantError.InsufficientETH) {
const errorMessage = "You don't have enough ETH";
errorFlasher.flashNewErrorMessage(dispatch, errorMessage);
@@ -117,8 +121,8 @@ const mergeProps = (
...ownProps,
...connectedState,
...connectedDispatch,
onBuySuccess: (buyQuote: BuyQuote, txHash: string) => {
connectedDispatch.onBuySuccess(buyQuote, txHash);
onBuySuccess: (swapQuote: MarketBuySwapQuote, txHash: string) => {
connectedDispatch.onBuySuccess(swapQuote, txHash);
if (connectedState.onSuccess) {
connectedState.onSuccess(txHash);
}

View File

@@ -1,4 +1,4 @@
import { AssetBuyer, BigNumber } from '@0x/asset-buyer';
import { BigNumber, SwapQuoter } from '@0x/asset-swapper';
import { assetDataUtils } from '@0x/order-utils';
import { AssetProxyId } from '@0x/types';
import { providerUtils } from '@0x/utils';
@@ -83,7 +83,7 @@ export const unrender = () => {
const renderInstant = (config: ZeroExInstantConfig, selector: string) => {
const appendToIfExists = document.querySelector(selector);
assert.assert(appendToIfExists !== null, `Could not find div with selector: ${selector}`);
parentElement = appendToIfExists as Element;
parentElement = appendToIfExists;
injectedDiv = document.createElement('div');
injectedDiv.setAttribute('id', INJECTED_DIV_ID);
injectedDiv.setAttribute('class', INJECTED_DIV_CLASS);
@@ -172,30 +172,31 @@ export const hasMetaDataForAssetData = (assetData: string): boolean => {
};
export const hasLiquidityForAssetDataAsync = async (
assetData: string,
takerAssetData: string,
orderSource: OrderSource,
networkId: Network = Network.Mainnet,
chainId: Network = Network.Mainnet,
supportedProvider?: SupportedProvider,
): Promise<boolean> => {
assert.isHexString('assetData', assetData);
assert.isHexString('takerAssetData', takerAssetData);
assert.isValidOrderSource('orderSource', orderSource);
assert.isNumber('networkId', networkId);
assert.isNumber('chainId', chainId);
let provider = supportedProvider;
if (provider !== undefined) {
provider = providerUtils.standardizeOrThrow(provider);
}
const bestProvider: ZeroExProvider = provider || providerFactory.getFallbackNoSigningProvider(networkId);
const bestProvider: ZeroExProvider = provider || providerFactory.getFallbackNoSigningProvider(chainId);
const assetBuyerOptions = { networkId };
const swapQuoterOptions = { chainId };
const assetBuyer = _.isString(orderSource)
? AssetBuyer.getAssetBuyerForStandardRelayerAPIUrl(bestProvider, orderSource, assetBuyerOptions)
: AssetBuyer.getAssetBuyerForProvidedOrders(bestProvider, orderSource, assetBuyerOptions);
const swapQuoter = _.isString(orderSource)
? SwapQuoter.getSwapQuoterForStandardRelayerAPIUrl(bestProvider, orderSource, swapQuoterOptions)
: SwapQuoter.getSwapQuoterForProvidedOrders(bestProvider, orderSource, swapQuoterOptions);
const liquidity = await assetBuyer.getLiquidityForAssetDataAsync(assetData);
return liquidity.ethValueAvailableInWei.gt(new BigNumber(0));
const wethAssetData = await swapQuoter.getEtherTokenAssetDataOrThrowAsync();
const liquidity = await swapQuoter.getLiquidityForMakerTakerAssetDataPairAsync(wethAssetData, takerAssetData);
return liquidity.makerAssetAvailableInBaseUnits.gt(new BigNumber(0));
};
// Write version info to the exported object for debugging

View File

@@ -32,8 +32,7 @@ export const asyncData = {
const { providerState, assetMetaDataMap, network } = state;
const swapQuoter = providerState.swapQuoter;
try {
// TODO(dave4506)
const wethAssetData = '';
const wethAssetData = await swapQuoter.getEtherTokenAssetDataOrThrowAsync();
const assetDatas = await swapQuoter.getAvailableMakerAssetDatasAsync(wethAssetData);
const deduplicatedAssetDatas = _.uniq(assetDatas);
const assets = assetUtils.createAssetsFromAssetDatas(deduplicatedAssetDatas, assetMetaDataMap, network);

View File

@@ -1,4 +1,4 @@
import { SwapQuote, SwapQuoter } from '@0x/asset-swapper';
import { SwapQuote, SwapQuoter, MarketBuySwapQuote } from '@0x/asset-swapper';
import { AssetProxyId } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
@@ -39,7 +39,7 @@ export const swapQuoteUpdater = {
// TODO(dave4506) expose wethAssetData + feePercentage utils
const wethAssetData = '';
const feePercentage = oc(options.affiliateInfo).feePercentage();
let newSwapQuote: SwapQuote | undefined;
let newSwapQuote: MarketBuySwapQuote | undefined;
const slippagePercentage =
asset.metaData.assetProxyId === AssetProxyId.ERC20
? ERC20_SWAP_QUOTE_SLIPPAGE_PERCENTAGE

View File

@@ -38,6 +38,7 @@ export const docGenConfigs: DocGenConfigs = {
'SubscriptionErrors',
'TypedDataError',
'SwapQuoterError',
'SwapQuoteConsumerError',
'SwapQuoteGetOutputOpts',
'SwapQuoteExecutionOpts',
'ForwarderError',

View File

@@ -2006,6 +2006,12 @@
dependencies:
"@types/node" "*"
"@types/bn.js@^4.11.0":
version "4.11.0"
resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-4.11.0.tgz#401cb20874f0a7b8414e46308a99c449759b7de9"
dependencies:
"@types/node" "*"
"@types/cheerio@*":
version "0.22.9"
resolved "https://registry.npmjs.org/@types/cheerio/-/cheerio-0.22.9.tgz#b5990152604c2ada749b7f88cab3476f21f39d7b"