|
6 | 6 | * @flow |
7 | 7 | */ |
8 | 8 |
|
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'; |
18 | 12 |
|
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'; |
26 | 15 |
|
27 | | -const phrase = 'hello'; |
| 16 | +const App = () => { |
| 17 | + const [info, setInfo] = useState({}); |
28 | 18 |
|
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 | + }, []); |
32 | 32 |
|
33 | | -const App = () => { |
34 | 33 | return ( |
35 | 34 | <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> |
73 | 55 | </Fragment> |
74 | 56 | ); |
75 | 57 | }; |
|
0 commit comments