feat: add 'Select Token' UI to asset amount input
This commit is contained in:
		@@ -8,13 +8,14 @@ import { BigNumberInput } from '../util/big_number_input';
 | 
				
			|||||||
import { util } from '../util/util';
 | 
					import { util } from '../util/util';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { ScalingAmountInput } from './scaling_amount_input';
 | 
					import { ScalingAmountInput } from './scaling_amount_input';
 | 
				
			||||||
import { Container, Text } from './ui';
 | 
					import { Container, Flex, Icon, Text } from './ui';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Asset amounts only apply to ERC20 assets
 | 
					// Asset amounts only apply to ERC20 assets
 | 
				
			||||||
export interface ERC20AssetAmountInputProps {
 | 
					export interface ERC20AssetAmountInputProps {
 | 
				
			||||||
    asset?: ERC20Asset;
 | 
					    asset?: ERC20Asset;
 | 
				
			||||||
    value?: BigNumberInput;
 | 
					    value?: BigNumberInput;
 | 
				
			||||||
    onChange: (value?: BigNumberInput, asset?: ERC20Asset) => void;
 | 
					    onChange: (value?: BigNumberInput, asset?: ERC20Asset) => void;
 | 
				
			||||||
 | 
					    onSymbolClick: (asset?: ERC20Asset) => void;
 | 
				
			||||||
    startingFontSizePx: number;
 | 
					    startingFontSizePx: number;
 | 
				
			||||||
    fontColor?: ColorOption;
 | 
					    fontColor?: ColorOption;
 | 
				
			||||||
    isDisabled: boolean;
 | 
					    isDisabled: boolean;
 | 
				
			||||||
@@ -27,6 +28,7 @@ export interface ERC20AssetAmountInputState {
 | 
				
			|||||||
export class ERC20AssetAmountInput extends React.Component<ERC20AssetAmountInputProps, ERC20AssetAmountInputState> {
 | 
					export class ERC20AssetAmountInput extends React.Component<ERC20AssetAmountInputProps, ERC20AssetAmountInputState> {
 | 
				
			||||||
    public static defaultProps = {
 | 
					    public static defaultProps = {
 | 
				
			||||||
        onChange: util.boundNoop,
 | 
					        onChange: util.boundNoop,
 | 
				
			||||||
 | 
					        onSymbolClick: util.boundNoop,
 | 
				
			||||||
        isDisabled: false,
 | 
					        isDisabled: false,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    constructor(props: ERC20AssetAmountInputProps) {
 | 
					    constructor(props: ERC20AssetAmountInputProps) {
 | 
				
			||||||
@@ -36,10 +38,18 @@ export class ERC20AssetAmountInput extends React.Component<ERC20AssetAmountInput
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    public render(): React.ReactNode {
 | 
					    public render(): React.ReactNode {
 | 
				
			||||||
        const { asset, onChange, ...rest } = this.props;
 | 
					        const { asset } = this.props;
 | 
				
			||||||
        const amountBorderBottom = this.props.isDisabled ? '' : `1px solid ${transparentWhite}`;
 | 
					 | 
				
			||||||
        return (
 | 
					        return (
 | 
				
			||||||
            <Container whiteSpace="nowrap">
 | 
					            <Container whiteSpace="nowrap">
 | 
				
			||||||
 | 
					                {!_.isUndefined(asset) ? this._renderContentForAsset(asset) : this._renderBackupContent()}
 | 
				
			||||||
 | 
					            </Container>
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    private readonly _renderContentForAsset = (asset: ERC20Asset): React.ReactNode => {
 | 
				
			||||||
 | 
					        const { onChange, ...rest } = this.props;
 | 
				
			||||||
 | 
					        const amountBorderBottom = this.props.isDisabled ? '' : `1px solid ${transparentWhite}`;
 | 
				
			||||||
 | 
					        return (
 | 
				
			||||||
 | 
					            <React.Fragment>
 | 
				
			||||||
                <Container borderBottom={amountBorderBottom} display="inline-block">
 | 
					                <Container borderBottom={amountBorderBottom} display="inline-block">
 | 
				
			||||||
                    <ScalingAmountInput
 | 
					                    <ScalingAmountInput
 | 
				
			||||||
                        {...rest}
 | 
					                        {...rest}
 | 
				
			||||||
@@ -49,18 +59,50 @@ export class ERC20AssetAmountInput extends React.Component<ERC20AssetAmountInput
 | 
				
			|||||||
                        onFontSizeChange={this._handleFontSizeChange}
 | 
					                        onFontSizeChange={this._handleFontSizeChange}
 | 
				
			||||||
                    />
 | 
					                    />
 | 
				
			||||||
                </Container>
 | 
					                </Container>
 | 
				
			||||||
                <Container display="inline-flex" marginLeft="10px" title={assetUtils.bestNameForAsset(asset)}>
 | 
					                <Container
 | 
				
			||||||
                    <Text
 | 
					                    cursor="pointer"
 | 
				
			||||||
                        fontSize={`${this.state.currentFontSizePx}px`}
 | 
					                    display="inline-block"
 | 
				
			||||||
                        fontColor={ColorOption.white}
 | 
					                    marginLeft="8px"
 | 
				
			||||||
                        textTransform="uppercase"
 | 
					                    title={assetUtils.bestNameForAsset(asset, undefined)}
 | 
				
			||||||
                    >
 | 
					                >
 | 
				
			||||||
                        {assetUtils.formattedSymbolForAsset(asset)}
 | 
					                    <Flex inline={true}>
 | 
				
			||||||
                    </Text>
 | 
					                        <Text
 | 
				
			||||||
 | 
					                            fontSize={`${this.state.currentFontSizePx}px`}
 | 
				
			||||||
 | 
					                            fontColor={ColorOption.white}
 | 
				
			||||||
 | 
					                            textTransform="uppercase"
 | 
				
			||||||
 | 
					                            onClick={this._handleSymbolClick}
 | 
				
			||||||
 | 
					                        >
 | 
				
			||||||
 | 
					                            {assetUtils.formattedSymbolForAsset(asset)}
 | 
				
			||||||
 | 
					                        </Text>
 | 
				
			||||||
 | 
					                        {this._renderChevronIcon()}
 | 
				
			||||||
 | 
					                    </Flex>
 | 
				
			||||||
                </Container>
 | 
					                </Container>
 | 
				
			||||||
 | 
					            </React.Fragment>
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    private readonly _renderBackupContent = (): React.ReactNode => {
 | 
				
			||||||
 | 
					        return (
 | 
				
			||||||
 | 
					            <Flex>
 | 
				
			||||||
 | 
					                <Text
 | 
				
			||||||
 | 
					                    fontSize="30px"
 | 
				
			||||||
 | 
					                    fontColor={ColorOption.white}
 | 
				
			||||||
 | 
					                    opacity={0.7}
 | 
				
			||||||
 | 
					                    fontWeight="500"
 | 
				
			||||||
 | 
					                    onClick={this._handleSymbolClick}
 | 
				
			||||||
 | 
					                >
 | 
				
			||||||
 | 
					                    Select Token
 | 
				
			||||||
 | 
					                </Text>
 | 
				
			||||||
 | 
					                {this._renderChevronIcon()}
 | 
				
			||||||
 | 
					            </Flex>
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    private readonly _renderChevronIcon = (): React.ReactNode => {
 | 
				
			||||||
 | 
					        return (
 | 
				
			||||||
 | 
					            <Container marginLeft="5px" onClick={this._handleSymbolClick}>
 | 
				
			||||||
 | 
					                <Icon icon="chevron" width={12} />
 | 
				
			||||||
            </Container>
 | 
					            </Container>
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
    }
 | 
					    };
 | 
				
			||||||
    private readonly _handleChange = (value?: BigNumberInput): void => {
 | 
					    private readonly _handleChange = (value?: BigNumberInput): void => {
 | 
				
			||||||
        this.props.onChange(value, this.props.asset);
 | 
					        this.props.onChange(value, this.props.asset);
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
@@ -69,6 +111,9 @@ export class ERC20AssetAmountInput extends React.Component<ERC20AssetAmountInput
 | 
				
			|||||||
            currentFontSizePx: fontSizePx,
 | 
					            currentFontSizePx: fontSizePx,
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					    private readonly _handleSymbolClick = () => {
 | 
				
			||||||
 | 
					        this.props.onSymbolClick(this.props.asset);
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
    // For assets with symbols of different length,
 | 
					    // For assets with symbols of different length,
 | 
				
			||||||
    // start scaling the input at different character lengths
 | 
					    // start scaling the input at different character lengths
 | 
				
			||||||
    private readonly _textLengthThresholdForAsset = (asset?: ERC20Asset): number => {
 | 
					    private readonly _textLengthThresholdForAsset = (asset?: ERC20Asset): number => {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,9 +48,6 @@ export class InstantHeading extends React.Component<InstantHeadingProps, {}> {
 | 
				
			|||||||
                <Flex direction="row" justify="space-between">
 | 
					                <Flex direction="row" justify="space-between">
 | 
				
			||||||
                    <Flex height="60px">
 | 
					                    <Flex height="60px">
 | 
				
			||||||
                        <SelectedERC20AssetAmountInput startingFontSizePx={38} />
 | 
					                        <SelectedERC20AssetAmountInput startingFontSizePx={38} />
 | 
				
			||||||
                        <Container marginLeft="5px">
 | 
					 | 
				
			||||||
                            <Icon icon="chevron" width={12} />
 | 
					 | 
				
			||||||
                        </Container>
 | 
					 | 
				
			||||||
                    </Flex>
 | 
					                    </Flex>
 | 
				
			||||||
                    <Flex direction="column" justify="space-between">
 | 
					                    <Flex direction="column" justify="space-between">
 | 
				
			||||||
                        {iconOrAmounts}
 | 
					                        {iconOrAmounts}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,6 +28,7 @@ export interface ContainerProps {
 | 
				
			|||||||
    zIndex?: number;
 | 
					    zIndex?: number;
 | 
				
			||||||
    whiteSpace?: string;
 | 
					    whiteSpace?: string;
 | 
				
			||||||
    opacity?: number;
 | 
					    opacity?: number;
 | 
				
			||||||
 | 
					    cursor?: string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const Container =
 | 
					export const Container =
 | 
				
			||||||
@@ -57,6 +58,7 @@ export const Container =
 | 
				
			|||||||
    ${props => cssRuleIfExists(props, 'z-index')}
 | 
					    ${props => cssRuleIfExists(props, 'z-index')}
 | 
				
			||||||
    ${props => cssRuleIfExists(props, 'white-space')}
 | 
					    ${props => cssRuleIfExists(props, 'white-space')}
 | 
				
			||||||
    ${props => cssRuleIfExists(props, 'opacity')}
 | 
					    ${props => cssRuleIfExists(props, 'opacity')}
 | 
				
			||||||
 | 
					    ${props => cssRuleIfExists(props, 'cursor')}
 | 
				
			||||||
    ${props => (props.hasBoxShadow ? `box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.1)` : '')};
 | 
					    ${props => (props.hasBoxShadow ? `box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.1)` : '')};
 | 
				
			||||||
    background-color: ${props => (props.backgroundColor ? props.theme[props.backgroundColor] : 'none')};
 | 
					    background-color: ${props => (props.backgroundColor ? props.theme[props.backgroundColor] : 'none')};
 | 
				
			||||||
    border-color: ${props => (props.borderColor ? props.theme[props.borderColor] : 'none')};
 | 
					    border-color: ${props => (props.borderColor ? props.theme[props.borderColor] : 'none')};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,14 +9,14 @@ export interface FlexProps {
 | 
				
			|||||||
    width?: string;
 | 
					    width?: string;
 | 
				
			||||||
    height?: string;
 | 
					    height?: string;
 | 
				
			||||||
    backgroundColor?: ColorOption;
 | 
					    backgroundColor?: ColorOption;
 | 
				
			||||||
    className?: string;
 | 
					    inline?: boolean;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const Flex =
 | 
					export const Flex =
 | 
				
			||||||
    styled.div <
 | 
					    styled.div <
 | 
				
			||||||
    FlexProps >
 | 
					    FlexProps >
 | 
				
			||||||
    `
 | 
					    `
 | 
				
			||||||
    display: flex;
 | 
					    display: ${props => (props.inline ? 'inline-flex' : 'flex')};
 | 
				
			||||||
    flex-direction: ${props => props.direction};
 | 
					    flex-direction: ${props => props.direction};
 | 
				
			||||||
    flex-wrap: ${props => props.flexWrap};
 | 
					    flex-wrap: ${props => props.flexWrap};
 | 
				
			||||||
    justify-content: ${props => props.justify};
 | 
					    justify-content: ${props => props.justify};
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user