From 6947e181c1f1ca412ce0b77b4ee37d7cbf1b70e1 Mon Sep 17 00:00:00 2001 From: meriadec Date: Wed, 24 Jan 2018 16:40:45 +0100 Subject: [PATCH] Display address as QR code, and ability to copy to clipboard --- src/components/AccountPage.js | 56 ++++++++++++++++++++++++-- src/components/base/CopyToClipboard.js | 15 +++++++ 2 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 src/components/base/CopyToClipboard.js diff --git a/src/components/AccountPage.js b/src/components/AccountPage.js index 7b8c08fc..85b12696 100644 --- a/src/components/AccountPage.js +++ b/src/components/AccountPage.js @@ -2,6 +2,7 @@ import React, { PureComponent, Fragment } from 'react' import { connect } from 'react-redux' +import styled from 'styled-components' import type { MapStateToProps } from 'react-redux' import type { Account, AccountData } from 'types/common' @@ -12,6 +13,8 @@ import { getAccountById, getAccountData } from 'reducers/accounts' import Box, { Card } from 'components/base/Box' import Text from 'components/base/Text' +import QRCode from 'components/base/QRCode' +import CopyToClipboard from 'components/base/CopyToClipboard' type Props = { account: Account, @@ -23,6 +26,32 @@ const mapStateToProps: MapStateToProps<*, *, *> = (state, props) => ({ accountData: getAccountData(state, props.match.params.id), }) +const AddressBox = styled(Box).attrs({ + borderWidth: 1, + borderColor: 'mouse', + bg: 'cream', + p: 2, +})` + text-align: center; + word-break: break-all; + border-radius: 3px; + user-select: text; +` + +const Action = styled(Box).attrs({ + color: 'mouse', + fontSize: 0, +})` + font-weight: bold; + text-align: center; + cursor: pointer; + text-transform: uppercase; + + &:hover { + color: ${p => p.theme.colors.gray}; + } +` + class AccountPage extends PureComponent { render() { const { account, accountData } = this.props @@ -35,11 +64,32 @@ class AccountPage extends PureComponent { {accountData && ( - + {format(accountData.balance)} - - {accountData.address} + + + + + + + + {'Current address'} + {accountData.address} + + + ( + + {'Copy'} + + )} + /> + {'Print'} + {'Share'} + + diff --git a/src/components/base/CopyToClipboard.js b/src/components/base/CopyToClipboard.js new file mode 100644 index 00000000..5f965de7 --- /dev/null +++ b/src/components/base/CopyToClipboard.js @@ -0,0 +1,15 @@ +// @flow + +import { clipboard } from 'electron' + +type Props = { + data: string, + render: Function, +} + +function CopyToClipboard(props: Props) { + const { render, data } = props + return render(() => clipboard.writeText(data)) +} + +export default CopyToClipboard