Copy button

Generic CopyableText component
CopyableText in wallet
CopyableText in shapeshift
This commit is contained in:
Graydon 2018-06-27 12:50:14 -05:00
parent b3e18933d2
commit b15c66e169
5 changed files with 85 additions and 6 deletions

View file

@ -0,0 +1,7 @@
import { connect } from 'react-redux';
import { doNotify } from 'lbry-redux';
import Address from './view';
export default connect(null, {
doNotify,
})(Address);

View file

@ -0,0 +1,55 @@
// @flow
import * as React from 'react';
import { clipboard } from 'electron';
import { FormRow } from 'component/common/form';
import Button from 'component/button';
import * as icons from 'constants/icons';
type Props = {
copyable: string,
doNotify: ({ message: string, displayType: Array<string> }) => void,
};
export default class CopyableInput extends React.PureComponent<Props> {
constructor() {
super();
this.input = null;
}
input: ?HTMLInputElement;
render() {
const { copyable, doNotify } = this.props;
return (
<FormRow verticallyCentered padded stretch>
<input
className="input-copyable form-field__input"
readOnly
value={copyable || ''}
ref={input => {
this.input = input;
}}
onFocus={() => {
if (this.input) {
this.input.select();
}
}}
/>
<Button
noPadding
button="secondary"
icon={icons.CLIPBOARD}
onClick={() => {
clipboard.writeText(copyable);
doNotify({
message: __('Text copied'),
displayType: ['snackbar'],
});
}}
/>
</FormRow>
);
}
}

View file

@ -3,7 +3,7 @@ import * as React from 'react';
import QRCode from 'component/common/qr-code'; import QRCode from 'component/common/qr-code';
import { FormRow } from 'component/common/form'; import { FormRow } from 'component/common/form';
import * as statuses from 'constants/shape_shift'; import * as statuses from 'constants/shape_shift';
import Address from 'component/address'; import CopyableText from 'component/copyableText';
import Button from 'component/button'; import Button from 'component/button';
import type { Dispatch } from 'redux/actions/shape_shift'; import type { Dispatch } from 'redux/actions/shape_shift';
import ShiftMarketInfo from './market_info'; import ShiftMarketInfo from './market_info';
@ -94,7 +94,7 @@ class ActiveShapeShift extends React.PureComponent<Props> {
{shiftDepositAddress && ( {shiftDepositAddress && (
<FormRow verticallyCentered padded> <FormRow verticallyCentered padded>
<QRCode value={shiftDepositAddress} paddingRight /> <QRCode value={shiftDepositAddress} paddingRight />
<Address address={shiftDepositAddress} showCopyButton padded /> <CopyableText copyable={shiftDepositAddress} showCopyButton padded />
</FormRow> </FormRow>
)} )}
</div> </div>
@ -145,3 +145,4 @@ class ActiveShapeShift extends React.PureComponent<Props> {
} }
export default ActiveShapeShift; export default ActiveShapeShift;

View file

@ -1,7 +1,7 @@
// @flow // @flow
import React from 'react'; import React from 'react';
import Button from 'component/button'; import Button from 'component/button';
import Address from 'component/address'; import CopyableText from 'component/copyableText';
import QRCode from 'component/common/qr-code'; import QRCode from 'component/common/qr-code';
import * as icons from 'constants/icons'; import * as icons from 'constants/icons';
@ -48,7 +48,7 @@ class WalletAddress extends React.PureComponent<Props> {
</p> </p>
<div className="card__content"> <div className="card__content">
<Address address={receiveAddress} showCopyButton /> <CopyableText copyable={receiveAddress} showCopyButton />
</div> </div>
<div className="card__actions"> <div className="card__actions">

View file

@ -2,6 +2,8 @@
import * as React from 'react'; import * as React from 'react';
import Button from 'component/button'; import Button from 'component/button';
import Page from 'component/page'; import Page from 'component/page';
import { shell } from 'electron';
import CopyableText from 'component/copyableText';
type Props = { type Props = {
daemonSettings: { daemonSettings: {
@ -37,10 +39,24 @@ class BackupPage extends React.PureComponent<Props> {
</p> </p>
<p> <p>
{__( {__(
'However, it is fairly easy to back up manually. To backup your wallet, make a copy of the folder listed below:' 'However, it is fairly easy to back up manually. To backup your wallet, click the button below to open your wallet directory, and copy the files to a safe location.'
)} )}
</p> </p>
<p className="card__success-msg">{lbryumWalletDir}</p> <div className="walletbackup__actions">
<Button
button="primary"
label={__('Open Wallet Directory')}
onClick={() => shell.showItemInFolder(lbryumWalletDir)}
/>
</div>
<p>
{__(
'Alternatively, you may navigate to this folder on your hard drive and copy the contents:'
)}
</p>
<div className="card__content">
<CopyableText copyable={lbryumWalletDir} showCopyButton />
</div>
<p> <p>
{__( {__(
'Access to these files are equivalent to having access to your credits. Keep any copies you make of your wallet in a secure place.' 'Access to these files are equivalent to having access to your credits. Keep any copies you make of your wallet in a secure place.'