Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/copy to clipboard #740

Merged
merged 5 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions wallet-web/components/CopyToClipboard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { useState } from 'react'
import { Button } from '@material-ui/core'
import { Check } from '@material-ui/icons'
import { green } from '@material-ui/core/colors'

const copy = (text: string): Promise<{ success: boolean; value: string }> => {
return new Promise((resolve, reject) => {
navigator.clipboard
.writeText(text)
.then(() => resolve({ success: true, value: text }))
.catch((e) => reject({ success: false, value: 'Failed to copy: ' + e }))
})
}

export const CopyToClipboard = ({ text }) => {
const [copied, setCopied] = useState(false)

const handleCopy = async () => {
setCopied(false)
const res = await copy(text)

if (res.success) {
setCopied(true)
} else {
console.log(res.value)
}
}

return (
<Button
size="small"
variant="outlined"
aria-label="save"
onClick={handleCopy}
endIcon={copied && <Check style={{ color: green[500] }} />}
>
{copied ? 'Copied' : 'Copy'}
</Button>
)
}
7 changes: 0 additions & 7 deletions wallet-web/next.config.js

This file was deleted.

29 changes: 17 additions & 12 deletions wallet-web/pages/receive.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { useMediaQuery } from '@material-ui/core'
import {
Card,
CardContent,
CardHeader,
Grid,
Typography,
} from '@material-ui/core'
import { Card, CardContent, Grid, Typography } from '@material-ui/core'
import React from 'react'
import { useContext } from 'react'
import { Layout, NymCard } from '../components'
import { CopyToClipboard } from '../components/CopyToClipboard'
import MainNav from '../components/MainNav'
import NoClientError from '../components/NoClientError'
import { ValidatorClientContext } from '../contexts/ValidatorClient'
Expand All @@ -34,12 +29,22 @@ const Receive = () => {
<Grid item>
<Card>
<CardContent>
<Typography
variant={matches ? 'h5' : 'subtitle1'}
style={{ wordBreak: 'break-word' }}
<div
style={{
display: 'flex',
justifyContent: 'space-between',
flexWrap: 'wrap',
}}
>
{client?.address}
</Typography>
<Typography
variant={matches ? 'h5' : 'subtitle1'}
style={{ wordBreak: 'break-word' }}
>
{client?.address}
</Typography>

<CopyToClipboard text={client?.address} />
</div>
</CardContent>
</Card>
</Grid>
Expand Down