From a9e0924a1d60dd4ca5d48e2b5f78e278f0feda5b Mon Sep 17 00:00:00 2001 From: tsukino <87639218+0xtsukino@users.noreply.github.com> Date: Mon, 8 Jan 2024 23:05:04 -0500 Subject: [PATCH] fix: webpack config and return data when handling rpc requests (#38) * upgrade tlsn-js and fix webpack config * fix: return data when handling rpc request * fix: fetch history and requests --- package.json | 4 ++-- src/entries/Background/rpc.ts | 2 +- src/entries/Popup/Popup.tsx | 7 ++++--- src/reducers/requests.ts | 7 ++++--- webpack.config.js | 37 ++++++++++++++++++++--------------- 5 files changed, 32 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 12379a49..372f75f3 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tlsn-extension", - "version": "0.0.1", + "version": "0.0.13", "license": "MIT", "repository": { "type": "git", @@ -35,7 +35,7 @@ "redux-logger": "^3.0.6", "redux-thunk": "^2.4.2", "tailwindcss": "^3.3.3", - "tlsn-js": "^0.0.2" + "tlsn-js": "0.1.0-alpha.3-rc1" }, "devDependencies": { "@babel/core": "^7.20.12", diff --git a/src/entries/Background/rpc.ts b/src/entries/Background/rpc.ts index 808a9f25..10425925 100644 --- a/src/entries/Background/rpc.ts +++ b/src/entries/Background/rpc.ts @@ -103,7 +103,7 @@ function handleGetRequests( const cache = getCacheByTabId(request.data); const keys = cache.keys() || []; const data = keys.map((key) => cache.get(key)); - return sendResponse(data); + return data; } async function handleGetProveRequests( diff --git a/src/entries/Popup/Popup.tsx b/src/entries/Popup/Popup.tsx index a4cab809..f87a5aae 100644 --- a/src/entries/Popup/Popup.tsx +++ b/src/entries/Popup/Popup.tsx @@ -18,6 +18,7 @@ import Notarize from '../../pages/Notarize'; import ProofViewer from '../../pages/ProofViewer'; import History from '../../pages/History'; import ProofUploader from '../../pages/ProofUploader'; +import browser from 'webextension-polyfill'; const Popup = () => { const dispatch = useDispatch(); @@ -27,21 +28,21 @@ const Popup = () => { useEffect(() => { (async () => { - const [tab] = await chrome.tabs.query({ + const [tab] = await browser.tabs.query({ active: true, lastFocusedWindow: true, }); dispatch(setActiveTab(tab || null)); - const logs = await chrome.runtime.sendMessage({ + const logs = await browser.runtime.sendMessage({ type: BackgroundActiontype.get_requests, data: tab?.id, }); dispatch(setRequests(logs)); - const history = await chrome.runtime.sendMessage({ + await browser.runtime.sendMessage({ type: BackgroundActiontype.get_prove_requests, data: tab?.id, }); diff --git a/src/reducers/requests.ts b/src/reducers/requests.ts index af82c59b..862fb303 100644 --- a/src/reducers/requests.ts +++ b/src/reducers/requests.ts @@ -7,6 +7,7 @@ import { AppRootState } from './index'; import deepEqual from 'fast-deep-equal'; import { get, NOTARY_API_LS_KEY, PROXY_API_LS_KEY } from '../utils/storage'; import { BackgroundActiontype } from '../entries/Background/rpc'; +import browser from 'webextension-polyfill'; enum ActionType { '/requests/setRequests' = '/requests/setRequests', @@ -59,8 +60,8 @@ export const notarizeRequest = (options: RequestHistory) => async () => { }; export const setActiveTab = ( - activeTab: chrome.tabs.Tab | null, -): Action => ({ + activeTab: browser.Tabs.Tab | null, +): Action => ({ type: ActionType['/requests/setActiveTab'], payload: activeTab, }); @@ -79,7 +80,7 @@ export default function requests( return { ...state, map: { - ...(action.payload || []).reduce( + ...(action?.payload || []).reduce( (acc: { [requestId: string]: RequestLog }, req: RequestLog) => { if (req) { acc[req.requestId] = req; diff --git a/webpack.config.js b/webpack.config.js index 3708b44b..79234245 100755 --- a/webpack.config.js +++ b/webpack.config.js @@ -193,23 +193,28 @@ var options = { }), new CopyWebpackPlugin({ patterns: [ + // { + // from: "node_modules/tlsn-js/build/7.js", + // to: path.join(__dirname, "build"), + // force: true, + // }, + // { + // from: "node_modules/tlsn-js/build/250.js", + // to: path.join(__dirname, "build"), + // force: true, + // }, + // { + // from: "node_modules/tlsn-js/build/278.js", + // to: path.join(__dirname, "build"), + // force: true, + // }, + // { + // from: "node_modules/tlsn-js/build/349.js", + // to: path.join(__dirname, "build"), + // force: true, + // }, { - from: "node_modules/tlsn-js/build/7.js", - to: path.join(__dirname, "build"), - force: true, - }, - { - from: "node_modules/tlsn-js/build/278.js", - to: path.join(__dirname, "build"), - force: true, - }, - { - from: "node_modules/tlsn-js/build/349.js", - to: path.join(__dirname, "build"), - force: true, - }, - { - from: "node_modules/tlsn-js/build/*.wasm", + from: "node_modules/tlsn-js/build", to: path.join(__dirname, "build"), force: true, },