From f2dedc4ad25686b3a04688a0174447ca3b24b50c Mon Sep 17 00:00:00 2001 From: mmv Date: Tue, 12 Mar 2019 17:46:35 +0400 Subject: [PATCH] add click to copy feature on safe page --- src/logic/wallets/ethAddresses.js | 2 +- src/routes/safe/component/Layout.jsx | 48 ++++++++++++++-------------- src/utils/clipboard.js | 13 ++++++++ 3 files changed, 38 insertions(+), 25 deletions(-) create mode 100644 src/utils/clipboard.js diff --git a/src/logic/wallets/ethAddresses.js b/src/logic/wallets/ethAddresses.js index df1ec918..e15c71e7 100644 --- a/src/logic/wallets/ethAddresses.js +++ b/src/logic/wallets/ethAddresses.js @@ -16,4 +16,4 @@ export const shortVersionOf = (address: string, cut: number) => { const final = 42 - cut return `${address.substring(0, initial)}...${address.substring(final)}` -} +} \ No newline at end of file diff --git a/src/routes/safe/component/Layout.jsx b/src/routes/safe/component/Layout.jsx index 7945a2ab..dc908991 100644 --- a/src/routes/safe/component/Layout.jsx +++ b/src/routes/safe/component/Layout.jsx @@ -13,7 +13,10 @@ import Paragraph from '~/components/layout/Paragraph' import NoSafe from '~/components/NoSafe' import { type SelectorProps } from '~/routes/safe/container/selector' import { openAddressInEtherScan } from '~/logic/wallets/getWeb3' -import { sm, xs, secondary, smallFontSize } from '~/theme/variables' +import { + sm, xs, secondary, smallFontSize, +} from '~/theme/variables' +import { copyToClipboard } from '~/utils/clipboard' import Balances from './Balances' type Props = SelectorProps & { @@ -74,10 +77,16 @@ class Layout extends React.Component { this.setState({ value }) } + copyAddress = () => { + const { safe } = this.props + + if (safe.address) { + copyToClipboard(safe.address) + } + } + render() { - const { - safe, provider, network, classes, granted, tokens, activeTokens, - } = this.props + const { safe, provider, network, classes, granted, tokens, activeTokens } = this.props const { value } = this.state if (!safe) { @@ -92,15 +101,15 @@ class Layout extends React.Component { - {safe.get('name')} - { !granted && - - Read Only - - } + + {safe.get('name')} + + {!granted && Read Only} - {address} + + {address} + { - + - {value === 0 && - } + {value === 0 && ( + + )} ) } diff --git a/src/utils/clipboard.js b/src/utils/clipboard.js new file mode 100644 index 00000000..4f91c494 --- /dev/null +++ b/src/utils/clipboard.js @@ -0,0 +1,13 @@ +// @flow + +export const copyToClipboard = (text: string) => { + if (!navigator.clipboard) { + return + } + + try { + navigator.clipboard.writeText(text) + } catch (err) { + console.error(err.message) + } +} \ No newline at end of file