Skip to content

Commit

Permalink
Merge pull request #59 from rodolfomiranda/msg-to-web
Browse files Browse the repository at this point in the history
Alert on web
  • Loading branch information
rodolfomiranda committed Jan 12, 2024
2 parents 16c6ea2 + 9cc1934 commit 3879cb4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions example-web/my-app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ function App() {
window.postMessage({ type: "init-req-credential" }, "*");
};



return (
<div className="App">
<header className="App-header">
Expand Down
17 changes: 17 additions & 0 deletions example-web/my-app/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ import './index.css';
import App from './App';

const root = ReactDOM.createRoot(document.getElementById('root'));

window.addEventListener(
"message",
(event) => {
// Accept messages only from same window
if (event.source !== window) {
return;
}
if (event.data.type && event.data.type === "signify-signature") {

alert("Signed headers received\n"+ JSON.stringify(event.data.data.headers, null, 2));
}
},
false
);


root.render(
<React.StrictMode>
<App />
Expand Down
2 changes: 2 additions & 0 deletions src/pages/content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ window.addEventListener(
"init-req-identifier"
);
break;
default:
break;
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/pages/dialog/signin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ export const SigninItem = ({ signin }: { signin: any }): JSX.Element => {
signin: signin,
},
});
alert("Signed headers received\n"+ JSON.stringify(headers.data.headers, null, 2));
const element = document.getElementById("__root");
if (element) element.remove();
// Communicate headers to web page
window.postMessage({ type: "signify-signature", data: headers.data }, "*");
};

return (
Expand Down

0 comments on commit 3879cb4

Please sign in to comment.