Skip to content

Commit 6050c94

Browse files
committed
Allow download of passphrase
1 parent 288892e commit 6050c94

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

wallets/client/components/passphrase.js

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React from 'react'
1+
import React, { useCallback } from 'react'
2+
import Button from 'react-bootstrap/Button'
23
import { CopyButton } from '@/components/form'
34
import styles from '@/styles/wallet.module.css'
45

@@ -7,7 +8,7 @@ export function Passphrase ({ passphrase }) {
78
return (
89
<>
910
<p className='fw-bold line-height-md'>
10-
Make sure to copy your passphrase now.
11+
Make sure to save your passphrase now.
1112
</p>
1213
<p className='fw-bold line-height-md'>
1314
This is the only time we will show it to you.
@@ -23,9 +24,49 @@ export function Passphrase ({ passphrase }) {
2324
</div>
2425
))}
2526
</div>
26-
<div className='d-flex justify-content-end mt-3'>
27+
<div className='d-flex justify-content-center mt-3 gap-2 align-items-center'>
2728
<CopyButton className='rounded' value={passphrase} variant='primary' />
29+
<span className='text-muted'>or</span>
30+
<DownloadButton passphrase={passphrase} />
2831
</div>
2932
</>
3033
)
3134
}
35+
36+
export default function DownloadButton ({ passphrase }) {
37+
const onClick = useCallback(() => {
38+
const filename = 'stacker-news-passphrase.txt'
39+
const value = `STACKER NEWS PASSPHRASE
40+
-----------------------
41+
42+
Your passphrase to unlock your wallets on any device is:
43+
44+
${passphrase}
45+
46+
Please keep this passphrase safe and do not share it with anyone.
47+
`
48+
download(filename, value)
49+
}, [passphrase])
50+
51+
return (
52+
<Button
53+
className='rounded'
54+
variant='primary'
55+
onClick={onClick}
56+
>
57+
download
58+
</Button>
59+
)
60+
}
61+
62+
function download (filename, value) {
63+
const blob = new Blob([value], { type: 'text/plain' })
64+
const url = URL.createObjectURL(blob)
65+
const a = document.createElement('a')
66+
a.href = url
67+
a.download = filename
68+
document.body.appendChild(a)
69+
a.click()
70+
document.body.removeChild(a)
71+
URL.revokeObjectURL(url)
72+
}

0 commit comments

Comments
 (0)