diff --git a/package.json b/package.json index f53701a..88201cd 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "scripts": { "start": "parcel watch --no-hmr src/manifest.json", "build": "parcel build src/manifest.json", + "build-release": "rm -rf dist .parcel-cache && parcel build --no-source-maps src/manifest.json", "release": "cross-env NODE_ENV=production rollup -c" }, "dependencies": { @@ -21,6 +22,8 @@ }, "devDependencies": { "@parcel/config-webextension": "^2.8.3", + "@parcel/optimizer-data-url": "2.8.3", + "@parcel/transformer-inline-string": "2.8.3", "@types/node": "^18.11.18", "@types/webextension-polyfill": "^0.10.0", "buffer": "^5.5.0", diff --git a/src/inject.ts b/src/inject.ts index fb393b9..68275dd 100644 --- a/src/inject.ts +++ b/src/inject.ts @@ -29,11 +29,13 @@ window.addEventListener('message', (message: MessageEvent) => { } }) +let authRedirectUrl: string | undefined = void 0 async function checkAndCall(method: string, params: T): Promise { const linked = await RelayOneClient.isLinked(); if (!linked) { - await send("onboard", {}) + showSignupPopup(authRedirectUrl || window.location.toString()) + return new Promise(() => { }); } const result = await send(method, params); if (result.error) { @@ -50,6 +52,7 @@ async function unLinkedCall(method: string, params: T): Promise { return result; } + const RelayOneClient = { p2p: true, extension: true, @@ -57,7 +60,7 @@ const RelayOneClient = { if (typeof url !== "string") { return false; } - // RELAY_STATE.authRedirect = url; + authRedirectUrl = url; return true; }, @@ -159,3 +162,121 @@ const RelayOneClient = { console.log("INJECTED"); (window as any)['relayone'] = RelayOneClient + +const image = require('data-url:./logo-header.png') +const POPUP = ` +
+ +
+ + ✕ + +
+
+
+ Please sign in with RelayX to enable spending +
+ + Sign in + +
+
+
+` + +function showSignupPopup(redirectUrl: string) { + const popup = document.createElement('div') + popup.setAttribute('style', ` + display: flex; + justify-content: center; + align-items: center; + + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color = rgb(0, 0, 0, 0.2); + z-index = 99999; + `) + popup.innerHTML = POPUP; + const a = popup.querySelector('a')! + a.addEventListener('click', () => { + window.location = `https://relayx.com/wallet/auth#${redirectUrl}` + }) + const close = popup.querySelector('.relay-one-close')! + close.addEventListener('click', () => { + document.body.removeChild(popup) + }) + + document.body.appendChild(popup) +} \ No newline at end of file diff --git a/src/manifest.json b/src/manifest.json index 85093ef..798b43f 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -25,8 +25,7 @@ ], "web_accessible_resources": [ "inject.ts", - "background/popup.html", - "background/popup_.ts" + "background/popup.html" ], "permissions": [ "activeTab", diff --git a/yarn.lock b/yarn.lock index 69b3e86..515980f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -472,6 +472,18 @@ __metadata: languageName: node linkType: hard +"@parcel/optimizer-data-url@npm:2.8.3": + version: 2.8.3 + resolution: "@parcel/optimizer-data-url@npm:2.8.3" + dependencies: + "@parcel/plugin": 2.8.3 + "@parcel/utils": 2.8.3 + isbinaryfile: ^4.0.2 + mime: ^2.4.4 + checksum: 5df8d888269f7f3dfaa7bd3fb4f11d2d02ab8665404c50e99534231664fb4fd0b5be3f80cab513ef217e29cda9f91d77f5c649cfe6d227c34d48d422df52901f + languageName: node + linkType: hard + "@parcel/optimizer-htmlnano@npm:2.8.3": version: 2.8.3 resolution: "@parcel/optimizer-htmlnano@npm:2.8.3" @@ -781,6 +793,15 @@ __metadata: languageName: node linkType: hard +"@parcel/transformer-inline-string@npm:2.8.3": + version: 2.8.3 + resolution: "@parcel/transformer-inline-string@npm:2.8.3" + dependencies: + "@parcel/plugin": 2.8.3 + checksum: 23fa279e1fb0acb0439bfa03d908362796f2c81e911c52f38b8818f4240f4c35b4c236e4e46550def9140c4269456bba104f63ed8f1b713d08ef0276f2758e6b + languageName: node + linkType: hard + "@parcel/transformer-js@npm:2.8.3": version: 2.8.3 resolution: "@parcel/transformer-js@npm:2.8.3" @@ -1940,6 +1961,13 @@ __metadata: languageName: node linkType: hard +"isbinaryfile@npm:^4.0.2": + version: 4.0.10 + resolution: "isbinaryfile@npm:4.0.10" + checksum: a6b28db7e23ac7a77d3707567cac81356ea18bd602a4f21f424f862a31d0e7ab4f250759c98a559ece35ffe4d99f0d339f1ab884ffa9795172f632ab8f88e686 + languageName: node + linkType: hard + "isexe@npm:^2.0.0": version: 2.0.0 resolution: "isexe@npm:2.0.0" @@ -2164,6 +2192,15 @@ __metadata: languageName: node linkType: hard +"mime@npm:^2.4.4": + version: 2.6.0 + resolution: "mime@npm:2.6.0" + bin: + mime: cli.js + checksum: 1497ba7b9f6960694268a557eae24b743fd2923da46ec392b042469f4b901721ba0adcf8b0d3c2677839d0e243b209d76e5edcbd09cfdeffa2dfb6bb4df4b862 + languageName: node + linkType: hard + "minimatch@npm:^3.1.1": version: 3.1.2 resolution: "minimatch@npm:3.1.2" @@ -2636,6 +2673,8 @@ __metadata: resolution: "relayone-extension@workspace:." dependencies: "@parcel/config-webextension": ^2.8.3 + "@parcel/optimizer-data-url": 2.8.3 + "@parcel/transformer-inline-string": 2.8.3 "@relayx/crypto": ^6.1.5 "@relayx/frame-messaging": ^1.1.1 "@relayx/wallet": ^5.0.4