mirror of
https://github.com/lil-org/tokenary.git
synced 2024-11-22 21:49:51 +03:00
remove ios popup
This commit is contained in:
parent
e7f0639dfd
commit
d505411079
@ -89,9 +89,7 @@ function sendMessageToNativeApp(message) {
|
||||
|
||||
// Receive from service-worker
|
||||
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
if ("popupDidAppear" in request && "id" in request) {
|
||||
setTimeout(() => pollPopupStatus(request.id), 500);
|
||||
} else if ("didTapExtensionButton" in request) {
|
||||
if ("didTapExtensionButton" in request) {
|
||||
sendResponse({ host: window.location.host, favicon: getFavicon() });
|
||||
} else if ("name" in request && request.name == "switchAccount") {
|
||||
sendMessageToNativeApp(request);
|
||||
@ -140,10 +138,6 @@ function genId() {
|
||||
|
||||
function didChangeVisibility() {
|
||||
if (document.pendingRequestsIds.size != 0 && document.visibilityState === 'visible') {
|
||||
if (typeof document.stashedPopupId !== "undefined" && document.stashedPopupId > -1) {
|
||||
pollPopupStatus(document.stashedPopupId);
|
||||
document.stashedPopupId = -1;
|
||||
}
|
||||
document.pendingRequestsIds.forEach(id => {
|
||||
const request = {id: id, subject: "getResponse", host: window.location.host, isMobile: isMobile};
|
||||
browser.runtime.sendMessage(request).then(response => {
|
||||
@ -158,18 +152,3 @@ function didChangeVisibility() {
|
||||
|
||||
document.addEventListener('visibilitychange', didChangeVisibility);
|
||||
window.addEventListener('focus', didChangeVisibility);
|
||||
|
||||
// MARK: - iOS extension popup
|
||||
|
||||
function pollPopupStatus(id) {
|
||||
if (document.visibilityState === 'visible') {
|
||||
const request = {id: id, subject: "POPUP_CHECK", isMobile: isMobile};
|
||||
browser.runtime.sendMessage(request).then(response => {
|
||||
if (typeof response !== "undefined" && "popupStillThere" in response) {
|
||||
setTimeout(() => pollPopupStatus(id), 500);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
document.stashedPopupId = id;
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,14 @@
|
||||
// Copyright © 2023 Tokenary. All rights reserved.
|
||||
|
||||
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
if (request.subject === "POPUP_CHECK") {
|
||||
checkPopupStatus(request.id, sendResponse);
|
||||
} else if (request.subject === "POPUP_DID_PROCEED") {
|
||||
popupDidProceed(request.id);
|
||||
} else if (request.subject === "POPUP_APPEARED") {
|
||||
didAppearPopup(request.tab, sendResponse);
|
||||
} else if (request.subject === "message-to-wallet") {
|
||||
if (request.subject === "message-to-wallet") {
|
||||
sendNativeMessage(request, sender, sendResponse);
|
||||
if (request.isMobile) {
|
||||
const name = request.message.name;
|
||||
if (name != "switchEthereumChain" && name != "addEthereumChain" && name != "switchAccount") {
|
||||
showPopupIfThereIsNoVisible(request.message);
|
||||
if (name != "switchEthereumChain" && name != "addEthereumChain") {
|
||||
mobileRedirectFor(request.message);
|
||||
}
|
||||
}
|
||||
sendNativeMessage(request, sender, sendResponse);
|
||||
} else if (request.subject === "getResponse") {
|
||||
browser.runtime.sendNativeMessage("mac.tokenary.io", request).then(response => {
|
||||
if (typeof response !== "undefined") {
|
||||
@ -139,127 +133,21 @@ browser.action.onClicked.addListener(tab => {
|
||||
return true;
|
||||
});
|
||||
|
||||
// MARK: - iOS extension popup
|
||||
// MARK: - mobile redirect
|
||||
|
||||
function checkPopupStatus(id, sendResponse) {
|
||||
getCurrentPopupRequest().then(currentRequest => {
|
||||
if (typeof currentRequest !== "undefined" && id == currentRequest.id) {
|
||||
if (hasVisiblePopup()) {
|
||||
sendResponse({ popupStillThere: true });
|
||||
} else {
|
||||
didDismissPopup();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showPopupIfThereIsNoVisible(popupRequest) {
|
||||
getCurrentPopupRequest().then(result => {
|
||||
if (typeof result === "undefined" && !hasVisiblePopup()) {
|
||||
storeCurrentPopupRequest(popupRequest);
|
||||
browser.action.openPopup();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function popupDidProceed(id) {
|
||||
cleanupCurrentPopupRequestOnProceed();
|
||||
}
|
||||
|
||||
function didDismissPopup() {
|
||||
cleanupCurrentPopupRequestOnDismiss();
|
||||
}
|
||||
|
||||
function cancelPopupRequest(request) {
|
||||
const cancelResponse = {
|
||||
id: request.id,
|
||||
provider: request.provider,
|
||||
name: request.name,
|
||||
error: "canceled",
|
||||
subject: "cancelRequest",
|
||||
};
|
||||
browser.runtime.sendNativeMessage("mac.tokenary.io", cancelResponse).catch(() => {});
|
||||
function mobileRedirectFor(request) {
|
||||
const query = encodeURIComponent(JSON.stringify(request));
|
||||
browser.tabs.getCurrent((tab) => {
|
||||
if (tab) {
|
||||
browser.tabs.sendMessage(tab.id, cancelResponse);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function didAppearPopup(tab, sendResponse) {
|
||||
getCurrentPopupRequest().then(popupRequest => {
|
||||
if (typeof popupRequest !== "undefined") {
|
||||
sendResponse(popupRequest);
|
||||
browser.tabs.sendMessage(tab.id, {popupDidAppear: true, id: popupRequest.id});
|
||||
} else {
|
||||
const message = {didTapExtensionButton: true};
|
||||
browser.tabs.sendMessage(tab.id, message).then(response => {
|
||||
if (typeof response !== "undefined" && typeof response.host !== "undefined") {
|
||||
getLatestConfiguration(response.host).then(currentConfiguration => {
|
||||
const latestConfigurations = currentConfiguration.latestConfigurations;
|
||||
const switchAccountMessage = {
|
||||
name: "switchAccount",
|
||||
id: genId(),
|
||||
provider: "unknown",
|
||||
body: currentConfiguration,
|
||||
host: response.host,
|
||||
favicon: response.favicon
|
||||
};
|
||||
sendResponse(switchAccountMessage);
|
||||
storeCurrentPopupRequest(switchAccountMessage);
|
||||
browser.tabs.sendMessage(tab.id, {popupDidAppear: true, id: switchAccountMessage.id});
|
||||
browser.tabs.sendMessage(tab.id, switchAccountMessage);
|
||||
});
|
||||
}
|
||||
browser.scripting.executeScript({
|
||||
target: { tabId: tab.id },
|
||||
func: (query) => { window.location.href = `https://tokenary.io/extension?query=${query}`; },
|
||||
args: [query]
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function hasVisiblePopup() {
|
||||
const popup = browser.extension.getViews({ type: 'popup' });
|
||||
if (popup.length === 0) {
|
||||
return false;
|
||||
} else if (popup.length > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - current popup storage
|
||||
|
||||
function getCurrentPopupRequest() {
|
||||
return new Promise((resolve) => {
|
||||
browser.storage.session.get("currentPopup").then(result => {
|
||||
if (typeof result !== "undefined") {
|
||||
resolve(result["currentPopup"]);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
}).catch(() => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function storeCurrentPopupRequest(request) {
|
||||
browser.storage.session.set({ ["currentPopup"]: request });
|
||||
}
|
||||
|
||||
function cleanupCurrentPopupRequestOnProceed() {
|
||||
browser.storage.session.remove("currentPopup");
|
||||
}
|
||||
|
||||
function cleanupCurrentPopupRequestOnDismiss() {
|
||||
getCurrentPopupRequest().then(result => {
|
||||
if (typeof result !== "undefined") {
|
||||
cancelPopupRequest(result);
|
||||
}
|
||||
browser.storage.session.remove("currentPopup");
|
||||
}).catch(() => {
|
||||
browser.storage.session.remove("currentPopup");
|
||||
});
|
||||
}
|
||||
|
||||
// MARK: - helpers
|
||||
|
||||
function genId() {
|
||||
|
@ -26,7 +26,6 @@
|
||||
}],
|
||||
|
||||
"action": {
|
||||
"default_popup": "popup.html",
|
||||
"default_icon": {
|
||||
"16": "images/toolbar-icon-16.png",
|
||||
"19": "images/toolbar-icon-19.png",
|
||||
|
@ -1,38 +0,0 @@
|
||||
:root {
|
||||
color-scheme: light dark;
|
||||
}
|
||||
|
||||
body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-family: system-ui;
|
||||
text-align: center;
|
||||
align-content: center;
|
||||
justify-content: center;
|
||||
min-width: 200pt;
|
||||
margin: 0;
|
||||
margin-top: 23pt;
|
||||
margin-bottom: 23pt;
|
||||
}
|
||||
|
||||
#tokenary-button {
|
||||
font-size: 21pt;
|
||||
font-weight: bold;
|
||||
color: white;
|
||||
background-color: #0093FF;
|
||||
width: 88%;
|
||||
min-height: 100pt;
|
||||
border: none;
|
||||
border-radius: min(17vw, 17vh);
|
||||
-webkit-touch-callout: none;
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
padding: 8pt;
|
||||
line-height: 1.2em;
|
||||
text-align: center;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="popup.css">
|
||||
<script type="module" src="popup.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<button id="tokenary-button">open the app</button>
|
||||
</body>
|
||||
</html>
|
@ -1,58 +0,0 @@
|
||||
// Copyright © 2023 Tokenary. All rights reserved.
|
||||
|
||||
const button = document.getElementById('tokenary-button');
|
||||
var message = {};
|
||||
|
||||
browser.tabs.getCurrent(tab => {
|
||||
browser.runtime.sendMessage({subject: 'POPUP_APPEARED', tab: tab, isMobile: true}).then((response) => {
|
||||
message = response;
|
||||
setupButton();
|
||||
});
|
||||
});
|
||||
|
||||
button.addEventListener('click', () => {
|
||||
browser.runtime.sendMessage({subject: 'POPUP_DID_PROCEED', id: message.id, isMobile: true});
|
||||
const query = encodeURIComponent(JSON.stringify(message));
|
||||
browser.tabs.getCurrent((tab) => {
|
||||
if (tab) {
|
||||
browser.scripting.executeScript({
|
||||
target: { tabId: tab.id },
|
||||
func: (query) => { window.location.href = `https://tokenary.io/extension?query=${query}`; },
|
||||
args: [query]
|
||||
});
|
||||
}
|
||||
});
|
||||
return true;
|
||||
});
|
||||
|
||||
function setupButton() {
|
||||
var title = "open the app";
|
||||
switch (message.name) {
|
||||
case "signPersonalMessage":
|
||||
case "signMessage":
|
||||
case "signTypedMessage":
|
||||
title = "sign message\nin the app";
|
||||
break;
|
||||
case "signTransaction":
|
||||
case "signAndSendTransactions":
|
||||
case "signAllTransactions":
|
||||
case "signAndSendTransaction":
|
||||
title = "approve transaction\nin the app";
|
||||
break;
|
||||
case "requestAccounts":
|
||||
case "signIn":
|
||||
case "connect":
|
||||
title = "connect";
|
||||
break;
|
||||
case "switchAccount":
|
||||
const latestConfigurations = message.body.latestConfigurations;
|
||||
if (Array.isArray(latestConfigurations) && latestConfigurations.length) {
|
||||
title = "switch\naccount";
|
||||
} else {
|
||||
title = "connect\nwallet";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
button.innerText = title;
|
||||
}
|
@ -102,9 +102,6 @@
|
||||
2C773F63274523DC007B04E7 /* ResponseToExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C773F61274523DC007B04E7 /* ResponseToExtension.swift */; };
|
||||
2C78F8282683BDCC00C10670 /* Alert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C78F8272683BDCC00C10670 /* Alert.swift */; };
|
||||
2C797E7E267BB88800F2CE2D /* WelcomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C797E7D267BB88800F2CE2D /* WelcomeViewController.swift */; };
|
||||
2C8155682ADFC7A700F4559B /* popup.css in Resources */ = {isa = PBXBuildFile; fileRef = 2C8155662ADFC7A700F4559B /* popup.css */; };
|
||||
2C81556B2ADFC7B900F4559B /* popup.js in Resources */ = {isa = PBXBuildFile; fileRef = 2C8155692ADFC7B900F4559B /* popup.js */; };
|
||||
2C81556E2ADFC7C400F4559B /* popup.html in Resources */ = {isa = PBXBuildFile; fileRef = 2C81556C2ADFC7C400F4559B /* popup.html */; };
|
||||
2C8944C52AEAFF97006A711F /* FixedWidthInteger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C8944C42AEAFF97006A711F /* FixedWidthInteger.swift */; };
|
||||
2C8944C62AEAFF97006A711F /* FixedWidthInteger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C8944C42AEAFF97006A711F /* FixedWidthInteger.swift */; };
|
||||
2C8944CB2AEB0C10006A711F /* EthereumRPC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C8944CA2AEB0C10006A711F /* EthereumRPC.swift */; };
|
||||
@ -380,9 +377,6 @@
|
||||
2C773F61274523DC007B04E7 /* ResponseToExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResponseToExtension.swift; sourceTree = "<group>"; };
|
||||
2C78F8272683BDCC00C10670 /* Alert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alert.swift; sourceTree = "<group>"; };
|
||||
2C797E7D267BB88800F2CE2D /* WelcomeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeViewController.swift; sourceTree = "<group>"; };
|
||||
2C8155662ADFC7A700F4559B /* popup.css */ = {isa = PBXFileReference; lastKnownFileType = text.css; path = popup.css; sourceTree = "<group>"; };
|
||||
2C8155692ADFC7B900F4559B /* popup.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = popup.js; sourceTree = "<group>"; };
|
||||
2C81556C2ADFC7C400F4559B /* popup.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = popup.html; sourceTree = "<group>"; };
|
||||
2C8944C42AEAFF97006A711F /* FixedWidthInteger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FixedWidthInteger.swift; sourceTree = "<group>"; };
|
||||
2C8944CA2AEB0C10006A711F /* EthereumRPC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EthereumRPC.swift; sourceTree = "<group>"; };
|
||||
2C8944CD2AEC34EB006A711F /* Blockies.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Blockies.swift; sourceTree = "<group>"; };
|
||||
@ -915,9 +909,6 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2CCEB83627594E2A00768473 /* manifest.json */,
|
||||
2C8155662ADFC7A700F4559B /* popup.css */,
|
||||
2C8155692ADFC7B900F4559B /* popup.js */,
|
||||
2C81556C2ADFC7C400F4559B /* popup.html */,
|
||||
2CFDDF4D2765417D00F89019 /* ios_specific_content.js */,
|
||||
);
|
||||
path = Resources;
|
||||
@ -1325,10 +1316,7 @@
|
||||
2CB3845B27654EA900A189B9 /* images in Resources */,
|
||||
2CE0594027640E8E0042D844 /* service_worker.js in Resources */,
|
||||
2CE0594227640E8E0042D844 /* inpage.js in Resources */,
|
||||
2C81556E2ADFC7C400F4559B /* popup.html in Resources */,
|
||||
2C8155682ADFC7A700F4559B /* popup.css in Resources */,
|
||||
2CCEB83727594E2A00768473 /* manifest.json in Resources */,
|
||||
2C81556B2ADFC7B900F4559B /* popup.js in Resources */,
|
||||
2CE0594127640E8E0042D844 /* content.js in Resources */,
|
||||
2CFDDF4E2765417E00F89019 /* ios_specific_content.js in Resources */,
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user