aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-05-18 01:54:32 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-05-18 04:04:39 +0800
commit5bc83fceaa3c281e45af0f30ace67643554830c8 (patch)
treebfdf27f448b4b0368c2a2945f47303eaa4a57289 /packages/website/ts
parente7fd501200f37581fa0b97854fc0914246d3e95c (diff)
downloaddexon-sol-tools-5bc83fceaa3c281e45af0f30ace67643554830c8.tar.gz
dexon-sol-tools-5bc83fceaa3c281e45af0f30ace67643554830c8.tar.zst
dexon-sol-tools-5bc83fceaa3c281e45af0f30ace67643554830c8.zip
Refactor code in response to CR feedback
Diffstat (limited to 'packages/website/ts')
-rw-r--r--packages/website/ts/components/inputs/balance_bounded_input.tsx15
-rw-r--r--packages/website/ts/components/inputs/token_amount_input.tsx4
-rw-r--r--packages/website/ts/components/wallet/wrap_ether_item.tsx2
-rw-r--r--packages/website/ts/types.ts3
-rw-r--r--packages/website/ts/utils/utils.ts3
5 files changed, 12 insertions, 15 deletions
diff --git a/packages/website/ts/components/inputs/balance_bounded_input.tsx b/packages/website/ts/components/inputs/balance_bounded_input.tsx
index 9a6ff64a7..b90232e05 100644
--- a/packages/website/ts/components/inputs/balance_bounded_input.tsx
+++ b/packages/website/ts/components/inputs/balance_bounded_input.tsx
@@ -5,7 +5,7 @@ import TextField from 'material-ui/TextField';
import * as React from 'react';
import { Link } from 'react-router-dom';
import { RequiredLabel } from 'ts/components/ui/required_label';
-import { InputErrMsg, ValidatedBigNumberCallback, WebsitePaths } from 'ts/types';
+import { ValidatedBigNumberCallback, WebsitePaths } from 'ts/types';
import { utils } from 'ts/utils/utils';
interface BalanceBoundedInputProps {
@@ -17,7 +17,7 @@ interface BalanceBoundedInputProps {
onErrorMsgChange?: (errorMsg: React.ReactNode) => void;
shouldShowIncompleteErrs?: boolean;
shouldCheckBalance: boolean;
- validate?: (amount: BigNumber) => InputErrMsg;
+ validate?: (amount: BigNumber) => React.ReactNode;
onVisitBalancesPageClick?: () => void;
shouldHideVisitBalancesLink?: boolean;
isDisabled?: boolean;
@@ -26,7 +26,7 @@ interface BalanceBoundedInputProps {
}
interface BalanceBoundedInputState {
- errMsg: InputErrMsg;
+ errMsg: React.ReactNode;
amountString: string;
}
@@ -37,7 +37,7 @@ export class BalanceBoundedInput extends React.Component<BalanceBoundedInputProp
isDisabled: false,
shouldShowErrs: true,
hintText: 'amount',
- onErrorMsgChange: utils.noop,
+ onErrorMsgChange: _.noop,
shouldShowUnderline: true,
};
constructor(props: BalanceBoundedInputProps) {
@@ -106,7 +106,8 @@ export class BalanceBoundedInput extends React.Component<BalanceBoundedInputProp
this.props.balance,
() => {
const isValid = _.isUndefined(this._validate(amountString, this.props.balance));
- if (utils.isNumeric(amountString) && !_.includes(amountString, '-')) {
+ const isPositiveNumber = utils.isNumeric(amountString) && !_.includes(amountString, '-');
+ if (isPositiveNumber) {
this.props.onChange(isValid, new BigNumber(amountString));
} else {
this.props.onChange(isValid);
@@ -114,7 +115,7 @@ export class BalanceBoundedInput extends React.Component<BalanceBoundedInputProp
},
);
}
- private _validate(amountString: string, balance: BigNumber): InputErrMsg {
+ private _validate(amountString: string, balance: BigNumber): React.ReactNode {
if (!utils.isNumeric(amountString)) {
return amountString !== '' ? 'Must be a number' : '';
}
@@ -155,7 +156,7 @@ export class BalanceBoundedInput extends React.Component<BalanceBoundedInputProp
}
}
- private _setAmountState(amount: string, balance: BigNumber, callback: () => void = utils.noop): void {
+ private _setAmountState(amount: string, balance: BigNumber, callback: () => void = _.noop): void {
const errorMsg = this._validate(amount, balance);
this.props.onErrorMsgChange(errorMsg);
this.setState({
diff --git a/packages/website/ts/components/inputs/token_amount_input.tsx b/packages/website/ts/components/inputs/token_amount_input.tsx
index 3ff2c5440..a5fd86f6c 100644
--- a/packages/website/ts/components/inputs/token_amount_input.tsx
+++ b/packages/website/ts/components/inputs/token_amount_input.tsx
@@ -6,7 +6,7 @@ import * as React from 'react';
import { Link } from 'react-router-dom';
import { Blockchain } from 'ts/blockchain';
import { BalanceBoundedInput } from 'ts/components/inputs/balance_bounded_input';
-import { InputErrMsg, Token, ValidatedBigNumberCallback, WebsitePaths } from 'ts/types';
+import { Token, ValidatedBigNumberCallback, WebsitePaths } from 'ts/types';
interface TokenAmountInputProps {
userAddress: string;
@@ -107,7 +107,7 @@ export class TokenAmountInput extends React.Component<TokenAmountInputProps, Tok
}
this.props.onChange(isValid, baseUnitAmount);
}
- private _validate(amount: BigNumber): InputErrMsg {
+ private _validate(amount: BigNumber): React.ReactNode {
if (this.props.shouldCheckAllowance && amount.gt(this.state.allowance)) {
return (
<span>
diff --git a/packages/website/ts/components/wallet/wrap_ether_item.tsx b/packages/website/ts/components/wallet/wrap_ether_item.tsx
index c8ced8d08..0dff22feb 100644
--- a/packages/website/ts/components/wallet/wrap_ether_item.tsx
+++ b/packages/website/ts/components/wallet/wrap_ether_item.tsx
@@ -56,7 +56,7 @@ const styles: Styles = {
errorMsg: {
fontSize: 12,
marginTop: 4,
- color: 'red',
+ color: colors.red,
minHeight: 20,
},
};
diff --git a/packages/website/ts/types.ts b/packages/website/ts/types.ts
index e3901fd81..33e4d6c30 100644
--- a/packages/website/ts/types.ts
+++ b/packages/website/ts/types.ts
@@ -207,8 +207,7 @@ export interface ContractEvent {
args: any;
}
-export type InputErrMsg = React.ReactNode | string | undefined;
-export type ValidatedBigNumberCallback = (isValid: boolean, amount?: BigNumber, errorMessage?: React.ReactNode) => void;
+export type ValidatedBigNumberCallback = (isValid: boolean, amount?: BigNumber) => void;
export enum ScreenWidths {
Sm = 'SM',
Md = 'MD',
diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts
index 5a0ab934d..3c99bd2fe 100644
--- a/packages/website/ts/utils/utils.ts
+++ b/packages/website/ts/utils/utils.ts
@@ -27,9 +27,6 @@ const MD_MIN_EM = 52;
const isDogfood = (): boolean => _.includes(window.location.href, configs.DOMAIN_DOGFOOD);
export const utils = {
- noop(): void {
- return undefined;
- },
assert(condition: boolean, message: string): void {
if (!condition) {
throw new Error(message);