MyCrypto/common/components/AddressFieldFactory/AddressFieldFactory.tsx
William O'Beirne bdaf40a0ce Send Form Style Adjustments (#1368)
* Remove title from account, tighten buttons and subtabs.

* Send everything button in input.

* Request tx to full width, adjust transaction fee spacing.

* Fix token balances button spacing.

* Fix address identicon flying offscreen. Tighten up identicon, show border even when theres no identicon.

* Add isSelfAddress boolean to AddressField, use it on WalletInfo tab.

* Use short amount again.

* Unused
2018-03-22 13:30:51 -05:00

69 lines
1.8 KiB
TypeScript

import { Query } from 'components/renderCbs';
import { setCurrentTo, TSetCurrentTo } from 'actions/transaction';
import { AddressInputFactory } from './AddressInputFactory';
import React from 'react';
import { connect } from 'react-redux';
import { ICurrentTo } from 'selectors/transaction';
interface DispatchProps {
setCurrentTo: TSetCurrentTo;
}
interface OwnProps {
to: string | null;
isSelfAddress?: boolean;
withProps(props: CallbackProps): React.ReactElement<any> | null;
}
export interface CallbackProps {
isValid: boolean;
readOnly: boolean;
currentTo: ICurrentTo;
onChange(ev: React.FormEvent<HTMLInputElement>): void;
}
type Props = DispatchProps & OwnProps;
class AddressFieldFactoryClass extends React.Component<Props> {
public componentDidMount() {
// this 'to' parameter can be either token or actual field related
const { to } = this.props;
if (to) {
this.props.setCurrentTo(to);
}
}
public render() {
return (
<AddressInputFactory
isSelfAddress={this.props.isSelfAddress}
onChange={this.setAddress}
withProps={this.props.withProps}
/>
);
}
private setAddress = (ev: React.FormEvent<HTMLInputElement>) => {
const { value } = ev.currentTarget;
this.props.setCurrentTo(value);
};
}
const AddressFieldFactory = connect(null, { setCurrentTo })(AddressFieldFactoryClass);
interface DefaultAddressFieldProps {
isSelfAddress?: boolean;
withProps(props: CallbackProps): React.ReactElement<any> | null;
}
const DefaultAddressField: React.SFC<DefaultAddressFieldProps> = ({ isSelfAddress, withProps }) => (
<Query
params={['to']}
withQuery={({ to }) => (
<AddressFieldFactory to={to} isSelfAddress={isSelfAddress} withProps={withProps} />
)}
/>
);
export { DefaultAddressField as AddressFieldFactory };