Skip to content

Commit 073dbc2

Browse files
author
user142513
committed
update wallet import from mnemonic
1 parent b2315b6 commit 073dbc2

File tree

1 file changed

+64
-78
lines changed

1 file changed

+64
-78
lines changed

src/screens/settings/restoremnemonic.js

+64-78
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,67 @@ import {
1313
Right,
1414
Icon,
1515
Form,
16+
Textarea,
1617
Text
1718
} from "native-base";
19+
import { StatusBar } from 'react-native';
1820
import styles from "./styles";
21+
import * as bip39 from '../../components/bip39';
22+
import * as phore from '../../wallet';
23+
import * as RealmDB from '../../realm/RealmSchemas';
24+
import * as hdkey from '../../components/hdkey';
25+
import * as uuid from "react-native-uuid";
1926

2027
class RestoreMnemonic extends Component {
28+
29+
state = {
30+
inputcode: '',
31+
seed: '',
32+
hdmaster: '',
33+
keypair: '',
34+
WIF: '',
35+
pubkey: '',
36+
address: '',
37+
xpub: '',
38+
xprv: ''
39+
40+
}
41+
42+
43+
importWallet = () => {
44+
RealmDB.realm.write(() => {
45+
var wid = uuid.v1()
46+
var seed = bip39.generateSeed(this.state.inputcode)
47+
var hdmaster = phore.generateHDMaster(seed)
48+
var keypair = phore.generateKeyPairFromMaster(hdmaster, 1)
49+
var WIF = phore.getWIFfromKeyPair(keypair)
50+
var recaddress = phore.getAddressFromKeyPair(keypair)
51+
var hdk = hdkey.rnHDKey(seed)
52+
var xpub = hdk.publicExtendedKey
53+
var xprv = hdk.privateExtendedKey
54+
RealmDB.realm.create('FullWallet', {
55+
wid: wid,
56+
seed: seed,
57+
WIF: WIF,
58+
recaddress: recaddress,
59+
xpub: xpub,
60+
xprv: xprv
61+
})
62+
})
63+
}
64+
2165
render() {
2266
return (
2367
<Container style={styles.container}>
2468
<Header>
69+
<StatusBar barStyle="light-content" />
2570
<Left>
2671
<Button transparent onPress={() => this.props.navigation.goBack()}>
27-
<Icon name="arrow-back" />
72+
<Icon name="arrow-back" style={{ color: 'white'}}/>
2873
</Button>
2974
</Left>
3075
<Body>
31-
<Title>Restore Mnemonic</Title>
76+
<Title style={{ color: 'white'}}>Restore Mnemonic</Title>
3277
</Body>
3378
<Right>
3479

@@ -39,84 +84,25 @@ class RestoreMnemonic extends Component {
3984

4085
<Text style={{alignSelf: 'center'}}>To restore your wallet you must enter the 24 words of your mnemonic code in the right order</Text>
4186
<Form>
42-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
43-
<Input placeholder="" />
44-
</Item>
45-
46-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
47-
<Input placeholder="" />
48-
</Item>
49-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
50-
<Input placeholder="" />
51-
</Item>
52-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
53-
<Input placeholder="" />
54-
</Item>
55-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
56-
<Input placeholder="" />
57-
</Item>
58-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
59-
<Input placeholder="" />
60-
</Item>
61-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
62-
<Input placeholder="" />
63-
</Item>
64-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
65-
<Input placeholder="" />
66-
</Item>
67-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
68-
<Input placeholder="" />
69-
</Item>
70-
71-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
72-
<Input placeholder="" />
73-
</Item>
74-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
75-
<Input placeholder="" />
76-
</Item>
77-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
78-
<Input placeholder="" />
79-
</Item>
80-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
81-
<Input placeholder="" />
82-
</Item>
83-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
84-
<Input placeholder="" />
85-
</Item>
86-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
87-
<Input placeholder="" />
88-
</Item>
89-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
90-
<Input placeholder="" />
91-
</Item>
92-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
93-
<Input placeholder="" />
94-
</Item>
95-
96-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
97-
<Input placeholder="" />
98-
</Item>
99-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
100-
<Input placeholder="" />
101-
</Item>
102-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
103-
<Input placeholder="" />
104-
</Item>
105-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
106-
<Input placeholder="" />
107-
</Item>
108-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
109-
<Input placeholder="" />
110-
</Item>
111-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
112-
<Input placeholder="" />
113-
</Item>
114-
<Item regular style={{ marginLeft: 15, margin: 15, marginTop: 15 }}>
115-
<Input placeholder="" />
116-
</Item>
87+
<Textarea rowSpan={10} bordered placeholder="Input words with space in between each"
88+
89+
Input
90+
onChangeText={ (inputcode) => this.setState({inputcode})}
91+
value={this.state.inputcode} />
92+
93+
94+
11795

11896
<Button bordered dark block style={{ margin: 15, marginTop: 15 }}
119-
onPress={() => this.props.navigation.navigate("RestoreWallet")}>
97+
onPress={() => {
98+
99+
console.log('inputcode is: ' + this.state.inputcode)
100+
101+
this.importWallet()
102+
103+
}
104+
105+
}>
120106
<Text>Confirm</Text>
121107
</Button>
122108

0 commit comments

Comments
 (0)