Remove previous <Select /> for recent addresses

This commit is contained in:
Connor Bryan 2018-07-12 16:20:26 -05:00
parent 85cd564fbb
commit 7f03ae4918
2 changed files with 42 additions and 76 deletions

View File

@ -2,32 +2,24 @@
@import 'common/sass/mixins';
.ViewOnly {
& .AddressInput {
margin-top: 15px;
&-fields {
display: flex;
flex-direction: column;
& .input-group-input {
margin-top: 1rem;
}
}
&-field {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
flex: 1;
&-recent {
text-align: left;
&-separator {
display: block;
margin: $space-sm 0;
text-align: center;
color: shade-dark(0.3);
}
.Select {
&-option {
@include ellipsis;
&:nth-of-type(2) {
margin-bottom: calc(1rem + 15px);
font-size: 1.2rem;
}
.Identicon {
display: inline-block;
margin-right: $space-sm;
& .AddressField {
width: 100%;
}
}
}

View File

@ -1,13 +1,11 @@
import React, { PureComponent } from 'react';
import { connect } from 'react-redux';
import Select, { Option } from 'react-select';
import translate, { translateRaw } from 'translations';
import { AddressOnlyWallet } from 'libs/wallet';
import { AppState } from 'features/reducers';
import { getIsValidAddressFn } from 'features/config';
import { walletSelectors } from 'features/wallet';
import { Input, Identicon } from 'components/ui';
import { Input } from 'components/ui';
import { AddressField } from 'components';
import './ViewOnly.scss';
@ -16,7 +14,6 @@ interface OwnProps {
}
interface StateProps {
recentAddresses: ReturnType<typeof walletSelectors.getRecentAddresses>;
isValidAddress: ReturnType<typeof getIsValidAddressFn>;
}
@ -34,57 +31,40 @@ class ViewOnlyDecryptClass extends PureComponent<Props, State> {
};
public render() {
const { recentAddresses, isValidAddress } = this.props;
const { isValidAddress } = this.props;
const { address, addressFromBook } = this.state;
const isValid = isValidAddress(address);
const or = <em className="ViewOnly-recent-separator">{translate('OR')}</em>;
const recentOptions = (recentAddresses.map(addr => ({
label: (
<React.Fragment>
<Identicon address={addr} />
{addr}
</React.Fragment>
),
value: addr
// I hate this assertion, but React elements definitely work as labels
})) as any) as Option[];
return (
<div className="ViewOnly">
<form className="form-group" onSubmit={this.openWalletWithAddress}>
{!!recentOptions.length && (
<div className="ViewOnly-recent">
<Select
value={address}
onChange={this.handleSelectAddress}
options={recentOptions}
placeholder={translateRaw('VIEW_ONLY_RECENT')}
<section className="ViewOnly-fields">
<section className="ViewOnly-fields-field">
<AddressField
value={addressFromBook}
showInputLabel={false}
showIdenticon={false}
placeholder={translateRaw('SELECT_FROM_ADDRESS_BOOK')}
onChangeOverride={this.handleSelectAddressFromBook}
dropdownThreshold={0}
/>
{or}
</div>
)}
<div className="ViewOnly-book">
<AddressField
value={addressFromBook}
showInputLabel={false}
showIdenticon={false}
placeholder={translateRaw('SELECT_FROM_ADDRESS_BOOK')}
onChangeOverride={this.handleSelectAddressFromBook}
dropdownThreshold={0}
/>
{or}
</div>
<Input
isValid={isValid}
className="ViewOnly-input"
value={address}
onChange={this.changeAddress}
placeholder={translateRaw('VIEW_ONLY_ENTER')}
/>
<button className="ViewOnly-submit btn btn-primary btn-block" disabled={!isValid}>
{translate('VIEW_ADDR')}
</button>
</section>
<section className="ViewOnly-fields-field">
<em>{translate('OR')}</em>
</section>
<section className="ViewOnly-fields-field">
<Input
isValid={isValid}
className="ViewOnly-input"
value={address}
onChange={this.changeAddress}
placeholder={translateRaw('VIEW_ONLY_ENTER')}
/>
<button className="ViewOnly-submit btn btn-primary btn-block" disabled={!isValid}>
{translate('VIEW_ADDR')}
</button>
</section>
</section>
</form>
</div>
);
@ -94,11 +74,6 @@ class ViewOnlyDecryptClass extends PureComponent<Props, State> {
this.setState({ address: ev.currentTarget.value });
};
private handleSelectAddress = (option: Option) => {
const address = option && option.value ? option.value.toString() : '';
this.setState({ address }, this.openWalletWithAddress);
};
private handleSelectAddressFromBook = (ev: React.FormEvent<HTMLInputElement>) => {
const { currentTarget: { value: addressFromBook } } = ev;
this.setState({ addressFromBook }, this.openWalletWithAddressBook);
@ -131,6 +106,5 @@ class ViewOnlyDecryptClass extends PureComponent<Props, State> {
}
export const ViewOnlyDecrypt = connect((state: AppState): StateProps => ({
recentAddresses: walletSelectors.getRecentAddresses(state),
isValidAddress: getIsValidAddressFn(state)
}))(ViewOnlyDecryptClass);