From e3d4d47a131c09b9bc2b11bdca667cd45901b102 Mon Sep 17 00:00:00 2001 From: Codetrauma Date: Mon, 22 Jul 2024 16:12:12 -0700 Subject: [PATCH 1/7] feat: Modal to disconnect from origin --- src/entries/Popup/Popup.tsx | 89 ++++++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 2 deletions(-) diff --git a/src/entries/Popup/Popup.tsx b/src/entries/Popup/Popup.tsx index addd94a4..35ae25a4 100644 --- a/src/entries/Popup/Popup.tsx +++ b/src/entries/Popup/Popup.tsx @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react'; +import React, { useEffect, useState } from 'react'; import { Navigate, Route, Routes, useNavigate } from 'react-router'; import { useDispatch } from 'react-redux'; import { @@ -28,6 +28,12 @@ import { NotarizeApproval } from '../../pages/NotarizeApproval'; import { InstallPluginApproval } from '../../pages/InstallPluginApproval'; import { GetPluginsApproval } from '../../pages/GetPluginsApproval'; import { RunPluginApproval } from '../../pages/RunPluginApproval'; +import Modal, { + ModalHeader, + ModalContent, + ModalFooter, +} from '../../components/Modal/Modal'; +import { deleteConnection, getConnection } from '../Background/db'; const Popup = () => { const dispatch = useDispatch(); @@ -35,6 +41,8 @@ const Popup = () => { const url = useActiveTabUrl(); const navigate = useNavigate(); + const [showConnectionDetails, setShowConnectionDetails] = useState(false); + useEffect(() => { (async () => { const [tab] = await browser.tabs.query({ @@ -89,7 +97,10 @@ const Popup = () => { alt="logo" onClick={() => navigate('/')} /> -
+
setShowConnectionDetails(true)} + > {!!activeTab?.favIconUrl && ( { )}
{url?.hostname}
+ {showConnectionDetails && ( + + )}
} /> @@ -127,4 +144,72 @@ const Popup = () => { ); }; +const ConnectionDetails = (props: { + showConnectionDetails: boolean; + setShowConnectionDetails: any; +}) => { + const activeTab = useActiveTab(); + const activeTabOrigin = useActiveTabUrl(); + + const [connected, setConnected] = useState(false); + + useEffect(() => { + (async () => { + if (activeTabOrigin) { + console.log(activeTabOrigin); + const isConnected: boolean | null = await getConnection( + activeTabOrigin?.origin, + ); + isConnected ? setConnected(true) : setConnected(false); + } + })(); + }, []); + + const handleDisconnect = async () => { + await deleteConnection(activeTabOrigin?.origin as string); + setConnected(false); + }; + + return ( + props.setShowConnectionDetails(false)} + className="w-full h-[50%]" + > + +
+ {!!activeTab?.favIconUrl && ( + logo + )} + {activeTabOrigin?.host} +
+
+ +
+ {!!activeTab?.favIconUrl && ( + logo + )} + {activeTabOrigin?.host} +
+
+ +
+
+ + + +
+ ); +}; export default Popup; From 01899b35a759738ac86612e293c1eec6e227f9b4 Mon Sep 17 00:00:00 2001 From: Codetrauma Date: Mon, 22 Jul 2024 16:28:32 -0700 Subject: [PATCH 2/7] refactor: styling --- src/entries/Popup/Popup.tsx | 81 ++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/src/entries/Popup/Popup.tsx b/src/entries/Popup/Popup.tsx index 35ae25a4..dfd806b9 100644 --- a/src/entries/Popup/Popup.tsx +++ b/src/entries/Popup/Popup.tsx @@ -172,44 +172,51 @@ const ConnectionDetails = (props: { return ( props.setShowConnectionDetails(false)} - className="w-full h-[50%]" + onClose={() => props.setShowConnectionDetails(false)} + className="w-full max-w-lg mx-auto rounded-lg shadow-lg" +> + +
+ {!!activeTab?.favIconUrl && ( + logo + )} + {activeTabOrigin?.host} +
+
+ +
+ {!!activeTab?.favIconUrl && ( + logo + )} + {activeTabOrigin?.host} +
+
+ +
+
+ + - - - - - -
+ Exit + + + ); }; export default Popup; From 054ff86fdf7d0c483655f5cbe9f431cae68ca04b Mon Sep 17 00:00:00 2001 From: Codetrauma Date: Mon, 22 Jul 2024 16:33:18 -0700 Subject: [PATCH 3/7] chore: linting --- src/entries/Popup/Popup.tsx | 88 ++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/src/entries/Popup/Popup.tsx b/src/entries/Popup/Popup.tsx index dfd806b9..a72e649c 100644 --- a/src/entries/Popup/Popup.tsx +++ b/src/entries/Popup/Popup.tsx @@ -172,51 +172,51 @@ const ConnectionDetails = (props: { return ( props.setShowConnectionDetails(false)} - className="w-full max-w-lg mx-auto rounded-lg shadow-lg" -> - -
- {!!activeTab?.favIconUrl && ( - logo - )} - {activeTabOrigin?.host} -
-
- -
- {!!activeTab?.favIconUrl && ( - logo - )} - {activeTabOrigin?.host} -
-
- -
-
- - - -
+ +
+ {!!activeTab?.favIconUrl && ( + logo + )} + {activeTabOrigin?.host} +
+
+ +
+ {!!activeTab?.favIconUrl && ( + logo + )} + {activeTabOrigin?.host} +
+
+ +
+
+ + + + ); }; export default Popup; From bab41ca7a469fe59b092119bd156444dfced6bd8 Mon Sep 17 00:00:00 2001 From: Codetrauma Date: Wed, 24 Jul 2024 14:01:18 -0700 Subject: [PATCH 4/7] refactor: styling connections modal --- src/entries/Popup/Popup.tsx | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/entries/Popup/Popup.tsx b/src/entries/Popup/Popup.tsx index a72e649c..8c8ccfa8 100644 --- a/src/entries/Popup/Popup.tsx +++ b/src/entries/Popup/Popup.tsx @@ -156,7 +156,6 @@ const ConnectionDetails = (props: { useEffect(() => { (async () => { if (activeTabOrigin) { - console.log(activeTabOrigin); const isConnected: boolean | null = await getConnection( activeTabOrigin?.origin, ); @@ -173,21 +172,14 @@ const ConnectionDetails = (props: { return ( props.setShowConnectionDetails(false)} - className="w-full max-w-lg mx-auto rounded-lg shadow-lg" + className="w-full h-[40%] max-w-lg mx-auto rounded-lg shadow-lg flex flex-col" >
- {!!activeTab?.favIconUrl && ( - logo - )} - {activeTabOrigin?.host} + Connections
- +
{!!activeTab?.favIconUrl && ( {activeTabOrigin?.host}
-
+
+
+ + + + + + ); +}; + +export default ConnectionDetailsModal; diff --git a/src/entries/Popup/Popup.tsx b/src/entries/Popup/Popup.tsx index 8c8ccfa8..e80884ea 100644 --- a/src/entries/Popup/Popup.tsx +++ b/src/entries/Popup/Popup.tsx @@ -21,6 +21,7 @@ import ProofUploader from '../../pages/ProofUploader'; import browser from 'webextension-polyfill'; import store from '../../utils/store'; import PluginUploadInfo from '../../components/PluginInfo'; +import ConnectionDetailsModal from '../../components/ConnectionDetailsModal'; import { ConnectionApproval } from '../../pages/ConnectionApproval'; import { GetHistoryApproval } from '../../pages/GetHistoryApproval'; import { GetProofApproval } from '../../pages/GetProofApproval'; @@ -28,12 +29,6 @@ import { NotarizeApproval } from '../../pages/NotarizeApproval'; import { InstallPluginApproval } from '../../pages/InstallPluginApproval'; import { GetPluginsApproval } from '../../pages/GetPluginsApproval'; import { RunPluginApproval } from '../../pages/RunPluginApproval'; -import Modal, { - ModalHeader, - ModalContent, - ModalFooter, -} from '../../components/Modal/Modal'; -import { deleteConnection, getConnection } from '../Background/db'; const Popup = () => { const dispatch = useDispatch(); @@ -111,7 +106,7 @@ const Popup = () => {
{url?.hostname}
{showConnectionDetails && ( - @@ -144,71 +139,5 @@ const Popup = () => { ); }; -const ConnectionDetails = (props: { - showConnectionDetails: boolean; - setShowConnectionDetails: any; -}) => { - const activeTab = useActiveTab(); - const activeTabOrigin = useActiveTabUrl(); - - const [connected, setConnected] = useState(false); - - useEffect(() => { - (async () => { - if (activeTabOrigin) { - const isConnected: boolean | null = await getConnection( - activeTabOrigin?.origin, - ); - isConnected ? setConnected(true) : setConnected(false); - } - })(); - }, []); - - const handleDisconnect = async () => { - await deleteConnection(activeTabOrigin?.origin as string); - setConnected(false); - }; - return ( - props.setShowConnectionDetails(false)} - className="w-full h-[40%] max-w-lg mx-auto rounded-lg shadow-lg flex flex-col" - > - -
- Connections -
-
- -
- {!!activeTab?.favIconUrl && ( - logo - )} - {activeTabOrigin?.host} -
-
- -
-
- - - -
- ); -}; export default Popup; From 8775fc7f625446c12f20e1a6ae6ab9ec1fc27abc Mon Sep 17 00:00:00 2001 From: Codetrauma Date: Wed, 24 Jul 2024 20:19:48 -0700 Subject: [PATCH 6/7] chore: linting --- src/components/ConnectionDetailsModal/index.tsx | 7 +------ src/entries/Popup/Popup.tsx | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/components/ConnectionDetailsModal/index.tsx b/src/components/ConnectionDetailsModal/index.tsx index 43cf4040..5b1ccee2 100644 --- a/src/components/ConnectionDetailsModal/index.tsx +++ b/src/components/ConnectionDetailsModal/index.tsx @@ -1,8 +1,5 @@ import React, { useEffect, useState } from 'react'; -import { - useActiveTab, - useActiveTabUrl, -} from '../../reducers/requests'; +import { useActiveTab, useActiveTabUrl } from '../../reducers/requests'; import Modal, { ModalHeader, ModalContent, @@ -10,8 +7,6 @@ import Modal, { } from '../../components/Modal/Modal'; import { deleteConnection, getConnection } from '../../entries/Background/db'; - - const ConnectionDetailsModal = (props: { showConnectionDetails: boolean; setShowConnectionDetails: any; diff --git a/src/entries/Popup/Popup.tsx b/src/entries/Popup/Popup.tsx index e80884ea..2f3d08e2 100644 --- a/src/entries/Popup/Popup.tsx +++ b/src/entries/Popup/Popup.tsx @@ -139,5 +139,4 @@ const Popup = () => { ); }; - export default Popup; From d5342a19047cafbfa59489aa51d015df5563f496 Mon Sep 17 00:00:00 2001 From: tsukino <0xtsukino@gmail.com> Date: Wed, 14 Aug 2024 00:38:59 +0800 Subject: [PATCH 7/7] fix: styling update --- .../ConnectionDetailsModal/index.tsx | 52 ++++++------- src/entries/Popup/Popup.tsx | 75 ++++++++++++++----- 2 files changed, 78 insertions(+), 49 deletions(-) diff --git a/src/components/ConnectionDetailsModal/index.tsx b/src/components/ConnectionDetailsModal/index.tsx index 5b1ccee2..2580aa7a 100644 --- a/src/components/ConnectionDetailsModal/index.tsx +++ b/src/components/ConnectionDetailsModal/index.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useCallback, useEffect, useState } from 'react'; import { useActiveTab, useActiveTabUrl } from '../../reducers/requests'; import Modal, { ModalHeader, @@ -6,12 +6,13 @@ import Modal, { ModalFooter, } from '../../components/Modal/Modal'; import { deleteConnection, getConnection } from '../../entries/Background/db'; +import { urlify } from '../../utils/misc'; +import Icon from '../Icon'; const ConnectionDetailsModal = (props: { showConnectionDetails: boolean; setShowConnectionDetails: any; }) => { - const activeTab = useActiveTab(); const activeTabOrigin = useActiveTabUrl(); const [connected, setConnected] = useState(false); @@ -27,50 +28,41 @@ const ConnectionDetailsModal = (props: { })(); }, []); - const handleDisconnect = async () => { + const handleDisconnect = useCallback(async () => { await deleteConnection(activeTabOrigin?.origin as string); + props.setShowConnectionDetails(false); setConnected(false); - }; + }, [props.setShowConnectionDetails]); return ( props.setShowConnectionDetails(false)} - className="w-full h-[40%] max-w-lg mx-auto rounded-lg shadow-lg flex flex-col" + className="flex flex-col gap-2 items-center text-base cursor-default justify-center mx-4 min-h-24" > - -
- Connections -
+ props.setShowConnectionDetails(false)} + > + + {activeTabOrigin?.hostname || 'Connections'} + - -
- {!!activeTab?.favIconUrl && ( - logo - )} - {activeTabOrigin?.host} + +
+ {connected + ? 'TLSN Extension is connected to this site.' + : 'TLSN Extension is not connected to this site. To connect to this site, find and click the connect button.'}
-
+ {connected && ( -
+ )}
- - - ); }; diff --git a/src/entries/Popup/Popup.tsx b/src/entries/Popup/Popup.tsx index 2f3d08e2..cb8a425a 100644 --- a/src/entries/Popup/Popup.tsx +++ b/src/entries/Popup/Popup.tsx @@ -29,6 +29,9 @@ import { NotarizeApproval } from '../../pages/NotarizeApproval'; import { InstallPluginApproval } from '../../pages/InstallPluginApproval'; import { GetPluginsApproval } from '../../pages/GetPluginsApproval'; import { RunPluginApproval } from '../../pages/RunPluginApproval'; +import Icon from '../../components/Icon'; +import classNames from 'classnames'; +import { getConnection } from '../Background/db'; const Popup = () => { const dispatch = useDispatch(); @@ -92,25 +95,7 @@ const Popup = () => { alt="logo" onClick={() => navigate('/')} /> -
setShowConnectionDetails(true)} - > - {!!activeTab?.favIconUrl && ( - logo - )} -
{url?.hostname}
-
- {showConnectionDetails && ( - - )} +
} /> @@ -140,3 +125,55 @@ const Popup = () => { }; export default Popup; + +function AppConnectionLogo() { + const activeTab = useActiveTab(); + const url = useActiveTabUrl(); + const [showConnectionDetails, setShowConnectionDetails] = useState(false); + const [connected, setConnected] = useState(false); + + useEffect(() => { + (async () => { + if (url) { + const isConnected: boolean | null = await getConnection(url?.origin); + isConnected ? setConnected(true) : setConnected(false); + } + })(); + }, [url]); + + return ( +
setShowConnectionDetails(true)} + > +
+ {!!activeTab?.favIconUrl ? ( + logo + ) : ( + + )} +
+
+ {showConnectionDetails && ( + + )} +
+ ); +}