0xProject / 0x-launch-kit-frontend

Apache License 2.0
112 stars 207 forks source link

Affiliate Forwarder config not work for values different than zero #568

Open JoaoCampos89 opened 4 years ago

JoaoCampos89 commented 4 years ago

Set the Affiliate Fee percentage to a value different than zero results in zero value for the affiliate config:

image

image

Changing the implementation to this one below works as intended: image

But then we can not complete the market buy orders because the computation to get the eth amount required does not take in account the additional eth value needed for the fees, this implementation under src/store/relayer/actions solves the issue:

    const ethBalance = getEthBalance(state) as BigNumber;
            let ethAmountRequired = amounts.reduce((total: BigNumber, currentValue: BigNumber) => {
                return total.plus(currentValue);
            }, new BigNumber(0));

            ethAmountRequired = ethAmountRequired.plus(
                ethAmountRequired.times(new BigNumber(AFFILIATE_FEE_PERCENTAGE)),
            );

            const isEthBalanceEnough = ethBalance.isGreaterThan(ethAmountRequired);
            const isMarketBuyForwarder = isBuy && isWeth(quoteToken.symbol) && isEthBalanceEnough;

Using Asset buyer solves this issue also.