Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove init-req* event and replace with TAB_STATE #70

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions example-web/my-app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@ import Button from "@mui/material/Button";
import "./App.css";

function App() {

const handleRequestIdentifier = () => {
window.postMessage({ type: "init-req-identifier" }, "*");
window.postMessage({ type: "select-identifier" }, "*");
};

const handleRequestCredential = () => {
window.postMessage({ type: "init-req-credential" }, "*");
window.postMessage({ type: "select-credential" }, "*");
};

const handleSyncRequest = () => {
// TODO extension Id harcoded just for testing, need to find a way to get it dynamically
chrome.runtime.sendMessage("fklmfbmpaimbgjplbambkdjphdadbmed", {data: "test"},
function(response) {
if (!response.success)
console.log(response.data)
alert("Signed headers received\n"+ JSON.stringify(response.data.headers, null, 2));
});
chrome.runtime.sendMessage(
"fklmfbmpaimbgjplbambkdjphdadbmed",
{ data: "test" },
function (response) {
if (!response.success) console.log(response.data);
alert(
"Signed headers received\n" +
JSON.stringify(response.data.headers, null, 2)
);
}
);
};



return (
<div className="App">
<header className="App-header">
Expand Down
5 changes: 3 additions & 2 deletions src/components/signinList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState, useEffect } from "react";
import { TAB_STATE } from "@pages/popup/constants";
import { SigninCard } from "@components/signinCard";
import { Loader } from "@components/loader";
import { IMessage } from "@pages/background/types";
Expand Down Expand Up @@ -31,7 +32,7 @@ export function SigninList(): JSX.Element {
chrome.tabs.sendMessage(tabs[0].id!, {
type: "tab",
subtype: "reload-state",
eventType: "init-req-identifier",
eventType: TAB_STATE.SELECT_IDENTIFIER,
});
});
}
Expand All @@ -53,7 +54,7 @@ export function SigninList(): JSX.Element {
chrome.tabs.sendMessage(tabs[0].id!, {
type: "tab",
subtype: "reload-state",
eventType: "init-req-identifier",
eventType: TAB_STATE.SELECT_IDENTIFIER,
});
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/pages/content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ window.addEventListener(
console.log("Content script received from web page: " + event.data.type);
if (event.data.type) {
switch (event.data.type) {
case "init-req-identifier":
case "init-req-credential":
case TAB_STATE.SELECT_IDENTIFIER:
case TAB_STATE.SELECT_CREDENTIAL:
setTabState(TAB_STATE.DEFAULT);
const { data } = await chrome.runtime.sendMessage<IMessage<void>>({
type: "authentication",
Expand All @@ -45,7 +45,7 @@ window.addEventListener(
false
);

// Handle messages from background script
// Handle messages from background script and popup
chrome.runtime.onMessage.addListener(async function (
message,
sender,
Expand Down
10 changes: 3 additions & 7 deletions src/pages/dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ export default function Dialog({
const [showPopupPrompt, setShowPopupPrompt] = useState(false);

const getEventTypeAppState = () => {
return eventType === "init-req-identifier"
? TAB_STATE.SELECT_IDENTIFIER
: eventType === "init-req-credential"
? TAB_STATE.SELECT_CREDENTIAL
: TAB_STATE.DEFAULT;
return eventType ?? TAB_STATE.DEFAULT;
};

const handleClick = () => {
Expand Down Expand Up @@ -71,7 +67,7 @@ export default function Dialog({
{!signins.length || !isConnected ? (
<p className="mt-2 text-sm text-green max-w-[280px] font-bold">
<span className="">{tabUrl}</span> requests authentication with{" "}
{eventType === "init-req-identifier" ? "AID" : "credential"}
{eventType === TAB_STATE.SELECT_IDENTIFIER ? "AID" : "credential"}
</p>
) : null}

Expand All @@ -89,7 +85,7 @@ export default function Dialog({
<img src={logo} className="h-4" alt="logo" />
</span>{" "}
to select other{" "}
{eventType === "init-req-identifier" ? "AID" : "credential"}{" "}
{eventType === TAB_STATE.SELECT_IDENTIFIER ? "AID" : "credential"}{" "}
</button>
</>
) : null}
Expand Down