-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
63 lines (54 loc) · 1.61 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import React, {useEffect, useState} from 'react';
import {SafeAreaView, ScrollView, View, Text, Button} from 'react-native';
// Import agent from setup
import {agent} from './src/veramo';
interface Identifier {
did: string;
}
const App = () => {
const [identifiers, setIdentifiers] = useState<Identifier[]>([]);
// Add the new identifier to state
const createIdentifier = async () => {
try {
const _id = await agent.didManagerCreate();
setIdentifiers(s => s.concat([_id]));
} catch (error) {
console.log(error);
}
};
// Check for existing identifers on load and set them to state
useEffect(() => {
const getIdentifiers = async () => {
const _ids = await agent.didManagerFind();
setIdentifiers(_ids);
// Inspect the id object in your debug tool
console.log('_ids:', _ids);
};
getIdentifiers();
}, []);
return (
<SafeAreaView>
<ScrollView>
<View style={{padding: 20}}>
<Text style={{fontSize: 30, fontWeight: 'bold'}}>Identifiers</Text>
<View style={{marginBottom: 50, marginTop: 20}}>
{identifiers && identifiers.length > 0 ? (
identifiers.map((id: Identifier) => (
<View key={id.did}>
<Text>{id.did}</Text>
</View>
))
) : (
<Text>No identifiers created yet</Text>
)}
</View>
<Button
onPress={() => createIdentifier()}
title={'Create Identifier'}
/>
</View>
</ScrollView>
</SafeAreaView>
);
};
export default App;