Skip to content

Commit

Permalink
Merge pull request #70 from HunnySajid/chore/update-eventtypes
Browse files Browse the repository at this point in the history
fix: remove init-req* event and replace with TAB_STATE
  • Loading branch information
rodolfomiranda committed Jan 17, 2024
2 parents 5debefb + cf9a6b1 commit 3832c67
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
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

0 comments on commit 3832c67

Please sign in to comment.