Skip to content

Commit

Permalink
fix: webpack config and return data when handling rpc requests (#38)
Browse files Browse the repository at this point in the history
* upgrade tlsn-js and fix webpack config

* fix: return data when handling rpc request

* fix: fetch history and requests
  • Loading branch information
0xtsukino authored Jan 9, 2024
1 parent c2b3b9d commit a9e0924
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 25 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tlsn-extension",
"version": "0.0.1",
"version": "0.0.13",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/entries/Background/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 4 additions & 3 deletions src/entries/Popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
});
Expand Down
7 changes: 4 additions & 3 deletions src/reducers/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -59,8 +60,8 @@ export const notarizeRequest = (options: RequestHistory) => async () => {
};

export const setActiveTab = (
activeTab: chrome.tabs.Tab | null,
): Action<chrome.tabs.Tab | null> => ({
activeTab: browser.Tabs.Tab | null,
): Action<browser.Tabs.Tab | null> => ({
type: ActionType['/requests/setActiveTab'],
payload: activeTab,
});
Expand All @@ -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;
Expand Down
37 changes: 21 additions & 16 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down

0 comments on commit a9e0924

Please sign in to comment.