-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from SimpleHold/mobile-backup-qrcode
Mobile backup qrcode
- Loading branch information
Showing
47 changed files
with
708 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ extension | |
*-error.log | ||
.env | ||
.idea/ | ||
extension.zip | ||
*.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import * as React from 'react' | ||
import { useHistory } from 'react-router-dom' | ||
|
||
// Components | ||
import Cover from '@components/Cover' | ||
import Header from '@components/Header' | ||
import QRCode from '@components/QRCode' | ||
import Button from '@components/Button' | ||
|
||
// Utils | ||
import { sha512hash } from '@utils/crypto' | ||
import { getItem } from '@utils/storage' | ||
import socket from '@utils/socket' | ||
|
||
// Styles | ||
import Styles from './styles' | ||
|
||
const ScanBackup: React.FC = () => { | ||
const history = useHistory() | ||
|
||
const [backupHash, setBackupHash] = React.useState<string>('') | ||
|
||
React.useEffect(() => { | ||
const getBackup = getItem('backup') | ||
|
||
if (getBackup) { | ||
setBackupHash(sha512hash(getBackup)) | ||
} | ||
}, []) | ||
|
||
React.useEffect(() => { | ||
socket.auth = { username: backupHash } | ||
|
||
socket.connect() | ||
|
||
socket.on('share-backup', ({ content, from }) => { | ||
if (content === backupHash) { | ||
socket.emit('share-backup', { | ||
content: getItem('backup'), | ||
to: from, | ||
}) | ||
} | ||
}) | ||
|
||
return () => { | ||
socket.disconnect() | ||
} | ||
}, [backupHash]) | ||
|
||
return ( | ||
<Styles.Wrapper> | ||
<Cover /> | ||
<Header withBack onBack={history.goBack} backTitle="Settings" /> | ||
<Styles.Container> | ||
<Styles.Row> | ||
{backupHash.length ? ( | ||
<Styles.QrCodeRow> | ||
<QRCode value={backupHash} size={200} /> | ||
</Styles.QrCodeRow> | ||
) : null} | ||
<Styles.Text>Scan the QR code to restore your mobile SimpleHold wallet</Styles.Text> | ||
</Styles.Row> | ||
<Button label="Close" onClick={history.goBack} /> | ||
</Styles.Container> | ||
</Styles.Wrapper> | ||
) | ||
} | ||
|
||
export default ScanBackup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ScanBackup from './ScanBackup' | ||
|
||
export default ScanBackup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import styled from 'styled-components' | ||
|
||
const Wrapper = styled.div` | ||
height: 600px; | ||
overflow: hidden; | ||
` | ||
|
||
const Container = styled.div` | ||
background-color: #f2f4f8; | ||
border-radius: 16px 16px 0px 0px; | ||
height: 540px; | ||
overflow: hidden; | ||
padding: 68px 30px 30px 30px; | ||
display: flex; | ||
flex-direction: column; | ||
` | ||
|
||
const Row = styled.div` | ||
flex: 1; | ||
` | ||
|
||
const QrCodeRow = styled.div` | ||
padding: 12px; | ||
background-color: #ffffff; | ||
border-radius: 16px; | ||
margin: 0 auto; | ||
width: fit-content; | ||
` | ||
|
||
const Text = styled.p` | ||
margin: 28px 18px 0 18px; | ||
font-size: 16px; | ||
line-height: 23px; | ||
text-align: center; | ||
color: #7d7e8d; | ||
` | ||
|
||
const Styles = { | ||
Wrapper, | ||
Container, | ||
Row, | ||
QrCodeRow, | ||
Text, | ||
} | ||
|
||
export default Styles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.