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

feat: added iframe with eventListener for coming messages #96

Merged
merged 2 commits into from
Jun 6, 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
41 changes: 41 additions & 0 deletions localstorage-sync.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!doctype html>
<html>
<head>
<title>Deriv</title>
<meta charset="utf-8" />
<meta name="referrer" content="origin" />
<script>
window.addEventListener('message', function (message) {
var allowed_origins = [
'https://deriv.app',
'https://staging.deriv.app',
'https://app.deriv.com',
'https://app.deriv.me',
'https://app.deriv.be',
'https://staging-app.deriv.com',
'https://staging-app.deriv.me',
'https://staging-app.deriv.be',
'https://test-app.deriv.com',
];

if (allowed_origins.includes(message.origin)) {
switch (message.data.key) {
case 'active_loginid': {
if (localStorage.getItem(message.data.key) !== message.data.value) {
localStorage.setItem(message.data.key, message.data.value);
farrah-deriv marked this conversation as resolved.
Show resolved Hide resolved
farrah-deriv marked this conversation as resolved.
Show resolved Hide resolved
}
break;
}
case 'client.accounts': {
if (localStorage.getItem(message.data.key) !== message.data.value) {
localStorage.setItem(message.data.key, message.data.value);
}
break;
}
}
}
});
</script>
</head>
<body></body>
</html>
3 changes: 2 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BrowserRouter } from 'react-router-dom';
import { QueryParamProvider } from 'use-query-params';
import { ReactRouter5Adapter } from 'use-query-params/adapters/react-router-5';
import { AppFooter, AppHeader } from '@/components';
import { AppFooter, AppHeader, DerivIframe } from '@/components';
import { initializeI18n, TranslationProvider } from '@deriv-com/translations';
import { useDevice } from '@deriv-com/ui';
import AppContent from './routes/AppContent';
Expand All @@ -18,6 +18,7 @@ const App = () => {
<BrowserRouter>
<QueryParamProvider adapter={ReactRouter5Adapter}>
<TranslationProvider defaultLang='EN' i18nInstance={i18nInstance}>
<DerivIframe />
<AppHeader />
<AppContent />
{isDesktop && <AppFooter />}
Expand Down
10 changes: 10 additions & 0 deletions src/components/DerivIframe/DerivIframe.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const DerivIframe = () => (
<iframe
id='localstorage-sync'
sandbox='allow-scripts'
src='../../../../localstorage-sync.html'
style={{ display: 'none', visibility: 'hidden' }}
/>
);

export default DerivIframe;
1 change: 1 addition & 0 deletions src/components/DerivIframe/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as DerivIframe } from './DerivIframe';
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from './Badge';
export * from './BuySellForm';
export * from './Checklist';
export * from './Clipboard';
export * from './DerivIframe';
export * from './FileDropzone';
export * from './FloatingRate';
export * from './FormProgress';
Expand Down
Loading