CryptoDonate: make crypto addresses copyable

datepicker-css
Alex Gleason 2021-06-09 17:39:45 -05:00
rodzic 483fadb7c2
commit fde99ff11c
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 25 dodań i 5 usunięć

Wyświetl plik

@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePureComponent from 'react-immutable-pure-component';
import QRCode from 'qrcode.react';
import { FormattedMessage } from 'react-intl';
import CoinDB from '../utils/coin_db';
import { getCoinIcon } from '../utils/coin_icons';
@ -13,6 +13,19 @@ export default class CryptoAddress extends ImmutablePureComponent {
note: PropTypes.string,
}
setInputRef = c => {
this.input = c;
}
handleCopyClick = e => {
if (!this.input) return;
this.input.select();
this.input.setSelectionRange(0, 99999);
document.execCommand('copy');
}
render() {
const { address, ticker, note } = this.props;
const title = CoinDB.getIn([ticker, 'name']);
@ -22,12 +35,14 @@ export default class CryptoAddress extends ImmutablePureComponent {
<div className='crypto-address__icon'>
<img src={getCoinIcon(ticker)} alt={title} />
</div>
<div className='crypto-address__qr-code'>
<QRCode value={address} />
</div>
<div className='crypto-address__title'>{title}</div>
<div className='crypto-address__address'>{address}</div>
{note && <div className='crypto-address__note'>{note}</div>}
<div className='crypto-address__address'>
<input ref={this.setInputRef} type='text' value={address} />
<button className='crypto-address__copy' onClick={this.handleCopyClick}>
<FormattedMessage id='crypto_donate.copy' defaultMessage='Copy' />
</button>
</div>
</div>
);
}

Wyświetl plik

@ -1,3 +1,8 @@
.crypto-address {
padding: 20px;
}
.site-wallet {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}