aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/components/erc20_asset_amount_input.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/instant/src/components/erc20_asset_amount_input.tsx')
-rw-r--r--packages/instant/src/components/erc20_asset_amount_input.tsx33
1 files changed, 18 insertions, 15 deletions
diff --git a/packages/instant/src/components/erc20_asset_amount_input.tsx b/packages/instant/src/components/erc20_asset_amount_input.tsx
index b27f349c0..5e07dcf2f 100644
--- a/packages/instant/src/components/erc20_asset_amount_input.tsx
+++ b/packages/instant/src/components/erc20_asset_amount_input.tsx
@@ -2,7 +2,7 @@ import * as _ from 'lodash';
import * as React from 'react';
import { ColorOption, transparentWhite } from '../style/theme';
-import { ERC20Asset } from '../types';
+import { ERC20Asset, SimpleHandler } from '../types';
import { assetUtils } from '../util/asset';
import { BigNumberInput } from '../util/big_number_input';
import { util } from '../util/util';
@@ -41,7 +41,7 @@ export class ERC20AssetAmountInput extends React.Component<ERC20AssetAmountInput
const { asset } = this.props;
return (
<Container whiteSpace="nowrap">
- {_.isUndefined(asset) ? this._renderBackupContent() : this._renderContentForAsset(asset)}
+ {_.isUndefined(asset) ? this._renderTokenSelectionContent() : this._renderContentForAsset(asset)}
</Container>
);
}
@@ -80,11 +80,11 @@ export class ERC20AssetAmountInput extends React.Component<ERC20AssetAmountInput
</React.Fragment>
);
};
- private readonly _renderBackupContent = (): React.ReactNode => {
+ private readonly _renderTokenSelectionContent = (): React.ReactNode => {
const { numberOfAssetsAvailable } = this.props;
let text = 'Select Token';
if (_.isUndefined(numberOfAssetsAvailable)) {
- text = '...Loading';
+ text = 'Loading...';
} else if (numberOfAssetsAvailable === 0) {
text = 'Assets Unavailable';
}
@@ -104,13 +104,12 @@ export class ERC20AssetAmountInput extends React.Component<ERC20AssetAmountInput
);
};
private readonly _renderChevronIcon = (): React.ReactNode => {
- const { numberOfAssetsAvailable } = this.props;
- if (_.isUndefined(numberOfAssetsAvailable) || numberOfAssetsAvailable <= 1) {
+ if (!this._areMultipleAssetsAvailable()) {
return null;
}
return (
<Container marginLeft="5px">
- <Icon icon="chevron" width={12} onClick={this._generateSelectAssetClickHandler()} />
+ <Icon icon="chevron" width={12} onClick={this._handleSelectAssetClick} />
</Container>
);
};
@@ -122,19 +121,23 @@ export class ERC20AssetAmountInput extends React.Component<ERC20AssetAmountInput
currentFontSizePx: fontSizePx,
});
};
- private readonly _generateSelectAssetClickHandler = (): (() => void) | undefined => {
+ private readonly _generateSelectAssetClickHandler = (): SimpleHandler | undefined => {
// We don't want to allow opening the token selection panel if there are no assets.
// Since styles are inferred from the presence of a click handler, we want to return undefined
// instead of providing a noop.
- const { numberOfAssetsAvailable, onSelectAssetClick } = this.props;
- if (
- _.isUndefined(numberOfAssetsAvailable) ||
- numberOfAssetsAvailable <= 1 ||
- _.isUndefined(onSelectAssetClick)
- ) {
+ if (!this._areMultipleAssetsAvailable() || _.isUndefined(this.props.onSelectAssetClick)) {
return undefined;
}
- return () => onSelectAssetClick(this.props.asset);
+ return this._handleSelectAssetClick;
+ };
+ private readonly _areMultipleAssetsAvailable = (): boolean => {
+ const { numberOfAssetsAvailable } = this.props;
+ return !_.isUndefined(numberOfAssetsAvailable) && numberOfAssetsAvailable > 1;
+ };
+ private readonly _handleSelectAssetClick = (): void => {
+ if (this.props.onSelectAssetClick) {
+ this.props.onSelectAssetClick();
+ }
};
// For assets with symbols of different length,
// start scaling the input at different character lengths