aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-03 06:33:00 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-03 06:33:00 +0800
commit8284f9c2ba80992609149333f8feb70fbe9b1bd1 (patch)
tree69858010cb985bec595158556952fe37d7b845c7
parent389665d3a1443abaa90ef5ec97e892c70610cac2 (diff)
downloaddexon-sol-tools-8284f9c2ba80992609149333f8feb70fbe9b1bd1.tar
dexon-sol-tools-8284f9c2ba80992609149333f8feb70fbe9b1bd1.tar.gz
dexon-sol-tools-8284f9c2ba80992609149333f8feb70fbe9b1bd1.tar.bz2
dexon-sol-tools-8284f9c2ba80992609149333f8feb70fbe9b1bd1.tar.lz
dexon-sol-tools-8284f9c2ba80992609149333f8feb70fbe9b1bd1.tar.xz
dexon-sol-tools-8284f9c2ba80992609149333f8feb70fbe9b1bd1.tar.zst
dexon-sol-tools-8284f9c2ba80992609149333f8feb70fbe9b1bd1.zip
Use generic Maybe
-rw-r--r--packages/instant/src/components/scaling_amount_input.tsx7
-rw-r--r--packages/instant/src/types.ts2
-rw-r--r--packages/instant/src/util/maybe_big_number.ts8
3 files changed, 9 insertions, 8 deletions
diff --git a/packages/instant/src/components/scaling_amount_input.tsx b/packages/instant/src/components/scaling_amount_input.tsx
index ca8ccbe31..5dc719293 100644
--- a/packages/instant/src/components/scaling_amount_input.tsx
+++ b/packages/instant/src/components/scaling_amount_input.tsx
@@ -2,8 +2,9 @@ import { BigNumber } from '@0x/utils';
import * as _ from 'lodash';
import * as React from 'react';
+import { Maybe } from '../types';
+
import { ColorOption } from '../style/theme';
-import { MaybeBigNumber } from '../types';
import { maybeBigNumberUtil } from '../util/maybe_big_number';
import { util } from '../util/util';
@@ -35,7 +36,7 @@ export class ScalingAmountInput extends React.Component<ScalingAmountInputProps,
stringValue: _.isUndefined(props.value) ? '' : props.value.toString(),
};
}
- public componentDidUpdate(prevProps: ScalingAmountInputProps): void {
+ public componentDidUpdate(): void {
const parsedStateValue = stringToMaybeBigNumber(this.state.stringValue);
const currentValue = this.props.value;
@@ -73,7 +74,7 @@ export class ScalingAmountInput extends React.Component<ScalingAmountInputProps,
});
// Trigger onAmountChange with a valid BigNumber, or undefined if the sanitizedValue is invalid or empty
- const bigNumberValue: MaybeBigNumber = _.isEmpty(sanitizedValue)
+ const bigNumberValue: Maybe<BigNumber> = _.isEmpty(sanitizedValue)
? undefined
: stringToMaybeBigNumber(sanitizedValue);
diff --git a/packages/instant/src/types.ts b/packages/instant/src/types.ts
index 739556801..c03d269f5 100644
--- a/packages/instant/src/types.ts
+++ b/packages/instant/src/types.ts
@@ -2,7 +2,7 @@ import { AssetProxyId, ObjectMap } from '@0x/types';
import { BigNumber } from '@0x/utils';
// Reusable
-export type MaybeBigNumber = BigNumber | undefined;
+export type Maybe<T> = T | undefined;
export enum AsyncProcessState {
NONE = 'None',
PENDING = 'Pending',
diff --git a/packages/instant/src/util/maybe_big_number.ts b/packages/instant/src/util/maybe_big_number.ts
index 113ba552f..9d3746e10 100644
--- a/packages/instant/src/util/maybe_big_number.ts
+++ b/packages/instant/src/util/maybe_big_number.ts
@@ -1,12 +1,12 @@
import { BigNumber } from '@0x/utils';
import * as _ from 'lodash';
-import { MaybeBigNumber } from '../types';
+import { Maybe } from '../types';
export const maybeBigNumberUtil = {
- // converts a string to a MaybeBigNumber
+ // converts a string to a Maybe<BigNumber>
// if string is a NaN, considered undefined
- stringToMaybeBigNumber: (stringValue: string): MaybeBigNumber => {
+ stringToMaybeBigNumber: (stringValue: string): Maybe<BigNumber> => {
let validBigNumber: BigNumber;
try {
validBigNumber = new BigNumber(stringValue);
@@ -16,7 +16,7 @@ export const maybeBigNumberUtil = {
return validBigNumber.isNaN() ? undefined : validBigNumber;
},
- areMaybeBigNumbersEqual: (val1: MaybeBigNumber, val2: MaybeBigNumber): boolean => {
+ areMaybeBigNumbersEqual: (val1: Maybe<BigNumber>, val2: Maybe<BigNumber>): boolean => {
if (!_.isUndefined(val1) && !_.isUndefined(val2)) {
return val1.equals(val2);
}