Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
const responseData = await response.json();
let { no, yes } = responseData;
yes = new BigNumber(yes);
no = new BigNumber(no);
const tally = {
...responseData,
yes: new BigNumber(yes),
no: new BigNumber(no),
};
return tally;
} catch (e) {
// Empty block
return {
yes: new BigNumber(0),
no: new BigNumber(0),
};
}
}
export function isRoundingErrorFloor(numerator: BigNumber, denominator: BigNumber, target: BigNumber): boolean {
if (denominator.eq(0)) {
throw new LibMathRevertErrors.DivisionByZeroError();
}
if (numerator.eq(0) || target.eq(0)) {
return false;
}
const remainder = numerator.times(target).mod(denominator);
// Need to do this separately because solidity evaluates RHS of the comparison expression first.
const rhs = safeMul(numerator, target);
const lhs = safeMul(remainder, new BigNumber(1000));
return lhs.gte(rhs);
}
};
const DEFAULT_FORWARDER_SWAP_QUOTE_EXECUTE_OPTS: ForwarderSwapQuoteExecutionOpts = DEFAULT_FORWARDER_SWAP_QUOTE_GET_OPTS;
const DEFAULT_SWAP_QUOTE_REQUEST_OPTS: SwapQuoteRequestOpts = {
shouldForceOrderRefresh: false,
slippagePercentage: 0.2, // 20% slippage protection,
};
const EMPTY_ORDERS_AND_FILLABLE_AMOUNTS: OrdersAndFillableAmounts = {
orders: [] as SignedOrder[],
remainingFillableMakerAssetAmounts: [] as BigNumber[],
};
export const constants = {
ZERO_AMOUNT: new BigNumber(0),
NULL_ADDRESS,
MAINNET_NETWORK_ID,
ETHER_TOKEN_DECIMALS: 18,
ONE_AMOUNT: new BigNumber(1),
ONE_SECOND_MS,
DEFAULT_SWAP_QUOTER_OPTS,
DEFAULT_FORWARDER_SWAP_QUOTE_GET_OPTS,
DEFAULT_FORWARDER_SWAP_QUOTE_EXECUTE_OPTS,
DEFAULT_SWAP_QUOTE_REQUEST_OPTS,
EMPTY_ORDERS_AND_FILLABLE_AMOUNTS,
};
import { BigNumber } from '@0x/utils';
// tslint:disable custom-no-magic-numbers
export const constants = {
NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
MAINNET_CHAIN_ID: 1,
ZERO_AMOUNT: new BigNumber(0),
TWO_WEEKS_IN_SEC: new BigNumber(14)
.times(24)
.times(60)
.times(60),
TEN_DAYS_IN_SEC: new BigNumber(10)
.times(24)
.times(60)
.times(60),
TWENTY_DAYS_IN_SEC: new BigNumber(20)
.times(24)
.times(60)
.times(60),
};
export function fromWei(amount: BigNumber | string) {
return new BigNumber(amount.toString()).div(TEN_18);
}
export function fromShares(
amount: BigNumber | string,
numTicks: string | number
) {
return new BigNumber(amount.toString())
.times(new BigNumber(numTicks))
.div(TEN_18);
}
_.forEach(balances, (balance, balanceIndex) => {
const tokenAddress = balanceInfo[balanceIndex].tokenAddress;
const tokenOwnerAddress = balanceInfo[balanceIndex].tokenOwnerAddress;
if (balancesByOwner[tokenOwnerAddress] === undefined) {
balancesByOwner[tokenOwnerAddress] = {};
}
const wrappedBalance = new BigNumber(balance);
balancesByOwner[tokenOwnerAddress][tokenAddress] = wrappedBalance;
});
return balancesByOwner;
shouldHideNextButton: true,
shouldCenterTitle: true,
shouldRemoveExtraSpacing: true,
},
{
position: nextToWalletPosition,
title: '0x Ecosystem Account Setup',
content: ,
shouldHideBackButton: true,
continueButtonDisplay: 'enabled',
},
{
position: nextToWalletPosition,
title: 'Step 1: Add ETH',
content: (
),
continueButtonDisplay: this._userHasVisibleEth() ? 'enabled' : 'disabled',
},
{
position: nextToWalletPosition,
title: 'Step 2: Wrap ETH',
content: ,
continueButtonDisplay: 'enabled',
},
{
position: nextToWalletPosition,
title: 'Step 2: Wrap ETH',
content: ,
continueButtonDisplay: this._userHasVisibleWeth() ? 'enabled' : 'disabled',
},
{
lastForceTokenStateRefetch: number;
isFullWidth?: boolean;
}
interface TokenBalancesState {
errorType: BalanceErrs;
trackedTokenStateByAddress: TokenStateByAddress;
isBalanceSpinnerVisible: boolean;
isZRXSpinnerVisible: boolean;
isTokenPickerOpen: boolean;
isAddingToken: boolean;
}
export class TokenBalances extends React.Component {
public static defaultProps: Partial = {
userEtherBalanceInWei: new BigNumber(0),
isFullWidth: false,
};
private _isUnmounted: boolean;
public constructor(props: TokenBalancesProps) {
super(props);
this._isUnmounted = false;
const initialTrackedTokenStateByAddress = this._getInitialTrackedTokenStateByAddress(props.trackedTokens);
this.state = {
errorType: undefined,
isBalanceSpinnerVisible: false,
isZRXSpinnerVisible: false,
isTokenPickerOpen: false,
isAddingToken: false,
trackedTokenStateByAddress: initialTrackedTokenStateByAddress,
};
}
);
const traderFeeProxyAllowance = await this._balanceAndProxyAllowanceFetcher.getProxyAllowanceAsync(
zrxAssetData,
traderAddress,
);
const transferrableTraderAssetAmount = BigNumber.min(traderProxyAllowance, traderBalance);
const transferrableFeeAssetAmount = BigNumber.min(traderFeeProxyAllowance, traderFeeBalance);
const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
const filledTakerAssetAmount = await this._orderFilledCancelledFetcher.getFilledTakerAmountAsync(orderHash);
const totalMakerAssetAmount = signedOrder.makerAssetAmount;
const totalTakerAssetAmount = signedOrder.takerAssetAmount;
const isOrderCancelled = await this._orderFilledCancelledFetcher.isOrderCancelledAsync(signedOrder);
const remainingTakerAssetAmount = isOrderCancelled
? new BigNumber(0)
: totalTakerAssetAmount.minus(filledTakerAssetAmount);
const remainingMakerAssetAmount = remainingTakerAssetAmount.eq(0)
? new BigNumber(0)
: remainingTakerAssetAmount.times(totalMakerAssetAmount).dividedToIntegerBy(totalTakerAssetAmount);
const remainingAssetAmount = isMakerSide ? remainingMakerAssetAmount : remainingTakerAssetAmount;
const remainingFillableCalculator = new RemainingFillableCalculator(
feeAmount,
assetAmount,
isAssetZRX,
transferrableTraderAssetAmount,
transferrableFeeAssetAmount,
remainingAssetAmount,
);
const remainingFillableAssetAmount = remainingFillableCalculator.computeRemainingFillable();