aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/components/buy_button.tsx
diff options
context:
space:
mode:
authorBrandon Millman <brandon@0xproject.com>2018-11-03 03:43:53 +0800
committerGitHub <noreply@github.com>2018-11-03 03:43:53 +0800
commitec83a1d9e735573fe51df7a5854424c0ad4101fb (patch)
treef28def28bee9925daf8dd859b750c94c0cd83f98 /packages/instant/src/components/buy_button.tsx
parente7e9c2a2ebf32ed96e859c9c50a5c9614e372bc7 (diff)
parentb895b855cbb555736be838e2630890ab6a69d884 (diff)
downloaddexon-sol-tools-ec83a1d9e735573fe51df7a5854424c0ad4101fb.tar
dexon-sol-tools-ec83a1d9e735573fe51df7a5854424c0ad4101fb.tar.gz
dexon-sol-tools-ec83a1d9e735573fe51df7a5854424c0ad4101fb.tar.bz2
dexon-sol-tools-ec83a1d9e735573fe51df7a5854424c0ad4101fb.tar.lz
dexon-sol-tools-ec83a1d9e735573fe51df7a5854424c0ad4101fb.tar.xz
dexon-sol-tools-ec83a1d9e735573fe51df7a5854424c0ad4101fb.tar.zst
dexon-sol-tools-ec83a1d9e735573fe51df7a5854424c0ad4101fb.zip
Merge pull request #1207 from 0xProject/feature/instant/affiliate-fee
[instant][asset-buyer] Implement affiliateInfo prop
Diffstat (limited to 'packages/instant/src/components/buy_button.tsx')
-rw-r--r--packages/instant/src/components/buy_button.tsx13
1 files changed, 10 insertions, 3 deletions
diff --git a/packages/instant/src/components/buy_button.tsx b/packages/instant/src/components/buy_button.tsx
index c00b1678d..12ac62601 100644
--- a/packages/instant/src/components/buy_button.tsx
+++ b/packages/instant/src/components/buy_button.tsx
@@ -1,10 +1,11 @@
import { AssetBuyer, AssetBuyerError, BuyQuote } from '@0x/asset-buyer';
import * as _ from 'lodash';
import * as React from 'react';
+import { oc } from 'ts-optchain';
import { WEB_3_WRAPPER_TRANSACTION_FAILED_ERROR_MSG_PREFIX } from '../constants';
import { ColorOption } from '../style/theme';
-import { ZeroExInstantError } from '../types';
+import { AffiliateInfo, ZeroExInstantError } from '../types';
import { getBestAddress } from '../util/address';
import { balanceUtil } from '../util/balance';
import { gasPriceEstimator } from '../util/gas_price_estimator';
@@ -16,6 +17,7 @@ import { Button, Text } from './ui';
export interface BuyButtonProps {
buyQuote?: BuyQuote;
assetBuyer?: AssetBuyer;
+ affiliateInfo?: AffiliateInfo;
onValidationPending: (buyQuote: BuyQuote) => void;
onValidationFail: (buyQuote: BuyQuote, errorMessage: AssetBuyerError | ZeroExInstantError) => void;
onSignatureDenied: (buyQuote: BuyQuote) => void;
@@ -42,7 +44,7 @@ export class BuyButton extends React.Component<BuyButtonProps> {
}
private readonly _handleClick = async () => {
// The button is disabled when there is no buy quote anyway.
- const { buyQuote, assetBuyer } = this.props;
+ const { buyQuote, assetBuyer, affiliateInfo } = this.props;
if (_.isUndefined(buyQuote) || _.isUndefined(assetBuyer)) {
return;
}
@@ -58,8 +60,13 @@ export class BuyButton extends React.Component<BuyButtonProps> {
let txHash: string | undefined;
const gasInfo = await gasPriceEstimator.getGasInfoAsync();
+ const feeRecipient = oc(affiliateInfo).feeRecipient();
try {
- txHash = await assetBuyer.executeBuyQuoteAsync(buyQuote, { takerAddress, gasPrice: gasInfo.gasPriceInWei });
+ txHash = await assetBuyer.executeBuyQuoteAsync(buyQuote, {
+ feeRecipient,
+ takerAddress,
+ gasPrice: gasInfo.gasPriceInWei,
+ });
} catch (e) {
if (e instanceof Error) {
if (e.message === AssetBuyerError.SignatureRequestDenied) {