MyCrypto/common/components/WalletDecrypt/components/WalletButton.tsx

129 lines
3.2 KiB
TypeScript
Raw Normal View History

import React from 'react';
import classnames from 'classnames';
2018-01-20 20:06:28 +00:00
import { translateRaw, TranslateType } from 'translations';
import { NewTabLink, Tooltip } from 'components/ui';
import './WalletButton.scss';
2018-01-20 20:06:28 +00:00
import { WalletName } from 'config';
interface OwnProps {
name: TranslateType;
description?: TranslateType;
example?: TranslateType;
icon?: string;
helpLink: string;
walletType: WalletName;
isSecure?: boolean;
isReadOnly?: boolean;
isDisabled?: boolean;
disableReason?: string;
onClick(walletType: string): void;
}
2018-01-20 20:06:28 +00:00
interface StateProps {
isFormatDisabled?: boolean;
}
interface Icon {
icon: string;
tooltip: string;
href?: string;
}
2018-01-20 20:06:28 +00:00
type Props = OwnProps & StateProps;
export class WalletButton extends React.PureComponent<Props> {
public render() {
const {
name,
description,
example,
icon,
helpLink,
isSecure,
isReadOnly,
isDisabled,
disableReason
} = this.props;
const icons: Icon[] = [];
if (isReadOnly) {
icons.push({
icon: 'eye',
tooltip: translateRaw('You cannot send using address only')
});
} else {
if (isSecure) {
icons.push({
icon: 'shield',
tooltip: translateRaw('This wallet type is secure')
});
} else {
icons.push({
icon: 'exclamation-triangle',
tooltip: translateRaw('This wallet type is insecure')
});
}
}
if (helpLink) {
icons.push({
icon: 'question-circle',
tooltip: translateRaw('NAV_Help'),
href: helpLink
});
}
return (
<div
className={classnames({
WalletButton: true,
'WalletButton--small': !isSecure,
'is-disabled': isDisabled
})}
onClick={this.handleClick}
tabIndex={isDisabled ? -1 : 0}
aria-disabled={isDisabled}
>
<div className="WalletButton-inner">
<div className="WalletButton-title">
{icon && <img className="WalletButton-title-icon" src={icon} />}
<span>{name}</span>
</div>
2018-01-20 20:06:28 +00:00
{description && <div className="WalletButton-description">{description}</div>}
{example && <div className="WalletButton-example">{example}</div>}
2018-01-20 20:06:28 +00:00
<div className="WalletButton-icons">
{icons.map(i => (
<span className="WalletButton-icons-icon" key={i.icon} onClick={this.stopPropogation}>
{i.href ? (
<NewTabLink href={i.href} onClick={this.stopPropogation}>
<i className={`fa fa-${i.icon}`} />
</NewTabLink>
) : (
<i className={`fa fa-${i.icon}`} />
)}
{!isDisabled && <Tooltip size="sm">{i.tooltip}</Tooltip>}
</span>
))}
</div>
</div>
{isDisabled && disableReason && <Tooltip>{disableReason}</Tooltip>}
</div>
);
}
private handleClick = () => {
2018-01-20 20:06:28 +00:00
if (this.props.isDisabled || this.props.isFormatDisabled) {
return;
}
this.props.onClick(this.props.walletType);
};
2018-01-20 20:06:28 +00:00
private stopPropogation = (ev: React.FormEvent<HTMLAnchorElement | HTMLSpanElement>) => {
ev.stopPropagation();
};
}