prettier + minor changes
This commit is contained in:
parent
1135d5a971
commit
c198d0079e
@ -89,11 +89,7 @@ export class ForwarderSwapQuoteConsumer implements SwapQuoteConsumerBase<Forward
|
|||||||
): Promise<SmartContractParamsInfo<ForwarderSmartContractParams>> {
|
): Promise<SmartContractParamsInfo<ForwarderSmartContractParams>> {
|
||||||
assert.isValidForwarderSwapQuote('quote', quote, await this._getEtherTokenAssetDataOrThrowAsync());
|
assert.isValidForwarderSwapQuote('quote', quote, await this._getEtherTokenAssetDataOrThrowAsync());
|
||||||
|
|
||||||
const { extensionContractOpts } = _.merge(
|
const { extensionContractOpts } = _.merge({}, constants.DEFAULT_FORWARDER_SWAP_QUOTE_GET_OPTS, opts);
|
||||||
{},
|
|
||||||
constants.DEFAULT_FORWARDER_SWAP_QUOTE_GET_OPTS,
|
|
||||||
opts,
|
|
||||||
);
|
|
||||||
|
|
||||||
assert.isValidForwarderExtensionContractOpts('extensionContractOpts', extensionContractOpts);
|
assert.isValidForwarderExtensionContractOpts('extensionContractOpts', extensionContractOpts);
|
||||||
|
|
||||||
|
@ -9,9 +9,7 @@ import { SwapQuoterError } from '../types';
|
|||||||
export class ProtocolFeeUtils {
|
export class ProtocolFeeUtils {
|
||||||
private readonly _exchangeContract: ExchangeContract;
|
private readonly _exchangeContract: ExchangeContract;
|
||||||
|
|
||||||
constructor(
|
constructor(exchangeContract: ExchangeContract) {
|
||||||
exchangeContract: ExchangeContract,
|
|
||||||
) {
|
|
||||||
this._exchangeContract = exchangeContract;
|
this._exchangeContract = exchangeContract;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +39,10 @@ export class ProtocolFeeUtils {
|
|||||||
/**
|
/**
|
||||||
* Calculates protocol fee with protofol fee multiplier for each fill.
|
* Calculates protocol fee with protofol fee multiplier for each fill.
|
||||||
*/
|
*/
|
||||||
public async calculateWorstCaseProtocolFeeAsync<T extends Order>(orders: T[], gasPrice: BigNumber): Promise<BigNumber> {
|
public async calculateWorstCaseProtocolFeeAsync<T extends Order>(
|
||||||
|
orders: T[],
|
||||||
|
gasPrice: BigNumber,
|
||||||
|
): Promise<BigNumber> {
|
||||||
const protocolFeeMultiplier = await this.getProtocolFeeMultiplierAsync();
|
const protocolFeeMultiplier = await this.getProtocolFeeMultiplierAsync();
|
||||||
const protocolFee = new BigNumber(orders.length).times(protocolFeeMultiplier).times(gasPrice);
|
const protocolFee = new BigNumber(orders.length).times(protocolFeeMultiplier).times(gasPrice);
|
||||||
return protocolFee;
|
return protocolFee;
|
||||||
|
@ -26,14 +26,14 @@ export const swapQuoteCalculator = {
|
|||||||
gasPrice: BigNumber,
|
gasPrice: BigNumber,
|
||||||
protocolFeeUtils: ProtocolFeeUtils,
|
protocolFeeUtils: ProtocolFeeUtils,
|
||||||
): Promise<MarketSellSwapQuote> {
|
): Promise<MarketSellSwapQuote> {
|
||||||
return await calculateSwapQuoteAsync(
|
return (await calculateSwapQuoteAsync(
|
||||||
prunedOrders,
|
prunedOrders,
|
||||||
takerAssetFillAmount,
|
takerAssetFillAmount,
|
||||||
slippagePercentage,
|
slippagePercentage,
|
||||||
gasPrice,
|
gasPrice,
|
||||||
protocolFeeUtils,
|
protocolFeeUtils,
|
||||||
MarketOperation.Sell,
|
MarketOperation.Sell,
|
||||||
) as MarketSellSwapQuote;
|
)) as MarketSellSwapQuote;
|
||||||
},
|
},
|
||||||
async calculateMarketBuySwapQuoteAsync(
|
async calculateMarketBuySwapQuoteAsync(
|
||||||
prunedOrders: PrunedSignedOrder[],
|
prunedOrders: PrunedSignedOrder[],
|
||||||
@ -42,14 +42,14 @@ export const swapQuoteCalculator = {
|
|||||||
gasPrice: BigNumber,
|
gasPrice: BigNumber,
|
||||||
protocolFeeUtils: ProtocolFeeUtils,
|
protocolFeeUtils: ProtocolFeeUtils,
|
||||||
): Promise<MarketBuySwapQuote> {
|
): Promise<MarketBuySwapQuote> {
|
||||||
return await calculateSwapQuoteAsync(
|
return (await calculateSwapQuoteAsync(
|
||||||
prunedOrders,
|
prunedOrders,
|
||||||
takerAssetFillAmount,
|
takerAssetFillAmount,
|
||||||
slippagePercentage,
|
slippagePercentage,
|
||||||
gasPrice,
|
gasPrice,
|
||||||
protocolFeeUtils,
|
protocolFeeUtils,
|
||||||
MarketOperation.Buy,
|
MarketOperation.Buy,
|
||||||
) as MarketBuySwapQuote;
|
)) as MarketBuySwapQuote;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -103,7 +103,13 @@ async function calculateSwapQuoteAsync(
|
|||||||
const takerAssetData = resultOrders[0].takerAssetData;
|
const takerAssetData = resultOrders[0].takerAssetData;
|
||||||
const makerAssetData = resultOrders[0].makerAssetData;
|
const makerAssetData = resultOrders[0].makerAssetData;
|
||||||
|
|
||||||
const bestCaseQuoteInfo = await calculateQuoteInfoAsync(resultOrders, assetFillAmount, gasPrice, protocolFeeUtils, marketOperation);
|
const bestCaseQuoteInfo = await calculateQuoteInfoAsync(
|
||||||
|
resultOrders,
|
||||||
|
assetFillAmount,
|
||||||
|
gasPrice,
|
||||||
|
protocolFeeUtils,
|
||||||
|
marketOperation,
|
||||||
|
);
|
||||||
// in order to calculate the maxRate, reverse the ordersAndFillableAmounts such that they are sorted from worst rate to best rate
|
// in order to calculate the maxRate, reverse the ordersAndFillableAmounts such that they are sorted from worst rate to best rate
|
||||||
const worstCaseQuoteInfo = await calculateQuoteInfoAsync(
|
const worstCaseQuoteInfo = await calculateQuoteInfoAsync(
|
||||||
_.reverse(_.clone(resultOrders)),
|
_.reverse(_.clone(resultOrders)),
|
||||||
|
@ -1,4 +1,11 @@
|
|||||||
import { affiliateFeeUtils, ExtensionContractType, MarketBuySwapQuote, SwapQuoteConsumer, SwapQuoteConsumerError, SwapQuoter } from '@0x/asset-swapper';
|
import {
|
||||||
|
affiliateFeeUtils,
|
||||||
|
ExtensionContractType,
|
||||||
|
MarketBuySwapQuote,
|
||||||
|
SwapQuoteConsumer,
|
||||||
|
SwapQuoteConsumerError,
|
||||||
|
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';
|
||||||
@ -26,9 +33,17 @@ export interface BuyButtonProps {
|
|||||||
affiliateInfo?: AffiliateInfo;
|
affiliateInfo?: AffiliateInfo;
|
||||||
selectedAsset?: Asset;
|
selectedAsset?: Asset;
|
||||||
onValidationPending: (swapQuote: MarketBuySwapQuote) => void;
|
onValidationPending: (swapQuote: MarketBuySwapQuote) => void;
|
||||||
onValidationFail: (swapQuote: MarketBuySwapQuote, errorMessage: SwapQuoteConsumerError | ZeroExInstantError) => void;
|
onValidationFail: (
|
||||||
|
swapQuote: MarketBuySwapQuote,
|
||||||
|
errorMessage: SwapQuoteConsumerError | ZeroExInstantError,
|
||||||
|
) => void;
|
||||||
onSignatureDenied: (swapQuote: MarketBuySwapQuote) => void;
|
onSignatureDenied: (swapQuote: MarketBuySwapQuote) => void;
|
||||||
onBuyProcessing: (swapQuote: MarketBuySwapQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => void;
|
onBuyProcessing: (
|
||||||
|
swapQuote: MarketBuySwapQuote,
|
||||||
|
txHash: string,
|
||||||
|
startTimeUnix: number,
|
||||||
|
expectedEndTimeUnix: number,
|
||||||
|
) => void;
|
||||||
onBuySuccess: (swapQuote: MarketBuySwapQuote, txHash: string) => void;
|
onBuySuccess: (swapQuote: MarketBuySwapQuote, txHash: string) => void;
|
||||||
onBuyFailure: (swapQuote: MarketBuySwapQuote, txHash: string) => void;
|
onBuyFailure: (swapQuote: MarketBuySwapQuote, txHash: string) => void;
|
||||||
}
|
}
|
||||||
@ -59,7 +74,14 @@ export class BuyButton extends React.PureComponent<BuyButtonProps> {
|
|||||||
}
|
}
|
||||||
private readonly _handleClick = async () => {
|
private readonly _handleClick = async () => {
|
||||||
// The button is disabled when there is no buy quote anyway.
|
// The button is disabled when there is no buy quote anyway.
|
||||||
const { swapQuote, swapQuoteConsumer, affiliateInfo, accountAddress, accountEthBalanceInWei, web3Wrapper } = this.props;
|
const {
|
||||||
|
swapQuote,
|
||||||
|
swapQuoteConsumer,
|
||||||
|
affiliateInfo,
|
||||||
|
accountAddress,
|
||||||
|
accountEthBalanceInWei,
|
||||||
|
web3Wrapper,
|
||||||
|
} = this.props;
|
||||||
if (swapQuote === undefined || accountAddress === undefined) {
|
if (swapQuote === undefined || accountAddress === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
import { MarketBuySwapQuote, SwapQuoteConsumer, SwapQuoter, SwapQuoterError, SwapQuoteConsumerError } from '@0x/asset-swapper';
|
import {
|
||||||
|
MarketBuySwapQuote,
|
||||||
|
SwapQuoteConsumer,
|
||||||
|
SwapQuoter,
|
||||||
|
SwapQuoterError,
|
||||||
|
SwapQuoteConsumerError,
|
||||||
|
} from '@0x/asset-swapper';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
@ -25,9 +31,17 @@ export interface BuyOrderStateButtonProps {
|
|||||||
selectedAsset?: Asset;
|
selectedAsset?: Asset;
|
||||||
onViewTransaction: () => void;
|
onViewTransaction: () => void;
|
||||||
onValidationPending: (swapQuote: MarketBuySwapQuote) => void;
|
onValidationPending: (swapQuote: MarketBuySwapQuote) => void;
|
||||||
onValidationFail: (swapQuote: MarketBuySwapQuote, errorMessage: SwapQuoteConsumerError | ZeroExInstantError) => void;
|
onValidationFail: (
|
||||||
|
swapQuote: MarketBuySwapQuote,
|
||||||
|
errorMessage: SwapQuoteConsumerError | ZeroExInstantError,
|
||||||
|
) => void;
|
||||||
onSignatureDenied: (swapQuote: MarketBuySwapQuote) => void;
|
onSignatureDenied: (swapQuote: MarketBuySwapQuote) => void;
|
||||||
onBuyProcessing: (swapQuote: MarketBuySwapQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => void;
|
onBuyProcessing: (
|
||||||
|
swapQuote: MarketBuySwapQuote,
|
||||||
|
txHash: string,
|
||||||
|
startTimeUnix: number,
|
||||||
|
expectedEndTimeUnix: number,
|
||||||
|
) => void;
|
||||||
onBuySuccess: (swapQuote: MarketBuySwapQuote, txHash: string) => void;
|
onBuySuccess: (swapQuote: MarketBuySwapQuote, txHash: string) => void;
|
||||||
onBuyFailure: (swapQuote: MarketBuySwapQuote, txHash: string) => void;
|
onBuyFailure: (swapQuote: MarketBuySwapQuote, txHash: string) => void;
|
||||||
onRetry: () => void;
|
onRetry: () => void;
|
||||||
|
@ -37,7 +37,7 @@ export class OrderDetails extends React.PureComponent<OrderDetailsProps> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(dave4506) adjust fees for the new system (add affiliate fees)
|
// TODO(dave4506) currently instant has affiliate fees disabled, until we resolve that, this displays only takerFees + protocolFees
|
||||||
private _renderRows(): React.ReactNode {
|
private _renderRows(): React.ReactNode {
|
||||||
const { swapQuoteInfo } = this.props;
|
const { swapQuoteInfo } = this.props;
|
||||||
return (
|
return (
|
||||||
@ -48,12 +48,16 @@ export class OrderDetails extends React.PureComponent<OrderDetailsProps> {
|
|||||||
/>
|
/>
|
||||||
<OrderDetailsRow
|
<OrderDetailsRow
|
||||||
labelText="Fee"
|
labelText="Fee"
|
||||||
primaryValue={this._displayAmountOrPlaceholder(swapQuoteInfo && swapQuoteInfo.feeTakerAssetAmount.plus(swapQuoteInfo.protocolFeeInEthAmount))}
|
primaryValue={this._displayAmountOrPlaceholder(
|
||||||
|
swapQuoteInfo && swapQuoteInfo.feeTakerAssetAmount.plus(swapQuoteInfo.protocolFeeInEthAmount),
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
<OrderDetailsRow
|
<OrderDetailsRow
|
||||||
labelText="Total Cost"
|
labelText="Total Cost"
|
||||||
isLabelBold={true}
|
isLabelBold={true}
|
||||||
primaryValue={this._displayAmountOrPlaceholder(swapQuoteInfo && swapQuoteInfo.totalTakerAssetAmount.plus(swapQuoteInfo.protocolFeeInEthAmount))}
|
primaryValue={this._displayAmountOrPlaceholder(
|
||||||
|
swapQuoteInfo && swapQuoteInfo.totalTakerAssetAmount.plus(swapQuoteInfo.protocolFeeInEthAmount),
|
||||||
|
)}
|
||||||
isPrimaryValueBold={true}
|
isPrimaryValueBold={true}
|
||||||
secondaryValue={this._totalCostSecondaryValue()}
|
secondaryValue={this._totalCostSecondaryValue()}
|
||||||
/>
|
/>
|
||||||
@ -89,7 +93,10 @@ export class OrderDetails extends React.PureComponent<OrderDetailsProps> {
|
|||||||
(secondaryCurrency === BaseCurrency.USD && this.props.ethUsdPrice && !this._hadErrorFetchingUsdPrice());
|
(secondaryCurrency === BaseCurrency.USD && this.props.ethUsdPrice && !this._hadErrorFetchingUsdPrice());
|
||||||
|
|
||||||
if (this.props.swapQuoteInfo && canDisplayCurrency) {
|
if (this.props.swapQuoteInfo && canDisplayCurrency) {
|
||||||
return this._displayAmount(secondaryCurrency, this.props.swapQuoteInfo.totalTakerAssetAmount.plus(this.props.swapQuoteInfo.protocolFeeInEthAmount));
|
return this._displayAmount(
|
||||||
|
secondaryCurrency,
|
||||||
|
this.props.swapQuoteInfo.totalTakerAssetAmount.plus(this.props.swapQuoteInfo.protocolFeeInEthAmount),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,6 @@ export class ZeroExInstantProvider extends React.PureComponent<ZeroExInstantProv
|
|||||||
networkId,
|
networkId,
|
||||||
),
|
),
|
||||||
assetMetaDataMap: completeAssetMetaDataMap,
|
assetMetaDataMap: completeAssetMetaDataMap,
|
||||||
affiliateInfo: props.affiliateInfo,
|
|
||||||
onSuccess: props.onSuccess,
|
onSuccess: props.onSuccess,
|
||||||
};
|
};
|
||||||
return storeStateFromProps;
|
return storeStateFromProps;
|
||||||
@ -140,7 +139,7 @@ export class ZeroExInstantProvider extends React.PureComponent<ZeroExInstantProv
|
|||||||
state.providerState,
|
state.providerState,
|
||||||
window,
|
window,
|
||||||
state.selectedAsset,
|
state.selectedAsset,
|
||||||
this.props.affiliateInfo,
|
undefined,
|
||||||
state.baseCurrency,
|
state.baseCurrency,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
import { MarketBuySwapQuote, SwapQuoteConsumer, SwapQuoteConsumerError, SwapQuoter, SwapQuoterError } from '@0x/asset-swapper';
|
import {
|
||||||
|
MarketBuySwapQuote,
|
||||||
|
SwapQuoteConsumer,
|
||||||
|
SwapQuoteConsumerError,
|
||||||
|
SwapQuoter,
|
||||||
|
SwapQuoterError,
|
||||||
|
} from '@0x/asset-swapper';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
@ -30,11 +36,19 @@ interface ConnectedState {
|
|||||||
interface ConnectedDispatch {
|
interface ConnectedDispatch {
|
||||||
onValidationPending: (swapQuote: MarketBuySwapQuote) => void;
|
onValidationPending: (swapQuote: MarketBuySwapQuote) => void;
|
||||||
onSignatureDenied: (swapQuote: MarketBuySwapQuote) => void;
|
onSignatureDenied: (swapQuote: MarketBuySwapQuote) => void;
|
||||||
onBuyProcessing: (swapQuote: MarketBuySwapQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => void;
|
onBuyProcessing: (
|
||||||
|
swapQuote: MarketBuySwapQuote,
|
||||||
|
txHash: string,
|
||||||
|
startTimeUnix: number,
|
||||||
|
expectedEndTimeUnix: number,
|
||||||
|
) => void;
|
||||||
onBuySuccess: (swapQuote: MarketBuySwapQuote, txHash: string) => void;
|
onBuySuccess: (swapQuote: MarketBuySwapQuote, txHash: string) => void;
|
||||||
onBuyFailure: (swapQuote: MarketBuySwapQuote, txHash: string) => void;
|
onBuyFailure: (swapQuote: MarketBuySwapQuote, txHash: string) => void;
|
||||||
onRetry: () => void;
|
onRetry: () => void;
|
||||||
onValidationFail: (swapQuote: MarketBuySwapQuote, errorMessage: SwapQuoteConsumerError | ZeroExInstantError) => void;
|
onValidationFail: (
|
||||||
|
swapQuote: MarketBuySwapQuote,
|
||||||
|
errorMessage: SwapQuoteConsumerError | ZeroExInstantError,
|
||||||
|
) => void;
|
||||||
}
|
}
|
||||||
export interface SelectedAssetBuyOrderStateButtons {}
|
export interface SelectedAssetBuyOrderStateButtons {}
|
||||||
const mapStateToProps = (state: State, _ownProps: SelectedAssetBuyOrderStateButtons): ConnectedState => {
|
const mapStateToProps = (state: State, _ownProps: SelectedAssetBuyOrderStateButtons): ConnectedState => {
|
||||||
@ -63,10 +77,7 @@ const mapStateToProps = (state: State, _ownProps: SelectedAssetBuyOrderStateButt
|
|||||||
state.swapOrderState.processState === OrderProcessState.Success ||
|
state.swapOrderState.processState === OrderProcessState.Success ||
|
||||||
state.swapOrderState.processState === OrderProcessState.Failure
|
state.swapOrderState.processState === OrderProcessState.Failure
|
||||||
) {
|
) {
|
||||||
const etherscanUrl = etherscanUtil.getEtherScanTxnAddressIfExists(
|
const etherscanUrl = etherscanUtil.getEtherScanTxnAddressIfExists(state.swapOrderState.txHash, chainId);
|
||||||
state.swapOrderState.txHash,
|
|
||||||
chainId,
|
|
||||||
);
|
|
||||||
if (etherscanUrl) {
|
if (etherscanUrl) {
|
||||||
analytics.trackTransactionViewed(state.swapOrderState.processState);
|
analytics.trackTransactionViewed(state.swapOrderState.processState);
|
||||||
|
|
||||||
@ -85,7 +96,12 @@ const mapDispatchToProps = (
|
|||||||
onValidationPending: (swapQuote: MarketBuySwapQuote) => {
|
onValidationPending: (swapQuote: MarketBuySwapQuote) => {
|
||||||
dispatch(actions.setSwapOrderStateValidating());
|
dispatch(actions.setSwapOrderStateValidating());
|
||||||
},
|
},
|
||||||
onBuyProcessing: (swapQuote: MarketBuySwapQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => {
|
onBuyProcessing: (
|
||||||
|
swapQuote: MarketBuySwapQuote,
|
||||||
|
txHash: string,
|
||||||
|
startTimeUnix: number,
|
||||||
|
expectedEndTimeUnix: number,
|
||||||
|
) => {
|
||||||
dispatch(actions.setSwapOrderStateProcessing(txHash, startTimeUnix, expectedEndTimeUnix));
|
dispatch(actions.setSwapOrderStateProcessing(txHash, startTimeUnix, expectedEndTimeUnix));
|
||||||
},
|
},
|
||||||
onBuySuccess: (swapQuote: MarketBuySwapQuote, txHash: string) => dispatch(actions.setSwapOrderStateSuccess(txHash)),
|
onBuySuccess: (swapQuote: MarketBuySwapQuote, txHash: string) => dispatch(actions.setSwapOrderStateSuccess(txHash)),
|
||||||
|
@ -29,11 +29,7 @@ interface ConnectedState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ConnectedDispatch {
|
interface ConnectedDispatch {
|
||||||
updateSwapQuote: (
|
updateSwapQuote: (swapQuoter: SwapQuoter, value?: BigNumber, asset?: ERC20Asset) => void;
|
||||||
swapQuoter: SwapQuoter,
|
|
||||||
value?: BigNumber,
|
|
||||||
asset?: ERC20Asset,
|
|
||||||
) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConnectedProps = Omit<ERC20AssetAmountInputProps, keyof SelectedERC20AssetAmountInputProps>;
|
type ConnectedProps = Omit<ERC20AssetAmountInputProps, keyof SelectedERC20AssetAmountInputProps>;
|
||||||
|
@ -48,9 +48,10 @@ const validateInstantRenderConfig = (config: ZeroExInstantConfig, selector: stri
|
|||||||
if (config.zIndex !== undefined) {
|
if (config.zIndex !== undefined) {
|
||||||
assert.isNumber('zIndex', config.zIndex);
|
assert.isNumber('zIndex', config.zIndex);
|
||||||
}
|
}
|
||||||
if (config.affiliateInfo !== undefined) {
|
// TODO(dave4506) reenable affiliate fees once we figure out how to work with it
|
||||||
assert.isValidAffiliateInfo('affiliateInfo', config.affiliateInfo);
|
// if (config.affiliateInfo !== undefined) {
|
||||||
}
|
// assert.isValidAffiliateInfo('affiliateInfo', config.affiliateInfo);
|
||||||
|
// }
|
||||||
if (config.provider !== undefined) {
|
if (config.provider !== undefined) {
|
||||||
providerUtils.standardizeOrThrow(config.provider);
|
providerUtils.standardizeOrThrow(config.provider);
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,8 @@ export const actions = {
|
|||||||
createAction(ActionTypes.SetSwapOrderStateProcessing, { txHash, startTimeUnix, expectedEndTimeUnix }),
|
createAction(ActionTypes.SetSwapOrderStateProcessing, { txHash, startTimeUnix, expectedEndTimeUnix }),
|
||||||
setSwapOrderStateFailure: (txHash: string) => createAction(ActionTypes.SetSwapOrderStateFailure, txHash),
|
setSwapOrderStateFailure: (txHash: string) => createAction(ActionTypes.SetSwapOrderStateFailure, txHash),
|
||||||
setSwapOrderStateSuccess: (txHash: string) => createAction(ActionTypes.SetSwapOrderStateSuccess, txHash),
|
setSwapOrderStateSuccess: (txHash: string) => createAction(ActionTypes.SetSwapOrderStateSuccess, txHash),
|
||||||
updateLatestSwapQuote: (swapQuote?: MarketBuySwapQuote) => createAction(ActionTypes.UpdateLatestSwapQuote, swapQuote),
|
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),
|
||||||
|
@ -200,7 +200,6 @@ export interface ZeroExInstantOptionalBaseConfig {
|
|||||||
defaultSelectedAssetData: string;
|
defaultSelectedAssetData: string;
|
||||||
additionalAssetMetaDataMap: ObjectMap<AssetMetaData>;
|
additionalAssetMetaDataMap: ObjectMap<AssetMetaData>;
|
||||||
networkId: Network;
|
networkId: Network;
|
||||||
affiliateInfo: AffiliateInfo;
|
|
||||||
shouldDisableAnalyticsTracking: boolean;
|
shouldDisableAnalyticsTracking: boolean;
|
||||||
onSuccess?: (txHash: string) => void;
|
onSuccess?: (txHash: string) => void;
|
||||||
}
|
}
|
||||||
|
@ -85,13 +85,18 @@ function trackingEventFnWithPayload(eventName: EventNames): (eventProperties: Ev
|
|||||||
const swapQuoteEventProperties = (swapQuote: MarketBuySwapQuote) => {
|
const swapQuoteEventProperties = (swapQuote: MarketBuySwapQuote) => {
|
||||||
const makerAssetFillAmount = swapQuote.makerAssetFillAmount.toString();
|
const makerAssetFillAmount = swapQuote.makerAssetFillAmount.toString();
|
||||||
const assetEthAmount = swapQuote.worstCaseQuoteInfo.takerAssetAmount.toString();
|
const assetEthAmount = swapQuote.worstCaseQuoteInfo.takerAssetAmount.toString();
|
||||||
const feeEthAmount = swapQuote.worstCaseQuoteInfo.protocolFeeInEthAmount.plus(swapQuote.worstCaseQuoteInfo.feeTakerAssetAmount).toString();
|
const feeEthAmount = swapQuote.worstCaseQuoteInfo.protocolFeeInEthAmount
|
||||||
const totalEthAmount = swapQuote.worstCaseQuoteInfo.totalTakerAssetAmount.toString();
|
.plus(swapQuote.worstCaseQuoteInfo.feeTakerAssetAmount)
|
||||||
|
.toString();
|
||||||
|
const totalEthAmount = swapQuote.worstCaseQuoteInfo.totalTakerAssetAmount
|
||||||
|
.plus(swapQuote.worstCaseQuoteInfo.protocolFeeInEthAmount)
|
||||||
|
.toString();
|
||||||
return {
|
return {
|
||||||
makerAssetFillAmount,
|
makerAssetFillAmount,
|
||||||
assetEthAmount,
|
assetEthAmount,
|
||||||
feeEthAmount,
|
feeEthAmount,
|
||||||
totalEthAmount,
|
totalEthAmount,
|
||||||
|
gasPrice: swapQuote.gasPrice,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -191,20 +196,35 @@ export const analytics = {
|
|||||||
...swapQuoteEventProperties(swapQuote),
|
...swapQuoteEventProperties(swapQuote),
|
||||||
errorMessage,
|
errorMessage,
|
||||||
}),
|
}),
|
||||||
trackBuyTxSubmitted: (swapQuote: MarketBuySwapQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) =>
|
trackBuyTxSubmitted: (
|
||||||
|
swapQuote: MarketBuySwapQuote,
|
||||||
|
txHash: string,
|
||||||
|
startTimeUnix: number,
|
||||||
|
expectedEndTimeUnix: number,
|
||||||
|
) =>
|
||||||
trackingEventFnWithPayload(EventNames.BuyTxSubmitted)({
|
trackingEventFnWithPayload(EventNames.BuyTxSubmitted)({
|
||||||
...swapQuoteEventProperties(swapQuote),
|
...swapQuoteEventProperties(swapQuote),
|
||||||
txHash,
|
txHash,
|
||||||
expectedTxTimeMs: expectedEndTimeUnix - startTimeUnix,
|
expectedTxTimeMs: expectedEndTimeUnix - startTimeUnix,
|
||||||
}),
|
}),
|
||||||
trackBuyTxSucceeded: (swapQuote: MarketBuySwapQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) =>
|
trackBuyTxSucceeded: (
|
||||||
|
swapQuote: MarketBuySwapQuote,
|
||||||
|
txHash: string,
|
||||||
|
startTimeUnix: number,
|
||||||
|
expectedEndTimeUnix: number,
|
||||||
|
) =>
|
||||||
trackingEventFnWithPayload(EventNames.BuyTxSucceeded)({
|
trackingEventFnWithPayload(EventNames.BuyTxSucceeded)({
|
||||||
...swapQuoteEventProperties(swapQuote),
|
...swapQuoteEventProperties(swapQuote),
|
||||||
txHash,
|
txHash,
|
||||||
expectedTxTimeMs: expectedEndTimeUnix - startTimeUnix,
|
expectedTxTimeMs: expectedEndTimeUnix - startTimeUnix,
|
||||||
actualTxTimeMs: new Date().getTime() - startTimeUnix,
|
actualTxTimeMs: new Date().getTime() - startTimeUnix,
|
||||||
}),
|
}),
|
||||||
trackBuyTxFailed: (swapQuote: MarketBuySwapQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) =>
|
trackBuyTxFailed: (
|
||||||
|
swapQuote: MarketBuySwapQuote,
|
||||||
|
txHash: string,
|
||||||
|
startTimeUnix: number,
|
||||||
|
expectedEndTimeUnix: number,
|
||||||
|
) =>
|
||||||
trackingEventFnWithPayload(EventNames.BuyTxFailed)({
|
trackingEventFnWithPayload(EventNames.BuyTxFailed)({
|
||||||
...swapQuoteEventProperties(swapQuote),
|
...swapQuoteEventProperties(swapQuote),
|
||||||
txHash,
|
txHash,
|
||||||
|
@ -35,7 +35,6 @@ export const swapQuoteUpdater = {
|
|||||||
// mark quote as pending
|
// mark quote as pending
|
||||||
dispatch(actions.setQuoteRequestStatePending());
|
dispatch(actions.setQuoteRequestStatePending());
|
||||||
}
|
}
|
||||||
// TODO(dave4506) expose wethAssetData + feePercentage utils
|
|
||||||
const wethAssetData = await swapQuoter.getEtherTokenAssetDataOrThrowAsync();
|
const wethAssetData = await swapQuoter.getEtherTokenAssetDataOrThrowAsync();
|
||||||
let newSwapQuote: MarketBuySwapQuote | undefined;
|
let newSwapQuote: MarketBuySwapQuote | undefined;
|
||||||
const slippagePercentage =
|
const slippagePercentage =
|
||||||
@ -43,9 +42,14 @@ export const swapQuoteUpdater = {
|
|||||||
? ERC20_SWAP_QUOTE_SLIPPAGE_PERCENTAGE
|
? ERC20_SWAP_QUOTE_SLIPPAGE_PERCENTAGE
|
||||||
: ERC721_SWAP_QUOTE_SLIPPAGE_PERCENTAGE;
|
: ERC721_SWAP_QUOTE_SLIPPAGE_PERCENTAGE;
|
||||||
try {
|
try {
|
||||||
newSwapQuote = await swapQuoter.getMarketBuySwapQuoteAsync(wethAssetData, asset.assetData, assetUnitAmount, {
|
newSwapQuote = await swapQuoter.getMarketBuySwapQuoteAsync(
|
||||||
|
wethAssetData,
|
||||||
|
asset.assetData,
|
||||||
|
assetUnitAmount,
|
||||||
|
{
|
||||||
slippagePercentage,
|
slippagePercentage,
|
||||||
});
|
},
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage = assetUtils.swapQuoterErrorMessage(asset, error);
|
const errorMessage = assetUtils.swapQuoterErrorMessage(asset, error);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user