Skip to content

Commit

Permalink
Merge pull request #9 from ExchangeUnion/feat/iframe
Browse files Browse the repository at this point in the history
feat: send messages to parent when running in the Electron app
  • Loading branch information
raladev authored Nov 10, 2020
2 parents f445b03 + 01c8067 commit 1029a75
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 63 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"author": "Exchange Union",
"private": true,
"scripts": {
"start": "cross-env NODE_ENV=development react-scripts start",
"start": "cross-env NODE_ENV=development HTTPS=true react-scripts start",
"build": "cross-env NODE_ENV=production react-scripts build",
"test": "cross-env NODE_ENV=test prettier --check src/ && react-scripts test",
"eject": "react-scripts eject",
Expand All @@ -18,7 +18,6 @@
"@fortawesome/react-fontawesome": "^0.1.12",
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
"electron-log": "^4.2.4",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.2.0",
Expand Down
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
Route,
Switch,
} from "react-router-dom";
import Dashboard from "./dashboard/Dashboard";
import { Path } from "./router/Path";
import ConnectionFailed from "./common/ConnectionFailed";
import NotFound from "./common/NotFound";
import Dashboard from "./dashboard/Dashboard";
import { Path } from "./router/Path";

const darkTheme = createMuiTheme({
palette: {
Expand Down
4 changes: 2 additions & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { from, Observable } from "rxjs";
import { catchError, mergeMap } from "rxjs/operators";
import { isElectron } from "./common/appUtil";
import { isElectron, sendMessageToParent } from "./common/appUtil";
import { GetbalanceResponse } from "./models/GetbalanceResponse";
import { Info } from "./models/Info";
import { SetupStatusResponse } from "./models/SetupStatusResponse";
Expand All @@ -17,7 +17,7 @@ const xudPath = `${path}/xud`;

const logError = (url: string, err: string) => {
if (isElectron()) {
(window as any).electron.logError(`requestUrl: ${url}; error: ${err}`);
sendMessageToParent(`logError: requestUrl: ${url}; error: ${err}`);
}
};

Expand Down
9 changes: 8 additions & 1 deletion src/common/ConnectionFailed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import {
Theme,
Typography,
} from "@material-ui/core";
import React, { ReactElement } from "react";
import React, { ReactElement, useEffect } from "react";
import { useHistory } from "react-router-dom";
import { Path } from "../router/Path";
import { isElectron, sendMessageToParent } from "./appUtil";

const useStyles = makeStyles((theme: Theme) =>
createStyles({
Expand All @@ -26,6 +27,12 @@ const ConnectionFailed = (): ReactElement => {
const history = useHistory();
const classes = useStyles();

useEffect(() => {
if (isElectron()) {
sendMessageToParent("connectionFailed");
}
}, []);

return (
<Grid
item
Expand Down
6 changes: 5 additions & 1 deletion src/common/appUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ export const isElectron = (): boolean => {

export const copyToClipboard = (value: string | number): void => {
if (isElectron()) {
(window as any).electron.copyToClipboard(value);
sendMessageToParent(`copyToClipboard: ${value}`);
return;
}
navigator.clipboard.writeText(value.toString());
};

export const sendMessageToParent = (message: string): void => {
window.parent.postMessage(message, "*");
};
19 changes: 9 additions & 10 deletions src/dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ import {
useHistory,
useRouteMatch,
} from "react-router-dom";
import { isElectron } from "../common/appUtil";
import { interval } from "rxjs";
import { filter, map, mergeMap, takeUntil } from "rxjs/operators";
import api from "../api";
import { isElectron, sendMessageToParent } from "../common/appUtil";
import NotFound from "../common/NotFound";
import { SetupStatusResponse } from "../models/SetupStatusResponse";
import { Status } from "../models/Status";
import { Path } from "../router/Path";
import MenuItem, { MenuItemProps } from "./menu/MenuItem";
import Overview from "./overview/Overview";
import Tradehistory from "./tradehistory/Tradehistory";
import Wallets from "./wallet/Wallets";
import NotFound from "../common/NotFound";
import api from "../api";
import { SetupStatusResponse } from "../models/SetupStatusResponse";
import { interval } from "rxjs";
import { filter, map, mergeMap, takeUntil } from "rxjs/operators";
import { Status } from "../models/Status";

export const drawerWidth = 200;

Expand Down Expand Up @@ -54,8 +54,8 @@ const useStyles = makeStyles((theme: Theme) =>
);

const Dashboard = (): ReactElement => {
const history = useHistory();
const classes = useStyles();
const history = useHistory();
const { path } = useRouteMatch();
const [syncInProgress, setSyncInProgress] = useState(false);
const [menuItemTooltipMsg, setMenuItemTooltipMsg] = useState<string[]>([]);
Expand Down Expand Up @@ -83,8 +83,7 @@ const Dashboard = (): ReactElement => {
];

const disconnect = (): void => {
// TODO: send message to parent
history.push(Path.HOME);
sendMessageToParent("disconnect");
};

useEffect(() => {
Expand Down
77 changes: 32 additions & 45 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1266,13 +1266,6 @@
slash "^2.0.0"
strip-ansi "^5.0.0"

"@jest/create-cache-key-function@^26.5.0":
version "26.6.2"
resolved "https://registry.yarnpkg.com/@jest/create-cache-key-function/-/create-cache-key-function-26.6.2.tgz#04cf439207a4fd12418d8aee551cddc86f9ac5f5"
integrity sha512-LgEuqU1f/7WEIPYqwLPIvvHuc1sB6gMVbT6zWhin3txYUNYK/kGQrC1F2WR4gR34YlI9bBtViTm5z98RqVZAaw==
dependencies:
"@jest/types" "^26.6.2"

"@jest/environment@^24.3.0", "@jest/environment@^24.9.0":
version "24.9.0"
resolved "https://registry.yarnpkg.com/@jest/environment/-/environment-24.9.0.tgz#21e3afa2d65c0586cbd6cbefe208bafade44ab18"
Expand Down Expand Up @@ -1805,9 +1798,9 @@
"@types/react" "*"

"@types/react@*", "@types/react@^16.9.49":
version "16.9.55"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.55.tgz#47078587f5bfe028a23b6b46c7b94ac0d436acff"
integrity sha512-6KLe6lkILeRwyyy7yG9rULKJ0sXplUsl98MGoCfpteXf9sPWFWWMknDcsvubcpaTdBuxtsLF6HDUwdApZL/xIg==
version "16.9.56"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.56.tgz#ea25847b53c5bec064933095fc366b1462e2adf0"
integrity sha512-gIkl4J44G/qxbuC6r2Xh+D3CGZpJ+NdWTItAPmZbR5mUS+JQ8Zvzpl0ea5qT/ZT3ZNTUcDKUVqV3xBE8wv/DyQ==
dependencies:
"@types/prop-types" "*"
csstype "^3.0.2"
Expand Down Expand Up @@ -2877,7 +2870,7 @@ [email protected]:
node-releases "^1.1.52"
pkg-up "^3.1.0"

browserslist@^4.0.0, browserslist@^4.12.0, browserslist@^4.14.5, browserslist@^4.6.2, browserslist@^4.6.4, browserslist@^4.8.5, browserslist@^4.9.1:
browserslist@^4.0.0, browserslist@^4.12.0, browserslist@^4.14.5, browserslist@^4.14.6, browserslist@^4.6.2, browserslist@^4.6.4, browserslist@^4.9.1:
version "4.14.6"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.14.6.tgz#97702a9c212e0c6b6afefad913d3a1538e348457"
integrity sha512-zeFYcUo85ENhc/zxHbiIp0LGzzTrE2Pv2JhxvS7kpUb9Q9D38kUX6Bie7pGutJ/5iF5rOxE7CepAuWD56xJ33A==
Expand Down Expand Up @@ -3066,9 +3059,9 @@ caniuse-api@^3.0.0:
lodash.uniq "^4.5.0"

caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001035, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001154:
version "1.0.30001156"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001156.tgz#75c20937b6012fe2b02ab58b30d475bf0718de97"
integrity sha512-z7qztybA2eFZTB6Z3yvaQBIoJpQtsewRD74adw2UbRWwsRq3jIPvgrQGawBMbfafekQaD21FWuXNcywtTDGGCw==
version "1.0.30001157"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001157.tgz#2d11aaeb239b340bc1aa730eca18a37fdb07a9ab"
integrity sha512-gOerH9Wz2IRZ2ZPdMfBvyOi3cjaz4O4dgNwPGzx8EhqAs4+2IL/O+fJsbt+znSigujoZG8bVcIAUM/I/E5K3MA==

capture-exit@^2.0.0:
version "2.0.0"
Expand Down Expand Up @@ -3478,27 +3471,27 @@ copy-descriptor@^0.1.0:
integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=

core-js-compat@^3.6.2:
version "3.6.5"
resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.6.5.tgz#2a51d9a4e25dfd6e690251aa81f99e3c05481f1c"
integrity sha512-7ItTKOhOZbznhXAQ2g/slGg1PJV5zDO/WdkTwi7UEOJmkvsE32PWvx6mKtDjiMpjnR2CNf6BAD6sSxIlv7ptng==
version "3.7.0"
resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.7.0.tgz#8479c5d3d672d83f1f5ab94cf353e57113e065ed"
integrity sha512-V8yBI3+ZLDVomoWICO6kq/CD28Y4r1M7CWeO4AGpMdMfseu8bkSubBmUPySMGKRTS+su4XQ07zUkAsiu9FCWTg==
dependencies:
browserslist "^4.8.5"
browserslist "^4.14.6"
semver "7.0.0"

core-js-pure@^3.0.0:
version "3.6.5"
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.6.5.tgz#c79e75f5e38dbc85a662d91eea52b8256d53b813"
integrity sha512-lacdXOimsiD0QyNf9BC/mxivNJ/ybBGJXQFKzRekp1WTHoVUWsUHEn+2T8GJAzzIhyOuXA+gOxCVN3l+5PLPUA==
version "3.7.0"
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.7.0.tgz#28a57c861d5698e053f0ff36905f7a3301b4191e"
integrity sha512-EZD2ckZysv8MMt4J6HSvS9K2GdtlZtdBncKAmF9lr2n0c9dJUaUN88PSTjvgwCgQPWKTkERXITgS6JJRAnljtg==

core-js@^2.4.0:
version "2.6.11"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.11.tgz#38831469f9922bded8ee21c9dc46985e0399308c"
integrity sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==

core-js@^3.5.0:
version "3.6.5"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.6.5.tgz#7395dc273af37fb2e50e9bd3d9fe841285231d1a"
integrity sha512-vZVEEwZoIsI+vPEuoF9Iqf5H7/M3eeQqWlQnYa8FSKKePuYTf5MWnxb5SDAzCa60b3JBRS5g9b+Dq7b1y/RCrA==
version "3.7.0"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.7.0.tgz#b0a761a02488577afbf97179e4681bf49568520f"
integrity sha512-NwS7fI5M5B85EwpWuIwJN4i/fbisQUwLwiSNUWeXlkAZ0sbBjLEvLvFLf1uzAUV66PcEPt4xCGCmOZSxVf3xzA==

[email protected], core-util-is@~1.0.0:
version "1.0.2"
Expand Down Expand Up @@ -4233,15 +4226,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=

electron-log@^4.2.4:
version "4.3.0"
resolved "https://registry.yarnpkg.com/electron-log/-/electron-log-4.3.0.tgz#6e841a5c9af34ed3ca83e5a8a4156fdc39bed464"
integrity sha512-iuJjH/ZEJkDyCbuAMvvFxAjCMDLMXIQ5NqvppETGrbtf4b/007r5P36BSvexdy0UzwDNzDtIuEXLR34vRXWZrg==

electron-to-chromium@^1.3.378, electron-to-chromium@^1.3.585:
version "1.3.588"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.588.tgz#c6515571737bfb42678115a5eaa818384593a9a5"
integrity sha512-0zr+ZfytnLeJZxGgmEpPTcItu5Mm4A5zHPZXLfHcGp0mdsk95rmD7ePNewYtK1yIdLbk8Z1U2oTRRfOtR4gbYg==
version "1.3.591"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.591.tgz#a18892bf1acb93f7b6e4da402705d564bc235017"
integrity sha512-ol/0WzjL4NS4Kqy9VD6xXQON91xIihDT36sYCew/G/bnd1v0/4D+kahp26JauQhgFUjrdva3kRSo7URcUmQ+qw==

elliptic@^6.5.3:
version "6.5.3"
Expand Down Expand Up @@ -7619,9 +7607,9 @@ node-notifier@^5.4.2:
which "^1.3.0"

node-releases@^1.1.52, node-releases@^1.1.65:
version "1.1.65"
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.65.tgz#52d9579176bd60f23eba05c4438583f341944b81"
integrity sha512-YpzJOe2WFIW0V4ZkJQd/DGR/zdVwc/pI4Nl1CZrBO19FdRcSTmsuhdttw9rsTzzJLrNcSloLiBbEYx1C4f6gpA==
version "1.1.66"
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.66.tgz#609bd0dc069381015cd982300bae51ab4f1b1814"
integrity sha512-JHEQ1iWPGK+38VLB2H9ef2otU4l8s3yAMt9Xf934r6+ojCYDMHPMqvCc9TnzfeFSP1QEOeU6YZEd3+De0LTCgg==

normalize-package-data@^2.3.2:
version "2.5.0"
Expand Down Expand Up @@ -10733,11 +10721,10 @@ tr46@^1.0.1:
punycode "^2.1.0"

ts-jest@^26.4.0:
version "26.4.3"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-26.4.3.tgz#d153a616033e7ec8544b97ddbe2638cbe38d53db"
integrity sha512-pFDkOKFGY+nL9v5pkhm+BIFpoAuno96ff7GMnIYr/3L6slFOS365SI0fGEVYx2RKGji5M2elxhWjDMPVcOCdSw==
version "26.4.4"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-26.4.4.tgz#61f13fb21ab400853c532270e52cc0ed7e502c49"
integrity sha512-3lFWKbLxJm34QxyVNNCgXX1u4o/RV0myvA2y2Bxm46iGIjKlaY0own9gIckbjZJPn+WaJEnfPPJ20HHGpoq4yg==
dependencies:
"@jest/create-cache-key-function" "^26.5.0"
"@types/jest" "26.x"
bs-logger "0.x"
buffer-from "1.x"
Expand Down Expand Up @@ -11242,9 +11229,9 @@ whatwg-encoding@^1.0.1, whatwg-encoding@^1.0.3, whatwg-encoding@^1.0.5:
iconv-lite "0.4.24"

whatwg-fetch@^3.0.0:
version "3.4.1"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.4.1.tgz#e5f871572d6879663fa5674c8f833f15a8425ab3"
integrity sha512-sofZVzE1wKwO+EYPbWfiwzaKovWiZXf4coEzjGP9b2GBVgQRLQUZ2QcuPpQExGDAW5GItpEm6Tl4OU5mywnAoQ==
version "3.5.0"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.5.0.tgz#605a2cd0a7146e5db141e29d1c62ab84c0c4c868"
integrity sha512-jXkLtsR42xhXg7akoDKvKWE40eJeI+2KZqcp2h3NsOrRnDvtWX36KcKl30dy+hxECivdk2BVUHVNrPtoMBUx6A==

whatwg-mimetype@^2.1.0, whatwg-mimetype@^2.2.0, whatwg-mimetype@^2.3.0:
version "2.3.0"
Expand Down Expand Up @@ -11529,9 +11516,9 @@ yaml@^1.7.2:
integrity sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg==

[email protected]:
version "20.2.3"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.3.tgz#92419ba867b858c868acf8bae9bf74af0dd0ce26"
integrity sha512-emOFRT9WVHw03QSvN5qor9QQT9+sw5vwxfYweivSMHTcAXPefwVae2FjO7JJjj8hCE4CzPOPeFM83VwT29HCww==
version "20.2.4"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.4.tgz#b42890f14566796f85ae8e3a25290d205f154a54"
integrity sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==

yargs-parser@^13.1.2:
version "13.1.2"
Expand Down

0 comments on commit 1029a75

Please sign in to comment.