-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateCredentialComponent.tsx
71 lines (60 loc) · 2.51 KB
/
CreateCredentialComponent.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
64
65
66
67
68
69
70
71
import React, { useEffect, useState } from 'react';
// Adjust the import path as necessary
import { createCredential } from './create-credential';
import createIdentifier from './create-identifier';
function CreateCredentialComponent() {
//did
const [identifier, setIdentifier] = useState<any>(null);
useEffect(() => {
const fetchData = async () => {
try {
const newIdentifier = await createIdentifier();
setIdentifier(newIdentifier);
} catch (error) {
console.error('Error creating identifier:', error);
}
};
fetchData();
});
// end creation did
const [you, setYou] = useState('');
const [driver, setDriver] = useState('');
const [weight, setWeight] = useState('');
const [date, setDate] = useState('');
const [credentialOutput, setCredentialOutput] = useState('');
const handleCreateCredential = async (e: React.FormEvent) => {
e.preventDefault();
try {
const verifiableCredential = await createCredential(you, driver, weight, date);
setCredentialOutput(`New credential created:\n${JSON.stringify(verifiableCredential, null, 2)}`);
} catch (error) {
const errorMessage = (error as Error).message;
console.error('Error creating credential:', errorMessage);
setCredentialOutput(`Error creating credential: ${errorMessage}`);
}
};
return (
<div>
<div>
<h1>Your DID</h1>
{identifier && (
<pre>{JSON.stringify(identifier, null, 2)}</pre>
)}
</div>
<h1>Create Credential</h1>
<form onSubmit={handleCreateCredential}>
<label htmlFor="you">Your Name:</label>
<input type="text" id="you" value={you} onChange={(e) => setYou(e.target.value)} required /><br /><br />
<label htmlFor="driver">Driver Name:</label>
<input type="text" id="driver" value={driver} onChange={(e) => setDriver(e.target.value)} required /><br /><br />
<label htmlFor="weight">Weight:</label>
<input type="text" id="weight" value={weight} onChange={(e) => setWeight(e.target.value)} required /><br /><br />
<label htmlFor="date">Date (DD-MM-YYYY):</label>
<input type="text" id="date" value={date} onChange={(e) => setDate(e.target.value)} required /><br /><br />
<button type="submit">Create Credential</button>
</form>
{credentialOutput && <pre>{credentialOutput}</pre>}
</div>
);
}
export default CreateCredentialComponent;