-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDAppRequest.tsx
More file actions
64 lines (56 loc) · 1.98 KB
/
DAppRequest.tsx
File metadata and controls
64 lines (56 loc) · 1.98 KB
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
import { useStore } from "@/stores/store";
import { Loader } from "lucide-react";
import { observer } from "mobx-react-lite";
import { useEffect, useState } from "react";
import CircuitBackground from "../Shared/CircuitBackground/CircuitBackground";
import DAppRequestContentSelection from "./DAppRequestContentSelection/DAppRequestContentSelection";
import PhishingWarning from "./PhishingWarning/PhishingWarning";
const DAppRequest = observer(() => {
const { qrlStore, dAppRequestStore, settingsStore } = useStore();
const { qrlConnection } = qrlStore;
const { isLoading } = qrlConnection;
const { dAppRequestData, approvalProcessingStatus, onPermission } =
dAppRequestStore;
const { hasCompleted } = approvalProcessingStatus;
const { phishingDetectionEnabled } = settingsStore;
const [phishingAcknowledged, setPhishingAcknowledged] = useState(false);
const phishingResult = dAppRequestData?.phishingResult;
const isDomainPhishing =
phishingDetectionEnabled && (phishingResult?.isDomainPhishing ?? false);
const showPhishingWarning = isDomainPhishing && !phishingAcknowledged;
useEffect(() => {
if (hasCompleted) {
window.close();
}
}, [hasCompleted]);
if (isLoading) {
return (
<div className="flex justify-center pt-48">
<Loader className="animate-spin" size={86} />
</div>
);
}
const senderUrl = dAppRequestData?.requestData?.senderData?.url ?? "";
let domain = "";
try {
domain = new URL(senderUrl).hostname;
} catch {
// invalid URL
}
return (
<>
<CircuitBackground />
<div className="relative z-10 flex flex-col items-center space-y-4 p-4">
<DAppRequestContentSelection />
</div>
<PhishingWarning
isOpen={showPhishingWarning}
domain={domain}
matchedDomain={phishingResult?.matchedDomain}
onReject={() => onPermission(false)}
onProceedAnyway={() => setPhishingAcknowledged(true)}
/>
</>
);
});
export default DAppRequest;