2018-01-01 19:46:28 +00:00
|
|
|
import React from 'react';
|
|
|
|
import classnames from 'classnames';
|
2018-01-20 20:06:28 +00:00
|
|
|
import { translateRaw, TranslateType } from 'translations';
|
2018-01-01 19:46:28 +00:00
|
|
|
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;
|
2018-01-01 19:46:28 +00:00
|
|
|
isSecure?: boolean;
|
|
|
|
isReadOnly?: boolean;
|
|
|
|
isDisabled?: boolean;
|
2018-01-26 20:08:39 +00:00
|
|
|
disableReason?: string;
|
2018-01-01 19:46:28 +00:00
|
|
|
onClick(walletType: string): void;
|
|
|
|
}
|
|
|
|
|
2018-01-20 20:06:28 +00:00
|
|
|
interface StateProps {
|
|
|
|
isFormatDisabled?: boolean;
|
|
|
|
}
|
|
|
|
|
2018-01-26 20:08:39 +00:00
|
|
|
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> {
|
2018-01-01 19:46:28 +00:00
|
|
|
public render() {
|
|
|
|
const {
|
|
|
|
name,
|
|
|
|
description,
|
|
|
|
example,
|
|
|
|
icon,
|
|
|
|
helpLink,
|
|
|
|
isSecure,
|
|
|
|
isReadOnly,
|
2018-01-26 20:08:39 +00:00
|
|
|
isDisabled,
|
|
|
|
disableReason
|
2018-01-01 19:46:28 +00:00
|
|
|
} = this.props;
|
|
|
|
|
2018-01-26 20:08:39 +00:00
|
|
|
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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-01-01 19:46:28 +00:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={classnames({
|
|
|
|
WalletButton: true,
|
|
|
|
'WalletButton--small': !isSecure,
|
|
|
|
'is-disabled': isDisabled
|
|
|
|
})}
|
|
|
|
onClick={this.handleClick}
|
|
|
|
tabIndex={isDisabled ? -1 : 0}
|
|
|
|
aria-disabled={isDisabled}
|
|
|
|
>
|
2018-01-26 20:08:39 +00:00
|
|
|
<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
|
|
|
|
2018-01-26 20:08:39 +00:00
|
|
|
{description && <div className="WalletButton-description">{description}</div>}
|
|
|
|
{example && <div className="WalletButton-example">{example}</div>}
|
2018-01-20 20:06:28 +00:00
|
|
|
|
2018-01-26 20:08:39 +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>
|
2018-01-01 19:46:28 +00:00
|
|
|
</div>
|
2018-01-26 20:08:39 +00:00
|
|
|
|
|
|
|
{isDisabled && disableReason && <Tooltip>{disableReason}</Tooltip>}
|
2018-01-01 19:46:28 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private handleClick = () => {
|
2018-01-20 20:06:28 +00:00
|
|
|
if (this.props.isDisabled || this.props.isFormatDisabled) {
|
2018-01-01 19:46:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.props.onClick(this.props.walletType);
|
|
|
|
};
|
|
|
|
|
2018-01-20 20:06:28 +00:00
|
|
|
private stopPropogation = (ev: React.FormEvent<HTMLAnchorElement | HTMLSpanElement>) => {
|
2018-01-01 19:46:28 +00:00
|
|
|
ev.stopPropagation();
|
|
|
|
};
|
|
|
|
}
|