-
Notifications
You must be signed in to change notification settings - Fork 11.4k
/
Copy pathTransactionResult.tsx
98 lines (82 loc) · 2.61 KB
/
TransactionResult.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { useParams } from 'react-router-dom';
import mockTransactionData from '../../utils/transaction_mock.json';
import styles from './TransactionResult.module.css';
type DataType = {
id: string;
status: string;
sender: string;
created?: string[];
deleted?: string[];
mutated?: string[];
};
function instanceOfDataType(object: any): object is DataType {
return (
object !== undefined &&
['id', 'status', 'sender'].every((x) => x in object)
);
}
function TransactionResult() {
const { id: txID } = useParams();
const data = mockTransactionData.data.find(({ id }) => id === txID);
if (instanceOfDataType(data)) {
let action: string;
let objectIDs: string[];
if (data.created !== undefined) {
action = 'Create';
objectIDs = data.created;
} else if (data.deleted !== undefined) {
action = 'Delete';
objectIDs = data.deleted;
} else if (data.mutated !== undefined) {
action = 'Mutate';
objectIDs = data.mutated;
} else {
action = 'Fail';
objectIDs = ['-'];
}
const statusClass =
data.status === 'success'
? styles['status-success']
: styles['status-fail'];
let actionClass;
switch (action) {
case 'Create':
actionClass = styles['action-create'];
break;
case 'Delete':
actionClass = styles['action-delete'];
break;
case 'Fail':
actionClass = styles['status-fail'];
break;
default:
actionClass = styles['action-mutate'];
}
return (
<dl className={styles.data}>
<dt>Transaction ID</dt>
<dd>{data.id}</dd>
<dt>Status</dt>
<dd data-testid="transaction-status" className={statusClass}>
{data.status}
</dd>
<dt>Sender</dt>
<dd>{data.sender}</dd>
<dt>Did</dt>
<dd className={actionClass}>{action}</dd>
<dt>Object</dt>
{objectIDs.map((objectID, index) => (
<dd key={`object-${index}`}>{objectID}</dd>
))}
</dl>
);
}
return (
<dl className={styles.data}>
<dt>This transaction could not be found:</dt>
<dd>{txID}</dd>
</dl>
);
}
export default TransactionResult;
export { instanceOfDataType };