Commit 1a5c9202 authored by Marek Kotewicz's avatar Marek Kotewicz Committed by GitHub
Browse files

Merge pull request #39 from paritytech/backup-brain

Backup recovery phrase.
parents e8d58589 cf76787d
......@@ -58,7 +58,7 @@
"pre-git": {
"pre-commit": [],
"pre-push": [
"npm run lint -- --fix",
"npm run lint",
"npm run test"
],
"post-commit": [],
......
......@@ -16,8 +16,10 @@
'use strict'
import React, { Component } from 'react'
import { ScrollView, View, Text, TextInput, Button } from 'react-native'
import React, { Component, PropTypes } from 'react'
import {
ScrollView, View, Text, TextInput, Button, TouchableOpacity, Share
} from 'react-native'
import { connect } from 'react-redux'
import { Actions } from 'react-native-router-flux'
import debounce from 'debounce'
......@@ -29,18 +31,29 @@ import AppStyles from '../styles'
const mapDispatchToProps = (dispatch) => {
return {
addAccount: (account) => {
onAddAccount: (account) => {
dispatch(selectAccount({
seed: account.seed,
address: account.address,
name: account.name
}))
Actions.accountSetPin()
},
onBackupPhrase: (seed, address) => {
Share.share({
message: `Recovery phrase for ${address}: ${seed}`,
ttile: `Recovery phrase for ${address}`
})
}
}
}
export class AccountNew extends Component {
static propTypes = {
onBackupPhrase: PropTypes.func.isRequired,
onAddAccount: PropTypes.func.isRequired
}
constructor (props) {
super(props)
......@@ -67,9 +80,15 @@ export class AccountNew extends Component {
})
} catch (e) {
// this should never fail
console.error(e)
}
}
backupSeed = () => {
const { address, seed } = this.state
this.props.onBackupPhrase(seed, address)
}
render () {
return (
<ScrollView style={AppStyles.view}>
......@@ -87,10 +106,15 @@ export class AccountNew extends Component {
autoFocus
onChangeText={(text) => { this.setState({name: text}) }}
/>
<Text style={AppStyles.hintText}>Recovery Phrase (for backup)</Text>
<Text style={AppStyles.hintText}>Recovery Phrase</Text>
<AccountSeed seed={this.state.seed} onChangeText={
debounce((text) => { this.updateAddress(this, text) }, 100)
} />
<TouchableOpacity
onPress={this.backupSeed}
>
<Text style={AppStyles.hintTextSmall}>Make sure to back up your recovery phrase! Click this text to share it.</Text>
</TouchableOpacity>
<Text style={AppStyles.hintText}>Address</Text>
<TextInput
editable={false}
......@@ -99,7 +123,7 @@ export class AccountNew extends Component {
/>
<View style={AppStyles.buttonContainer}>
<Button
onPress={() => this.props.addAccount({
onPress={() => this.props.onAddAccount({
seed: this.state.seed,
address: this.state.address,
name: this.state.name
......
......@@ -36,6 +36,11 @@ export default StyleSheet.create({
marginBottom: 10,
marginTop: 10
},
hintTextSmall: {
fontSize: 12,
color: '#777',
marginBottom: 10
},
valueText: {
fontSize: 12,
color: 'black',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment