Skip to content

Commit 716e018

Browse files
authored
Merge pull request #2 from jacogr/master
Update
2 parents befd0cd + ecc37ba commit 716e018

File tree

6 files changed

+1139
-9003
lines changed

6 files changed

+1139
-9003
lines changed

App.js

Lines changed: 40 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,70 +6,52 @@
66
* @flow
77
*/
88

9-
import React, { Fragment } from 'react';
10-
import {
11-
SafeAreaView,
12-
StyleSheet,
13-
ScrollView,
14-
View,
15-
Text,
16-
StatusBar,
17-
} from 'react-native';
9+
import React, { useEffect, useState, Fragment } from 'react';
10+
import { StyleSheet, View, Text } from 'react-native';
11+
import { Colors } from 'react-native/Libraries/NewAppScreen';
1812

19-
import {
20-
Header,
21-
LearnMoreLinks,
22-
Colors,
23-
DebugInstructions,
24-
ReloadInstructions,
25-
} from 'react-native/Libraries/NewAppScreen';
13+
import { Keyring } from '@polkadot/keyring';
14+
import { mnemonicGenerate, cryptoWaitReady } from '@polkadot/util-crypto';
2615

27-
const phrase = 'hello';
16+
const App = () => {
17+
const [info, setInfo] = useState({});
2818

29-
//Commet out this <----------
30-
//const { bip39Generate } = require('@polkadot/wasm-crypto');
31-
//phrase = bip39Generate()
19+
useEffect(() => {
20+
cryptoWaitReady().then(() => {
21+
try {
22+
const keyring = new Keyring({ type: 'sr25519' });
23+
const phrase = mnemonicGenerate(12);
24+
const { address, type } = keyring.createFromUri(phrase);
25+
26+
setInfo({ address, phrase, type });
27+
} catch (error) {
28+
console.error(error.message)
29+
}
30+
});
31+
}, []);
3232

33-
const App = () => {
3433
return (
3534
<Fragment>
36-
<StatusBar barStyle="dark-content" />
37-
<SafeAreaView>
38-
<ScrollView
39-
contentInsetAdjustmentBehavior="automatic"
40-
style={styles.scrollView}>
41-
<Header />
42-
43-
<View style={styles.body}>
44-
<View style={styles.sectionContainer}>
45-
<Text style={styles.sectionTitle}>Step One</Text>
46-
<Text style={styles.sectionDescription}>
47-
Edit <Text style={styles.highlight}>App.js</Text> to change this
48-
screen and then come back to see your edits.
49-
</Text>
50-
</View>
51-
<View style={styles.sectionContainer}>
52-
<Text style={styles.sectionTitle}>See Your Changes---> {phrase}</Text>
53-
<Text style={styles.sectionDescription}>
54-
<ReloadInstructions />
55-
</Text>
56-
</View>
57-
<View style={styles.sectionContainer}>
58-
<Text style={styles.sectionTitle}>Debug</Text>
59-
<Text style={styles.sectionDescription}>
60-
<DebugInstructions />
61-
</Text>
62-
</View>
63-
<View style={styles.sectionContainer}>
64-
<Text style={styles.sectionTitle}>Learn More</Text>
65-
<Text style={styles.sectionDescription}>
66-
Read the docs to discover what to do next:
67-
</Text>
68-
</View>
69-
<LearnMoreLinks />
70-
</View>
71-
</ScrollView>
72-
</SafeAreaView>
35+
<View style={styles.body}>
36+
<View style={styles.sectionContainer}>
37+
<Text style={styles.sectionTitle}>phrase</Text>
38+
<Text style={styles.sectionDescription}>
39+
{info.phrase || '<unknown>'}
40+
</Text>
41+
</View>
42+
<View style={styles.sectionContainer}>
43+
<Text style={styles.sectionTitle}>address</Text>
44+
<Text style={styles.sectionDescription}>
45+
{info.address || '<unknown>'}
46+
</Text>
47+
</View>
48+
<View style={styles.sectionContainer}>
49+
<Text style={styles.sectionTitle}>type</Text>
50+
<Text style={styles.sectionDescription}>
51+
{info.type || '<unknown>'}
52+
</Text>
53+
</View>
54+
</View>
7355
</Fragment>
7456
);
7557
};

README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
1-
### Setup
1+
## RN + @polkadot/keyring
22

3-
```
4-
npm install
5-
react-native link
6-
cd ios && pod install && cd ..
7-
```
3+
Adapted from [qalqi/AwesomeProject](https://github.com/qalqi/AwesomeProject)
4+
5+
![screenshots](output.png)
6+
7+
### Setup & running
8+
9+
Assuming MacOS and yarn, initialize the project with -
810

9-
### Run metro bundler
1011
```
11-
npm start
12+
yarn
13+
react-native link
14+
cd ios && pod install && cd ..
1215
```
1316

14-
### Run in iOS simulator (Mac only in new Tab)
17+
Run the metro bundler with additional memory options since the asm.js deps are big -
1518

1619
```
17-
npm run ios
20+
NODE_OPTIONS=--max_old_space_size=8192 yarn start
1821
```
1922

20-
### To Change react native code open App.js and Press CMD+R to refresh in simulator
23+
Be aware that this takes a significant time for the first clean build. Make a coffee, drink a beer, go for a walk or play with the dog while it is building.
2124

25+
In a new tab, start the emulator, in this case running iOS -
2226

23-
### Clean metro builder (On new install)
2427
```
25-
npm run clean:perfect
28+
yarn ios
2629
```
2730

31+
If (at some point) you need to clean all the caches, i.e. your dog needs some attention and you need an excuse to walk away on the next build, you can run -
2832

29-
33+
```
34+
yarn clean:perfect
35+
```

output.png

186 KB
Loading

0 commit comments

Comments
 (0)