@vechain/connex
Advanced tools
Comparing version 2.0.0-beta.10 to 2.0.0-beta.11
@@ -14,14 +14,115 @@ "use strict"; | ||
const config_1 = require("./config"); | ||
function openExternal(requestId) { | ||
const check = require('custom-protocol-detection'); | ||
const url = `connex:sign?rid=${encodeURIComponent(requestId)}`; | ||
function registerEvent(target, event, cb) { | ||
target.addEventListener(event, cb); | ||
return { | ||
remove: () => { | ||
target.removeEventListener(event, cb); | ||
} | ||
}; | ||
} | ||
function createOrGetHiddenIframe() { | ||
const id = 'hiddenIframe'; | ||
const exist = document.getElementById(id); | ||
if (exist) { | ||
return exist; | ||
} | ||
const iframe = document.createElement("iframe"); | ||
iframe.src = 'about:blank'; | ||
iframe.id = id; | ||
iframe.style.display = "none"; | ||
document.body.appendChild(iframe); | ||
return iframe; | ||
} | ||
function openUriWithHiddenFrame(uri, timeout) { | ||
return new Promise((resolve, reject) => { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
check(url, () => reject(new Error('protocol not found')), () => resolve(), () => reject(new Error('protocol not found'))); | ||
const timer = setTimeout(() => { | ||
reject(); | ||
handler.remove(); | ||
}, timeout); | ||
const handler = registerEvent(window, "blur", () => { | ||
clearTimeout(timer); | ||
handler.remove(); | ||
resolve(); | ||
}); | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
createOrGetHiddenIframe().contentWindow.location.href = uri; | ||
}); | ||
} | ||
function openUriWithTimeoutHack(uri, timeout) { | ||
return new Promise((resolve, reject) => { | ||
//handle page running in an iframe (blur must be registered with top level window) | ||
let target = window; | ||
while (target != target.parent) { | ||
target = target.parent; | ||
} | ||
const timer = setTimeout(() => { | ||
reject(); | ||
handler.remove(); | ||
}, timeout); | ||
const handler = registerEvent(target, "blur", () => { | ||
clearTimeout(timer); | ||
handler.remove(); | ||
resolve(); | ||
}); | ||
window.location.href = uri; | ||
}); | ||
} | ||
function openUriUsingFirefox(uri) { | ||
return new Promise((resolve, reject) => { | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
createOrGetHiddenIframe().contentWindow.location.href = uri; | ||
resolve(); | ||
} | ||
catch (e) { | ||
// if (e.name == "NS_ERROR_UNKNOWN_PROTOCOL") { | ||
reject(); | ||
// } | ||
} | ||
}); | ||
} | ||
function openUriWithMsLaunchUri(uri) { | ||
return new Promise((resolve, reject) => { | ||
navigator.msLaunchUri(uri, resolve, reject); | ||
}); | ||
} | ||
function checkBrowser() { | ||
const isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0; | ||
const ua = navigator.userAgent.toLowerCase(); | ||
return { | ||
isOpera: isOpera, | ||
isFirefox: typeof window.InstallTrigger !== 'undefined', | ||
isSafari: (~ua.indexOf('safari') && !~ua.indexOf('chrome')) || Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0, | ||
isIOS: /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream, | ||
isChrome: !!window.chrome && !isOpera, | ||
isIE: /*@cc_on!@*/ false || !!document.documentMode // At least IE6 | ||
}; | ||
} | ||
function openUri(requestId, timeout) { | ||
const uri = `connex:sign?rid=${encodeURIComponent(requestId)}`; | ||
// eslint-disable-next-line no-extra-boolean-cast | ||
if (!!navigator.msLaunchUri) { //for IE and Edge in Win 8 and Win 10 | ||
return openUriWithMsLaunchUri(uri); | ||
} | ||
else { | ||
const browser = checkBrowser(); | ||
if (browser.isFirefox) { | ||
return openUriUsingFirefox(uri); | ||
} | ||
else if (browser.isChrome || browser.isIOS) { | ||
return openUriWithTimeoutHack(uri, timeout); | ||
} | ||
else if (browser.isSafari) { | ||
return openUriWithHiddenFrame(uri, timeout); | ||
} | ||
else { | ||
return Promise.reject(); | ||
//not supported, implement please | ||
} | ||
} | ||
} | ||
function open(requestId, spaWallet) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
yield openExternal(requestId); | ||
yield openUri(requestId, 1000); | ||
return; | ||
@@ -45,2 +146,2 @@ } | ||
exports.open = open; | ||
//# sourceMappingUR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UFFLElBQUksQ0FBQyxDQUFBO1lBQzlCLE9BQU07U0FDVDtRQUFDLFdBQU07WUFDSixNQUFNO1NBQ1Q7UUFDRCxJQUFJO1lBQ0EsTUFBTSxlQUFlLEdBQUcsV0FBVyxDQUFBO1lBQ25DLE1BQU0saUJBQWlCLEdBQUcsK0RBQStELENBQUE7WUFDekYsTUFBTSxDQUFDLElBQUksQ0FBQyxHQUFHLFNBQVMsSUFBSSxhQUFJLENBQUMsU0FBUyxZQUFZLGtCQUFrQixDQUFDLFNBQVMsQ0FBQyxFQUFFLEVBQUUsZUFBZSxFQUFFLGlCQUFpQixFQUFFLElBQUksQ0FBQyxDQUFBO1lBQ2hJLE9BQU07U0FDVDtRQUFDLFdBQU07WUFDSixNQUFNO1NBQ1Q7UUFDRCxNQUFNLElBQUksS0FBSyxDQUFDLGFBQWEsQ0FBQyxDQUFBO0lBQ2xDLENBQUM7Q0FBQTtBQWhCRCxvQkFnQkMifQ== |
{ | ||
"name": "@vechain/connex", | ||
"version": "2.0.0-beta.10", | ||
"version": "2.0.0-beta.11", | ||
"description": "Standard interface to connect DApp with VeChain and user", | ||
@@ -42,7 +42,6 @@ "main": "dist/index.js", | ||
"@vechain/connex-framework": "^2.0.0-beta.10", | ||
"custom-protocol-detection": "^1.0.1", | ||
"randombytes": "^2.1.0", | ||
"thor-devkit": "^1.3.1" | ||
}, | ||
"gitHead": "7f4a5a9a49d9a3d5c997847af1500c4e7521aaf2" | ||
"gitHead": "4d64845d154d5ae8fbd1d998e9b72ac56f1237bf" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4
1815
1519585
- Removedcustom-protocol-detection@^1.0.1
- Removedcustom-protocol-detection@1.0.1(transitive)