aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-02 07:32:14 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-02 07:32:14 +0800
commita2e1bf0e6287e86c226b0801311f6f4498c893ed (patch)
tree5c03514c0d0afce1aba61341c079822030e0ece0 /packages
parent7c30fd4b2da83c9522f9137f4d18e6c308f2b66f (diff)
downloaddexon-sol-tools-a2e1bf0e6287e86c226b0801311f6f4498c893ed.tar
dexon-sol-tools-a2e1bf0e6287e86c226b0801311f6f4498c893ed.tar.gz
dexon-sol-tools-a2e1bf0e6287e86c226b0801311f6f4498c893ed.tar.bz2
dexon-sol-tools-a2e1bf0e6287e86c226b0801311f6f4498c893ed.tar.lz
dexon-sol-tools-a2e1bf0e6287e86c226b0801311f6f4498c893ed.tar.xz
dexon-sol-tools-a2e1bf0e6287e86c226b0801311f6f4498c893ed.tar.zst
dexon-sol-tools-a2e1bf0e6287e86c226b0801311f6f4498c893ed.zip
Getting rid of BigNumberInput in favor of BigNumber
Diffstat (limited to 'packages')
-rw-r--r--packages/instant/src/components/erc20_asset_amount_input.tsx8
-rw-r--r--packages/instant/src/components/scaling_amount_input.tsx10
-rw-r--r--packages/instant/src/components/zero_ex_instant_provider.tsx4
-rw-r--r--packages/instant/src/containers/selected_erc20_asset_amount_input.ts9
-rw-r--r--packages/instant/src/redux/actions.ts5
-rw-r--r--packages/instant/src/redux/reducer.ts3
-rw-r--r--packages/instant/src/util/big_number_input.ts34
7 files changed, 17 insertions, 56 deletions
diff --git a/packages/instant/src/components/erc20_asset_amount_input.tsx b/packages/instant/src/components/erc20_asset_amount_input.tsx
index b1fec6405..a67d7d5db 100644
--- a/packages/instant/src/components/erc20_asset_amount_input.tsx
+++ b/packages/instant/src/components/erc20_asset_amount_input.tsx
@@ -1,10 +1,10 @@
+import { BigNumber } from '@0x/utils';
import * as _ from 'lodash';
import * as React from 'react';
import { ColorOption, transparentWhite } from '../style/theme';
import { ERC20Asset } from '../types';
import { assetUtils } from '../util/asset';
-import { BigNumberInput } from '../util/big_number_input';
import { util } from '../util/util';
import { ScalingAmountInput } from './scaling_amount_input';
@@ -13,8 +13,8 @@ import { Container, Flex, Icon, Text } from './ui';
// Asset amounts only apply to ERC20 assets
export interface ERC20AssetAmountInputProps {
asset?: ERC20Asset;
- value?: BigNumberInput;
- onChange: (value?: BigNumberInput, asset?: ERC20Asset) => void;
+ value?: BigNumber;
+ onChange: (value?: BigNumber, asset?: ERC20Asset) => void;
onSelectAssetClick?: (asset?: ERC20Asset) => void;
startingFontSizePx: number;
fontColor?: ColorOption;
@@ -102,7 +102,7 @@ export class ERC20AssetAmountInput extends React.Component<ERC20AssetAmountInput
</Container>
);
};
- private readonly _handleChange = (value?: BigNumberInput): void => {
+ private readonly _handleChange = (value?: BigNumber): void => {
this.props.onChange(value, this.props.asset);
};
private readonly _handleFontSizeChange = (fontSizePx: number): void => {
diff --git a/packages/instant/src/components/scaling_amount_input.tsx b/packages/instant/src/components/scaling_amount_input.tsx
index cfbf3b7cc..4b046e8da 100644
--- a/packages/instant/src/components/scaling_amount_input.tsx
+++ b/packages/instant/src/components/scaling_amount_input.tsx
@@ -1,8 +1,8 @@
+import { BigNumber } from '@0x/utils';
import * as _ from 'lodash';
import * as React from 'react';
import { ColorOption } from '../style/theme';
-import { BigNumberInput } from '../util/big_number_input';
import { util } from '../util/util';
import { ScalingInput } from './scaling_input';
@@ -12,8 +12,8 @@ export interface ScalingAmountInputProps {
maxFontSizePx: number;
textLengthThreshold: number;
fontColor?: ColorOption;
- value?: BigNumberInput;
- onChange: (value?: BigNumberInput) => void;
+ value?: BigNumber;
+ onChange: (value?: BigNumber) => void;
onFontSizeChange: (fontSizePx: number) => void;
}
@@ -32,7 +32,7 @@ export class ScalingAmountInput extends React.Component<ScalingAmountInputProps>
onFontSizeChange={onFontSizeChange}
fontColor={fontColor}
onChange={this._handleChange}
- value={!_.isUndefined(value) ? value.toDisplayString() : ''}
+ value={!_.isUndefined(value) ? value.toString() : ''}
placeholder="0.00"
emptyInputWidthCh={3.5}
isDisabled={this.props.isDisabled}
@@ -44,7 +44,7 @@ export class ScalingAmountInput extends React.Component<ScalingAmountInputProps>
let bigNumberValue;
if (!_.isEmpty(value)) {
try {
- bigNumberValue = new BigNumberInput(value);
+ bigNumberValue = new BigNumber(value);
} catch {
// We don't want to allow values that can't be a BigNumber, so don't even call onChange.
return;
diff --git a/packages/instant/src/components/zero_ex_instant_provider.tsx b/packages/instant/src/components/zero_ex_instant_provider.tsx
index 8c1025723..9391c03f7 100644
--- a/packages/instant/src/components/zero_ex_instant_provider.tsx
+++ b/packages/instant/src/components/zero_ex_instant_provider.tsx
@@ -1,5 +1,6 @@
import { AssetBuyer } from '@0x/asset-buyer';
import { ObjectMap, SignedOrder } from '@0x/types';
+import { BigNumber } from '@0x/utils';
import * as _ from 'lodash';
import * as React from 'react';
import { Provider } from 'react-redux';
@@ -11,7 +12,6 @@ import { store, Store } from '../redux/store';
import { fonts } from '../style/fonts';
import { AssetMetaData, Network } from '../types';
import { assetUtils } from '../util/asset';
-import { BigNumberInput } from '../util/big_number_input';
import { errorFlasher } from '../util/error_flasher';
import { gasPriceEstimator } from '../util/gas_price_estimator';
import { getProvider } from '../util/provider';
@@ -64,7 +64,7 @@ export class ZeroExInstantProvider extends React.Component<ZeroExInstantProvider
selectedAsset: assetUtils.createAssetFromAssetData(props.assetData, completeAssetMetaDataMap, networkId),
selectedAssetAmount: _.isUndefined(props.defaultAssetBuyAmount)
? state.selectedAssetAmount
- : new BigNumberInput(props.defaultAssetBuyAmount),
+ : new BigNumber(props.defaultAssetBuyAmount),
assetMetaDataMap: completeAssetMetaDataMap,
};
return storeStateFromProps;
diff --git a/packages/instant/src/containers/selected_erc20_asset_amount_input.ts b/packages/instant/src/containers/selected_erc20_asset_amount_input.ts
index 217d603d2..1a5609b12 100644
--- a/packages/instant/src/containers/selected_erc20_asset_amount_input.ts
+++ b/packages/instant/src/containers/selected_erc20_asset_amount_input.ts
@@ -13,7 +13,6 @@ import { State } from '../redux/reducer';
import { ColorOption } from '../style/theme';
import { ERC20Asset, OrderProcessState } from '../types';
import { assetUtils } from '../util/asset';
-import { BigNumberInput } from '../util/big_number_input';
import { errorFlasher } from '../util/error_flasher';
export interface SelectedERC20AssetAmountInputProps {
@@ -24,19 +23,19 @@ export interface SelectedERC20AssetAmountInputProps {
interface ConnectedState {
assetBuyer?: AssetBuyer;
- value?: BigNumberInput;
+ value?: BigNumber;
asset?: ERC20Asset;
isDisabled: boolean;
}
interface ConnectedDispatch {
- updateBuyQuote: (assetBuyer?: AssetBuyer, value?: BigNumberInput, asset?: ERC20Asset) => void;
+ updateBuyQuote: (assetBuyer?: AssetBuyer, value?: BigNumber, asset?: ERC20Asset) => void;
}
interface ConnectedProps {
- value?: BigNumberInput;
+ value?: BigNumber;
asset?: ERC20Asset;
- onChange: (value?: BigNumberInput, asset?: ERC20Asset) => void;
+ onChange: (value?: BigNumber, asset?: ERC20Asset) => void;
isDisabled: boolean;
}
diff --git a/packages/instant/src/redux/actions.ts b/packages/instant/src/redux/actions.ts
index bfae68e2b..a0781db19 100644
--- a/packages/instant/src/redux/actions.ts
+++ b/packages/instant/src/redux/actions.ts
@@ -2,8 +2,6 @@ import { BuyQuote } from '@0x/asset-buyer';
import { BigNumber } from '@0x/utils';
import * as _ from 'lodash';
-import { BigNumberInput } from '../util/big_number_input';
-
import { ActionsUnion, OrderState } from '../types';
export interface PlainAction<T extends string> {
@@ -38,8 +36,7 @@ export enum ActionTypes {
export const actions = {
updateEthUsdPrice: (price?: BigNumber) => createAction(ActionTypes.UPDATE_ETH_USD_PRICE, price),
- updateSelectedAssetAmount: (amount?: BigNumberInput) =>
- createAction(ActionTypes.UPDATE_SELECTED_ASSET_AMOUNT, amount),
+ updateSelectedAssetAmount: (amount?: BigNumber) => createAction(ActionTypes.UPDATE_SELECTED_ASSET_AMOUNT, amount),
updateBuyOrderState: (orderState: OrderState) => createAction(ActionTypes.UPDATE_BUY_ORDER_STATE, orderState),
updateLatestBuyQuote: (buyQuote?: BuyQuote) => createAction(ActionTypes.UPDATE_LATEST_BUY_QUOTE, buyQuote),
updateSelectedAsset: (assetData?: string) => createAction(ActionTypes.UPDATE_SELECTED_ASSET, assetData),
diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts
index dd9403052..20f682787 100644
--- a/packages/instant/src/redux/reducer.ts
+++ b/packages/instant/src/redux/reducer.ts
@@ -15,7 +15,6 @@ import {
OrderState,
} from '../types';
import { assetUtils } from '../util/asset';
-import { BigNumberInput } from '../util/big_number_input';
import { Action, ActionTypes } from './actions';
@@ -24,7 +23,7 @@ export interface State {
assetBuyer?: AssetBuyer;
assetMetaDataMap: ObjectMap<AssetMetaData>;
selectedAsset?: Asset;
- selectedAssetAmount?: BigNumberInput;
+ selectedAssetAmount?: BigNumber;
buyOrderState: OrderState;
ethUsdPrice?: BigNumber;
latestBuyQuote?: BuyQuote;
diff --git a/packages/instant/src/util/big_number_input.ts b/packages/instant/src/util/big_number_input.ts
deleted file mode 100644
index 370d91a0a..000000000
--- a/packages/instant/src/util/big_number_input.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { BigNumber } from '@0x/utils';
-import * as _ from 'lodash';
-
-/**
- * A BigNumber extension that is more flexible about decimal strings.
- * Such as allowing:
- * new BigNumberInput('0.') => 0
- * new BigNumberInput('1.') => 1
- * new BigNumberInput('1..') => still throws
- */
-export class BigNumberInput extends BigNumber {
- private readonly _isEndingWithDecimal: boolean;
- constructor(numberOrString: string | number) {
- if (_.isString(numberOrString)) {
- const hasDecimalPeriod = _.endsWith(numberOrString, '.');
- let internalString = numberOrString;
- if (hasDecimalPeriod) {
- internalString = numberOrString.slice(0, -1);
- }
- super(internalString);
- this._isEndingWithDecimal = hasDecimalPeriod;
- } else {
- super(numberOrString);
- this._isEndingWithDecimal = false;
- }
- }
- public toDisplayString(): string {
- const internalString = super.toString();
- if (this._isEndingWithDecimal) {
- return `${internalString}.`;
- }
- return internalString;
- }
-}